]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathAMSArray.cpp
cosmetics
[lyx.git] / src / mathed / InsetMathAMSArray.cpp
1 /**
2  * \file InsetMathAMSArray.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 "InsetMathAMSArray.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MetricsInfo.h"
20
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "gettext.h"
24
25 #include "support/lstrings.h"
26 #include "support/std_ostream.h"
27
28
29 namespace lyx {
30
31 using support::bformat;
32
33
34 InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n)
35         : InsetMathGrid(m, n), name_(name)
36 {}
37
38
39 InsetMathAMSArray::InsetMathAMSArray(docstring const & name)
40         : InsetMathGrid(1, 1), name_(name)
41 {}
42
43
44 Inset * InsetMathAMSArray::clone() const
45 {
46         return new InsetMathAMSArray(*this);
47 }
48
49
50 char const * InsetMathAMSArray::name_left() const
51 {
52         if (name_ == "bmatrix")
53                 return "[";
54         if (name_ == "Bmatrix")
55                 return "{";
56         if (name_ == "vmatrix")
57                 return "|";
58         if (name_ == "Vmatrix")
59                 return "Vert";
60         if (name_ == "pmatrix")
61                 return "(";
62         return ".";
63 }
64
65
66 char const * InsetMathAMSArray::name_right() const
67 {
68         if (name_ == "bmatrix")
69                 return "]";
70         if (name_ == "Bmatrix")
71                 return "}";
72         if (name_ == "vmatrix")
73                 return "|";
74         if (name_ == "Vmatrix")
75                 return "Vert";
76         if (name_ == "pmatrix")
77                 return ")";
78         return ".";
79 }
80
81
82 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
83 {
84         ArrayChanger dummy(mi.base);
85         InsetMathGrid::metrics(mi, dim);
86         dim.wid += 14;
87 }
88
89
90 Dimension const InsetMathAMSArray::dimension(BufferView const & bv) const
91 {
92         Dimension dim = InsetMathGrid::dimension(bv);
93         dim.wid += 14;
94         return dim;
95 }
96
97
98 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
99 {
100         Dimension const dim = dimension(*pi.base.bv);
101         int const yy = y - dim.ascent();
102         // Drawing the deco after an ArrayChanger does not work
103         mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
104         mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
105         ArrayChanger dummy(pi.base);
106         InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
107 }
108
109
110 bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
111                 FuncStatus & flag) const
112 {
113         switch (cmd.action) {
114         case LFUN_TABULAR_FEATURE: {
115                 docstring const & s = cmd.argument();
116                 if (s == "add-vline-left" || s == "add-vline-right") {
117                         flag.message(bformat(
118                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),       name_));
119                         flag.enabled(false);
120                         return true;
121                 }
122                 return InsetMathGrid::getStatus(cur, cmd, flag);
123         }
124         default:
125                 return InsetMathGrid::getStatus(cur, cmd, flag);
126         }
127 }
128
129
130 void InsetMathAMSArray::write(WriteStream & os) const
131 {
132         os << "\\begin{" << name_ << '}';
133         InsetMathGrid::write(os);
134         os << "\\end{" << name_ << '}';
135 }
136
137
138 void InsetMathAMSArray::infoize(odocstream & os) const
139 {
140         docstring name = name_;
141         name[0] = support::uppercase(name[0]);
142         os << name << ' ';
143 }
144
145
146 void InsetMathAMSArray::normalize(NormalStream & os) const
147 {
148         os << '[' << name_ << ' ';
149         InsetMathGrid::normalize(os);
150         os << ']';
151 }
152
153
154 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
155 {
156         features.require("amsmath");
157         InsetMathGrid::validate(features);
158 }
159
160
161 } // namespace lyx