mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
more IU
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8351 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
04076d27ac
commit
55ee6cb346
@ -17,8 +17,11 @@
|
||||
#include "debug.h"
|
||||
|
||||
#include "mathed/math_inset.h"
|
||||
#include "mathed/math_data.h"
|
||||
|
||||
#include "insets/updatableinset.h"
|
||||
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
using std::endl;
|
||||
@ -181,3 +184,64 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
|
||||
;
|
||||
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;
|
||||
}
|
||||
|
@ -127,4 +127,17 @@ bool operator<(CursorSlice const &, CursorSlice const &);
|
||||
/// 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
|
||||
|
@ -86,8 +86,6 @@ libmathed_la_SOURCES = \
|
||||
math_hullinset.h \
|
||||
math_inset.C \
|
||||
math_inset.h \
|
||||
math_iterator.C \
|
||||
math_iterator.h \
|
||||
math_kerninset.C \
|
||||
math_kerninset.h \
|
||||
math_lefteqninset.C \
|
||||
|
@ -830,7 +830,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
|
||||
#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;
|
||||
|
||||
@ -842,11 +842,11 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
|
||||
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_)) {
|
||||
|
@ -246,14 +246,14 @@ void MathCursor::last()
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -491,7 +491,7 @@ bool MathCursor::up(bool sel)
|
||||
dump("up 1");
|
||||
macroModeClose();
|
||||
selHandle(sel);
|
||||
MathIterator save = Cursor_;
|
||||
CursorBase save = Cursor_;
|
||||
if (goUpDown(true))
|
||||
return true;
|
||||
Cursor_ = save;
|
||||
@ -505,7 +505,7 @@ bool MathCursor::down(bool sel)
|
||||
dump("down 1");
|
||||
macroModeClose();
|
||||
selHandle(sel);
|
||||
MathIterator save = Cursor_;
|
||||
CursorBase save = Cursor_;
|
||||
if (goUpDown(false))
|
||||
return true;
|
||||
Cursor_ = save;
|
||||
@ -788,8 +788,8 @@ void MathCursor::pullArg()
|
||||
|
||||
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();
|
||||
}
|
||||
@ -1028,11 +1028,11 @@ bool MathCursor::goUpDown(bool up)
|
||||
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_)) {
|
||||
@ -1052,7 +1052,7 @@ bool MathCursor::bruteFind
|
||||
|
||||
if (it == et)
|
||||
break;
|
||||
++it;
|
||||
increment(it);
|
||||
}
|
||||
|
||||
if (best_dist < 1e10)
|
||||
@ -1065,9 +1065,9 @@ void MathCursor::bruteFind2(int x, int y)
|
||||
{
|
||||
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) {
|
||||
@ -1083,7 +1083,7 @@ void MathCursor::bruteFind2(int x, int y)
|
||||
}
|
||||
if (it == et)
|
||||
break;
|
||||
++it;
|
||||
increment(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1286,7 +1286,7 @@ bool MathCursor::interpret(char c)
|
||||
}
|
||||
|
||||
|
||||
void MathCursor::setSelection(MathIterator const & where, size_type n)
|
||||
void MathCursor::setSelection(CursorBase const & where, size_type n)
|
||||
{
|
||||
selection_ = true;
|
||||
Anchor_ = where;
|
||||
|
@ -13,10 +13,9 @@
|
||||
#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>
|
||||
|
||||
@ -225,7 +224,7 @@ public:
|
||||
/// 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
|
||||
@ -282,9 +281,9 @@ private:
|
||||
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
|
||||
|
@ -1,88 +0,0 @@
|
||||
/**
|
||||
* \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;
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
// -*- 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
|
Loading…
Reference in New Issue
Block a user