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"
23 #include <boost/signal.hpp>
24 #include <boost/signals/trackable.hpp>
37 /// This encapsulates a single slice of a document iterator as used e.g.
40 // After IU, the distinction of MathInset and InsetOld as well as
41 // that of MathData and Text should vanish. They are conceptually the
44 class CursorSlice : public boost::signals::trackable {
46 /// Those needs inset_ access.
48 friend class DocIterator;
49 friend class StableDocIterator;
52 /// type for cell number in inset
53 typedef size_t idx_type;
54 /// type for row indices
55 typedef size_t row_type;
56 /// type for col indices
57 typedef size_t col_type;
62 CursorSlice(CursorSlice const &);
64 explicit CursorSlice(Inset &);
66 CursorSlice & operator=(CursorSlice const &);
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 /// increments the paragraph this cursor is in
84 /// decrements the paragraph this cursor is in
86 /// return the position within the paragraph
87 pos_type pos() const { return pos_; }
88 /// return the position within the paragraph
89 pos_type & pos() { return pos_; }
90 /// return the last position within the paragraph
91 pos_type lastpos() const;
92 /// return the number of embedded cells
93 size_t nargs() const { return inset_->nargs(); }
94 /// return the number of columns (1 in non-grid-like insets)
95 size_t ncols() const { return inset_->ncols(); }
96 /// return the number of rows (1 in non-grid-like insets)
97 size_t nrows() const { return inset_->nrows(); }
99 * \return the grid row of the current cell.
100 * This does only make sense in grid like insets.
102 row_type row() const;
104 * \return the grid column of the current cell.
105 * This does only make sense in grid like insets.
107 col_type col() const;
110 /// texted specific stuff
112 /// returns text corresponding to this position
113 Text * text() { return inset_->getText(idx_); }
114 /// returns text corresponding to this position
115 Text const * text() const { return inset_->getText(idx_); }
116 /// paragraph in this cell
117 Paragraph & paragraph();
118 /// paragraph in this cell
119 Paragraph const & paragraph() const;
122 /// mathed specific stuff
124 /// returns the owning inset if it is a InsetMath, else 0
125 InsetMath * asInsetMath() const { return inset_->asInsetMath(); }
126 /// returns cell corresponding to this position
127 MathData & cell() const;
129 /// write some debug information to \p os
130 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
135 /// pointer to 'owning' inset. This is some kind of cache.
139 * Cell index of a position in this inset.
140 * This is the primary cell information also for grid like insets,
141 * although we have the convenience functions row() and col() for
142 * those * and column changes every time the number of columns ornumber
143 * of 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
161 /// test for equality
162 bool operator==(CursorSlice const &, CursorSlice const &);
163 /// test for inequality
164 bool operator!=(CursorSlice const &, CursorSlice const &);
166 bool operator<(CursorSlice const &, CursorSlice const &);
168 bool operator>(CursorSlice const &, CursorSlice const &);
170 bool operator<=(CursorSlice const &, CursorSlice const &);