Minimise the use of the BufferView cache. The only things left using it

are InsetFormula, InsetExternal, InsetGraphic and InsetInclude that all
need to inform the BufferView of their changed status when the graphic
is loaded.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7897 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-10-12 18:54:12 +00:00
parent c57b67f24f
commit 122e7616d7
26 changed files with 148 additions and 132 deletions

View File

@ -1,3 +1,29 @@
2003-10-12 Angus Leeming <leeming@lyx.org>
* renderbase.h (view, view_): removed.
* renderbase.C: removed.
* Makefile.am: remove render_base.C. The shortest lived file in history?
* renderbutton.C (draw):
* render_graphic.C (draw): don't cache the BufferView.
* insetabase.h (cache, view): removed.
* inset.h (generatePreview) removed.
* insetcallapsable.[Ch] (cache, view, view_): removed.
* insetcollapsable.C (draw): don't cache the BufferView.
* insetcommand.[Ch] (view): removed.
* insetexternal.[Ch] (cache, view, view_):
* insetgraphics.[Ch] (cache, view, view_):
* insetinclude.[Ch] (cache, view, view_): added. Cache the BufferView.
* insetlabel.C: small clean-up. Don't use the BufferView cache, view(),
when you have direct access to it. In fact, don't use the cache at all.
2003-10-10 Angus Leeming <leeming@lyx.org>
* insetinclude.C (metrics): use preview_->metrics.
@ -43,7 +69,7 @@
* insetinclude.[Ch]: mods to PreviewImpl due to the changes to
PreviewedInset.
2003-10-09 Angus Leeming <leeming@lyx.org>
* insetinclude.C (metrics, draw, restartLoading): pass a buffer arg

View File

@ -19,7 +19,6 @@ libinsets_la_SOURCES = \
ExternalTemplate.h \
ExternalTransforms.C \
ExternalTransforms.h \
render_base.C \
render_base.h \
render_button.C \
render_button.h \

View File

@ -300,15 +300,6 @@ public:
* defaults to empty.
*/
virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
*
* Most insets have no interest in this capability, so the method
* defaults to empty.
*/
virtual void generatePreview(Buffer const &) const {}
protected:
///
mutable int top_x;

View File

@ -95,10 +95,6 @@ public:
/// draw inset and update (xo, yo)-cache
virtual void draw(PainterInfo & pi, int x, int y) const = 0;
/// Methods to cache and retrieve a cached BufferView.
virtual void cache(BufferView *) const {}
///
virtual BufferView * view() const { return 0; }
/// request "external features"
virtual void validate(LaTeXFeatures &) const {}
/// Appends \c list with all labels found within this inset.

View File

@ -138,9 +138,6 @@ void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
{
BOOST_ASSERT(pi.base.bv);
cache(pi.base.bv);
Dimension dim_collapsed;
dimension_collapsed(dim_collapsed);
@ -562,15 +559,3 @@ void InsetCollapsable::addPreview(PreviewLoader & loader) const
{
inset.addPreview(loader);
}
void InsetCollapsable::cache(BufferView * bv) const
{
view_ = bv->owner()->view();
}
BufferView * InsetCollapsable::view() const
{
return view_.lock().get();
}

View File

@ -20,8 +20,6 @@
#include "box.h"
#include "lyxfont.h"
#include <boost/weak_ptr.hpp>
class Painter;
class LyXText;
class Paragraph;
@ -149,11 +147,6 @@ public:
void addPreview(lyx::graphics::PreviewLoader &) const;
protected:
///
virtual void cache(BufferView *) const;
///
virtual BufferView * view() const;
///
void dimension_collapsed(Dimension &) const;
///
@ -197,8 +190,6 @@ private:
bool in_update;
///
mutable bool first_after_edit;
///
mutable boost::weak_ptr<BufferView> view_;
};

View File

