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