]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathAMSArray.C
This commit cleans up everything related to singleton. The other important change...
[lyx.git] / src / mathed / InsetMathAMSArray.C
1 /**
2  * \file InsetMathAMSArray.C
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 "MathMLStream.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 using lyx::docstring;
29
30 using std::string;
31 using std::auto_ptr;
32 using lyx::support::bformat;
33
34
35 InsetMathAMSArray::InsetMathAMSArray(string const & name, int m, int n)
36         : InsetMathGrid(m, n), name_(name)
37 {}
38
39
40 InsetMathAMSArray::InsetMathAMSArray(string const & name)
41         : InsetMathGrid(1, 1), name_(name)
42 {}
43
44
45 auto_ptr<InsetBase> InsetMathAMSArray::doClone() const
46 {
47         return auto_ptr<InsetBase>(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         dim_ = dim;
89 }
90
91
92 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
93 {
94         int const yy = y - dim_.ascent();
95         // Drawing the deco after an ArrayChanger does not work
96         mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left());
97         mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), name_right());
98         ArrayChanger dummy(pi.base);
99         InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
100 }
101
102
103 bool InsetMathAMSArray::getStatus(LCursor & cur, FuncRequest const & cmd,
104                 FuncStatus & flag) const
105 {
106         switch (cmd.action) {
107         case LFUN_TABULAR_FEATURE: {
108                 docstring const & s = cmd.argument();
109                 if (s == "add-vline-left" || s == "add-vline-right") {
110                         flag.message(bformat(
111                         lyx::from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
112                                 lyx::from_utf8(name_)));
113                         flag.enabled(false);
114                         return true;
115                 }
116                 return InsetMathGrid::getStatus(cur, cmd, flag);
117         }
118         default:
119                 return InsetMathGrid::getStatus(cur, cmd, flag);
120         }
121 }
122
123
124 void InsetMathAMSArray::write(WriteStream & os) const
125 {
126         os << "\\begin{" << name_ << '}';
127         InsetMathGrid::write(os);
128         os << "\\end{" << name_ << '}';
129 }
130
131
132 void InsetMathAMSArray::infoize(std::ostream & os) const
133 {
134         string name = name_;
135         name[0] = lyx::support::uppercase(name[0]);
136         os << name << ' ';
137 }
138
139
140 void InsetMathAMSArray::normalize(NormalStream & os) const
141 {
142         os << '[' << name_ << ' ';
143         InsetMathGrid::normalize(os);
144         os << ']';
145 }
146
147
148 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
149 {
150         features.require("amsmath");
151         InsetMathGrid::validate(features);
152 }