+ /// output
+ friend std::ostream & operator<<(std::ostream & os, CursorData const & cur);
+ friend LyXErr & operator<<(LyXErr & os, CursorData const & cur);
+
+ /// reset cursor bottom to the beginning of the top inset
+ // (sort of 'chroot' environment...)
+ void reset();
+ /// sets cursor part
+ /// this (intentionally) does neither touch anchor nor selection status
+ void setCursor(DocIterator const & it);
+ /// set the cursor to dit normalised against the anchor, and set selection.
+ void setCursorSelectionTo(DocIterator dit);
+ /// sets the cursor to the normalized selection anchor
+ void setCursorToAnchor();
+
+ //
+ // selection
+ //
+ /// selection active?
+ bool selection() const { return selection_; }
+ /// set selection; this is lower level than (set|clear)Selection
+ void selection(bool sel) { selection_ = sel; }
+ /// do we have a multicell selection?
+ bool selIsMultiCell() const
+ { return selection_ && selBegin().idx() != selEnd().idx(); }
+ /// do we have a multiline selection?
+ bool selIsMultiLine() const
+ { return selection_ && selBegin().pit() != selEnd().pit(); }
+ ///
+ void setWordSelection(bool set) { word_selection_ = set; }
+ ///
+ bool wordSelection() { return word_selection_; }
+ /// did we place the anchor?
+ bool mark() const { return mark_; }
+ /// did we place the anchor?
+ void setMark(bool mark) { mark_ = mark; }
+ ///
+ void setSelection();
+ /// set selection at given position
+ void setSelection(DocIterator const & where, int n);
+ ///
+ void clearSelection();
+ /// check whether selection contains specific type of inset
+ /// returns 0 if no selection was made
+ bool insetInSelection(InsetCode const & inset);
+ /// count occurences of specific inset type in the selection
+ /// returns 0 if no selection was made
+ int countInsetsInSelection(InsetCode const & inset);
+
+ /// access to normalized selection anchor
+ CursorSlice normalAnchor() const;
+ /// access to real selection anchor
+ DocIterator const & realAnchor() const { return anchor_; }
+ DocIterator & realAnchor() { return anchor_; }
+ /// sets anchor to cursor position
+ void resetAnchor();
+
+ /// access start of selection
+ CursorSlice selBegin() const;
+ /// access end of selection
+ CursorSlice selEnd() const;
+ /// access start of selection
+ DocIterator selectionBegin() const;
+ /// access end of selection
+ DocIterator selectionEnd() const;
+
+ ///
+ docstring selectionAsString(bool with_label) const;
+ /// get some interesting description of top position
+ void info(odocstream & os, bool devel_mode) const;
+ ///
+ docstring currentState(bool devel_mode) const;
+
+ /// auto-correct mode
+ bool autocorrect() const { return autocorrect_; }
+ /// auto-correct mode
+ bool & autocorrect() { return autocorrect_; }
+
+ /// 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();
+