]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macro.C
Remove mixed_content from output parameters.
[lyx.git] / src / mathed / math_macro.C
1 /**
2  * \file math_macro.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "math_macro.h"
15 #include "math_support.h"
16 #include "math_extern.h"
17 #include "math_mathmlstream.h"
18
19 #include "buffer.h"
20 #include "cursor.h"
21 #include "debug.h"
22 #include "BufferView.h"
23 #include "LaTeXFeatures.h"
24
25 using std::string;
26 using std::max;
27 using std::auto_ptr;
28 using std::endl;
29
30
31 MathMacro::MathMacro(string const & name, int numargs)
32         : MathNestInset(numargs), name_(name)
33 {}
34
35
36 auto_ptr<InsetBase> MathMacro::clone() const
37 {
38         return auto_ptr<InsetBase>(new MathMacro(*this));
39 }
40
41
42 string MathMacro::name() const
43 {
44         return name_;
45 }
46
47
48 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
49 {
50         if (!MacroTable::globalMacros().has(name())) {
51                 mathed_string_dim(mi.base.font, "Unknown: " + name(), dim);
52         } else if (editing(mi.base.bv)) {
53                 asArray(MacroTable::globalMacros().get(name()).def(), tmpl_);
54                 LyXFont font = mi.base.font;
55                 augmentFont(font, "lyxtex");
56                 tmpl_.metrics(mi, dim);
57                 dim.wid += mathed_string_width(font, name()) + 10;
58                 int ww = mathed_string_width(font, "#1: ");
59                 for (idx_type i = 0; i < nargs(); ++i) {
60                         MathArray const & c = cell(i);
61                         c.metrics(mi);
62                         dim.wid  = max(dim.wid, c.width() + ww);
63                         dim.des += c.height() + 10;
64                 }
65         } else {
66                 MacroTable::globalMacros().get(name()).expand(cells_, expanded_);
67                 expanded_.metrics(mi, dim);
68         }
69         metricsMarkers2(dim);
70         dim_ = dim;
71 }
72
73
74 void MathMacro::draw(PainterInfo & pi, int x, int y) const
75 {
76         if (!MacroTable::globalMacros().has(name())) {
77                 drawStrRed(pi, x, y, "Unknown: " + name());
78         } else if (editing(pi.base.bv)) {
79                 LyXFont font = pi.base.font;
80                 augmentFont(font, "lyxtex");
81                 int h = y - dim_.ascent() + 2 + tmpl_.ascent();
82                 drawStr(pi, font, x + 3, h, name());
83                 int const w = mathed_string_width(font, name());
84                 tmpl_.draw(pi, x + w + 12, h);
85                 h += tmpl_.descent();
86                 Dimension ldim;
87                 mathed_string_dim(font, "#1: ", ldim);
88                 for (idx_type i = 0; i < nargs(); ++i) {
89                         MathArray const & c = cell(i);
90                         h += max(c.ascent(), ldim.asc) + 5;
91                         c.draw(pi, x + ldim.wid, h);
92                         char str[] = "#1:";
93                         str[1] += static_cast<char>(i);
94                         drawStr(pi, font, x + 3, h, str);
95                         h += max(c.descent(), ldim.des) + 5;
96                 }
97         } else {
98                 expanded_.draw(pi, x, y);
99         }
100         drawMarkers2(pi, x, y);
101 }
102
103
104 void MathMacro::validate(LaTeXFeatures & features) const
105 {
106         if (name() == "binom" || name() == "mathcircumflex")
107                 features.require(name());
108 }
109
110
111 void MathMacro::maple(MapleStream & os) const
112 {
113         updateExpansion();
114         ::maple(expanded_, os);
115 }
116
117
118 void MathMacro::mathmlize(MathMLStream & os) const
119 {
120         updateExpansion();
121         ::mathmlize(expanded_, os);
122 }
123
124
125 void MathMacro::octave(OctaveStream & os) const
126 {
127         updateExpansion();
128         ::octave(expanded_, os);
129 }
130
131
132 void MathMacro::updateExpansion() const
133 {
134         //expanded_.substitute(*this);
135 }
136
137
138 void MathMacro::infoize(std::ostream & os) const
139 {
140         os << "Macro: " << name();
141 }
142
143
144 void MathMacro::infoize2(std::ostream & os) const
145 {
146         os << "Macro: " << name();
147
148 }