From f84080f01c46ece104796746e9e914d205c286cd Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 6 Nov 2007 08:32:25 +0000 Subject: [PATCH] * Bufferview::updateMetrics(): Separate out the SinglePar optimization. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21463 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 29 +++++++++++++---------------- src/BufferView.h | 3 +-- src/frontends/WorkArea.cpp | 2 +- src/frontends/qt4/GuiParagraph.cpp | 2 +- src/frontends/qt4/GuiView.cpp | 2 +- src/frontends/qt4/GuiWorkArea.cpp | 6 +++--- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 5275791927..2cf95fdf1f 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -532,7 +532,7 @@ void BufferView::processUpdateFlags(Update::flags flags) bool const fit_cursor = fitCursor(); // tell the frontend to update the screen if needed. if (fit_cursor) { - updateMetrics(false); + updateMetrics(); buffer_.changed(); return; } @@ -550,8 +550,9 @@ void BufferView::processUpdateFlags(Update::flags flags) if (flags & Update::MultiParSel) full_metrics |= multiParSel(); - bool const single_par = !full_metrics; - updateMetrics(single_par); + if (full_metrics || singleParUpdate()) + // We have to update the full screen metrics. + updateMetrics(); if (!(flags & Update::FitCursor)) { buffer_.changed(); @@ -569,7 +570,7 @@ void BufferView::processUpdateFlags(Update::flags flags) // The screen has been recentered around the cursor position so // refresh it: - updateMetrics(false); + updateMetrics(); buffer_.changed(); } @@ -653,7 +654,7 @@ void BufferView::scrollDocView(int value) tm.redoParagraph(d->anchor_ref_); int const h = tm.parMetrics(d->anchor_ref_).height(); d->offset_ref_ = int((bar * t.paragraphs().size() - d->anchor_ref_) * h); - updateMetrics(false); + updateMetrics(); buffer_.changed(); } @@ -1345,7 +1346,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) if (p.y_ < 0 || p.y_ > height_) { // The cursor is off-screen so recenter before proceeding. center(); - updateMetrics(false); + updateMetrics(); //FIXME: updateMetrics() does not update paragraph position // This is done at draw() time. So we need a redraw! buffer_.changed(); @@ -1430,7 +1431,7 @@ void BufferView::resize(int width, int height) width_ = width; height_ = height; - updateMetrics(false); + updateMetrics(); } @@ -1584,7 +1585,7 @@ void BufferView::scrollDown(int offset) tm.newParMetricsDown(); } d->offset_ref_ += offset; - updateMetrics(false); + updateMetrics(); buffer_.changed(); } @@ -1608,7 +1609,7 @@ void BufferView::scrollUp(int offset) tm.newParMetricsUp(); } d->offset_ref_ -= offset; - updateMetrics(false); + updateMetrics(); buffer_.changed(); } @@ -1701,7 +1702,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old) updateLabels(buffer_); - updateMetrics(false); + updateMetrics(); buffer_.changed(); return true; } @@ -1837,12 +1838,8 @@ bool BufferView::singleParUpdate() } -void BufferView::updateMetrics(bool singlepar) +void BufferView::updateMetrics() { - if (singlepar && singleParUpdate()) - // No need to update the full screen metrics. - return; - Text & buftext = buffer_.text(); pit_type const npit = int(buftext.paragraphs().size()); @@ -1993,7 +1990,7 @@ void BufferView::menuInsertLyXFile(string const & filenm) // emit message signal. message(bformat(res, disp_fn)); buffer_.errors("Parse"); - updateMetrics(false); + updateMetrics(); } diff --git a/src/BufferView.h b/src/BufferView.h index 16cbcd7aa2..b553f26f83 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -201,8 +201,7 @@ public: /// \sa ViewMetricsInfo ViewMetricsInfo const & viewMetricsInfo(); /// update the internal \c ViewMetricsInfo. - /// \param singlepar indicates wether - void updateMetrics(bool singlepar = false); + void updateMetrics(); /// TextMetrics const & textMetrics(Text const * t) const; diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index c3abe443b2..06f22e096b 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -131,7 +131,7 @@ void WorkArea::redraw() // metrics are already up to date. if (lyx_view_ != theApp()->currentView()) { // FIXME: it would be nice to optimize for the off-screen case. - buffer_view_->updateMetrics(false); + buffer_view_->updateMetrics(); buffer_view_->cursor().fixIfBroken(); } diff --git a/src/frontends/qt4/GuiParagraph.cpp b/src/frontends/qt4/GuiParagraph.cpp index 29b7e8c816..9e26f5cc2a 100644 --- a/src/frontends/qt4/GuiParagraph.cpp +++ b/src/frontends/qt4/GuiParagraph.cpp @@ -297,7 +297,7 @@ void GuiParagraph::dispatchParams() return; } - bufferview()->updateMetrics(false); + bufferview()->updateMetrics(); bufferview()->buffer().changed(); } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index bf924837a9..f58e7be789 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -810,7 +810,7 @@ WorkArea * GuiView::addWorkArea(Buffer & buffer) GuiWorkArea * wa = new GuiWorkArea(buffer, *this); wa->setUpdatesEnabled(false); d.tab_widget_->addTab(wa, toqstr(buffer.fileName().displayName(30))); - wa->bufferView().updateMetrics(false); + wa->bufferView().updateMetrics(); if (d.stack_widget_) d.stack_widget_->setCurrentWidget(d.tab_widget_); // Hide tabbar if there's only one tab. diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 9b55e9173f..4e6eaf160a 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -507,7 +507,7 @@ void GuiWorkArea::updateScreen() void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape) { if (schedule_redraw_) { - buffer_view_->updateMetrics(false); + buffer_view_->updateMetrics(); updateScreen(); viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height())); schedule_redraw_ = false; @@ -568,7 +568,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e) } GuiPainter pain(&screen_); - buffer_view_->updateMetrics(false); + buffer_view_->updateMetrics(); buffer_view_->draw(pain); FontInfo font = buffer_view_->cursor().getFont().fontInfo(); FontMetrics const & fm = theFontMetrics(font); @@ -809,7 +809,7 @@ void TabWorkArea::on_currentTabChanged(int i) GuiWorkArea * wa = dynamic_cast(widget(i)); BOOST_ASSERT(wa); BufferView & bv = wa->bufferView(); - bv.updateMetrics(false); + bv.updateMetrics(); bv.cursor().fixIfBroken(); wa->setUpdatesEnabled(true); wa->redraw(); -- 2.39.2