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"
34 /// This encapsulates a single slice of a document iterator as used e.g.
37 // After IU, the distinction of MathInset and UpdatableInset as well as
38 // that of MathArray and LyXText should vanish. They are conceptually the
43 /// type for cell number in inset
44 typedef size_t idx_type;
45 /// type for paragraph numbers positions within a cell
46 typedef lyx::pit_type pit_type;
47 /// type for cursor positions within a cell
48 typedef lyx::pos_type pos_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(InsetBase &);
60 InsetBase & inset() const { return *inset_; }
61 /// return the cell this cursor is in
62 idx_type idx() const { return idx_; }
63 /// return the cell this cursor is in
64 idx_type & idx() { return idx_; }
65 /// return the last cell in this inset
66 idx_type lastidx() const { return nargs() - 1; }
67 /// return the offset of the paragraph this cursor is in
68 pit_type pit() const { return pit_; }
69 /// set the offset of the paragraph this cursor is in
70 pit_type & pit() { return pit_; }
71 /// increments the paragraph this cursor is in
73 /// decrements the paragraph this cursor is in
75 /// return the position within the paragraph
76 pos_type pos() const { return pos_; }
77 /// return the position within the paragraph
78 pos_type & pos() { return pos_; }
79 /// return the last position within the paragraph
80 pos_type lastpos() const;
81 /// return the number of embedded cells
84 * \return the number of columns.
85 * This does only make sense in grid like insets.
89 * \return the number of rows.
90 * This does only make sense in grid like insets.
94 * \return the grid row of the current cell.
95 * This does only make sense in grid like insets.
99 * \return the grid column of the current cell.
100 * This does only make sense in grid like insets.
102 col_type col() const;
105 /// texted specific stuff
108 bool boundary() const { return boundary_; }
110 bool & boundary() { return boundary_; }
111 /// returns text corresponding to this position
113 /// returns text corresponding to this position
114 LyXText const * text() const;
115 /// returns the owning inset if it is an UpdatableInset, else 0
116 UpdatableInset * asUpdatableInset() const;
117 /// paragraph in this cell
118 Paragraph & paragraph();
119 /// paragraph in this cell
120 Paragraph const & paragraph() const;
123 /// mathed specific stuff
125 /// returns cell corresponding to this position
126 MathArray & cell() const;
127 /// returns the owning inset if it is a MathInset, else 0
128 MathInset * asMathInset() const;
130 /// write some debug information to \p os
131 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
133 /// pointer to 'owning' inset. This is some kind of cache.
137 * Cell index of a position in this inset.
138 * This is the primary cell information also for grid like insets,
139 * although we have the convenience functions row() and col() for
141 * This means that the corresponding idx_ of a cell in a given row
142 * and column changes every time the number of columns or number of
143 * rows changes. Normally the cursor should stay in the same cell,
144 * so these changes should typically be performed like the following:
146 * row_type const r = cur.row();
147 * col_type const c = cur.col();
148 * // change nrows() and/or ncols()
149 * cur.idx = index(r, c);
153 /// paragraph in this cell (used by texted)
155 /// true if 'pit' was properly initialized
157 /// position in this cell
160 * When the cursor position is i, is the cursor after the i-th char
161 * or before the i+1-th char ? Normally, these two interpretations are
162 * equivalent, except when the fonts of the i-th and i+1-th char
164 * We use boundary_ to distinguish between the two options:
165 * If boundary_=true, then the cursor is after the i-th char
166 * and if boundary_=false, then the cursor is before the i+1-th char.
168 * We currently use the boundary only when the language direction of
169 * the i-th char is different than the one of the i+1-th char.
170 * In this case it is important to distinguish between the two
171 * cursor interpretations, in order to give a reasonable behavior to
177 /// test for equality
178 bool operator==(CursorSlice const &, CursorSlice const &);
179 /// test for inequality
180 bool operator!=(CursorSlice const &, CursorSlice const &);
182 bool operator<(CursorSlice const &, CursorSlice const &);
184 bool operator>(CursorSlice const &, CursorSlice const &);
186 bool operator<=(CursorSlice const &, CursorSlice const &);