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-09-26 16:52:34 +00:00
|
|
|
#include "math_inset.h"
|
2001-10-18 13:21:21 +00:00
|
|
|
#include "LString.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-11-08 12:28:33 +00:00
|
|
|
class MathHullInset;
|
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-10-12 12:02:49 +00:00
|
|
|
class Selection;
|
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
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom * par_;
|
2001-07-16 15:53:25 +00:00
|
|
|
/// cell index
|
2001-09-26 16:52:34 +00:00
|
|
|
MathInset::idx_type idx_;
|
2001-07-16 15:53:25 +00:00
|
|
|
/// cell position
|
2001-09-26 16:52:34 +00:00
|
|
|
MathInset::pos_type pos_;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
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 16:52:34 +00:00
|
|
|
MathArray & cell(MathInset::idx_type 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 16:52:34 +00:00
|
|
|
MathXArray & xcell(MathInset::idx_type 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-09-26 16:52:34 +00:00
|
|
|
/// 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;
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
explicit MathCursor(InsetFormulaBase *, bool left);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
void insert(MathAtom const &);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-16 15:53:25 +00:00
|
|
|
void insert(MathArray const &);
|
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
void paste(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 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-10-12 12:02:49 +00:00
|
|
|
void plainInsert(MathAtom const &);
|
2001-07-26 10:21:18 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
void niceInsert(MathAtom const &);
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
///
|
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-10-12 12:02:49 +00:00
|
|
|
MathAtom & 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 16:52:34 +00:00
|
|
|
MathArrayInset * enclosingArray(idx_type &) 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 16:52:34 +00:00
|
|
|
pos_type pos() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
idx_type idx() const;
|
2001-08-07 15:04:57 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
size_type size() const;
|
2001-08-08 07:46:16 +00:00
|
|
|
///
|
2001-11-13 08:03:52 +00:00
|
|
|
bool interpret(string const &);
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-11-13 08:03:52 +00:00
|
|
|
bool interpret(char);
|
2001-10-10 16:35:18 +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-10-23 13:48:52 +00:00
|
|
|
void selGet(MathArray & ar);
|
|
|
|
///
|
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-11-12 16:45:09 +00:00
|
|
|
/// read contents of line into an array
|
|
|
|
void readLine(MathArray & ar) const;
|
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-11-12 16:45:09 +00:00
|
|
|
col_type ncols() const;
|
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
col_type col() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
///
|
2001-09-26 16:52:34 +00:00
|
|
|
row_type row() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
/// Make sure cursor position is valid
|
|
|
|
void normalize() const;
|
2001-10-24 19:09:31 +00:00
|
|
|
///
|
|
|
|
UpdatableInset * asHyperActiveInset() const;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
/// enter a MathInset
|
|
|
|
void push(MathAtom & par);
|
2001-08-08 07:12:09 +00:00
|
|
|
/// enter a MathInset from the front
|
2001-10-12 12:02:49 +00:00
|
|
|
void pushLeft(MathAtom & par);
|
2001-08-08 07:12:09 +00:00
|
|
|
/// enter a MathInset from the back
|
2001-10-12 12:02:49 +00:00
|
|
|
void pushRight(MathAtom & par);
|
2001-08-08 07:12:09 +00:00
|
|
|
/// 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
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
bool hasPrevAtom() const;
|
|
|
|
///
|
|
|
|
bool hasNextAtom() const;
|
|
|
|
///
|
|
|
|
MathAtom const & prevAtom() const;
|
2001-09-11 10:58:17 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & prevAtom();
|
2001-09-11 10:58:17 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & nextAtom() const;
|
2001-09-11 10:58:17 +00:00
|
|
|
///
|
2001-10-12 12:02:49 +00:00
|
|
|
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
|
|
|
///
|
|
|
|
void seldump(char const * str) const;
|
|
|
|
///
|
|
|
|
void dump(char const * str) const;
|
2001-11-07 11:14:59 +00:00
|
|
|
///
|
|
|
|
void stripFromLastEqualSign();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
///
|
|
|
|
friend class Selection;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
private:
|
2001-10-10 13:20:51 +00:00
|
|
|
/// 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();
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
///
|
|
|
|
string macroName() const;
|
|
|
|
///
|
2001-10-10 16:35:18 +00:00
|
|
|
int macroNamePos() const;
|
|
|
|
///
|
2001-10-10 13:20:51 +00:00
|
|
|
void insert(char, MathTextCodes t);
|
2001-08-20 13:45:02 +00:00
|
|
|
/// can we enter the inset?
|
2001-10-12 12:02:49 +00:00
|
|
|
bool openable(MathAtom const &, bool selection) const;
|
2001-08-20 13:45:02 +00:00
|
|
|
/// can the setPos routine enter that inset?
|
2001-10-12 12:02:49 +00:00
|
|
|
bool positionable(MathAtom const &, int x, int y) const;
|
2001-08-20 13:45:02 +00:00
|
|
|
/// write access to cursor cell position
|
2001-09-26 16:52:34 +00:00
|
|
|
pos_type & pos();
|
2001-08-20 13:45:02 +00:00
|
|
|
/// write access to cursor cell index
|
2001-09-26 16:52:34 +00:00
|
|
|
idx_type & idx();
|
2001-08-08 09:31:36 +00:00
|
|
|
/// x-offset of current cell relative to par xo
|
2001-10-01 12:10:32 +00:00
|
|
|
int cellXOffset() const;
|
2001-08-08 09:31:36 +00:00
|
|
|
/// y-offset of current cell relative to par yo
|
2001-10-01 12:10:32 +00:00
|
|
|
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
|