]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
rename MathArray into MathData
[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 #include "MathData.h"
15 #include "MathStream.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(docstring const & name, char valign)
36         : InsetMathGrid(1, 1, valign, docstring()), 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(Cursor & 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'")),       name_));
77                         flag.enabled(false);
78                         return true;
79                 }
80                 return InsetMathGrid::getStatus(cur, cmd, flag);
81         }
82         default:
83                 return InsetMathGrid::getStatus(cur, cmd, flag);
84         }
85 }
86
87
88 void InsetMathSplit::write(WriteStream & ws) const
89 {
90         if (ws.fragile())
91                 ws << "\\protect";
92         ws << "\\begin{" << name_ << '}';
93         if (name_ != "split" && valign() != 'c')
94                 ws << '[' << valign() << ']';
95         if (name_ == "alignedat")
96                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
97         InsetMathGrid::write(ws);
98         if (ws.fragile())
99                 ws << "\\protect";
100         ws << "\\end{" << name_ << "}\n";
101 }
102
103
104 void InsetMathSplit::infoize(odocstream & os) const
105 {
106         docstring name = name_;
107         name[0] = support::uppercase(name[0]);
108         os << name << ' ';
109 }
110
111
112 void InsetMathSplit::validate(LaTeXFeatures & features) const
113 {
114         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
115             name_ == "alignedat")
116                 features.require("amsmath");
117         InsetMathGrid::validate(features);
118 }
119
120
121 } // namespace lyx