]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
re-enable spaces and hyphens in labels;
[lyx.git] / src / mathed / math_cursor.h
index da2a4ecf769ae7d709e3fb4fdc7770d60d87e52f..90519bec17aa0cd1327c11cf083eac80e7adf45b 100644 (file)
 #include "math_defs.h"
 
 class MathInset;
+class MathArrayInset;
 class MathFuncInset;
-class MathUpDownInset;
+class MathMatrixInset;
+class MathScriptInset;
+class MathSpaceInset;
 class InsetFormulaBase;
 class MathArray;
 class MathXArray;
+class Painter;
+class latexkeys;
+
+/// Description of a position 
+struct MathCursorPos {
+       /// inset
+       MathInset * par_;
+       /// cell index
+       int idx_;
+       /// cell position
+       int pos_;
+       /// returns cell corresponding to this position
+       MathArray & cell() const;
+       /// returns cell corresponding to this position
+       MathArray & cell(int idx) const;
+       /// returns xcell corresponding to this position
+       MathXArray & xcell() const;
+       /// returns xcell corresponding to this position
+       MathXArray & xcell(int idx) const;
+};
+
+/// 
+bool operator==(MathCursorPos const &, MathCursorPos const &);
+/// 
+bool operator<(MathCursorPos const &, MathCursorPos const &);
+
 
 /// This is the external interface of Math's subkernel
 class MathCursor {
@@ -36,89 +65,106 @@ public:
        ///
        explicit MathCursor(InsetFormulaBase *);
        ///
-       void insert(char, MathTextCodes t = LM_TC_MIN);
-       ///
        void insert(MathInset *);
        ///
-       void Home();
+       void insert(MathArray const &);
+       ///
+       void erase();
+       ///
+       void backspace();
        ///
-       void End();
+       void home();
        ///
-       bool Right(bool sel = false);
+       void end();
        ///
-       bool Left(bool sel = false);
+       bool right(bool sel = false);
        ///
-       bool Up(bool sel = false);
+       bool left(bool sel = false);
        ///
-       bool Down(bool sel = false);
+       bool up(bool sel = false);
+       ///
+       bool down(bool sel = false);
        /// Put the cursor in the first position
        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();
        ///
-       bool plainLeft();
+       void idxPrev();
        ///
-       bool plainRight();
+       void plainErase();
        ///
-       void Delete();
+       void plainInsert(MathInset * p);
        ///
-       void DelLine();
+       void niceInsert(MathInset * p);
+       ///
+       void delLine();
        /// This is in pixels from (maybe?) the top of inset
-       void SetPos(int, int);
+       void setPos(int, int);
        ///
-       void GetPos(int & x, int & y);
+       void getPos(int & x, int & y);
        ///
        MathInset * par() const;
-       /// return the next enclosing par of the given type and the cursor's
-       //index in it
-       MathInset * enclosing(MathInsetTypes, int &) const;
+       /// return the next enclosing grid inset and the cursor's index in it
+       MathArrayInset * enclosingArray(int &) const;
        ///
        InsetFormulaBase const * formula();
        ///
        int pos() const;
        ///
-       void Interpret(string const &);
+       int idx() const;
+       ///
+       int size() const;
+       ///
+       void interpret(string const &);
        ///
-       void SetSize(MathStyles);
+       void setSize(MathStyles);
        ///
        bool toggleLimits();
        ///
        // Macro mode methods
-       void MacroModeOpen();
+       void macroModeClose();
        ///
-       void MacroModeClose();
-       ///
-       bool InMacroMode() const;
+       bool inMacroMode() const;
        
        // Local selection methods
        ///
-       bool Selection() const;
-       ///
-       void SelCopy();
+       bool selection() const;
        ///
-       void SelCut();
+       void selCopy();
        ///
-       void SelDel();
+       void selCut();
        ///
-       void SelPaste();
+       void selDel();
        ///
-       void SelHandle(bool);
+       void selPaste();
        ///
-       void SelStart();
+       void selHandle(bool);
        ///
-       void SelClear();
+       void selStart();
        ///
-       void SelGetArea(int * xp, int * yp, int & n);
+       void selClear();
        ///
-       void clearLastCode();
-       ///
-       void setLastCode(MathTextCodes t);
+       void drawSelection(Painter & pain) const;
        ///
        void handleFont(MathTextCodes t);
        ///
-       void handleAccent(string const & name, int code);
+       void handleDelim(latexkeys const * l, latexkeys 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 
@@ -126,20 +172,12 @@ public:
        ///
        MathTextCodes getLastCode() const;
        ///
-       int idx() const { return cursor_.idx_; }
-       ///
-       void idxNext();
-       ///
-       void idxPrev();
-       ///
-       void pullArg();
+       void pullArg(bool goright);
        ///
-       bool isInside(MathInset *) const;
+       bool isInside(MathInset const *) const;
        ///
        MathTextCodes nextCode() const;
        ///
-       MathTextCodes prevCode() const;
-       ///
        char valign() const;
        ///
        char halign() const;
@@ -148,54 +186,39 @@ public:
        ///
        int row() const;
 
-//protected:
        ///
-       bool macro_mode;
+       MathStyles style() const;
+       /// Make sure cursor position is valid
+       void normalize() const;
        
-       // Selection stuff
-       /// do we currently select
-       bool selection;
-
-       ///
-       InsetFormulaBase * const formula_;
-       ///
-       MathTextCodes lastcode;
+       /// enter a MathInset from the front
+       void pushLeft(MathInset * par);
+       /// enter a MathInset from the back
+       void pushRight(MathInset * par);
+       /// leave current MathInset to the left
+       bool popLeft();
+       /// leave current MathInset to the left
+       bool popRight();
 
        ///
        MathArray & array() const;
        ///
        MathXArray & xarray() const;
 
-       ///
-       MathStyles style() 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:
-       /// Description of a position 
-       struct MathIter {
-               /// inset
-               MathInset * par_;
-               /// cell inset
-               int idx_;
-               ///
-               int pos_;
-       };
+       /// returns the selection
+       void getSelection(MathCursorPos &, MathCursorPos &) const;
+       /// returns the normalized anchor of the selection
+       MathCursorPos normalAnchor() const;
 
        /// path of positions the cursor had to go if it were leving each inset
-       std::vector<MathIter> path_;
+       std::vector<MathCursorPos> Cursor_;
+       /// path of positions the anchor had to go if it were leving each inset
+       std::vector<MathCursorPos> Anchor_;
 
        /// reference to the last item of the path
-       MathIter anchor_;
+       MathCursorPos & cursor();
        ///
-       MathIter cursor_;
-       ///
-       int path_idx_;
+       MathCursorPos const & cursor() const;
 
 
        ///  
@@ -203,19 +226,12 @@ private:
        ///
        MathInset * parInset(int i) const;
        ///
+       MathMatrixInset * outerPar() const;
+       ///
        void seldump(char const * str) const;
        ///
        void dump(char const * str) const;
 
-       ///
-       int xpos() const;
-       ///
-       void gotoX(int x);
-
-       ///
-       bool nextIsInset() const;
-       ///
-       bool prevIsInset() const;
        ///
        void merge(MathArray const & arr);
        ///
@@ -223,10 +239,40 @@ private:
        ///
        MathInset * prevInset() const;
        ///
-       MathUpDownInset * nearbyUpDownInset() const;
+       MathScriptInset * prevScriptInset() const;
+       ///
+       MathSpaceInset * prevSpaceInset() const;
+private:
+       ///
+       string macroName() const;
+       ///
+       void insert(char, MathTextCodes t = LM_TC_MIN);
+       /// can we enter the inset? 
+       bool openable(MathInset *, bool selection) const;
+       /// can the setPos routine enter that inset?
+       bool positionable(MathInset *, bool selection) const;
+       /// write access to cursor cell position
+       int & pos();
+       /// write access to cursor cell index
+       int & idx();
+       /// x-offset of current cell relative to par xo
+       int cellXOffset() const;
+       /// y-offset of current cell relative to par yo
+       int cellYOffset() const;
+       /// current x position relative to par xo
+       int xpos() const;
+       /// current y position relative to par yo
+       int ypos() const;
+       /// adjust position in current cell according to x. idx is not changed.
+       void gotoX(int x);
 
        ///
-       MathFuncInset * imacro;
+       InsetFormulaBase * const formula_;
+       ///
+       MathTextCodes lastcode_;
+       // Selection stuff
+       /// do we currently select
+       bool selection_;
 };
 
 extern MathCursor * mathcursor;