4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
10 * \author André Pönitz
12 * \author Jürgen Vigna
14 * Full author contact details are available in file CREDITS.
20 #include "support/types.h"
21 #include "support/strfwd.h"
22 #include "insets/Inset.h"
32 /// This encapsulates a single slice of a document iterator as used e.g.
35 // After inset unification, the distinction of InsetMath and Inset as well as
36 // that of MathData and Text should vanish. They are conceptually the
41 /// \name Those needs inset_ access.
43 friend class DocIterator;
44 friend class StableDocIterator;
47 /// type for cell number in inset
48 typedef size_t idx_type;
49 /// type for row indices
50 typedef size_t row_type;
51 /// type for col indices
52 typedef size_t col_type;
57 explicit CursorSlice(Inset &);
59 /// \name Comparison operators.
61 friend bool operator==(CursorSlice const &, CursorSlice const &);
62 friend bool operator!=(CursorSlice const &, CursorSlice const &);
63 friend bool operator<(CursorSlice const &, CursorSlice const &);
64 friend bool operator>(CursorSlice const &, CursorSlice const &);
65 friend bool operator<=(CursorSlice const &, CursorSlice const &);
68 /// return true if the slice has not been initialized
69 bool empty() const { return !inset_; }
71 Inset & inset() const { return *inset_; }
72 /// return the cell this cursor is in
73 idx_type idx() const { return idx_; }
74 /// return the cell this cursor is in
75 idx_type & idx() { return idx_; }
76 /// return the last cell in this inset
77 idx_type lastidx() const { return nargs() - 1; }
78 /// return the offset of the paragraph this cursor is in
79 pit_type pit() const { return pit_; }
80 /// set the offset of the paragraph this cursor is in
81 pit_type & pit() { return pit_; }
82 /// return the last paragraph offset within the ParagraphList
83 pit_type lastpit() const;
84 /// increments the paragraph this cursor is in
86 /// decrements the paragraph this cursor is in
88 /// return the position within the paragraph
89 pos_type pos() const { return pos_; }
90 /// return the position within the paragraph
91 pos_type & pos() { return pos_; }
93 * \return the last position within the paragraph.
94 * Note that this is the position behind the last character or inset,
95 * i.e. you cannot dereference it.
97 pos_type lastpos() const;
98 /// return the number of embedded cells
99 size_t nargs() const { return inset_->nargs(); }
100 /// return the number of columns (1 in non-grid-like insets)
101 size_t ncols() const { return inset_->ncols(); }
102 /// return the number of rows (1 in non-grid-like insets)
103 size_t nrows() const { return inset_->nrows(); }
105 * \return the grid row of the current cell.
106 * This does only make sense in grid like insets.
108 row_type row() const;
110 * \return the grid column of the current cell.
111 * This does only make sense in grid like insets.
113 col_type col() const;
116 /// texted specific stuff
118 /// returns text corresponding to this position
119 Text * text() const { return inset_->getText(idx_); }
120 /// paragraph in this cell
121 Paragraph & paragraph() const;
123 void setPitPos(pit_type pit, pos_type pos);
126 /// mathed specific stuff
128 /// returns the owning inset if it is a InsetMath, else 0
129 InsetMath * asInsetMath() const { return inset_->asInsetMath(); }
130 /// returns cell corresponding to this position
131 MathData & cell() const;
133 /// write some debug information to \p os
134 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
135 /// move to next position
137 /// move to previous position
139 /// move to next cell
141 /// move to previous cell
143 /// are we at the end of the cell
144 bool at_cell_end() const;
145 /// are we at the start of the cell
146 bool at_cell_begin() const;
147 /// are we at the end of this slice
149 /// are we at the start of this slice
150 bool at_begin() const;
154 /// pointer to 'owning' inset. This is some kind of cache.
158 * Cell index of a position in this inset.
159 * This is the primary cell information also for grid like insets,
160 * although we have the convenience functions row() and col() for
162 * This means that the corresponding idx_ of a cell in a given row
163 * and column changes every time the number of columns or number
164 * of rows changes. Normally the cursor should stay in the same cell,
165 * so these changes should typically be performed like the following:
167 * row_type const r = cur.row();
168 * col_type const c = cur.col();
169 * // change nrows() and/or ncols()
170 * cur.idx = index(r, c);
174 /// paragraph in this cell (used by texted)
176 /// position in this cell