4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "cursor_slice.h"
30 * The cursor class describes the position of a cursor within a document.
35 /// type for cell number in inset
36 typedef CursorSlice::idx_type idx_type;
37 /// type for paragraph numbers positions within a cell
38 typedef CursorSlice::par_type par_type;
39 /// type for cursor positions within a cell
40 typedef CursorSlice::pos_type pos_type;
41 /// type for row indices
42 typedef CursorSlice::row_type row_type;
43 /// type for col indices
44 typedef CursorSlice::col_type col_type;
46 /// create 'empty' cursor. REMOVE ME
48 /// create the cursor of a BufferView
49 explicit LCursor(BufferView & bv);
50 /// dispatch from innermost inset upwards
51 DispatchResult dispatch(FuncRequest const & cmd);
53 void push(InsetBase * inset);
54 /// restrict cursor nesting to given size
56 /// pop one level off the cursor
58 /// access to cursor 'tip'
59 CursorSlice & top() { return cursor_.back(); }
60 /// access to cursor 'tip'
61 CursorSlice const & top() const { return cursor_.back(); }
62 /// how many nested insets do we have?
63 size_t depth() const { return cursor_.size(); }
65 /// access to the topmost slice
67 InsetBase * inset() const { return top().inset(); }
68 /// return the text-ed cell this cursor is in
69 idx_type idx() const { return top().idx(); }
70 /// return the text-ed cell this cursor is in
71 idx_type & idx() { return top().idx(); }
72 /// return the paragraph this cursor is in
73 par_type par() const { return top().par(); }
74 /// return the paragraph this cursor is in
75 par_type & par() { return top().par(); }
76 /// return the position within the paragraph
77 pos_type pos() const { return top().pos(); }
78 /// return the position within the paragraph
79 pos_type & pos() { return top().pos(); }
80 /// return the last position within the paragraph
81 pos_type lastpos() const { return top().lastpos(); }
82 /// return the number of embedded cells
83 size_t nargs() const { return top().nargs(); }
84 /// return the number of embedded cells
85 size_t ncols() const { return top().ncols(); }
86 /// return the number of embedded cells
87 size_t nrows() const { return top().nrows(); }
88 /// return the grid row of the current cell
89 row_type row() const { return top().row(); }
90 /// return the grid row of the current cell
91 col_type col() const { return top().col(); }
96 /// return the mathed cell this cursor is in
97 MathArray const & cell() const { return top().cell(); }
98 /// return the mathed cell this cursor is in
99 MathArray & cell() { return top().cell(); }
100 /// the mathatom left of the cursor
101 MathAtom const & prevAtom() const;
102 /// the mathatom left of the cursor
103 MathAtom & prevAtom();
104 /// the mathatom right of the cursor
105 MathAtom const & nextAtom() const;
106 /// the mathatom right of the cursor
107 MathAtom & nextAtom();
110 // text-specific part
112 UpdatableInset * innerInset() const;
114 UpdatableInset * innerInsetOfType(int code) const;
116 InsetTabular * innerInsetTabular() const;
118 LyXText * innerText() const;
119 /// returns x,y position
120 void getPos(int & x, int & y) const;
121 /// returns cursor dimension
122 void getDim(int & asc, int & desc) const;
127 /// move one step to the left
129 /// move one step to the right
132 /// cache the absolute coordinate from the top inset
134 /// sets anchor to cursor position
136 /// access to owning BufferView
137 BufferView & bv() const;
139 friend std::ostream & operator<<(std::ostream &, LCursor const &);
141 /// mainly used as stack, but wee need random access
142 std::vector<CursorSlice> cursor_;
144 std::vector<CursorSlice> anchor_;
152 #endif // LYXCURSOR_H