A bit more re-organization.
[lyx.git] / src / mathed / InsetMathCases.cpp
blob5e1ee21fdb6ce446af87adab85bce699dd9a8d1c
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.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathCases.h"
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"
25 #include "support/lstrings.h"
27 #include <ostream>
29 using namespace std;
30 using namespace lyx::support;
32 namespace lyx {
35 InsetMathCases::InsetMathCases(Buffer * buf, row_type n)
36 : InsetMathGrid(buf, 2, n, 'c', from_ascii("ll"))
40 Inset * InsetMathCases::clone() const
42 return new InsetMathCases(*this);
46 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
48 InsetMathGrid::metrics(mi, dim);
49 dim.wid += 8;
53 Dimension const InsetMathCases::dimension(BufferView const & bv) const
55 Dimension dim = InsetMathGrid::dimension(bv);
56 dim.wid += 8;
57 return dim;
61 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
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);
70 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
72 //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
73 switch (cmd.action) {
74 case LFUN_TABULAR_FEATURE: {
75 docstring const & s = cmd.argument();
76 // vertical lines and adding/deleting columns is not allowed for \cases
77 if (s == "append-column" || s == "delete-column"
78 || s == "add-vline-left" || s == "add-vline-right") {
79 cur.undispatched();
80 break;
82 cur.recordUndo();
84 default:
85 InsetMathGrid::doDispatch(cur, cmd);
90 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
91 FuncStatus & flag) const
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.setEnabled(false);
98 flag.message(bformat(
99 from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
100 s));
101 return true;
103 if (s == "append-column" || s == "delete-column") {
104 flag.setEnabled(false);
105 flag.message(bformat(
106 from_utf8(N_("Changing number of columns not allowed in "
107 "'cases': feature %1$s")), s));
108 return true;
111 default:
112 return InsetMathGrid::getStatus(cur, cmd, flag);
117 void InsetMathCases::write(WriteStream & os) const
119 MathEnsurer ensurer(os);
120 if (os.fragile())
121 os << "\\protect";
122 os << "\\begin{cases}\n";
123 InsetMathGrid::write(os);
124 if (os.fragile())
125 os << "\\protect";
126 os << "\\end{cases}";
130 void InsetMathCases::normalize(NormalStream & os) const
132 os << "[cases ";
133 InsetMathGrid::normalize(os);
134 os << ']';
138 void InsetMathCases::maple(MapleStream & os) const
140 os << "cases(";
141 InsetMathGrid::maple(os);
142 os << ')';
146 void InsetMathCases::infoize(odocstream & os) const
148 os << "Cases ";
152 void InsetMathCases::validate(LaTeXFeatures & features) const
154 features.require("amsmath");
155 InsetMathGrid::validate(features);
159 } // namespace lyx