#include "debug.h"
#include "mathed/math_inset.h"
+#include "mathed/math_data.h"
+
#include "insets/updatableinset.h"
+
#include <boost/assert.hpp>
using std::endl;
;
return os;
}
+
+
+
+
+void increment(CursorBase & it)
+{
+ CursorSlice & top = it.back();
+ MathArray & ar = top.asMathInset()->cell(top.idx_);
+
+ // move into the current inset if possible
+ // it is impossible for pos() == size()!
+ MathInset * n = 0;
+ if (top.pos_ != ar.size())
+ n = (ar.begin() + top.pos_)->nucleus();
+ if (n && n->isActive()) {
+ it.push_back(CursorSlice(n));
+ return;
+ }
+
+ // otherwise move on one cell back if possible
+ if (top.pos_ < ar.size()) {
+ // pos() == size() is valid!
+ ++top.pos_;
+ return;
+ }
+
+ // otherwise try to move on one cell if possible
+ while (top.idx_ + 1 < top.asMathInset()->nargs()) {
+ // idx() == nargs() is _not_ valid!
+ ++top.idx_;
+ if (top.asMathInset()->validCell(top.idx_)) {
+ top.pos_ = 0;
+ return;
+ }
+ }
+
+ // otherwise leave array, move on one back
+ // this might yield pos() == size(), but that's a ok.
+ it.pop_back();
+ // it certainly invalidates top
+ ++it.back().pos_;
+}
+
+
+CursorBase ibegin(InsetBase * p)
+{
+ CursorBase it;
+ it.push_back(CursorSlice(p));
+ return it;
+}
+
+
+CursorBase iend(InsetBase * p)
+{
+ CursorBase it;
+ it.push_back(CursorSlice(p));
+ CursorSlice & top = it.back();
+ top.idx_ = top.asMathInset()->nargs() - 1;
+ top.pos_ = top.asMathInset()->cell(top.idx_).size();
+ return it;
+}
/// test for order
bool operator>(CursorSlice const &, CursorSlice const &);
+#include <vector>
+
+
+// this is used for traversing math insets
+typedef std::vector<CursorSlice> CursorBase;
+/// move on one step
+void increment(CursorBase &);
+///
+CursorBase ibegin(InsetBase * p);
+///
+CursorBase iend(InsetBase * p);
+
+
#endif
math_hullinset.h \
math_inset.C \
math_inset.h \
- math_iterator.C \
- math_iterator.h \
math_kerninset.C \
math_kerninset.h \
math_lefteqninset.C \
#warning pretty ugly
#endif
static InsetFormulaBase * lastformula = 0;
- static MathIterator current = MathIterator(ibegin(par().nucleus()));
+ static CursorBase current = CursorBase(ibegin(par().nucleus()));
static MathArray ar;
static string laststr;
ar.clear();
mathed_parse_cell(ar, str);
} else {
- ++current;
+ increment(current);
}
//lyxerr << "searching '" << str << "' in " << this << ar << endl;
- for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
+ for (CursorBase it = current; it != iend(par().nucleus()); increment(it)) {
CursorSlice & top = it.back();
MathArray const & a = top.asMathInset()->cell(top.idx_);
if (a.matchpart(ar, top.pos_)) {
bool positionable
- (MathIterator const & cursor, MathIterator const & anchor)
+ (CursorBase const & cursor, CursorBase 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 (MathIterator::size_type i = 0; i < cursor.size(); ++i)
+ for (CursorBase::size_type i = 0; i < cursor.size(); ++i)
if (cursor[i].asMathInset() != anchor[i].asMathInset())
return false;
dump("up 1");
macroModeClose();
selHandle(sel);
- MathIterator save = Cursor_;
+ CursorBase save = Cursor_;
if (goUpDown(true))
return true;
Cursor_ = save;
dump("down 1");
macroModeClose();
selHandle(sel);
- MathIterator save = Cursor_;
+ CursorBase save = Cursor_;
if (goUpDown(false))
return true;
Cursor_ = save;
void MathCursor::touch()
{
- MathIterator::const_iterator it = Cursor_.begin();
- MathIterator::const_iterator et = Cursor_.end();
+ CursorBase::const_iterator it = Cursor_.begin();
+ CursorBase::const_iterator et = Cursor_.end();
for ( ; it != et; ++it)
it->cell().touch();
}
bool MathCursor::bruteFind
(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
- MathIterator best_cursor;
+ CursorBase best_cursor;
double best_dist = 1e10;
- MathIterator it = ibegin(formula()->par().nucleus());
- MathIterator et = iend(formula()->par().nucleus());
+ CursorBase it = ibegin(formula()->par().nucleus());
+ CursorBase et = iend(formula()->par().nucleus());
while (1) {
// avoid invalid nesting when selecting
if (!selection_ || positionable(it, Anchor_)) {
if (it == et)
break;
- ++it;
+ increment(it);
}
if (best_dist < 1e10)
{
double best_dist = 1e10;
- MathIterator it = Cursor_;
+ CursorBase it = Cursor_;
it.back().setPos(0);
- MathIterator et = Cursor_;
+ CursorBase et = Cursor_;
int n = et.back().asMathInset()->cell(et.back().idx_).size();
et.back().setPos(n);
for (int i = 0; ; ++i) {
}
if (it == et)
break;
- ++it;
+ increment(it);
}
}
}
-void MathCursor::setSelection(MathIterator const & where, size_type n)
+void MathCursor::setSelection(CursorBase const & where, size_type n)
{
selection_ = true;
Anchor_ = where;
#ifndef MATH_CURSOR
#define MATH_CURSOR
+#include "cursor_slice.h"
#include "math_inset.h"
#include "math_data.h"
-#include "math_iterator.h"
-#include "support/types.h"
#include <string>
/// dump selection information for debugging
void dump(char const * str) const;
/// moves on
- void setSelection(MathIterator const & where, size_type n);
+ void setSelection(CursorBase const & where, size_type n);
/// grab selection marked by anchor and current cursor
std::string grabSelection() const;
/// guess what
idx_type & idx();
/// path of positions the cursor had to go if it were leaving each inset
- MathIterator Cursor_;
+ CursorBase Cursor_;
/// path of positions the anchor had to go if it were leaving each inset
- mutable MathIterator Anchor_;
+ mutable CursorBase Anchor_;
/// pointer to enclsing LyX inset
InsetFormulaBase * formula_;
// Selection stuff
+++ /dev/null
-/**
- * \file math_iterator.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author André Pönitz
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "math_iterator.h"
-#include "math_inset.h"
-#include "math_data.h"
-
-#include <boost/assert.hpp>
-
-
-void MathIterator::operator++()
-{
- CursorSlice & top = back();
- MathArray & ar = top.asMathInset()->cell(top.idx_);
-
- // move into the current inset if possible
- // it is impossible for pos() == size()!
- MathInset * n = 0;
- if (top.pos_ != ar.size())
- n = (ar.begin() + top.pos_)->nucleus();
- if (n && n->isActive()) {
- push_back(CursorSlice(n));
- return;
- }
-
- // otherwise move on one cell back if possible
- if (top.pos_ < ar.size()) {
- // pos() == size() is valid!
- ++top.pos_;
- return;
- }
-
- // otherwise try to move on one cell if possible
- while (top.idx_ + 1 < top.asMathInset()->nargs()) {
- // idx() == nargs() is _not_ valid!
- ++top.idx_;
- if (top.asMathInset()->validCell(top.idx_)) {
- top.pos_ = 0;
- return;
- }
- }
-
- // otherwise leave array, move on one back
- // this might yield pos() == size(), but that's a ok.
- pop_back();
- // it certainly invalidates top
- ++back().pos_;
-}
-
-
-bool operator==(MathIterator const & it, MathIterator const & jt)
-{
- return MathIterator::base_type(it) == MathIterator::base_type(jt);
-}
-
-
-bool operator!=(MathIterator const & it, MathIterator const & jt)
-{
- return MathIterator::base_type(it) != MathIterator::base_type(jt);
-}
-
-
-MathIterator ibegin(MathInset * p)
-{
- MathIterator it;
- it.push_back(CursorSlice(p));
- return it;
-}
-
-
-MathIterator iend(MathInset * p)
-{
- MathIterator it;
- it.push_back(CursorSlice(p));
- CursorSlice & top = it.back();
- top.idx_ = top.asMathInset()->nargs() - 1;
- top.pos_ = top.asMathInset()->cell(top.idx_).size();
- return it;
-}
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file math_iterator.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author André Pönitz
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef MATH_ITERATOR_H
-#define MATH_ITERATOR_H
-
-#include "cursor_slice.h"
-
-#include <vector>
-
-
-// this is used for traversing math insets
-
-class MathIterator : private std::vector<CursorSlice> {
-public:
- // re-use inherited stuff
- typedef std::vector<CursorSlice> 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::erase;
- 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 &);
-
- /// move on one step
- void operator++();
- /// read access to top most item
- MathArray const & cell() const;
-};
-
-///
-bool operator==(MathIterator const &, MathIterator const &);
-///
-bool operator!=(MathIterator const &, MathIterator const &);
-
-///
-MathIterator ibegin(MathInset * p);
-///
-MathIterator iend(MathInset * p);
-
-#endif