]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCases.cpp
bcedc88b764acffe3c839a5b1ad8fb8a125afeeb
[lyx.git] / src / mathed / InsetMathCases.cpp
1 /**
2  * \file InsetMathCases.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 "InsetMathCases.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "support/std_ostream.h"
20 #include "Cursor.h"
21 #include "FuncRequest.h"
22 #include "gettext.h"
23 #include "Undo.h"
24
25 #include "support/lstrings.h"
26
27
28 namespace lyx {
29
30 using support::bformat;
31
32 using std::endl;
33
34
35 InsetMathCases::InsetMathCases(row_type n)
36         : InsetMathGrid(2, n, 'c', from_ascii("ll"))
37 {}
38
39
40 Inset * InsetMathCases::clone() const
41 {
42         return new InsetMathCases(*this);
43 }
44
45
46 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         InsetMathGrid::metrics(mi);
49         dim_.wid += 8;
50         dim = dim_;
51 }
52
53
54 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
55 {
56         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), from_ascii("{"));
57         InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
58         setPosCache(pi, x, y);
59 }
60
61
62 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
63 {
64         //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
65         switch (cmd.action) {
66         case LFUN_TABULAR_FEATURE: {
67                 recordUndo(cur);
68                 docstring const & s = cmd.argument();
69                 if (s == "add-vline-left" || s == "add-vline-right") {
70                         cur.undispatched();
71                         break;
72                 }
73         }
74         default:
75                 InsetMathGrid::doDispatch(cur, cmd);
76         }
77 }
78
79
80 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
81                 FuncStatus & flag) const
82 {
83         switch (cmd.action) {
84         case LFUN_TABULAR_FEATURE: {
85                 docstring const & s = cmd.argument();
86                 if (s == "add-vline-left" || s == "add-vline-right") {
87                         flag.enabled(false);
88                         flag.message(bformat(
89                                 from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
90                                 s));
91                         return true;
92                 }
93         }
94         default:
95                 return InsetMathGrid::getStatus(cur, cmd, flag);
96         }
97 }
98
99
100 void InsetMathCases::write(WriteStream & os) const
101 {
102         if (os.fragile())
103                 os << "\\protect";
104         os << "\\begin{cases}\n";
105         InsetMathGrid::write(os);
106         if (os.fragile())
107                 os << "\\protect";
108         os << "\\end{cases}";
109 }
110
111
112 void InsetMathCases::normalize(NormalStream & os) const
113 {
114         os << "[cases ";
115         InsetMathGrid::normalize(os);
116         os << ']';
117 }
118
119
120 void InsetMathCases::maple(MapleStream & os) const
121 {
122         os << "cases(";
123         InsetMathGrid::maple(os);
124         os << ')';
125 }
126
127
128 void InsetMathCases::infoize(odocstream & os) const
129 {
130         os << "Cases ";
131 }
132
133
134 void InsetMathCases::validate(LaTeXFeatures & features) const
135 {
136         features.require("amsmath");
137         InsetMathGrid::validate(features);
138 }
139
140
141 } // namespace lyx