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