]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBox.cpp
simplify GuiToc / TocWidget interaction. Much can still be simplified...
[lyx.git] / src / mathed / InsetMathBox.cpp
1 /**
2  * \file InsetMathBox.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Ling Li (InsetMathMakebox)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMathBox.h"
15
16 #include "LaTeXFeatures.h"
17 #include "MathData.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20 #include "MetricsInfo.h"
21
22 #include "frontends/Painter.h"
23
24 #include <ostream>
25
26
27 namespace lyx {
28
29 /////////////////////////////////////////////////////////////////////
30 //
31 // InsetMathBox
32 //
33 /////////////////////////////////////////////////////////////////////
34
35 InsetMathBox::InsetMathBox(docstring const & name)
36         : InsetMathNest(1), name_(name)
37 {}
38
39
40 void InsetMathBox::write(WriteStream & os) const
41 {
42         os << '\\' << name_ << '{' << cell(0) << '}';
43 }
44
45
46 void InsetMathBox::normalize(NormalStream & os) const
47 {
48         os << '[' << name_ << ' ';
49         //text_->write(buffer(), os);
50         os << "] ";
51 }
52
53
54 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
55 {
56         FontSetChanger dummy(mi.base, "textnormal");
57         cell(0).metrics(mi, dim);
58         metricsMarkers(dim);
59 }
60
61
62 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
63 {
64         FontSetChanger dummy(pi.base, "textnormal");
65         cell(0).draw(pi, x, y);
66         drawMarkers(pi, x, y);
67 }
68
69
70 void InsetMathBox::infoize(odocstream & os) const
71 {
72         os << "Box: " << name_;
73 }
74
75
76
77 /////////////////////////////////////////////////////////////////////
78 //
79 // InsetMathFBox
80 //
81 /////////////////////////////////////////////////////////////////////
82
83
84 InsetMathFBox::InsetMathFBox()
85         : InsetMathNest(1)
86 {}
87
88
89 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
90 {
91         FontSetChanger dummy(mi.base, "textnormal");
92         cell(0).metrics(mi, dim);
93         metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
94 }
95
96
97 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
98 {
99         Dimension const dim = dimension(*pi.base.bv);
100         pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
101                 dim.width() - 2, dim.height() - 2, Color_foreground);
102         FontSetChanger dummy(pi.base, "textnormal");
103         cell(0).draw(pi, x + 3, y);
104         setPosCache(pi, x, y);
105 }
106
107
108 void InsetMathFBox::write(WriteStream & os) const
109 {
110         os << "\\fbox{" << cell(0) << '}';
111 }
112
113
114 void InsetMathFBox::normalize(NormalStream & os) const
115 {
116         os << "[fbox " << cell(0) << ']';
117 }
118
119
120 void InsetMathFBox::infoize(odocstream & os) const
121 {
122         os << "FBox: ";
123 }
124
125
126 /////////////////////////////////////////////////////////////////////
127 //
128 // InsetMathFrameBox
129 //
130 /////////////////////////////////////////////////////////////////////
131
132
133 InsetMathFrameBox::InsetMathFrameBox()
134         : InsetMathNest(3)
135 {}
136
137
138 void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
139 {
140         FontSetChanger dummy(mi.base, "textnormal");
141         w_ = mathed_char_width(mi.base.font, '[');
142         InsetMathNest::metrics(mi);
143         dim  = cell(0).dimension(*mi.base.bv);
144         dim += cell(1).dimension(*mi.base.bv);
145         dim += cell(2).dimension(*mi.base.bv);
146         metricsMarkers(dim);
147 }
148
149
150 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
151 {
152         FontSetChanger dummy(pi.base, "textnormal");
153         Dimension const dim = dimension(*pi.base.bv);
154         pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
155                 dim.width() - 2, dim.height() - 2, Color_foreground);
156         x += 5;
157         BufferView const & bv = *pi.base.bv;
158
159         drawStrBlack(pi, x, y, from_ascii("["));
160         x += w_;
161         cell(0).draw(pi, x, y);
162         x += cell(0).dimension(bv).wid;
163         drawStrBlack(pi, x, y, from_ascii("]"));
164         x += w_ + 4;
165
166         drawStrBlack(pi, x, y, from_ascii("["));
167         x += w_;
168         cell(1).draw(pi, x, y);
169         x += cell(1).dimension(bv).wid;
170         drawStrBlack(pi, x, y, from_ascii("]"));
171         x += w_ + 4;
172
173         cell(2).draw(pi, x, y);
174         drawMarkers(pi, x, y);
175 }
176
177
178 void InsetMathFrameBox::write(WriteStream & os) const
179 {
180         os << "\\framebox";
181         os << '[' << cell(0) << ']';
182         if (cell(1).size())
183                 os << '[' << cell(1) << ']';
184         os << '{' << cell(2) << '}';
185 }
186
187
188 void InsetMathFrameBox::normalize(NormalStream & os) const
189 {
190         os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
191 }
192
193
194
195 /////////////////////////////////////////////////////////////////////
196 //
197 // InsetMathBoxed
198 //
199 /////////////////////////////////////////////////////////////////////
200
201 InsetMathBoxed::InsetMathBoxed()
202         : InsetMathNest(1)
203 {}
204
205
206 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
207 {
208         cell(0).metrics(mi, dim);
209         metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
210 }
211
212
213 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
214 {
215         Dimension const dim = dimension(*pi.base.bv);
216         pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
217                 dim.width() - 2, dim.height() - 2, Color_foreground);
218         cell(0).draw(pi, x + 3, y);
219         setPosCache(pi, x, y);
220 }
221
222
223 void InsetMathBoxed::write(WriteStream & os) const
224 {
225         os << "\\boxed{" << cell(0) << '}';
226 }
227
228
229 void InsetMathBoxed::normalize(NormalStream & os) const
230 {
231         os << "[boxed " << cell(0) << ']';
232 }
233
234
235 void InsetMathBoxed::infoize(odocstream & os) const
236 {
237         os << "Boxed: ";
238 }
239
240
241 void InsetMathBoxed::validate(LaTeXFeatures & features) const
242 {
243         features.require("amsmath");
244 }
245
246
247 /////////////////////////////////////////////////////////////////////
248 //
249 // InsetMathMakebox
250 //
251 /////////////////////////////////////////////////////////////////////
252
253
254 InsetMathMakebox::InsetMathMakebox()
255         : InsetMathNest(3)
256 {}
257
258
259 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
260 {
261         FontSetChanger dummy(mi.base, from_ascii("textnormal"));
262         w_ = mathed_char_width(mi.base.font, '[');
263         InsetMathNest::metrics(mi);
264         dim   = cell(0).dimension(*mi.base.bv);
265         dim  += cell(1).dimension(*mi.base.bv);
266         dim  += cell(2).dimension(*mi.base.bv);
267         dim.wid += 4 * w_ + 4;
268         metricsMarkers(dim);
269 }
270
271
272 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
273 {
274         FontSetChanger dummy(pi.base, from_ascii("textnormal"));
275         drawMarkers(pi, x, y);
276
277         drawStrBlack(pi, x, y, from_ascii("["));
278         x += w_;
279         cell(0).draw(pi, x, y);
280         x += cell(0).dimension(*pi.base.bv).width();
281         drawStrBlack(pi, x, y, from_ascii("]"));
282         x += w_ + 2;
283
284         drawStrBlack(pi, x, y, from_ascii("["));
285         x += w_;
286         cell(1).draw(pi, x, y);
287         x += cell(1).dimension(*pi.base.bv).wid;
288         drawStrBlack(pi, x, y, from_ascii("]"));
289         x += w_ + 2;
290
291         cell(2).draw(pi, x, y);
292         setPosCache(pi, x, y);
293 }
294
295
296 void InsetMathMakebox::write(WriteStream & os) const
297 {
298         os << "\\makebox";
299         os << '[' << cell(0) << ']';
300         if (cell(1).size())
301                 os << '[' << cell(1) << ']';
302         os << '{' << cell(2) << '}';
303 }
304
305
306 void InsetMathMakebox::normalize(NormalStream & os) const
307 {
308         os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
309 }
310
311
312 void InsetMathMakebox::infoize(odocstream & os) const
313 {
314         os << "Makebox (width: " << cell(0)
315             << " pos: " << cell(1) << ")";
316 }
317
318
319 } // namespace lyx