diff --git a/src/BufferView.C b/src/BufferView.C index 6760ac7369..5749c80252 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -334,7 +334,7 @@ bool BufferView::multiParSel() } -std::pair BufferView::update(Update::flags flags) +bool BufferView::update(Update::flags flags) { // This is close to a hot-path. if (lyxerr.debugging(Debug::DEBUG)) { @@ -348,7 +348,7 @@ std::pair BufferView::update(Update::flags flags) // Check needed to survive LyX startup if (!buffer_) - return make_pair(false, false); + return false; if (lyxerr.debugging(Debug::WORKAREA)) { lyxerr[Debug::WORKAREA] << "BufferView::update" << std::endl; @@ -363,16 +363,16 @@ std::pair BufferView::update(Update::flags flags) // Case when no explicit update is requested. if (!flags) { - // no need to do anything. - return make_pair(false, false); + // no need to redraw anything. + return false; } if (flags == Update::FitCursor) { bool const fit_cursor = fitCursor(); if (fit_cursor) updateMetrics(false); - // tell the frontend to update the screen. - return make_pair(fit_cursor, false); + // tell the frontend to update the screen if needed. + return fit_cursor; } bool full_metrics = flags & Update::Force; @@ -386,7 +386,7 @@ std::pair BufferView::update(Update::flags flags) updateMetrics(false); // tell the frontend to update the screen. - return make_pair(true, single_par); + return true; } @@ -1027,7 +1027,7 @@ void BufferView::workAreaResize(int width, int height) } -std::pair BufferView::workAreaDispatch(FuncRequest const & cmd0) +bool BufferView::workAreaDispatch(FuncRequest const & cmd0) { //lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl; @@ -1037,7 +1037,7 @@ std::pair BufferView::workAreaDispatch(FuncRequest const & cmd0) // E.g. Qt mouse press when no buffer if (!buffer_) - return make_pair(false, false); + return false; LCursor cur(*this); cur.push(buffer_->inset()); @@ -1055,27 +1055,53 @@ std::pair BufferView::workAreaDispatch(FuncRequest const & cmd0) //lyxerr << BOOST_CURRENT_FUNCTION // << " * created temp cursor:" << cur << endl; - // NOTE: eidtXY returns the top level inset of nested insets. If you happen + // NOTE: editXY 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. + // FIXME (abdel 07/12/06): I don't think the static solution will work in + // a multiple BufferView context. static InsetBase * last_inset = NULL; if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) { - bool need_update = false; + bool need_redraw = false; if (inset != last_inset) { if (last_inset) - need_update |= last_inset->setMouseHover(false); + need_redraw |= last_inset->setMouseHover(false); if (inset) - need_update |= inset->setMouseHover(true); + need_redraw |= inset->setMouseHover(true); last_inset = inset; } - // if in singlepar mode, update to get a full screen repaint. - // otherwise, buttons outside of the current paragraph will not be redrawn. - if (need_update && metrics_info_.singlepar) - update(); + + // if last metrics update was in singlepar mode, WorkArea::redraw() will + // not expose the button for redraw. We adjust here the metrics dimension + // to enable a full redraw. + // FIXME: It is possible to redraw only the area around the button! + if (need_redraw && metrics_info_.singlepar) { + // FIXME: It should be possible to redraw only the area around + // the button by doing this: + // + //metrics_info_.singlepar = false; + //metrics_info_.y1 = ymin of button; + //metrics_info_.y2 = ymax of button; + // + // Unfortunately, rowpainter.C:paintText() does not distinguish + // between background updates and text updates. So we use the hammer + // solution for now. We could also avoid the updateMetrics() below + // by using the first and last pit of the CoordCache. Have a look + // at LyXText::getPitNearY() to see what I mean. + // + //metrics_info_.pit1 = first pit of CoordCache; + //metrics_info_.pit2 = last pit of CoordCache; + //metrics_info_.singlepar = false; + //metrics_info_.y1 = 0; + //metrics_info_.y2 = height_; + // + updateMetrics(false); + } + // This event (moving without mouse click) is not passed further. // This should be changed if it is further utilized. - return make_pair(need_update, need_update); + return need_redraw; } // Put anchor at the same position. @@ -1098,8 +1124,7 @@ std::pair BufferView::workAreaDispatch(FuncRequest const & cmd0) if (cur.result().dispatched() && cur.result().update()) return update(cur.result().update()); - // When the above and the inner function are fixed, we can do this: - return make_pair(false, false); + return false; } diff --git a/src/BufferView.h b/src/BufferView.h index 514534739b..4b69b7968d 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -95,16 +95,13 @@ public: /// load a buffer into the view. bool loadLyXFile(support::FileName const & name, bool tolastfiles = true); - /// perform pending painting updates. - /** \c fitcursor means first - * to do a fitcursor, and to force an update if screen - * position changes. \c forceupdate means to force an update - * in any case. - * \retval (false, xxx) if no redraw is required - * \retval (true, true) if a single paragraph redraw is needed - * \retval (true, false) if a full redraw is needed + /// perform pending metrics updates. + /** \c Update::FitCursor means first to do a FitCursor, and to + * force an update if screen position changes. + * \c Update::Force means to force an update in any case. + * \retval true if a screen redraw is needed */ - std::pair update(Update::flags flags = Update::FitCursor | Update::Force); + bool update(Update::flags flags = Update::FitCursor | Update::Force); /// move the screen to fit the cursor. /// Only to be called with good y coordinates (after a bv::metrics) @@ -172,10 +169,8 @@ public: /// dispatch method helper for \c WorkArea /// \sa WorkArea - /// \retval (false, xxx) if no redraw is required - /// \retval (true, true) if a single paragraph redraw is needed - /// \retval (true, false) if a full redraw is needed - std::pair workAreaDispatch(FuncRequest const & ev); + /// \retval true if a redraw is needed + bool workAreaDispatch(FuncRequest const & ev); /// access to anchor. pit_type anchor_ref() const; diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index cc9455c599..8b8cad2a9f 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -195,7 +195,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0) theLyXFunc().setLyXView(&lyx_view_); - std::pair needRedraw = buffer_view_->workAreaDispatch(cmd0); + bool needRedraw = buffer_view_->workAreaDispatch(cmd0); // Skip these when selecting if (cmd0.action != LFUN_MOUSE_MOTION) { @@ -218,7 +218,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0) toggleCursor(); } - if (needRedraw.first) + if (needRedraw) redraw(); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 2a9f579ae9..147592e729 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1712,15 +1712,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // BufferView::update() updates the ViewMetricsInfo and // also initializes the position cache for all insets in // (at least partially) visible top-level paragraphs. - std::pair needSecondUpdate - = view()->update(updateFlags); - - // Redraw screen unless explicitly told otherwise. - if (needSecondUpdate.first) + // We will redraw the screen only if needed. + if (view()->update(updateFlags)) { // Buffer::changed() signals that a repaint is needed. // The frontend (WorkArea) knows which area to repaint // thanks to the ViewMetricsInfo updated above. view()->buffer()->changed(); + } lyx_view_->updateStatusBar();