diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3857970072..761f360f58 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,29 @@ +2003-10-12 Angus Leeming + + * 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 * 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 * insetinclude.C (metrics, draw, restartLoading): pass a buffer arg diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 7c8ea08619..48a5776bbe 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -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 \ diff --git a/src/insets/inset.h b/src/insets/inset.h index bc653185ea..cad92c891f 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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; diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index b771a11da7..f261618f9b 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -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. diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 5b6e09acf7..59c66883b2 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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(); -} diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 859e78866f..e455544895 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -20,8 +20,6 @@ #include "box.h" #include "lyxfont.h" -#include - 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 view_; }; diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index acc2033c2c..b39930f7e3 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -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_) { diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 992a1df308..32129d039b 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 7d41bb29b2..2fb0b6b2d4 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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); } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 93d0e678c0..31d2b9ae33 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -21,6 +21,7 @@ #include #include +#include /** 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 renderer_; + + /// Cached + mutable boost::weak_ptr view_; }; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index f3c3493c26..6cc2a3415d 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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); } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index c9e1887ceb..2ac1afc35b 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -18,6 +18,7 @@ #include #include +#include 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 const graphic_; + + /// Cached + mutable boost::weak_ptr view_; }; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 3dea3f3585..5d4dee35bb 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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(); } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 96256d2026..9fda837950 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -16,6 +16,7 @@ #include "insetcommandparams.h" #include "render_button.h" #include +#include 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 const preview_; /// cache + mutable boost::weak_ptr view_; mutable bool set_label_; mutable RenderButton button_; }; diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index a310f30d83..ac056649d7 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -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 InsetLabel::clone() const +{ + return std::auto_ptr(new InsetLabel(params())); +} + + void InsetLabel::getLabelList(Buffer const &, std::vector & 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; } diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 2fe34f0b1f..c9db1eea30 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -14,6 +14,7 @@ #include "insetcommand.h" +#include class InsetLabel : public InsetCommand { public: @@ -22,13 +23,11 @@ public: /// ~InsetLabel(); /// - virtual std::auto_ptr clone() const { - return std::auto_ptr(new InsetLabel(params())); - } + std::auto_ptr 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; } /// diff --git a/src/insets/render_base.C b/src/insets/render_base.C deleted file mode 100644 index 1f3ea2c4c0..0000000000 --- a/src/insets/render_base.C +++ /dev/null @@ -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 - -#include "render_base.h" - -#include "BufferView.h" - - -BufferView * RenderBase::view() const -{ - return view_.lock().get(); -} diff --git a/src/insets/render_base.h b/src/insets/render_base.h index 2fbb97775a..20285f5fd8 100644 --- a/src/insets/render_base.h +++ b/src/insets/render_base.h @@ -14,9 +14,6 @@ #include "dimension.h" -#include - -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 view_; + /// Cached mutable Dimension dim_; }; diff --git a/src/insets/render_button.C b/src/insets/render_button.C index fd794b02d5..3200ac5b86 100644 --- a/src/insets/render_button.C +++ b/src/insets/render_button.C @@ -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); diff --git a/src/insets/render_graphic.C b/src/insets/render_graphic.C index cab82d915f..52186bc9f4 100644 --- a/src/insets/render_graphic.C +++ b/src/insets/render_graphic.C @@ -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(); diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 0d7ced68c9..c182932080 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2003-10-12 Angus Leeming + + * 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 * command_inset.h:trivial changes ButtonRenderer -> RenderButton. diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 798f1695a2..cd977f2435 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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(); diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index c03799c3a5..ffdd3e4726 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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(); } diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 6c3d8dc269..c00a9a4da0 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -15,6 +15,7 @@ #define INSET_FORMULABASE_H #include "insets/updatableinset.h" +#include class Buffer; @@ -66,9 +67,6 @@ public: /// virtual MathAtom & par() = 0; /// - // And shouldn't this really return a shared_ptr 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 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 view_; }; // We don't really mess want around with mathed stuff outside mathed. diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index f52a6edd7b..bf181510c9 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -12,24 +12,15 @@ #include #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; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 981a5e5b1a..e9aaa63bda 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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 &);