]> git.lyx.org Git - lyx.git/blob - src/mathed/math_splitinset.C
Martins and my getStatus and infoize fixes
[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
22 #include "support/lstrings.h"
23 #include "support/std_ostream.h"
24
25
26 using lyx::support::bformat;
27 using std::string;
28 using std::auto_ptr;
29
30
31 MathSplitInset::MathSplitInset(string const & name)
32         : MathGridInset(1, 1), name_(name)
33 {
34         setDefaults();
35 }
36
37
38 auto_ptr<InsetBase> MathSplitInset::doClone() const
39 {
40         return auto_ptr<InsetBase>(new MathSplitInset(*this));
41 }
42
43
44 char MathSplitInset::defaultColAlign(col_type col)
45 {
46         if (name_ == "split")
47                 return 'l';
48         if (name_ == "gathered")
49                 return 'c';
50         if (name_ == "aligned")
51                 return (col & 1) ? 'l' : 'r';
52         if (name_ == "alignedat")
53                 return (col & 1) ? 'l' : 'r';
54         return 'l';
55 }
56
57
58 bool MathSplitInset::getStatus(LCursor & cur, FuncRequest const & cmd,
59                 FuncStatus & flag) const
60 {
61         switch (cmd.action) {
62         case LFUN_TABULAR_FEATURE: {
63                 string const s = cmd.argument;
64                 if (s == "add-vline-left" || s == "add-vline-right") {
65                         flag.message(bformat(
66                         N_("Can't add vertical grid lines in '%1$s'"),
67                                 name_));
68                         flag.enabled(false);
69                         return true;
70                 }
71                 return MathGridInset::getStatus(cur, cmd, flag);
72         }
73         default:
74                 return MathGridInset::getStatus(cur, cmd, flag);
75         }
76 }
77
78
79 void MathSplitInset::write(WriteStream & ws) const
80 {
81         if (ws.fragile())
82                 ws << "\\protect";
83         ws << "\\begin{" << name_ << '}';
84         MathGridInset::write(ws);
85         if (ws.fragile())
86                 ws << "\\protect";
87         ws << "\\end{" << name_ << "}\n";
88 }
89
90
91 void MathSplitInset::infoize(std::ostream & os) const
92 {
93         string name = name_;
94         name[0] = lyx::support::uppercase(name[0]);
95         os << name << ' ';
96 }