]> git.lyx.org Git - lyx.git/blob - src/mathed/math_splitinset.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / mathed / math_splitinset.C
1 /**
2  * \file math_splitinset.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 "math_splitinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17
18 #include "funcrequest.h"
19 #include "FuncStatus.h"
20 #include "gettext.h"
21 #include "LaTeXFeatures.h"
22
23 #include "support/lstrings.h"
24 #include "support/std_ostream.h"
25
26
27 using lyx::support::bformat;
28 using std::string;
29 using std::auto_ptr;
30
31
32 MathSplitInset::MathSplitInset(string const & name)
33         : MathGridInset(1, 1), name_(name)
34 {
35         setDefaults();
36 }
37
38
39 auto_ptr<InsetBase> MathSplitInset::doClone() const
40 {
41         return auto_ptr<InsetBase>(new MathSplitInset(*this));
42 }
43
44
45 char MathSplitInset::defaultColAlign(col_type col)
46 {
47         if (name_ == "split")
48                 return 'l';
49         if (name_ == "gathered")
50                 return 'c';
51         if (name_ == "aligned")
52                 return (col & 1) ? 'l' : 'r';
53         if (name_ == "alignedat")
54                 return (col & 1) ? 'l' : 'r';
55         return 'l';
56 }
57
58
59 void MathSplitInset::draw(PainterInfo & pi, int x, int y) const
60 {
61         MathGridInset::draw(pi, x, y);
62         setPosCache(pi, x, y);
63 }
64
65
66 bool MathSplitInset::getStatus(LCursor & cur, FuncRequest const & cmd,
67                 FuncStatus & flag) const
68 {
69         switch (cmd.action) {
70         case LFUN_TABULAR_FEATURE: {
71                 string const s = cmd.argument;
72                 if (s == "add-vline-left" || s == "add-vline-right") {
73                         flag.message(bformat(
74                         N_("Can't add vertical grid lines in '%1$s'"),
75                                 name_));
76                         flag.enabled(false);
77                         return true;
78                 }
79                 return MathGridInset::getStatus(cur, cmd, flag);
80         }
81         default:
82                 return MathGridInset::getStatus(cur, cmd, flag);
83         }
84 }
85
86
87 void MathSplitInset::write(WriteStream & ws) const
88 {
89         if (ws.fragile())
90                 ws << "\\protect";
91         ws << "\\begin{" << name_ << '}';
92         if (name_ == "alignedat")
93                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
94         MathGridInset::write(ws);
95         if (ws.fragile())
96                 ws << "\\protect";
97         ws << "\\end{" << name_ << "}\n";
98 }
99
100
101 void MathSplitInset::infoize(std::ostream & os) const
102 {
103         string name = name_;
104         name[0] = lyx::support::uppercase(name[0]);
105         os << name << ' ';
106 }
107
108
109 void MathSplitInset::validate(LaTeXFeatures & features) const
110 {
111         features.require("amsmath");
112         MathNestInset::validate(features);
113 }