3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "formulamacro.h"
15 #include "math_macrotable.h"
16 #include "math_macrotemplate.h"
17 #include "math_mathmlstream.h"
19 #include "BufferView.h"
25 #include "outputparams.h"
27 #include "frontends/Painter.h"
28 #include "frontends/font_metrics.h"
30 #include "support/lstrings.h"
34 using lyx::support::bformat;
43 InsetFormulaMacro::InsetFormulaMacro()
44 : MathNestInset(2), name_("unknownA")
48 InsetFormulaMacro::InsetFormulaMacro
49 (string const & name, int nargs, string const & type)
50 : MathNestInset(2), name_(name)
52 MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
56 InsetFormulaMacro::InsetFormulaMacro(string const & s)
57 : MathNestInset(2), name_("unknownB")
59 std::istringstream is(s);
64 auto_ptr<InsetBase> InsetFormulaMacro::clone() const
66 return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
70 void InsetFormulaMacro::write(Buffer const &, ostream & os) const
72 os << "FormulaMacro\n";
73 WriteStream wi(os, false, false);
78 int InsetFormulaMacro::latex(Buffer const &, ostream & os,
79 OutputParams const & runparams) const
81 //lyxerr << "InsetFormulaMacro::latex" << endl;
82 WriteStream wi(os, runparams.moving_arg, true);
88 int InsetFormulaMacro::plaintext(Buffer const &, ostream & os,
89 OutputParams const &) const
91 WriteStream wi(os, false, true);
97 int InsetFormulaMacro::linuxdoc(Buffer const & buf, ostream & os,
98 OutputParams const & runparams) const
100 return plaintext(buf, os, runparams);
104 int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
105 OutputParams const & runparams) const
107 return plaintext(buf, os, runparams);
111 void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
113 read(lex.getStream());
117 void InsetFormulaMacro::read(std::istream & is)
119 auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
121 MathMacroTable::create(MathAtom(p.release()));
125 string InsetFormulaMacro::prefix() const
127 return bformat(_(" Macro: %1$s: "), name_);
131 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
133 //lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl;
134 tmpl()->metrics(mi, dim);
137 dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
142 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
145 LyXFont font = p.base.font;
146 font.setColor(LColor::math);
148 PainterInfo pi(p.base.bv, p.pain);
149 pi.base.style = LM_ST_TEXT;
152 int const a = y - dim_.asc + 1;
153 int const w = dim_.wid - 2;
154 int const h = dim_.height() - 2;
156 // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
157 pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
158 pi.pain.rectangle(x, a, w, h, LColor::mathframe);
164 LCursor & cur = p.base.bv->cursor();
165 if (cur.isInside(this))
166 cur.drawSelection(pi);
169 pi.pain.text(x + 2, y, prefix(), font);
172 tmpl()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
174 setPosCache(pi, x, y);
178 MathAtom & InsetFormulaMacro::tmpl() const
180 return MathMacroTable::provide(name_);