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"
31 // this is used for traversing math insets
32 typedef std::vector<CursorSlice> CursorBase;
34 void increment(CursorBase &);
36 CursorBase ibegin(InsetBase * p);
38 CursorBase iend(InsetBase * p);
42 * The cursor class describes the position of a cursor within a document.
47 /// type for cell number in inset
48 typedef CursorSlice::idx_type idx_type;
49 /// type for paragraph numbers positions within a cell
50 typedef CursorSlice::par_type par_type;
51 /// type for cursor positions within a cell
52 typedef CursorSlice::pos_type pos_type;
53 /// type for row indices
54 typedef CursorSlice::row_type row_type;
55 /// type for col indices
56 typedef CursorSlice::col_type col_type;
58 /// create the cursor of a BufferView
59 explicit LCursor(BufferView & bv);
60 /// dispatch from innermost inset upwards
61 DispatchResult dispatch(FuncRequest const & cmd);
63 void push(InsetBase * inset);
64 /// restrict cursor nesting to given size
66 /// pop one level off the cursor
68 /// access to current cursor slice
69 CursorSlice & current();
70 /// access to current cursor slice
71 CursorSlice const & current() const;
72 /// how many nested insets do we have?
73 size_t depth() const { return cursor_.size(); }
79 bool selection() const { return selection_; }
81 bool & selection() { return selection_; }
82 /// did we place the anchor?
83 bool mark() const { return mark_; }
84 /// did we place the anchor?
85 bool & mark() { return mark_; }
89 void clearSelection();
91 CursorSlice & selStart();
93 CursorSlice const & selStart() const;
95 CursorSlice & selEnd();
97 CursorSlice const & selEnd() const;
100 // access to the 'current' cursor slice
102 /// the current inset
103 InsetBase * inset() const { return current().inset(); }
104 /// return the text-ed cell this cursor is in
105 idx_type idx() const { return current().idx(); }
106 /// return the text-ed cell this cursor is in
107 idx_type & idx() { return current().idx(); }
108 /// return the paragraph this cursor is in
109 par_type par() const { return current().par(); }
110 /// return the paragraph this cursor is in
111 par_type & par() { return current().par(); }
112 /// return the position within the paragraph
113 pos_type pos() const { return current().pos(); }
114 /// return the position within the paragraph
115 pos_type & pos() { return current().pos(); }
116 /// return the last position within the paragraph
117 pos_type lastpos() const;
118 /// return the number of embedded cells
119 size_t nargs() const;
120 /// return the number of embedded cells
121 size_t ncols() const;
122 /// return the number of embedded cells
123 size_t nrows() const;
124 /// return the grid row of the current cell
125 row_type row() const;
126 /// return the grid row of the current cell
127 col_type col() const;
130 // math-specific part
132 /// return the mathed cell this cursor is in
133 MathArray const & cell() const;
134 /// return the mathed cell this cursor is in
136 /// the mathatom left of the cursor
137 MathAtom const & prevAtom() const;
138 /// the mathatom left of the cursor
139 MathAtom & prevAtom();
140 /// the mathatom right of the cursor
141 MathAtom const & nextAtom() const;
142 /// the mathatom right of the cursor
143 MathAtom & nextAtom();
144 /// auto-correct mode
145 bool autocorrect() const { return autocorrect_; }
146 /// auto-correct mode
147 bool & autocorrect() { return autocorrect_; }
148 /// are we entering a macro name?
149 bool macromode() const { return macromode_; }
150 /// are we entering a macro name?
151 bool & macromode() { return macromode_; }
154 // text-specific part
156 bool boundary() const { return current().boundary(); }
158 Paragraph & paragraph();
160 Paragraph const & paragraph() const;
162 InsetBase * innerInsetOfType(int code) const;
164 InsetTabular * innerInsetTabular() const;
166 LyXText * innerText() const;
167 /// returns x,y position
168 void getPos(int & x, int & y) const;
169 /// returns cursor dimension
170 void getDim(int & asc, int & desc) const;
175 /// move one step to the left
177 /// move one step to the right
180 /// set target x position of cursor
181 void x_target(int x);
182 /// return target x position of cursor
183 int x_target() const;
185 /// access to selection anchor
186 CursorSlice & anchor();
187 /// access to selection anchor
188 CursorSlice const & anchor() const;
189 /// cache the absolute coordinate from the top inset
191 /// sets anchor to cursor position
193 /// access to owning BufferView
194 BufferView & bv() const;
195 /// get some interesting description of current position
196 void info(std::ostream & os);
199 friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
202 /// mainly used as stack, but wee need random access
203 std::vector<CursorSlice> cursor_;
204 /// the anchor position
205 std::vector<CursorSlice> anchor_;
208 /// don't implement this
209 void operator=(LCursor const &);
210 /// don't implement this
211 LCursor(LCursor const &);
214 BufferView * const bv_;
220 * The target x position of the cursor. This is used for when
221 * we have text like :
223 * blah blah blah blah| blah blah blah
225 * blah blah blah blah blah blah
227 * When we move onto row 3, we would like to be vertically aligned
228 * with where we were in row 1, despite the fact that row 2 is
232 // do we have a selection?
234 // are we on the way to get one?
238 // math specific stuff that could be promoted to "global" later
240 /// do we allow autocorrection
242 /// are we entering a macro name?
246 #endif // LYXCURSOR_H