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