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