]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
Disable append-column with gathered
[lyx.git] / src / mathed / InsetMathSplit.cpp
1 /**
2  * \file InsetMathSplit.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 "InsetMathSplit.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18
19 #include "Buffer.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "support/gettext.h"
23 #include "LaTeXFeatures.h"
24 #include "MetricsInfo.h"
25
26 #include "support/lstrings.h"
27
28 #include <ostream>
29
30 using namespace std;
31
32 namespace lyx {
33
34 using support::bformat;
35
36
37 // FIXME: handle numbers in gui, currently they are only read and written
38
39 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
40         char valign, bool numbered)
41         : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
42           numbered_(numbered)
43 {
44 }
45
46
47 Inset * InsetMathSplit::clone() const
48 {
49         return new InsetMathSplit(*this);
50 }
51
52
53 char InsetMathSplit::defaultColAlign(col_type col)
54 {
55         if (name_ == "gathered")
56                 return 'c';
57         if (name_ == "lgathered")
58                 return 'l';
59         if (name_ == "rgathered")
60                 return 'r';
61         if (name_ == "split"
62             || name_ == "aligned"
63             || name_ == "align"
64             || name_ == "alignedat")
65                 return colAlign(hullAlign, col);
66         return 'l';
67 }
68
69
70 char InsetMathSplit::displayColAlign(idx_type idx) const
71 {
72         if (name_ == "gathered")
73                 return 'c';
74         if (name_ == "lgathered")
75                 return 'l';
76         if (name_ == "rgathered")
77                 return 'r';
78         if (name_ == "split"
79             || name_ == "aligned"
80             || name_ == "align"
81             || name_ == "alignedat")
82                 return colAlign(hullAlign, col(idx));
83         return InsetMathGrid::displayColAlign(idx);
84 }
85
86
87 int InsetMathSplit::displayColSpace(col_type col) const
88 {
89         if (name_ == "split" || name_ == "aligned" || name_ == "align")
90                 return colSpace(hullAlign, col);
91         if (name_ == "alignedat")
92                 return colSpace(hullAlignAt, col);
93         return 0;
94 }
95
96
97
98 void InsetMathSplit::metrics(MetricsInfo & mi, Dimension & dim) const
99 {
100         Changer dummy = mi.base.changeEnsureMath();
101         InsetMathGrid::metrics(mi, dim);
102 }
103
104
105
106 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
107 {
108         Changer dummy = pi.base.changeEnsureMath();
109         InsetMathGrid::draw(pi, x, y);
110 }
111
112
113 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
114                 FuncStatus & flag) const
115 {
116         switch (cmd.action()) {
117         case LFUN_TABULAR_FEATURE: {
118                 string s = cmd.getArg(0);
119                 if (s == "append-column"
120                     && (name_ == "gathered" || name_ == "lgathered" || name_ == "rgathered")) {
121                         // gathered does not support multiple columns
122                         flag.setEnabled(false);
123                         return true;
124                 }
125                 if (s == "add-vline-left" || s == "add-vline-right") {
126                         flag.message(bformat(
127                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
128                                 name_));
129                         flag.setEnabled(false);
130                         return true;
131                 }
132                 if (s == "align-left" || s == "align-center" || s == "align-right") {
133                         flag.setEnabled(false);
134                         return true;
135                 }
136                 break;
137         }
138         default:
139                 break;
140         }
141         return InsetMathGrid::getStatus(cur, cmd, flag);
142 }
143
144
145 void InsetMathSplit::write(WriteStream & ws) const
146 {
147         MathEnsurer ensurer(ws);
148         if (ws.fragile())
149                 ws << "\\protect";
150         docstring suffix;
151         if (!numbered_ && name_ == "align")
152                 suffix = from_ascii("*");
153         ws << "\\begin{" << name_ << suffix << '}';
154         bool open = ws.startOuterRow();
155         bool const hasArg(name_ == "alignedat");
156         if (name_ != "split" && name_ != "align") {
157                 if (verticalAlignment() != 'c')
158                         ws << '[' << verticalAlignment() << ']';
159                 else if (!hasArg) {
160                         docstring const first(asString(cell(0)));
161                         // prevent misinterpretation of the first character of
162                         // the first cell as optional argument (bug 10361)
163                         if (!first.empty() && first[0] == '[')
164                                 ws << "[]";
165                 }
166         }
167         if (hasArg)
168                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
169         InsetMathGrid::write(ws);
170         if (ws.fragile())
171                 ws << "\\protect";
172         ws << "\\end{" << name_ << suffix << "}\n";
173         if (open)
174                 ws.startOuterRow();
175 }
176
177
178 void InsetMathSplit::infoize(odocstream & os) const
179 {
180         docstring name = name_;
181         name[0] = support::uppercase(name[0]);
182         if (name_ == "align" && !numbered_)
183                 os << name << "* ";
184         else
185                 os << name << ' ';
186 }
187
188
189 void InsetMathSplit::mathmlize(MathStream & ms) const
190 {
191         // split, gathered, aligned, alignedat
192         // At the moment, those seem to display just fine without any
193         // special treatment.
194         // FIXME
195         // lgathered and rgathered could use the proper alignment, but
196         // it's not clear how to do that without copying a lot of code.
197         // One idea would be to wrap the table in an <mrow>, and set the
198         // alignment there via CSS.
199         // FIXME how to handle numbered and unnumbered align?
200         InsetMathGrid::mathmlize(ms);
201 }
202
203
204 void InsetMathSplit::htmlize(HtmlStream & ms) const
205 {
206         // split, gathered, aligned, alignedat
207         // At the moment, those seem to display just fine without any
208         // special treatment.
209         // FIXME
210         // lgathered and rgathered could use the proper alignment.
211         // FIXME how to handle numbered and unnumbered align?
212         InsetMathGrid::htmlize(ms);
213 }
214
215
216 void InsetMathSplit::validate(LaTeXFeatures & features) const
217 {
218         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
219             name_ == "alignedat" || name_ == "align")
220                 features.require("amsmath");
221         else if (name_ == "lgathered" || name_ == "rgathered")
222                 features.require("mathtools");
223         InsetMathGrid::validate(features);
224 }
225
226
227 } // namespace lyx