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-02-13 13:28:32 +00:00
|
|
|
class MathFuncInset;
|
2001-07-12 07:18:29 +00:00
|
|
|
class MathUpDownInset;
|
2001-06-25 00:06:33 +00:00
|
|
|
class InsetFormulaBase;
|
|
|
|
class MathArray;
|
|
|
|
class MathXArray;
|
2001-07-16 15:53:25 +00:00
|
|
|
class Painter;
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
/// moves position on cell to the left
|
|
|
|
bool idxLeft();
|
|
|
|
/// moves position on cell to the right
|
|
|
|
bool idxRight();
|
|
|
|
/// moves position on cell up
|
|
|
|
bool idxUp();
|
|
|
|
/// moves position on cell up
|
|
|
|
bool idxDown();
|
|
|
|
};
|
|
|
|
|
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(char, MathTextCodes t = LM_TC_MIN);
|
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-02-13 13:28:32 +00:00
|
|
|
void Home();
|
|
|
|
///
|
|
|
|
void End();
|
|
|
|
///
|
|
|
|
bool Right(bool sel = false);
|
|
|
|
///
|
|
|
|
bool Left(bool sel = false);
|
|
|
|
///
|
|
|
|
bool Up(bool sel = false);
|
|
|
|
///
|
|
|
|
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-02-13 13:28:32 +00:00
|
|
|
///
|
2001-07-13 14:54:56 +00:00
|
|
|
bool plainLeft();
|
|
|
|
///
|
2001-06-27 14:10:35 +00:00
|
|
|
bool plainRight();
|
|
|
|
///
|
2001-02-13 13:28:32 +00:00
|
|
|
void Delete();
|
|
|
|
///
|
|
|
|
void DelLine();
|
2001-06-25 00:06:33 +00:00
|
|
|
/// This is in pixels from (maybe?) the top of inset
|
2001-02-13 13:28:32 +00:00
|
|
|
void SetPos(int, int);
|
|
|
|
///
|
2001-02-13 19:10:18 +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;
|
|
|
|
/// return the next enclosing par of the given type and the cursor's
|
|
|
|
//index in it
|
|
|
|
MathInset * enclosing(MathInsetTypes, 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-06-25 00:06:33 +00:00
|
|
|
int pos() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
|
|
|
void Interpret(string const &);
|
|
|
|
///
|
2001-06-25 00:06:33 +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
|
|
|
|
void MacroModeOpen();
|
|
|
|
///
|
|
|
|
void MacroModeClose();
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
bool InMacroMode() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
// Local selection methods
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
bool Selection() const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
|
|
|
void SelCopy();
|
|
|
|
///
|
|
|
|
void SelCut();
|
|
|
|
///
|
|
|
|
void SelDel();
|
|
|
|
///
|
|
|
|
void SelPaste();
|
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
void SelHandle(bool);
|
|
|
|
///
|
2001-02-13 13:28:32 +00:00
|
|
|
void SelStart();
|
|
|
|
///
|
|
|
|
void SelClear();
|
|
|
|
///
|
2001-07-16 15:53:25 +00:00
|
|
|
void drawSelection(Painter & pain) const;
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-02-13 19:10:18 +00:00
|
|
|
void clearLastCode();
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
void setLastCode(MathTextCodes t);
|
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-07-13 07:55:55 +00:00
|
|
|
void handleAccent(string const & name, int code);
|
2001-07-10 13:17:43 +00:00
|
|
|
///
|
|
|
|
void handleDelim(int l, int r);
|
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-16 15:53:25 +00:00
|
|
|
int idx() const { return cursor().idx_; }
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-07-06 12:09:32 +00:00
|
|
|
void idxNext();
|
|
|
|
///
|
|
|
|
void idxPrev();
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2001-07-23 14:15:14 +00:00
|
|
|
void pullArg(bool goright);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
|
|
|
bool isInside(MathInset *) const;
|
|
|
|
///
|
|
|
|
MathTextCodes nextCode() const;
|
|
|
|
///
|
|
|
|
MathTextCodes prevCode() const;
|
|
|
|
///
|
2001-06-27 14:10:35 +00:00
|
|
|
char valign() const;
|
|
|
|
///
|
|
|
|
char halign() const;
|
|
|
|
///
|
|
|
|
int col() const;
|
|
|
|
///
|
|
|
|
int row() const;
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
///
|
|
|
|
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:
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
|
|
|
bool macro_mode;
|
|
|
|
|
|
|
|
// Selection stuff
|
2001-07-13 16:06:10 +00:00
|
|
|
/// do we currently select
|
2001-02-13 13:28:32 +00:00
|
|
|
bool selection;
|
2001-07-13 16:06:10 +00:00
|
|
|
|
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-06-25 00:06:33 +00:00
|
|
|
MathTextCodes lastcode;
|
|
|
|
|
|
|
|
///
|
|
|
|
MathArray & array() const;
|
|
|
|
///
|
|
|
|
MathXArray & xarray() const;
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
/// returns the first position of the (normalized) selection
|
|
|
|
MathCursorPos firstSelectionPos() const;
|
|
|
|
/// returns the last position of the (normalized) selection
|
|
|
|
MathCursorPos lastSelectionPos() const;
|
|
|
|
/// returns the selection
|
|
|
|
void getSelection(MathCursorPos &, MathCursorPos &) const;
|
|
|
|
/// returns the normalized anchor of the selection
|
|
|
|
MathCursorPos normalAnchor() const;
|
|
|
|
/// returns the normalized anchor of the selection
|
|
|
|
bool openable(MathInset *, bool selection, bool useupdown) 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
|
|
|
///
|
|
|
|
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;
|
|
|
|
///
|
2001-07-24 16:10:17 +00:00
|
|
|
MathUpDownInset * prevUpDownInset() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
///
|
|
|
|
MathFuncInset * imacro;
|
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
|