]> git.lyx.org Git - lyx.git/blobdiff - src/insets/figinset.C
updates to minipage inset
[lyx.git] / src / insets / figinset.C
index a82b9deb1b011417d151510b919bfa770361a0a0..2b8a109d49fbab980d514c3a14755576ec963082 100644 (file)
@@ -33,6 +33,7 @@
 #include <list>
 #include <algorithm>
 #include <vector>
+#include <utility>
 
 #include <unistd.h>
 #include <csignal>
@@ -47,7 +48,7 @@
 #include "lyx.h"
 #include "lyx_main.h"
 #include "buffer.h"
-#include "filedlg.h"
+#include "frontends/FileDialog.h"
 #include "support/filetools.h"
 #include "LyXView.h" // just because of form_main
 #include "debug.h"
 #include "bufferview_funcs.h"
 #include "ColorHandler.h"
 #include "converter.h"
+#include "frontends/Dialogs.h" // redrawGUI
+
+#ifdef SIGC_CXX_NAMESPACES
+using SigC::slot;
+#endif
 
 using std::ostream;
 using std::istream;
@@ -75,6 +81,8 @@ using std::flush;
 using std::endl;
 using std::ostringstream;
 using std::copy;
+using std::pair;
+using std::make_pair;
 
 extern BufferView * current_view;
 extern FL_OBJECT * figinset_canvas;
@@ -162,10 +170,14 @@ void kill_gs(int pid, int sig)
 }
 
 
-extern "C" // static
-int GhostscriptMsg(FL_OBJECT *, Window, int, int,
-                  XEvent * ev, void *)
+extern "C" {
+static
+int GhostscriptMsg(XEvent * ev, void *)
 {
+       // bin all events not of interest
+       if (ev->type != ClientMessage)
+               return FL_PREEMPT;
+
        XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
 
        if (lyxerr.debugging()) {
@@ -292,7 +304,8 @@ int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                        }
                        break;
                }
-       return 0;
+       return FL_PREEMPT;
+}
 }
 
 
@@ -373,6 +386,9 @@ void AllocGrays(int num)
 }
 
 
+// xforms doesn't define this
+extern "C" FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
+
 static
 void InitFigures()
 {
@@ -384,9 +400,10 @@ void InitFigures()
        // first get visual
        gs_color = false;
        if (lyxrc.use_gui) {
-               fl_add_canvas_handler(figinset_canvas, ClientMessage,
-                                     GhostscriptMsg,
-                                     current_view->owner()->getForm());
+               /* we want to capture every event, in order to work around an
+                * xforms bug.
+                */
+               fl_set_preemptive_callback(fl_get_canvas_id(figinset_canvas), GhostscriptMsg, 0);
 
                local_gc_copy = createGC();
 
@@ -425,9 +442,6 @@ void DoneFigures()
        figures.clear();
        
        lyxerr.debug() << "Unregistering figures..." << endl;
-
-       fl_remove_canvas_handler(figinset_canvas, ClientMessage,
-                                GhostscriptMsg);
 }
 
 
@@ -555,7 +569,7 @@ void runqueue()
                                for (i = 0; i < nprop; ++i) {
                                        char * p = XGetAtomName(tempdisp,
                                                                prop[i]);
-                                       if (strcmp(p, "GHOSTVIEW") == 0) {
+                                       if (compare(p, "GHOSTVIEW") == 0) {
                                                err = false;
                                                // We free it when we leave so we don't leak.
                                                XFree(p);
@@ -941,6 +955,7 @@ InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
        raw_wid = raw_hgh = 0;
        changedfname = false;
        RegisterFigure(this);
+       r_ = Dialogs::redrawGUI.connect(slot(this, &InsetFig::redraw));
 }
 
 
@@ -950,6 +965,14 @@ InsetFig::~InsetFig()
                lyxerr << "Figure destructor called" << endl;
        }
        UnregisterFigure(this);
+       r_.disconnect();
+}
+
+
+void InsetFig::redraw()
+{
+       if (form && form->Figure->visible)
+               fl_redraw_form(form->Figure);
 }
 
 
@@ -1213,8 +1236,9 @@ void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
        if (form->Figure->visible) {
                fl_raise_form(form->Figure);
        } else {
-               fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
-                            FL_FULLBORDER, _("Figure"));
+               fl_show_form(form->Figure,
+                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
+                            _("Figure"));
        }
 }
 
@@ -1902,7 +1926,7 @@ void InsetFig::Preview(string const & p)
            tfname += ".eps";
        string buf1 = OnlyPath(owner->fileName());
        string buf2 = MakeAbsPath(tfname, buf1);
-       if (!Formats::View(owner, buf2, "eps"))
+       if (!formats.View(owner, buf2, "eps"))
                lyxerr << "Can't view " << buf2 << endl;
 }
 
@@ -1910,7 +1934,6 @@ void InsetFig::BrowseFile()
 {
        static string current_figure_path;
        static int once = 0;
-       LyXFileDlg fileDlg;
 
        if (lyxerr.debugging()) {
                lyxerr << "Filename: "
@@ -1935,23 +1958,21 @@ void InsetFig::BrowseFile()
                bufclip = AddName (system_lyxdir, "clipart");   
 
 
-       fileDlg.SetButton(0, _("Clipart"), bufclip); 
-       fileDlg.SetButton(1, _("Document"), buf); 
+       FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
+               LFUN_SELECT_FILE_SYNC,
+               make_pair(string(_("Clip art")), string(bufclip)),
+               make_pair(string(_("Documents")), string(buf)));
 
        bool error = false;
        do {
-               ProhibitInput(current_view);
-               if (once) {
-                       p = fileDlg.Select(_("EPS Figure"),
-                                          current_figure_path,
-                                          "*ps", string());
-               } else {
-                       p = fileDlg.Select(_("EPS Figure"), buf,
-                                          "*ps", string());
-               }
-               AllowInput(current_view);
+               string const path = (once) ? current_figure_path : buf;
+
+               FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
 
-               if (p.empty()) return;
+               string const p = result.second;
+
+               if (p.empty())
+                       return;
 
                buf = MakeRelPath(p, buf2);
                current_figure_path = OnlyPath(p);