//lyxerr << "searching '" << str << "' in " << this << ar << endl;
for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
- if (it.cell().matchpart(ar, it.position().pos_)) {
+ if (it.cell().matchpart(ar, it.back().pos_)) {
bv->unlockInset(bv->theLockingInset());
if (!bv->lockInset(this)) {
lyxerr << "Cannot lock inset" << endl;
delete mathcursor;
mathcursor = new MathCursor(this, true);
metrics(bv);
- mathcursor->setSelection(it.cursor(), ar.size());
+ mathcursor->setSelection(it, ar.size());
current = it;
it.jump(ar.size());
updateLocal(bv, false);
if (t->asScriptInset())
return false;
- if (!sel) {
+ if (sel) {
// we can't move into anything new during selection
if (depth() == Anchor_.size())
return false;
}
-bool positionable(MathCursor::cursor_type const & cursor,
- MathCursor::cursor_type const & anchor)
+bool positionable(MathIterator const & cursor, MathIterator const & anchor)
{
// avoid deeper nested insets when selecting
if (cursor.size() > anchor.size())
return false;
// anchor might be deeper, should have same path then
- for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
+ for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
if (cursor[i].par_ != anchor[i].par_)
return false;
dump("up 1");
macroModeClose();
selHandle(sel);
- cursor_type save = Cursor_;
+ MathIterator save = Cursor_;
if (goUpDown(true))
return true;
Cursor_ = save;
dump("down 1");
macroModeClose();
selHandle(sel);
- cursor_type save = Cursor_;
+ MathIterator save = Cursor_;
if (goUpDown(false))
return true;
Cursor_ = save;
void MathCursor::touch()
{
- cursor_type::const_iterator it = Cursor_.begin();
- cursor_type::const_iterator et = Cursor_.end();
+ MathIterator::const_iterator it = Cursor_.begin();
+ MathIterator::const_iterator et = Cursor_.end();
for ( ; it != et; ++it)
it->xcell().touch();
}
bool MathCursor::bruteFind
(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
- cursor_type best_cursor;
+ MathIterator best_cursor;
double best_dist = 1e10;
MathIterator it = ibegin(formula()->par().nucleus());
MathIterator et = iend(formula()->par().nucleus());
while (1) {
// avoid invalid nesting when selecting
- if (!selection_ || positionable(it.cursor(), Anchor_)) {
+ if (!selection_ || positionable(it, Anchor_)) {
int xo, yo;
- it.position().getPos(xo, yo);
+ it.back().getPos(xo, yo);
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
// '<=' in order to take the last possible position
// this is important for clicking behind \sum in e.g. '\sum_i a'
if (d <= best_dist) {
best_dist = d;
- best_cursor = it.cursor();
+ best_cursor = it;
}
}
}
}
-void MathCursor::setSelection(cursor_type const & where, size_type n)
+void MathCursor::setSelection(MathIterator const & where, size_type n)
{
selection_ = true;
Anchor_ = where;
#endif
#include "math_inset.h"
-#include "math_pos.h"
+#include "math_iterator.h"
#include "LString.h"
class InsetFormulaBase;
[Have a look at math_inset.h first]
The MathCursor is different from the kind of cursor used in the Outer
-World. It contains a stack of MathCursorPositions, each of which is made
+World. It contains a stack of MathCursorPos, each of which is made
up of a inset pointer, an index and a position offset, marking a path from
-this formula's mathHullInset to the current position.
+this formula's MathHullInset to the current position.
*/
typedef MathInset::row_type row_type;
/// type for column numbers
typedef MathInset::col_type col_type;
- /// how to store a cursor
- typedef std::vector<MathCursorPos> cursor_type;
///
explicit MathCursor(InsetFormulaBase *, bool left);
/// dump selection information for debugging
void dump(char const * str) const;
/// moves on
- void setSelection(cursor_type const & where, size_type n);
+ void setSelection(MathIterator const & where, size_type n);
///
void insert(char c);
///
idx_type & idx();
/// path of positions the cursor had to go if it were leaving each inset
- cursor_type Cursor_;
+ MathIterator Cursor_;
/// path of positions the anchor had to go if it were leaving each inset
- mutable cursor_type Anchor_;
+ mutable MathIterator Anchor_;
/// pointer to enclsing LyX inset
InsetFormulaBase * formula_;
// Selection stuff
#include <config.h>
#include "math_iterator.h"
+#include "math_inset.h"
#include "debug.h"
#include "support/LAssert.h"
-//MathIterator::MathIterator()
-//{}
+MathIterator::MathIterator()
+{}
MathIterator::MathIterator(MathInset * p)
}
-//MathIterator::MathIterator(MathCursor::cursor_type const & c)
-// : cursor_(c)
-//{}
-
-
-MathCursor::cursor_type const & MathIterator::cursor() const
-{
- return cursor_;
-}
-
-
MathInset const * MathIterator::par() const
{
- return position().par_;
+ return back().par_;
}
MathInset * MathIterator::par()
{
- return position().par_;
+ return back().par_;
}
MathArray const & MathIterator::cell() const
{
- MathCursorPos const & top = position();
+ MathCursorPos const & top = back();
return top.par_->cell(top.idx_);
}
void MathIterator::push(MathInset * p)
{
//lyxerr << "push: " << p << endl;
- cursor_.push_back(MathCursorPos(p));
+ push_back(MathCursorPos(p));
}
void MathIterator::pop()
{
//lyxerr << "pop: " << endl;
- lyx::Assert(cursor_.size());
- cursor_.pop_back();
+ lyx::Assert(size());
+ pop_back();
}
MathCursorPos const & MathIterator::operator*() const
{
- return position();
+ return back();
}
MathCursorPos const & MathIterator::operator->() const
{
- return position();
+ return back();
}
void MathIterator::goEnd()
{
- MathCursorPos & top = position();
+ MathCursorPos & top = back();
top.idx_ = top.par_->nargs() - 1;
top.pos_ = cell().size();
}
void MathIterator::operator++()
{
- MathCursorPos & top = position();
+ MathCursorPos & top = back();
MathArray const & ar = top.par_->cell(top.idx_);
// move into the current inset if possible
return;
}
- // otherwise move on one cell position if possible
+ // otherwise move on one cell back if possible
if (top.pos_ < ar.size()) {
// pos() == size() is valid!
++top.pos_;
}
}
- // otherwise leave array, move on one position
+ // otherwise leave array, move on one back
// this might yield pos() == size(), but that's a ok.
pop();
// it certainly invalidates top
- ++position().pos_;
+ ++back().pos_;
}
-void MathIterator::jump(MathInset::difference_type i)
+void MathIterator::jump(difference_type i)
{
- position().pos_ += i;
- //lyx::Assert(position().pos_ >= 0);
- lyx::Assert(position().pos_ <= cell().size());
+ back().pos_ += i;
+ //lyx::Assert(back().pos_ >= 0);
+ lyx::Assert(back().pos_ <= cell().size());
}
bool operator==(MathIterator const & it, MathIterator const & jt)
{
- //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
- if (it.cursor().size() != jt.cursor().size())
- return false;
- return it.cursor() == jt.cursor();
+ return MathIterator::base_type(it) == MathIterator::base_type(jt);
}
bool operator!=(MathIterator const & it, MathIterator const & jt)
{
- //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
- if (it.cursor().size() != jt.cursor().size())
- return true;
- return it.cursor() != jt.cursor();
+ return MathIterator::base_type(it) != MathIterator::base_type(jt);
}
#ifndef MATH_ITERATOR_H
#define MATH_ITERATOR_H
-#include "math_cursor.h"
+#include "math_pos.h"
+#include <vector>
-// this helper struct is used for traversing math insets
+// this is used for traversing math insets
-class MathIterator {
+class MathIterator : private std::vector<MathCursorPos> {
public:
- /// default constructor, used for end of range
- //MathIterator();
+ // re-use inherited stuff
+ typedef std::vector<MathCursorPos> base_type;
+ using base_type::clear;
+ using base_type::size;
+ using base_type::push_back;
+ using base_type::pop_back;
+ using base_type::back;
+ using base_type::begin;
+ using base_type::end;
+ using base_type::operator[];
+ using base_type::size_type;
+ using base_type::difference_type;
+ using base_type::const_iterator;
+ friend bool operator!=(MathIterator const &, MathIterator const &);
+ friend bool operator==(MathIterator const &, MathIterator const &);
+
+ /// default constructor
+ MathIterator();
/// start with given inset
explicit MathIterator(MathInset * p);
- /// start with given position
- //explicit MathIterator(MathCursor::cursor_type const & cursor);
///
MathCursorPos const & operator*() const;
///
/// move on one step
void operator++();
/// move on several steps
- void jump(MathInset::difference_type);
- /// read access to top most item (inline after running gprof!)
- MathCursorPos const & position() const { return cursor_.back(); }
- /// write access to top most item
- MathCursorPos & position() { return cursor_.back(); }
- /// read access to full path
- MathCursor::cursor_type const & cursor() const;
+ void jump(difference_type);
/// read access to top most inset
MathInset const * par() const;
/// read access to top most inset
void push(MathInset *);
/// own level up
void pop();
-
- /// current position
- MathCursor::cursor_type cursor_;
};
///
dim_.w = lyx_width_;
dim_.a = rows_.front().dim.a;
dim_.d = rows_.back().dim.d + yo;
- metricsMarkers();
+ metricsMarkers2();
xcell(0).setDim(dim_);
#endif
}
#else
xcell(0).drawExternal(pi, x + 1, y, rows_);
#endif
- drawMarkers(pi, x, y);
+ drawMarkers2(pi, x, y);
}