* Mathed now caches the BufferView as a weak_ptr.

* PreviewedInset caches the LaTeX snippet.
* Further clean-up of mathed's preview code.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4838 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-08-02 12:38:20 +00:00
parent 3d137bfe77
commit 984cbba504
10 changed files with 50 additions and 40 deletions

View File

@ -1,3 +1,7 @@
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

View File

@ -33,7 +33,7 @@ bool PreviewedInset::activated()
}
void PreviewedInset::generatePreview() const
void PreviewedInset::generatePreview()
{
if (!Previews::activated() || !previewWanted() ||
!view() || !view()->buffer())
@ -46,15 +46,14 @@ void PreviewedInset::generatePreview() const
}
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;
@ -66,7 +65,7 @@ void PreviewedInset::addPreview(grfx::PreviewLoader & ploader) const
boost::bind(&PreviewedInset::imageReady, this, _1));
}
ploader.add(snippet);
ploader.add(snippet_);
}
@ -76,13 +75,10 @@ bool PreviewedInset::previewReady() const
!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_)
@ -95,7 +91,7 @@ bool PreviewedInset::previewReady() const
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;

View File

@ -41,12 +41,12 @@ public:
/** 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;
@ -73,10 +73,12 @@ private:
///
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

View File

@ -1,3 +1,18 @@
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.

View File

@ -103,7 +103,7 @@ InsetFormula::InsetFormula(BufferView * bv)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
view_ = bv;
view_ = bv->owner()->view();
}
@ -191,7 +191,6 @@ void InsetFormula::read(Buffer const *, LyXLex & lex)
{
mathed_parse_normal(par_, lex);
metrics();
updatePreview();
}
@ -207,6 +206,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
{
// 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);
@ -390,8 +390,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
result = InsetFormulaBase::localDispatch(bv, action, arg);
}
//updatePreview();
return result;
}

View File

@ -89,7 +89,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
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();
@ -151,7 +151,7 @@ void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
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;
@ -204,6 +204,7 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
}
releaseMathCursor(bv);
}
generatePreview();
bv->updateInset(this, false);
}
@ -836,13 +837,13 @@ Inset::Code InsetFormulaBase::lyxCode() const
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_);
}
@ -854,7 +855,7 @@ int InsetFormulaBase::xlow() const
int InsetFormulaBase::xhigh() const
{
return xo_ + width(view_, font_);
return xo_ + width(view(), font_);
}

View File

@ -23,6 +23,8 @@
#include "frontends/mouse_state.h"
#include "lyxfont.h"
#include <boost/weak_ptr.hpp>
#include <iosfwd>
class Buffer;
@ -99,7 +101,7 @@ public:
///
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 &,
@ -115,9 +117,6 @@ public:
virtual void revealCodes(BufferView *) const;
///
virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
///
virtual void updatePreview() {}
private:
/// unimplemented
@ -127,7 +126,7 @@ private:
protected:
///
mutable BufferView * view_;
mutable boost::weak_ptr<BufferView> view_;
///
mutable LyXFont font_;

View File

@ -16,7 +16,7 @@ MathMetricsBase::MathMetricsBase()
MathMetricsInfo::MathMetricsInfo()
: view(0), fullredraw(false)
: fullredraw(false)
{}

View File

@ -4,6 +4,8 @@
#include "lyxfont.h"
#include "LString.h"
#include <boost/weak_ptr.hpp>
class BufferView;
class Painter;
class MathNestInset;
@ -46,7 +48,7 @@ struct MathMetricsInfo {
///
MathMetricsBase base;
///
BufferView * view;
boost::weak_ptr<BufferView> view;
///
bool fullredraw;
};

View File

@ -319,11 +319,4 @@ void MathNestInset::normalize(NormalStream & os) const
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();
}
{}