]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
* gcc does not like missing characters in keywords
[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
33
34 InsetMathSplit::InsetMathSplit(docstring const & name, char valign)
35         : InsetMathGrid(1, 1, valign, docstring()), name_(name)
36 {
37 }
38
39
40 Inset * InsetMathSplit::clone() const
41 {
42         return new InsetMathSplit(*this);
43 }
44
45
46 char InsetMathSplit::defaultColAlign(col_type col)
47 {
48         if (name_ == "split")
49                 return 'l';
50         if (name_ == "gathered")
51                 return 'c';
52         if (name_ == "aligned")
53                 return (col & 1) ? 'l' : 'r';
54         if (name_ == "alignedat")
55                 return (col & 1) ? 'l' : 'r';
56         return 'l';
57 }
58
59
60 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
61 {
62         InsetMathGrid::draw(pi, x, y);
63         setPosCache(pi, x, y);
64 }
65
66
67 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
68                 FuncStatus & flag) const
69 {
70         switch (cmd.action) {
71         case LFUN_TABULAR_FEATURE: {
72                 docstring const & s = cmd.argument();
73                 if (s == "add-vline-left" || s == "add-vline-right") {
74                         flag.message(bformat(
75                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),       name_));
76                         flag.enabled(false);
77                         return true;
78                 }
79                 return InsetMathGrid::getStatus(cur, cmd, flag);
80         }
81         default:
82                 return InsetMathGrid::getStatus(cur, cmd, flag);
83         }
84 }
85
86
87 void InsetMathSplit::write(WriteStream & ws) const
88 {
89         if (ws.fragile())
90                 ws << "\\protect";
91         ws << "\\begin{" << name_ << '}';
92         if (name_ != "split" && valign() != 'c')
93                 ws << '[' << valign() << ']';
94         if (name_ == "alignedat")
95                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
96         InsetMathGrid::write(ws);
97         if (ws.fragile())
98                 ws << "\\protect";
99         ws << "\\end{" << name_ << "}\n";
100 }
101
102
103 void InsetMathSplit::infoize(odocstream & os) const
104 {
105         docstring name = name_;
106         name[0] = support::uppercase(name[0]);
107         os << name << ' ';
108 }
109
110
111 void InsetMathSplit::validate(LaTeXFeatures & features) const
112 {
113         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
114             name_ == "alignedat")
115                 features.require("amsmath");
116         InsetMathGrid::validate(features);
117 }
118
119
120 } // namespace lyx