+#include "form_graphics.h"
+#include "lyx_gui_misc.h"
+#include "filedlg.h"
+#include "support/FileInfo.h"
+#include "support/filetools.h"
+
+using std::ostream;
+using std::endl;
+
+extern string system_lyxdir;
+extern string user_lyxdir;
+extern string system_tempdir;
+
+string browseFile();
+
+extern "C" void GraphicxCB(FL_OBJECT * obj, long arg)
+{
+ lyxerr << "GraphicxCB: obj = " << obj << " arg = " << arg << endl;
+ switch (arg) {
+ case 0: // The graphics file
+ lyxerr << "Set the graphics file in InsetGraphics" << endl;
+ break;
+ case 1: // The file browser
+ browseFile();
+ break;
+ case 2: // The Apply button
+ lyxerr << "Scan the form and set the "
+ "InsetGraphics accordingly." << endl;
+ break;
+ case 3: // The OK button
+ GraphicxCB(obj, 2); // do the apply
+ GraphicxCB(obj, 4); // do the cancel
+ break;
+ case 4: // The Cancel button
+ lyxerr << "Just hide the form and do nothing else!" << endl;
+ break;
+ case 99:
+ lyxerr << "Not implemented yet..." << endl;
+ break;
+ default:
+ lyxerr << "Unknown callback value!" << endl;
+ break;
+ }
+}
+
+
+string browseFile()
+{
+ // This function is probably not good enough yet, and does need some
+ // arguemnts to tell what dir to start looking in.
+
+ static string current_figure_path = ".";
+
+ LyXFileDlg fileDlg;
+
+ // Does user clipart directory exist?
+ string bufclip = AddName (user_lyxdir, "clipart");
+ FileInfo fileInfo(bufclip);
+ if (!(fileInfo.isOK() && fileInfo.isDir()))
+ // No - bail out to system clipart directory
+ bufclip = AddName (system_lyxdir, "clipart");
+
+
+ fileDlg.SetButton(0, _("Clipart"), bufclip);
+
+ bool error = false;
+ string buf;
+ do {
+ string p = fileDlg.Select(_("Graphics"),
+ current_figure_path,
+ "*ps", string());
+
+ if (p.empty()) return p;
+
+ current_figure_path = OnlyPath(p);
+
+ if (p.find_first_of("#~$% ") != string::npos) {
+ WriteAlert(_("Filename can't contain any "
+ "of these characters:"),
+ // xgettext:no-c-format
+ _("space, '#', '~', '$' or '%'."));
+ error = true;
+ }
+ } while (error);
+
+ return buf;
+}
+
+
+InsetGraphics::InsetGraphics()
+ : form(0)
+{}