#endif
#include "math_defs.h"
+#include "math_inset.h"
+#include "LString.h"
class MathInset;
+class MathAtom;
+class MathArrayInset;
class MathFuncInset;
+class MathMatrixInset;
class MathScriptInset;
+class MathSpaceInset;
class InsetFormulaBase;
class MathArray;
class MathXArray;
+class Painter;
+class Selection;
+class latexkeys;
+
+/// 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 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 MathCursor(InsetFormulaBase *, bool left);
+ ///
+ void insert(MathAtom const &);
+ ///
+ void insert(MathArray const &);
///
- explicit MathCursor(InsetFormulaBase *);
+ void paste(MathArray const &);
///
- void insert(char, MathTextCodes t = LM_TC_MIN);
+ void erase();
///
- void insert(MathInset *);
+ void backspace();
///
- void Home();
+ void home(bool sel = false);
///
- void End();
+ void end(bool sel = false);
///
- bool Right(bool sel = false);
+ bool right(bool sel = false);
///
- bool Left(bool sel = false);
+ bool left(bool sel = false);
///
- bool Up(bool sel = false);
+ bool up(bool sel = false);
///
- bool Down(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 plainRight();
+ void idxNext();
///
- void Delete();
+ void idxPrev();
///
- void DelLine();
+ void plainErase();
+ ///
+ void plainInsert(MathAtom const &);
+ ///
+ void niceInsert(MathAtom const &);
+
+ ///
+ 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;
+ MathAtom & par() const;
+ /// return the next enclosing grid inset and the cursor's index in it
+ MathArrayInset * enclosingArray(idx_type &) const;
///
InsetFormulaBase const * formula();
///
- int pos() const;
+ pos_type pos() const;
///
- void Interpret(string const &);
+ idx_type idx() const;
///
- void SetSize(MathStyles);
+ size_type size() const;
+ ///
+ void interpret(string const &);
+ ///
+ void interpret(char);
+ ///
+ 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();
- ///
- void MacroModeClose();
+ void macroModeClose();
///
- bool InMacroMode() const;
+ bool inMacroMode() const;
// Local selection methods
///
- bool Selection() const;
+ bool selection() const;
///
- void SelCopy();
+ void selCopy();
///
- void SelCut();
+ void selCut();
///
- void SelDel();
+ void selDel();
///
- void SelPaste();
+ void selPaste();
///
- void SelHandle(bool);
+ void selHandle(bool);
///
- void SelStart();
+ void selStart();
///
- void SelClear();
+ void selClear();
///
- void SelGetArea(int * xp, int * yp, int & n);
- ///
- void clearLastCode();
- ///
- void setLastCode(MathTextCodes t);
+ void drawSelection(Painter & pain) const;
///
void handleFont(MathTextCodes t);
///
- MathTextCodes getLastCode() const;
+ void handleDelim(string const & l, string const & r);
///
- int idx() const { return idx_; }
+ 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();
///
- void idxRight();
+ MathTextCodes getLastCode() const;
///
- void pullArg();
+ void pullArg(bool goright);
///
- bool isInside(MathInset *) const;
+ bool isInside(MathInset const *) const;
///
MathTextCodes nextCode() const;
///
- MathTextCodes prevCode() const;
- ///
- void selArray(MathArray &) const;
- ///
char valign() const;
///
char halign() const;
///
- int col() const;
+ col_type col() const;
///
- int row() const;
+ row_type row() const;
-//protected:
- ///
- bool macro_mode;
-
- // Selection stuff
///
- bool selection;
- ///
- int anchor_;
- ///
- int cursor_;
- ///
- int idx_;
- ///
- MathInset * par_;
- ///
- InsetFormulaBase * const formula_;
+ MathStyles style() const;
+ /// Make sure cursor position is valid
+ void normalize() 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();
+
///
- void doAccent(char c, MathTextCodes t);
+ MathArray & array() const;
///
- void doAccent(MathInset * p);
+ MathXArray & xarray() const;
///
- int accent;
+ bool hasPrevAtom() const;
///
- int nestaccent[8];
+ bool hasNextAtom() const;
///
- MathTextCodes lastcode;
-
+ MathAtom const & prevAtom() const;
///
- MathArray & array() const;
+ MathAtom & prevAtom();
///
- MathXArray & xarray() const;
-
+ MathAtom const & nextAtom() 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();
+ MathAtom & nextAtom();
-private:
- /// Description of a position
- struct MathIter {
- MathInset * par_;
- int idx_;
- int cursor_;
- };
+ /// returns the selection
+ void getSelection(MathCursorPos &, MathCursorPos &) const;
+ /// returns the normalized anchor of the selection
+ MathCursorPos normalAnchor() 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_;
- ///
- int last() const;
+ /// reference to the last item of the path
+ MathCursorPos & cursor();
///
- MathInset * parInset(int i) const;
+ MathCursorPos const & cursor() const;
+
///
void seldump(char const * str) const;
///
void dump(char const * str) const;
///
- int xpos() const;
+ 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();
+ /// 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);
///
- 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 * nearbyScriptInset() const;
-
+ InsetFormulaBase * const formula_;
///
- MathFuncInset * imacro;
+ MathTextCodes lastcode_;
+ // Selection stuff
+ /// do we currently select
+ bool selection_;
};
extern MathCursor * mathcursor;