]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
use stream-like syntax for LaTeX output
[lyx.git] / src / mathed / math_cursor.h
index 978da16e401f66b4d4c0e481632dcf460d4e5b09..ce9c89cc970261000833ac97303cb28cebd89e36 100644 (file)
@@ -22,6 +22,8 @@
 #endif
 
 #include "math_defs.h"
+#include "math_inset.h"
+#include "LString.h"
 
 class MathInset;
 class MathAtom;
@@ -34,24 +36,26 @@ class InsetFormulaBase;
 class MathArray;
 class MathXArray;
 class Painter;
+class Selection;
 class latexkeys;
 
 /// Description of a position 
 struct MathCursorPos {
        /// inset
-       MathInset * par_;
+       MathAtom * par_;
        /// cell index
-       unsigned int idx_;
+       MathInset::idx_type idx_;
        /// cell position
-       unsigned int pos_;
+       MathInset::pos_type pos_;
+
        /// returns cell corresponding to this position
        MathArray & cell() const;
        /// returns cell corresponding to this position
-       MathArray & cell(unsigned int idx) const;
+       MathArray & cell(MathInset::idx_type idx) const;
        /// returns xcell corresponding to this position
        MathXArray & xcell() const;
        /// returns xcell corresponding to this position
-       MathXArray & xcell(unsigned int idx) const;
+       MathXArray & xcell(MathInset::idx_type idx) const;
 };
 
 /// 
@@ -63,13 +67,26 @@ bool operator<(MathCursorPos const &, MathCursorPos const &);
 /// This is the external interface of Math's subkernel
 class MathCursor {
 public:
+       /// short of anything else reasonable
+       typedef MathInset::size_type    size_type;
+       /// type for cursor positions within a cell
+       typedef MathInset::pos_type     pos_type;
+       /// type for cell indices
+       typedef MathInset::idx_type     idx_type;
+       /// type for row numbers
+       typedef MathInset::row_type     row_type;
+       /// type for column numbers
+       typedef MathInset::col_type     col_type;
+
        ///
-       explicit MathCursor(InsetFormulaBase *);
+       explicit MathCursor(InsetFormulaBase *, bool left);
        ///
-       void insert(MathInset *);
+       void insert(MathAtom const &);
        ///
        void insert(MathArray const &);
        ///
+       void paste(MathArray const &);
+       ///
        void erase();
        ///
        void backspace();
@@ -89,18 +106,6 @@ public:
        void first();
        /// Put the cursor in the last position
        void last();
-       /// moves cursor position one cell to the left
-       bool posLeft();
-       /// moves cursor position one cell to the right
-       bool posRight();
-       /// moves cursor index one cell to the left
-       bool idxLeft();
-       /// moves cursor index one cell to the right
-       bool idxRight();
-       /// moves position somehow up
-       bool goUp();
-       /// moves position somehow down
-       bool goDown();
        ///
        void idxNext();
        ///
@@ -108,9 +113,10 @@ public:
        ///
        void plainErase();
        ///
-       void plainInsert(MathInset * p);
+       void plainInsert(MathAtom const &);
        ///
-       void niceInsert(MathInset * p);
+       void niceInsert(MathAtom const &);
+
        ///
        void delLine();
        /// This is in pixels from (maybe?) the top of inset
@@ -118,20 +124,22 @@ public:
        ///
        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
-       MathArrayInset * enclosingArray(unsigned int &) const;
+       MathArrayInset * enclosingArray(idx_type &) const;
        ///
        InsetFormulaBase const * formula();
        ///
-       unsigned int pos() const;
+       pos_type pos() const;
        ///
-       unsigned int idx() const;
+       idx_type idx() const;
        ///
-       unsigned int size() const;
+       size_type size() const;
        ///
        void interpret(string const &);
        ///
+       void interpret(char);
+       ///
        void setSize(MathStyles);
        ///
        bool toggleLimits();
@@ -183,19 +191,21 @@ public:
        ///
        char halign() const;
        ///
-       unsigned int col() const;
+       col_type col() const;
        ///
-       unsigned int row() const;
+       row_type row() const;
 
        ///
        MathStyles style() const;
        /// Make sure cursor position is valid
        void normalize() const;
-       
+
+       /// enter a MathInset 
+       void push(MathAtom & par);
        /// enter a MathInset from the front
-       void pushLeft(MathInset * par);
+       void pushLeft(MathAtom & par);
        /// enter a MathInset from the back
-       void pushRight(MathInset * par);
+       void pushRight(MathAtom & par);
        /// leave current MathInset to the left
        bool popLeft();
        /// leave current MathInset to the left
@@ -206,13 +216,17 @@ public:
        ///
        MathXArray & xarray() const;
        ///
-       MathAtom const * prevAtom() const;
+       bool hasPrevAtom() const;
+       ///
+       bool hasNextAtom() const;
        ///
-       MathAtom * prevAtom();
+       MathAtom const & prevAtom() const;
        ///
-       MathAtom const * nextAtom() const;
+       MathAtom & prevAtom();
        ///
-       MathAtom * nextAtom();
+       MathAtom const & nextAtom() const;
+       ///
+       MathAtom & nextAtom();
 
        /// returns the selection
        void getSelection(MathCursorPos &, MathCursorPos &) const;
@@ -229,45 +243,46 @@ public:
        ///
        MathCursorPos const & cursor() const;
 
-
-       ///  
-       unsigned int last() const;
-       ///
-       MathInset * parInset(int i) const;
-       ///
-       MathMatrixInset * outerPar() const;
        ///
        void seldump(char const * str) const;
        ///
        void dump(char const * str) const;
 
        ///
-       void merge(MathArray const & arr);
-       ///
-       MathInset * nextInset() const;
-       ///
-       MathInset * prevInset() const;
-       ///
-       MathScriptInset * prevScriptInset() const;
-       ///
-       MathSpaceInset * prevSpaceInset() const;
+       friend class Selection;
+
 private:
+       /// moves cursor position one cell to the left
+       bool posLeft();
+       /// moves cursor position one cell to the right
+       bool posRight();
+       /// moves cursor index one cell to the left
+       bool idxLeft();
+       /// moves cursor index one cell to the right
+       bool idxRight();
+       /// moves position somehow up
+       bool goUp();
+       /// moves position somehow down
+       bool goDown();
+
        ///
        string macroName() const;
        ///
-       void insert(char, MathTextCodes t = LM_TC_MIN);
+       int macroNamePos() const;
+       ///
+       void insert(char, MathTextCodes t);
        /// can we enter the inset? 
-       bool openable(MathInset *, bool selection) const;
+       bool openable(MathAtom const &, bool selection) const;
        /// can the setPos routine enter that inset?
-       MathInset * positionable(MathAtom *, int x, int y) const;
+       bool positionable(MathAtom const &, int x, int y) const;
        /// write access to cursor cell position
-       unsigned int & pos();
+       pos_type & pos();
        /// write access to cursor cell index
-       unsigned int & idx();
+       idx_type & idx();
        /// x-offset of current cell relative to par xo
-       unsigned int cellXOffset() const;
+       int cellXOffset() const;
        /// y-offset of current cell relative to par yo
-       unsigned int cellYOffset() const;
+       int cellYOffset() const;
        /// current x position relative to par xo
        int xpos() const;
        /// current y position relative to par yo