]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.h
prepare infrastructure for multicell selection
[lyx.git] / src / mathed / math_cursor.h
index dea75ab022f98eb433af044ed8feb5d38d847a5e..da2a4ecf769ae7d709e3fb4fdc7770d60d87e52f 100644 (file)
  *
  *  Dependencies: Xlib, XForms
  *
- *  Copyright: (c) 1996, Alejandro Aguilar Sierra
- *
- *   Version: 0.8beta, Mathed & Lyx project.
+ *  Copyright: 1996, Alejandro Aguilar Sierra
  *
  *   You are free to use and modify this code under the terms of
  *   the GNU General Public Licence version 2 or later.
  */
 
-#ifndef __MATH_CURSOR__
-#define __MATH_CURSOR__
+#ifndef MATH_CURSOR
+#define MATH_CURSOR
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-#include "math_iter.h" 
-#include "math_inset.h"
-
-
-/// This is the external interface of Mathed's subkernel
-class MathedCursor {
- public:
-    ///
-    MathedCursor(MathParInset *p);
-    ///
-    ~MathedCursor() { };
-    ///
-    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(long unsigned pm, int x, int y);
-    ///
-    void Redraw();
-    ///
-    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(char const*);
-    ///
-    void SetSize(short);
-    ///
-    void setNumbered();
-    void setLabel(char const*);
-    ///
-    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();  
-    ///
-    XPoint *SelGetArea(int&);
-    ///
-    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:
-       ///
-    char macrobf[80];
-       ///
-    int macroln;
-       ///
-    MathFuncInset* imacro;
-};
+#include "math_defs.h"
 
+class MathInset;
+class MathFuncInset;
+class MathUpDownInset;
+class InsetFormulaBase;
+class MathArray;
+class MathXArray;
 
-//--------------------   Inline Functions  -------------------------// 
+/// This is the external interface of Math's subkernel
+class MathCursor {
+public:
+       ///
+       explicit MathCursor(InsetFormulaBase *);
+       ///
+       void insert(char, MathTextCodes t = LM_TC_MIN);
+       ///
+       void insert(MathInset *);
+       ///
+       void Home();
+       ///
+       void End();
+       ///
+       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();
+       ///
+       bool plainLeft();
+       ///
+       bool plainRight();
+       ///
+       void Delete();
+       ///
+       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 par of the given type and the cursor's
+       //index in it
+       MathInset * enclosing(MathInsetTypes, int &) const;
+       ///
+       InsetFormulaBase const * formula();
+       ///
+       int pos() const;
+       ///
+       void Interpret(string const &);
+       ///
+       void SetSize(MathStyles);
+       ///
+       bool toggleLimits();
+       ///
+       // Macro mode methods
+       void MacroModeOpen();
+       ///
+       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 SelGetArea(int * xp, int * yp, int & n);
+       ///
+       void clearLastCode();
+       ///
+       void setLastCode(MathTextCodes t);
+       ///
+       void handleFont(MathTextCodes t);
+       ///
+       void handleAccent(string const & name, int code);
+       ///
+       void handleDelim(int l, int r);
+       /// 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;
+       ///
+       int idx() const { return cursor_.idx_; }
+       ///
+       void idxNext();
+       ///
+       void idxPrev();
+       ///
+       void pullArg();
+       ///
+       bool isInside(MathInset *) const;
+       ///
+       MathTextCodes nextCode() const;
+       ///
+       MathTextCodes prevCode() const;
+       ///
+       char valign() const;
+       ///
+       char halign() const;
+       ///
+       int col() const;
+       ///
+       int row() const;
 
+//protected:
+       ///
+       bool macro_mode;
+       
+       // Selection stuff
+       /// do we currently select
+       bool selection;
 
-#endif
+       ///
+       InsetFormulaBase * const formula_;
+       ///
+       MathTextCodes lastcode;
+
+       ///
+       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();
+
+private:
+       /// Description of a position 
+       struct MathIter {
+               /// inset
+               MathInset * par_;
+               /// cell inset
+               int idx_;
+               ///
+               int pos_;
+       };
+
+       /// path of positions the cursor had to go if it were leving each inset
+       std::vector<MathIter> path_;
+
+       /// reference to the last item of the path
+       MathIter anchor_;
+       ///
+       MathIter cursor_;
+       ///
+       int path_idx_;
+
+
+       ///  
+       int last() const;
+       ///
+       MathInset * parInset(int i) 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);
+       ///
+       MathInset * nextInset() const;
+       ///
+       MathInset * prevInset() const;
+       ///
+       MathUpDownInset * nearbyUpDownInset() const;
+
+       ///
+       MathFuncInset * imacro;
+};
+
+extern MathCursor * mathcursor;
+
+#endif