5 #include "math_nestinset.h"
6 #include "math_mathmlstream.h"
10 MathNestInset::MathNestInset(idx_type nargs)
11 : MathDimInset(), cells_(nargs)
15 MathInset::idx_type MathNestInset::nargs() const
21 MathXArray & MathNestInset::xcell(idx_type i)
27 MathXArray const & MathNestInset::xcell(idx_type i) const
33 MathArray & MathNestInset::cell(idx_type i)
35 return cells_[i].data_;
39 MathArray const & MathNestInset::cell(idx_type i) const
41 return cells_[i].data_;
45 void MathNestInset::substitute(MathMacro const & m)
47 for (idx_type i = 0; i < nargs(); ++i)
48 cell(i).substitute(m);
52 void MathNestInset::metrics(MathMetricsInfo const & mi) const
54 for (idx_type i = 0; i < nargs(); ++i)
59 void MathNestInset::draw(Painter & pain, int x, int y) const
61 for (idx_type i = 0; i < nargs(); ++i)
62 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
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::validate(LaTeXFeatures & features) const
151 for (idx_type i = 0; i < nargs(); ++i)
152 cell(i).validate(features);
156 bool MathNestInset::covers(int x, int y) const
160 int x0 = xcell(0).xo();
161 int y0 = xcell(0).yo() - xcell(0).ascent();
162 int x1 = xcell(0).xo() + xcell(0).width();
163 int y1 = xcell(0).yo() + xcell(0).descent();
164 for (idx_type i = 1; i < nargs(); ++i) {
165 x0 = std::min(x0, xcell(i).xo());
166 y0 = std::min(y0, xcell(i).yo() - xcell(i).ascent());
167 x1 = std::max(x1, xcell(i).xo() + xcell(i).width());
168 y1 = std::max(y1, xcell(i).yo() + xcell(i).descent());
170 //lyxerr << "xO: " << x0 << " x1: " << x1 << " "
171 // << "yO: " << y0 << " y1: " << y1 << " "
172 // << "x: " << x << " y: " << y << '\n';
173 return x >= x0 && x <= x1 && y >= y0 && y <= y1;
177 bool MathNestInset::match(MathInset * p) const
179 if (nargs() != p->nargs())
181 for (idx_type i = 0; i < nargs(); ++i)
182 if (!cell(i).match(p->cell(i)))
188 void MathNestInset::replace(ReplaceData & rep)
190 for (idx_type i = 0; i < nargs(); ++i)
191 cell(i).replace(rep);