* BufferView:

- update(): return bool only, and cleanup of the DOX comments.
  - workAreaDispatch(): return bool only, cleanup of the DOX comments, change update() call to updateMetrics() and add some FIXMEs.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16197 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-12-07 11:46:27 +00:00
parent 9295b6e6c8
commit 5ce7ae1883
4 changed files with 58 additions and 40 deletions

View File

@ -334,7 +334,7 @@ bool BufferView::multiParSel()
} }
std::pair<bool, bool> BufferView::update(Update::flags flags) bool BufferView::update(Update::flags flags)
{ {
// This is close to a hot-path. // This is close to a hot-path.
if (lyxerr.debugging(Debug::DEBUG)) { if (lyxerr.debugging(Debug::DEBUG)) {
@ -348,7 +348,7 @@ std::pair<bool, bool> BufferView::update(Update::flags flags)
// Check needed to survive LyX startup // Check needed to survive LyX startup
if (!buffer_) if (!buffer_)
return make_pair(false, false); return false;
if (lyxerr.debugging(Debug::WORKAREA)) { if (lyxerr.debugging(Debug::WORKAREA)) {
lyxerr[Debug::WORKAREA] << "BufferView::update" << std::endl; lyxerr[Debug::WORKAREA] << "BufferView::update" << std::endl;
@ -363,16 +363,16 @@ std::pair<bool, bool> BufferView::update(Update::flags flags)
// Case when no explicit update is requested. // Case when no explicit update is requested.
if (!flags) { if (!flags) {
// no need to do anything. // no need to redraw anything.
return make_pair(false, false); return false;
} }
if (flags == Update::FitCursor) { if (flags == Update::FitCursor) {
bool const fit_cursor = fitCursor(); bool const fit_cursor = fitCursor();
if (fit_cursor) if (fit_cursor)
updateMetrics(false); updateMetrics(false);
// tell the frontend to update the screen. // tell the frontend to update the screen if needed.
return make_pair(fit_cursor, false); return fit_cursor;
} }
bool full_metrics = flags & Update::Force; bool full_metrics = flags & Update::Force;
@ -386,7 +386,7 @@ std::pair<bool, bool> BufferView::update(Update::flags flags)
updateMetrics(false); updateMetrics(false);
// tell the frontend to update the screen. // 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<bool, bool> BufferView::workAreaDispatch(FuncRequest const & cmd0) bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
{ {
//lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl; //lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
@ -1037,7 +1037,7 @@ std::pair<bool, bool> BufferView::workAreaDispatch(FuncRequest const & cmd0)
// E.g. Qt mouse press when no buffer // E.g. Qt mouse press when no buffer
if (!buffer_) if (!buffer_)
return make_pair(false, false); return false;
LCursor cur(*this); LCursor cur(*this);
cur.push(buffer_->inset()); cur.push(buffer_->inset());
@ -1055,27 +1055,53 @@ std::pair<bool, bool> BufferView::workAreaDispatch(FuncRequest const & cmd0)
//lyxerr << BOOST_CURRENT_FUNCTION //lyxerr << BOOST_CURRENT_FUNCTION
// << " * created temp cursor:" << cur << endl; // << " * 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 // 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. // 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; static InsetBase * last_inset = NULL;
if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) { if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
bool need_update = false; bool need_redraw = false;
if (inset != last_inset) { if (inset != last_inset) {
if (last_inset) if (last_inset)
need_update |= last_inset->setMouseHover(false); need_redraw |= last_inset->setMouseHover(false);
if (inset) if (inset)
need_update |= inset->setMouseHover(true); need_redraw |= inset->setMouseHover(true);
last_inset = inset; 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 last metrics update was in singlepar mode, WorkArea::redraw() will
if (need_update && metrics_info_.singlepar) // not expose the button for redraw. We adjust here the metrics dimension
update(); // 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 event (moving without mouse click) is not passed further.
// This should be changed if it is further utilized. // 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. // Put anchor at the same position.
@ -1098,8 +1124,7 @@ std::pair<bool, bool> BufferView::workAreaDispatch(FuncRequest const & cmd0)
if (cur.result().dispatched() && cur.result().update()) if (cur.result().dispatched() && cur.result().update())
return update(cur.result().update()); return update(cur.result().update());
// When the above and the inner function are fixed, we can do this: return false;
return make_pair(false, false);
} }

View File

@ -95,16 +95,13 @@ public:
/// load a buffer into the view. /// load a buffer into the view.
bool loadLyXFile(support::FileName const & name, bool tolastfiles = true); bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
/// perform pending painting updates. /// perform pending metrics updates.
/** \c fitcursor means first /** \c Update::FitCursor means first to do a FitCursor, and to
* to do a fitcursor, and to force an update if screen * force an update if screen position changes.
* position changes. \c forceupdate means to force an update * \c Update::Force means to force an update in any case.
* in any case. * \retval true if a screen redraw is needed
* \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<bool, bool> update(Update::flags flags = Update::FitCursor | Update::Force); bool update(Update::flags flags = Update::FitCursor | Update::Force);
/// move the screen to fit the cursor. /// move the screen to fit the cursor.
/// Only to be called with good y coordinates (after a bv::metrics) /// Only to be called with good y coordinates (after a bv::metrics)
@ -172,10 +169,8 @@ public:
/// dispatch method helper for \c WorkArea /// dispatch method helper for \c WorkArea
/// \sa WorkArea /// \sa WorkArea
/// \retval (false, xxx) if no redraw is required /// \retval true if a redraw is needed
/// \retval (true, true) if a single paragraph redraw is needed bool workAreaDispatch(FuncRequest const & ev);
/// \retval (true, false) if a full redraw is needed
std::pair<bool, bool> workAreaDispatch(FuncRequest const & ev);
/// access to anchor. /// access to anchor.
pit_type anchor_ref() const; pit_type anchor_ref() const;

View File

@ -195,7 +195,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0)
theLyXFunc().setLyXView(&lyx_view_); theLyXFunc().setLyXView(&lyx_view_);
std::pair<bool, bool> needRedraw = buffer_view_->workAreaDispatch(cmd0); bool needRedraw = buffer_view_->workAreaDispatch(cmd0);
// Skip these when selecting // Skip these when selecting
if (cmd0.action != LFUN_MOUSE_MOTION) { if (cmd0.action != LFUN_MOUSE_MOTION) {
@ -218,7 +218,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0)
toggleCursor(); toggleCursor();
} }
if (needRedraw.first) if (needRedraw)
redraw(); redraw();
} }

View File

@ -1712,15 +1712,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// BufferView::update() updates the ViewMetricsInfo and // BufferView::update() updates the ViewMetricsInfo and
// also initializes the position cache for all insets in // also initializes the position cache for all insets in
// (at least partially) visible top-level paragraphs. // (at least partially) visible top-level paragraphs.
std::pair<bool, bool> needSecondUpdate // We will redraw the screen only if needed.
= view()->update(updateFlags); if (view()->update(updateFlags)) {
// Redraw screen unless explicitly told otherwise.
if (needSecondUpdate.first)
// Buffer::changed() signals that a repaint is needed. // Buffer::changed() signals that a repaint is needed.
// The frontend (WorkArea) knows which area to repaint // The frontend (WorkArea) knows which area to repaint
// thanks to the ViewMetricsInfo updated above. // thanks to the ViewMetricsInfo updated above.
view()->buffer()->changed(); view()->buffer()->changed();
}
lyx_view_->updateStatusBar(); lyx_view_->updateStatusBar();