]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macro.C
d0d91646e1b48737faa63f8ed0ea3eca40dc7d15
[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
32 MathMacro::MathMacro(string const & name)
33         : name_(name)
34 {}
35
36
37 auto_ptr<InsetBase> MathMacro::clone() const
38 {
39         return auto_ptr<InsetBase>(new MathMacro(*this));
40 }
41
42
43 string MathMacro::name() const
44 {
45         return name_;
46 }
47
48
49 void MathMacro::setExpansion(MathArray const & exp, MathArray const & arg) const
50 {
51         expanded_ = exp;
52         args_ = arg;
53 }
54
55
56 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
57 {
58         LyXFont font = mi.base.font;
59         augmentFont(font, "lyxtex");
60         mathed_string_dim(font, "\\" + name(), dim);
61         dim_ = dim;
62 }
63
64
65 void MathMacro::metricsExpanded(MetricsInfo & mi, Dimension & dim) const
66 {
67         args_.metrics(mi);
68         expanded_.metrics(mi, dim);
69         dim.wid -= args_.size() ? args_.width() : 0;
70         dim_ = dim;
71 }
72
73
74 void MathMacro::draw(PainterInfo & pi, int x, int y) const
75 {
76         LyXFont font = pi.base.font;
77         augmentFont(font, "lyxtex");
78         drawStr(pi, font, x, y, "\\" + name());
79         setPosCache(pi, x, y);
80 }
81
82
83 void MathMacro::drawExpanded(PainterInfo & pi, int x, int y) const
84 {
85         expanded_.draw(pi, x, y);
86         drawMarkers2(pi, x, y);
87 }
88
89
90 int MathMacro::widthExpanded() const
91 {
92         return expanded_.width();
93 }
94
95
96 void MathMacro::validate(LaTeXFeatures & features) const
97 {
98         if (name() == "binom" || name() == "mathcircumflex")
99                 features.require(name());
100 }
101
102
103 void MathMacro::maple(MapleStream & os) const
104 {
105         updateExpansion();
106         ::maple(expanded_, os);
107 }
108
109
110 void MathMacro::mathmlize(MathMLStream & os) const
111 {
112         updateExpansion();
113         ::mathmlize(expanded_, os);
114 }
115
116
117 void MathMacro::octave(OctaveStream & os) const
118 {
119         updateExpansion();
120         ::octave(expanded_, os);
121 }
122
123
124 void MathMacro::updateExpansion() const
125 {
126 #warning FIXME
127         //expand();
128         //expanded_.substitute(*this);
129 }
130
131
132 void MathMacro::infoize(std::ostream & os) const
133 {
134         os << "Macro: " << name();
135 }
136
137
138 void MathMacro::infoize2(std::ostream & os) const
139 {
140         os << "Macro: " << name();
141
142 }