]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSubstack.cpp
The previous commit was actually a fix for bug #9158.
[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 "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25
26 #include <ostream>
27
28 using namespace std;
29
30 namespace lyx {
31
32 using support::bformat;
33
34
35 InsetMathSubstack::InsetMathSubstack(Buffer * buf)
36         : InsetMathGrid(buf, 1, 1)
37 {}
38
39
40 Inset * InsetMathSubstack::clone() const
41 {
42         return new InsetMathSubstack(*this);
43 }
44
45
46 void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         Changer dummy = mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY);
49         InsetMathGrid::metrics(mi, dim);
50 }
51
52
53 void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
54 {
55         Changer dummy = pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY);
56         InsetMathGrid::draw(pi, x + 1, y);
57 }
58
59
60 bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
61                 FuncStatus & flag) const
62 {
63         switch (cmd.action()) {
64         case LFUN_TABULAR_FEATURE: {
65                 string s = cmd.getArg(0);
66                 if (s == "add-vline-left" || s == "add-vline-right") {
67                         flag.message(bformat(
68                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
69                                 from_utf8("substack")));
70                         flag.setEnabled(false);
71                         return true;
72                 }
73                 // in contrary to \subarray, the columns in \substack
74                 // are always centered and this cannot be changed
75                 if (s == "align-left" || s == "align-right") {
76                         flag.message(bformat(
77                                 from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
78                                 from_utf8("substack")));
79                         flag.setEnabled(false);
80                         return true;
81                 }
82                 break;
83         }
84
85         default:
86                 break;
87         }
88         return InsetMathGrid::getStatus(cur, cmd, flag);
89 }
90
91
92 void InsetMathSubstack::infoize(odocstream & os) const
93 {
94         os << "Substack ";
95 }
96
97
98 void InsetMathSubstack::write(WriteStream & os) const
99 {
100         MathEnsurer ensurer(os);
101         os << "\\substack{";
102         bool open = os.startOuterRow();
103         InsetMathGrid::write(os);
104         os << "}\n";
105         if (open)
106                 os.startOuterRow();
107 }
108
109
110 void InsetMathSubstack::normalize(NormalStream & os) const
111 {
112         os << "[substack ";
113         InsetMathGrid::normalize(os);
114         os << ']';
115 }
116
117
118 void InsetMathSubstack::maple(MapleStream & os) const
119 {
120         os << "substack(";
121         InsetMathGrid::maple(os);
122         os << ')';
123 }
124
125
126 void InsetMathSubstack::mathmlize(MathStream & os) const
127 {
128         int movers = 0;
129         row_type const numrows = nrows();
130         for (row_type row = 0; row < nrows(); ++row) {
131                 if (row < numrows - 1) {
132                         movers ++;
133                         os << MTag("munder");
134                 }
135                 os << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
136         }
137         for (int i = 1; i <= movers; ++i)
138                 os << ETag("munder");
139 }
140
141
142 void InsetMathSubstack::htmlize(HtmlStream & os) const
143 {
144         os << MTag("span", "class='substack'");
145         for (row_type row = 0; row < nrows(); ++row)
146                 os << MTag("span") << cell(index(row, 0)) << ETag("span");
147         os << ETag("span");
148 }
149
150
151 void InsetMathSubstack::validate(LaTeXFeatures & features) const
152 {
153         if (features.runparams().isLaTeX())
154                 features.require("amsmath");
155         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
156                 features.addCSSSnippet(
157                         "span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
158                         "span.substack span{display: block;}");
159
160         InsetMathGrid::validate(features);
161 }
162
163
164 } // namespace lyx