]> git.lyx.org Git - features.git/blob - src/mathed/math_nestinset.C
*duck*
[features.git] / src / mathed / math_nestinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_nestinset.h"
6 #include "math_cursor.h"
7 #include "math_mathmlstream.h"
8 #include "debug.h"
9 #include "frontends/Painter.h"
10
11
12 MathNestInset::MathNestInset(idx_type nargs)
13         : MathDimInset(), cells_(nargs), lock_(false)
14 {}
15
16
17 MathInset::idx_type MathNestInset::nargs() const
18 {
19         return cells_.size();
20 }
21
22
23 MathXArray & MathNestInset::xcell(idx_type i)
24 {
25         return cells_[i];
26 }
27
28
29 MathXArray const & MathNestInset::xcell(idx_type i) const
30 {
31         return cells_[i];
32 }
33
34
35 MathArray & MathNestInset::cell(idx_type i)
36 {
37         return cells_[i].data_;
38 }
39
40
41 MathArray const & MathNestInset::cell(idx_type i) const
42 {
43         return cells_[i].data_;
44 }
45
46
47 void MathNestInset::substitute(MathMacro const & m)
48 {
49         for (idx_type i = 0; i < nargs(); ++i)
50                 cell(i).substitute(m);
51 }
52
53
54 void MathNestInset::metrics(MathMetricsInfo const & mi) const
55 {
56         MathMetricsInfo m = mi;
57         m.inset = this;
58         for (idx_type i = 0; i < nargs(); ++i) {
59                 m.idx = i;
60                 xcell(i).metrics(m);
61         }
62 }
63
64
65 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
66 {
67         if (idx + 1 >= nargs())
68                 return false;
69         ++idx;
70         pos = 0;
71         return true;
72 }
73
74
75 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
76 {
77         return idxNext(idx, pos);
78 }
79
80
81 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
82 {
83         if (idx == 0)
84                 return false;
85         --idx;
86         pos = cell(idx).size();
87         return true;
88 }
89
90
91 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
92 {
93         return idxPrev(idx, pos);
94 }
95
96
97 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
98 {
99         if (nargs() == 0)
100                 return false;
101         i = 0;
102         pos = 0;
103         return true;
104 }
105
106
107 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
108 {
109         if (nargs() == 0)
110                 return false;
111         i = nargs() - 1;
112         pos = cell(i).size();
113         return true;
114 }
115
116
117 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
118 {
119         if (pos == 0)
120                 return false;
121         pos = 0;
122         return true;
123 }
124
125
126 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
127 {
128         pos_type n = cell(idx).size();
129         if (pos == n)
130                 return false;
131         pos = n;
132         return true;
133 }
134
135
136 void MathNestInset::dump() const
137 {
138         WriteStream os(lyxerr);
139         os << "---------------------------------------------\n";
140         write(os);
141         os << "\n";
142         for (idx_type i = 0; i < nargs(); ++i)
143                 os << cell(i) << "\n";
144         os << "---------------------------------------------\n";
145 }
146
147
148 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
149 void MathNestInset::draw(MathPainterInfo &, int, int) const
150 {
151 #if 0
152         if (lock_)
153                 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
154                                         LColor::mathlockbg);
155 #endif
156 }
157
158
159 void MathNestInset::validate(LaTeXFeatures & features) const
160 {
161         for (idx_type i = 0; i < nargs(); ++i)
162                 cell(i).validate(features);
163 }
164
165
166 bool MathNestInset::match(MathInset * p) const
167 {
168         if (nargs() != p->nargs())
169                 return false;
170         for (idx_type i = 0; i < nargs(); ++i)
171                 if (!cell(i).match(p->cell(i)))
172                         return false;
173         return true;
174 }
175
176
177 void MathNestInset::replace(ReplaceData & rep)
178 {
179         for (idx_type i = 0; i < nargs(); ++i)
180                 cell(i).replace(rep);
181 }
182
183
184 bool MathNestInset::contains(MathArray const & ar)
185 {
186         for (idx_type i = 0; i < nargs(); ++i)
187                 if (cell(i).contains(ar))
188                         return true;
189         return false;
190 }
191
192
193 bool MathNestInset::editing() const
194 {
195         return mathcursor && mathcursor->isInside(this);
196 }
197
198
199 bool MathNestInset::lock() const
200 {
201         return lock_;
202 }
203
204
205 void MathNestInset::lock(bool l)
206 {
207         lock_ = l;
208 }
209
210
211 bool MathNestInset::isActive() const
212 {
213         return nargs() > 0;
214 }
215
216
217 MathArray MathNestInset::glue() const
218 {
219         MathArray ar;
220         for (unsigned i = 0; i < nargs(); ++i)
221                 ar.push_back(cell(i));
222         return ar;
223 }