]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathFrameBox.cpp
Put mathed on a diet: transfer dimension cache from inset to BufferView.
[lyx.git] / src / mathed / InsetMathFrameBox.cpp
1 /**
2  * \file InsetMathFrameBox.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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathFrameBox.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "Color.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23 InsetMathFrameBox::InsetMathFrameBox()
24         : InsetMathNest(3)
25 {}
26
27
28 Inset * InsetMathFrameBox::clone() const
29 {
30         return new InsetMathFrameBox(*this);
31 }
32
33
34 void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         FontSetChanger dummy(mi.base, "textnormal");
37         w_ = mathed_char_width(mi.base.font, '[');
38         InsetMathNest::metrics(mi);
39         dim  = cell(0).dim();
40         dim += cell(1).dim();
41         dim += cell(2).dim();
42         metricsMarkers(dim);
43         // Cache the inset dimension. 
44         setDimCache(mi, dim);
45 }
46
47
48 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
49 {
50         FontSetChanger dummy(pi.base, "textnormal");
51         Dimension const dim = dimension(*pi.base.bv);
52         pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
53                 dim.width() - 2, dim.height() - 2, Color::foreground);
54         x += 5;
55
56         drawStrBlack(pi, x, y, from_ascii("["));
57         x += w_;
58         cell(0).draw(pi, x, y);
59         x += cell(0).width();
60         drawStrBlack(pi, x, y, from_ascii("]"));
61         x += w_ + 4;
62
63         drawStrBlack(pi, x, y, from_ascii("["));
64         x += w_;
65         cell(1).draw(pi, x, y);
66         x += cell(1).width();
67         drawStrBlack(pi, x, y, from_ascii("]"));
68         x += w_ + 4;
69
70         cell(2).draw(pi, x, y);
71         drawMarkers(pi, x, y);
72 }
73
74
75 void InsetMathFrameBox::write(WriteStream & os) const
76 {
77         os << "\\framebox";
78         os << '[' << cell(0) << ']';
79         if (cell(1).size())
80                 os << '[' << cell(1) << ']';
81         os << '{' << cell(2) << '}';
82 }
83
84
85 void InsetMathFrameBox::normalize(NormalStream & os) const
86 {
87         os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
88 }
89
90
91 } // namespace lyx