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