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 "math_macro.h"
15 #include "math_support.h"
16 #include "math_extern.h"
17 #include "math_mathmlstream.h"
22 #include "BufferView.h"
23 #include "LaTeXFeatures.h"
24 #include "frontends/Painter.h"
32 MathMacro::MathMacro(string const & name, int numargs)
33 : MathNestInset(numargs), name_(name)
37 auto_ptr<InsetBase> MathMacro::doClone() const
39 return auto_ptr<InsetBase>(new MathMacro(*this));
43 string MathMacro::name() const
49 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
51 if (!MacroTable::globalMacros().has(name())) {
52 mathed_string_dim(mi.base.font, "Unknown: " + name(), dim);
53 } else if (editing(mi.base.bv)) {
54 asArray(MacroTable::globalMacros().get(name()).def(), tmpl_);
55 LyXFont font = mi.base.font;
56 augmentFont(font, "lyxtex");
57 tmpl_.metrics(mi, dim);
58 dim.wid += mathed_string_width(font, name()) + 10;
59 int ww = mathed_string_width(font, "#1: ");
60 for (idx_type i = 0; i < nargs(); ++i) {
61 MathArray const & c = cell(i);
63 dim.wid = max(dim.wid, c.width() + ww);
64 dim.des += c.height() + 10;
67 MacroTable::globalMacros().get(name()).expand(cells_, expanded_);
68 expanded_.metrics(mi, dim);
75 void MathMacro::draw(PainterInfo & pi, int x, int y) const
77 if (!MacroTable::globalMacros().has(name())) {
78 drawStrRed(pi, x, y, "Unknown: " + name());
79 } else if (editing(pi.base.bv)) {
80 LyXFont font = pi.base.font;
81 augmentFont(font, "lyxtex");
82 int h = y - dim_.ascent() + 2 + tmpl_.ascent();
83 pi.pain.text(x + 3, h, name(), font);
84 int const w = mathed_string_width(font, name());
85 tmpl_.draw(pi, x + w + 12, h);
88 mathed_string_dim(font, "#1: ", ldim);
89 for (idx_type i = 0; i < nargs(); ++i) {
90 MathArray const & c = cell(i);
91 h += max(c.ascent(), ldim.asc) + 5;
92 c.draw(pi, x + ldim.wid, h);
94 str[1] += static_cast<char>(i);
95 pi.pain.text(x + 3, h, str, font);
96 h += max(c.descent(), ldim.des) + 5;
99 expanded_.draw(pi, x, y);
101 drawMarkers2(pi, x, y);
105 void MathMacro::validate(LaTeXFeatures & features) const
107 if (name() == "binom" || name() == "mathcircumflex")
108 features.require(name());
112 void MathMacro::maple(MapleStream & os) const
115 ::maple(expanded_, os);
119 void MathMacro::mathmlize(MathMLStream & os) const
122 ::mathmlize(expanded_, os);
126 void MathMacro::octave(OctaveStream & os) const
129 ::octave(expanded_, os);
133 void MathMacro::updateExpansion() const
135 //expanded_.substitute(*this);
139 void MathMacro::infoize(std::ostream & os) const
141 os << "Macro: " << name();
145 void MathMacro::infoize2(std::ostream & os) const
147 os << "Macro: " << name();