]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.C
move everything into namespace lyx
[lyx.git] / src / mathed / InsetMathSplit.C
1 /**
2  * \file InsetMathSplit.C
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 #include "MathData.h"
15 #include "MathMLStream.h"
16 #include "MathStream.h"
17
18 #include "funcrequest.h"
19 #include "FuncStatus.h"
20 #include "gettext.h"
21 #include "LaTeXFeatures.h"
22
23 #include "support/lstrings.h"
24 #include "support/std_ostream.h"
25
26
27 namespace lyx {
28
29 using support::bformat;
30
31 using std::string;
32 using std::auto_ptr;
33
34
35 InsetMathSplit::InsetMathSplit(string const & name, char valign)
36         : InsetMathGrid(1, 1, valign, string()), name_(name)
37 {
38 }
39
40
41 auto_ptr<InsetBase> InsetMathSplit::doClone() const
42 {
43         return auto_ptr<InsetBase>(new InsetMathSplit(*this));
44 }
45
46
47 char InsetMathSplit::defaultColAlign(col_type col)
48 {
49         if (name_ == "split")
50                 return 'l';
51         if (name_ == "gathered")
52                 return 'c';
53         if (name_ == "aligned")
54                 return (col & 1) ? 'l' : 'r';
55         if (name_ == "alignedat")
56                 return (col & 1) ? 'l' : 'r';
57         return 'l';
58 }
59
60
61 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
62 {
63         InsetMathGrid::draw(pi, x, y);
64         setPosCache(pi, x, y);
65 }
66
67
68 bool InsetMathSplit::getStatus(LCursor & cur, FuncRequest const & cmd,
69                 FuncStatus & flag) const
70 {
71         switch (cmd.action) {
72         case LFUN_TABULAR_FEATURE: {
73                 docstring const & s = cmd.argument();
74                 if (s == "add-vline-left" || s == "add-vline-right") {
75                         flag.message(bformat(
76                         from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
77                         from_utf8(name_)));
78                         flag.enabled(false);
79                         return true;
80                 }
81                 return InsetMathGrid::getStatus(cur, cmd, flag);
82         }
83         default:
84                 return InsetMathGrid::getStatus(cur, cmd, flag);
85         }
86 }
87
88
89 void InsetMathSplit::write(WriteStream & ws) const
90 {
91         if (ws.fragile())
92                 ws << "\\protect";
93         ws << "\\begin{" << name_ << '}';
94         if (name_ != "split" && valign() != 'c')
95                 ws << '[' << valign() << ']';
96         if (name_ == "alignedat")
97                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
98         InsetMathGrid::write(ws);
99         if (ws.fragile())
100                 ws << "\\protect";
101         ws << "\\end{" << name_ << "}\n";
102 }
103
104
105 void InsetMathSplit::infoize(std::ostream & os) const
106 {
107         string name = name_;
108         name[0] = support::uppercase(name[0]);
109         os << name << ' ';
110 }
111
112
113 void InsetMathSplit::validate(LaTeXFeatures & features) const
114 {
115         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
116             name_ == "alignedat")
117                 features.require("amsmath");
118         InsetMathGrid::validate(features);
119 }
120
121
122 } // namespace lyx