]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
small mouse click stuff. still not ok...
[lyx.git] / src / mathed / math_cursor.h
index 60f76d2512e48fdc34e4fba853545558a22e4cd0..3aa02de9566447b9f43027439356b67e1aa575de 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"
+#include "math_inset.h"
+#include "LString.h"
 
-class MathFuncInset;
-class MathParInset;
+class InsetFormulaBase;
 class Painter;
+class Selection;
+
+/// Description of a position 
+struct MathCursorPos {
+       /// inset
+       MathAtom * par_;
+       /// cell index
+       MathInset::idx_type idx_;
+       /// cell position
+       MathInset::pos_type pos_;
+
+       /// returns cell corresponding to this position
+       MathArray & cell() const;
+       /// returns cell corresponding to this position
+       MathArray & cell(MathInset::idx_type idx) const;
+       /// returns xcell corresponding to this position
+       MathXArray & xcell() const;
+       /// returns xcell corresponding to this position
+       MathXArray & xcell(MathInset::idx_type 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:
+       /// short of anything else reasonable
+       typedef MathInset::size_type    size_type;
+       /// type for cursor positions within a cell
+       typedef MathInset::pos_type     pos_type;
+       /// type for cell indices
+       typedef MathInset::idx_type     idx_type;
+       /// type for row numbers
+       typedef MathInset::row_type     row_type;
+       /// type for column numbers
+       typedef MathInset::col_type     col_type;
+
        ///
-       explicit
-       MathedCursor(MathParInset * p);
+       explicit MathCursor(InsetFormulaBase *, bool left);
        ///
-       void Insert(byte, MathedTextCodes t = LM_TC_MIN);
+       void insert(MathAtom const &);
        ///
-       void Insert(MathedInset *, int t = LM_TC_INSET);
+       void insert(MathArray const &);
        ///
-       void Home();
+       void paste(MathArray const &);
        ///
-       void End();
+       void erase();
        ///
-       bool Right(bool sel = false);
+       void backspace();
        ///
-       bool Left(bool sel = false);
+       void home(bool sel = false);
        ///
-       bool Up(bool sel = false);
+       void end(bool sel = false);
        ///
-       bool Down(bool sel = false);
+       bool right(bool sel = false);
        ///
-       bool Pop();
+       bool left(bool sel = false);
        ///
-       bool Push();
-       /// Pull out an argument from its container inset
-       bool pullArg();
+       bool up(bool sel = false);
        ///
-       void draw(Painter &, int x, int y);
+       bool down(bool sel = false);
+       /// Put the cursor in the first position
+       void first();
+       /// Put the cursor in the last position
+       void last();
        ///
-       void Redraw(Painter &);
+       void idxNext();
        ///
-       void Delete();
+       void idxPrev();
        ///
-       void DelLine();
+       void plainErase();
        ///
-       void SetPos(int, int);
+       void plainInsert(MathAtom const &);
        ///
-       void GetPos(int & x, int & y);
+       void niceInsert(MathAtom const &);
+
        ///
-       short GetFCode();
+       void delLine();
+       /// This is in pixels from (maybe?) the top of inset
+       // don't move further in than the Anchor's inset if respect_anchor == true
+       void setPos(int x, int y, bool respect_anchor = false);
+       /// This is in pixels from (maybe?) the top of inset, don't move further
        ///
-       MathParInset * GetPar();
+       void getPos(int & x, int & y);
        ///
-       MathParInset * getCurrentPar() const;
+       MathAtom & par() const;
+       /// return the next enclosing grid inset and the cursor's index in it
+       MathGridInset * enclosingGrid(idx_type &) const;
        ///
-       void SetPar(MathParInset *);
+       InsetFormulaBase const * formula();
        ///
-       void Interpret(string const &);
+       pos_type pos() const;
        ///
-       void SetSize(short);
+       idx_type idx() const;
        ///
-       void setNumbered();
+       size_type size() const;
        ///
-       void setLabel(string const &);
+       bool interpret(string const &);
        ///
-       string const & getLabel() const;
+       bool interpret(char);
        ///
-       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;
        // 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 selGet(MathArray & ar);
        ///
-       void clearLastCode();
+       void drawSelection(Painter & pain) const;
        ///
-       void setLastCode(MathedTextCodes t);
+       void handleFont(MathTextCodes t);
        ///
-       void toggleLastCode(MathedTextCodes t);
+       void handleDelim(string const & l, string const & r);
        ///
-       MathedTextCodes getLastCode() const;
-       
-protected:
+       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();
+       /// read contents of line into an array
+       void readLine(MathArray & ar) const;
        ///
-       bool macro_mode;
+       MathTextCodes getLastCode() const;
        ///
-       void MacroModeBack();
+       void pullArg(bool goright);
        ///
-       void MacroModeInsert(char);
-       
-       // Selection stuff
+       bool isInside(MathInset const *) const;
+       ///
+       MathTextCodes nextCode() const;
        ///
-       bool selection;
+       char valign() const;
        ///
-       int  selpos;
+       char halign() const;
+       ///
+       col_type ncols() const;
+       ///
+       col_type col() const;
+       ///
+       row_type row() const;
+
+       /// Make sure cursor position is valid
+       void normalize() const;
        ///
-       MathedXIter cursel;
+       UpdatableInset * asHyperActiveInset() const;
+
+       /// enter a MathInset 
+       void push(MathAtom & par);
+       /// enter a MathInset from the front
+       void pushLeft(MathAtom & par);
+       /// enter a MathInset from the back
+       void pushRight(MathAtom & par);
+       /// leave current MathInset to the left
+       bool popLeft();
+       /// leave current MathInset to the left
+       bool popRight();
+
        ///
-       MathedXIter * anchor;
+       MathArray & array() const;
        ///
-//    MathedArray *selarray; 
+       MathXArray & xarray() const;
        ///
-       bool is_visible;
+       bool hasPrevAtom() const;
        ///
-       long unsigned win;
+       bool hasNextAtom() const;
        ///
-       MathParInset * par;
+       MathAtom const & prevAtom() const;
        ///
-       MathedXIter * cursor;
+       MathAtom & prevAtom();
        ///
-       int xc;
+       MathAtom const & nextAtom() const;
        ///
-       int yc;
+       MathAtom & nextAtom();
+
+       /// 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();
        ///
-       void doAccent(byte c, MathedTextCodes t);
+       MathCursorPos const & cursor() const;
+
        ///
-       void doAccent(MathedInset * p);
+       void seldump(char const * str) const;
        ///
-       int accent;
+       void dump(char const * str) const;
        ///
-       int nestaccent[8];
+       void stripFromLastEqualSign();
+
        ///
-       MathedTextCodes lastcode;
-       
+       friend class Selection;
+
 private:
+       /// 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();
+
+       ///
+       string macroName() const;
+       ///
+       int macroNamePos() const;
+       ///
+       void insert(char, MathTextCodes t);
+       /// can we enter the inset? 
+       bool openable(MathAtom const &, bool selection) const;
+       /// can the setPos routine enter that inset?
+       bool positionable(MathAtom const &, int x, int y) const;
+       /// write access to cursor cell position
+       pos_type & pos();
+       /// write access to cursor cell index
+       idx_type & idx();
+
+       ///
+       InsetFormulaBase * const formula_;
        ///
-       MathFuncInset * imacro;
+       MathTextCodes lastcode_;
+       // Selection stuff
+       /// do we currently select
+       bool selection_;
 };
 
+extern MathCursor * mathcursor;
+
 #endif