]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathAMSArray.cpp
Fixed some lines that were too long. It compiled afterwards.
[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 using std::auto_ptr;
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 auto_ptr<Inset> InsetMathAMSArray::doClone() const
45 {
46         return auto_ptr<Inset>(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 bool InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
83 {
84         ArrayChanger dummy(mi.base);
85         InsetMathGrid::metrics(mi, dim);
86         dim.wid += 14;
87         bool const changed = dim_ != dim;
88         dim_ = dim;
89         return changed;
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(), from_ascii(name_left()));
98         mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right()));
99         ArrayChanger dummy(pi.base);
100         InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
101 }
102
103
104 bool InsetMathAMSArray::getStatus(Cursor & 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'")),       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(odocstream & os) const
133 {
134         docstring name = name_;
135         name[0] = 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 }
153
154
155 } // namespace lyx