On Sat, Jul 02, 2005 at 08:43:22PM +0200, Andre Poenitz wrote:
> On Fri, Jul 01, 2005 at 11:43:45PM +0300, Martin Vermeer wrote:
> > OK, I see it now: idx_type should be a struct with two int members, .row
> > and .col. And suitable operator definitions added. No duplication of
> > information, and still "idx() = ..." will work. Does that sound like a 
> > plan?
> 
> I still don't think so. idx_ is just an integer offset in the cell
> vector. These cells may be laid out in a grid as in, well, a
> MathGridInset, or even a MathFracInset, but do not have to (as shown
> by e.g. MathSqrtInset).
> 
> This single-number idx member is chosen as primary information as it is
> directly useful when accessing the cell vector.
> 
> For grid-like structures it is sometimes convienient to extract row and
> col from idx. So there are some helper functions. And sometimes it is
> useful to give the user the impression that row and col are primary
> because that's what the user expects if he e.g. works in grids. In this 
> situation we just adjust the idx. You found places where this adjsutment
> was not or not properly done. But that means just that: The adjustment
> is wrong, not the scheme.
> 
> You propose to make row and col primary information but that does not
> fit well into the current scheme. We'd need to compute idx ach time we
> access the cell vector. For some insets like sqrt it would not even be
> clear what values for row and col are permissable etc.
> 
> Andre'

Andre,

While most of what you write has merit, I respectfully want to play the
devil's advocate with the attached patch, which just bites the bullet
and re-writes all the idx()-as-lvalue statements. It eliminates idx_ and
makes row_, col_ the primary data. 

It is true that this causes some gotchas, e.g., with tabulars, which I'm 
sure you will spot in the code. It is also true that currently some
unnecessary idx computations are done, but most of those can be
eliminated (and anyway are very cheap integer operations). And sqrt and
friends need work... this is for now just a proof-of-principle.

It is also true that this patch got rather big, because "idx() =..." was
used all over the place (I think this is not recommended practice BTW).
But it is essentially mostly a dumb substitution exercise. What I want
to argue is that this is a _fundamental_ fix for the need for (and
sometimes wrong/missing) adjustments, not a kludge.

I rest my case ;-)

- Martin

BTW I'll be poorly connected for the week to come... please try to sort 
this one out without me ;-)

Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.126
diff -u -p -r1.126 cursor.C
--- cursor.C    6 May 2005 20:00:30 -0000       1.126
+++ cursor.C    2 Jul 2005 20:13:17 -0000
@@ -877,7 +877,7 @@ void LCursor::normalize()
                       << idx() << ' ' << nargs()
                       << " in: " << &inset() << endl;
        }
