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