]> git.lyx.org Git - lyx.git/blob - src/mathed/math_splitinset.C
Fix to bug 2362: Deleting superscript also deletes subscript.
[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 void MathSplitInset::draw(PainterInfo & pi, int x, int y) const
59 {
60         MathGridInset::draw(pi, x, y);
61         setPosCache(pi, x, y);
62 }
63
64
65 bool MathSplitInset::getStatus(LCursor & cur, FuncRequest const & cmd,
66                 FuncStatus & flag) const
67 {
68         switch (cmd.action) {
69         case LFUN_TABULAR_FEATURE: {
70                 string const s = cmd.argument;
71                 if (s == "add-vline-left" || s == "add-vline-right") {
72                         flag.message(bformat(
73                         N_("Can't add vertical grid lines in '%1$s'"),
74                                 name_));
75                         flag.enabled(false);
76                         return true;
77                 }
78                 return MathGridInset::getStatus(cur, cmd, flag);
79         }
80         default:
81                 return MathGridInset::getStatus(cur, cmd, flag);
82         }
83 }
84
85
86 void MathSplitInset::write(WriteStream & ws) const
87 {
88         if (ws.fragile())
89                 ws << "\\protect";
90         ws << "\\begin{" << name_ << '}';
91         if (name_ == "alignedat")
92                 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
93         MathGridInset::write(ws);
94         if (ws.fragile())
95                 ws << "\\protect";
96         ws << "\\end{" << name_ << "}\n";
97 }
98
99
100 void MathSplitInset::infoize(std::ostream & os) const
101 {
102         string name = name_;
103         name[0] = lyx::support::uppercase(name[0]);
104         os << name << ' ';
105 }