]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathTabular.cpp
8d59cbd1df4e6bf241e8374bd082825ae2932f9e
[lyx.git] / src / mathed / InsetMathTabular.cpp
1 /**
2  * \file InsetMathTabular.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 "InsetMathTabular.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathStream.h"
18
19 #include "support/lstrings.h"
20
21 #include <ostream>
22
23 namespace lyx {
24
25 InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n)
26         : InsetMathGrid(m, n), name_(name)
27 {}
28
29
30 InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n,
31                 char valign, docstring const & halign)
32         : InsetMathGrid(m, n, valign, halign), name_(name)
33 {}
34
35
36
37 Inset * InsetMathTabular::clone() const
38 {
39         return new InsetMathTabular(*this);
40 }
41
42
43 void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const
44 {
45         FontSetChanger dummy(mi.base, "textnormal");
46         InsetMathGrid::metrics(mi, dim);
47         dim.wid += 6;
48 }
49
50
51 Dimension const InsetMathTabular::dimension(BufferView const & bv) const
52 {
53         Dimension dim = InsetMathGrid::dimension(bv);
54         dim.wid += 6;
55         return dim;
56 }
57
58
59 void InsetMathTabular::draw(PainterInfo & pi, int x, int y) const
60 {
61         FontSetChanger dummy(pi.base, "textnormal");
62         InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
63 }
64
65
66 void InsetMathTabular::write(WriteStream & os) const
67 {
68         // This is a text mode tabular, so close any previous \ensuremath
69         // command and set the proper mode.
70         if (os.latex() && os.pendingBrace()) {
71                 os.pendingBrace(false);
72                 os << '}';
73         }
74         bool textmode = os.textMode();
75         os.textMode(true);
76
77         if (os.fragile())
78                 os << "\\protect";
79         os << "\\begin{" << name_ << '}';
80
81         char const v = verticalAlignment();
82         if (v == 't' || v == 'b')
83                 os << '[' << v << ']';
84         os << '{' << horizontalAlignments() << "}\n";
85
86         InsetMathGrid::write(os);
87
88         if (os.fragile())
89                 os << "\\protect";
90         os << "\\end{" << name_ << '}';
91         // adding a \n here is bad if the tabular is the last item
92         // in an \eqnarray...
93
94         os.textMode(textmode);
95 }
96
97
98 void InsetMathTabular::infoize(odocstream & os) const
99 {
100         docstring name = name_;
101         name[0] = support::uppercase(name[0]);
102         os << name << ' ';
103 }
104
105
106 void InsetMathTabular::normalize(NormalStream & os) const
107 {
108         os << '[' << name_ << ' ';
109         InsetMathGrid::normalize(os);
110         os << ']';
111 }
112
113
114 void InsetMathTabular::maple(MapleStream & os) const
115 {
116         os << "array(";
117         InsetMathGrid::maple(os);
118         os << ')';
119 }
120
121
122 } // namespace lyx