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