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 virtual ~CursorSlice();
68 CursorSlice & operator=(CursorSlice const &);
73 Inset & inset() const { return *inset_; }
74 /// return the cell this cursor is in
75 idx_type idx() const { return idx_; }
76 /// return the cell this cursor is in
77 idx_type & idx() { return idx_; }
78 /// return the last cell in this inset
79 idx_type lastidx() const { return nargs() - 1; }
80 /// return the offset of the paragraph this cursor is in
81 pit_type pit() const { return pit_; }
82 /// set the offset of the paragraph this cursor is in
83 pit_type & pit() { return pit_; }
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_; }
92 /// return the last position within the paragraph
93 pos_type lastpos() const;
94 /// return the number of embedded cells
95 size_t nargs() const { return inset_->nargs(); }
96 /// return the number of columns (1 in non-grid-like insets)
97 size_t ncols() const { return inset_->ncols(); }
98 /// return the number of rows (1 in non-grid-like insets)
99 size_t nrows() const { return inset_->nrows(); }
101 * \return the grid row of the current cell.
102 * This does only make sense in grid like insets.
104 row_type row() const;
106 * \return the grid column of the current cell.
107 * This does only make sense in grid like insets.
109 col_type col() const;
112 /// texted specific stuff
114 /// returns text corresponding to this position
115 Text * text() { return inset_->getText(idx_); }
116 /// returns text corresponding to this position
117 Text const * text() const { return inset_->getText(idx_); }
118 /// paragraph in this cell
119 Paragraph & paragraph();
120 /// paragraph in this cell
121 Paragraph const & paragraph() const;
124 /// mathed specific stuff
126 /// returns the owning inset if it is a InsetMath, else 0
127 InsetMath * asInsetMath() const { return inset_->asInsetMath(); }
128 /// returns cell corresponding to this position
129 MathData & cell() const;
131 /// write some debug information to \p os
132 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
137 /// pointer to 'owning' inset. This is some kind of cache.
141 * Cell index of a position in this inset.
142 * This is the primary cell information also for grid like insets,
143 * although we have the convenience functions row() and col() for
144 * those * and column changes every time the number of columns ornumber
145 * of rows changes. Normally the cursor should stay in the same cell,
146 * so these changes should typically be performed like the following:
148 * row_type const r = cur.row();
149 * col_type const c = cur.col();
150 * // change nrows() and/or ncols()
151 * cur.idx = index(r, c);
155 /// paragraph in this cell (used by texted)
157 /// true if 'pit' was properly initialized
159 /// position in this cell
161 /// connection to referred \c inset_ destruction signal.
162 boost::signals::connection inset_connection_;
165 /// test for equality
166 bool operator==(CursorSlice const &, CursorSlice const &);
167 /// test for inequality
168 bool operator!=(CursorSlice const &, CursorSlice const &);
170 bool operator<(CursorSlice const &, CursorSlice const &);
172 bool operator>(CursorSlice const &, CursorSlice const &);
174 bool operator<=(CursorSlice const &, CursorSlice const &);