]> 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 5f6721553df29d2dcd4706600660d1b36c947253..d0a71e46fc8338ce2f09c99f040b8e01744de14a 100644 (file)
@@ -10,8 +10,6 @@
  *
  *  Copyright: 1996, Alejandro Aguilar Sierra
  *
- *   Version: 0.8beta, Mathed & Lyx project.
- *
  *   You are free to use and modify this code under the terms of
  *   the GNU General Public Licence version 2 or later.
  */
 #pragma interface
 #endif
 
-#include "math_iter.h" 
-//#include "math_inset.h"
-#include "math_xiter.h"
+#include "math_defs.h"
 
+class MathInset;
 class MathFuncInset;
+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 Mathed's subkernel
-class MathedCursor {
+
+/// This is the external interface of Math's subkernel
+class MathCursor {
 public:
        ///
-       explicit
-       MathedCursor(MathParInset * p);
+       explicit MathCursor(InsetFormulaBase *);
+       ///
+       void insert(char, MathTextCodes t = LM_TC_MIN);
        ///
-       void Insert(byte, MathedTextCodes t = LM_TC_MIN);
+       void insert(MathInset *);
        ///
-       void Insert(MathedInset *, int t = LM_TC_INSET);
+       void insert(MathArray const &);
        ///
        void Home();
        ///
@@ -52,63 +86,48 @@ public:
        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();
        ///
-       bool Pop();
-       ///
-       bool Push();
-       /// Pull out an argument from its container inset
-       bool pullArg();
+       bool plainLeft();
        ///
-       void draw(Painter &, int x, int y);
-       ///
-       void Redraw(Painter &);
+       bool plainRight();
        ///
        void Delete();
        ///
        void DelLine();
-       ///
+       /// This is in pixels from (maybe?) the top of inset
        void SetPos(int, int);
        ///
-       void GetPos(int & x, int & y) { cursor->GetPos(x, y); }
-       ///
-       short GetFCode() { return cursor->FCode(); }
+       void GetPos(int & x, int & y);
        ///
-       MathParInset * GetPar() { return par; }
+       MathInset * par() const;
+       /// return the next enclosing par of the given type and the cursor's
+       //index in it
+       MathInset * enclosing(MathInsetTypes, int &) const;
        ///
-       MathParInset * getCurrentPar() const { return cursor->p; }
+       InsetFormulaBase const * formula();
        ///
-       void SetPar(MathParInset *);
+       int pos() const;
        ///
        void Interpret(string const &);
        ///
-       void SetSize(short);
-       ///
-       void setNumbered();
-       ///
-       void setLabel(string const &);
-       ///
-       string const & getLabel() const {
-               return cursor->getLabel();
-       }
+       void SetSize(MathStyles);
        ///
-       bool Limits();
-       /// Set accent: if argument = 0 it's considered consumed 
-       void setAccent(int ac = 0);
-       /// Returns last accent
-       int getAccent() const;
+       bool toggleLimits();
        ///
-       bool IsEnd() const { return !cursor->OK(); }
        // Macro mode methods
-       ///
        void MacroModeOpen();
        ///
        void MacroModeClose();
        ///
-       bool InMacroMode() { return macro_mode; }
+       bool InMacroMode() const;
        
        // Local selection methods
        ///
-       bool Selection() { return selection; }
+       bool Selection() const;
        ///
        void SelCopy();
        ///
@@ -118,67 +137,133 @@ public:
        ///
        void SelPaste();
        ///
+       void SelHandle(bool);
+       ///
        void SelStart();
        ///
        void SelClear();
        ///
-       void SelBalance();
+       void drawSelection(Painter & pain) const;
        ///
-       void SelGetArea(int ** xp, int ** yp, int & n);
+       void clearLastCode();
        ///
-       void clearLastCode() { lastcode = LM_TC_MIN; }
+       void setLastCode(MathTextCodes t);
        ///
-       void setLastCode(MathedTextCodes t) { lastcode = t; }
+       void handleFont(MathTextCodes t);
        ///
-       void toggleLastCode(MathedTextCodes t);
+       void handleAccent(string const & name, int code);
        ///
-       MathedTextCodes getLastCode() const { return lastcode; }
-       
-protected:
+       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();
        ///
-       bool macro_mode;
+       MathTextCodes getLastCode() const;
+       ///
+       int idx() const { return cursor().idx_; }
+       ///
+       void idxNext();
+       ///
+       void idxPrev();
+       ///
+       void pullArg(bool goright);
+       ///
+       bool isInside(MathInset *) const;
+       ///
+       MathTextCodes nextCode() const;
+       ///
+       MathTextCodes prevCode() const;
        ///
-       void MacroModeBack();
+       char valign() const;
        ///
-       void MacroModeInsert(char);
+       char halign() const;
+       ///
+       int col() const;
+       ///
+       int row() const;
+
+       ///
+       MathStyles style() const;
+       /// Make sure cursor position is valid
+       void normalize() const;
        
-       // Selection stuff
+       /// 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;
+
+       ///
+       InsetFormulaBase * const formula_;
        ///
-       int  selpos;
+       MathTextCodes lastcode;
+
        ///
-       MathedXIter cursel;
+       MathArray & array() const;
        ///
-       MathedXIter * anchor;
+       MathXArray & xarray() const;
+
+       /// 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_;
+       /// 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
+       MathCursorPos & cursor();
        ///
-//    MathedArray *selarray; 
+       MathCursorPos const & cursor() const;
+
+
+       ///  
+       int last() const;
        ///
-       bool is_visible;
+       MathInset * parInset(int i) const;
        ///
-       long unsigned win;
+       void seldump(char const * str) const;
        ///
-       MathParInset * par;
+       void dump(char const * str) const;
+
        ///
-       MathedXIter * cursor;
+       int xpos() const;
        ///
-       int xc;
+       void gotoX(int x);
+
        ///
-       int yc;
+       bool nextIsInset() const;
        ///
-       void doAccent(byte c, MathedTextCodes t);
+       bool prevIsInset() const;
        ///
-       void doAccent(MathedInset * p);
+       void merge(MathArray const & arr);
        ///
-       int accent;
+       MathInset * nextInset() const;
        ///
-       int nestaccent[8];
+       MathInset * prevInset() const;
        ///
-       MathedTextCodes lastcode;
-       
-private:
+       MathUpDownInset * nearbyUpDownInset() const;
+
        ///
        MathFuncInset * imacro;
 };
 
+extern MathCursor * mathcursor;
+
 #endif