From 6b89c145fdec2bf224e0bd8c56b3a55dfd5adf22 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 13 Aug 2004 14:56:06 +0000 Subject: [PATCH] fix toggling of collapsable insets with the mouse (bug 1558) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8901 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 9 ++++----- src/ChangeLog | 16 +++++++++++++++- src/cursor.C | 17 +++++++++++++++-- src/cursor.h | 6 +++++- src/insets/ChangeLog | 11 +++++++++++ src/insets/insetbase.C | 2 ++ src/insets/insetcollapsable.C | 20 +++++++++----------- src/lyxfunc.C | 6 +++--- 8 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2c264a7d20..a54c32e82e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -883,18 +883,17 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) // via the temp cursor. If the inset wishes to change the real // cursor it has to do so explicitly by using // cur.bv().cursor() = cur; (or similar)' - DispatchResult res; if (inset) inset->dispatch(cur, cmd); // Now dispatch to the temporary cursor. If the real cursor should // be modified, the inset's dispatch has to do so explicitly. - if (!res.dispatched()) - res = cur.dispatch(cmd); + if (!cur.result().dispatched()) + cur.dispatch(cmd); - if (res.dispatched()) { + if (cur.result().dispatched()) { // Redraw if requested or necessary. - if (fitCursor() || res.update()) + if (fitCursor() || cur.result().update()) update(); } diff --git a/src/ChangeLog b/src/ChangeLog index ea87c4538c..9629e53bd0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2004-08-13 Jean-Marc Lasgouttes + + Fix toggling of collapsable insets with the mouse (bug 1558) + + * lyxfunc.C (dispatch): adapt to LCursor changes + + * BufferView_pimpl.C (workAreaDispatch): adapt to LCursor changes; + make sure that dispatch is not invoked twice + + * cursor.C (needsUpdate): new method + (dispatch): return void + (result): new method, to access the DispatchResult of the cursor. + 2004-08-13 José Matos * tabular.C (docbook): close empty tags in XML. Fix bug 1147. @@ -12,7 +25,8 @@ 2004-08-12 André Pönitz * text3.C: take out the 'cursor right' form insertInset and only - do it in those places when it is really needed. Fixes crash on C-m... + do it in those places when it is really needed. Fixes crash on + C-m... 2004-08-08 Jean-Marc Lasgouttes diff --git a/src/cursor.C b/src/cursor.C index c2de922fb8..2e4c8017d4 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -84,11 +84,11 @@ void LCursor::setCursor(DocIterator const & cur, bool sel) } -DispatchResult LCursor::dispatch(FuncRequest const & cmd0) +void LCursor::dispatch(FuncRequest const & cmd0) { lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; if (empty()) - return DispatchResult(); + return; FuncRequest cmd = cmd0; LCursor safe = *this; @@ -115,6 +115,11 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) operator=(safe); disp_.dispatched(false); } +} + + +DispatchResult LCursor::result() const +{ return disp_; } @@ -1123,7 +1128,15 @@ void LCursor::dispatched() } +void LCursor::needsUpdate() +{ + disp_.update(true); +} + + void LCursor::noUpdate() { disp_.update(false); } + + diff --git a/src/cursor.h b/src/cursor.h index e99a8a06bd..5fbad76ef7 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -38,7 +38,9 @@ public: explicit LCursor(BufferView & bv); /// dispatch from innermost inset upwards - DispatchResult dispatch(FuncRequest const & cmd); + void dispatch(FuncRequest const & cmd); + /// get the resut of the last dispatch + DispatchResult result() const; /// are we willing to handle this event? bool getStatus(FuncRequest const & cmd, FuncStatus & flag); @@ -145,6 +147,8 @@ public: void undispatched(); /// the event was already dispatched void dispatched(); + /// call update() when done + void needsUpdate(); /// don't call update() when done void noUpdate(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 77bcf614de..19287b2378 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2004-08-13 Jean-Marc Lasgouttes + + * insetcollapsable.C (priv_dispatch): on a mouse press event, do + not ask for an update if we did nothing; on a mouse release, make + sure that the cursor is moved to the right position; on a mouse + release, exit from the inset instead of invoking a + LFUN_FINISHED_RIGHT. + + * insetbase.C (dispatch): before invoking dispatch, set cursor + result to dispatch=update=true. + 2004-08-13 José Matos * insetgraphics.C (docbook): close empty tags in XML. Fix bug 1147. diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index cf7e3604c3..4346c3705b 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -113,6 +113,8 @@ InsetBase::Code InsetBase::translate(std::string const & name) void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd) { + cur.needsUpdate(); + cur.dispatched(); priv_dispatch(cur, cmd); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 6d908ce86e..7b31d8e750 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -245,11 +245,6 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) cur.push(*this); //lyxerr << "InsetCollapsable: edit xy" << endl; if (status_ == Collapsed) { - setStatus(Open); - // We are not calling editXY() because the row cache of the - // inset might be invalid. 'Entering from the left' should be - // ok, though. - InsetText::edit(cur, true); return this; } return InsetText::editXY(cur, x, y); @@ -258,14 +253,17 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) { - //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd - // << " button y: " << button_dim.y2 << endl; +// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd +// << " button y: " << button_dim.y2 +// << " coll/inline/open: " << status_ << endl; switch (cmd.action) { case LFUN_MOUSE_PRESS: if (status_ == Inlined) InsetText::priv_dispatch(cur, cmd); else if (status_ == Open && !hitButton(cmd)) InsetText::priv_dispatch(cur, cmd); + else + cur.noUpdate(); break; case LFUN_MOUSE_MOTION: @@ -287,15 +285,15 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; setStatus(Open); edit(cur, true); + cur.bv().cursor() = cur; break; case Open: { - FuncRequest cmd1 = cmd; - if (hitButton(cmd1)) { + if (hitButton(cmd)) { lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; setStatus(Collapsed); - cur.undispatched(); - cmd = FuncRequest(LFUN_FINISHED_RIGHT); + leaveInset(cur, *this); + cur.bv().cursor() = cur; } else { lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; InsetText::priv_dispatch(cur, cmd); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 5ed01e177f..f4fac34f66 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1422,9 +1422,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) default: { update = false; - DispatchResult res = view()->cursor().dispatch(cmd); - if (res.dispatched()) - update |= res.update(); + view()->cursor().dispatch(cmd); + if (view()->cursor().result().dispatched()) + update |= view()->cursor().result().update(); else update |= view()->dispatch(cmd); -- 2.39.5