]> git.lyx.org Git - lyx.git/commitdiff
bug 69
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 13 Jan 2002 17:28:42 +0000 (17:28 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 13 Jan 2002 17:28:42 +0000 (17:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3357 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/WorkArea.C
src/WorkArea.h
src/text2.C

index 8e2021b8ac83a4158edf310120dd03816be6df2c..cf671b5216472648222c3c519c5acc404f43e424 100644 (file)
@@ -155,6 +155,8 @@ BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
                .connect(slot(this, &BufferView::Pimpl::tripleClick));
        workarea_.workAreaKeyPress
                .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
+       workarea_.selectionRequested
+               .connect(slot(this, &BufferView::Pimpl::selectionRequested)); 
        
        cursor_timeout.timeout.connect(slot(this,
                                            &BufferView::Pimpl::cursorToggle));
@@ -736,6 +738,15 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
 }
 
 
+void BufferView::Pimpl::selectionRequested()
+{
+       string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(), false)); 
+       if (!sel.empty()) {
+               workarea_.putClipboard(sel);
+       }
+}
+
 void BufferView::Pimpl::enterView()
 {
        if (active() && available()) {
@@ -780,6 +791,11 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
        if (button == 2)
                return;
 
+       // finish selection
+       if (button == 1) {
+               workarea_.haveSelection(bv_->getLyXText()->selection.set());
+       }
        setState();
        owner_->showState();
        owner_->updateMenubar();
index 27c4961b068da93bc4bdf15233140c4e73bb298d..652b6c7be4c2aa0fa863f5f2d7944b189a7b2674 100644 (file)
@@ -78,6 +78,8 @@ struct BufferView::Pimpl : public SigC::Object {
        ///
        void tripleClick(int x, int y, unsigned int button);
        ///
+       void selectionRequested();
+       ///
        void enterView();
        ///
        void leaveView();
index 47ec906add65b73849668cd94c9b48a7566e95fd..8081e1fa8f21217e6dcc80633845e14ed4a84eed 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-26  John Levon  <moz@compsoc.man.ac.uk>
+
+       * BufferView_pimpl.h:
+       * BufferView_pimpl.C:
+       * WorkArea.h:
+       * WorkArea.C:
+       * text2.C: tell X when we have made a selection for copying
+
 2002-01-13  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * BufferView_pimpl.C (MenuInsertLyXFile): 
index f969ff3cf35a943b2f3f17fed3f4c056a0b1d16a..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;
 
@@ -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;
+       }
 }
 
 
@@ -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();
 }
 
@@ -559,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;
index c9f58b7fa9a3fe453cc815e0af8ff7a5527213e6..872323573eb5f181a15ca336dfb8ed2e410e37f8 100644 (file)
@@ -95,6 +95,8 @@ public:
                                     int /*key*/, void * xev);
        /// xforms callback
        static void scroll_cb(FL_OBJECT *, long);
+       /// a selection exists
+       void haveSelection(bool) const;
        ///
        string const getClipboard() const;
        ///
@@ -124,9 +126,15 @@ public:
        SigC::Signal3<void, int, int, unsigned int> workAreaDoubleClick;
        ///
        SigC::Signal3<void, int, int, unsigned int> workAreaTripleClick;
+       /// emitted when an X client has requested our selection
+       SigC::Signal0<void> selectionRequested;
+       /// handles SelectionRequest X Event, to fill the clipboard
+       void WorkArea::event_cb(XEvent * xev);
 private:
        ///
        void createPixmap(int, int);
        ///
        FL_OBJECT * backgroundbox;
        ///     
index 0c030a5cbd1100aa38fd92c8858b42b4cebde228..3867ffa8c03ca61e44967fab0623795215177f0b 100644 (file)
@@ -1796,14 +1796,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
 
 void LyXText::copySelection(BufferView * bview)
 {
-       // Stuff what we got on the clipboard. Even if there is no selection.
-
-       // There is a problem with having the stuffing here in that the
-       // larger the selection the slower LyX will get. This can be
-       // solved by running the line below only when the selection has
-       // finished. The solution used currently just works, to make it
-       // faster we need to be more clever and probably also have more
-       // calls to stuffClipboard. (Lgb)
+       // stuff the selection onto the X clipboard, from an explicit copy request
        bview->stuffClipboard(selectionAsString(bview->buffer(), true));
 
        // this doesnt make sense, if there is no selection