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::drawSelection(MathPainterInfo & pi,
186 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
189 MathXArray const & c = xcell(idx1);
190 int x1 = c.xo() + c.pos2x(pos1);
191 int y1 = c.yo() - c.ascent();
192 int x2 = c.xo() + c.pos2x(pos2);
193 int y2 = c.yo() + c.descent();
194 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
196 vector<MathInset::idx_type> indices = idxBetween(idx1, idx2);
197 for (unsigned i = 0; i < indices.size(); ++i) {
198 MathXArray const & c = xcell(indices[i]);
200 int y1 = c.yo() - c.ascent();
201 int x2 = c.xo() + c.width();
202 int y2 = c.yo() + c.descent();
203 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
209 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
213 int t = x + width() - 1;
214 int d = y + descent();
215 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
216 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
217 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
218 pi.pain.line(t - 2, d, t, d, LColor::mathframe);
222 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
226 drawMarkers(pi, x, y);
227 int t = x + width() - 1;
228 int a = y - ascent();
229 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
230 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
231 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
232 pi.pain.line(t - 2, a, t, a, LColor::mathframe);
236 void MathNestInset::validate(LaTeXFeatures & features) const
238 for (idx_type i = 0; i < nargs(); ++i)
239 cell(i).validate(features);
243 bool MathNestInset::match(MathInset * p) const
245 if (nargs() != p->nargs())
247 for (idx_type i = 0; i < nargs(); ++i)
248 if (!cell(i).match(p->cell(i)))
254 void MathNestInset::replace(ReplaceData & rep)
256 for (idx_type i = 0; i < nargs(); ++i)
257 cell(i).replace(rep);
261 bool MathNestInset::contains(MathArray const & ar)
263 for (idx_type i = 0; i < nargs(); ++i)
264 if (cell(i).contains(ar))
270 bool MathNestInset::editing() const
272 return mathcursor && mathcursor->isInside(this);
276 bool MathNestInset::lock() const
282 void MathNestInset::lock(bool l)
288 bool MathNestInset::isActive() const
294 MathArray MathNestInset::glue() const
297 for (unsigned i = 0; i < nargs(); ++i)
298 ar.push_back(cell(i));
303 void MathNestInset::notifyCursorLeaves()
305 // Generate a preview only if previews are active and we are leaving
306 // the InsetFormula itself
307 if (!grfx::Previews::activated() ||
308 !mathcursor || mathcursor->depth() != 1)
311 InsetFormulaBase * inset = mathcursor->formula();
312 BufferView * bufferview = inset->view();
315 if (!bufferview || !bufferview->buffer())
318 grfx::Previews & previews = grfx::Previews::get();
319 grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
321 inset->generatePreview(loader);
322 loader.startLoading();