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