]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCases.cpp
Get rid of Inset::setPosCache
[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
15 #include "Cursor.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "support/gettext.h"
19 #include "LaTeXFeatures.h"
20 #include "MathData.h"
21 #include "MathStream.h"
22 #include "MathSupport.h"
23 #include "MetricsInfo.h"
24
25 #include "support/lstrings.h"
26
27 #include <ostream>
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33
34
35 InsetMathCases::InsetMathCases(Buffer * buf, row_type n)
36         : InsetMathGrid(buf, 2, n, 'c', from_ascii("ll"))
37 {}
38
39
40 Inset * InsetMathCases::clone() const
41 {
42         return new InsetMathCases(*this);
43 }
44
45
46 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         Changer dummy = mi.base.changeEnsureMath();
49         InsetMathGrid::metrics(mi, dim);
50 }
51
52
53 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
54 {
55         Changer dummy = pi.base.changeEnsureMath();
56         Dimension const dim = dimension(*pi.base.bv);
57         mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
58         InsetMathGrid::draw(pi, x, y);
59 }
60
61
62 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
63 {
64         //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
65         switch (cmd.action()) {
66         case LFUN_TABULAR_FEATURE: {
67                 string s = cmd.getArg(0);
68                 // vertical lines and adding/deleting columns is not allowed for \cases
69                 // FIXME: "I suspect that the break after cur.undispatched() should be a
70                 // return; the recordUndo seems bogus too." (lasgouttes)
71                 if (s == "append-column" || s == "delete-column"
72                     || s == "add-vline-left" || s == "add-vline-right") {
73                         cur.undispatched();
74                         break;
75                 }
76                 cur.recordUndo();
77         }
78         default:
79                 break;
80         }
81         InsetMathGrid::doDispatch(cur, cmd);
82 }
83
84
85 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
86                 FuncStatus & flag) const
87 {
88         switch (cmd.action()) {
89         case LFUN_TABULAR_FEATURE: {
90                 string s = cmd.getArg(0);
91                 if (s == "add-vline-left" || s == "add-vline-right") {
92                         flag.setEnabled(false);
93                         flag.message(bformat(
94                                 from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
95                                 from_utf8(s)));
96                         return true;
97                 }
98                 if (s == "append-column" || s == "delete-column") {
99                         flag.setEnabled(false);
100                         flag.message(bformat(
101                                 from_utf8(N_("Changing number of columns not allowed in "
102                                              "'cases': feature %1$s")), from_utf8(s)));
103                         return true;
104                 }
105                 break;
106         }
107         default:
108                 break;
109         }
110         return InsetMathGrid::getStatus(cur, cmd, flag);
111 }
112
113
114 void InsetMathCases::write(WriteStream & os) const
115 {
116         MathEnsurer ensurer(os);
117         if (os.fragile())
118                 os << "\\protect";
119         bool open = os.startOuterRow();
120         os << "\\begin{cases}\n";
121         InsetMathGrid::write(os);
122         if (os.fragile())
123                 os << "\\protect";
124         os << "\\end{cases}";
125         if (open)
126                 os.startOuterRow();
127 }
128
129
130 void InsetMathCases::normalize(NormalStream & os) const
131 {
132         os << "[cases ";
133         InsetMathGrid::normalize(os);
134         os << ']';
135 }
136
137
138 void InsetMathCases::maple(MapleStream & os) const
139 {
140         os << "cases(";
141         InsetMathGrid::maple(os);
142         os << ')';
143 }
144
145
146 void InsetMathCases::mathmlize(MathStream & ms) const
147 {
148         ms << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>{</mo>";
149         InsetMathGrid::mathmlize(ms);
150 }
151
152
153 // FIXME XHTML
154 // We need a brace here, somehow.
155 void InsetMathCases::htmlize(HtmlStream & ms) const
156 {
157         InsetMathGrid::htmlize(ms, "class='cases'");
158 }
159
160
161 void InsetMathCases::infoize(odocstream & os) const
162 {
163         os << "Cases ";
164 }
165
166
167 void InsetMathCases::validate(LaTeXFeatures & features) const
168 {
169         features.require("amsmath");
170         InsetMathGrid::validate(features);
171         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
172                 // CSS based on eLyXer's, with modifications suggested in bug #8755
173                 features.addCSSSnippet(
174                         "table.cases{display: inline-block; text-align: center; border: none;"
175                         "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
176                         "table.cases td {text-align: left; border: none;}");
177 }
178
179
180 int InsetMathCases::displayColSpace(col_type) const
181 {
182         return 20;
183 }
184
185
186 } // namespace lyx