X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_cursor.h;h=90519bec17aa0cd1327c11cf083eac80e7adf45b;hb=aea21e8cacad73e0d5df58637994b87b3eabc30e;hp=e47807aefe1ca438d6f8d9fc4c9a6ed054ea1cf0;hpb=61529b136ed5b7b2dc4ec3de2b190dc8c015a7bd;p=lyx.git diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index e47807aefe..90519bec17 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -24,11 +24,40 @@ #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 End(); + void backspace(); /// - bool Right(bool sel = false); + void home(); /// - bool Left(bool sel = false); + void end(); /// - bool Up(bool sel = false); + bool right(bool sel = false); /// - bool Down(bool sel = false); + bool left(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(); + /// + void plainErase(); /// - bool plainRight(); + void plainInsert(MathInset * p); /// - void Delete(); + void niceInsert(MathInset * p); /// - void DelLine(); + 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 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,70 +186,52 @@ public: /// int row() const; -//protected: /// - bool macro_mode; + MathStyles style() const; + /// Make sure cursor position is valid + void normalize() const; - // Selection stuff - /// - bool selection; - /// - int anchor_; - /// - int cursor_; - /// - int idx_; - /// - MathInset * par_; - /// - 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(); + /// returns the selection + void getSelection(MathCursorPos &, MathCursorPos &) const; + /// returns the normalized anchor of the selection + MathCursorPos normalAnchor() const; -private: - /// Description of a position - struct MathIter { - MathInset * par_; - int idx_; - int cursor_; - }; + /// path of positions the cursor had to go if it were leving each inset + std::vector Cursor_; + /// path of positions the anchor had to go if it were leving each inset + std::vector Anchor_; + + /// reference to the last item of the path + MathCursorPos & cursor(); + /// + MathCursorPos const & cursor() const; - /// MathPath - std::vector path_; /// 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 gotoX(int x); - - /// - bool nextIsInset() const; - /// - bool prevIsInset() const; /// void merge(MathArray const & arr); /// @@ -219,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;