From 760829360dc0aba810bd40b456237d5c4a3d056a Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 9 Oct 2003 23:14:30 +0000 Subject: [PATCH] Towards saner generation of previews code. Yeah, I know. I wrote it in the first place. I was younger then. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7888 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/graphics/ChangeLog | 5 +++++ src/graphics/PreviewedInset.C | 11 +---------- src/graphics/PreviewedInset.h | 2 +- src/insets/ChangeLog | 5 +++++ src/insets/insetinclude.C | 7 ++----- src/mathed/ChangeLog | 8 ++++++++ src/mathed/formula.C | 30 +++++++++++++++++++----------- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 9841e1049e..9c1da815dd 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,8 @@ +2003-10-09 Angus Leeming + + * PreviewedInset.[Ch] (previewReady): remove the side effects. + Now simply reports whether the preview is ready. + 2003-10-09 Angus Leeming * PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics. diff --git a/src/graphics/PreviewedInset.C b/src/graphics/PreviewedInset.C index 39a078cf8e..8056a1b82c 100644 --- a/src/graphics/PreviewedInset.C +++ b/src/graphics/PreviewedInset.C @@ -91,17 +91,8 @@ void PreviewedInset::removePreview(Buffer const & buffer) } -bool PreviewedInset::previewReady(Buffer const & buffer) const +bool PreviewedInset::previewReady() const { - if (!activated() || !previewWanted(buffer)) - return false; - - if (!pimage_ || snippet_ != pimage_->snippet()) { - graphics::PreviewLoader & ploader = - graphics::Previews::get().loader(buffer); - pimage_ = ploader.preview(snippet_); - } - return pimage_ ? pimage_->image() : false; } diff --git a/src/graphics/PreviewedInset.h b/src/graphics/PreviewedInset.h index ee05138b63..4fbc2b79d1 100644 --- a/src/graphics/PreviewedInset.h +++ b/src/graphics/PreviewedInset.h @@ -57,7 +57,7 @@ public: void removePreview(Buffer const &); /// The preview has been generated and is ready to use. - bool previewReady(Buffer const &) const; + bool previewReady() const; /// If the preview is not ready, returns 0. lyx::graphics::PreviewImage const * const pimage() const { return pimage_; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 32ebf45e50..39d15f35af 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-10-09 Angus Leeming + + * insetinclude.C (metrics, draw): no longer need to pass a Buffer arg + to PreviewedInset::previewReady. + 2003-10-09 Angus Leeming * insetexternal.[Ch] (statusChanged): diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 24e75ddfc7..ea2a1e902d 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -539,8 +539,7 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer, void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const { - Buffer const * buffer_ptr = mi.base.bv ? mi.base.bv->buffer() : 0; - if (buffer_ptr && preview_->previewReady(*buffer_ptr)) { + if (preview_->previewReady()) { dim.asc = preview_->pimage()->ascent(); dim.des = preview_->pimage()->descent(); dim.wid = preview_->pimage()->width(); @@ -565,10 +564,8 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const void InsetInclude::draw(PainterInfo & pi, int x, int y) const { cache(pi.base.bv); - Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0; - bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr); - if (!use_preview) { + if (!preview_->previewReady()) { button_.draw(pi, x + button_.box().x1, y); return; } diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index eecd49f19c..7daeff64dc 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,11 @@ +2003-10-09 Angus Leeming + + * formula.C (metrics, draw): no longer need to pass a Buffer arg + to PreviewedInset::previewReady because it no longer has the side + effect of secretly starting preview generation. + (draw): call PreviewedInset::generatePreview explicitly if the + inset is no longer being edited. + 2003-10-09 Angus Leeming * formula.[Ch]: mods to PreviewImpl due to the changes to diff --git a/src/mathed/formula.C b/src/mathed/formula.C index e739e16d7b..84ec914000 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -193,11 +193,18 @@ void InsetFormula::read(Buffer const &, LyXLex & lex) void InsetFormula::draw(PainterInfo & pi, int x, int y) const { - cache(pi.base.bv); - // This initiates the loading of the preview, so should come - // before the metrics are computed. - Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0; - bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr); + BufferView * bv = pi.base.bv; + cache(bv); + + // The previews are drawn only when we're not editing the inset. + bool const editing_inset = mathcursor && mathcursor->formula() == this; + bool const use_preview = !editing_inset && preview_->previewReady(); + + if (!editing_inset && bv) { + Buffer const * buffer_ptr = bv->buffer(); + if (buffer_ptr) + preview_->generatePreview(*buffer_ptr); + } int const w = dim_.wid; int const d = dim_.des; @@ -208,7 +215,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const pi.pain.image(x + 1, y - a, w, h, // one pixel gap in front *(preview_->pimage()->image())); } else { - PainterInfo p(pi.base.bv); + PainterInfo p(bv); p.base.style = LM_ST_TEXT; p.base.font = pi.base.font; p.base.font.setColor(LColor::math); @@ -216,9 +223,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const != lcolor.getX11Name(LColor::background)) p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg); - if (mathcursor && - const_cast(mathcursor->formula()) == this) - { + if (editing_inset) { mathcursor->drawSelection(pi); //p.pain.rectangle(x, y - a, w, h, LColor::mathframe); } @@ -262,8 +267,11 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const { view_ = m.base.bv; - Buffer const * buffer_ptr = m.base.bv ? m.base.bv->buffer() : 0; - if (buffer_ptr && preview_->previewReady(*buffer_ptr)) { + + bool const editing_inset = mathcursor && mathcursor->formula() == this; + bool const use_preview = !editing_inset && preview_->previewReady(); + + if (use_preview) { dim.asc = preview_->pimage()->ascent(); dim.des = preview_->pimage()->descent(); // insert a one pixel gap in front of the formula -- 2.39.5