-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.36
diff -u -p -r1.36 cursor.C
--- cursor.C    16 Jan 2004 12:36:22 -0000      1.36
+++ cursor.C    16 Jan 2004 13:09:05 -0000
@@ -26,6 +26,8 @@
 #include "insets/insettabular.h"
 #include "insets/insettext.h"
 
+#include "mathed/math_data.h"
+
 #include <boost/assert.hpp>
 
 using std::vector;
@@ -227,3 +229,32 @@ BufferView & LCursor::bv() const
 {
        return *bv_;
 }
+
+
+MathAtom const & LCursor::prevAtom() const
+{
+       BOOST_ASSERT(pos() > 0);
+       return cell()[pos() - 1];
+}
+
+
+MathAtom & LCursor::prevAtom()
+{
+       BOOST_ASSERT(pos() > 0);
+       return cell()[pos() - 1];
+}
+
+
+MathAtom const & LCursor::nextAtom() const
+{
+       BOOST_ASSERT(pos() < lastpos());
+       return cell()[pos()];
+}
+
+
+MathAtom & LCursor::nextAtom()
+{
+       BOOST_ASSERT(pos() < lastpos());
+       return cell()[pos()];
+}
+
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.20
diff -u -p -r1.20 cursor.h
--- cursor.h    16 Jan 2004 12:36:22 -0000      1.20
+++ cursor.h    16 Jan 2004 13:09:05 -0000
@@ -19,6 +19,7 @@
 
 class BufferView;
 class UpdatableInset;
+class MathAtom;
 class DispatchResult;
 class FuncRequest;
 class LyXText;
@@ -68,10 +69,6 @@ public:
        idx_type idx() const { return top().idx(); }
        /// return the text-ed cell this cursor is in
        idx_type & idx() { return top().idx(); }
-       /// return the mathed cell this cursor is in
-       MathArray const & cell() const { return top().cell(); }
-       /// return the mathed cell this cursor is in
-       MathArray & cell() { return top().cell(); }
        /// return the paragraph this cursor is in
        par_type par() const { return top().par(); }
        /// return the paragraph this cursor is in
@@ -93,6 +90,24 @@ public:
        /// return the grid row of the current cell
        col_type col() const { return top().col(); }
 
+       //
+       // math-specific part
+       //
+       /// return the mathed cell this cursor is in
+       MathArray const & cell() const { return top().cell(); }
+       /// return the mathed cell this cursor is in
+       MathArray & cell() { return top().cell(); }
+       /// the mathatom left of the cursor
+       MathAtom const & prevAtom() const;
+       /// the mathatom left of the cursor
+       MathAtom & prevAtom();
+       /// the mathatom right of the cursor
+       MathAtom const & nextAtom() const;
+       /// the mathatom right of the cursor
+       MathAtom & nextAtom();
+
+       //
+       // text-specific part
        ///
        UpdatableInset * innerInset() const;
        ///
@@ -105,6 +120,7 @@ public:
        void getPos(int & x, int & y) const;
        /// returns cursor dimension
        void getDim(int & asc, int & desc) const;
+
        /// cache the absolute coordinate from the top inset
        void updatePos();
        /// sets anchor to cursor position
Index: mathed/math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.380
diff -u -p -r1.380 math_cursor.C
--- mathed/math_cursor.C        16 Jan 2004 12:36:23 -0000      1.380
+++ mathed/math_cursor.C        16 Jan 2004 13:09:06 -0000
@@ -211,8 +211,8 @@ bool MathCursor::left(LCursor & cur, boo
        }
        selHandle(cur, sel);
 