@ -33,12 +33,6 @@ InsetCommand::InsetCommand(InsetCommandParams const & p)
{}
BufferView * InsetCommand::view() const
{
return button_.view();
}
void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (!set_label_) {

View File

@ -80,8 +80,6 @@ protected:
void setOptions(std::string const & o) { p_.setOptions(o); }
///
void setParams(InsetCommandParams const &);
///
virtual BufferView * view() const;
/// This should provide the text for the button
virtual std::string const getScreenLabel(Buffer const &) const = 0;

View File

@ -25,8 +25,10 @@
#include "latexrunparams.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "metricsinfo.h"
#include "frontends/lyx_gui.h"
#include "frontends/LyXView.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -388,9 +390,21 @@ InsetExternal::~InsetExternal()
}
void InsetExternal::cache(BufferView * view) const
{
BOOST_ASSERT(view);
view_ = view->owner()->view();
}
BufferView * InsetExternal::view() const
{
return view_.lock().get();
}
void InsetExternal::statusChanged() const
{
BufferView * const bv = renderer_->view();
BufferView * const bv = view();
if (bv)
bv->updateInset(this);
}
@ -445,6 +459,7 @@ void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
{
cache(pi.base.bv);
renderer_->draw(pi, x, y);
}

View File

@ -21,6 +21,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/signals/trackable.hpp>
#include <boost/weak_ptr.hpp>
/** No two InsetExternalParams variables can have the same temporary file.
@ -128,6 +129,8 @@ public:
void setParams(InsetExternalParams const &, Buffer const &);
private:
void cache(BufferView *) const;
BufferView * view() const;
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
@ -137,6 +140,9 @@ private:
InsetExternalParams params_;
/// The thing that actually draws the image on LyX's screen.
boost::scoped_ptr<RenderBase> renderer_;
/// Cached
mutable boost::weak_ptr<BufferView> view_;
};

View File

@ -66,8 +66,10 @@ TODO
#include "latexrunparams.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "metricsinfo.h"
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
#include "support/filetools.h"
#include "support/lyxalgo.h" // lyx::count
@ -181,9 +183,21 @@ InsetGraphics::~InsetGraphics()
}
void InsetGraphics::cache(BufferView * view) const
{
BOOST_ASSERT(view);
view_ = view->owner()->view();
}
BufferView * InsetGraphics::view() const
{
return view_.lock().get();
}
void InsetGraphics::statusChanged() const
{
BufferView * bv = graphic_->view();
BufferView * bv = view();
if (bv)
bv->updateInset(this);
}
@ -227,6 +241,7 @@ void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
{
cache(pi.base.bv);
graphic_->draw(pi, x, y);
}

View File

@ -18,6 +18,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/signals/trackable.hpp>
#include <boost/weak_ptr.hpp>
class Dialogs;
@ -38,8 +39,6 @@ public:
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
EDITABLE editable() const;
///
void write(Buffer const &, std::ostream &) const;
@ -77,11 +76,16 @@ public:
/// Get the inset parameters, used by the GUIndependent dialog.
InsetGraphicsParams const & params() const;
///
void draw(PainterInfo & pi, int x, int y) const;
private:
///
friend class InsetGraphicsMailer;
void cache(BufferView *) const;
BufferView * view() const;
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
@ -105,6 +109,9 @@ private:
/// The thing that actually draws the image on LyX's screen.
boost::scoped_ptr<RenderGraphic> const graphic_;
/// Cached
mutable boost::weak_ptr<BufferView> view_;
};

View File

@ -25,6 +25,7 @@
#include "lyxlex.h"
#include "metricsinfo.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "graphics/PreviewImage.h"
@ -557,9 +558,15 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
}
void InsetInclude::cache(BufferView * view) const
{
BOOST_ASSERT(view);
view_ = view->owner()->view();
}
BufferView * InsetInclude::view() const
{
return button_.view();
return view_.lock().get();
}

View File

@ -16,6 +16,7 @@
#include "insetcommandparams.h"
#include "render_button.h"
#include <boost/scoped_ptr.hpp>
#include <boost/weak_ptr.hpp>
class Buffer;
@ -42,8 +43,6 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
virtual BufferView * view() const;
/// get the parameters
InsetCommandParams const & params(void) const;
@ -83,6 +82,9 @@ public:
void addPreview(lyx::graphics::PreviewLoader &) const;
private:
void cache(BufferView *) const;
BufferView * view() const;
/// Slot receiving a signal that the preview is ready to display.
void statusChanged() const;
/** Slot receiving a signal that the external file has changed
@ -90,7 +92,6 @@ private:
*/
void fileChanged() const;
friend class InsetIncludeMailer;
/// set the parameters
@ -111,6 +112,7 @@ private:
boost::scoped_ptr<RenderMonitoredPreview> const preview_;
/// cache
mutable boost::weak_ptr<BufferView> view_;
mutable bool set_label_;
mutable RenderButton button_;
};

