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