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>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
class Buffer;
|
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;
|
2005-01-10 09:28:06 +00:00
|
|
|
|
class LyXFont;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// these should go
|
2006-09-16 18:11:38 +00:00
|
|
|
|
class InsetMathUnknown;
|
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
|
2004-08-13 14:56:06 +00:00
|
|
|
|
void dispatch(FuncRequest const & cmd);
|
|
|
|
|
/// get the resut of the last dispatch
|
|
|
|
|
DispatchResult result() const;
|
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();
|
2005-05-06 20:00:31 +00:00
|
|
|
|
/// make sure we are outside of given inset
|
2005-05-06 18:54:36 +00:00
|
|
|
|
void leaveInset(InsetBase const & inset);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// sets cursor part
|
2004-08-14 19:55:00 +00:00
|
|
|
|
void setCursor(DocIterator const & it);
|
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
|
2006-10-21 11:29:34 +00:00
|
|
|
|
void setSelection(DocIterator const & where, int n);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
///
|
|
|
|
|
void clearSelection();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// access start of selection
|
2004-04-07 13:15:34 +00:00
|
|
|
|
CursorSlice selBegin() const;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// access end of selection
|
2004-04-07 13:15:34 +00:00
|
|
|
|
CursorSlice 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
|
|
|
|
///
|
2006-10-22 11:46:36 +00:00
|
|
|
|
bool selHandle(bool selecting);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring selectionAsString(bool label) const;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
///
|
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;
|
2006-12-19 13:39:46 +00:00
|
|
|
|
/// the row in the paragraph we're in
|
|
|
|
|
Row & textRow();
|
|
|
|
|
/// the row in the paragraph we're in
|
|
|
|
|
Row const & textRow() 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
|
2006-10-21 00:16:43 +00:00
|
|
|
|
void insert(char_type c);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
/// insert a string
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void insert(docstring const & str);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
/// in pixels from left of screen
|
|
|
|
|
int targetX() const;
|
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-11-30 01:59:49 +00:00
|
|
|
|
/// set targetX in current position
|
|
|
|
|
void setTargetX();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
/// clear target x position of cursor
|
|
|
|
|
void clearTargetX();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-04-07 13:15:34 +00:00
|
|
|
|
/// access to normalized selection anchor
|
|
|
|
|
CursorSlice anchor() const;
|
2004-01-13 18:08:13 +00:00
|
|
|
|
/// sets anchor to cursor position
|
2004-04-03 08:37:12 +00:00
|
|
|
|
void resetAnchor();
|
2004-01-16 12:36:23 +00:00
|
|
|
|
/// access to owning BufferView
|
2004-04-03 08:37:12 +00:00
|
|
|
|
BufferView & bv() const;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
/// access to owning Buffer
|
|
|
|
|
Buffer & buffer() const;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// get some interesting description of top position
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void info(odocstream & 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);
|
2005-05-09 17:29:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* the event was not (yet) dispatched.
|
|
|
|
|
*
|
|
|
|
|
* Should only be called by an inset's doDispatch() method. It means:
|
|
|
|
|
* I, the doDispatch() method of InsetFoo, hereby declare that I am
|
|
|
|
|
* not able to handle that request and trust my parent will do the
|
|
|
|
|
* Right Thing (even if my getStatus partner said that I can do it).
|
|
|
|
|
* It is sort of a kludge that should be used only rarely...
|
|
|
|
|
*/
|
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();
|
2006-10-22 11:46:36 +00:00
|
|
|
|
/// Set which update should be done
|
|
|
|
|
void updateFlags(Update::flags f);
|
2005-05-09 17:29:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* don't call update() when done
|
|
|
|
|
*
|
|
|
|
|
* Should only be called by an inset's doDispatch() method. It means:
|
|
|
|
|
* I handled that request and I can reassure you that the screen does
|
|
|
|
|
* not need to be re-drawn and all entries in the coord cache stay
|
|
|
|
|
* valid (and there are no other things to put in the coord cache).
|
|
|
|
|
* This is a fairly rare event as well and only some optimization.
|
|
|
|
|
* Not using noUpdate() should never be wrong.
|
|
|
|
|
*/
|
2004-03-01 17:12:09 +00:00
|
|
|
|
void noUpdate();
|
2005-02-15 17:34:54 +00:00
|
|
|
|
/// fix cursor in circumstances that should never happen
|
|
|
|
|
void fixIfBroken();
|
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-04-03 08:37:12 +00:00
|
|
|
|
|
|
|
|
|
///
|
2004-02-16 11:58:51 +00:00
|
|
|
|
DispatchResult disp_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +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_;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
/// If true, we are behind the previous char, otherwise we are in front
|
|
|
|
|
// of the next char. This only make a difference when we are in front
|
|
|
|
|
// of a big inset spanning a whole row and computing coordinates for
|
|
|
|
|
// displaying the cursor.
|
|
|
|
|
bool logicalpos_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-08-15 21:20:58 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void niceInsert(docstring const & str);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
/// in pixels from top of screen
|
|
|
|
|
void setScreenPos(int x, int y);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// current offset in the top cell
|
2006-01-11 17:08:50 +00:00
|
|
|
|
|
|
|
|
|
/// interpret name a name of a macro. Returns true if
|
|
|
|
|
/// something got inserted.
|
|
|
|
|
bool macroModeClose();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// are we currently typing the name of a macro?
|
|
|
|
|
bool inMacroMode() const;
|
|
|
|
|
/// get access to the macro we are currently typing
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathUnknown * activeMacro();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
/// replace selected stuff with at, placing the former
|
|
|
|
|
// selection in given cell of atom
|
|
|
|
|
void handleNest(MathAtom const & at, int cell = 0);
|
|
|
|
|
///
|
|
|
|
|
bool isInside(InsetBase const *);
|
|
|
|
|
|
|
|
|
|
/// make sure cursor position is valid
|
|
|
|
|
void normalize();
|
|
|
|
|
/// mark current cursor trace for redraw
|
|
|
|
|
void touch();
|
|
|
|
|
|
|
|
|
|
/// 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
|
2006-10-21 00:16:43 +00:00
|
|
|
|
void message(docstring const & msg) const;
|
2004-02-03 11:49:05 +00:00
|
|
|
|
/// display an error message
|
2006-10-21 00:16:43 +00:00
|
|
|
|
void errorMessage(docstring const & msg) const;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
///
|
2006-11-11 11:27:47 +00:00
|
|
|
|
docstring 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
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring macroName();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/// 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;
|
2005-01-10 09:28:06 +00:00
|
|
|
|
/// font at cursor position
|
|
|
|
|
LyXFont getFont() const;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#endif // LYXCURSOR_H
|