From 813234f7e6c1f731a77249dd5b0ac02769c4879f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 13 Jan 2002 17:28:42 +0000 Subject: [PATCH] bug 69 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3357 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 16 ++++++++++++++++ src/BufferView_pimpl.h | 2 ++ src/ChangeLog | 8 ++++++++ src/WorkArea.C | 36 ++++++++++++++++++++++++++++++++++++ src/WorkArea.h | 8 ++++++++ src/text2.C | 9 +-------- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 8e2021b8ac..cf671b5216 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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(); diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 27c4961b06..652b6c7be4 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -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(); diff --git a/src/ChangeLog b/src/ChangeLog index 47ec906add..8081e1fa8f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2001-11-26 John Levon + + * 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 * BufferView_pimpl.C (MenuInsertLyXFile): diff --git a/src/WorkArea.C b/src/WorkArea.C index f969ff3cf3..ba4c4407df 100644 --- a/src/WorkArea.C +++ b/src/WorkArea.C @@ -31,6 +31,10 @@ #include #include +// xforms doesn't define this (but it should be in ). +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(form->u_vdata); + wa->event_cb(static_cast(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; diff --git a/src/WorkArea.h b/src/WorkArea.h index c9f58b7fa9..872323573e 100644 --- a/src/WorkArea.h +++ b/src/WorkArea.h @@ -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 workAreaDoubleClick; /// SigC::Signal3 workAreaTripleClick; + /// emitted when an X client has requested our selection + SigC::Signal0 selectionRequested; + + /// handles SelectionRequest X Event, to fill the clipboard + void WorkArea::event_cb(XEvent * xev); private: /// void createPixmap(int, int); + /// FL_OBJECT * backgroundbox; /// diff --git a/src/text2.C b/src/text2.C index 0c030a5cbd..3867ffa8c0 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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 -- 2.39.2