Add a boolean to GuiWorkArea::redraw to indicate whether the metrics must be updated. The current test "lyx_view_ != guiApp->currentView() || lyx_view_->currentWorkArea() != this" is not enough, especially not if the buffer is changed and buffer->changed() is called. Moreover, there are a lot of combinations of updateMetrics() followed by buffer->changed(), these can now be replaced by one call to buffer->changed(bool).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32874 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-01-08 02:03:54 +00:00
parent 41270b98b4
commit 570f96bc6e
13 changed files with 33 additions and 44 deletions

View File

@ -392,10 +392,10 @@ bool Buffer::isClone() const
}
void Buffer::changed() const
void Buffer::changed(bool update_metrics) const
{
if (d->wa_)
d->wa_->redrawAll();
d->wa_->redrawAll(update_metrics);
}

View File

@ -470,7 +470,7 @@ public:
Undo & undo();
/// This function is called when the buffer is changed.
void changed() const;
void changed(bool update_metrics) const;
///
void updateTocItem(std::string const &, DocIterator const &) const;
/// This function is called when the buffer structure is changed.

View File

@ -336,16 +336,16 @@ bool BufferList::releaseChild(Buffer * parent, Buffer * child)
}
void BufferList::changed() const
void BufferList::changed(bool update_metrics) const
{
BufferStorage::const_iterator it = bstore.begin();
BufferStorage::const_iterator end = bstore.end();
for (; it != end; ++it)
(*it)->changed();
(*it)->changed(update_metrics);
it = binternal.begin();
end = binternal.end();
for (; it != end; ++it)
(*it)->changed();
(*it)->changed(update_metrics);
}

View File

@ -109,7 +109,7 @@ public:
void setCurrentAuthor(docstring const & name, docstring const & email);
/// Call changed() on all buffers, internal or not
void changed() const;
void changed(bool update_metrics) const;
private:
/// noncopiable

View File

@ -424,7 +424,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
if (flags == Update::Decoration) {
d->update_strategy_ = DecorationUpdate;
buffer_.changed();
buffer_.changed(false);
return;
}
@ -437,7 +437,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
}
if (flags & Update::Decoration) {
d->update_strategy_ = DecorationUpdate;
buffer_.changed();
buffer_.changed(false);
return;
}
// no screen update is needed.
@ -453,13 +453,13 @@ void BufferView::processUpdateFlags(Update::flags flags)
if (!(flags & Update::FitCursor)) {
// Nothing to do anymore. Trigger a redraw and return
buffer_.changed();
buffer_.changed(false);
return;
}
// updateMetrics() does not update paragraph position
// This is done at draw() time. So we need a redraw!
buffer_.changed();
buffer_.changed(false);
if (fitCursor()) {
// The cursor is off screen so ensure it is visible.
@ -573,8 +573,7 @@ void BufferView::scrollDocView(int value)
// If the offset is less than 2 screen height, prefer to scroll instead.
if (abs(offset) <= 2 * height_) {
d->anchor_ypos_ -= offset;
updateMetrics();
buffer_.changed();
buffer_.changed(true);
return;
}
@ -765,7 +764,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
// To center the screen on this new position we need the
// paragraph position which is computed at draw() time.
// So we need a redraw!
buffer_.changed();
buffer_.changed(false);
if (fitCursor())
showCursor();
}
@ -811,7 +810,7 @@ void BufferView::showCursor()
void BufferView::showCursor(DocIterator const & dit, bool recenter)
{
if (scrollToCursor(dit, recenter))
buffer_.changed();
buffer_.changed(false);
}
@ -1675,8 +1674,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
Cursor old = cur;
bool const in_texted = cur.inTexted();
cur.reset();
updateMetrics();
buffer_.changed();
buffer_.changed(true);
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
true, cmd.action == LFUN_SCREEN_UP);
//FIXME: what to do with cur.x_target()?
@ -1939,7 +1937,7 @@ void BufferView::clearSelection()
d->xsel_cache_.set = false;
// The buffer did not really change, but this causes the
// redraw we need because we cleared the selection above.
buffer_.changed();
buffer_.changed(false);
}
@ -2034,7 +2032,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
// This event (moving without mouse click) is not passed further.
// This should be changed if it is further utilized.
buffer_.changed();
buffer_.changed(false);
return;
}
@ -2095,8 +2093,7 @@ void BufferView::lfunScroll(FuncRequest const & cmd)
if (scroll_value)
scroll(scroll_step * scroll_value);
}
updateMetrics();
buffer_.changed();
buffer_.changed(true);
}
@ -2282,9 +2279,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
d->cursor_ = cur;
buffer_.updateLabels();
updateMetrics();
buffer_.changed();
buffer_.changed(true);
return true;
}
@ -2518,8 +2513,7 @@ void BufferView::insertLyXFile(FileName const & fname)
res = _("Could not insert document %1$s");
}
updateMetrics();
buffer_.changed();
buffer_.changed(true);
// emit message signal.
message(bformat(res, disp_fn));
buffer_.errors("Parse");
@ -2826,8 +2820,7 @@ void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
else
cur.innerText()->insertStringAsLines(cur, tmpstr, cur.current_font);
updateMetrics();
buffer_.changed();
buffer_.changed(true);
}

