]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCases.C
Fix bug 2789 (as discussed)
[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 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 InsetMathCases::InsetMathCases(row_type n)
41         : InsetMathGrid(2, n, 'c', "ll")
42 {}
43
44
45 auto_ptr<InsetBase> InsetMathCases::doClone() const
46 {
47         return auto_ptr<InsetBase>(new InsetMathCases(*this));
48 }
49
50
51 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
52 {
53         InsetMathGrid::metrics(mi);
54         dim_.wid += 8;
55         dim = dim_;
56 }
57
58
59 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
60 {
61         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), "{");
62         InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
63         setPosCache(pi, x, y);
64 }
65
66
67 void InsetMathCases::doDispatch(LCursor & cur, FuncRequest & cmd)
68 {
69         //lyxerr << "*** InsetMathCases: 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                 InsetMathGrid::doDispatch(cur, cmd);
81         }
82 }
83
84
85 bool InsetMathCases::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                                 lyx::from_utf8(N_("No vertical grid lines in '%1$s'")),
95                                 s));
96                         return true;
97                 }
98         }
99         default:
100                 return InsetMathGrid::getStatus(cur, cmd, flag);
101         }
102 }
103
104
105 void InsetMathCases::write(WriteStream & os) const
106 {
107         if (os.fragile())
108                 os << "\\protect";
109         os << "\\begin{cases}\n";
110         InsetMathGrid::write(os);
111         if (os.fragile())
112                 os << "\\protect";
113         os << "\\end{cases}";
114 }
115
116
117 void InsetMathCases::normalize(NormalStream & os) const
118 {
119         os << "[cases ";
120         InsetMathGrid::normalize(os);
121         os << ']';
122 }
123
124
125 void InsetMathCases::maple(MapleStream & os) const
126 {
127         os << "cases(";
128         InsetMathGrid::maple(os);
129         os << ')';
130 }
131
132
133 void InsetMathCases::infoize(std::ostream & os) const
134 {
135         os << "Cases ";
136 }
137
138
139 void InsetMathCases::validate(LaTeXFeatures & features) const
140 {
141         features.require("amsmath");
142         InsetMathGrid::validate(features);
143 }