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_cursor.h"
16 #include "math_macrotable.h"
17 #include "math_macrotemplate.h"
18 #include "math_mathmlstream.h"
23 #include "outputparams.h"
25 #include "frontends/Painter.h"
26 #include "frontends/font_metrics.h"
28 #include "support/lstrings.h"
29 #include "support/std_sstream.h"
31 using lyx::support::bformat;
38 extern MathCursor * mathcursor;
41 InsetFormulaMacro::InsetFormulaMacro()
43 // inset name is inherited from Inset
44 setInsetName("unknown");
48 InsetFormulaMacro::InsetFormulaMacro
49 (string const & name, int nargs, string const & type)
52 MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
56 InsetFormulaMacro::InsetFormulaMacro(string const & s)
58 std::istringstream is(s);
63 auto_ptr<InsetBase> InsetFormulaMacro::clone() const
65 return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
69 void InsetFormulaMacro::write(Buffer const &, ostream & os) const
71 os << "FormulaMacro ";
72 WriteStream wi(os, false, false);
77 int InsetFormulaMacro::latex(Buffer const &, ostream & os,
78 OutputParams const & runparams) const
80 WriteStream wi(os, runparams.moving_arg, true);
86 int InsetFormulaMacro::plaintext(Buffer const &, ostream & os,
87 OutputParams const &) const
89 WriteStream wi(os, false, true);
95 int InsetFormulaMacro::linuxdoc(Buffer const & buf, ostream & os,
96 OutputParams const & runparams) const
98 return plaintext(buf, os, runparams);
102 int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
103 OutputParams const & runparams) const
105 return plaintext(buf, os, runparams);
109 void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
111 read(lex.getStream());
115 void InsetFormulaMacro::read(std::istream & is)
117 auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
118 setInsetName(p->name());
119 MathMacroTable::create(MathAtom(p.release()));
124 string InsetFormulaMacro::prefix() const
126 return bformat(_(" Macro: %1$s: "), getInsetName());
130 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
132 par()->metrics(mi, dim_);
135 dim_.wid += 10 + font_metrics::width(prefix(), mi.base.font);
140 MathAtom const & InsetFormulaMacro::par() const
142 return MathMacroTable::provide(getInsetName());
146 MathAtom & InsetFormulaMacro::par()
148 return MathMacroTable::provide(getInsetName());
152 InsetOld::Code InsetFormulaMacro::lyxCode() const
154 return InsetOld::MATHMACRO_CODE;
158 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
161 LyXFont font = p.base.font;
162 font.setColor(LColor::math);
164 PainterInfo pi(p.base.bv);
165 pi.base.style = LM_ST_TEXT;
168 int const a = y - dim_.asc + 1;
169 int const w = dim_.wid - 2;
170 int const h = dim_.height() - 2;
172 // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
173 pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
174 pi.pain.rectangle(x, a, w, h, LColor::mathframe);
177 const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
178 mathcursor->drawSelection(pi);
180 pi.pain.text(x + 2, y, prefix(), font);
183 par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);