]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
fix pullArg when pressing <Delete> at the end of an cell
[lyx.git] / src / mathed / math_cursor.h
index 928431907053bfd1a036115d9eae50822c1ace51..d0a71e46fc8338ce2f09c99f040b8e01744de14a 100644 (file)
 
 class MathInset;
 class MathFuncInset;
-class MathScriptInset;
+class MathUpDownInset;
 class InsetFormulaBase;
 class MathArray;
 class MathXArray;
+class Painter;
+
+/// 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;
+       /// 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();
+};
+
+/// 
+bool operator==(MathCursorPos const &, MathCursorPos const &);
+/// 
+bool operator<(MathCursorPos const &, MathCursorPos const &);
+
 
 /// This is the external interface of Math's subkernel
 class MathCursor {
@@ -40,6 +73,8 @@ public:
        ///
        void insert(MathInset *);
        ///
+       void insert(MathArray const &);
+       ///
        void Home();
        ///
        void End();
@@ -56,6 +91,10 @@ public:
        /// Put the cursor in the last position
        void last();
        ///
+       bool plainLeft();
+       ///
+       bool plainRight();
+       ///
        void Delete();
        ///
        void DelLine();
@@ -78,10 +117,6 @@ public:
        void SetSize(MathStyles);
        ///
        bool toggleLimits();
-       /// Set accent: if argument = 0 it's considered consumed 
-       void setAccent(int ac = 0);
-       /// Returns last accent
-       int getAccent() const;
        ///
        // Macro mode methods
        void MacroModeOpen();
@@ -108,21 +143,31 @@ public:
        ///
        void SelClear();
        ///
-       void SelGetArea(int * xp, int * yp, int & n);
+       void drawSelection(Painter & pain) const;
        ///
        void clearLastCode();
        ///
        void setLastCode(MathTextCodes t);
        ///
-       void toggleLastCode(MathTextCodes t);
+       void handleFont(MathTextCodes t);
+       ///
+       void handleAccent(string const & name, int code);
+       ///
+       void handleDelim(int l, int r);
+       /// Splits cells and shifts right part to the next cell
+       void splitCell();
+       /// Splits line and insert new row of cell 
+       void breakLine();
        ///
        MathTextCodes getLastCode() const;
        ///
-       int idx() const { return idx_; }
+       int idx() const { return cursor().idx_; }
        ///
-       void idxRight();
+       void idxNext();
        ///
-       void pullArg();
+       void idxPrev();
+       ///
+       void pullArg(bool goright);
        ///
        bool isInside(MathInset *) const;
        ///
@@ -130,34 +175,35 @@ public:
        ///
        MathTextCodes prevCode() const;
        ///
-       void selArray(MathArray &) const;
+       char valign() const;
+       ///
+       char halign() const;
+       ///
+       int col() const;
+       ///
+       int row() const;
+
+       ///
+       MathStyles style() const;
+       /// Make sure cursor position is valid
+       void normalize() const;
        
-//protected:
+       /// Enter a new MathInset from the front or the back
+       void push(MathInset * par, bool first);
+       /// Leave current MathInset
+       bool pop();
+
+//private:
        ///
        bool macro_mode;
        
        // Selection stuff
-       ///
+       /// do we currently select
        bool selection;
-       ///
-       int anchor_;
-       ///
-       int cursor_;
-       ///
-       int idx_;
-       ///
-       MathInset       * par_;
+
        ///
        InsetFormulaBase * const formula_;
        ///
-       void doAccent(char c, MathTextCodes t);
-       ///
-       void doAccent(MathInset * p);
-       ///
-       int accent;
-       ///
-       int nestaccent[8];
-       ///
        MathTextCodes lastcode;
 
        ///
@@ -165,26 +211,28 @@ public:
        ///
        MathXArray & xarray() const;
 
-       ///
-       MathStyles style() const;
-       ///
-       void normalize() const;
-       
-private:
-       /// Description of a position 
-       struct MathIter {
-               MathInset * par_;
-               int idx_;
-               int cursor_;
-       };
+       /// 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;
 
-       /// MathPath
-       std::vector<MathIter> path_;
+       /// path of positions the cursor had to go if it were leving each inset
+       std::vector<MathCursorPos> Cursor_;
+       /// path of positions the anchor had to go if it were leving each inset
+       std::vector<MathCursorPos> Anchor_;
 
-       ///  
-       void push(MathInset * par, bool first);
+       /// reference to the last item of the path
+       MathCursorPos & cursor();
        ///
-       void pop();
+       MathCursorPos const & cursor() const;
+
+
        ///  
        int last() const;
        ///
@@ -202,31 +250,15 @@ private:
        ///
        bool nextIsInset() const;
        ///
-       bool nextIsActive() const;
-       ///
        bool prevIsInset() const;
        ///
-       bool prevIsActive() const;
-       ///
-       bool IsFont() const;
-       ///
-       bool IsScript() const;
-       ///
        void merge(MathArray const & arr);
        ///
        MathInset * nextInset() const;
        ///
-       MathInset * nextActiveInset() const;
-       ///
        MathInset * prevInset() const;
        ///
-       MathInset * prevActiveInset() const;
-       ///
-       MathScriptInset * prevScriptInset() const;
-       ///
-       int col() const;
-       ///
-       int row() const;
+       MathUpDownInset * nearbyUpDownInset() const;
 
        ///
        MathFuncInset * imacro;