]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
fix deletion of subscript if superscript is present and vice versa
[lyx.git] / src / mathed / math_nestinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_nestinset.h"
6 #include "debug.h"
7
8
9 MathNestInset::MathNestInset(int nargs, string const & name)
10         : MathDimInset(), cells_(nargs)
11 {
12         name_ = name;
13 }
14
15
16 int MathNestInset::nargs() const
17 {
18         return cells_.size();
19 }
20
21
22 MathXArray & MathNestInset::xcell(int i)
23 {
24         return cells_[i];
25 }
26
27
28 MathXArray const & MathNestInset::xcell(int i) const
29 {
30         return cells_[i];
31 }
32
33
34 MathArray & MathNestInset::cell(int i)
35 {
36         return cells_[i].data_;
37 }
38
39
40 MathArray const & MathNestInset::cell(int i) const
41 {
42         return cells_[i].data_;
43 }
44
45
46 void MathNestInset::substitute(MathArray & array, MathMacro const & m) const
47 {
48         array.push_back(clone());
49         for (int i = 0; i < nargs(); ++i)
50                 array.back()->cell(i).substitute(m);
51 }
52
53
54 void MathNestInset::metrics(MathStyles st) const
55 {
56         size_ = st;
57         for (int i = 0; i < nargs(); ++i)
58                 xcell(i).metrics(st);
59 }
60
61
62 void MathNestInset::draw(Painter & pain, int x, int y) const
63 {
64         xo(x);
65         yo(y);
66         for (int i = 0; i < nargs(); ++i)
67                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
68 }
69
70
71 bool MathNestInset::idxNext(int & idx, int & pos) const
72 {
73         if (idx + 1 >= nargs())
74                 return false;
75         ++idx;
76         pos = 0;
77         return true;
78 }
79
80
81 bool MathNestInset::idxRight(int & idx, int & pos) const
82 {
83         return idxNext(idx, pos);
84 }
85
86
87 bool MathNestInset::idxPrev(int & idx, int & pos) const
88 {
89         if (idx == 0)
90                 return false;
91         --idx;
92         pos = cell(idx).size();
93         return true;
94 }
95
96
97 bool MathNestInset::idxLeft(int & idx, int & pos) const
98 {
99         return idxPrev(idx, pos);
100 }
101
102
103 bool MathNestInset::idxFirst(int & i, int & pos) const
104 {
105         if (nargs() == 0)
106                 return false;
107         i = 0;
108         pos = 0;
109         return true;
110 }
111
112
113 bool MathNestInset::idxLast(int & i, int & pos) const
114 {
115         if (nargs() == 0)
116                 return false;
117         i = nargs() - 1;
118         pos = cell(i).size();
119         return true;
120 }
121
122
123 bool MathNestInset::idxHome(int & /* idx */, int & pos) const
124 {
125         if (pos == 0)
126                 return false;
127         pos = 0;
128         return true;
129 }
130
131
132 bool MathNestInset::idxEnd(int & idx, int & pos) const
133 {
134         if (pos == cell(idx).size())
135                 return false;
136
137         pos = cell(idx).size();
138         return true;
139 }
140
141
142 void MathNestInset::dump() const
143 {
144         lyxerr << "---------------------------------------------\n";
145         write(lyxerr, false);
146         lyxerr << "\n";
147         for (int i = 0; i < nargs(); ++i)
148                 lyxerr << cell(i) << "\n";
149         lyxerr << "---------------------------------------------\n";
150 }
151
152
153 void MathNestInset::push_back(unsigned char ch, MathTextCodes fcode)
154 {
155         if (nargs())
156                 cells_.back().data_.push_back(ch, fcode);
157         else
158                 lyxerr << "can't push without a cell\n";
159 }
160
161
162 void MathNestInset::push_back(MathInset * p)
163 {
164         if (nargs())
165                 cells_.back().data_.push_back(p);
166         else
167                 lyxerr << "can't push without a cell\n";
168 }
169
170
171 void MathNestInset::validate(LaTeXFeatures & features) const
172 {
173         for (int i = 0; i < nargs(); ++i)
174                 cell(i).validate(features);
175 }