From dace843ddc05c5533cfab11fa3c50d290a0876ca Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 28 Mar 2007 14:47:52 +0000 Subject: [PATCH] Re-enable mouse hover detection over insets. This was disable at rev 17589 to fix bug 3144 which has been re-opened for this. There is a user visible change with this commit: For text insets, the button stays "highlighted" as long as the mouse cursor is within the inset but not within a nested inset. Formerly the button was highlighted only when hovered. This new behaviour is better because we can now imagine funkier behaviour like inset color background change when hovered. Also the small math pink corners can be adapted to react to mouse hover in the future. Ideally we should also "highlight" the button when entering the inset via the keyboard or when the keyboard cursor is just before the inset (because we can then use Ctrl-i). * BufferView: - getCoveringInset(): new method. - workAreaDispatch(): use getCoveringInset() instead of LyXText::checkInsetHit() git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17610 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 78 +++++++++++++++++++++++++++++++++++++++--------- src/BufferView.h | 9 ++++++ 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index ec9db814b6..78e2dc659a 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -1078,6 +1078,54 @@ void BufferView::workAreaResize(int width, int height) } +InsetBase const * BufferView::getCoveringInset(LyXText const & text, int x, int y) +{ + pit_type pit = text.getPitNearY(*this, y); + BOOST_ASSERT(pit != -1); + Paragraph const & par = text.getPar(pit); + + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION + << ": x: " << x + << " y: " << y + << " pit: " << pit + << endl; + InsetList::const_iterator iit = par.insetlist.begin(); + InsetList::const_iterator iend = par.insetlist.end(); + for (; iit != iend; ++iit) { + InsetBase * const inset = iit->inset; + if (inset->covers(*this, x, y)) { + if (!inset->descendable()) + // No need to go further down if the inset is not + // descendable. + return inset; + + size_t cell_number = inset->nargs(); + // Check all the inner cell. + for (size_t i = 0; i != cell_number; ++i) { + LyXText const * inner_text = inset->getText(i); + if (inner_text) { + // Try deeper. + InsetBase const * inset_deeper = + getCoveringInset(*inner_text, x, y); + if (inset_deeper) + return inset_deeper; + } + } + + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION + << ": Hit inset: " << inset << endl; + return inset; + } + } + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION + << ": No inset hit. " << endl; + return 0; +} + + bool BufferView::workAreaDispatch(FuncRequest const & cmd0) { //lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl; @@ -1101,22 +1149,24 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0) cmd.y = min(max(cmd.y, -1), height_); if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) { + + // Get inset under mouse, if there is one. + InsetBase const * covering_inset = + getCoveringInset(buffer_->text(), cmd.x, cmd.y); + if (covering_inset == last_inset_) + // Same inset, no need to do anything... + return false; bool need_redraw = false; - - //Get inset under mouse, if there is one - // NOTE: checkInsetHit returns the top level inset of nested insets. - // If you happen to move from a text (inset=0) to a text inside an inset - // (e.g. an opened footnote inset, again inset=0), that inset will not - // be redrawn. - InsetBase * inset = buffer_->text().checkInsetHit(cur.bv(), cmd.x, cmd.y); - if (inset != last_inset_) { - if (last_inset_) - need_redraw |= last_inset_->setMouseHover(false); - if (inset) - need_redraw |= inset->setMouseHover(true); - last_inset_ = inset; - } + // const_cast because of setMouseHover(). + InsetBase * inset = const_cast(covering_inset); + if (last_inset_) + // Remove the hint on the last hovered inset (if any). + need_redraw |= last_inset_->setMouseHover(false); + if (inset) + // Highlighted the newly hovered inset (if any). + need_redraw |= inset->setMouseHover(true); + last_inset_ = inset; // if last metrics update was in singlepar mode, WorkArea::redraw() will // not expose the button for redraw. We adjust here the metrics dimension diff --git a/src/BufferView.h b/src/BufferView.h index 357e33e8cb..8ebd0e6f94 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -249,6 +249,15 @@ public: private: /// bool multiParSel(); + + /// Search recursively for the the innermost inset that covers (x, y) position. + /// \retval 0 if no inset is found. + InsetBase const * getCoveringInset( + LyXText const & text, //< The LyXText where we start searching. + int x, //< x-coordinate on screen + int y //< y-coordinate on screen + ); + /// int width_; /// -- 2.39.2