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