+
+ /// fix cursor in circumstances that should never happen.
+ /// \retval true if a fix occurred.
+ bool fixIfBroken();
+ /// Repopulate the slices insets from bottom to top. Useful
+ /// for stable iterators or Undo data.
+ void sanitize();
+
+ ///
+ bool undoAction();
+ ///
+ bool redoAction();
+
+ /// makes sure the next operation will be stored
+ void finishUndo() const;
+ /// open a new group of undo operations. Groups can be nested.
+ void beginUndoGroup() const;
+ /// end the current undo group
+ void endUndoGroup() const;
+
+ /// The general case: prepare undo for an arbitrary range.
+ void recordUndo(pit_type from, pit_type to) const;
+ /// Convenience: prepare undo for the range between 'from' and cursor.
+ void recordUndo(pit_type from) const;
+ /// Convenience: prepare undo for the single paragraph or cell
+ /// containing the cursor
+ void recordUndo(UndoKind kind = ATOMIC_UNDO) const;
+ /// Convenience: prepare undo for the inset containing the cursor
+ void recordUndoInset(Inset const * inset = 0) const;
+ /// Convenience: prepare undo for the whole buffer
+ void recordUndoFullBuffer() const;
+ /// Convenience: prepare undo for buffer parameters
+ void recordUndoBufferParams() const;
+ /// Convenience: prepare undo for the selected paragraphs or cells
+ void recordUndoSelection() const;
+
+ /// hook for text input to maintain the "new born word"
+ void markNewWordPosition();
+ /// The position of the new born word
+ /// As the user is entering a word without leaving it
+ /// the result is not empty. When not in text mode
+ /// and after leaving the word the result is empty.
+ DocIterator newWord() const { return new_word_; }
+
+ /// are we in math mode (2), text mode (1) or unsure (0)?
+ int currentMode();
+
+ /// Return true if the next or previous inset has confirmDeletion depending
+ /// on the boolean before. If there is a selection, return true if at least
+ /// one inset in the selection has confirmDeletion.
+ bool confirmDeletion(bool before = false) const;
+
+private:
+ /// validate the "new born word" position
+ void checkNewWordPosition();
+ /// clear the "new born word" position
+ void clearNewWordPosition();
+
+ /// the anchor position
+ DocIterator anchor_;
+ /// do we have a selection?
+ bool selection_;
+ /// are we on the way to get one?
+ bool mark_;
+ /// are we in word-selection mode? This is set when double clicking.
+ bool word_selection_;
+
+ /// the start of the new born word
+ DocIterator new_word_;
+ //
+ // math specific stuff that could be promoted to "global" later
+ //
+ /// do we allow autocorrection
+ bool autocorrect_;
+
+ // FIXME: make them private
+public:
+ /// The current font settings. This holds the settings for output.
+ Font current_font;
+ /// The current display font. This holds the settings of the text
+ /// in the workarea.
+ Font real_current_font;
+};
+
+
+/// The cursor class describes the position of a cursor within a document.
+class Cursor : public CursorData
+{
+public:
+ /// create the cursor of a BufferView
+ explicit Cursor(BufferView & bv);
+
+ /// add a new cursor slice
+ void push(Inset & inset);
+ /// add a new cursor slice, place cursor at front (move backwards)
+ void pushBackward(Inset & inset);
+ /// try to put cursor in inset before it in entry cell, or next one
+ /// if it is not empty, or exit the slice if there is no next one.
+ void editInsertedInset();
+
+ /// pop one level off the cursor
+ void pop();
+ /// pop one slice off the cursor stack and go backwards
+ bool popBackward();
+ /// pop one slice off the cursor stack and go forward
+ bool popForward();
+ /// set the cursor data
+ void setCursorData(CursorData const & data);
+
+ /// returns true if we made a decision
+ bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
+ /// dispatch from innermost inset upwards
+ void dispatch(FuncRequest const & cmd);
+ /// display a message
+ void message(docstring const & msg) const;
+ /// display an error message
+ void errorMessage(docstring const & msg) const;
+ /// get the resut of the last dispatch
+ DispatchResult const & result() const;
+
+ ///
+ void setCurrentFont();
+
+ /**
+ * Update the selection status and save permanent
+ * selection if needed.
+ * @param selecting the new selection status
+ * @return whether the selection status has changed
+ */
+ bool selHandle(bool selecting);
+