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"
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
81 size_t nargs() const { return inset_->nargs(); }
82 /// return the number of columns (1 in non-grid-like insets)
83 size_t ncols() const { return inset_->ncols(); }
84 /// return the number of rows (1 in non-grid-like insets)
85 size_t nrows() const { return inset_->nrows(); }
87 * \return the grid row of the current cell.
88 * This does only make sense in grid like insets.
92 * \return the grid column of the current cell.
93 * This does only make sense in grid like insets.
98 /// texted specific stuff
100 /// returns text corresponding to this position
101 LyXText * text() { return inset_->getText(idx_); }
102 /// returns text corresponding to this position
103 LyXText const * text() const { return inset_->getText(idx_); }
104 /// paragraph in this cell
105 Paragraph & paragraph();
106 /// paragraph in this cell
107 Paragraph const & paragraph() const;
110 /// mathed specific stuff
112 /// returns the owning inset if it is a MathInset, else 0
113 MathInset * asMathInset() const { return inset_->asMathInset(); }
114 /// returns cell corresponding to this position
115 MathArray & cell() const;
117 /// write some debug information to \p os
118 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
120 /// pointer to 'owning' inset. This is some kind of cache.
124 * Cell index of a position in this inset.
125 * This is the primary cell information also for grid like insets,
126 * although we have the convenience functions row() and col() for
127 * those * and column changes every time the number of columns ornumber
128 * of rows changes. Normally the cursor should stay in the same cell,
129 * so these changes should typically be performed like the following:
131 * row_type const r = cur.row();
132 * col_type const c = cur.col();
133 * // change nrows() and/or ncols()
134 * cur.idx = index(r, c);
138 /// paragraph in this cell (used by texted)
140 /// true if 'pit' was properly initialized
142 /// position in this cell
146 /// test for equality
147 bool operator==(CursorSlice const &, CursorSlice const &);
148 /// test for inequality
149 bool operator!=(CursorSlice const &, CursorSlice const &);
151 bool operator<(CursorSlice const &, CursorSlice const &);
153 bool operator>(CursorSlice const &, CursorSlice const &);
155 bool operator<=(CursorSlice const &, CursorSlice const &);