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