]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
fix cursor positioning using the mouse
[lyx.git] / src / mathed / math_cursor.h
index 766cc1c26d3ff2825990e0f4dbd4abf93d8ae11b..34f93337891f9851ef2ed385b9fc0977e621b927 100644 (file)
 #include "math_defs.h"
 
 class MathInset;
+class MathAtom;
+class MathArrayInset;
 class MathFuncInset;
+class MathMatrixInset;
 class MathScriptInset;
 class MathSpaceInset;
 class InsetFormulaBase;
 class MathArray;
 class MathXArray;
 class Painter;
+class latexkeys;
 
 /// Description of a position 
 struct MathCursorPos {
@@ -48,14 +52,6 @@ struct MathCursorPos {
        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();
 };
 
 /// 
@@ -70,93 +66,106 @@ public:
        ///
        explicit MathCursor(InsetFormulaBase *);
        ///
-       void insert(char, MathTextCodes t = LM_TC_MIN);
-       ///
        void insert(MathInset *);
        ///
        void insert(MathArray const &);
        ///
        void erase();
        ///
-       void Home();
+       void backspace();
        ///
-       void End();
+       void home(bool sel = false);
        ///
-       bool Right(bool sel = false);
+       void end(bool sel = false);
        ///
-       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();
        ///
-       bool plainLeft();
+       void idxNext();
+       ///
+       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;
+       bool selection() const;
        ///
-       void SelCopy();
+       void selCopy();
        ///
-       void SelCut();
+       void selCut();
        ///
-       void SelDel();
+       void selDel();
        ///
-       void SelPaste();
+       void selPaste();
        ///
-       void SelHandle(bool);
+       void selHandle(bool);
        ///
-       void SelStart();
+       void selStart();
        ///
-       void SelClear();
+       void selClear();
        ///
        void drawSelection(Painter & pain) const;
        ///
-       void clearLastCode();
-       ///
-       void setLastCode(MathTextCodes t);
-       ///
        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 
@@ -164,20 +173,12 @@ public:
        ///
        MathTextCodes getLastCode() const;
        ///
-       int idx() const { return cursor().idx_; }
-       ///
-       void idxNext();
-       ///
-       void idxPrev();
-       ///
        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;
@@ -191,39 +192,32 @@ public:
        /// 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();
+       /// 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();
 
-//private:
        ///
-       bool macro_mode;
-       
-       // Selection stuff
-       /// do we currently select
-       bool selection;
-
+       MathArray & array() const;
        ///
-       InsetFormulaBase * const formula_;
+       MathXArray & xarray() const;
        ///
-       MathTextCodes lastcode;
-
+       MathAtom const * prevAtom() const;
        ///
-       MathArray & array() const;
+       MathAtom * prevAtom();
        ///
-       MathXArray & xarray() const;
+       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_;
@@ -241,19 +235,12 @@ public:
        ///
        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);
        ///
@@ -264,9 +251,37 @@ public:
        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?
+       MathInset * positionable(MathAtom *, int x, int y) 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;