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