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"
33 /// This encapsulates a single slice of a document iterator as used e.g.
36 // After IU, the distinction of MathInset and InsetOld as well as
37 // that of MathArray and LyXText should vanish. They are conceptually the
42 /// type for cell number in inset
43 typedef size_t idx_type;
44 /// type for paragraph numbers positions within a cell
45 typedef lyx::pit_type pit_type;
46 /// type for cursor positions within a cell
47 typedef lyx::pos_type pos_type;
48 /// type for row indices
49 typedef size_t row_type;
50 /// type for col indices
51 typedef size_t col_type;
56 explicit CursorSlice(InsetBase &);
59 InsetBase & inset() const { return *inset_; }
60 /// return the cell this cursor is in
61 idx_type idx() const { return idx_; }
62 /// return the cell this cursor is in
63 idx_type & idx() { return idx_; }
64 /// return the last cell in this inset
65 idx_type lastidx() const { return nargs() - 1; }
66 /// return the offset of the paragraph this cursor is in
67 pit_type pit() const { return pit_; }
68 /// set the offset of the paragraph this cursor is in
69 pit_type & pit() { return pit_; }
70 /// increments the paragraph this cursor is in
72 /// decrements the paragraph this cursor is in
74 /// return the position within the paragraph
75 pos_type pos() const { return pos_; }
76 /// return the position within the paragraph
77 pos_type & pos() { return pos_; }
78 /// return the last position within the paragraph
79 pos_type lastpos() const;
80 /// return the number of embedded cells
83 * \return the number of columns.
84 * This does only make sense in grid like insets.
88 * \return the number of rows.
89 * This does only make sense in grid like insets.
93 * \return the grid row of the current cell.
94 * This does only make sense in grid like insets.
98 * \return the grid column of the current cell.
99 * This does only make sense in grid like insets.
101 col_type col() const;
104 /// texted specific stuff
106 /// returns text corresponding to this position
108 /// returns text corresponding to this position
109 LyXText const * text() const;
110 /// paragraph in this cell
111 Paragraph & paragraph();
112 /// paragraph in this cell
113 Paragraph const & paragraph() const;
116 /// mathed specific stuff
118 /// returns cell corresponding to this position
119 MathArray & cell() const;
120 /// returns the owning inset if it is a MathInset, else 0
121 MathInset * asMathInset() const;
123 /// write some debug information to \p os
124 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
126 /// pointer to 'owning' inset. This is some kind of cache.
130 * Cell index of a position in this inset.
131 * This is the primary cell information also for grid like insets,
132 * although we have the convenience functions row() and col() for
134 * This means that the corresponding idx_ of a cell in a given row
135 * and column changes every time the number of columns or number of
136 * rows changes. Normally the cursor should stay in the same cell,
137 * so these changes should typically be performed like the following:
139 * row_type const r = cur.row();
140 * col_type const c = cur.col();
141 * // change nrows() and/or ncols()
142 * cur.idx = index(r, c);
146 /// paragraph in this cell (used by texted)
148 /// true if 'pit' was properly initialized
150 /// position in this cell
154 /// test for equality
155 bool operator==(CursorSlice const &, CursorSlice const &);
156 /// test for inequality
157 bool operator!=(CursorSlice const &, CursorSlice const &);
159 bool operator<(CursorSlice const &, CursorSlice const &);
161 bool operator>(CursorSlice const &, CursorSlice const &);
163 bool operator<=(CursorSlice const &, CursorSlice const &);