+2002-08-02 Angus Leeming <leeming@lyx.org>
+
+ * PreviewedInset.[Ch]: cache the LaTeX snippet.
+
2002-08-01 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch]: new files. An abstract base class that can help
}
-void PreviewedInset::generatePreview() const
+void PreviewedInset::generatePreview()
{
if (!Previews::activated() || !previewWanted() ||
!view() || !view()->buffer())
}
-void PreviewedInset::addPreview(grfx::PreviewLoader & ploader) const
+void PreviewedInset::addPreview(grfx::PreviewLoader & ploader)
{
if (!Previews::activated() || !previewWanted())
return;
- // Generate the LaTeX snippet.
- string const snippet = latexString();
+ snippet_ = latexString();
- pimage_ = ploader.preview(snippet);
+ pimage_ = ploader.preview(snippet_);
if (pimage_)
return;
boost::bind(&PreviewedInset::imageReady, this, _1));
}
- ploader.add(snippet);
+ ploader.add(snippet_);
}
!view() || !view()->buffer())
return false;
- // If the cached grfx::PreviewImage is invalid, update it.
- string const snippet = latexString();
-
- if (!pimage_ || snippet != pimage_->snippet()) {
+ if (!pimage_ || snippet_ != pimage_->snippet()) {
grfx::PreviewLoader & ploader =
grfx::Previews::get().loader(view()->buffer());
- pimage_ = ploader.preview(snippet);
+ pimage_ = ploader.preview(snippet_);
}
if (!pimage_)
void PreviewedInset::imageReady(grfx::PreviewImage const & pimage) const
{
// Check snippet against the Inset's current contents
- if (latexString() != pimage.snippet())
+ if (snippet_ != pimage.snippet())
return;
pimage_ = &pimage;
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
*/
- void generatePreview() const;
+ void generatePreview();
/** Add a LaTeX snippet to the PreviewLoader but do not start the
* loading process.
*/
- void addPreview(PreviewLoader & ploader) const;
+ void addPreview(PreviewLoader & ploader);
/// The preview has been generated and is ready to use.
bool previewReady() const;
///
Inset & inset_;
- /// We don't own this
+ ///
+ string snippet_;
+ /// We don't own this. Cached for efficiency reasons.
mutable PreviewImage const * pimage_;
///
- mutable boost::signals::connection connection_;
+ boost::signals::connection connection_;
};
} // namespace grfx
+2002-08-02 Angus Leeming <leeming@lyx.org>
+
+ * formulabase.[Ch]: store the BufferView as a weak_ptr.
+ (updatePreview): removed.
+ (insetUnlock): invoke generatePreview().
+
+ * formula.C (InsetFormula): pass the shared_ptr to view_, not the raw
+ BufferView.
+ (read, localDispatch): remove those calls to updatePreview().
+
+ * math_metricsinfo.[Ch]: store the BufferView as a weak_ptr.
+
+ * math_nestinset.C (notifyCursorLeaves): empty, because
+ generatePreview() is now called from InsetFormulaBase::insetUnlock.
+
2002-08-01 Angus Leeming <leeming@lyx.org>
* formula.C: move code into the new PreviewedInset class.
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
- view_ = bv;
+ view_ = bv->owner()->view();
}
{
mathed_parse_normal(par_, lex);
metrics();
- updatePreview();
}
{
// This initiates the loading of the preview, so should come
// before the metrics are computed.
+ view_ = bv->owner()->view();
bool const use_preview = preview_->previewReady();
int const x = int(xx);
result = InsetFormulaBase::localDispatch(bv, action, arg);
}
- //updatePreview();
-
return result;
}
InsetFormulaBase::InsetFormulaBase()
- : view_(0), font_(), xo_(0), yo_(0)
+ : font_(), xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
initMath();
void InsetFormulaBase::metrics(BufferView * bv) const
{
if (bv)
- view_ = bv;
+ view_ = bv->owner()->view();
MathMetricsInfo mi;
mi.view = view_;
//mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
}
releaseMathCursor(bv);
}
+ generatePreview();
bv->updateInset(this, false);
}
int InsetFormulaBase::ylow() const
{
- return yo_ - ascent(view_, font_);
+ return yo_ - ascent(view(), font_);
}
int InsetFormulaBase::yhigh() const
{
- return yo_ + descent(view_, font_);
+ return yo_ + descent(view(), font_);
}
int InsetFormulaBase::xhigh() const
{
- return xo_ + width(view_, font_);
+ return xo_ + width(view(), font_);
}
#include "frontends/mouse_state.h"
#include "lyxfont.h"
+#include <boost/weak_ptr.hpp>
+
#include <iosfwd>
class Buffer;
///
virtual void updateLocal(BufferView * bv, bool mark_dirty);
///
- BufferView * view() const { return view_; }
+ BufferView * view() const { return view_.get(); }
///
virtual bool searchForward(BufferView *, string const &,
virtual void revealCodes(BufferView *) const;
///
virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
- ///
- virtual void updatePreview() {}
-
private:
/// unimplemented
protected:
///
- mutable BufferView * view_;
+ mutable boost::weak_ptr<BufferView> view_;
///
mutable LyXFont font_;
MathMetricsInfo::MathMetricsInfo()
- : view(0), fullredraw(false)
+ : fullredraw(false)
{}
#include "lyxfont.h"
#include "LString.h"
+#include <boost/weak_ptr.hpp>
+
class BufferView;
class Painter;
class MathNestInset;
///
MathMetricsBase base;
///
- BufferView * view;
+ boost::weak_ptr<BufferView> view;
///
bool fullredraw;
};
void MathNestInset::notifyCursorLeaves()
-{
- // Generate a preview only if we are leaving the InsetFormula itself
- if (!mathcursor || mathcursor->depth() != 1)
- return;
-
- InsetFormulaBase * inset = mathcursor->formula();
- inset->generatePreview();
-}
+{}