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::push_back(MathAtom const & t)
152 cells_.back().data_.push_back(t);
154 lyxerr << "can't push without a cell\n";
158 void MathNestInset::validate(LaTeXFeatures & features) const
160 for (idx_type i = 0; i < nargs(); ++i)
161 cell(i).validate(features);
165 bool MathNestInset::covers(int x, int y) const
169 int x0 = xcell(0).xo();
170 int y0 = xcell(0).yo() - xcell(0).ascent();
171 int x1 = xcell(0).xo() + xcell(0).width();
172 int y1 = xcell(0).yo() + xcell(0).descent();
173 for (idx_type i = 1; i < nargs(); ++i) {
174 x0 = std::min(x0, xcell(i).xo());
175 y0 = std::min(y0, xcell(i).yo() - xcell(i).ascent());
176 x1 = std::max(x1, xcell(i).xo() + xcell(i).width());
177 y1 = std::max(y1, xcell(i).yo() + xcell(i).descent());
179 return x >= x0 && x <= x1 && y >= y0 && y <= y1;