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