-       idx() = min(idx(), lastidx());
+       idx(min(idx(), lastidx()));
 
        if (pos() > lastpos()) {
                lyxerr << "this should not really happen - 2: "
@@ -916,7 +916,7 @@ bool LCursor::goUpDown(bool up)
                        if (p && p->has(up)) {
                                --pos();
                                push(inset());
-                               idx() = up; // the superscript has index 1
+                               idx(up); // the superscript has index 1
                                pos() = lastpos();
                                //lyxerr << "updown: handled by scriptinset to 
the left" << endl;
                                return true;
@@ -928,7 +928,7 @@ bool LCursor::goUpDown(bool up)
                        MathScriptInset const * p = nextAtom()->asScriptInset();
                        if (p && p->has(up)) {
                                push(inset());
-                               idx() = up;
+                               idx(up);
                                pos() = 0;
                                //lyxerr << "updown: handled by scriptinset to 
the right" << endl;
                                return true;
Index: cursor_slice.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.C,v
retrieving revision 1.27
diff -u -p -r1.27 cursor_slice.C
--- cursor_slice.C      31 Jan 2005 16:29:38 -0000      1.27
+++ cursor_slice.C      2 Jul 2005 20:13:17 -0000
@@ -30,16 +30,27 @@ using std::endl;
 
 
 CursorSlice::CursorSlice()
-       : inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false)
+       : inset_(0), row_(0), col_(0), pit_(0), pos_(0), boundary_(false)
 {}
 
 
 CursorSlice::CursorSlice(InsetBase & p)
-       : inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false)
+       : inset_(&p), row_(0), col_(0), pit_(0), pos_(0), boundary_(false)
 {
        BOOST_ASSERT(inset_);
 }
 
+void CursorSlice::idx(idx_type idx) 
+{
+       if (ncols() == 0) {
+               col_ = idx;
+               row_ = 0;
+       } else {
+               col_ = idx % ncols(); 
+               row_ = idx / ncols();
+       }
+}
+
 
 size_t CursorSlice::nargs() const
 {
@@ -72,14 +83,14 @@ CursorSlice::pos_type CursorSlice::lastp
 CursorSlice::row_type CursorSlice::row() const
 {
        BOOST_ASSERT(asMathInset());
-       return asMathInset()->row(idx_);
+       return asMathInset()->row(idx());
 }
 
 
 CursorSlice::col_type CursorSlice::col() const
 {
        BOOST_ASSERT(asMathInset());
-       return asMathInset()->col(idx_);
+       return asMathInset()->col(idx());
 }
 
 
@@ -100,20 +111,20 @@ UpdatableInset * CursorSlice::asUpdatabl
 MathArray & CursorSlice::cell() const
 {
        BOOST_ASSERT(asMathInset());
-       return asMathInset()->cell(idx_);
+       return asMathInset()->cell(idx());
 }
 
 
 LyXText * CursorSlice::text()
 {
        BOOST_ASSERT(inset_);
-       return inset_->getText(idx_);
+       return inset_->getText(idx());
 }
 
 LyXText const * CursorSlice::text() const
 {
        BOOST_ASSERT(inset_);
-       return inset_->getText(idx_);
+       return inset_->getText(idx());
 }
 
 
Index: cursor_slice.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.h,v
retrieving revision 1.22
diff -u -p -r1.22 cursor_slice.h
--- cursor_slice.h      30 Jun 2005 18:02:39 -0000      1.22
+++ cursor_slice.h      2 Jul 2005 20:13:17 -0000
@@ -42,6 +42,7 @@ class CursorSlice {
 public:
        /// type for cell number in inset
        typedef size_t idx_type;
+
        /// type for paragraph numbers positions within a cell
        typedef lyx::pit_type pit_type;
        /// type for cursor positions within a cell
@@ -59,13 +60,9 @@ public:
        /// the current inset
        InsetBase & inset() const { return *inset_; }
        /// return the cell this cursor is in
-       idx_type idx() const { return idx_; }
-       /// return the cell this cursor is in
-       idx_type & idx() { return idx_; }
-       /// Save current cursor idx as row, col
-       void idxSave() { col_ = idx_ % ncols(); row_ = idx_ / ncols(); }
-       /// update idx to correspond to row, col
-       void idxLoad() { idx_ = col_ + ncols() * row_; }
+       idx_type idx() const { return col_ + ncols() * row_; }
+       /// set the cell this cursor is in
+       void idx(idx_type idx);
        /// return the last cell in this inset
        idx_type lastidx() const { return nargs() - 1; }
        /// return the offset of the paragraph this cursor is in
@@ -125,8 +122,6 @@ public:
        /// pointer to 'owning' inset. This is some kind of cache.
        InsetBase * inset_;
 private:
-       /// cell index of a position in this inset
-       idx_type idx_;
        /// row position in inset
        row_type row_;
        /// column position in inset
Index: dociterator.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dociterator.C,v
retrieving revision 1.27
diff -u -p -r1.27 dociterator.C
--- dociterator.C       26 Apr 2005 11:12:10 -0000      1.27
+++ dociterator.C       2 Jul 2005 20:13:17 -0000
@@ -329,7 +329,7 @@ void DocIterator::forwardPos()
        // otherwise try to move on one cell if possible
        if (tip.idx() < lastidx()) {
                //lyxerr << "... next idx" << endl;
-               ++tip.idx();
+               tip.idx(tip.idx() + 1);
                tip.pit() = 0;
                tip.pos() = 0;
                return;
@@ -369,7 +369,7 @@ void DocIterator::forwardPosNoDescend()
        // otherwise try to move on one cell if possible
        if (tip.idx() < lastidx()) {
                //lyxerr << "... next idx" << endl;
-               ++tip.idx();
+               tip.idx(tip.idx() + 1);
                tip.pit() = 0;
                tip.pos() = 0;
                return;
@@ -436,7 +436,7 @@ void DocIterator::backwardPos()
        //this dog bites his tail
        if (empty()) {
                push_back(CursorSlice(*inset_));
-               top().idx() = lastidx();
+               top().idx(lastidx());
                top().pit() = lastpit();
                top().pos() = lastpos();
                return;
@@ -451,7 +451,7 @@ void DocIterator::backwardPos()
                tip.pos() = lastpos();
                return;
        } else if (tip.idx() != 0) {
-               --tip.idx();
+               tip.idx(tip.idx() - 1);
                tip.pit() = lastpit();
                tip.pos() = lastpos();
                return;
@@ -472,7 +472,7 @@ void DocIterator::backwardPos()
 
        if (n && n->isActive()) {
                push_back(CursorSlice(*n));
-               top().idx() = lastidx();
+               top().idx(lastidx());
                top().pit() = lastpit();
                top().pos() = lastpos();
        }
Index: dociterator.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dociterator.h,v
retrieving revision 1.18
diff -u -p -r1.18 dociterator.h
--- dociterator.h       30 Jun 2005 18:02:39 -0000      1.18
+++ dociterator.h       2 Jul 2005 20:13:17 -0000
@@ -89,12 +89,8 @@ public:
        InsetBase & inset() const { return top().inset(); }
        /// return the cell of the inset this cursor is in
        idx_type idx() const { return top().idx(); }
-       /// return the cell of the inset this cursor is in
-       idx_type & idx() { return top().idx(); }
-       ///
-       void idxSave() { top().idxSave(); }
-       ///
-       void idxLoad() { top().idxLoad(); }
+       /// set the cell of the inset this cursor is in
+       void idx(idx_type idx) { top().idx(idx); }
        /// return the last possible cell in this inset
        idx_type lastidx() const;
        /// return the paragraph this cursor is in
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.52
diff -u -p -r1.52 insetbase.h
--- insets/insetbase.h  9 May 2005 17:29:21 -0000       1.52
+++ insets/insetbase.h  2 Jul 2005 20:13:17 -0000
@@ -155,7 +158,7 @@ public:
        virtual bool idxLast(LCursor &) const { return false; }
 
        /// Delete a cell and move cursor
-       virtual bool idxDelete(idx_type &) { return false; }
+       virtual bool idxDelete(idx_type) { return false; }
        /// pulls cell after pressing erase
        virtual void idxGlue(idx_type) {}
        /// returns list of cell indices that are "between" from and to for
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.466
diff -u -p -r1.466 insettabular.C
--- insets/insettabular.C       16 Jun 2005 15:20:09 -0000      1.466
+++ insets/insettabular.C       2 Jul 2005 20:13:18 -0000
@@ -412,16 +412,16 @@ void InsetTabular::edit(LCursor & cur, b
        cur.push(*this);
        if (left) {
                if (isRightToLeft(cur))
-                       cur.idx() = tabular.getLastCellInRow(0);
+                       cur.idx(tabular.getLastCellInRow(0));
                else
-                       cur.idx() = 0;
+                       cur.idx(0);
                cur.pit() = 0;
                cur.pos() = 0;
        } else {
                if (isRightToLeft(cur))
-                       cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 
1);
+                       cur.idx(tabular.getFirstCellInRow(tabular.rows() - 1));
                else
-                       cur.idx() = tabular.getNumberOfCells() - 1;
+                       cur.idx(tabular.getNumberOfCells() - 1);
                cur.pit() = 0;
                cur.pos() = cur.lastpos(); // FIXME crude guess
        }
@@ -534,7 +534,7 @@ void InsetTabular::doDispatch(LCursor & 
                cur.dispatched(); // override the cell's decision
                if (sl == cur.top())
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 
1) {
-                               cur.idx() = tabular.getCellBelow(cur.idx());
+                               cur.idx(tabular.getCellBelow(cur.idx()));
                                cur.pit() = 0;
                                cur.pos() = 0;
                                resetPos(cur);
@@ -552,7 +552,7 @@ void InsetTabular::doDispatch(LCursor & 
                cur.dispatched(); // override the cell's decision
                if (sl == cur.top())
                        if (tabular.row_of_cell(cur.idx()) != 0) {
-                               cur.idx() = tabular.getCellAbove(cur.idx());
+                               cur.idx(tabular.getCellAbove(cur.idx()));
                                cur.pit() = cur.lastpit();
                                cur.pos() = cur.lastpos();
                                resetPos(cur);
@@ -756,7 +756,7 @@ void InsetTabular::doDispatch(LCursor & 
                        for (row_type i = rs; i <= re; ++i)
                                for (col_type j = cs; j <= ce; ++j) {
                                        // cursor follows cell:
-                                       cur.idx() = tabular.getCellNumber(i, j);
+                                       cur.idx(tabular.getCellNumber(i, j));
                                        // select this cell only:
                                        cur.pos() = 0;
                                        cur.resetAnchor();
@@ -766,10 +766,10 @@ void InsetTabular::doDispatch(LCursor & 
                                        cell(cur.idx())->dispatch(cur, cmd);
                                }
                        // Restore original selection
-                       cur.idx() = tabular.getCellNumber(rs, cs);
+                       cur.idx(tabular.getCellNumber(rs, cs));
                        cur.pos() = 0;
                        cur.resetAnchor();
-                       cur.idx() = tabular.getCellNumber(re, ce);
+                       cur.idx(tabular.getCellNumber(re, ce));
                        cur.pos() = cur.top().lastpos();
                        cur.setCursor(cur);
                        cur.setSelection();
@@ -1161,7 +1161,7 @@ InsetBase * InsetTabular::editXY(LCursor
        //lyxerr << "InsetTabular::editXY: " << this << endl;
        cur.selection() = false;
        cur.push(const_cast<InsetTabular&>(*this));
-       cur.idx() = getNearestCell(x, y);
+       cur.idx(getNearestCell(x, y));
        resetPos(cur);
        return cell(cur.idx())->text_.editXY(cur, x, y);
        //int xx = cursorx_ - xo() + 
tabular.getBeginningOfTextInCell(cur.idx());
@@ -1171,7 +1171,7 @@ InsetBase * InsetTabular::editXY(LCursor
 void InsetTabular::setCursorFromCoordinates(LCursor & cur, int x, int y) const
 {
        //lyxerr << "# InsetTabular::setCursorFromCoordinates()\n" << cur << 
endl;
-       cur.idx() = getNearestCell(x, y);
+       cur.idx(getNearestCell(x, y));
        resetPos(cur);
        return cell(cur.idx())->text_.setCursorFromCoordinates(cur, x, y);
 }
@@ -1263,17 +1263,17 @@ void InsetTabular::moveNextCell(LCursor 
                        row_type const row = tabular.row_of_cell(cur.idx());
                        if (row == tabular.rows() - 1)
                                return;
-                       cur.idx() = 
tabular.getCellBelow(tabular.getLastCellInRow(row));
+                       
cur.idx(tabular.getCellBelow(tabular.getLastCellInRow(row)));
                } else {
                        if (cur.idx() == 0)
                                return;
-                       --cur.idx();
+                       cur.idx(cur.idx() - 1);
                }
        } else {
                lyxerr << "InsetTabular::moveNextCell B cur: " << endl;
                if (tabular.isLastCell(cur.idx()))
                        return;
-               ++cur.idx();
+               cur.idx(cur.idx() + 1);
        }
        cur.pit() = 0;
        cur.pos() = 0;
@@ -1289,17 +1289,17 @@ void InsetTabular::movePrevCell(LCursor 
                        row_type const row = tabular.row_of_cell(cur.idx());
                        if (row == 0)
                                return;
-                       cur.idx() = tabular.getFirstCellInRow(row);
-                       cur.idx() = tabular.getCellAbove(cur.idx());
+                       cur.idx(tabular.getFirstCellInRow(row));
+                       cur.idx(tabular.getCellAbove(cur.idx()));
                } else {
                        if (tabular.isLastCell(cur.idx()))
                                return;
-                       ++cur.idx();
+                       cur.idx(cur.idx() + 1);
                }
        } else {
                if (cur.idx() == 0) // first cell
                        return;
-               --cur.idx();
+               cur.idx(cur.idx() - 1);
        }
        cur.pit() = cur.lastpit();
        cur.pos() = cur.lastpos();
@@ -1453,7 +1453,7 @@ void InsetTabular::tabularFeatures(LCurs
                        tabular.deleteRow(sel_row_start);
                if (sel_row_start >= tabular.rows())
                        --sel_row_start;
-               cur.idx() = tabular.getCellNumber(sel_row_start, column);
+               cur.idx(tabular.getCellNumber(sel_row_start, column));
                cur.pit() = 0;
                cur.pos() = 0;
                cur.selection() = false;
@@ -1464,7 +1464,7 @@ void InsetTabular::tabularFeatures(LCurs
                        tabular.deleteColumn(sel_col_start);
                if (sel_col_start >= tabular.columns())
                        --sel_col_start;
-               cur.idx() = tabular.getCellNumber(row, sel_col_start);
+               cur.idx(tabular.getCellNumber(row, sel_col_start));
                cur.pit() = 0;
                cur.pos() = 0;
                cur.selection() = false;
@@ -1574,7 +1574,7 @@ void InsetTabular::tabularFeatures(LCurs
                idx_type const s_start = cur.selBegin().idx();
                idx_type const s_end = cur.selEnd().idx();
                tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 
1);
-               cur.idx() = s_start;
+               cur.idx(s_start);
                cur.pit() = 0;
                cur.pos() = 0;
                cur.selection() = false;
@@ -1817,6 +1817,12 @@ void InsetTabular::getSelection(LCursor 
        re = tabular.row_of_cell(end.idx());
        if (rs > re)
                swap(rs, re);
+}
+
+
+size_t InsetTabular::ncols() const
+{
+       return tabular.columns();
 }
 
 
Index: insets/insettabular.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v
retrieving revision 1.201
diff -u -p -r1.201 insettabular.h
--- insets/insettabular.h       26 Apr 2005 11:12:20 -0000      1.201
+++ insets/insettabular.h       2 Jul 2005 20:13:18 -0000
@@ -106,6 +106,8 @@ public:
        /// number of cells
        size_t nargs() const;
        ///
+       size_t ncols() const;
+
        boost::shared_ptr<InsetText const> cell(idx_type) const;
        ///
        boost::shared_ptr<InsetText> cell(idx_type);
Index: mathed/math_fracbase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracbase.C,v
retrieving revision 1.21
diff -u -p -r1.21 math_fracbase.C
--- mathed/math_fracbase.C      26 Jan 2004 10:13:13 -0000      1.21
+++ mathed/math_fracbase.C      2 Jul 2005 20:13:18 -0000
@@ -37,7 +37,7 @@ bool MathFracbaseInset::idxUpDown(LCurso
        MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has 
idx 0
        if (cur.idx() == target)
                return false;
-       cur.idx() = target;
+       cur.idx(target);
        cur.pos() = cell(target).x2pos(cur.x_target());
        return true;
 }
Index: mathed/math_gridinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.C,v
retrieving revision 1.163
diff -u -p -r1.163 math_gridinset.C
--- mathed/math_gridinset.C     30 Jun 2005 18:02:39 -0000      1.163
+++ mathed/math_gridinset.C     2 Jul 2005 20:13:18 -0000
@@ -778,11 +778,11 @@ bool MathGridInset::idxUpDown(LCursor & 
        if (up) {
                if (cur.idx() < ncols())
                        return false;
-               cur.idx() -= ncols();
+               cur.idx(cur.idx() - ncols());
        } else {
                if (cur.idx() >= ncols() * (nrows() - 1))
                        return false;
-               cur.idx() += ncols();
+               cur.idx(cur.idx() + ncols());
        }
        cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
        return true;
@@ -794,7 +794,7 @@ bool MathGridInset::idxLeft(LCursor & cu
        // leave matrix if on the left hand edge
        if (cur.col() == 0)
                return false;
-       --cur.idx();
+       cur.idx(cur.idx() - 1);
        cur.pos() = cur.lastpos();
        return true;
 }
@@ -805,7 +805,7 @@ bool MathGridInset::idxRight(LCursor & c
        // leave matrix if on the right hand edge
        if (cur.col() + 1 == ncols())
                return false;
-       ++cur.idx();
+       cur.idx(cur.idx() + 1);
        cur.pos() = 0;
        return true;
 }
@@ -815,13 +815,13 @@ bool MathGridInset::idxFirst(LCursor & c
 {
        switch (v_align_) {
                case 't':
-                       cur.idx() = 0;
+                       cur.idx(0);
                        break;
                case 'b':
-                       cur.idx() = (nrows() - 1) * ncols();
+                       cur.idx((nrows() - 1) * ncols());
                        break;
                default:
-                       cur.idx() = ((nrows() - 1) / 2) * ncols();
+                       cur.idx(((nrows() - 1) / 2) * ncols());
        }
        cur.pos() = 0;
        return true;
@@ -832,20 +832,20 @@ bool MathGridInset::idxLast(LCursor & cu
 {
        switch (v_align_) {
                case 't':
-                       cur.idx() = ncols() - 1;
+                       cur.idx(ncols() - 1);
                        break;
                case 'b':
-                       cur.idx() = nargs() - 1;
+                       cur.idx(nargs() - 1);
                        break;
                default:
-                       cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
+                       cur.idx(((nrows() - 1) / 2 + 1) * ncols() - 1);
        }
        cur.pos() = cur.lastpos();
        return true;
 }
 
 
-bool MathGridInset::idxDelete(idx_type & idx)
+bool MathGridInset::idxDelete(idx_type idx)
 {
        // nothing to do if we have just one row
        if (nrows() == 1)
@@ -1015,7 +1015,7 @@ void MathGridInset::splitCell(LCursor & 
        MathArray ar = cur.cell();
        ar.erase(0, cur.pos());
        cur.cell().erase(cur.pos(), cur.lastpos());
-       ++cur.idx();
+       cur.idx(cur.idx() + 1);
        cur.pos() = 0;
        cur.cell().insert(0, ar);
 }
@@ -1050,7 +1050,7 @@ void MathGridInset::doDispatch(LCursor &
                if (nrows() > 1)
                        delRow(cur.row());
                if (cur.idx() > cur.lastidx())
-                       cur.idx() = cur.lastidx();
+                       cur.idx(cur.lastidx());
                if (cur.pos() > cur.lastpos())
                        cur.pos() = cur.lastpos();
                break;
@@ -1073,7 +1073,7 @@ void MathGridInset::doDispatch(LCursor &
                splitCell(cur);
                swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
                if (cur.idx() > 0)
-                       --cur.idx();
+                       cur.idx(cur.idx() - 1);
                cur.pos() = cur.lastpos();
 
                //mathcursor->normalize();
@@ -1106,15 +1106,13 @@ void MathGridInset::doDispatch(LCursor &
                        for (int i = 0, n = extractInt(is); i < n; ++i) {
                                delRow(cur.row());
                                if (cur.idx() > nargs())
-                                       cur.idx() -= ncols();
+                                       cur.idx(cur.idx() - ncols());
                        }
                else if (s == "copy-row") {
                        // Here (as later) we save the cursor col/row 
                        // in order to restore it after operation. 
-                       cur.idxSave();
                        for (int i = 0, n = extractInt(is); i < n; ++i)
                                copyRow(cur.row());
-                       cur.idxLoad();
                        }
                else if (s == "swap-row") {
                        swapRow(cur.row());
@@ -1132,22 +1130,16 @@ void MathGridInset::doDispatch(LCursor &
                        rowinfo_[cur.row()+1].lines_--;
                else if (s == "append-column")
                        for (int i = 0, n = extractInt(is); i < n; ++i) {
-                               cur.idxSave();
                                addCol(cur.col());
-                               cur.idxLoad();
                        }
                else if (s == "delete-column")
                        for (int i = 0, n = extractInt(is); i < n; ++i) {
-                               cur.idxSave();
                                delCol(col(cur.idx()));
-                               cur.idxLoad();
                                if (cur.idx() > nargs())
-                                       cur.idx() -= ncols();
+                                       cur.idx(cur.idx() - ncols());
                        }
                else if (s == "copy-column") {
-                       cur.idxSave();
                        copyCol(cur.col());
-                       cur.idxLoad();
                        }
                else if (s == "swap-column") {
                        swapCol(cur.col());
@@ -1215,10 +1207,10 @@ void MathGridInset::doDispatch(LCursor &
                if (cur.pos() != 0) {
                        cur.pos() = 0;
                } else if (cur.idx() % cur.ncols() != 0) {
-                       cur.idx() -= cur.idx() % cur.ncols();
+                       cur.idx(cur.idx() - cur.idx() % cur.ncols());
                        cur.pos() = 0;
                } else if (cur.idx() != 0) {
-                       cur.idx() = 0;
+                       cur.idx(0);
                        cur.pos() = 0;
                } else {
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
@@ -1236,10 +1228,10 @@ void MathGridInset::doDispatch(LCursor &
                if (cur.pos() != cur.lastpos()) {
                        cur.pos() = cur.lastpos();
                } else if ((cur.idx() + 1) % cur.ncols() != 0) {
-                       cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
+                       cur.idx(cur.idx() + cur.ncols() - 1 - cur.idx() % 
cur.ncols());
                        cur.pos() = cur.lastpos();
                } else if (cur.idx() != cur.lastidx()) {
-                       cur.idx() = cur.lastidx();
+                       cur.idx(cur.lastidx());
                        cur.pos() = cur.lastpos();
                } else {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
Index: mathed/math_gridinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.h,v
retrieving revision 1.88
diff -u -p -r1.88 math_gridinset.h
--- mathed/math_gridinset.h     26 Apr 2005 11:12:20 -0000      1.88
+++ mathed/math_gridinset.h     2 Jul 2005 20:13:18 -0000
@@ -154,7 +154,7 @@ public:
        ///
        bool idxLast(LCursor &) const;
        ///
-       bool idxDelete(idx_type & idx);
+       bool idxDelete(idx_type idx);
        /// pulls cell after pressing erase
        void idxGlue(idx_type idx);
 
Index: mathed/math_hullinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v
retrieving revision 1.167
diff -u -p -r1.167 math_hullinset.C
--- mathed/math_hullinset.C     17 Jun 2005 14:35:19 -0000      1.167
+++ mathed/math_hullinset.C     2 Jul 2005 20:13:18 -0000
@@ -192,7 +192,7 @@ MathInset::mode_type MathHullInset::curr
 
 bool MathHullInset::idxFirst(LCursor & cur) const
 {
-       cur.idx() = 0;
+       cur.idx(0);
        cur.pos() = 0;
        return true;
 }
@@ -200,7 +200,7 @@ bool MathHullInset::idxFirst(LCursor & c
 
 bool MathHullInset::idxLast(LCursor & cur) const
 {
-       cur.idx() = nargs() - 1;
+       cur.idx(nargs() - 1);
        cur.pos() = cur.lastpos();
        return true;
 }
@@ -917,7 +917,7 @@ void MathHullInset::doExtern(LCursor & c
        eq.push_back(MathAtom(new MathCharInset('=')));
 
        // go to first item in line
-       cur.idx() -= cur.idx() % ncols();
+       cur.idx(cur.idx() - cur.idx() % ncols());
        cur.pos() = 0;
 
        if (getType() == "simple") {
@@ -943,9 +943,9 @@ void MathHullInset::doExtern(LCursor & c
                mutate("eqnarray");
                MathArray & ar = cur.cell();
                lyxerr << "use cell: " << ar << endl;
-               ++cur.idx();
+               cur.idx(cur.idx() + 1);
                cur.cell() = eq;
-               ++cur.idx();
+               cur.idx(cur.idx() + 1);
                cur.cell() = pipeThroughExtern(lang, extra, ar);
                // move to end of line
                cur.pos() = cur.lastpos();
@@ -954,7 +954,7 @@ void MathHullInset::doExtern(LCursor & c
 
        {
                lyxerr << "use eqnarray" << endl;
-               cur.idx() += 2 - cur.idx() % ncols();
+               cur.idx(cur.idx() + 2 - cur.idx() % ncols());
                cur.pos() = 0;
                MathArray ar = cur.cell();
                lyxerr << "use cell: " << ar << endl;
@@ -962,10 +962,9 @@ void MathHullInset::doExtern(LCursor & c
 #warning temporarily disabled
 #endif
                addRow(cur.row());
-               ++cur.idx();
-               ++cur.idx();
+               cur.idx(cur.idx() + 2);
                cur.cell() = eq;
-               ++cur.idx();
+               cur.idx(cur.idx() + 1);
                cur.cell() = pipeThroughExtern(lang, extra, ar);
                cur.pos() = cur.lastpos();
        }
@@ -993,7 +992,7 @@ void MathHullInset::doDispatch(LCursor &
                if (type_ == "simple" || type_ == "equation") {
                        recordUndoInset(cur);
                        mutate("eqnarray");
-                       cur.idx() = 0;
+                       cur.idx(0);
                        cur.pos() = cur.lastpos();
                }
                MathGridInset::doDispatch(cur, cmd);
@@ -1057,9 +1056,9 @@ void MathHullInset::doDispatch(LCursor &
                row_type row = cur.row();
                col_type col = cur.col();
                mutate(cmd.argument);
-               cur.idx() = row * ncols() + col;
+               cur.idx(row * ncols() + col);
                if (cur.idx() > cur.lastidx()) {
-                       cur.idx() = cur.lastidx();
+                       cur.idx(cur.lastidx());
                        cur.pos() = cur.lastpos();
                }
                if (cur.pos() > cur.lastpos())
@@ -1071,7 +1070,7 @@ void MathHullInset::doDispatch(LCursor &
        case LFUN_MATH_DISPLAY: {
                recordUndoInset(cur);
                mutate(type_ == "simple" ? "equation" : "simple");
-               cur.idx() = 0;
+               cur.idx(0);
                cur.pos() = cur.lastpos();
                //cur.dispatched(FINISHED);
                break;
Index: mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.156
diff -u -p -r1.156 math_nestinset.C
--- mathed/math_nestinset.C     17 Jun 2005 14:35:19 -0000      1.156
+++ mathed/math_nestinset.C     2 Jul 2005 20:13:18 -0000
@@ -143,7 +143,7 @@ bool MathNestInset::idxNext(LCursor & cu
        BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (cur.idx() == cur.lastidx())
                return false;
-       ++cur.idx();
+       cur.idx(cur.idx() + 1);
        cur.pos() = 0;
        return true;
 }
@@ -160,7 +160,7 @@ bool MathNestInset::idxPrev(LCursor & cu
        BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (cur.idx() == 0)
                return false;
-       --cur.idx();
+       cur.idx(cur.idx() - 1);
        cur.pos() = cur.lastpos();
        return true;
 }
@@ -177,7 +177,7 @@ bool MathNestInset::idxFirst(LCursor & c
        BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (nargs() == 0)
                return false;
-       cur.idx() = 0;
+       cur.idx(0);
        cur.pos() = 0;
        return true;
 }
@@ -188,7 +188,7 @@ bool MathNestInset::idxLast(LCursor & cu
        BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (nargs() == 0)
                return false;
-       cur.idx() = cur.lastidx();
+       cur.idx(cur.lastidx());
        cur.pos() = cur.lastpos();
        return true;
 }
@@ -526,11 +526,11 @@ void MathNestInset::doDispatch(LCursor &
        case LFUN_MOUSE_TRIPLE:
        case LFUN_WORDSEL:
                cur.pos() = 0;
-               cur.idx() = 0;
+               cur.idx(0);
                cur.resetAnchor();
                cur.selection() = true;
                cur.pos() = cur.lastpos();
-               cur.idx() = cur.lastidx();
+               cur.idx(cur.lastidx());
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
@@ -548,10 +548,10 @@ void MathNestInset::doDispatch(LCursor &
                if (cur.pos() != 0) {
                        cur.pos() = 0;
                } else if (cur.col() != 0) {
-                       cur.idx() -= cur.col();
+                       cur.idx(cur.idx() - cur.col());
                        cur.pos() = 0;
                } else if (cur.idx() != 0) {
-                       cur.idx() = 0;
+                       cur.idx(0);
                        cur.pos() = 0;
                } else {
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
@@ -569,10 +569,10 @@ void MathNestInset::doDispatch(LCursor &
                if (cur.pos() != cur.lastpos()) {
                        cur.pos() = cur.lastpos();
                } else if (ncols() && (cur.col() != cur.lastcol())) {
-                       cur.idx() = cur.idx() - cur.col() + cur.lastcol();
+                       cur.idx(cur.idx() - cur.col() + cur.lastcol());
                        cur.pos() = cur.lastpos();
                } else if (cur.idx() != cur.lastidx()) {
-                       cur.idx() = cur.lastidx();
+                       cur.idx(cur.lastidx());
                        cur.pos() = cur.lastpos();
                } else {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
@@ -951,7 +951,7 @@ bool MathNestInset::getStatus(LCursor & 
 void MathNestInset::edit(LCursor & cur, bool left)
 {
        cur.push(*this);
-       cur.idx() = left ? 0 : cur.lastidx();
+       cur.idx(left ? 0 : cur.lastidx());
        cur.pos() = left ? 0 : cur.lastpos();
        cur.resetAnchor();
        lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
@@ -971,7 +971,7 @@ InsetBase * MathNestInset::editXY(LCurso
        }
        MathArray const & ar = cell(idx_min);
        cur.push(const_cast<MathNestInset&>(*this));
-       cur.idx() = idx_min;
+       cur.idx(idx_min);
        cur.pos() = ar.x2pos(x - ar.xo());
        lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
        if (dist_min == 0) {
@@ -1207,13 +1207,13 @@ bool MathNestInset::script(LCursor & cur
                MathScriptInset * inset = asScriptInset();
                lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
                inset->ensure(up);
-               cur.idx() = inset->idxOfScript(up);
+               cur.idx(inset->idxOfScript(up));
                cur.pos() = 0;
        } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
                --cur.pos();
                MathScriptInset * inset = 
cur.nextAtom().nucleus()->asScriptInset();
                cur.push(*inset);
-               cur.idx() = inset->idxOfScript(up);
+               cur.idx(inset->idxOfScript(up));
                cur.pos() = cur.lastpos();
        } else {
                // convert the thing to our left to a scriptinset or create a 
new
@@ -1228,7 +1228,7 @@ bool MathNestInset::script(LCursor & cur
                --cur.pos();
                MathScriptInset * inset = 
cur.nextAtom().nucleus()->asScriptInset();
                cur.push(*inset);
-               cur.idx() = 1;
+               cur.idx(1);
                cur.pos() = 0;
        }
        lyxerr << "pasting 1: safe:\n" << safe << endl;
Index: mathed/math_oversetinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_oversetinset.C,v
retrieving revision 1.13
diff -u -p -r1.13 math_oversetinset.C
--- mathed/math_oversetinset.C  23 Nov 2004 23:04:52 -0000      1.13
+++ mathed/math_oversetinset.C  2 Jul 2005 20:13:18 -0000
@@ -53,7 +53,7 @@ void MathOversetInset::draw(PainterInfo 
 
 bool MathOversetInset::idxFirst(LCursor & cur) const
 {
-       cur.idx() = 1;
+       cur.idx(1);
        cur.pos() = 0;
        return true;
 }
@@ -61,7 +61,7 @@ bool MathOversetInset::idxFirst(LCursor 
 
 bool MathOversetInset::idxLast(LCursor & cur) const
 {
-       cur.idx() = 1;
+       cur.idx(1);
        cur.pos() = cur.lastpos();
        return true;
 }
Index: mathed/math_rootinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_rootinset.C,v
retrieving revision 1.47
diff -u -p -r1.47 math_rootinset.C
--- mathed/math_rootinset.C     14 Feb 2005 15:28:45 -0000      1.47
+++ mathed/math_rootinset.C     2 Jul 2005 20:13:18 -0000
@@ -85,7 +85,7 @@ bool MathRootInset::idxUpDown(LCursor & 
        LCursor::idx_type const target = up ? 0 : 1;
        if (cur.idx() == target)
                return false;
-       cur.idx() = target;
+       cur.idx(target);
        cur.pos() = up ? cur.lastpos() : 0;
        return true;
 }
Index: mathed/math_scriptinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.C,v
retrieving revision 1.120
diff -u -p -r1.120 math_scriptinset.C
--- mathed/math_scriptinset.C   24 Nov 2004 21:58:41 -0000      1.120
+++ mathed/math_scriptinset.C   2 Jul 2005 20:13:18 -0000
@@ -67,7 +67,7 @@ MathScriptInset * MathScriptInset::asScr
 
 bool MathScriptInset::idxFirst(LCursor & cur) const
 {
-       cur.idx() = 0;
+       cur.idx(0);
        cur.pos() = 0;
        return true;
 }
@@ -75,7 +75,7 @@ bool MathScriptInset::idxFirst(LCursor &
 
 bool MathScriptInset::idxLast(LCursor & cur) const
 {
-       cur.idx() = 0;
+       cur.idx(0);
        cur.pos() = nuc().size();
        return true;
 }
@@ -381,7 +381,7 @@ bool MathScriptInset::idxUpDown(LCursor 
                // go up/down only if in the last position
                // or in the first position of something with displayed limits
                if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && 
hasLimits())) {
-                       cur.idx() = idxOfScript(up);
+                       cur.idx(idxOfScript(up));
                        cur.pos() = 0;
                        return true;
                }
@@ -394,7 +394,7 @@ bool MathScriptInset::idxUpDown(LCursor 
                if (up)
                        return false;
                // otherwise go to last position in the nucleus
-               cur.idx() = 0;
+               cur.idx(0);
                cur.pos() = cur.lastpos();
                return true;
        }
@@ -405,7 +405,7 @@ bool MathScriptInset::idxUpDown(LCursor 
                if (!up)
                        return false;
                // otherwise go to last position in the nucleus
-               cur.idx() = 0;
+               cur.idx(0);
                cur.pos() = cur.lastpos();
                return true;
        }
Index: mathed/math_undersetinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_undersetinset.C,v
retrieving revision 1.26
diff -u -p -r1.26 math_undersetinset.C
--- mathed/math_undersetinset.C 23 Nov 2004 23:04:52 -0000      1.26
+++ mathed/math_undersetinset.C 2 Jul 2005 20:13:18 -0000
@@ -54,7 +54,7 @@ void MathUndersetInset::draw(PainterInfo
 
 bool MathUndersetInset::idxFirst(LCursor & cur) const
 {
-       cur.idx() = 1;
+       cur.idx(1);
        cur.pos() = 0;
        return true;
 }
@@ -62,7 +62,7 @@ bool MathUndersetInset::idxFirst(LCursor
 
 bool MathUndersetInset::idxLast(LCursor & cur) const
 {
-       cur.idx() = 1;
+       cur.idx(1);
        cur.pos() = cur.lastpos();
        return true;
 }
@@ -73,7 +73,7 @@ bool MathUndersetInset::idxUpDown(LCurso
        idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
        if (cur.idx() == target)
                return false;
-       cur.idx() = target;
+       cur.idx(target);
        cur.pos() = cur.cell().x2pos(cur.x_target());
        return true;
 }

Attachment: pgp3HqVz4r6ZZ.pgp
Description: PGP signature

Reply via email to