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"
20 #include "latexrunparams.h"
21 #include "frontends/Painter.h"
22 #include "frontends/font_metrics.h"
23 #include "support/lstrings.h"
25 #include "support/std_sstream.h"
27 using namespace lyx::support;
32 extern MathCursor * mathcursor;
35 InsetFormulaMacro::InsetFormulaMacro()
37 // inset name is inherited from Inset
38 setInsetName("unknown");
42 InsetFormulaMacro::InsetFormulaMacro
43 (string const & name, int nargs, string const & type)
46 MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
50 InsetFormulaMacro::InsetFormulaMacro(string const & s)
52 std::istringstream is(STRCONV(s));
57 auto_ptr<InsetBase> InsetFormulaMacro::clone() const
59 return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
63 void InsetFormulaMacro::write(Buffer const &, ostream & os) const
65 os << "FormulaMacro ";
66 WriteStream wi(os, false, false);
71 int InsetFormulaMacro::latex(Buffer const &, ostream & os,
72 LatexRunParams const & runparams) const
74 WriteStream wi(os, runparams.moving_arg, true);
80 int InsetFormulaMacro::ascii(Buffer const &, ostream & os, int) const
82 WriteStream wi(os, false, true);
88 int InsetFormulaMacro::linuxdoc(Buffer const & buf, ostream & os) const
90 return ascii(buf, os, 0);
94 int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os, bool) const
96 return ascii(buf, os, 0);
100 void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
102 read(lex.getStream());
106 void InsetFormulaMacro::read(std::istream & is)
108 MathMacroTemplate * p = new MathMacroTemplate(is);
109 setInsetName(p->name());
110 MathMacroTable::create(MathAtom(p));
115 string InsetFormulaMacro::prefix() const
117 return bformat(_(" Macro: %1$s: "), getInsetName());
121 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
123 par()->metrics(mi, dim_);
126 dim_.wid += 10 + font_metrics::width(prefix(), mi.base.font);
131 MathAtom const & InsetFormulaMacro::par() const
133 return MathMacroTable::provide(getInsetName());
137 MathAtom & InsetFormulaMacro::par()
139 return MathMacroTable::provide(getInsetName());
143 InsetOld::Code InsetFormulaMacro::lyxCode() const
145 return InsetOld::MATHMACRO_CODE;
149 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
152 LyXFont font = p.base.font;
153 font.setColor(LColor::math);
155 PainterInfo pi(p.base.bv);
156 pi.base.style = LM_ST_TEXT;
159 int const a = y - dim_.asc + 1;
160 int const w = dim_.wid - 2;
161 int const h = dim_.height() - 2;
163 // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
164 pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
165 pi.pain.rectangle(x, a, w, h, LColor::mathframe);
168 const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
169 mathcursor->drawSelection(pi);
171 pi.pain.text(x + 2, y, prefix(), font);
174 par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);