From 93f7adabbb85af4bcf09fd70c5a2ffe5305d1db8 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 14 Jul 2006 09:56:21 +0000 Subject: [PATCH] This commit removes the needRedraw() interface and simplify the screen update procedure. It also fixes all crash problems. The performance may suffer a bit because we do the second drawing step in all cases. This could be possibly optimized out by checking the return value of the BufferView::update() method in "lyxfunc.C:1610". But it is maybe better to keep those two parts of the frontend ignorant of each other: the event handling and the drawing. BufferView: * needRedra(), need_redraw_: deleted. * updateMetrics(): now public. * update(): only do the first drawing step. Returns true if a full updateMetrics is needed before drawing on screen. WorkArea: * redraw(): no check on BufferView::needRedraw(), call updateMetrics() unconditionally. * processKeySim(): uneeded "redraw()" call commented out. When/if the call to LyXView::redrawWorkArea() in "lyxfunc.C:1610" is not needed anymore, this line should be uncommented out. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14456 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 14 ++++---------- src/BufferView.h | 8 ++++---- src/BufferView_pimpl.C | 31 ++++++++++--------------------- src/BufferView_pimpl.h | 16 +++------------- src/frontends/WorkArea.C | 11 ++++++----- 5 files changed, 27 insertions(+), 53 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index b4b4cb1a1f..86e1729681 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -129,9 +129,9 @@ bool BufferView::fitCursor() } -void BufferView::update(Update::flags flags) +bool BufferView::update(Update::flags flags) { - pimpl_->update(flags); + return pimpl_->update(flags); } @@ -404,13 +404,7 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo() } -bool BufferView::needsRedraw() const +void BufferView::updateMetrics(bool singlepar) { - return pimpl_->needsRedraw(); -} - - -void BufferView::needsRedraw(bool redraw_needed) -{ - pimpl_->needsRedraw(redraw_needed); + pimpl_->updateMetrics(singlepar); } diff --git a/src/BufferView.h b/src/BufferView.h index 3f8ff3eab0..c8f833496b 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -116,9 +116,10 @@ public: * to do a fitcursor, and to force an update if screen * position changes. \c forceupdate means to force an update * in any case. + * \return true if a full updateMetrics() is needed. */ + bool update(Update::flags flags = Update::FitCursor | Update::Force); - void 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) bool fitCursor(); @@ -223,10 +224,9 @@ public: int length, bool backwards); /// ViewMetricsInfo const & viewMetricsInfo(); - /// - bool needsRedraw() const; - void needsRedraw(bool redraw_needed); + void updateMetrics(bool singlepar = false); + private: /// class Pimpl; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 7ba4368d13..43c9c918f2 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -128,7 +128,7 @@ T * getInsetByCode(LCursor & cur, InsetBase::Code code) BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner) : bv_(&bv), owner_(owner), buffer_(0), wh_(0), cursor_(bv), - multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0), needs_redraw_(false) + multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0) { xsel_cache_.set = false; @@ -652,7 +652,7 @@ ViewMetricsInfo const & BufferView::Pimpl::viewMetricsInfo() } -void BufferView::Pimpl::update(Update::flags flags) +bool BufferView::Pimpl::update(Update::flags flags) { // This is close to a hot-path. if (lyxerr.debugging(Debug::DEBUG)) { @@ -666,31 +666,20 @@ void BufferView::Pimpl::update(Update::flags flags) // Check needed to survive LyX startup if (!buffer_) - return; - - // Check if there is already a redraw waiting in the queue. - if (needs_redraw_) - return; + return false; // Update macro store buffer_->buildMacros(); // First drawing step - bool singlePar = flags & Update::SinglePar; - needs_redraw_ = (flags & (Update::Force | Update::SinglePar)); - - updateMetrics(singlePar); + updateMetrics(flags & Update::SinglePar); - if ((flags & (Update::FitCursor | Update::MultiParSel)) - && (fitCursor() || multiParSel())) { - needs_redraw_ = true; - singlePar = false; - } - - if (needs_redraw_) { - // Second drawing step - updateMetrics(singlePar); - } + // The second drawing step is done in WorkArea::redraw() if needed. + bool const need_second_step = + (flags & (Update::Force | Update::FitCursor | Update::MultiParSel)) + && (fitCursor() || multiParSel()); + + return need_second_step; } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index ca9c78c215..5d645cf029 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -58,7 +58,7 @@ public: // bool multiParSel(); /// - void update(Update::flags flags = Update::Force); + bool update(Update::flags flags = Update::Force); /// load a buffer into the view bool loadLyXFile(std::string const &, bool); /// @@ -117,14 +117,8 @@ public: /// ViewMetricsInfo const & viewMetricsInfo(); /// - bool needsRedraw() const - { - return needs_redraw_; - } - void needsRedraw(bool redraw_needed) - { - needs_redraw_ = redraw_needed; - } + void updateMetrics(bool singlepar = false); + private: /// int width_; @@ -132,8 +126,6 @@ private: int height_; /// ScrollbarParameters scrollbarParameters_; - /// - bool needs_redraw_; /// An error list (replaces the error insets) ErrorList errorlist_; @@ -164,8 +156,6 @@ private: /// ViewMetricsInfo metrics_info_; - /// - void updateMetrics(bool singlepar = false); /// friend class BufferView; diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 0ff8fb4f82..1f925795af 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -189,9 +189,7 @@ void WorkArea::redraw() return; } - if (!buffer_view_->needsRedraw()) - return; - + buffer_view_->updateMetrics(false); ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo(); greyed_out_ = false; getPainter().start(); @@ -202,7 +200,6 @@ void WorkArea::redraw() ( vi.p2 < vi.size - 1 ? vi.y2 : height() ); expose(0, ymin, width(), ymax - ymin); getPainter().end(); - buffer_view_->needsRedraw(false); lyxerr[Debug::DEBUG] << " ymin = " << ymin << " width() = " << width() @@ -225,7 +222,11 @@ void WorkArea::processKeySym(LyXKeySymPtr key, */ // if (buffer_view_->available()) toggleCursor(); - redraw(); + + // uneeded "redraw()" call commented out for now. + // When/if the call to LyXView::redrawWorkArea() in "lyxfunc.C:1610" + // is not needed anymore, this line should be uncommented out + //redraw(); } -- 2.39.2