5 #include "math_nestinset.h"
6 #include "math_cursor.h"
7 #include "math_mathmlstream.h"
8 #include "formulabase.h"
9 #include "BufferView.h"
11 #include "frontends/Painter.h"
12 #include "graphics/PreviewLoader.h"
13 #include "graphics/Previews.h"
16 MathNestInset::MathNestInset(idx_type nargs)
17 : MathDimInset(), cells_(nargs), lock_(false)
21 MathInset::idx_type MathNestInset::nargs() const
27 MathXArray & MathNestInset::xcell(idx_type i)
33 MathXArray const & MathNestInset::xcell(idx_type i) const
39 MathArray & MathNestInset::cell(idx_type i)
41 return cells_[i].data();
45 MathArray const & MathNestInset::cell(idx_type i) const
47 return cells_[i].data();
51 void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
53 x = cells_[idx].xo() + cells_[idx].pos2x(pos);
55 // move cursor visually into empty cells ("blue rectangles");
56 if (!cells_[idx].data().size())
60 void MathNestInset::substitute(MathMacro const & m)
62 for (idx_type i = 0; i < nargs(); ++i)
63 cell(i).substitute(m);
67 void MathNestInset::metrics(MathMetricsInfo const & mi) const
69 MathMetricsInfo m = mi;
70 for (idx_type i = 0; i < nargs(); ++i)
75 void MathNestInset::metricsMarkers(int frame) const
82 void MathNestInset::metricsMarkers2(int frame) const
90 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
92 if (idx + 1 >= nargs())
100 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
102 return idxNext(idx, pos);
106 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
111 pos = cell(idx).size();
116 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
118 return idxPrev(idx, pos);
122 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
132 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
137 pos = cell(i).size();
142 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
151 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
153 pos_type n = cell(idx).size();
161 void MathNestInset::dump() const
163 WriteStream os(lyxerr);
164 os << "---------------------------------------------\n";
167 for (idx_type i = 0; i < nargs(); ++i)
168 os << cell(i) << "\n";
169 os << "---------------------------------------------\n";
173 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
174 void MathNestInset::draw(MathPainterInfo &, int, int) const
178 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
184 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
188 int t = x + width() - 1;
189 int d = y + descent();
190 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
191 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
192 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
193 pi.pain.line(t - 2, d, t, d, LColor::mathframe);
197 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
201 drawMarkers(pi, x, y);
202 int t = x + width() - 1;
203 int a = y - ascent();
204 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
205 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
206 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
207 pi.pain.line(t - 2, a, t, a, LColor::mathframe);
211 void MathNestInset::validate(LaTeXFeatures & features) const
213 for (idx_type i = 0; i < nargs(); ++i)
214 cell(i).validate(features);
218 bool MathNestInset::match(MathInset * p) const
220 if (nargs() != p->nargs())
222 for (idx_type i = 0; i < nargs(); ++i)
223 if (!cell(i).match(p->cell(i)))
229 void MathNestInset::replace(ReplaceData & rep)
231 for (idx_type i = 0; i < nargs(); ++i)
232 cell(i).replace(rep);
236 bool MathNestInset::contains(MathArray const & ar)
238 for (idx_type i = 0; i < nargs(); ++i)
239 if (cell(i).contains(ar))
245 bool MathNestInset::editing() const
247 return mathcursor && mathcursor->isInside(this);
251 bool MathNestInset::lock() const
257 void MathNestInset::lock(bool l)
263 bool MathNestInset::isActive() const
269 MathArray MathNestInset::glue() const
272 for (unsigned i = 0; i < nargs(); ++i)
273 ar.push_back(cell(i));
278 void MathNestInset::notifyCursorLeaves()
280 //lyxerr << "leaving " << *this << "\n";
281 if (!mathcursor || !grfx::Previews::activated())
284 InsetFormulaBase * inset = mathcursor->formula();
285 BufferView * bufferview = inset->view();
286 if (!bufferview || !bufferview->buffer())
289 grfx::Previews & previews = grfx::Previews::get();
290 grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
292 inset->generatePreview(loader);
293 loader.startLoading();