]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCases.cpp
rename LCursor->Cursor
[lyx.git] / src / mathed / InsetMathCases.cpp
1 /**
2  * \file InsetMathCases.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 "InsetMathCases.h"
14 #include "MathArray.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "support/std_ostream.h"
20 #include "Cursor.h"
21 #include "FuncRequest.h"
22 #include "gettext.h"
23 #include "Undo.h"
24
25 #include "support/lstrings.h"
26
27
28 namespace lyx {
29
30 using support::bformat;
31
32 using std::endl;
33 using std::max;
34 using std::min;
35 using std::swap;
36 using std::auto_ptr;
37
38
39 InsetMathCases::InsetMathCases(row_type n)
40         : InsetMathGrid(2, n, 'c', from_ascii("ll"))
41 {}
42
43
44 auto_ptr<InsetBase> InsetMathCases::doClone() const
45 {
46         return auto_ptr<InsetBase>(new InsetMathCases(*this));
47 }
48
49
50 bool InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
51 {
52         dim = dim_;
53         InsetMathGrid::metrics(mi);
54         dim_.wid += 8;
55
56         if (dim_ == dim)
57                 return false;
58         dim = dim_;
59         return true;
60 }
61
62
63 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
64 {
65         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), from_ascii("{"));
66         InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
67         setPosCache(pi, x, y);
68 }
69
70
71 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
72 {
73         //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
74         switch (cmd.action) {
75         case LFUN_TABULAR_FEATURE: {
76                 recordUndo(cur);
77                 docstring const & s = cmd.argument();
78                 if (s == "add-vline-left" || s == "add-vline-right") {
79                         cur.undispatched();
80                         break;
81                 }
82         }
83         default:
84                 InsetMathGrid::doDispatch(cur, cmd);
85         }
86 }
87
88
89 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
90                 FuncStatus & flag) const
91 {
92         switch (cmd.action) {
93         case LFUN_TABULAR_FEATURE: {
94                 docstring const & s = cmd.argument();
95                 if (s == "add-vline-left" || s == "add-vline-right") {
96                         flag.enabled(false);
97                         flag.message(bformat(
98                                 from_utf8(N_("No vertical grid lines in '%1$s'")),
99                                 s));
100                         return true;
101                 }
102         }
103         default:
104                 return InsetMathGrid::getStatus(cur, cmd, flag);
105         }
106 }
107
108
109 void InsetMathCases::write(WriteStream & os) const
110 {
111         if (os.fragile())
112                 os << "\\protect";
113         os << "\\begin{cases}\n";
114         InsetMathGrid::write(os);
115         if (os.fragile())
116                 os << "\\protect";
117         os << "\\end{cases}";
118 }
119
120
121 void InsetMathCases::normalize(NormalStream & os) const
122 {
123         os << "[cases ";
124         InsetMathGrid::normalize(os);
125         os << ']';
126 }
127
128
129 void InsetMathCases::maple(MapleStream & os) const
130 {
131         os << "cases(";
132         InsetMathGrid::maple(os);
133         os << ')';
134 }
135
136
137 void InsetMathCases::infoize(odocstream & os) const
138 {
139         os << "Cases ";
140 }
141
142
143 void InsetMathCases::validate(LaTeXFeatures & features) const
144 {
145         features.require("amsmath");
146         InsetMathGrid::validate(features);
147 }
148
149
150 } // namespace lyx