]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
Native support for \smash[t] and \smash[b]
[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 "MathStream.h"
18
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "support/gettext.h"
22 #include "LaTeXFeatures.h"
23
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 // FIXME: handle numbers in gui, currently they are only read and written
36
37 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
38         char valign, bool numbered)
39         : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
40           numbered_(numbered)
41 {
42 }
43
44
45 Inset * InsetMathSplit::clone() const
46 {
47         return new InsetMathSplit(*this);
48 }
49
50
51 char InsetMathSplit::defaultColAlign(col_type col)
52 {
53         if (name_ == "split")
54                 return 'l';
55         if (name_ == "gathered")
56                 return 'c';
57         if (name_ == "aligned" || name_ == "align")
58                 return (col & 1) ? 'l' : 'r';
59         if (name_ == "alignedat")
60                 return (col & 1) ? 'l' : 'r';
61         return 'l';
62 }
63
64
65 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
66 {
67         InsetMathGrid::draw(pi, x, y);
68         setPosCache(pi, x, y);
69 }
70
71
72 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
73                 FuncStatus & flag) const
74 {
75         switch (cmd.action()) {
76         case LFUN_INSET_MODIFY: {
77                 istringstream is(to_utf8(cmd.argument()));
78                 string s;
79                 is >> s;
80                 if (s != "tabular")
81                         break;
82                 is >> s;
83                 if (s == "add-vline-left" || s == "add-vline-right") {
84                         flag.message(bformat(
85                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),       name_));
86                         flag.setEnabled(false);
87                         return true;
88                 }
89                 break;
90         }
91         default:
92                 break;
93         }
94         return InsetMathGrid::getStatus(cur, cmd, flag);
95 }
96
97
98 void InsetMathSplit::write(WriteStream & ws) const
99 {
100         MathEnsurer ensurer(ws);
101         if (ws.fragile())
102                 ws << "\\protect";
103         docstring suffix;
104         if (!numbered_ && name_ == "align")
105                 suffix = from_ascii("*");
106         ws << "\\begin{" << name_ << suffix << '}';
107         if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
108                 ws << '[' << verticalAlignment() << ']';
109         if (name_ == "alignedat")
110                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
111         InsetMathGrid::write(ws);
112         if (ws.fragile())
113                 ws << "\\protect";
114         ws << "\\end{" << name_ << suffix << "}\n";
115 }
116
117
118 void InsetMathSplit::infoize(odocstream & os) const
119 {
120         docstring name = name_;
121         name[0] = support::uppercase(name[0]);
122         if (name_ == "align" && !numbered_)
123                 os << name << "* ";
124         else
125                 os << name << ' ';
126 }
127
128
129 void InsetMathSplit::mathmlize(MathStream & ms) const
130 {
131         // split, gathered, aligned, alignedat
132         // At the moment, those seem to display just fine without any
133         // special treatment.
134         // FIXME
135         // lgathered and rgathered could use the proper alignment, but
136         // it's not clear how to do that without copying a lot of code.
137         // One idea would be to wrap the table in an <mrow>, and set the
138         // alignment there via CSS.
139         // FIXME how to handle numbered and unnumbered align?
140         InsetMathGrid::mathmlize(ms);
141 }
142
143
144 void InsetMathSplit::htmlize(HtmlStream & ms) const
145 {
146         // split, gathered, aligned, alignedat
147         // At the moment, those seem to display just fine without any
148         // special treatment.
149         // FIXME
150         // lgathered and rgathered could use the proper alignment.
151         // FIXME how to handle numbered and unnumbered align?
152         InsetMathGrid::htmlize(ms);
153 }
154
155
156 void InsetMathSplit::validate(LaTeXFeatures & features) const
157 {
158         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
159             name_ == "alignedat" || name_ == "align")
160                 features.require("amsmath");
161         else if (name_ == "lgathered" || name_ == "rgathered")
162                 features.require("mathtools");
163         InsetMathGrid::validate(features);
164 }
165
166
167 } // namespace lyx