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