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