]> git.lyx.org Git - lyx.git/blobdiff - src/WorkArea.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / WorkArea.C
index a6fc52ddb00c126d25551c5d4c823ec9cf4570a9..7b028ef122966cb1b47716aa94a61582c1f94193 100644 (file)
@@ -9,32 +9,35 @@
  * ====================================================== */
 
 #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
 
-using std::endl;
+#include "support/filetools.h" // LibFileSearch
+#include "support/lstrings.h"
+#include "support/LAssert.h"
 
-FL_OBJECT * figinset_canvas;
+#include <cmath>
+#include <cctype>
 
-// needed to make the c++ compiler find the correct version of abs.
-// This is at least true for g++.
-//using std::abs;
+// 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;
 
 namespace {
 
@@ -64,6 +67,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;
+       }
 }
 
 
@@ -72,23 +82,13 @@ WorkArea::WorkArea(int xpos, int ypos, int width, int height)
 {
        fl_freeze_all_forms();
 
-       figinset_canvas = 0;
-
        if (lyxerr.debugging(Debug::WORKAREA))
                lyxerr << "Creating work area: +"
                       << xpos << '+' << ypos << ' '
                       << width << 'x' << height << endl;
        //
        FL_OBJECT * obj;
-       int const bw = int(std::abs(float(fl_get_border_width())));
-
-       // We really want to get rid of figinset_canvas.
-       ::figinset_canvas = figinset_canvas = obj =
-                 fl_add_canvas(FL_NORMAL_CANVAS,
-                               xpos + 1, ypos + 1, 1, 1, "");
-       fl_set_object_boxtype(obj, FL_NO_BOX);
-       fl_set_object_resize(obj, FL_RESIZE_ALL);
-       fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
+       int const bw = int(abs(fl_get_border_width()));
 
        // a box
        if (lyxerr.debugging(Debug::WORKAREA))
@@ -145,7 +145,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
 
@@ -172,6 +173,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 +207,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 +330,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)
@@ -340,16 +343,14 @@ 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)
                        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 +564,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;
@@ -576,8 +603,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;