]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCases.cpp
Fix CSS
[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 rows)
36         : InsetMathGrid(buf, 2, rows, '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         switch (cmd.action()) {
65         case LFUN_TABULAR_FEATURE: {
66                 string s = cmd.getArg(0);
67                 // vertical lines and adding/deleting columns is not allowed for \cases
68                 if (s == "append-column" || s == "delete-column"
69                     || s == "add-vline-left" || s == "add-vline-right") {
70                         cur.undispatched();
71                         return;
72                 }
73         }
74         default:
75                 break;
76         }
77         InsetMathGrid::doDispatch(cur, cmd);
78 }
79
80
81 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
82                 FuncStatus & flag) const
83 {
84         switch (cmd.action()) {
85         case LFUN_TABULAR_FEATURE: {
86                 string s = cmd.getArg(0);
87                 if (s == "add-vline-left" || s == "add-vline-right") {
88                         flag.setEnabled(false);
89                         flag.message(bformat(
90                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
91                                 from_utf8("cases")));
92                         return true;
93                 }
94                 if (s == "append-column" || s == "delete-column") {
95                         flag.setEnabled(false);
96                         flag.message(bformat(
97                                 from_utf8(N_("Changing number of columns not allowed in "
98                                              "'%1$s'")), from_utf8("cases")));
99                         return true;
100                 }
101                 break;
102         }
103         default:
104                 break;
105         }
106         return InsetMathGrid::getStatus(cur, cmd, flag);
107 }
108
109
110 void InsetMathCases::write(TeXMathStream & os) const
111 {
112         MathEnsurer ensurer(os);
113         if (os.fragile())
114                 os << "\\protect";
115         bool open = os.startOuterRow();
116         os << "\\begin{cases}\n";
117         InsetMathGrid::write(os);
118         if (os.fragile())
119                 os << "\\protect";
120         os << "\\end{cases}";
121         if (open)
122                 os.startOuterRow();
123 }
124
125
126 void InsetMathCases::normalize(NormalStream & os) const
127 {
128         os << "[cases ";
129         InsetMathGrid::normalize(os);
130         os << ']';
131 }
132
133
134 void InsetMathCases::maple(MapleStream & os) const
135 {
136         os << "cases(";
137         InsetMathGrid::maple(os);
138         os << ')';
139 }
140
141
142 void InsetMathCases::mathmlize(MathMLStream & ms) const
143 {
144         ms << "<" << from_ascii(ms.namespacedTag("mo"))
145            << " form='prefix' fence='true' stretchy='true' symmetric='true'>"
146            << "{"
147            << "</" << from_ascii(ms.namespacedTag("mo")) << ">";
148         InsetMathGrid::mathmlize(ms);
149 }
150
151
152 // FIXME XHTML
153 // We need a brace here, somehow.
154 void InsetMathCases::htmlize(HtmlStream & ms) const
155 {
156         InsetMathGrid::htmlize(ms, "class='cases'");
157 }
158
159
160 void InsetMathCases::infoize(odocstream & os) const
161 {
162         os << "Cases ";
163 }
164
165
166 void InsetMathCases::validate(LaTeXFeatures & features) const
167 {
168         features.require("amsmath");
169         InsetMathGrid::validate(features);
170         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
171                 // CSS based on eLyXer's, with modifications suggested in bug #8755
172                 features.addCSSSnippet(
173                         "table.cases{display: inline-block; text-align: center; border: none;"
174                         "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
175                         "table.cases td {text-align: left; border: none;}");
176 }
177
178
179 int InsetMathCases::displayColSpace(col_type) const
180 {
181         return 20;
182 }
183
184
185 } // namespace lyx