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