]> git.lyx.org Git - lyx.git/blobdiff - src/WorkArea.C
bug 183
[lyx.git] / src / WorkArea.C
index a6fc52ddb00c126d25551c5d4c823ec9cf4570a9..ba4c4407df742bac0a556144065b1afec655559a 100644 (file)
@@ -9,33 +9,37 @@
  * ====================================================== */
 
 #include <config.h>
-#include <cmath>
-#include <cctype>
+
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "WorkArea.h"
 #include "debug.h"
-#include "support/lstrings.h"
 #include "LyXView.h"
-#include "support/filetools.h" // LibFileSearch
 #include "lyxrc.h" // lyxrc.show_banner
 #include "version.h" // lyx_version
-#include "support/LAssert.h"
 
 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
 #include "lyxlookup.h"
 #endif
 
+#include "support/filetools.h" // LibFileSearch
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+
+#include <cmath>
+#include <cctype>
+
+// xforms doesn't define this (but it should be in <forms.h>).
+extern "C"
+FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
 using std::endl;
+using std::abs;
 
 FL_OBJECT * figinset_canvas;
 
-// needed to make the c++ compiler find the correct version of abs.
-// This is at least true for g++.
-//using std::abs;
-
 namespace {
 
 inline
@@ -64,6 +68,13 @@ extern "C" {
                return WorkArea::work_area_handler(ob, event,
                                                   0, 0, key, xev);
         }
+
+       static
+       int C_WorkAreaEventCB(FL_FORM * form, void * xev) {
+               WorkArea * wa=static_cast<WorkArea*>(form->u_vdata);
+               wa->event_cb(static_cast<XEvent*>(xev));
+               return 0;
+       }
 }
 
 
@@ -80,7 +91,7 @@ WorkArea::WorkArea(int xpos, int ypos, int width, int height)
                       << width << 'x' << height << endl;
        //
        FL_OBJECT * obj;
-       int const bw = int(std::abs(float(fl_get_border_width())));
+       int const bw = int(abs(fl_get_border_width()));
 
        // We really want to get rid of figinset_canvas.
        ::figinset_canvas = figinset_canvas = obj =
@@ -172,6 +183,10 @@ WorkArea::WorkArea(int xpos, int ypos, int width, int height)
        fl_set_object_resize(obj, FL_RESIZE_ALL);
        fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
 
+       /// X selection hook - xforms gets it wrong
+       fl_current_form->u_vdata = this;
+       fl_register_raw_callback(fl_current_form, FL_ALL_EVENT, C_WorkAreaEventCB); 
        fl_unfreeze_all_forms();
 }
 
@@ -202,7 +217,7 @@ void WorkArea::resize(int xpos, int ypos, int width, int height)
 {
        fl_freeze_all_forms();
        
-       int const bw = int(std::abs(float(fl_get_border_width())));
+       int const bw = int(abs(fl_get_border_width()));
 
        // a box
        fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
@@ -325,8 +340,6 @@ void WorkArea::scroll_cb(FL_OBJECT * ob, long)
 }
 
 
-bool Lgb_bug_find_hack = false;
-
 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
                                FL_Coord, FL_Coord ,
                                int key, void * xev)
@@ -347,9 +360,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
                        return 1;
                lyxerr[Debug::WORKAREA] << "Workarea event: DRAW" << endl;
                area->createPixmap(area->workWidth(), area->height());
-               Lgb_bug_find_hack = true;
                area->workAreaExpose();
-               Lgb_bug_find_hack = false;
                break;
        case FL_PUSH:
                if (!ev || ev->xbutton.button == 0) break;
@@ -563,6 +574,27 @@ extern "C" {
 
 } // namespace anon
 
+void WorkArea::event_cb(XEvent * xev)
+{
+       if (xev->type != SelectionRequest)
+               return;
+       selectionRequested.emit();
+       return;
+}
+
+
+void WorkArea::haveSelection(bool yes) const
+{
+       if (!yes) {
+               XSetSelectionOwner(fl_get_display(), XA_PRIMARY, None, CurrentTime);
+               return;
+       }
+       XSetSelectionOwner(fl_get_display(), XA_PRIMARY, FL_ObjWin(work_area), CurrentTime);
+}
+
 string const WorkArea::getClipboard() const 
 {
        clipboard_read = false;