]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
small mouse click stuff. still not ok...
[lyx.git] / src / mathed / math_cursor.h
index 0d3381edb979adcde731766a6d0bbc18a084fe4f..3aa02de9566447b9f43027439356b67e1aa575de 100644 (file)
 #endif
 
 #include "math_defs.h"
+#include "math_inset.h"
+#include "LString.h"
 
-class MathInset;
-class MathArrayInset;
-class MathFuncInset;
-class MathMatrixInset;
-class MathScriptInset;
-class MathSpaceInset;
 class InsetFormulaBase;
-class MathArray;
-class MathXArray;
 class Painter;
+class Selection;
 
 /// Description of a position 
 struct MathCursorPos {
        /// inset
-       MathInset * par_;
+       MathAtom * par_;
        /// cell index
-       int idx_;
+       MathInset::idx_type idx_;
        /// cell position
-       int pos_;
+       MathInset::pos_type pos_;
+
        /// returns cell corresponding to this position
        MathArray & cell() const;
        /// returns cell corresponding to this position
-       MathArray & cell(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(int idx) const;
-       /// moves position on cell to the left
-       bool idxLeft();
-       /// moves position on cell to the right
-       bool idxRight();
-       /// moves position on cell up
-       bool idxUp();
-       /// moves position on cell up
-       bool idxDown();
+       MathXArray & xcell(MathInset::idx_type idx) const;
 };
 
 /// 
@@ -69,22 +57,33 @@ 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 *);
-       ///
-       ~MathCursor();
-       ///
-       void insert(char, MathTextCodes t = LM_TC_MIN);
+       explicit MathCursor(InsetFormulaBase *, bool left);
        ///
-       void insert(MathInset *);
+       void insert(MathAtom const &);
        ///
        void insert(MathArray const &);
        ///
+       void paste(MathArray const &);
+       ///
        void erase();
        ///
-       void home();
+       void backspace();
+       ///
+       void home(bool sel = false);
        ///
-       void end();
+       void end(bool sel = false);
        ///
        bool right(bool sel = false);
        ///
@@ -98,37 +97,44 @@ public:
        /// Put the cursor in the last position
        void last();
        ///
-       void plainLeft();
+       void idxNext();
        ///
-       void plainRight();
+       void idxPrev();
        ///
        void plainErase();
        ///
-       void plainInsert(MathInset * p);
+       void plainInsert(MathAtom const &);
+       ///
+       void niceInsert(MathAtom const &);
+
        ///
        void delLine();
        /// This is in pixels from (maybe?) the top of inset
-       void setPos(int, int);
+       // don't move further in than the Anchor's inset if respect_anchor == true
+       void setPos(int x, int y, bool respect_anchor = false);
+       /// This is in pixels from (maybe?) the top of inset, don't move further
        ///
        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(int &) const;
+       MathGridInset * enclosingGrid(idx_type &) const;
        ///
        InsetFormulaBase const * formula();
        ///
-       int pos() const;
+       pos_type pos() const;
        ///
-       void interpret(string const &);
+       idx_type idx() const;
        ///
-       void setSize(MathStyles);
+       size_type size() const;
+       ///
+       bool interpret(string const &);
+       ///
+       bool interpret(char);
        ///
        bool toggleLimits();
        ///
        // Macro mode methods
-       void macroModeOpen();
-       ///
        void macroModeClose();
        ///
        bool inMacroMode() const;
@@ -151,82 +157,77 @@ public:
        ///
        void selClear();
        ///
-       void drawSelection(Painter & pain) const;
-       ///
-       void clearLastCode();
+       void selGet(MathArray & ar);
        ///
-       void setLastCode(MathTextCodes t);
+       void drawSelection(Painter & pain) const;
        ///
        void handleFont(MathTextCodes t);
        ///
-       void handleAccent(string const & name);
+       void handleDelim(string const & l, string const & r);
        ///
-       void handleDelim(int l, int r);
+       void handleNest(MathInset * p);
        /// Splits cells and shifts right part to the next cell
        void splitCell();
        /// Splits line and insert new row of cell 
        void breakLine();
