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 "insets/Inset.h"
34 /// This encapsulates a single slice of a document iterator as used e.g.
37 // After IU, the distinction of MathInset and InsetOld as well as
38 // that of MathData and LyXText should vanish. They are conceptually the
43 /// type for cell number in inset
44 typedef size_t idx_type;
45 /// type for row indices
46 typedef size_t row_type;
47 /// type for col indices
48 typedef size_t col_type;
53 explicit CursorSlice(Inset &);
56 Inset & inset() const { return *inset_; }
57 /// return the cell this cursor is in
58 idx_type idx() const { return idx_; }
59 /// return the cell this cursor is in
60 idx_type & idx() { return idx_; }
61 /// return the last cell in this inset
62 idx_type lastidx() const { return nargs() - 1; }
63 /// return the offset of the paragraph this cursor is in
64 pit_type pit() const { return pit_; }
65 /// set the offset of the paragraph this cursor is in
66 pit_type & pit() { return pit_; }
67 /// increments the paragraph this cursor is in
69 /// decrements the paragraph this cursor is in
71 /// return the position within the paragraph
72 pos_type pos() const { return pos_; }
73 /// return the position within the paragraph
74 pos_type & pos() { return pos_; }
75 /// return the last position within the paragraph
76 pos_type lastpos() const;
77 /// return the number of embedded cells
78 size_t nargs() const { return inset_->nargs(); }
79 /// return the number of columns (1 in non-grid-like insets)
80 size_t ncols() const { return inset_->ncols(); }
81 /// return the number of rows (1 in non-grid-like insets)
82 size_t nrows() const { return inset_->nrows(); }
84 * \return the grid row of the current cell.
85 * This does only make sense in grid like insets.
89 * \return the grid column of the current cell.
90 * This does only make sense in grid like insets.
95 /// texted specific stuff
97 /// returns text corresponding to this position
98 LyXText * text() { return inset_->getText(idx_); }
99 /// returns text corresponding to this position
100 LyXText const * text() const { return inset_->getText(idx_); }
101 /// paragraph in this cell
102 Paragraph & paragraph();
103 /// paragraph in this cell
104 Paragraph const & paragraph() const;
107 /// mathed specific stuff
109 /// returns the owning inset if it is a InsetMath, else 0
110 InsetMath * asInsetMath() const { return inset_->asInsetMath(); }
111 /// returns cell corresponding to this position
112 MathData & cell() const;
114 /// write some debug information to \p os
115 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
117 /// pointer to 'owning' inset. This is some kind of cache.
121 * Cell index of a position in this inset.
122 * This is the primary cell information also for grid like insets,
123 * although we have the convenience functions row() and col() for
124 * those * and column changes every time the number of columns ornumber
125 * of rows changes. Normally the cursor should stay in the same cell,
126 * so these changes should typically be performed like the following:
128 * row_type const r = cur.row();
129 * col_type const c = cur.col();
130 * // change nrows() and/or ncols()
131 * cur.idx = index(r, c);
135 /// paragraph in this cell (used by texted)
137 /// true if 'pit' was properly initialized
139 /// position in this cell
143 /// test for equality
144 bool operator==(CursorSlice const &, CursorSlice const &);
145 /// test for inequality
146 bool operator!=(CursorSlice const &, CursorSlice const &);
148 bool operator<(CursorSlice const &, CursorSlice const &);
150 bool operator>(CursorSlice const &, CursorSlice const &);
152 bool operator<=(CursorSlice const &, CursorSlice const &);