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