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::substitute(MathMacro const & m)
53 for (idx_type i = 0; i < nargs(); ++i)
54 cell(i).substitute(m);
58 void MathNestInset::metrics(MathMetricsInfo const & mi) const
60 MathMetricsInfo m = mi;
61 for (idx_type i = 0; i < nargs(); ++i)
66 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
68 if (idx + 1 >= nargs())
76 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
78 return idxNext(idx, pos);
82 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
87 pos = cell(idx).size();
92 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
94 return idxPrev(idx, pos);
98 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
108 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
113 pos = cell(i).size();
118 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
127 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
129 pos_type n = cell(idx).size();
137 void MathNestInset::dump() const
139 WriteStream os(lyxerr);
140 os << "---------------------------------------------\n";
143 for (idx_type i = 0; i < nargs(); ++i)
144 os << cell(i) << "\n";
145 os << "---------------------------------------------\n";
149 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
150 void MathNestInset::draw(MathPainterInfo &, int, int) const
154 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
160 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
164 int t = x + width() - 1;
165 int d = y + descent();
166 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
167 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
168 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
169 pi.pain.line(t - 2, d, t, d, LColor::mathframe);
173 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
177 drawMarkers(pi, x, y);
178 int t = x + width() - 1;
179 int a = y - ascent();
180 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
181 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
182 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
183 pi.pain.line(t - 2, a, t, a, LColor::mathframe);
187 void MathNestInset::validate(LaTeXFeatures & features) const
189 for (idx_type i = 0; i < nargs(); ++i)
190 cell(i).validate(features);
194 bool MathNestInset::match(MathInset * p) const
196 if (nargs() != p->nargs())
198 for (idx_type i = 0; i < nargs(); ++i)
199 if (!cell(i).match(p->cell(i)))
205 void MathNestInset::replace(ReplaceData & rep)
207 for (idx_type i = 0; i < nargs(); ++i)
208 cell(i).replace(rep);
212 bool MathNestInset::contains(MathArray const & ar)
214 for (idx_type i = 0; i < nargs(); ++i)
215 if (cell(i).contains(ar))
221 bool MathNestInset::editing() const
223 return mathcursor && mathcursor->isInside(this);
227 bool MathNestInset::lock() const
233 void MathNestInset::lock(bool l)
239 bool MathNestInset::isActive() const
245 MathArray MathNestInset::glue() const
248 for (unsigned i = 0; i < nargs(); ++i)
249 ar.push_back(cell(i));
254 void MathNestInset::notifyCursorLeaves()
256 //lyxerr << "leaving " << *this << "\n";
257 if (!mathcursor || !grfx::Previews::activated())
260 InsetFormulaBase * inset = mathcursor->formula();
261 BufferView * bufferview = inset->view();
262 if (!bufferview || !bufferview->buffer())
265 grfx::Previews & previews = grfx::Previews::get();
266 grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
268 inset->generatePreview(loader);
269 loader.startLoading();