View File

@ -15,6 +15,8 @@
#include "BufferView.h"
#include "funcrequest.h"
#include "frontends/LyXView.h"
#include "support/lstrings.h"
#include "support/std_ostream.h"
@ -36,18 +38,33 @@ InsetLabel::~InsetLabel()
}
std::auto_ptr<InsetBase> InsetLabel::clone() const
{
return std::auto_ptr<InsetBase>(new InsetLabel(params()));
}
void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
{
list.push_back(getContents());
}
string const InsetLabel::getScreenLabel(Buffer const &) const
{
return getContents();
}
dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
{
BOOST_ASSERT(cmd.view());
BufferView * const bv = cmd.view();
switch (cmd.action) {
case LFUN_INSET_EDIT:
InsetCommandMailer("label", *this).showDialog(cmd.view());
InsetCommandMailer("label", *this).showDialog(bv);
return DISPATCHED;
break;
@ -58,13 +75,13 @@ dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
return UNDISPATCHED;
bool clean = true;
if (view() && p.getContents() != params().getContents()) {
clean = view()->ChangeRefsIfUnique(params().getContents(),
p.getContents());
if (bv && p.getContents() != params().getContents()) {
clean = bv->ChangeRefsIfUnique(params().getContents(),
p.getContents());
}
setParams(p);
cmd.view()->updateInset(this);
bv->updateInset(this);
return DISPATCHED;
}

View File

@ -14,6 +14,7 @@
#include "insetcommand.h"
#include <boost/weak_ptr.hpp>
class InsetLabel : public InsetCommand {
public:
@ -22,13 +23,11 @@ public:
///
~InsetLabel();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetLabel(params()));
}
std::auto_ptr<InsetBase> clone() const;
///
virtual dispatch_result localDispatch(FuncRequest const & cmd);
///
std::string const getScreenLabel(Buffer const &) const { return getContents(); }
std::string const getScreenLabel(Buffer const &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
///

View File

@ -1,21 +0,0 @@
/**
* \file render_base.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "render_base.h"
#include "BufferView.h"
BufferView * RenderBase::view() const
{
return view_.lock().get();
}

View File

@ -14,9 +14,6 @@
#include "dimension.h"
#include <boost/weak_ptr.hpp>
class BufferView;
class MetricsInfo;
class PainterInfo;
@ -32,16 +29,12 @@ public:
/// draw inset and update (xo, yo)-cache
virtual void draw(PainterInfo & pi, int x, int y) const = 0;
/// An accessor function to the cached store.
BufferView * view() const;
protected:
RenderBase() {}
RenderBase(RenderBase const &) {}
void operator=(RenderBase const &) {}
/// These are cached variables (are not copied).
mutable boost::weak_ptr<BufferView> view_;
/// Cached
mutable Dimension dim_;
};

View File

@ -12,12 +12,10 @@
#include "render_button.h"
#include "BufferView.h"
#include "LColor.h"
#include "metricsinfo.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
using std::string;
@ -57,9 +55,6 @@ void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
void RenderButton::draw(PainterInfo & pi, int x, int y) const
{
BOOST_ASSERT(pi.base.bv);
view_ = pi.base.bv->owner()->view();
// Draw it as a box with the LaTeX text
LyXFont font(LyXFont::ALL_SANE);
font.setColor(LColor::command);

View File

@ -14,13 +14,11 @@
#include "insets/inset.h"
#include "BufferView.h"
#include "gettext.h"
#include "LColor.h"
#include "metricsinfo.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "graphics/GraphicsImage.h"
@ -156,9 +154,6 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
{
BOOST_ASSERT(pi.base.bv);
view_ = pi.base.bv->owner()->view();
if (params_.display != lyx::graphics::NoDisplay &&
loader_.status() == lyx::graphics::WaitingToLoad)
loader_.startLoading();

View File

@ -1,3 +1,12 @@
2003-10-12 Angus Leeming <leeming@lyx.org>
* formulabase.[Ch] (cache): added.
(view): make protected.
(view_): store as a boost::weak_ptr.
(generatePreview): added this virtual function. Moved from inset.h.
* math_inset.[Ch] (view): removed.
2003-10-10 Angus Leeming <leeming@lyx.org>
* command_inset.h:trivial changes ButtonRenderer -> RenderButton.

View File

@ -180,9 +180,7 @@ void InsetFormula::read(Buffer const &, LyXLex & lex)
void InsetFormula::draw(PainterInfo & pi, int x, int y) const
{
BOOST_ASSERT(pi.base.bv);
BufferView * bv = pi.base.bv;
cache(bv);
cache(pi.base.bv);
// The previews are drawn only when we're not editing the inset.
bool const editing_inset = mathcursor && mathcursor->formula() == this;
@ -197,7 +195,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
// one pixel gap in front
preview_->draw(pi, x + 1, y);
} else {
PainterInfo p(bv);
PainterInfo p(pi.base.bv);
p.base.style = LM_ST_TEXT;
p.base.font = pi.base.font;
p.base.font.setColor(LColor::math);
@ -248,9 +246,6 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const
void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
{
BOOST_ASSERT(m.base.bv);
view_ = m.base.bv;
bool const editing_inset = mathcursor && mathcursor->formula() == this;
bool const use_preview = !editing_inset && preview_->previewReady();

View File

@ -75,7 +75,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
InsetFormulaBase::InsetFormulaBase()
: view_(0), xo_(0), yo_(0)
: xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
initMath();
@ -139,9 +139,15 @@ void InsetFormulaBase::handleFont2(BufferView * bv, string const & arg)
void InsetFormulaBase::cache(BufferView * view) const
{
BOOST_ASSERT(view);
view_ = view->owner()->view();
}
BufferView * InsetFormulaBase::view() const
{
return view_;
return view_.lock().get();
}

View File

@ -15,6 +15,7 @@
#define INSET_FORMULABASE_H
#include "insets/updatableinset.h"
#include <boost/weak_ptr.hpp>
class Buffer;
@ -66,9 +67,6 @@ public:
///
virtual MathAtom & par() = 0;
///
// And shouldn't this really return a shared_ptr<BufferView> instead?
BufferView * view() const;
///
virtual bool searchForward(BufferView *, std::string const &,
bool = true, bool = false);
@ -101,11 +99,19 @@ private:
dispatch_result lfunMouseMotion(FuncRequest const &);
protected:
///
//mutable boost::weak_ptr<BufferView> view_;
mutable BufferView * view_;
void cache(BufferView *) const;
BufferView * view() const;
protected:
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
*
* Most insets have no interest in this capability, so the method
* defaults to empty.
*/
virtual void generatePreview(Buffer const &) const {}
///
void handleFont(BufferView * bv, std::string const & arg, std::string const & font);
///
@ -115,6 +121,9 @@ protected:
mutable int xo_;
///
mutable int yo_;
private:
// Cache
mutable boost::weak_ptr<BufferView> view_;
};
// We don't really mess want around with mathed stuff outside mathed.

View File

@ -12,24 +12,15 @@
#include <config.h>
#include "math_inset.h"
#include "math_data.h"
#include "math_mathmlstream.h"
#include "math_cursor.h"
#include "debug.h"
#include "formulabase.h"
using std::string;
using std::ostream;
using std::endl;
BufferView * MathInset::view() const
{
return mathcursor ? mathcursor->formula()->view() : 0;
}
MathInset::size_type MathInset::nargs() const
{
return 0;

View File

@ -256,10 +256,6 @@ public:
virtual std::string fileInsetLabel() const;
/// usually the latex name
virtual std::string name() const;
protected:
/// a dirty hack
BufferView * view() const;
};
std::ostream & operator<<(std::ostream &, MathAtom const &);