]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
Allow automatic text direction in Painter::text()
[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_TABULAR_FEATURE: {
77                 string s = cmd.getArg(0);
78                 if (s == "add-vline-left" || s == "add-vline-right") {
79                         flag.message(bformat(
80                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
81                                 name_));
82                         flag.setEnabled(false);
83                         return true;
84                 }
85                 break;
86         }
87         default:
88                 break;
89         }
90         return InsetMathGrid::getStatus(cur, cmd, flag);
91 }
92
93
94 void InsetMathSplit::write(WriteStream & ws) const
95 {
96         MathEnsurer ensurer(ws);
97         if (ws.fragile())
98                 ws << "\\protect";
99         docstring suffix;
100         if (!numbered_ && name_ == "align")
101                 suffix = from_ascii("*");
102         ws << "\\begin{" << name_ << suffix << '}';
103         bool open = ws.startOuterRow();
104         if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
105                 ws << '[' << verticalAlignment() << ']';
106         if (name_ == "alignedat")
107                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
108         InsetMathGrid::write(ws);
109         if (ws.fragile())
110                 ws << "\\protect";
111         ws << "\\end{" << name_ << suffix << "}\n";
112         if (open)
113                 ws.startOuterRow();
114 }
115
116
117 void InsetMathSplit::infoize(odocstream & os) const
118 {
119         docstring name = name_;
120         name[0] = support::uppercase(name[0]);
121         if (name_ == "align" && !numbered_)
122                 os << name << "* ";
123         else
124                 os << name << ' ';
125 }
126
127
128 void InsetMathSplit::mathmlize(MathStream & ms) const
129 {
130         // split, gathered, aligned, alignedat
131         // At the moment, those seem to display just fine without any
132         // special treatment.
133         // FIXME
134         // lgathered and rgathered could use the proper alignment, but
135         // it's not clear how to do that without copying a lot of code.
136         // One idea would be to wrap the table in an <mrow>, and set the
137         // alignment there via CSS.
138         // FIXME how to handle numbered and unnumbered align?
139         InsetMathGrid::mathmlize(ms);
140 }
141
142
143 void InsetMathSplit::htmlize(HtmlStream & ms) const
144 {
145         // split, gathered, aligned, alignedat
146         // At the moment, those seem to display just fine without any
147         // special treatment.
148         // FIXME
149         // lgathered and rgathered could use the proper alignment.
150         // FIXME how to handle numbered and unnumbered align?
151         InsetMathGrid::htmlize(ms);
152 }
153
154
155 void InsetMathSplit::validate(LaTeXFeatures & features) const
156 {
157         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
158             name_ == "alignedat" || name_ == "align")
159                 features.require("amsmath");
160         else if (name_ == "lgathered" || name_ == "rgathered")
161                 features.require("mathtools");
162         InsetMathGrid::validate(features);
163 }
164
165
166 } // namespace lyx