-       if (hasPrevAtom(cur) && openable(prevAtom(cur), sel)) {
-               pushRight(cur, prevAtom(cur));
+       if (cur.pos() != 0 && openable(cur.prevAtom(), sel)) {
+               pushRight(cur, cur.prevAtom());
                return true;
        }
 
@@ -231,8 +231,8 @@ bool MathCursor::right(LCursor & cur, bo
        }
        selHandle(cur, sel);
 
-       if (hasNextAtom(cur) && openable(nextAtom(cur), sel)) {
-               pushLeft(cur, nextAtom(cur));
+       if (cur.pos() != cur.lastpos() && openable(cur.nextAtom(), sel)) {
+               pushLeft(cur, cur.nextAtom());
                return true;
        }
 
@@ -401,7 +401,7 @@ void MathCursor::niceInsert(LCursor & cu
        // enter the new inset and move the contents of the selection if possible
        if (t->isActive()) {
                posLeft(cur);
-               pushLeft(cur, nextAtom(cur));
+               pushLeft(cur, cur.nextAtom());
                paste(cur, safe);
        }
 }
@@ -449,7 +449,7 @@ bool MathCursor::backspace(LCursor & cur
                }
        }
 
-       if (hasPrevAtom(cur) && prevAtom(cur)->nargs() > 0) {
+       if (cur.pos() != 0 && cur.prevAtom()->nargs() > 0) {
                // let's require two backspaces for 'big stuff' and
                // highlight on the first
                left(cur, true);
@@ -490,7 +490,7 @@ bool MathCursor::erase(LCursor & cur)
                return true;
        }
 
-       if (hasNextAtom(cur) && nextAtom(cur)->nargs() > 0)
+       if (cur.pos() != cur.lastpos() && cur.nextAtom()->nargs() > 0)
                right(cur, true);
        else
                plainErase(cur);
@@ -656,7 +656,7 @@ void MathCursor::handleNest(LCursor & cu
        MathAtom at = a;
        asArray(grabAndEraseSelection(cur), at.nucleus()->cell(c));
        insert(cur, at);
-       pushRight(cur, prevAtom(cur));
+       pushRight(cur, cur.prevAtom());
 }
 
 
@@ -700,28 +700,28 @@ void MathCursor::adjust(LCursor & cur, p
 
 bool MathCursor::inMacroMode(LCursor & cur) const
 {
-       if (!hasPrevAtom(cur))
+       if (!cur.pos() != 0)
                return false;
-       MathUnknownInset const * p = prevAtom(cur)->asUnknownInset();
+       MathUnknownInset const * p = cur.prevAtom()->asUnknownInset();
        return p && !p->final();
 }
 
 
 MathUnknownInset * MathCursor::activeMacro(LCursor & cur)
 {
-       return inMacroMode(cur) ? prevAtom(cur).nucleus()->asUnknownInset() : 0;
+       return inMacroMode(cur) ? cur.prevAtom().nucleus()->asUnknownInset() : 0;
 }
 
 
 MathUnknownInset const * MathCursor::activeMacro(LCursor & cur) const
 {
-       return inMacroMode(cur) ? prevAtom(cur)->asUnknownInset() : 0;
+       return inMacroMode(cur) ? cur.prevAtom()->asUnknownInset() : 0;
 }
 
 
 bool MathCursor::inMacroArgMode(LCursor & cur) const
 {
-       return cur.pos() > 0 && prevAtom(cur)->getChar() == '#';
+       return cur.pos() > 0 && cur.prevAtom()->getChar() == '#';
 }
 
 
@@ -818,46 +818,6 @@ void MathCursor::normalize(LCursor & cur
 }
 
 
-bool MathCursor::hasPrevAtom(LCursor & cur) const
-{
-       return cur.pos() > 0;
-}
-
-
-bool MathCursor::hasNextAtom(LCursor & cur) const
-{
-       return cur.pos() < cur.lastpos();
-}
-
-
-MathAtom const & MathCursor::prevAtom(LCursor & cur) const
-{
-       BOOST_ASSERT(cur.pos() > 0);
-       return cur.cell()[cur.pos() - 1];
-}
-
-
-MathAtom & MathCursor::prevAtom(LCursor & cur)
-{
-       BOOST_ASSERT(cur.pos() > 0);
-       return cur.cell()[cur.pos() - 1];
-}
-
-
-MathAtom const & MathCursor::nextAtom(LCursor & cur) const
-{
-       BOOST_ASSERT(cur.pos() < cur.lastpos());
-       return cur.cell()[cur.pos()];
-}
-
-
-MathAtom & MathCursor::nextAtom(LCursor & cur)
-{
-       BOOST_ASSERT(cur.pos() < cur.lastpos());
-       return cur.cell()[cur.pos()];
-}
-
-
 void MathCursor::idxNext(LCursor & cur)
 {
        cur.inset()->asMathInset()->idxNext(cur);
@@ -918,11 +878,11 @@ bool MathCursor::goUpDown(LCursor & cur,
        // try neigbouring script insets
        if (!selection()) {
                // try left
-               if (hasPrevAtom(cur)) {
-                       MathScriptInset const * p = prevAtom(cur)->asScriptInset();
+               if (cur.pos() != 0) {
+                       MathScriptInset const * p = cur.prevAtom()->asScriptInset();
                        if (p && p->has(up)) {
                                --cur.pos();
-                               push(cur, nextAtom(cur));
+                               push(cur, cur.nextAtom());
                                cur.idx() = up; // the superscript has index 1
                                cur.pos() = cur.lastpos();
                                //lyxerr << "updown: handled by scriptinset to the 
left" << endl;
@@ -931,10 +891,10 @@ bool MathCursor::goUpDown(LCursor & cur,
                }
 
                // try right
-               if (hasNextAtom(cur)) {
-                       MathScriptInset const * p = nextAtom(cur)->asScriptInset();
+               if (cur.pos() != cur.lastpos()) {
+                       MathScriptInset const * p = cur.nextAtom()->asScriptInset();
                        if (p && p->has(up)) {
-                               push(cur, nextAtom(cur));
+                               push(cur, cur.nextAtom());
                                cur.idx() = up;
                                cur.pos() = 0;
                                //lyxerr << "updown: handled by scriptinset to the 
right" << endl;
@@ -1090,22 +1050,22 @@ bool MathCursor::script(LCursor & cur, b
                cur.inset()->asMathInset()->asScriptInset()->ensure(up);
                cur.idx() = up;
                cur.pos() = 0;
-       } else if (hasPrevAtom(cur) && prevAtom(cur)->asScriptInset()) {
-               prevAtom(cur).nucleus()->asScriptInset()->ensure(up);
-               pushRight(cur, prevAtom(cur));
+       } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
+               cur.prevAtom().nucleus()->asScriptInset()->ensure(up);
+               pushRight(cur, cur.prevAtom());
                cur.idx() = up;
                cur.pos() = cur.lastpos();
-       } else if (hasPrevAtom(cur)) {
+       } else if (cur.pos() != 0) {
                --cur.pos();
                cur.cell()[cur.pos()]
-                       = MathAtom(new MathScriptInset(nextAtom(cur), up));
-               pushLeft(cur, nextAtom(cur));
+                       = MathAtom(new MathScriptInset(cur.nextAtom(), up));
+               pushLeft(cur, cur.nextAtom());
                cur.idx() = up;
                cur.pos() = 0;
        } else {
                plainInsert(cur, MathAtom(new MathScriptInset(up)));
-               prevAtom(cur).nucleus()->asScriptInset()->ensure(up);
-               pushRight(cur, prevAtom(cur));
+               cur.prevAtom().nucleus()->asScriptInset()->ensure(up);
+               pushRight(cur, cur.prevAtom());
                cur.idx() = up;
                cur.pos() = 0;
        }
@@ -1206,12 +1166,12 @@ bool MathCursor::interpret(LCursor & cur
                        // but suppress direct insertion of two spaces in a row
                        // the still allows typing  '<space>a<space>' and deleting the 
'a', but
                        // it is better than nothing...
-                       if (!hasPrevAtom(cur) || prevAtom(cur)->getChar() != ' ')
+                       if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
                                insert(cur, c);
                        return true;
                }
-               if (hasPrevAtom(cur) && prevAtom(cur)->asSpaceInset()) {
-                       prevAtom(cur).nucleus()->asSpaceInset()->incSpace();
+               if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
+                       cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
                        return true;
                }
                if (popRight(cur))
@@ -1263,12 +1223,12 @@ void MathCursor::setSelection
 
 void MathCursor::insetToggle(LCursor & cur)
 {
-       if (hasNextAtom(cur)) {
+       if (cur.pos() != cur.lastpos()) {
                // toggle previous inset ...
-               nextAtom(cur).nucleus()->lock(!nextAtom(cur)->lock());
-       } else if (popLeft(cur) && hasNextAtom(cur)) {
+               cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
+       } else if (popLeft(cur) && cur.pos() != cur.lastpos()) {
                // ... or enclosing inset if we are in the last inset position
-               nextAtom(cur).nucleus()->lock(!nextAtom(cur)->lock());
+               cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
                posRight(cur);
        }
 }
@@ -1282,8 +1242,8 @@ string MathCursor::info(LCursor & cur) c
                cur.cursor_[i].asMathInset()->infoize(os);
                os << "  ";
        }
-       if (hasPrevAtom(cur))
-               prevAtom(cur)->infoize2(os);
+       if (cur.pos() != 0)
+               cur.prevAtom()->infoize2(os);
        os << "                    ";
        return os.str();
 }
Index: mathed/math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.160
diff -u -p -r1.160 math_cursor.h
--- mathed/math_cursor.h        16 Jan 2004 12:36:23 -0000      1.160
+++ mathed/math_cursor.h        16 Jan 2004 13:09:06 -0000
@@ -181,26 +181,11 @@ public:
        /// leave current MathInset to the left
        bool popRight(LCursor & cur);
 
-       ///
-       bool hasPrevAtom(LCursor & cur) const;
-       ///
-       bool hasNextAtom(LCursor & cur) const;
-       ///
-       MathAtom const & prevAtom(LCursor & cur) const;
-       ///
-       MathAtom & prevAtom(LCursor & cur);
-       ///
-       MathAtom const & nextAtom(LCursor & cur) const;
-       ///
-       MathAtom & nextAtom(LCursor & cur);
-
        /// returns the selection
        void getSelection(LCursor & cur, CursorSlice &, CursorSlice &) const;
        /// returns the normalized anchor of the selection
        CursorSlice normalAnchor(LCursor & cur) const;
 
-       /// how deep are we nested?
-       unsigned depth(LCursor & cur) const;
        /// describe the situation
        std::string info(LCursor & cur) const;
        /// dump selection information for debugging

Reply via email to