]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
remove unneeded member
[lyx.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 "formulabase.h"
9 #include "BufferView.h"
10 #include "debug.h"
11 #include "frontends/Painter.h"
12 #include "graphics/PreviewLoader.h"
13 #include "graphics/Previews.h"
14
15
16 MathNestInset::MathNestInset(idx_type nargs)
17         : MathDimInset(), cells_(nargs), lock_(false)
18 {}
19
20
21 MathInset::idx_type MathNestInset::nargs() const
22 {
23         return cells_.size();
24 }
25
26
27 MathXArray & MathNestInset::xcell(idx_type i)
28 {
29         return cells_[i];
30 }
31
32
33 MathXArray const & MathNestInset::xcell(idx_type i) const
34 {
35         return cells_[i];
36 }
37
38
39 MathArray & MathNestInset::cell(idx_type i)
40 {
41         return cells_[i].data();
42 }
43
44
45 MathArray const & MathNestInset::cell(idx_type i) const
46 {
47         return cells_[i].data();
48 }
49
50
51 void MathNestInset::substitute(MathMacro const & m)
52 {
53         for (idx_type i = 0; i < nargs(); ++i)
54                 cell(i).substitute(m);
55 }
56
57
58 void MathNestInset::metrics(MathMetricsInfo const & mi) const
59 {
60         MathMetricsInfo m = mi;
61         for (idx_type i = 0; i < nargs(); ++i)
62                 xcell(i).metrics(m);
63 }
64
65
66 void MathNestInset::metricsMarkers() const
67 {
68         descent_ += 1;
69         width_   += 2;
70 }
71
72
73 void MathNestInset::metricsMarkers2() const
74 {
75         ascent_  += 1;
76         descent_ += 1;
77         width_   += 2;
78 }
79
80
81 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
82 {
83         if (idx + 1 >= nargs())
84                 return false;
85         ++idx;
86         pos = 0;
87         return true;
88 }
89
90
91 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
92 {
93         return idxNext(idx, pos);
94 }
95
96
97 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
98 {
99         if (idx == 0)
100                 return false;
101         --idx;
102         pos = cell(idx).size();
103         return true;
104 }
105
106
107 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
108 {
109         return idxPrev(idx, pos);
110 }
111
112
113 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
114 {
115         if (nargs() == 0)
116                 return false;
117         i = 0;
118         pos = 0;
119         return true;
120 }
121
122
123 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
124 {
125         if (nargs() == 0)
126                 return false;
127         i = nargs() - 1;
128         pos = cell(i).size();
129         return true;
130 }
131
132
133 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
134 {
135         if (pos == 0)
136                 return false;
137         pos = 0;
138         return true;
139 }
140
141
142 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
143 {
144         pos_type n = cell(idx).size();
145         if (pos == n)
146                 return false;
147         pos = n;
148         return true;
149 }
150
151
152 void MathNestInset::dump() const
153 {
154         WriteStream os(lyxerr);
155         os << "---------------------------------------------\n";
156         write(os);
157         os << "\n";
158         for (idx_type i = 0; i < nargs(); ++i)
159                 os << cell(i) << "\n";
160         os << "---------------------------------------------\n";
161 }
162
163
164 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
165 void MathNestInset::draw(MathPainterInfo &, int, int) const
166 {
167 #if 0
168         if (lock_)
169                 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
170                                         LColor::mathlockbg);
171 #endif
172 }
173
174
175 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
176 {
177         if (!editing())
178                 return;
179         int t = x + width() - 1;
180         int d = y + descent();
181         pi.pain.line(x, d - 3, x, d, LColor::mathframe); 
182         pi.pain.line(t, d - 3, t, d, LColor::mathframe); 
183         pi.pain.line(x, d, x + 3, d, LColor::mathframe); 
184         pi.pain.line(t - 2, d, t, d, LColor::mathframe); 
185 }
186
187
188 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
189 {
190         if (!editing())
191                 return;
192         drawMarkers(pi, x, y);  
193         int t = x + width() - 1;
194         int a = y - ascent();
195         pi.pain.line(x, a + 3, x, a, LColor::mathframe); 
196         pi.pain.line(t, a + 3, t, a, LColor::mathframe); 
197         pi.pain.line(x, a, x + 3, a, LColor::mathframe); 
198         pi.pain.line(t - 2, a, t, a, LColor::mathframe); 
199 }
200
201
202 void MathNestInset::validate(LaTeXFeatures & features) const
203 {
204         for (idx_type i = 0; i < nargs(); ++i)
205                 cell(i).validate(features);
206 }
207
208
209 bool MathNestInset::match(MathInset * p) const
210 {
211         if (nargs() != p->nargs())
212                 return false;
213         for (idx_type i = 0; i < nargs(); ++i)
214                 if (!cell(i).match(p->cell(i)))
215                         return false;
216         return true;
217 }
218
219
220 void MathNestInset::replace(ReplaceData & rep)
221 {
222         for (idx_type i = 0; i < nargs(); ++i)
223                 cell(i).replace(rep);
224 }
225
226
227 bool MathNestInset::contains(MathArray const & ar)
228 {
229         for (idx_type i = 0; i < nargs(); ++i)
230                 if (cell(i).contains(ar))
231                         return true;
232         return false;
233 }
234
235
236 bool MathNestInset::editing() const
237 {
238         return mathcursor && mathcursor->isInside(this);
239 }
240
241
242 bool MathNestInset::lock() const
243 {
244         return lock_;
245 }
246
247
248 void MathNestInset::lock(bool l)
249 {
250         lock_ = l;
251 }
252
253
254 bool MathNestInset::isActive() const
255 {
256         return nargs() > 0;
257 }
258
259
260 MathArray MathNestInset::glue() const
261 {
262         MathArray ar;
263         for (unsigned i = 0; i < nargs(); ++i)
264                 ar.push_back(cell(i));
265         return ar;
266 }
267
268
269 void MathNestInset::notifyCursorLeaves()
270 {
271         //lyxerr << "leaving " << *this << "\n";
272         if (!mathcursor || !grfx::Previews::activated())
273                 return;
274
275         InsetFormulaBase * inset = mathcursor->formula();
276         BufferView * bufferview = inset->view();
277         if (!bufferview || !bufferview->buffer())
278                 return;
279
280         grfx::Previews & previews = grfx::Previews::get();
281         grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
282
283         inset->generatePreview(loader);
284         loader.startLoading();
285 }