View File

@ -38,7 +38,7 @@ public:
virtual ~WorkArea() {}
/// redraw the screen, without using existing pixmap
virtual void redraw() = 0;
virtual void redraw(bool update_metrics) = 0;
/// close this work area.
/// Slot for Buffer::closing signal.

View File

@ -31,10 +31,10 @@ void WorkAreaManager::remove(WorkArea * wa)
}
void WorkAreaManager::redrawAll()
void WorkAreaManager::redrawAll(bool update_metrics)
{
for (iterator it = work_areas_.begin(); it != work_areas_.end(); ++it)
(*it)->redraw();
(*it)->redraw(update_metrics);
}

View File

@ -35,7 +35,7 @@ public:
///
void remove(WorkArea * wa);
///
void redrawAll();
void redrawAll(bool update_metrics);
///
void closeAll();
/// This function is called when the buffer readonly status change.

View File

@ -949,7 +949,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
// Set current_view_ to zero to forbid GuiWorkArea::redraw()
// to skip the refresh.
current_view_ = 0;
theBufferList().changed();
theBufferList().changed(false);
// Restore current_view_
current_view_ = view;
break;

View File

@ -286,7 +286,7 @@ int GuiCompare::run()
if (!new_buffer_ || !old_buffer_ || !dest_buffer_)
return 0;
dest_buffer_->changed();
dest_buffer_->changed(true);
dest_buffer_->markDirty();
// get the options from the dialog

View File

@ -100,8 +100,7 @@ void GuiInfo::applyView()
// FIXME: update the inset contents
bufferview()->buffer().updateLabels();
BufferView * bv = const_cast<BufferView *>(bufferview());
bv->updateMetrics();
bv->buffer().changed();
bv->buffer().changed(true);
bv->buffer().markDirty();
}

View File

@ -406,7 +406,7 @@ void GuiWorkArea::startBlinkingCursor()
}
void GuiWorkArea::redraw()
void GuiWorkArea::redraw(bool update_metrics)
{
if (!isVisible())
// No need to redraw in this case.
@ -414,7 +414,7 @@ void GuiWorkArea::redraw()
// No need to do anything if this is the current view. The BufferView
// metrics are already up to date.
if (lyx_view_ != guiApp->currentView()
if (update_metrics || lyx_view_ != guiApp->currentView()
|| lyx_view_->currentWorkArea() != this) {
// FIXME: it would be nice to optimize for the off-screen case.
buffer_view_->updateMetrics();
@ -1503,17 +1503,14 @@ void TabWorkArea::on_currentTabChanged(int i)
return;
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
LASSERT(wa, return);
BufferView & bv = wa->bufferView();
bv.cursor().fixIfBroken();
bv.updateMetrics();
wa->setUpdatesEnabled(true);
wa->redraw();
wa->redraw(true);
wa->setFocus();
///
currentWorkAreaChanged(wa);
LYXERR(Debug::GUI, "currentTabChanged " << i
<< "File" << bv.buffer().absFileName());
<< "File" << wa->bufferView().buffer().absFileName());
}

View File

@ -126,7 +126,7 @@ public:
///
BufferView const & bufferView() const;
///
void redraw();
void redraw(bool update_metrics);
///
void stopBlinkingCursor();
///