2003-09-17 16:44:51 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/**
|
|
|
|
|
* \file cursor.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef CURSOR_H
|
|
|
|
|
#define CURSOR_H
|
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2004-03-01 17:12:09 +00:00
|
|
|
|
#include "dociterator.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
2003-11-10 09:40:14 +00:00
|
|
|
|
#include <iosfwd>
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
class BufferView;
|
2004-02-20 17:19:53 +00:00
|
|
|
|
class FuncStatus;
|
2003-09-18 11:21:53 +00:00
|
|
|
|
class FuncRequest;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// these should go
|
|
|
|
|
class MathUnknownInset;
|
|
|
|
|
class MathGridInset;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
class Encoding;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-02-04 12:24:01 +00:00
|
|
|
|
|
2004-03-08 21:14:45 +00:00
|
|
|
|
/// The cursor class describes the position of a cursor within a document.
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// The public inheritance should go in favour of a suitable data member
|
|
|
|
|
// (or maybe private inheritance) at some point of time.
|
2004-03-31 19:11:56 +00:00
|
|
|
|
class LCursor : public DocIterator {
|
2003-09-17 16:44:51 +00:00
|
|
|
|
public:
|
2004-01-16 12:36:23 +00:00
|
|
|
|
/// create the cursor of a BufferView
|
2004-01-16 10:55:19 +00:00
|
|
|
|
explicit LCursor(BufferView & bv);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2003-11-06 10:30:43 +00:00
|
|
|
|
/// dispatch from innermost inset upwards
|
2003-09-18 11:21:53 +00:00
|
|
|
|
DispatchResult dispatch(FuncRequest const & cmd);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
/// are we willing to handle this event?
|
|
|
|
|
bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// add a new cursor slice
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void push(InsetBase & inset);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// add a new cursor slice, place cursor on left end
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void pushLeft(InsetBase & inset);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
/// pop one level off the cursor
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void pop();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// pop one slice off the cursor stack and go left
|
|
|
|
|
bool popLeft();
|
|
|
|
|
/// pop one slice off the cursor stack and go right
|
|
|
|
|
bool popRight();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// sets cursor part
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void setCursor(DocIterator const & it, bool sel);
|
2004-01-16 12:36:23 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
//
|
|
|
|
|
// selection
|
|
|
|
|
//
|
|
|
|
|
/// selection active?
|
|
|
|
|
bool selection() const { return selection_; }
|
|
|
|
|
/// selection active?
|
|
|
|
|
bool & selection() { return selection_; }
|
|
|
|
|
/// did we place the anchor?
|
|
|
|
|
bool mark() const { return mark_; }
|
|
|
|
|
/// did we place the anchor?
|
|
|
|
|
bool & mark() { return mark_; }
|
|
|
|
|
///
|
|
|
|
|
void setSelection();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// set selection at given position
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void setSelection(DocIterator const & where, size_t n);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
|
|
|
|
void clearSelection();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// access start of selection
|
|
|
|
|
CursorSlice const & selBegin() const;
|
|
|
|
|
/// access end of selection
|
|
|
|
|
CursorSlice const & selEnd() const;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
/// access start of selection
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator selectionBegin() const;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
/// access start of selection
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator selectionEnd() const;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
2004-01-26 10:13:15 +00:00
|
|
|
|
std::string grabSelection();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void eraseSelection();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
2004-01-26 10:13:15 +00:00
|
|
|
|
std::string grabAndEraseSelection();
|
|
|
|
|
// other selection methods
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void selCopy();
|
|
|
|
|
///
|
|
|
|
|
void selCut();
|
|
|
|
|
///
|
|
|
|
|
void selDel();
|
|
|
|
|
/// pastes n-th element of cut buffer
|
|
|
|
|
void selPaste(size_t n);
|
|
|
|
|
///
|
|
|
|
|
void selHandle(bool selecting);
|
|
|
|
|
/// start selection
|
|
|
|
|
void selStart();
|
|
|
|
|
/// clear selection
|
|
|
|
|
void selClear();
|
|
|
|
|
/// clears or deletes selection depending on lyxrc setting
|
|
|
|
|
void selClearOrDel();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//
|
|
|
|
|
std::string selectionAsString(bool label) const;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
///
|
|
|
|
|
void paste(std::string const & data);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
///
|
|
|
|
|
std::string currentState();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
|
|
|
|
/// auto-correct mode
|
|
|
|
|
bool autocorrect() const { return autocorrect_; }
|
|
|
|
|
/// auto-correct mode
|
|
|
|
|
bool & autocorrect() { return autocorrect_; }
|
|
|
|
|
/// are we entering a macro name?
|
|
|
|
|
bool macromode() const { return macromode_; }
|
|
|
|
|
/// are we entering a macro name?
|
|
|
|
|
bool & macromode() { return macromode_; }
|
2003-11-10 09:06:48 +00:00
|
|
|
|
/// returns x,y position
|
|
|
|
|
void getPos(int & x, int & y) const;
|
2003-11-13 08:50:26 +00:00
|
|
|
|
/// returns cursor dimension
|
|
|
|
|
void getDim(int & asc, int & desc) const;
|
2004-01-16 13:35:10 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// common part
|
|
|
|
|
//
|
|
|
|
|
/// move one step to the left
|
|
|
|
|
bool posLeft();
|
|
|
|
|
/// move one step to the right
|
|
|
|
|
bool posRight();
|
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
/// insert an inset
|
|
|
|
|
void insert(InsetBase *);
|
|
|
|
|
/// insert a single char
|
|
|
|
|
void insert(char c);
|
|
|
|
|
/// insert a string
|
|
|
|
|
void insert(std::string const & str);
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
/// write acess to target x position of cursor
|
|
|
|
|
int & x_target();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
/// return target x position of cursor
|
|
|
|
|
int x_target() const;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
/// clear target x position of cursor
|
|
|
|
|
void clearTargetX();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
|
|
|
|
/// access to selection anchor
|
|
|
|
|
CursorSlice & anchor();
|
|
|
|
|
/// access to selection anchor
|
|
|
|
|
CursorSlice const & anchor() const;
|
2004-01-13 18:08:13 +00:00
|
|
|
|
/// sets anchor to cursor position
|
|
|
|
|
void resetAnchor();
|
2004-01-16 12:36:23 +00:00
|
|
|
|
/// access to owning BufferView
|
2004-01-16 10:55:19 +00:00
|
|
|
|
BufferView & bv() const;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// get some interesting description of top position
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void info(std::ostream & os) const;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// are we in math mode (2), text mode (1) or unsure (0)?
|
|
|
|
|
int currentMode();
|
2004-03-19 16:36:52 +00:00
|
|
|
|
/// reset cursor bottom to the beginning of the given inset
|
|
|
|
|
// (sort of 'chroot' environment...)
|
|
|
|
|
void reset(InsetBase &);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
/// for spellchecking
|
|
|
|
|
void replaceWord(std::string const & replacestring);
|
2004-02-13 11:05:29 +00:00
|
|
|
|
/// update our view
|
|
|
|
|
void update();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
/// the event was not (yet) dispatched
|
2004-03-01 17:12:09 +00:00
|
|
|
|
void undispatched();
|
2004-03-27 12:46:30 +00:00
|
|
|
|
/// the event was already dispatched
|
|
|
|
|
void dispatched();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// don't call update() when done
|
|
|
|
|
void noUpdate();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
|
|
|
|
/// output
|
|
|
|
|
friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2003-09-17 16:44:51 +00:00
|
|
|
|
public:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
///
|
|
|
|
|
BufferView * bv_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
//private:
|
|
|
|
|
/// the anchor position
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator anchor_;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
DispatchResult disp_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2003-11-11 09:06:41 +00:00
|
|
|
|
private:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* The target x position of the cursor. This is used for when
|
|
|
|
|
* we have text like :
|
|
|
|
|
*
|
|
|
|
|
* blah blah blah blah| blah blah blah
|
|
|
|
|
* blah blah blah
|
|
|
|
|
* blah blah blah blah blah blah
|
|
|
|
|
*
|
|
|
|
|
* When we move onto row 3, we would like to be vertically aligned
|
|
|
|
|
* with where we were in row 1, despite the fact that row 2 is
|
|
|
|
|
* shorter than x()
|
|
|
|
|
*/
|
|
|
|
|
int x_target_;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
/// do we have a selection?
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool selection_;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
/// are we on the way to get one?
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool mark_;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// math specific stuff that could be promoted to "global" later
|
|
|
|
|
//
|
|
|
|
|
/// do we allow autocorrection
|
|
|
|
|
bool autocorrect_;
|
|
|
|
|
/// are we entering a macro name?
|
|
|
|
|
bool macromode_;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// The part below is the non-integrated rest of the original math
|
|
|
|
|
// cursor. This should be either generalized for texted or moved
|
|
|
|
|
// back to the math insets.
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
void insert(MathAtom const &);
|
|
|
|
|
///
|
|
|
|
|
void insert(MathArray const &);
|
|
|
|
|
/// return false for empty math insets
|
|
|
|
|
bool erase();
|
|
|
|
|
/// return false for empty math insets
|
|
|
|
|
bool backspace();
|
|
|
|
|
/// called for LFUN_UP etc
|
|
|
|
|
bool up();
|
|
|
|
|
/// called for LFUN_DOWN etc
|
|
|
|
|
bool down();
|
|
|
|
|
///
|
|
|
|
|
void plainErase();
|
|
|
|
|
///
|
|
|
|
|
void plainInsert(MathAtom const & at);
|
|
|
|
|
///
|
|
|
|
|
void niceInsert(MathAtom const & at);
|
|
|
|
|
///
|
|
|
|
|
void niceInsert(std::string const & str);
|
|
|
|
|
|
|
|
|
|
/// in pixels from top of screen
|
|
|
|
|
void setScreenPos(int x, int y);
|
|
|
|
|
/// in pixels from left of screen
|
|
|
|
|
int targetX() const;
|
|
|
|
|
/// return the next enclosing grid inset and the cursor's index in it
|
|
|
|
|
MathGridInset * enclosingGrid(idx_type & idx) const;
|
|
|
|
|
/// adjust anchor position after deletions/insertions
|
|
|
|
|
void adjust(pos_type from, int diff);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// current offset in the top cell
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// interpret name a name of a macro
|
|
|
|
|
void macroModeClose();
|
|
|
|
|
/// are we currently typing the name of a macro?
|
|
|
|
|
bool inMacroMode() const;
|
|
|
|
|
/// get access to the macro we are currently typing
|
|
|
|
|
MathUnknownInset * activeMacro();
|
|
|
|
|
/// are we currently typing '#1' or '#2' or...?
|
|
|
|
|
bool inMacroArgMode() const;
|
|
|
|
|
|
|
|
|
|
/// replace selected stuff with at, placing the former
|
|
|
|
|
// selection in given cell of atom
|
|
|
|
|
void handleNest(MathAtom const & at, int cell = 0);
|
|
|
|
|
/// remove this as soon as LyXFunc::getStatus is "localized"
|
|
|
|
|
//inline std::string getLastCode() { return "mathnormal"; }
|
|
|
|
|
///
|
|
|
|
|
bool isInside(InsetBase const *);
|
|
|
|
|
///
|
|
|
|
|
char valign();
|
|
|
|
|
///
|
|
|
|
|
char halign();
|
|
|
|
|
|
|
|
|
|
/// make sure cursor position is valid
|
|
|
|
|
void normalize();
|
|
|
|
|
/// mark current cursor trace for redraw
|
|
|
|
|
void touch();
|
|
|
|
|
|
|
|
|
|
/// returns the normalized anchor of the selection
|
|
|
|
|
CursorSlice normalAnchor();
|
|
|
|
|
|
|
|
|
|
/// hack for reveal codes
|
|
|
|
|
void markInsert();
|
|
|
|
|
void markErase();
|
|
|
|
|
/// injects content of a cell into parent
|
|
|
|
|
void pullArg();
|
|
|
|
|
/// split font inset etc
|
|
|
|
|
void handleFont(std::string const & font);
|
|
|
|
|
|
2004-02-03 11:49:05 +00:00
|
|
|
|
/// display a message
|
|
|
|
|
void message(std::string const & msg) const;
|
|
|
|
|
/// display an error message
|
|
|
|
|
void errorMessage(std::string const & msg) const;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
///
|
|
|
|
|
std::string getPossibleLabel();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// moves position somehow up or down
|
|
|
|
|
bool goUpDown(bool up);
|
|
|
|
|
|
|
|
|
|
/// the name of the macro we are currently inputting
|
|
|
|
|
std::string macroName();
|
|
|
|
|
/// where in the curent cell does the macro name start?
|
|
|
|
|
int macroNamePos();
|
|
|
|
|
/// can we enter the inset?
|
2004-02-25 12:00:53 +00:00
|
|
|
|
bool openable(MathAtom const &) const;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
///
|
|
|
|
|
Encoding const * getEncoding() const;
|
2004-03-18 16:05:32 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/// moves position closest to (x, y) in current cell
|
|
|
|
|
void bruteFind2(int x, int y);
|
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
|
bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
|
2003-09-17 16:44:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // LYXCURSOR_H
|