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 void MathNestInset::metricsMarkers(int frame) const
73 void MathNestInset::metricsMarkers2(int frame) const
81 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
83 if (idx + 1 >= nargs())
91 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
93 return idxNext(idx, pos);
97 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
102 pos = cell(idx).size();
107 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
109 return idxPrev(idx, pos);
113 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
123 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
128 pos = cell(i).size();
133 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
142 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
144 pos_type n = cell(idx).size();
152 void MathNestInset::dump() const
154 WriteStream os(lyxerr);
155 os << "---------------------------------------------\n";
158 for (idx_type i = 0; i < nargs(); ++i)
159 os << cell(i) << "\n";
160 os << "---------------------------------------------\n";
164 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
165 void MathNestInset::draw(MathPainterInfo &, int, int) const
169 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
175 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
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);
188 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
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);
202 void MathNestInset::validate(LaTeXFeatures & features) const
204 for (idx_type i = 0; i < nargs(); ++i)
205 cell(i).validate(features);
209 bool MathNestInset::match(MathInset * p) const
211 if (nargs() != p->nargs())
213 for (idx_type i = 0; i < nargs(); ++i)
214 if (!cell(i).match(p->cell(i)))
220 void MathNestInset::replace(ReplaceData & rep)
222 for (idx_type i = 0; i < nargs(); ++i)
223 cell(i).replace(rep);
227 bool MathNestInset::contains(MathArray const & ar)
229 for (idx_type i = 0; i < nargs(); ++i)
230 if (cell(i).contains(ar))
236 bool MathNestInset::editing() const
238 return mathcursor && mathcursor->isInside(this);
242 bool MathNestInset::lock() const
248 void MathNestInset::lock(bool l)
254 bool MathNestInset::isActive() const
260 MathArray MathNestInset::glue() const
263 for (unsigned i = 0; i < nargs(); ++i)
264 ar.push_back(cell(i));
269 void MathNestInset::notifyCursorLeaves()
271 //lyxerr << "leaving " << *this << "\n";
272 if (!mathcursor || !grfx::Previews::activated())
275 InsetFormulaBase * inset = mathcursor->formula();
276 BufferView * bufferview = inset->view();
277 if (!bufferview || !bufferview->buffer())
280 grfx::Previews & previews = grfx::Previews::get();
281 grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
283 inset->generatePreview(loader);
284 loader.startLoading();