+       /// read contents of line into an array
+       void readLine(MathArray & ar) const;
        ///
        MathTextCodes getLastCode() const;
        ///
-       int idx() const { return cursor().idx_; }
-       ///
-       void idxNext();
-       ///
-       void idxPrev();
-       ///
        void pullArg(bool goright);
        ///
        bool isInside(MathInset const *) const;
        ///
        MathTextCodes nextCode() const;
        ///
-       MathTextCodes prevCode() const;
-       ///
        char valign() const;
        ///
        char halign() const;
        ///
-       int col() const;
+       col_type ncols() const;
        ///
-       int row() const;
-
+       col_type col() const;
        ///
-       MathStyles style() const;
+       row_type row() const;
+
        /// Make sure cursor position is valid
        void normalize() const;
-       
-       /// Enter a new MathInset from the front or the back
-       void push(MathInset * par, bool first);
-       /// Leave current MathInset
-       bool pop();
-
-//private:
        ///
-       InsetFormulaBase * const formula_;
-       ///
-       MathTextCodes lastcode_;
-       ///
-       MathFuncInset * imacro_;
-       // Selection stuff
-       /// do we currently select
-       bool selection_;
+       UpdatableInset * asHyperActiveInset() const;
+
+       /// enter a MathInset 
+       void push(MathAtom & par);
+       /// enter a MathInset from the front
+       void pushLeft(MathAtom & par);
+       /// enter a MathInset from the back
+       void pushRight(MathAtom & par);
+       /// leave current MathInset to the left
+       bool popLeft();
+       /// leave current MathInset to the left
+       bool popRight();
 
        ///
        MathArray & array() const;
        ///
        MathXArray & xarray() const;
+       ///
+       bool hasPrevAtom() const;
+       ///
+       bool hasNextAtom() const;
+       ///
+       MathAtom const & prevAtom() const;
+       ///
+       MathAtom & prevAtom();
+       ///
+       MathAtom const & nextAtom() const;
+       ///
+       MathAtom & nextAtom();
 
-       /// returns the first position of the (normalized) selection
-       MathCursorPos firstSelectionPos() const;
-       /// returns the last position of the (normalized) selection
-       MathCursorPos lastSelectionPos() const;
        /// returns the selection
        void getSelection(MathCursorPos &, MathCursorPos &) const;
        /// returns the normalized anchor of the selection
        MathCursorPos normalAnchor() const;
-       /// returns the normalized anchor of the selection
-       bool openable(MathInset *, bool selection, bool useupdown) const;
 
        /// path of positions the cursor had to go if it were leving each inset
        std::vector<MathCursorPos> Cursor_;
@@ -238,33 +239,52 @@ public:
        ///
        MathCursorPos const & cursor() const;
 
-
-       ///  
-       int last() const;
-       ///
-       MathInset * parInset(int i) const;
-       ///
-       MathMatrixInset * outerPar() const;
        ///
        void seldump(char const * str) const;
        ///
        void dump(char const * str) const;
-
        ///
-       int xpos() const;
+       void stripFromLastEqualSign();
+
        ///
-       void gotoX(int x);
+       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();
 
        ///
-       void merge(MathArray const & arr);
+       string macroName() const;
        ///
-       MathInset * nextInset() const;
+       int macroNamePos() const;
        ///
-       MathInset * prevInset() const;
+       void insert(char, MathTextCodes t);
+       /// can we enter the inset? 
+       bool openable(MathAtom const &, bool selection) const;
+       /// can the setPos routine enter that inset?
+       bool positionable(MathAtom const &, int x, int y) const;
+       /// write access to cursor cell position
+       pos_type & pos();
+       /// write access to cursor cell index
+       idx_type & idx();
+
        ///
-       MathScriptInset * prevScriptInset() const;
+       InsetFormulaBase * const formula_;
        ///
-       MathSpaceInset * prevSpaceInset() const;
+       MathTextCodes lastcode_;
+       // Selection stuff
+       /// do we currently select
+       bool selection_;
 };
 
 extern MathCursor * mathcursor;