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 MathXArray const & ar = xcell(idx);
54 x = ar.xo() + ar.pos2x(pos);
56 // move cursor visually into empty cells ("blue rectangles");
57 if (cell(idx).empty())
61 void MathNestInset::substitute(MathMacro const & m)
63 for (idx_type i = 0; i < nargs(); ++i)
64 cell(i).substitute(m);
68 void MathNestInset::metrics(MathMetricsInfo const & mi) const
70 MathMetricsInfo m = mi;
71 for (idx_type i = 0; i < nargs(); ++i)
76 void MathNestInset::metricsMarkers(int frame) const
83 void MathNestInset::metricsMarkers2(int frame) const
91 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
93 if (idx + 1 >= nargs())
101 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
103 return idxNext(idx, pos);
107 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
112 pos = cell(idx).size();
117 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
119 return idxPrev(idx, pos);
123 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
133 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
138 pos = cell(i).size();
143 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
152 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
154 pos_type n = cell(idx).size();
162 void MathNestInset::dump() const
164 WriteStream os(lyxerr);
165 os << "---------------------------------------------\n";
168 for (idx_type i = 0; i < nargs(); ++i)
169 os << cell(i) << "\n";
170 os << "---------------------------------------------\n";
174 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
175 void MathNestInset::draw(MathPainterInfo &, int, int) const
179 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
185 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
189 int t = x + width() - 1;
190 int d = y + descent();
191 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
192 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
193 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
194 pi.pain.line(t - 2, d, t, d, LColor::mathframe);
198 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
202 drawMarkers(pi, x, y);
203 int t = x + width() - 1;
204 int a = y - ascent();
205 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
206 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
207 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
208 pi.pain.line(t - 2, a, t, a, LColor::mathframe);
212 void MathNestInset::validate(LaTeXFeatures & features) const
214 for (idx_type i = 0; i < nargs(); ++i)
215 cell(i).validate(features);
219 bool MathNestInset::match(MathInset * p) const
221 if (nargs() != p->nargs())
223 for (idx_type i = 0; i < nargs(); ++i)
224 if (!cell(i).match(p->cell(i)))
230 void MathNestInset::replace(ReplaceData & rep)
232 for (idx_type i = 0; i < nargs(); ++i)
233 cell(i).replace(rep);
237 bool MathNestInset::contains(MathArray const & ar)
239 for (idx_type i = 0; i < nargs(); ++i)
240 if (cell(i).contains(ar))
246 bool MathNestInset::editing() const
248 return mathcursor && mathcursor->isInside(this);
252 bool MathNestInset::lock() const
258 void MathNestInset::lock(bool l)
264 bool MathNestInset::isActive() const
270 MathArray MathNestInset::glue() const
273 for (unsigned i = 0; i < nargs(); ++i)
274 ar.push_back(cell(i));
279 void MathNestInset::notifyCursorLeaves()
281 // Generate a preview only if previews are active and we are leaving
282 // the InsetFormula itself
283 if (!grfx::Previews::activated() ||
284 !mathcursor || mathcursor->depth() != 1)
287 InsetFormulaBase * inset = mathcursor->formula();
288 BufferView * bufferview = inset->view();
291 if (!bufferview || !bufferview->buffer())
294 grfx::Previews & previews = grfx::Previews::get();
295 grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
297 inset->generatePreview(loader);
298 loader.startLoading();