]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSubstack.cpp
Remove profiling.py
[lyx.git] / src / mathed / InsetMathSubstack.cpp
1 /**
2  * \file InsetMathSubstack.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 "InsetMathSubstack.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17
18 #include "Cursor.h"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "LaTeXFeatures.h"
22 #include "MetricsInfo.h"
23
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
26
27 #include <ostream>
28
29 using namespace std;
30
31 namespace lyx {
32
33 using support::bformat;
34
35
36 InsetMathSubstack::InsetMathSubstack(Buffer * buf)
37         : InsetMathGrid(buf, 1, 1)
38 {}
39
40
41 Inset * InsetMathSubstack::clone() const
42 {
43         return new InsetMathSubstack(*this);
44 }
45
46
47 void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
48 {
49         Changer dummy2 = mi.base.changeEnsureMath();
50         Changer dummy = mi.base.changeArray();
51         InsetMathGrid::metrics(mi, dim);
52 }
53
54
55 void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
56 {
57         Changer dummy2 = pi.base.changeEnsureMath();
58         Changer dummy = pi.base.changeArray();
59         InsetMathGrid::draw(pi, x + 1, y);
60 }
61
62
63 void InsetMathSubstack::doDispatch(Cursor & cur, FuncRequest & cmd)
64 {
65         switch (cmd.action()) {
66         case LFUN_TABULAR_FEATURE: {
67                 string s = cmd.getArg(0);
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 InsetMathSubstack::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.message(bformat(
89                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
90                                 from_utf8("substack")));
91                         flag.setEnabled(false);
92                         return true;
93                 }
94                 // in contrary to \subarray, the columns in \substack
95                 // are always centered and this cannot be changed
96                 if (s == "align-left" || s == "align-right") {
97                         flag.message(bformat(
98                                 from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
99                                 from_utf8("substack")));
100                         flag.setEnabled(false);
101                         return true;
102                 }
103                 // disallow changing number of columns
104                 if (s == "append-column" || s == "delete-column") {
105                         flag.setEnabled(false);
106                         flag.message(bformat(
107                                 from_utf8(N_("Changing number of columns not allowed in "
108                                              "'%1$s'")), from_utf8("substack")));
109                         return true;
110                 }
111                 break;
112         }
113
114         default:
115                 break;
116         }
117         return InsetMathGrid::getStatus(cur, cmd, flag);
118 }
119
120
121 void InsetMathSubstack::infoize(odocstream & os) const
122 {
123         os << "Substack ";
124 }
125
126
127 void InsetMathSubstack::write(TeXMathStream & os) const
128 {
129         MathEnsurer ensurer(os);
130         if (os.fragile())
131                 os << "\\protect";
132         os << "\\substack{";
133         bool open = os.startOuterRow();
134         InsetMathGrid::write(os);
135         os << "}\n";
136         if (open)
137                 os.startOuterRow();
138 }
139
140
141 void InsetMathSubstack::normalize(NormalStream & os) const
142 {
143         os << "[substack ";
144         InsetMathGrid::normalize(os);
145         os << ']';
146 }
147
148
149 void InsetMathSubstack::maple(MapleStream & os) const
150 {
151         os << "substack(";
152         InsetMathGrid::maple(os);
153         os << ')';
154 }
155
156
157 void InsetMathSubstack::mathmlize(MathMLStream & ms) const
158 {
159         // Output the substack as a standard grid.
160         InsetMathGrid::mathmlize(ms);
161 }
162
163
164 void InsetMathSubstack::htmlize(HtmlStream & os) const
165 {
166         os << MTag("span", "class='substack'");
167         for (row_type row = 0; row < nrows(); ++row)
168                 os << MTag("span") << cell(index(row, 0)) << ETag("span");
169         os << ETag("span");
170 }
171
172
173 void InsetMathSubstack::validate(LaTeXFeatures & features) const
174 {
175         if (features.runparams().isLaTeX())
176                 features.require("amsmath");
177         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
178                 features.addCSSSnippet(
179                         "span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
180                         "span.substack span{display: block;}");
181
182         InsetMathGrid::validate(features);
183 }
184
185
186 } // namespace lyx