diff --git a/src/BufferView.C b/src/BufferView.C index f1c1834b1c..aba9142877 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -408,3 +408,15 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo() { return pimpl_->viewMetricsInfo(); } + + +bool BufferView::needsRedraw() const +{ + return pimpl_->needsRedraw(); +} + + +void BufferView::needsRedraw(bool redraw_needed) +{ + pimpl_->needsRedraw(redraw_needed); +} diff --git a/src/BufferView.h b/src/BufferView.h index 924637e10c..a967a2fed4 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -226,6 +226,10 @@ public: /// ViewMetricsInfo const & viewMetricsInfo(); + + /// + bool needsRedraw() const; + void needsRedraw(bool redraw_needed); private: /// class Pimpl; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2365d64f11..2fb94a60ad 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -139,7 +139,7 @@ T * getInsetByCode(LCursor & cur, InsetBase::Code code) BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner) : bv_(&bv), owner_(owner), buffer_(0), wh_(0), cursor_timeout(400), using_xterm_cursor(false), cursor_(bv), - multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0) + multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0), needs_redraw_(false) { xsel_cache_.set = false; @@ -699,39 +699,38 @@ void BufferView::Pimpl::update(Update::flags flags) << "] buffer: " << buffer_ << endl; } + // This, together with doneUpdating(), verifies (using + // asserts) that screen redraw is not called from + // within itself. + theCoords.startUpdating(); + // Check needed to survive LyX startup if (buffer_) { // Update macro store buffer_->buildMacros(); - // This, together with doneUpdating(), verifies (using - // asserts) that screen redraw is not called from - // within itself. - theCoords.startUpdating(); - // First drawing step bool singlePar = flags & Update::SinglePar; - bool forceupdate(flags & (Update::Force | Update::SinglePar)); + needs_redraw_ = flags & (Update::Force | Update::SinglePar); if ((flags & (Update::FitCursor | Update::MultiParSel)) && (fitCursor() || multiParSel())) { - forceupdate = true; + needs_redraw_ = true; singlePar = false; } - if (forceupdate) { + if (needs_redraw_) { // Second drawing step updateMetrics(singlePar); - owner_->workArea()->redraw(*bv_); - } else { - // Abort updating of the coord - // cache - just restore the old one - theCoords.doneUpdating(); } - } else - owner_->workArea()->greyOut(); + } + owner_->redrawWorkArea(); owner_->view_state_changed(); + + // Abort updating of the coord + // cache - just restore the old one + theCoords.doneUpdating(); } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index c39e137dc2..6edea86b5a 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -120,6 +120,15 @@ public: /// ViewMetricsInfo const & viewMetricsInfo(); + /// + bool needsRedraw() const + { + return needs_redraw_; + } + void needsRedraw(bool redraw_needed) + { + needs_redraw_ = redraw_needed; + } private: /// int width_; @@ -127,6 +136,8 @@ private: int height_; /// ScrollbarParameters scrollbarParameters_; + /// + bool needs_redraw_; /// An error list (replaces the error insets) ErrorList errorlist_; diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 8581ac2ec3..7cf2a05887 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -81,14 +81,20 @@ LyXView::LyXView(Gui & owner) } +LyXView::~LyXView() +{ +} + + void LyXView::setWorkArea(WorkArea * work_area) { work_area_ = work_area; } -LyXView::~LyXView() +void LyXView::redrawWorkArea() { + work_area_->redraw(); } diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index ef1377a4ed..36245d0f5b 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -153,6 +153,9 @@ public: virtual lyx::frontend::Gui & gui(); lyx::frontend::WorkArea * workArea() const { return work_area_; } + + /// Temporary method used by the kernel to redraw the work area. + virtual void redrawWorkArea(); protected: /// current work area (screen view of a BufferView). /** diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 9abf811b11..debf0005d9 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -155,10 +155,20 @@ void WorkArea::checkAndGreyOut() } -void WorkArea::redraw(BufferView & bv) +void WorkArea::redraw() { + BOOST_ASSERT(buffer_view_); + + if (!buffer_view_->buffer()) { + greyOut(); + return; + } + + if (!buffer_view_->needsRedraw()) + return; + greyed_out_ = false; - ViewMetricsInfo const & vi = bv.viewMetricsInfo(); + ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo(); getPainter().start(); paintText(*buffer_view_, vi); lyxerr[Debug::DEBUG] << "Redraw screen" << endl; @@ -167,7 +177,14 @@ void WorkArea::redraw(BufferView & bv) ( vi.p2 < vi.size - 1 ? vi.y2 : height() ); expose(0, ymin, width(), ymax - ymin); getPainter().end(); - theCoords.doneUpdating(); + //theCoords.doneUpdating(); + buffer_view_->needsRedraw(false); + + if (lyxerr.debugging(Debug::DEBUG)) { + lyxerr[Debug::DEBUG] + << " ymin = " << ymin << " width() = " << width() + << " ymax-ymin = " << ymax-ymin << std::endl; + } } diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index ad55382e60..083bd600df 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -64,7 +64,7 @@ public: virtual void setScrollbarParams(int height, int pos, int line_height) = 0; /// redraw the screen, without using existing pixmap - virtual void redraw(BufferView & bv); + virtual void redraw(); /// grey out (no buffer) void greyOut();