#include "BufferView.h"
#include "debug.h"
-#include "latexrunparams.h"
#include "LColor.h"
+#include "lyx_main.h"
+#include "outputparams.h"
#include "frontends/Painter.h"
-#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
#include "insets/render_preview.h"
int InsetFormula::latex(Buffer const &, ostream & os,
- LatexRunParams const & runparams) const
+ OutputParams const & runparams) const
{
WriteStream wi(os, runparams.moving_arg, true);
par_->write(wi);
}
-int InsetFormula::ascii(Buffer const &, ostream & os, int) const
+int InsetFormula::plaintext(Buffer const &, ostream & os,
+ OutputParams const &) const
{
if (0 && display()) {
Dimension dim;
}
-int InsetFormula::linuxdoc(Buffer const & buf, ostream & os) const
+int InsetFormula::linuxdoc(Buffer const & buf, ostream & os,
+ OutputParams const & runparams) const
{
- return docbook(buf, os, false);
+ return docbook(buf, os, runparams);
}
-int InsetFormula::docbook(Buffer const & buf, ostream & os, bool) const
+int InsetFormula::docbook(Buffer const & buf, ostream & os,
+ OutputParams const & runparams) const
{
MathMLStream ms(os);
ms << MTag("equation");
ms << MTag("alt");
ms << "<[CDATA[";
- int res = ascii(buf, ms.os(), 0);
+ int res = plaintext(buf, ms.os(), runparams);
ms << "]]>";
ms << ETag("alt");
ms << MTag("math");
}
-//ostream & operator<<(ostream & os, LyXCursor const & c)
-//{
-// os << '[' << c.x() << ' ' << c.y() << ' ' << c.pos() << ']';
-// return os;
-//}
+namespace {
+
+bool editing_inset(InsetFormula const * inset)
+{
+ return mathcursor &&
+ (const_cast<InsetFormulaBase const *>(mathcursor->formula()) ==
+ inset);
+}
+
+} // namespace anon
void InsetFormula::draw(PainterInfo & pi, int x, int y) const
{
- BOOST_ASSERT(pi.base.bv);
- BufferView * bv = pi.base.bv;
- cache(bv);
+ xo_ = x;
+ yo_ = y;
// 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();
+ bool const use_preview = !editing_inset(this)
+ && RenderPreview::activated()
+ && preview_->previewReady();
int const w = dim_.wid;
int const d = dim_.des;
// 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);
!= lcolor.getX11Name(LColor::background))
p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
- if (editing_inset) {
+ if (editing_inset(this)) {
mathcursor->drawSelection(pi);
//p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
- par_->draw(p, x + offset_, y);
+ par_->draw(p, x, y);
}
-
- xo_ = x;
- yo_ = y;
}
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();
+ bool const use_preview = !editing_inset(this)
+ && RenderPreview::activated()
+ && preview_->previewReady();
if (use_preview) {
preview_->metrics(m, dim);
dim.des += 1;
}
- if (display()) {
- offset_ = (m.base.textwidth - dim.wid) / 2;
- dim.wid = m.base.textwidth;
- } else {
- offset_ = 0;
- }
-
dim_ = dim;
}
void InsetFormula::statusChanged() const
{
- if (view())
- view()->updateInset(this);
+ LyX::cref().updateInset(this);
}
namespace {
-bool preview_wanted(InsetFormula const & inset, Buffer const &)
-{
- // Don't want a preview when we're editing the inset
- return !(mathcursor && mathcursor->formula() == &inset);
-}
-
-
string const latex_string(InsetFormula const & inset, Buffer const &)
{
- ostringstream ls;
- WriteStream wi(ls, false, false);
+ ostringstream os;
+ WriteStream wi(os, false, false);
inset.par()->write(wi);
- return ls.str();
+ return os.str();
}
} // namespace anon
void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
- if (preview_wanted(*this, ploader.buffer())) {
- string const snippet = latex_string(*this, ploader.buffer());
- preview_->addPreview(snippet, ploader);
- }
+ string const snippet = latex_string(*this, ploader.buffer());
+ preview_->addPreview(snippet, ploader);
}
void InsetFormula::generatePreview(Buffer const & buffer) const
{
- if (preview_wanted(*this, buffer)) {
- string const snippet = latex_string(*this, buffer);
- preview_->generatePreview(snippet, buffer);
- }
+ string const snippet = latex_string(*this, buffer);
+ preview_->addPreview(snippet, buffer);
+ preview_->startLoading(buffer);
}