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