5 #include "math_nestinset.h"
6 #include "math_cursor.h"
7 #include "math_mathmlstream.h"
8 #include "math_parser.h"
9 #include "funcrequest.h"
11 #include "frontends/Painter.h"
14 MathNestInset::MathNestInset(idx_type nargs)
15 : MathDimInset(), cells_(nargs), lock_(false)
19 MathInset::idx_type MathNestInset::nargs() const
25 MathArray & MathNestInset::cell(idx_type i)
31 MathArray const & MathNestInset::cell(idx_type i) const
37 void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
39 MathArray const & ar = cell(idx);
40 x = ar.xo() + ar.pos2x(pos);
42 // move cursor visually into empty cells ("blue rectangles");
43 if (cell(idx).empty())
47 void MathNestInset::substitute(MathMacro const & m)
49 for (idx_type i = 0; i < nargs(); ++i)
50 cell(i).substitute(m);
54 void MathNestInset::metrics(MathMetricsInfo const & mi) const
56 MathMetricsInfo m = mi;
57 for (idx_type i = 0; i < nargs(); ++i)
62 void MathNestInset::metricsMarkers(int frame) const
69 void MathNestInset::metricsMarkers2(int frame) const
77 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
79 if (idx + 1 >= nargs())
87 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
89 return idxNext(idx, pos);
93 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
98 pos = cell(idx).size();
103 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
105 return idxPrev(idx, pos);
109 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
119 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
124 pos = cell(i).size();
129 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
138 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
140 pos_type n = cell(idx).size();
148 void MathNestInset::dump() const
150 WriteStream os(lyxerr);
151 os << "---------------------------------------------\n";
154 for (idx_type i = 0; i < nargs(); ++i)
155 os << cell(i) << "\n";
156 os << "---------------------------------------------\n";
160 //void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const
161 void MathNestInset::draw(MathPainterInfo &, int, int) const
165 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
171 void MathNestInset::drawSelection(MathPainterInfo & pi,
172 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
175 MathArray const & c = cell(idx1);
176 int x1 = c.xo() + c.pos2x(pos1);
177 int y1 = c.yo() - c.ascent();
178 int x2 = c.xo() + c.pos2x(pos2);
179 int y2 = c.yo() + c.descent();
180 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
182 for (idx_type i = 0; i < nargs(); ++i) {
183 if (idxBetween(i, idx1, idx2)) {
184 MathArray const & c = cell(i);
186 int y1 = c.yo() - c.ascent();
187 int x2 = c.xo() + c.width();
188 int y2 = c.yo() + c.descent();
189 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
196 void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const
200 int t = x + width() - 1;
201 int d = y + descent();
202 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
203 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
204 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
205 pi.pain.line(t - 2, d, t, d, LColor::mathframe);
209 void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const
213 drawMarkers(pi, x, y);
214 int t = x + width() - 1;
215 int a = y - ascent();
216 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
217 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
218 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
219 pi.pain.line(t - 2, a, t, a, LColor::mathframe);
223 void MathNestInset::validate(LaTeXFeatures & features) const
225 for (idx_type i = 0; i < nargs(); ++i)
226 cell(i).validate(features);
230 bool MathNestInset::match(MathAtom const & at) const
232 if (nargs() != at->nargs())
234 for (idx_type i = 0; i < nargs(); ++i)
235 if (!cell(i).match(at->cell(i)))
241 void MathNestInset::replace(ReplaceData & rep)
243 for (idx_type i = 0; i < nargs(); ++i)
244 cell(i).replace(rep);
248 bool MathNestInset::contains(MathArray const & ar) const
250 for (idx_type i = 0; i < nargs(); ++i)
251 if (cell(i).contains(ar))
257 bool MathNestInset::editing() const
259 return mathcursor && mathcursor->isInside(this);
263 bool MathNestInset::lock() const
269 void MathNestInset::lock(bool l)
275 bool MathNestInset::isActive() const
281 MathArray MathNestInset::glue() const
284 for (unsigned i = 0; i < nargs(); ++i)
290 void MathNestInset::write(WriteStream & os) const
292 os << '\\' << name().c_str();
293 for (unsigned i = 0; i < nargs(); ++i)
294 os << '{' << cell(i) << '}';
295 if (lock_ && !os.latex())
302 void MathNestInset::normalize(NormalStream & os) const
304 os << '[' << name().c_str();
305 for (unsigned i = 0; i < nargs(); ++i)
306 os << ' ' << cell(i);
311 void MathNestInset::notifyCursorLeaves()
315 MathInset::result_type MathNestInset::dispatch
316 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
318 switch (cmd.action) {
321 lyxerr << "pasting '" << cmd.argument << "'\n";
323 mathed_parse_cell(ar, cmd.argument);
324 lyxerr << "pasting '" << ar << "'\n";
325 lyxerr << "cell(idx) '" << cell(idx) << "'\n";
326 cell(idx).insert(pos, ar);
332 return MathInset::dispatch(cmd, idx, pos);