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