math_notinset.h \
math_parser.C \
math_parser.h \
+ math_pos.C \
+ math_pos.h \
math_replace.h \
math_rootinset.C \
math_rootinset.h \
if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background))
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
- if (mathcursor && mathcursor->formula() == this) {
+ if (mathcursor &&
+ const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
+ {
mathcursor->drawSelection(pain);
pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
pain.fillRectangle(int(x), a , w, h, LColor::mathmacrobg);
pain.rectangle(int(x), a, w, h, LColor::mathframe);
- if (mathcursor && mathcursor->formula() == this)
+ if (mathcursor &&
+ const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
mathcursor->drawSelection(pain);
pain.text(int(x + 2), y, prefix(), font);
data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
else {
std::vector<MathInset::idx_type> indices =
- i1.par_->idxBetween(i1.idx_, i2.idx_);
+ i1.par_->nucleus()->idxBetween(i1.idx_, i2.idx_);
for (MathInset::idx_type i = 0; i < indices.size(); ++i)
data_.push_back(i1.cell(indices[i]));
}
i1.cell().erase(i1.pos_, i2.pos_);
else {
std::vector<MathInset::idx_type> indices =
- i1.par_->idxBetween(i1.idx_, i2.idx_);
+ i1.par_->nucleus()->idxBetween(i1.idx_, i2.idx_);
for (unsigned i = 0; i < indices.size(); ++i)
i1.cell(indices[i]).erase();
}
void MathCursor::push(MathAtom & t)
{
- Cursor_.push_back(MathCursorPos(t.nucleus()));
+ MathCursorPos p;
+ p.par_ = &t;
+ p.idx_ = 0;
+ p.pos_ = 0;
+ Cursor_.push_back(p);
}
bool MathCursor::isInside(MathInset const * p) const
{
for (unsigned i = 0; i < Cursor_.size(); ++i)
- if (Cursor_[i].par_ == p)
+ if (Cursor_[i].par_->nucleus() == p)
return true;
return false;
}
// we can't move into anything new during selection
if (Cursor_.size() == Anchor_.size())
return false;
- if (t.nucleus() != Anchor_[Cursor_.size()].par_)
+ if (&t != Anchor_[Cursor_.size()].par_)
return false;
}
return true;
cursor_type best_cursor;
double best_dist = 1e10;
- MathIterator it(formula()->par().nucleus());
- MathIterator et;
+ MathIterator it = ibegin(formula()->par());
+ MathIterator et = iend(formula()->par());
for ( ; it != et; ++it) {
+ //lyxerr << "*it: " << *it << " *et: " << *et << "\n";
if (selection_) {
// avoid deeper nested insets when selecting
if (it.cursor().size() > Anchor_.size())
continue;
// anchor might be deeper!
if (it.cursor().size() == Anchor_.size())
- if (it.par() != Anchor_.back().par_)
+ if (it.par().nucleus() != Anchor_.back().par_->nucleus())
continue;
//if (it.par() != Anchor_[it.cursor().size()].par_)
// continue;
if (best_dist < 1e10)
Cursor_ = best_cursor;
//lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n";
+ lyx::Assert(Cursor_.size());
dump("setPos 2");
}
MathCursorPos i1;
MathCursorPos i2;
getSelection(i1, i2);
- //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
if (i1.idx_ == i2.idx_) {
MathXArray & c = i1.xcell();
pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
} else {
std::vector<MathInset::idx_type> 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();
#ifdef WITH_WARNINGS
#warning This should probably take cellXOffset and cellYOffset into account
#endif
- dump("getPos 1");
x = xarray().xo() + xarray().pos2x(pos());
y = xarray().yo();
- dump("getPos 2");
}
-MathInset * MathCursor::par() const
+MathAtom & MathCursor::par() const
{
- return cursor().par_;
+ return *cursor().par_;
}
-InsetFormulaBase const * MathCursor::formula()
+InsetFormulaBase * MathCursor::formula()
{
return formula_;
}
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;
return dummy;
}
+ if (Cursor_.size() == 0) {
+ lyxerr << "############ Cursor_.size() == 0 not valid\n";
+ return dummy;
+ }
+
return cursor().cell();
}
MathXArray & MathCursor::xarray() const
{
+ static MathXArray dummy;
+
+ if (Cursor_.size() == 0) {
+ lyxerr << "############ Cursor_.size() == 0 not valid\n";
+ return dummy;
+ }
+
return cursor().xcell();
}
p->mutate(LM_OT_EQNARRAY);
idx() = 0;
pos() = size();
- return;
- }
-
- p->addRow(row());
+ } else {
+ p->addRow(row());
- // split line
- const row_type r = row();
- for (col_type c = col() + 1; c < p->ncols(); ++c)
- p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
+ // split line
+ const row_type r = row();
+ for (col_type c = col() + 1; c < p->ncols(); ++c)
+ p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
- // split cell
- splitCell();
- p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
+ // split cell
+ splitCell();
+ p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
+ }
}
MathCursorPos & MathCursor::cursor()
{
+ lyx::Assert(Cursor_.size());
return Cursor_.back();
}
MathCursorPos const & MathCursor::cursor() const
{
+ lyx::Assert(Cursor_.size());
return Cursor_.back();
}
cursor_type best_cursor;
double best_dist = 1e10;
- MathIterator it(formula()->par().nucleus());
- MathIterator et;
+ MathIterator it = ibegin(formula()->par());
+ MathIterator et = iend(formula()->par());
for ( ; it != et; ++it) {
int xo = it.position().xpos();
int yo = it.position().ypos();
MathCursorPos MathCursor::normalAnchor() const
{
+ lyx::Assert(Anchor_.size() >= Cursor_.size());
// use Anchor on the same level as Cursor
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
}
-////////////////////////////////////////////////////////////////////////
-
-
-MathCursorPos::MathCursorPos()
- : par_(0), idx_(0), pos_(0)
-{}
-
-
-MathCursorPos::MathCursorPos(MathInset * p)
- : par_(p), idx_(0), pos_(0)
-{}
-
-
-MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
-{
- return par_->cell(idx);
-}
-
-
-MathArray & MathCursorPos::cell() const
-{
- return par_->cell(idx_);
-}
-
-
-MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
-{
- return par_->xcell(idx);
-}
-
-
-MathXArray & MathCursorPos::xcell() const
-{
- return par_->xcell(idx_);
-}
-
-
-int MathCursorPos::xpos() const
-{
- return xcell().xo() + xcell().pos2x(pos_);
-}
-
-
-int MathCursorPos::ypos() const
-{
- return xcell().yo();
-}
-
-std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
-{
- os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
- return os;
-}
-
-
-bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
-{
- return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
-}
-
-
-bool operator!=(MathCursorPos const & ti, MathCursorPos const & it)
-{
- return ti.par_ != it.par_ || ti.idx_ != it.idx_ || ti.pos_ != it.pos_;
-}
-
-
-bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
-{
- if (ti.par_ != it.par_) {
- lyxerr << "can't compare cursor and anchor in different insets\n";
- return true;
- }
- if (ti.idx_ != it.idx_)
- return ti.idx_ < it.idx_;
- return ti.pos_ < it.pos_;
-}
-
-
#include "math_defs.h"
#include "math_inset.h"
+#include "math_pos.h"
#include "LString.h"
class InsetFormulaBase;
*/
-/// Description of a position
-class MathCursorPos {
-public:
- ///
- MathCursorPos();
- ///
- explicit MathCursorPos(MathInset * p);
-
- /// returns cell corresponding to this position
- MathArray & cell() const;
- /// returns cell corresponding to this position
- MathArray & cell(MathInset::idx_type idx) const;
- /// returns xcell corresponding to this position
- MathXArray & xcell() const;
- /// returns xcell corresponding to this position
- MathXArray & xcell(MathInset::idx_type idx) const;
- ///
- int xpos() const;
- ///
- int ypos() const;
-
-public:
- /// pointer to an inset
- MathInset * par_;
- /// cell index of a position in this inset
- MathInset::idx_type idx_;
- /// position in this cell
- MathInset::pos_type pos_;
-};
-
-/// test for equality
-bool operator==(MathCursorPos const &, MathCursorPos const &);
-/// test for inequality
-bool operator!=(MathCursorPos const &, MathCursorPos const &);
-/// test for order
-bool operator<(MathCursorPos const &, MathCursorPos const &);
-/// output
-std::ostream & operator<<(std::ostream &, MathCursorPos const &);
-
-
-/// see above
class MathCursor {
public:
/// short of anything else reasonable
/// in pixels from top of screen
void getPos(int & x, int & y);
///
- MathInset * par() const;
+ MathAtom & par() const;
/// return the next enclosing grid inset and the cursor's index in it
MathGridInset * enclosingGrid(idx_type &) const;
///
- InsetFormulaBase const * formula();
+ InsetFormulaBase * formula();
/// current offset in the current cell
pos_type pos() const;
/// current cell
idx_type & idx();
///
- InsetFormulaBase * const formula_;
+ InsetFormulaBase * formula_;
///
MathTextCodes lastcode_;
// Selection stuff
* the GNU General Public Licence version 2 or later.
*/
-#ifndef MATHEDARRAY_H
-#define MATHEDARRAY_H
+#ifndef MATH_DATA_H
+#define MATH_DATA_H
#include <vector>
typedef buffer_type::iterator iterator;
///
typedef buffer_type::size_type size_type;
+ ///
+ typedef buffer_type::size_type idx_type;
+ ///
+ typedef buffer_type::size_type pos_type;
public:
///
#include <config.h>
-#include "debug.h"
#include "math_iterator.h"
+#include "debug.h"
+#include "support/LAssert.h"
-MathIterator::MathIterator()
-{}
+//MathIterator::MathIterator()
+//{}
-MathIterator::MathIterator(MathInset * p)
+MathIterator::MathIterator(MathAtom & t)
{
- push(p);
+ push(t);
}
MathCursorPos const & MathIterator::position() const
{
+ lyx::Assert(cursor_.size());
return cursor_.back();
}
MathCursorPos & MathIterator::position()
{
+ lyx::Assert(cursor_.size());
return cursor_.back();
}
}
-MathInset * MathIterator::par() const
+MathAtom const & MathIterator::par() const
+{
+ return *(position().par_);
+}
+
+
+MathAtom & MathIterator::par()
{
- return cursor_.size() ? cursor_.back().par_ : 0;
+ return *(position().par_);
}
MathXArray const & MathIterator::xcell() const
{
- if (!par())
- lyxerr << "MathIterator::xcell: no cell\n";
return par()->xcell(position().idx_);
}
-MathInset * MathIterator::nextInset() const
+MathAtom * MathIterator::nextInset() const
{
if (position().pos_ == xcell().data_.size())
return 0;
- return (xcell().begin() + position().pos_)->nucleus();
+ return const_cast<MathAtom *>(xcell().begin() + position().pos_);
}
-void MathIterator::push(MathInset * p)
+void MathIterator::push(MathAtom & t)
{
//lyxerr << "push: " << p << endl;
- cursor_.push_back(MathCursorPos(p));
+ cursor_.push_back(MathCursorPos(t));
}
void MathIterator::pop()
{
//lyxerr << "pop: " << endl;
+ lyx::Assert(cursor_.size());
cursor_.pop_back();
}
}
+void MathIterator::goEnd()
+{
+ position().idx_ = par()->nargs() - 1;
+ position().pos_ = xcell().data_.size();
+}
+
+
void MathIterator::operator++()
{
// move into the current inset if possible
// it is impossible for pos() == size()!
- if (nextInset() && nextInset()->isActive()) {
- push(nextInset());
+ if (nextInset() && nextInset()->nucleus()->isActive()) {
+ push(*nextInset());
return;
}
return;
}
- // otherwise leave array, move on one cell
+ // otherwise leave array, move on one position
// this might yield pos() == size(), but that's a ok.
pop();
++position().pos_;
return it.cursor() != jt.cursor();
}
+
+
+MathIterator ibegin(MathAtom & t)
+{
+ return MathIterator(t);
+}
+
+
+MathIterator iend(MathAtom & t)
+{
+ MathIterator it(t);
+ it.goEnd();
+ return it;
+}
class MathIterator {
public:
/// default constructor, used for end of range
- MathIterator();
+ //MathIterator();
/// start with given formula
- explicit MathIterator(MathInset * p);
+ explicit MathIterator(MathAtom & t);
/// start with given position
explicit MathIterator(MathCursor::cursor_type const & cursor);
///
/// read access to full path
MathCursor::cursor_type const & cursor() const;
/// read access to top most inset
- MathInset * par() const;
+ MathAtom const & par() const;
+ /// read access to top most inset
+ MathAtom & par();
+ /// helper for iend
+ void goEnd();
private:
/// write access to top most item
MathXArray const & xcell() const;
/// write access to top most item
- MathInset * nextInset() const;
+ MathAtom * nextInset() const;
/// own level down
- void push(MathInset *);
+ void push(MathAtom &);
/// own level up
void pop();
///
bool operator!=(MathIterator const &, MathIterator const &);
+///
+MathIterator ibegin(MathAtom & p);
+///
+MathIterator iend(MathAtom & p);
#endif
--- /dev/null
+#include "config.h"
+
+#include <iostream>
+
+#include "math_pos.h"
+#include "math_inset.h"
+#include "debug.h"
+#include "support/LAssert.h"
+
+
+MathCursorPos::MathCursorPos()
+ : par_(0), idx_(0), pos_(0)
+{}
+
+
+MathCursorPos::MathCursorPos(MathAtom & t)
+ : par_(&t), 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);
+}
+
+
+MathArray & MathCursorPos::cell() const
+{
+ lyx::Assert(par_);
+ lyx::Assert(par_->nucleus());
+ return par_->nucleus()->cell(idx_);
+}
+
+
+MathXArray & MathCursorPos::xcell(MathArray::idx_type idx) const
+{
+ lyx::Assert(par_);
+ lyx::Assert(par_->nucleus());
+ return par_->nucleus()->xcell(idx);
+}
+
+
+MathXArray & MathCursorPos::xcell() const
+{
+ lyx::Assert(par_);
+ lyx::Assert(par_->nucleus());
+ return par_->nucleus()->xcell(idx_);
+}
+
+
+int MathCursorPos::xpos() const
+{
+ return xcell().xo() + xcell().pos2x(pos_);
+}
+
+
+int MathCursorPos::ypos() const
+{
+ return xcell().yo();
+}
+
+
+std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
+{
+ os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
+ return os;
+}
+
+
+bool operator==(MathCursorPos const & p, MathCursorPos const & q)
+{
+ return p.par_ == q.par_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
+}
+
+
+bool operator!=(MathCursorPos const & p, MathCursorPos const & q)
+{
+ return p.par_ != q.par_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
+}
+
+
+bool operator<(MathCursorPos const & p, MathCursorPos const & q)
+{
+ if (p.par_ != q.par_) {
+ lyxerr << "can't compare cursor and anchor in different insets\n";
+ return true;
+ }
+ if (p.idx_ != q.idx_)
+ return p.idx_ < q.idx_;
+ return p.pos_ < q.pos_;
+}
+
+
--- /dev/null
+#ifndef MATH_POS_H
+#define MATH_POS_H
+
+#include <iosfwd>
+#include "math_xdata.h"
+
+
+/// Description of a position
+class MathCursorPos {
+public:
+ ///
+ MathCursorPos();
+ ///
+ explicit MathCursorPos(MathAtom &);
+
+ /// returns cell corresponding to this position
+ MathArray & cell() const;
+ /// returns cell corresponding to this position
+ MathArray & cell(MathArray::idx_type idx) const;
+ /// returns xcell corresponding to this position
+ MathXArray & xcell() const;
+ /// returns xcell corresponding to this position
+ MathXArray & xcell(MathArray::idx_type idx) const;
+ ///
+ int xpos() const;
+ ///
+ int ypos() const;
+
+public:
+ /// pointer to an inset
+ MathAtom * par_;
+ /// cell index of a position in this inset
+ MathArray::idx_type idx_;
+ /// position in this cell
+ MathArray::pos_type pos_;
+};
+
+/// test for equality
+bool operator==(MathCursorPos const &, MathCursorPos const &);
+/// test for inequality
+bool operator!=(MathCursorPos const &, MathCursorPos const &);
+/// test for order
+bool operator<(MathCursorPos const &, MathCursorPos const &);
+/// output
+std::ostream & operator<<(std::ostream &, MathCursorPos const &);
+
+#endif