]> 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 51a9942ef5e43cee4ca1562619863b5f95c99ef4..90519bec17aa0cd1327c11cf083eac80e7adf45b 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_xiter.h"
+#include "math_defs.h"
 
+class MathInset;
+class MathArrayInset;
 class MathFuncInset;
-class MathParInset;
+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 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(byte, MathedTextCodes t = LM_TC_MIN);
+       void insert(MathInset *);
        ///
-       void insertInset(MathedInset *, int t);
+       void insert(MathArray const &);
        ///
-       void Home();
+       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 Pop();
+       bool up(bool sel = false);
        ///
-       bool Push();
-       /// Pull out an argument from its container inset
-       bool pullArg();
+       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 draw(Painter &, int x, int y);
+       void idxNext();
        ///
-       void Redraw(Painter &);
+       void idxPrev();
        ///
-       void Delete();
+       void plainErase();
        ///
-       void DelLine();
+       void plainInsert(MathInset * p);
        ///
-       void SetPos(int, int);
+       void niceInsert(MathInset * p);
        ///
-       void GetPos(int & x, int & y);
+       void delLine();
+       /// This is in pixels from (maybe?) the top of inset
+       void setPos(int, int);
        ///
-       short GetFCode();
+       void getPos(int & x, int & y);
        ///
-       MathParInset * GetPar();
+       MathInset * par() const;
+       /// return the next enclosing grid inset and the cursor's index in it
+       MathArrayInset * enclosingArray(int &) const;
        ///
-       MathParInset * getCurrentPar() const;
+       InsetFormulaBase const * formula();
        ///
-       void SetPar(MathParInset *);
+       int pos() const;
        ///
-       void Interpret(string const &);
+       int idx() const;
        ///
-       void SetSize(short);
+       int size() const;
        ///
-       void setNumbered();
+       void interpret(string const &);
        ///
-       void setLabel(string const &);
+       void setSize(MathStyles);
        ///
-       string const & getLabel() const;
+       bool toggleLimits();
        ///
-       bool Limits();
-       /// Set accent: if argument = 0 it's considered consumed 
-       void setAccent(int ac = 0);
-       /// Returns last accent
-       int getAccent() const;
-       ///
-       bool IsEnd() const;
        // Macro mode methods
+       void macroModeClose();
        ///
-       void MacroModeOpen();
-       ///
-       void MacroModeClose();
-       ///
-       bool InMacroMode();
+       bool inMacroMode() const;
        
        // Local selection methods
        ///
-       bool Selection();
+       bool selection() const;
        ///
-       void SelCopy();
+       void selCopy();
        ///
-       void SelCut();
+       void selCut();
        ///
-       void SelDel();
+       void selDel();
        ///
-       void SelPaste();
+       void selPaste();
        ///
-       void SelStart();
+       void selHandle(bool);
        ///
-       void SelClear();
+       void selStart();
        ///
-       void SelBalance();
+       void selClear();
        ///
-       void SelGetArea(int ** xp, int ** yp, int & n);
+       void drawSelection(Painter & pain) const;
        ///
-       void clearLastCode();
+       void handleFont(MathTextCodes t);
        ///
-       void setLastCode(MathedTextCodes t);
+       void handleDelim(latexkeys const * l, latexkeys const * r);
        ///
-       void toggleLastCode(MathedTextCodes t);
+       void handleNest(MathInset * p);
+       /// Splits cells and shifts right part to the next cell
+       void splitCell();
+       /// Splits line and insert new row of cell 
+       void breakLine();
        ///
-       MathedTextCodes getLastCode() const;
-       
-protected:
+       MathTextCodes getLastCode() const;
+       ///
+       void pullArg(bool goright);
+       ///
+       bool isInside(MathInset const *) const;
+       ///
+       MathTextCodes nextCode() const;
+       ///
+       char valign() const;
+       ///
+       char halign() const;
+       ///
+       int col() const;
+       ///
+       int row() const;
+
        ///
-       bool macro_mode;
+       MathStyles style() const;
+       /// Make sure cursor position is valid
+       void normalize() const;
        
-       // Selection stuff
+       /// 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();
+
        ///
-       bool selection;
+       MathArray & array() const;
        ///
-       int  selpos;
+       MathXArray & xarray() const;
+
+       /// 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<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();
        ///
-       MathedXIter cursel;
+       MathCursorPos const & cursor() const;
+
+
+       ///  
+       int last() const;
        ///
-       MathedXIter * anchor;
+       MathInset * parInset(int i) const;
        ///
-       MathParInset * par;
+       MathMatrixInset * outerPar() const;
        ///
-       MathedXIter * cursor;
+       void seldump(char const * str) const;
        ///
-       void doAccent(byte c, MathedTextCodes t);
+       void dump(char const * str) const;
+
        ///
-       void doAccent(MathedInset * p);
+       void merge(MathArray const & arr);
        ///
-       int accent;
+       MathInset * nextInset() const;
        ///
-       int nestaccent[8];
+       MathInset * prevInset() const;
        ///
-       MathedTextCodes lastcode;
-       
+       MathScriptInset * prevScriptInset() const;
+       ///
+       MathSpaceInset * prevSpaceInset() const;
 private:
        ///
-       MathFuncInset * imacro;
+       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);
+
+       ///
+       InsetFormulaBase * const formula_;
+       ///
+       MathTextCodes lastcode_;
+       // Selection stuff
+       /// do we currently select
+       bool selection_;
 };
 
+extern MathCursor * mathcursor;
+
 #endif