1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_cursor.h
|
|
|
|
* Purpose: Declaration of interaction classes for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: MathCursor control all user interaction
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib, XForms
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
#ifndef MATH_CURSOR
|
|
|
|
#define MATH_CURSOR
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_defs.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
class MathInset;
|
2001-09-11 10:58:17 +00:00
|
|
|
class MathAtom;
|
2001-08-06 17:20:26 +00:00
|
|
|
class MathArrayInset;
|
2001-02-13 13:28:32 +00:00
|
|
|
class MathFuncInset;
|
2001-08-06 17:20:26 +00:00
|
|
|
class MathMatrixInset;
|
2001-07-26 06:46:50 +00:00
|
|
|
class MathScriptInset;
|
2001-07-25 14:15:05 +00:00
|
|
|
class MathSpaceInset;
|
2001-06-25 00:06:33 +00:00
|
|
|
class InsetFormulaBase;
|
|
|
|
class MathArray;
|
|
|
|
class MathXArray;
|
2001-07-16 15:53:25 +00:00
|
|
|
class Painter;
|
2001-08-09 15:19:31 +00:00
|
|
|
class latexkeys;
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
/// Description of a position
|
|
|
|
struct MathCursorPos {
|
|
|
|
/// inset
|
|
|
|
MathInset * par_;
|
|
|
|
/// cell index
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int idx_;
|
2001-07-16 15:53:25 +00:00
|
|
|
/// cell position
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int pos_;
|
2001-07-16 15:53:25 +00:00
|
|
|
/// returns cell corresponding to this position
|
|
|
|
MathArray & cell() const;
|
|
|
|
/// returns cell corresponding to this position
|
2001-09-26 15:20:45 +00:00
|
|
|
MathArray & cell(unsigned int idx) const;
|
2001-07-16 15:53:25 +00:00
|
|
|
/// returns xcell corresponding to this position
|
|
|
|
MathXArray & xcell() const;
|
|
|
|
/// returns xcell corresponding to this position
|
2001-09-26 15:20:45 +00:00
|
|
|
MathXArray & xcell(unsigned int idx) const;
|
2001-07-16 15:53:25 +00:00
|
|
|
};
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
///
|
|
|
|
bool operator==(MathCursorPos const &, MathCursorPos const &);
|
|
|
|
///
|
|
|
|
bool operator<(MathCursorPos const &, MathCursorPos const &);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/// This is the external interface of Math's subkernel
|
|
|
|
class MathCursor {
|
2001-02-13 13:28:32 +00:00
|
|
|
public:
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
explicit MathCursor(InsetFormulaBase *);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
void insert(MathInset *);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-16 15:53:25 +00:00
|
|
|
void insert(MathArray const &);
|
|
|
|
///
|
2001-07-26 06:46:50 +00:00
|
|
|
void erase();
|
|
|
|
///
|
2001-08-07 15:04:57 +00:00
|
|
|
void backspace();
|
|
|
|
///
|
2001-08-30 10:17:28 +00:00
|
|
|
void home(bool sel = false);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-08-30 10:17:28 +00:00
|
|
|
void end(bool sel = false);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool right(bool sel = false);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool left(bool sel = false);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool up(bool sel = false);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool down(bool sel = false);
|
2001-06-25 00:06:33 +00:00
|
|
|
/// Put the cursor in the first position
|
|
|
|
void first();
|
|
|
|
/// Put the cursor in the last position
|
|
|
|
void last();
|
2001-08-08 11:03:53 +00:00
|
|
|
/// moves cursor position one cell to the left
|
2001-08-08 07:46:16 +00:00
|
|
|
bool posLeft();
|
2001-08-08 11:03:53 +00:00
|
|
|
/// moves cursor position one cell to the right
|
2001-08-08 07:46:16 +00:00
|
|
|
bool posRight();
|
2001-08-08 11:03:53 +00:00
|
|
|
/// moves cursor index one cell to the left
|
2001-08-08 07:46:16 +00:00
|
|
|
bool idxLeft();
|
2001-08-08 11:03:53 +00:00
|
|
|
/// moves cursor index one cell to the right
|
2001-08-08 07:46:16 +00:00
|
|
|
bool idxRight();
|
2001-08-08 11:03:53 +00:00
|
|
|
/// moves position somehow up
|
|
|
|
bool goUp();
|
|
|
|
/// moves position somehow down
|
|
|
|
bool goDown();
|
2001-08-08 07:46:16 +00:00
|
|
|
///
|
|
|
|
void idxNext();
|
2001-07-13 14:54:56 +00:00
|
|
|
///
|
2001-08-08 07:46:16 +00:00
|
|
|
void idxPrev();
|
2001-06-27 14:10:35 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void plainErase();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 10:21:18 +00:00
|
|
|
void plainInsert(MathInset * p);
|
|
|
|
///
|
2001-08-13 14:02:37 +00:00
|
|
|
void niceInsert(MathInset * p);
|
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void delLine();
|
2001-06-25 00:06:33 +00:00
|
|
|
/// This is in pixels from (maybe?) the top of inset
|
2001-07-26 09:01:36 +00:00
|
|
|
void setPos(int, int);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void getPos(int & x, int & y);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * par() const;
|
2001-08-01 13:28:45 +00:00
|
|
|
/// return the next enclosing grid inset and the cursor's index in it
|
2001-09-26 15:20:45 +00:00
|
|
|
MathArrayInset * enclosingArray(unsigned int &) const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
InsetFormulaBase const * formula();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int pos() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int idx() const;
|
2001-08-07 15:04:57 +00:00
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int size() const;
|
2001-08-08 07:46:16 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void interpret(string const &);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void setSize(MathStyles);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
bool toggleLimits();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
|
|
|
// Macro mode methods
|
2001-07-26 09:01:36 +00:00
|
|
|
void macroModeClose();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool inMacroMode() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
// Local selection methods
|
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
bool selection() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selCopy();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selCut();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selDel();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selPaste();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selHandle(bool);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selStart();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-26 09:01:36 +00:00
|
|
|
void selClear();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-16 15:53:25 +00:00
|
|
|
void drawSelection(Painter & pain) const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-03 07:56:55 +00:00
|
|
|
void handleFont(MathTextCodes t);
|
2001-07-10 13:17:43 +00:00
|
|
|
///
|
2001-09-12 12:51:55 +00:00
|
|
|
void handleDelim(string const & l, string const & r);
|
2001-08-08 07:46:16 +00:00
|
|
|
///
|
|
|
|
void handleNest(MathInset * p);
|
2001-07-06 12:09:32 +00:00
|
|
|
/// Splits cells and shifts right part to the next cell
|
|
|
|
void splitCell();
|
|
|
|
/// Splits line and insert new row of cell
|
|
|
|
void breakLine();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
MathTextCodes getLastCode() const;
|
|
|
|
///
|
2001-07-23 14:15:14 +00:00
|
|
|
void pullArg(bool goright);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-08-06 17:20:26 +00:00
|
|
|
bool isInside(MathInset const *) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
|
|
|
MathTextCodes nextCode() const;
|
|
|
|
///
|
2001-06-27 14:10:35 +00:00
|
|
|
char valign() const;
|
|
|
|
///
|
|
|
|
char halign() const;
|
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int col() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int row() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
///
|
|
|
|
MathStyles style() const;
|
|
|
|
/// Make sure cursor position is valid
|
|
|
|
void normalize() const;
|
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
/// 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();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
MathArray & array() const;
|
|
|
|
///
|
|
|
|
MathXArray & xarray() const;
|
2001-09-11 10:58:17 +00:00
|
|
|
///
|
|
|
|
MathAtom const * prevAtom() const;
|
|
|
|
///
|
|
|
|
MathAtom * prevAtom();
|
|
|
|
///
|
|
|
|
MathAtom const * nextAtom() const;
|
|
|
|
///
|
|
|
|
MathAtom * nextAtom();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
/// returns the selection
|
|
|
|
void getSelection(MathCursorPos &, MathCursorPos &) const;
|
|
|
|
/// returns the normalized anchor of the selection
|
|
|
|
MathCursorPos normalAnchor() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-13 16:06:10 +00:00
|
|
|
/// path of positions the cursor had to go if it were leving each inset
|
2001-07-16 15:53:25 +00:00
|
|
|
std::vector<MathCursorPos> Cursor_;
|
|
|
|
/// path of positions the anchor had to go if it were leving each inset
|
|
|
|
std::vector<MathCursorPos> Anchor_;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-13 16:06:10 +00:00
|
|
|
/// reference to the last item of the path
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos & cursor();
|
2001-07-13 16:06:10 +00:00
|
|
|
///
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos const & cursor() const;
|
2001-07-13 16:06:10 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int last() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
|
|
|
MathInset * parInset(int i) const;
|
|
|
|
///
|
2001-08-06 17:20:26 +00:00
|
|
|
MathMatrixInset * outerPar() const;
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
void seldump(char const * str) const;
|
|
|
|
///
|
|
|
|
void dump(char const * str) const;
|
|
|
|
|
|
|
|
///
|
|
|
|
void merge(MathArray const & arr);
|
|
|
|
///
|
|
|
|
MathInset * nextInset() const;
|
|
|
|
///
|
|
|
|
MathInset * prevInset() const;
|
|
|
|
///
|
2001-07-26 06:46:50 +00:00
|
|
|
MathScriptInset * prevScriptInset() const;
|
2001-07-25 14:15:05 +00:00
|
|
|
///
|
|
|
|
MathSpaceInset * prevSpaceInset() const;
|
2001-08-07 15:04:57 +00:00
|
|
|
private:
|
2001-08-14 11:19:19 +00:00
|
|
|
///
|
|
|
|
string macroName() const;
|
|
|
|
///
|
|
|
|
void insert(char, MathTextCodes t = LM_TC_MIN);
|
2001-08-20 13:45:02 +00:00
|
|
|
/// can we enter the inset?
|
|
|
|
bool openable(MathInset *, bool selection) const;
|
|
|
|
/// can the setPos routine enter that inset?
|
2001-09-11 12:46:58 +00:00
|
|
|
MathInset * positionable(MathAtom *, int x, int y) const;
|
2001-08-20 13:45:02 +00:00
|
|
|
/// write access to cursor cell position
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int & pos();
|
2001-08-20 13:45:02 +00:00
|
|
|
/// write access to cursor cell index
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int & idx();
|
2001-08-08 09:31:36 +00:00
|
|
|
/// x-offset of current cell relative to par xo
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int cellXOffset() const;
|
2001-08-08 09:31:36 +00:00
|
|
|
/// y-offset of current cell relative to par yo
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int cellYOffset() const;
|
2001-08-08 09:31:36 +00:00
|
|
|
/// 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);
|
2001-08-08 07:12:09 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
InsetFormulaBase * const formula_;
|
|
|
|
///
|
|
|
|
MathTextCodes lastcode_;
|
|
|
|
// Selection stuff
|
|
|
|
/// do we currently select
|
|
|
|
bool selection_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
extern MathCursor * mathcursor;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|