]> git.lyx.org Git - lyx.git/blobdiff - src/WorkArea.C
get rid of LYX_LIBS
[lyx.git] / src / WorkArea.C
index c3b0d5f0abc0f38b1d69f7d34f42a0109657b38d..792bad1d7f66ec32d34e49bea74daf2e9e381c4c 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;
+using std::hex;
 
 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 +69,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 +92,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 =
@@ -148,7 +157,8 @@ WorkArea::WorkArea(int xpos, int ypos, int width, int height)
        fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
        obj->u_vdata = this;
        fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0);
-
+       setScrollbarBounds(0.0, 0.0);
+       
        ///
        /// The free object
 
@@ -175,6 +185,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 +219,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);
@@ -341,7 +355,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
 
        if (!area) return 1;
        
-       switch (event){
+       switch (event) {
        case FL_DRAW:
                if (!area->work_area ||
                    !area->work_area->form->visible)
@@ -562,6 +576,32 @@ extern "C" {
 
 } // namespace anon
 
+void WorkArea::event_cb(XEvent * xev)
+{
+       switch (xev->type) {
+               case SelectionRequest:
+                       lyxerr[Debug::GUI] << "X requested selection." << endl;
+                       selectionRequested.emit();
+                       break;
+               case SelectionClear:
+                       lyxerr[Debug::GUI] << "Lost selection." << endl;
+                       selectionLost.emit();
+                       break; 
+       }
+}
+
+
+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;
@@ -575,8 +615,8 @@ string const WorkArea::getClipboard() const
                if (fl_check_forms() == FL_EVENT) {
                        fl_XNextEvent(&ev);
                        lyxerr << "Received unhandled X11 event" << endl; 
-                       lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
-                               "Target: 0x" << std::hex << ev.xany.window << endl;
+                       lyxerr << "Type: 0x" << hex << ev.xany.type <<
+                               " Target: 0x" << hex << ev.xany.window << endl;
                }
        }
        return clipboard_selection;