diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 309ed06d16..79176cae1d 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -68,7 +68,7 @@ struct Selection data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_)); else { std::vector indices = - i1.par_->nucleus()->idxBetween(i1.idx_, i2.idx_); + i1.par_->idxBetween(i1.idx_, i2.idx_); for (MathInset::idx_type i = 0; i < indices.size(); ++i) data_.push_back(i1.cell(indices[i])); } @@ -83,7 +83,7 @@ struct Selection i1.cell().erase(i1.pos_, i2.pos_); else { std::vector indices = - i1.par_->nucleus()->idxBetween(i1.idx_, i2.idx_); + i1.par_->idxBetween(i1.idx_, i2.idx_); for (unsigned i = 0; i < indices.size(); ++i) i1.cell(indices[i]).erase(); } @@ -130,11 +130,7 @@ MathCursor::MathCursor(InsetFormulaBase * formula, bool left) void MathCursor::push(MathAtom & t) { - MathCursorPos p; - p.par_ = &t; - p.idx_ = 0; - p.pos_ = 0; - Cursor_.push_back(p); + Cursor_.push_back(MathCursorPos(t.nucleus())); } @@ -211,7 +207,7 @@ UpdatableInset * MathCursor::asHyperActiveInset() const bool MathCursor::isInside(MathInset const * p) const { for (unsigned i = 0; i < Cursor_.size(); ++i) - if (Cursor_[i].par_->nucleus() == p) + if (Cursor_[i].par_ == p) return true; return false; } @@ -232,7 +228,7 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const // we can't move into anything new during selection if (Cursor_.size() == Anchor_.size()) return false; - if (&t != Anchor_[Cursor_.size()].par_) + if (t.nucleus() != Anchor_[Cursor_.size()].par_) return false; } return true; @@ -327,8 +323,8 @@ void MathCursor::setPos(int x, int y) cursor_type best_cursor; double best_dist = 1e10; - MathIterator it = ibegin(formula()->par()); - MathIterator et = iend(formula()->par()); + MathIterator it = ibegin(formula()->par().nucleus()); + MathIterator et = iend(formula()->par().nucleus()); for ( ; it != et; ++it) { //lyxerr << "*it: " << *it << " *et: " << *et << "\n"; if (selection_) { @@ -337,7 +333,7 @@ void MathCursor::setPos(int x, int y) continue; // anchor might be deeper! if (it.cursor().size() == Anchor_.size()) - if (it.par().nucleus() != Anchor_.back().par_->nucleus()) + if (it.par() != Anchor_.back().par_) continue; //if (it.par() != Anchor_[it.cursor().size()].par_) // continue; @@ -742,7 +738,7 @@ void MathCursor::drawSelection(Painter & pain) const pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); } else { std::vector indices - = (*i1.par_)->idxBetween(i1.idx_, i2.idx_); + = i1.par_->idxBetween(i1.idx_, i2.idx_); for (unsigned i = 0; i < indices.size(); ++i) { MathXArray & c = i1.xcell(indices[i]); int x1 = c.xo(); @@ -811,9 +807,9 @@ void MathCursor::getPos(int & x, int & y) } -MathAtom & MathCursor::par() const +MathInset * MathCursor::par() const { - return *cursor().par_; + return cursor().par_; } @@ -862,7 +858,7 @@ bool MathCursor::selection() const MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const { for (int i = Cursor_.size() - 1; i >= 0; --i) { - MathGridInset * p = (*Cursor_[i].par_)->asGridInset(); + MathGridInset * p = Cursor_[i].par_->asGridInset(); if (p) { idx = Cursor_[i].idx_; return p; @@ -934,13 +930,13 @@ MathCursor::size_type MathCursor::size() const MathCursor::col_type MathCursor::hullCol() const { - return Cursor_[0].par_->nucleus()->asGridInset()->col(Cursor_[0].idx_); + return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_); } MathCursor::row_type MathCursor::hullRow() const { - return Cursor_[0].par_->nucleus()->asGridInset()->row(Cursor_[0].idx_); + return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_); } @@ -1179,8 +1175,8 @@ bool MathCursor::bruteFind(int xlow, int xhigh, int ylow, int yhigh) cursor_type best_cursor; double best_dist = 1e10; - MathIterator it = ibegin(formula()->par()); - MathIterator et = iend(formula()->par()); + MathIterator it = ibegin(formula()->par().nucleus()); + MathIterator et = iend(formula()->par().nucleus()); for ( ; it != et; ++it) { int xo = it.position().xpos(); int yo = it.position().ypos(); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 4ba5976744..ec6ae8934b 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -102,8 +102,8 @@ public: void setPos(int x, int y); /// in pixels from top of screen void getPos(int & x, int & y); - /// - MathAtom & par() const; + /// current inset + MathInset * par() const; /// return the next enclosing grid inset and the cursor's index in it MathGridInset * enclosingGrid(idx_type &) const; /// diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C index ca65d4a340..f84858abf6 100644 --- a/src/mathed/math_iterator.C +++ b/src/mathed/math_iterator.C @@ -10,15 +10,15 @@ //{} -MathIterator::MathIterator(MathAtom & t) +MathIterator::MathIterator(MathInset * p) { - push(t); + push(p); } -MathIterator::MathIterator(MathCursor::cursor_type const & c) - : cursor_(c) -{} +//MathIterator::MathIterator(MathCursor::cursor_type const & c) +// : cursor_(c) +//{} MathCursorPos const & MathIterator::position() const @@ -41,15 +41,15 @@ MathCursor::cursor_type const & MathIterator::cursor() const } -MathAtom const & MathIterator::par() const +MathInset const * MathIterator::par() const { - return *(position().par_); + return position().par_; } -MathAtom & MathIterator::par() +MathInset * MathIterator::par() { - return *(position().par_); + return position().par_; } @@ -59,18 +59,18 @@ MathXArray const & MathIterator::xcell() const } -MathAtom * MathIterator::nextInset() const +MathInset * MathIterator::nextInset() const { if (position().pos_ == xcell().data_.size()) return 0; - return const_cast(&*(xcell().begin() + position().pos_)); + return (xcell().begin() + position().pos_)->nucleus(); } -void MathIterator::push(MathAtom & t) +void MathIterator::push(MathInset * p) { //lyxerr << "push: " << p << endl; - cursor_.push_back(MathCursorPos(t)); + cursor_.push_back(MathCursorPos(p)); } @@ -105,8 +105,8 @@ void MathIterator::operator++() { // move into the current inset if possible // it is impossible for pos() == size()! - if (nextInset() && nextInset()->nucleus()->isActive()) { - push(*nextInset()); + if (nextInset() && nextInset()->isActive()) { + push(nextInset()); return; } @@ -152,15 +152,15 @@ bool operator!=(MathIterator const & it, MathIterator const & jt) -MathIterator ibegin(MathAtom & t) +MathIterator ibegin(MathInset * p) { - return MathIterator(t); + return MathIterator(p); } -MathIterator iend(MathAtom & t) +MathIterator iend(MathInset * p) { - MathIterator it(t); + MathIterator it(p); it.goEnd(); return it; } diff --git a/src/mathed/math_iterator.h b/src/mathed/math_iterator.h index 9f721b7f02..d95ff6f00f 100644 --- a/src/mathed/math_iterator.h +++ b/src/mathed/math_iterator.h @@ -10,10 +10,10 @@ class MathIterator { public: /// default constructor, used for end of range //MathIterator(); - /// start with given formula - explicit MathIterator(MathAtom & t); + /// start with given inset + explicit MathIterator(MathInset * p); /// start with given position - explicit MathIterator(MathCursor::cursor_type const & cursor); + //explicit MathIterator(MathCursor::cursor_type const & cursor); /// MathCursorPos const & operator*() const; /// @@ -27,9 +27,9 @@ public: /// read access to full path MathCursor::cursor_type const & cursor() const; /// read access to top most inset - MathAtom const & par() const; + MathInset const * par() const; /// read access to top most inset - MathAtom & par(); + MathInset * par(); /// helper for iend void goEnd(); @@ -37,9 +37,9 @@ private: /// write access to top most item MathXArray const & xcell() const; /// write access to top most item - MathAtom * nextInset() const; + MathInset * nextInset() const; /// own level down - void push(MathAtom &); + void push(MathInset *); /// own level up void pop(); @@ -53,8 +53,8 @@ bool operator==(MathIterator const &, MathIterator const &); bool operator!=(MathIterator const &, MathIterator const &); /// -MathIterator ibegin(MathAtom & p); +MathIterator ibegin(MathInset * p); /// -MathIterator iend(MathAtom & p); +MathIterator iend(MathInset * p); #endif diff --git a/src/mathed/math_pos.C b/src/mathed/math_pos.C index 889f13782a..4322409656 100644 --- a/src/mathed/math_pos.C +++ b/src/mathed/math_pos.C @@ -13,43 +13,38 @@ MathCursorPos::MathCursorPos() {} -MathCursorPos::MathCursorPos(MathAtom & t) - : par_(&t), idx_(0), pos_(0) +MathCursorPos::MathCursorPos(MathInset * p) + : par_(p), idx_(0), pos_(0) { lyx::Assert(par_); - lyx::Assert(par_->nucleus()); } MathArray & MathCursorPos::cell(MathArray::idx_type idx) const { lyx::Assert(par_); - lyx::Assert(par_->nucleus()); - return par_->nucleus()->cell(idx); + return par_->cell(idx); } MathArray & MathCursorPos::cell() const { lyx::Assert(par_); - lyx::Assert(par_->nucleus()); - return par_->nucleus()->cell(idx_); + return par_->cell(idx_); } MathXArray & MathCursorPos::xcell(MathArray::idx_type idx) const { lyx::Assert(par_); - lyx::Assert(par_->nucleus()); - return par_->nucleus()->xcell(idx); + return par_->xcell(idx); } MathXArray & MathCursorPos::xcell() const { lyx::Assert(par_); - lyx::Assert(par_->nucleus()); - return par_->nucleus()->xcell(idx_); + return par_->xcell(idx_); } diff --git a/src/mathed/math_pos.h b/src/mathed/math_pos.h index 8d8e9e951a..5ffa93ceac 100644 --- a/src/mathed/math_pos.h +++ b/src/mathed/math_pos.h @@ -11,7 +11,7 @@ public: /// MathCursorPos(); /// - explicit MathCursorPos(MathAtom &); + explicit MathCursorPos(MathInset *); /// returns cell corresponding to this position MathArray & cell() const; @@ -28,7 +28,7 @@ public: public: /// pointer to an inset - MathAtom * par_; + MathInset * par_; /// cell index of a position in this inset MathArray::idx_type idx_; /// position in this cell