5 #include "math_nestinset.h"
6 #include "math_cursor.h"
7 #include "math_mathmlstream.h"
8 #include "formulabase.h"
10 #include "frontends/Painter.h"
15 MathNestInset::MathNestInset(idx_type nargs)
16 : MathDimInset(), cells_(nargs), lock_(false)
20 MathInset::idx_type MathNestInset::nargs() const
26 MathXArray & MathNestInset::xcell(idx_type i)
32 MathXArray const & MathNestInset::xcell(idx_type i) const
38 MathArray & MathNestInset::cell(idx_type i)
40 return cells_[i].data();
44 MathArray const & MathNestInset::cell(idx_type i) const
46 return cells_[i].data();
50 void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
52 MathXArray const & ar = xcell(idx);
53 x = ar.xo() + ar.pos2x(pos);
55 // move cursor visually into empty cells ("blue rectangles");
56 if (cell(idx).empty())
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::drawSelection(MathPainterInfo & pi,
185 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
188 MathXArray const & c = xcell(idx1);
189 int x1 = c.xo() + c.pos2x(pos1);
190 int y1 = c.yo() - c.ascent();
191 int x2 = c.xo() + c.pos2x(pos2);
192 int y2 = c.yo() + c.descent();
193 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
195 for (idx_type i = 0; i < nargs(); ++i) {
196 if (idxBetween(i, idx1, idx2)) {
197 MathXArray const & c = xcell(i);
199 int y1 = c.yo() - c.ascent();
200 int x2 = c.xo() + c.width();
201 int y2 = c.yo() + c.descent();
202 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)
303 void MathNestInset::write(WriteStream & os) const
305 os << '\\' << name().c_str();
306 for (unsigned i = 0; i < nargs(); ++i)
307 os << '{' << cell(i) << '}';
308 if (lock_ && !os.latex())
313 void MathNestInset::normalize(NormalStream & os) const
315 os << '[' << name().c_str();
316 for (unsigned i = 0; i < nargs(); ++i)
317 os << ' ' << cell(i);
322 void MathNestInset::notifyCursorLeaves()