]> git.lyx.org Git - lyx.git/blobdiff - src/WorkArea.C
Michael's latest batch of new gnome files.
[lyx.git] / src / WorkArea.C
index c3b0d5f0abc0f38b1d69f7d34f42a0109657b38d..ba4c4407df742bac0a556144065b1afec655559a 100644 (file)
 #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
@@ -67,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;
+       }
 }
 
 
@@ -83,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 =
@@ -175,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();
 }
 
@@ -205,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);
@@ -562,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;