*
* 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"
-
-
-/// This is the external interface of Mathed's subkernel
-class MathedCursor {
- public:
- ///
- explicit
- MathedCursor(MathParInset * p);
- ///
- void Insert(byte, MathedTextCodes t = LM_TC_MIN);
- ///
- void Insert(MathedInset *, int t = LM_TC_INSET);
- ///
- void Home();
- ///
- void End();
- ///
- bool Right(bool sel = false);
- ///
- bool Left(bool sel = false);
- ///
- bool Up(bool sel = false);
- ///
- bool Down(bool sel = false);
- ///
- bool Pop();
- ///
- bool Push();
- /// Pull out an argument from its container inset
- bool pullArg();
- ///
- void draw(Painter &, int x, int y);
- ///
- void Redraw(Painter &);
- ///
- void Delete();
- ///
- void DelLine();
- ///
- void SetPos(int, int);
- ///
- void GetPos(int & x, int & y) { cursor->GetPos(x, y); }
- ///
- short GetFCode() { return cursor->FCode(); }
- ///
- MathParInset * GetPar() { return par; }
- ///
- MathParInset * getCurrentPar() const { return cursor->p; }
- ///
- void SetPar(MathParInset *);
- ///
- void Interpret(string const &);
- ///
- void SetSize(short);
- ///
- void setNumbered();
- ///
- void setLabel(string const &);
- ///
- string const & getLabel() const {
- return cursor->getLabel();
- }
- ///
- 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 { return !cursor->OK(); }
- // Macro mode methods
- ///
- void MacroModeOpen();
- ///
- void MacroModeClose();
- ///
- bool InMacroMode() { return macro_mode; }
-
- // Local selection methods
- ///
- bool Selection() { return selection; }
- ///
- void SelCopy();
- ///
- void SelCut();
- ///
- void SelDel();
- ///
- void SelPaste();
- ///
- void SelStart();
- ///
- void SelClear();
- ///
- void SelBalance();
- ///
- void SelGetArea(int ** xp, int ** yp, int & n);
- ///
- void clearLastCode() { lastcode = LM_TC_MIN; }
- ///
- void setLastCode(MathedTextCodes t) { lastcode = t; }
- ///
- MathedTextCodes getLastCode() const { return lastcode; }
-
- protected:
- ///
- bool macro_mode;
- ///
- void MacroModeBack();
- ///
- void MacroModeInsert(char);
-
- // Selection stuff
- ///
- bool selection;
- ///
- int selpos;
- ///
- MathedXIter cursel, * anchor;
- ///
-// LyxArrayBase *selarray;
- ///
- bool is_visible;
- ///
- long unsigned win;
- ///
- MathParInset * par;
- ///
- MathedXIter * cursor;
- ///
- int xc, yc;
- ///
- void doAccent(byte c, MathedTextCodes t);
- ///
- void doAccent(MathedInset * p);
- ///
- int accent;
- ///
- int nestaccent[8];
- ///
- MathedTextCodes lastcode;
-
- private:
- ///
- MathFuncInset * imacro;
+#include "math_defs.h"
+
+class MathInset;
+class MathAtom;
+class MathArrayInset;
+class MathFuncInset;
+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 &);
-//-------------------- Inline Functions -------------------------//
+/// This is the external interface of Math's subkernel
+class MathCursor {
+public:
+ ///
+ explicit MathCursor(InsetFormulaBase *);
+ ///
+ void insert(MathInset *);
+ ///
+ void insert(MathArray const &);
+ ///
+ void erase();
+ ///
+ void backspace();
+ ///
+ void home(bool sel = false);
+ ///
+ void end(bool sel = false);
+ ///
+ bool right(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();
+ ///
+ void idxPrev();
+ ///
+ void plainErase();
+ ///
+ void plainInsert(MathInset * p);
+ ///
+ void niceInsert(MathInset * p);
+ ///
+ void delLine();
+ /// This is in pixels from (maybe?) the top of inset
+ void setPos(int, int);
+ ///
+ void getPos(int & x, int & y);
+ ///
+ MathInset * par() const;
+ /// return the next enclosing grid inset and the cursor's index in it
+ MathArrayInset * enclosingArray(int &) const;
+ ///
+ InsetFormulaBase const * formula();
+ ///
+ int pos() const;
+ ///
+ int idx() const;
+ ///
+ int size() const;
+ ///
+ void interpret(string const &);
+ ///
+ void setSize(MathStyles);
+ ///
+ bool toggleLimits();
+ ///
+ // Macro mode methods
+ void macroModeClose();
+ ///
+ bool inMacroMode() const;
+
+ // Local selection methods
+ ///
+ bool selection() const;
+ ///
+ void selCopy();
+ ///
+ void selCut();
+ ///
+ void selDel();
+ ///
+ void selPaste();
+ ///
+ void selHandle(bool);
+ ///
+ void selStart();
+ ///
+ void selClear();
+ ///
+ void drawSelection(Painter & pain) const;
+ ///
+ void handleFont(MathTextCodes t);
+ ///
+ void handleDelim(latexkeys const * l, latexkeys const * 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
+ void breakLine();
+ ///
+ 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;
+
+ ///
+ MathStyles style() const;
+ /// Make sure cursor position is valid
+ void normalize() const;
+
+ /// 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;
+ ///
+ MathAtom const * prevAtom() const;
+ ///
+ MathAtom * prevAtom();
+ ///
+ MathAtom const * nextAtom() const;
+ ///
+ 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();
+ ///
+ MathCursorPos const & cursor() const;
+
+
+ ///
+ int last() const;
+ ///
+ MathInset * parInset(int i) const;
+ ///
+ MathMatrixInset * outerPar() const;
+ ///
+ void seldump(char const * str) const;
+ ///
+ void dump(char const * str) const;
+
+ ///
+ void merge(MathArray const & arr);
+ ///
+ MathInset * nextInset() const;
+ ///
+ MathInset * prevInset() 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?
+ MathInset * positionable(MathAtom *, int x, int y) 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