1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_cursor.h
|
|
|
|
* Purpose: Declaration of interaction classes for mathed
|
2002-03-21 17:42:56 +00:00
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
1999-09-27 18:44:28 +00:00
|
|
|
* 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-09-26 16:52:34 +00:00
|
|
|
#include "math_inset.h"
|
2002-07-26 14:11:19 +00:00
|
|
|
#include "math_iterator.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 InsetFormulaBase;
|
2002-07-25 13:34:13 +00:00
|
|
|
class BufferView;
|
2002-05-30 07:09:54 +00:00
|
|
|
class MathPainterInfo;
|
|
|
|
class MathUnknownInset;
|
2001-10-12 12:02:49 +00:00
|
|
|
class Selection;
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
/**
|
|
|
|
|
|
|
|
[Have a look at math_inset.h first]
|
|
|
|
|
|
|
|
The MathCursor is different from the kind of cursor used in the Outer
|
2002-07-26 14:11:19 +00:00
|
|
|
World. It contains a stack of MathCursorPos, each of which is made
|
2001-12-03 16:24:50 +00:00
|
|
|
up of a inset pointer, an index and a position offset, marking a path from
|
2002-07-26 14:11:19 +00:00
|
|
|
this formula's MathHullInset to the current position.
|
2001-12-03 16:24:50 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
class MathCursor {
|
2001-02-13 13:28:32 +00:00
|
|
|
public:
|
2001-09-26 16:52:34 +00:00
|
|
|
/// short of anything else reasonable
|
2001-11-30 14:40:38 +00:00
|
|
|
typedef MathInset::size_type size_type;
|
2001-09-26 16:52:34 +00:00
|
|
|
/// type for cursor positions within a cell
|
2001-11-30 14:40:38 +00:00
|
|
|
typedef MathInset::pos_type pos_type;
|
2001-09-26 16:52:34 +00:00
|
|
|
/// type for cell indices
|
2001-11-30 14:40:38 +00:00
|
|
|
typedef MathInset::idx_type idx_type;
|
2001-09-26 16:52:34 +00:00
|
|
|
/// type for row numbers
|
2001-11-30 14:40:38 +00:00
|
|
|
typedef MathInset::row_type row_type;
|
2001-09-26 16:52:34 +00:00
|
|
|
/// type for column numbers
|
2001-11-30 14:40:38 +00:00
|
|
|
typedef MathInset::col_type col_type;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
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
|
|
|
///
|
2002-06-27 18:12:50 +00:00
|
|
|
~MathCursor();
|
|
|
|
///
|
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 &);
|
|
|
|
///
|
2002-06-18 15:44:30 +00:00
|
|
|
void paste(MathGridInset const & data);
|
|
|
|
///
|
2001-07-26 06:46:50 +00:00
|
|
|
void erase();
|
|
|
|
///
|
2001-08-07 15:04:57 +00:00
|
|
|
void backspace();
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_HOME etc
|
2002-07-18 10:07:20 +00:00
|
|
|
bool home(bool sel = false);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_END etc
|
2002-07-18 10:07:20 +00:00
|
|
|
bool end(bool sel = false);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_RIGHT and LFUN_RIGHTSEL
|
2001-07-26 09:01:36 +00:00
|
|
|
bool right(bool sel = false);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_LEFT etc
|
2001-07-26 09:01:36 +00:00
|
|
|
bool left(bool sel = false);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_UP etc
|
2001-07-26 09:01:36 +00:00
|
|
|
bool up(bool sel = false);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// called for LFUN_DOWN etc
|
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-12-03 16:24:50 +00:00
|
|
|
/// move to next cell in current inset
|
2001-08-08 07:46:16 +00:00
|
|
|
void idxNext();
|
2001-12-03 16:24:50 +00:00
|
|
|
/// move to previous cell in current inset
|
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-12-03 16:24:50 +00:00
|
|
|
/// in pixels from top of screen
|
2001-11-20 11:15:18 +00:00
|
|
|
void setPos(int x, int y);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// in pixels from top of screen
|
2001-07-26 09:01:36 +00:00
|
|
|
void getPos(int & x, int & y);
|
2001-12-11 15:35:18 +00:00
|
|
|
/// current inset
|
|
|
|
MathInset * par() const;
|
2001-08-01 13:28:45 +00:00
|
|
|
/// return the next enclosing grid inset and the cursor's index in it
|
2002-06-18 15:44:30 +00:00
|
|
|
MathGridInset * enclosingGrid(idx_type & idx) const;
|
|
|
|
/// return the next enclosing hull inset and the cursor's index in it
|
|
|
|
MathHullInset * enclosingHull(idx_type & idx) const;
|
|
|
|
/// go up to enclosing grid
|
2002-03-26 12:38:59 +00:00
|
|
|
void popToEnclosingGrid();
|
2002-06-18 15:44:30 +00:00
|
|
|
/// go up to the hull inset
|
|
|
|
void popToEnclosingHull();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2002-07-08 06:39:40 +00:00
|
|
|
InsetFormulaBase * formula() const;
|
2001-12-03 16:24:50 +00:00
|
|
|
/// current offset in the current cell
|
2001-09-26 16:52:34 +00:00
|
|
|
pos_type pos() const;
|
2001-12-03 16:24:50 +00:00
|
|
|
/// current cell
|
2001-09-26 16:52:34 +00:00
|
|
|
idx_type idx() const;
|
2001-12-03 16:24:50 +00:00
|
|
|
/// size of current cell
|
2001-09-26 16:52:34 +00:00
|
|
|
size_type size() const;
|
2001-08-08 07:46:16 +00:00
|
|
|
///
|
2001-12-12 14:37:59 +00:00
|
|
|
bool script(bool);
|
|
|
|
///
|
2001-11-13 08:03:52 +00:00
|
|
|
bool interpret(string const &);
|
2002-06-13 18:07:40 +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-12-03 16:24:50 +00:00
|
|
|
/// interpret name a name of a macro
|
2001-07-26 09:01:36 +00:00
|
|
|
void macroModeClose();
|
2002-01-11 10:26:13 +00:00
|
|
|
/// are we currently typing the name of a macro?
|
2002-05-30 07:09:54 +00:00
|
|
|
MathUnknownInset * inMacroMode() const;
|
2002-01-11 10:26:13 +00:00
|
|
|
/// are we currently typing '#1' or '#2' or...?
|
|
|
|
bool inMacroArgMode() const;
|
2002-07-18 11:02:33 +00:00
|
|
|
/// are we in math mode (1), text mode (-1) or unsure?
|
|
|
|
MathInset::mode_type currentMode() const;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
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();
|
2002-05-14 09:15:40 +00:00
|
|
|
/// clears or deletes selection depending on lyxrc setting
|
|
|
|
void selClearOrDel();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-10-23 13:48:52 +00:00
|
|
|
void selGet(MathArray & ar);
|
|
|
|
///
|
2002-05-30 07:09:54 +00:00
|
|
|
void drawSelection(MathPainterInfo & pain) const;
|
2001-07-10 13:17:43 +00:00
|
|
|
///
|
2002-07-17 10:25:33 +00:00
|
|
|
void handleNest(MathAtom const & at);
|
2001-12-03 16:24:50 +00:00
|
|
|
/// splits cells and shifts right part to the next cell
|
2001-07-06 12:09:32 +00:00
|
|
|
void splitCell();
|
2002-03-21 17:42:56 +00:00
|
|
|
/// splits line and insert new row of cell
|
2001-07-06 12:09:32 +00:00
|
|
|
void breakLine();
|
2001-11-12 16:45:09 +00:00
|
|
|
/// read contents of line into an array
|
|
|
|
void readLine(MathArray & ar) const;
|
2002-01-03 12:50:00 +00:00
|
|
|
/// remove this as soon as LyXFunc::getStatus is "localized"
|
2002-05-30 07:09:54 +00:00
|
|
|
string getLastCode() const { return "mathnormal"; }
|
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
|
|
|
///
|
2001-06-27 14:10:35 +00:00
|
|
|
char valign() const;
|
|
|
|
///
|
|
|
|
char halign() const;
|
|
|
|
///
|
2001-12-11 15:04:02 +00:00
|
|
|
col_type hullCol() const;
|
2001-11-12 16:45:09 +00:00
|
|
|
///
|
2001-12-11 15:04:02 +00:00
|
|
|
row_type hullRow() const;
|
2001-12-15 16:13:11 +00:00
|
|
|
///
|
|
|
|
col_type gridCol() const;
|
|
|
|
///
|
|
|
|
row_type gridRow() const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
/// make sure cursor position is valid
|
2001-12-18 12:21:33 +00:00
|
|
|
void normalize();
|
2002-03-21 17:42:56 +00:00
|
|
|
/// mark current cursor trace for redraw
|
2002-03-12 14:59:08 +00:00
|
|
|
void touch();
|
2001-10-24 19:09:31 +00:00
|
|
|
///
|
|
|
|
UpdatableInset * asHyperActiveInset() const;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
/// enter a MathInset
|
2001-10-12 12:02:49 +00:00
|
|
|
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;
|
|
|
|
///
|
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-12-03 16:24:50 +00:00
|
|
|
/// reference to the last item of the path, i.e. "The Cursor"
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos & cursor();
|
2001-12-03 16:24:50 +00:00
|
|
|
/// reference to the last item of the path, i.e. "The Cursor"
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos const & cursor() const;
|
2002-06-18 15:44:30 +00:00
|
|
|
/// how deep are we nested?
|
|
|
|
unsigned depth() const;
|
2001-07-13 16:06:10 +00:00
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
/// local dispatcher
|
|
|
|
int dispatch(string const & cmd);
|
2002-01-16 14:24:38 +00:00
|
|
|
/// describe the situation
|
|
|
|
string info() const;
|
2001-12-03 16:24:50 +00:00
|
|
|
/// dump selection information for debugging
|
2001-06-25 00:06:33 +00:00
|
|
|
void seldump(char const * str) const;
|
2001-12-03 16:24:50 +00:00
|
|
|
/// dump selection information for debugging
|
2001-06-25 00:06:33 +00:00
|
|
|
void dump(char const * str) const;
|
2002-03-21 17:42:56 +00:00
|
|
|
/// moves on
|
2002-07-26 14:11:19 +00:00
|
|
|
void setSelection(MathIterator const & where, size_type n);
|
2002-02-01 14:56:49 +00:00
|
|
|
///
|
2002-06-24 15:37:14 +00:00
|
|
|
void insert(char c);
|
|
|
|
///
|
|
|
|
void insert(string const & str);
|
2002-05-30 07:09:54 +00:00
|
|
|
/// lock/unlock inset
|
|
|
|
void insetToggle();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
/// hack for reveal codes
|
|
|
|
void markInsert();
|
|
|
|
void markErase();
|
2002-06-18 15:44:30 +00:00
|
|
|
void handleExtern(string const & arg);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
///
|
|
|
|
friend class Selection;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
private:
|
2002-07-26 07:39:13 +00:00
|
|
|
/// injects content of a cell into parent
|
|
|
|
void pullArg();
|
2001-10-10 13:20:51 +00:00
|
|
|
/// moves cursor index one cell to the left
|
|
|
|
bool idxLeft();
|
|
|
|
/// moves cursor index one cell to the right
|
|
|
|
bool idxRight();
|
2002-06-18 15:44:30 +00:00
|
|
|
/// moves cursor to beginning first cell of current line
|
|
|
|
bool idxLineFirst();
|
|
|
|
/// moves cursor to end of last cell of current line
|
|
|
|
bool idxLineLast();
|
|
|
|
/// moves cursor position one cell to the left
|
|
|
|
bool posLeft();
|
|
|
|
/// moves cursor position one cell to the right
|
|
|
|
bool posRight();
|
2001-12-11 18:51:47 +00:00
|
|
|
/// moves position somehow up or down
|
|
|
|
bool goUpDown(bool up);
|
2001-12-05 17:50:18 +00:00
|
|
|
/// moves position into box
|
2001-12-11 18:51:47 +00:00
|
|
|
bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
|
2002-07-30 13:56:02 +00:00
|
|
|
/// are we in a nucleus of a script inset?
|
|
|
|
bool inNucleus() const;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
/// grab grid marked by anchor and current cursor
|
|
|
|
MathGridInset grabSelection() const;
|
|
|
|
/// erase the selected part and re-sets the cursor
|
|
|
|
void eraseSelection();
|
|
|
|
/// guess what
|
|
|
|
MathGridInset grabAndEraseSelection();
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
///
|
|
|
|
string macroName() const;
|
|
|
|
///
|
2002-01-08 15:13:31 +00:00
|
|
|
MathInset::difference_type macroNamePos() const;
|
2002-03-21 17:42:56 +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
|
|
|
/// 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 07:12:09 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
/// path of positions the cursor had to go if it were leaving each inset
|
2002-07-26 14:11:19 +00:00
|
|
|
MathIterator Cursor_;
|
2002-06-18 15:44:30 +00:00
|
|
|
/// path of positions the anchor had to go if it were leaving each inset
|
2002-07-26 14:11:19 +00:00
|
|
|
mutable MathIterator Anchor_;
|
2002-03-12 14:59:08 +00:00
|
|
|
/// pointer to enclsing LyX inset
|
2001-12-10 10:09:00 +00:00
|
|
|
InsetFormulaBase * formula_;
|
2002-05-30 07:09:54 +00:00
|
|
|
// Selection stuff
|
2002-03-12 14:59:08 +00:00
|
|
|
/// text code of last char entered
|
2002-05-30 07:09:54 +00:00
|
|
|
//MathTextCodes lastcode_;
|
2002-05-24 08:29:16 +00:00
|
|
|
/// do we allow autocorrection
|
|
|
|
bool autocorrect_;
|
2001-08-08 07:12:09 +00:00
|
|
|
/// do we currently select
|
|
|
|
bool selection_;
|
2002-05-30 07:09:54 +00:00
|
|
|
/// are we entering a macro name?
|
|
|
|
bool macromode_;
|
2002-06-13 18:07:40 +00:00
|
|
|
/// are we targeting a certain x coordinate, if so, which one?
|
|
|
|
int targetx_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
extern MathCursor * mathcursor;
|
2002-07-25 13:34:13 +00:00
|
|
|
void releaseMathCursor(BufferView * bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|