]> git.lyx.org Git - lyx.git/blobdiff - src/WorkArea.C
some new clipboard code
[lyx.git] / src / WorkArea.C
index f93ca8c8abfc3529c4aba6226cb76f05c6491194..1e6604ff1a880905f4ece5f7fdafd8ff37f9a5dd 100644 (file)
@@ -24,7 +24,7 @@ using std::endl;
 
 FL_OBJECT * figinset_canvas;
 
-// need to make the c++ compiler fint the correct version of abs.
+// need to make the c++ compiler find the correct version of abs.
 // This is at least true for g++.
 using std::abs;
 
@@ -65,7 +65,7 @@ WorkArea::WorkArea(BufferView * o, int xpos, int ypos, int width, int height)
                       << width << 'x' << height << endl;
        //
        FL_OBJECT * obj;
-       const int bw = int(abs(float(fl_get_border_width())));
+       const int bw = int(std::abs(float(fl_get_border_width())));
 
        // We really want to get rid of figinset_canvas.
        ::figinset_canvas = figinset_canvas = obj =
@@ -162,7 +162,7 @@ void WorkArea::resize(int xpos, int ypos, int width, int height)
 {
        fl_freeze_all_forms();
        
-       const int bw = int(abs(float(fl_get_border_width())));
+       const int bw = int(std::abs(float(fl_get_border_width())));
 
        // a box
        fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
@@ -344,10 +344,12 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
                break;
        case FL_OTHER:
                if (!ev) break;
+#ifndef XFORMS_CLIPBOARD
                if (ev->type == SelectionNotify) {
                        lyxerr.debug() << "Workarea event: SELECTION" << endl;
                        area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
                } else
+#endif
                        lyxerr.debug() << "Workarea event: OTHER" << endl;
 
                break;
@@ -355,3 +357,52 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
   
        return 1;
 }
+
+
+#ifdef XFORMS_CLIPBOARD
+static string clipboard_selection;
+static bool clipboard_read = false;
+
+static
+int request_clipboard_cb(FL_OBJECT * /*ob*/, long /*type*/,
+                       void const * data, long size) 
+{
+       clipboard_selection.erase();
+       if (size == 0) return 0; // no selection
+        
+       clipboard_selection.reserve(size);
+       for (int i = 0; i < size; ++i) {
+               clipboard_selection.push_back(static_cast<char*>(data)[i]);
+       }
+       clipboard_read = true;
+       return 0;
+}
+
+
+string WorkArea::getClipboard() const 
+{
+       clipboard_read = false;
+       
+       if (fl_request_clipboard(work_area, 0, request_clipboard_cb) == -1)
+               return string();
+
+       XEvent ev;
+       
+       while (!clipboard_read) {
+               if (fl_check_forms() == FL_EVENT) {
+                       lyxerr << "LyX: This shouldn't happen..." << endl;
+                       fl_XNextEvent(&ev);
+               }
+       }
+       return clipboard_selection;
+}
+
+       
+void WorkArea::putClipboard(string const & s) const
+{
+       static string hold;
+       hold = s;
+       
+       fl_stuff_clipboard(work_area, 0, hold.c_str(), hold.size(), 0);
+}
+#endif