]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSplit.cpp
Add comment.
[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_TABULAR_FEATURE: {
74                 docstring const & s = cmd.argument();
75                 if (s == "add-vline-left" || s == "add-vline-right") {
76                         flag.message(bformat(
77                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),       name_));
78                         flag.setEnabled(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         MathEnsurer ensurer(ws);
92         if (ws.fragile())
93                 ws << "\\protect";
94         ws << "\\begin{" << name_ << '}';
95         if (name_ != "split" && verticalAlignment() != 'c')
96                 ws << '[' << verticalAlignment() << ']';
97         if (name_ == "alignedat")
98                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
99         InsetMathGrid::write(ws);
100         if (ws.fragile())
101                 ws << "\\protect";
102         ws << "\\end{" << name_ << "}\n";
103 }
104
105
106 void InsetMathSplit::infoize(odocstream & os) const
107 {
108         docstring name = name_;
109         name[0] = support::uppercase(name[0]);
110         os << name << ' ';
111 }
112
113
114 void InsetMathSplit::validate(LaTeXFeatures & features) const
115 {
116         if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
117             name_ == "alignedat")
118                 features.require("amsmath");
119         InsetMathGrid::validate(features);
120 }
121
122
123 } // namespace lyx