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"
34 /// This encapsulates a single slice of a document iterator as used e.g.
37 // After IU, the distinction of MathInset and UpdatableInset as well as
38 // that of MathArray and LyXText should vanish. They are conceptually the
43 /// type for cell number in inset
44 typedef size_t idx_type;
45 /// type for paragraph numbers positions within a cell
46 typedef lyx::pit_type pit_type;
47 /// type for cursor positions within a cell
48 typedef lyx::pos_type pos_type;
49 /// type for row indices
50 typedef size_t row_type;
51 /// type for col indices
52 typedef size_t col_type;
57 explicit CursorSlice(InsetBase &);
60 InsetBase & inset() const { return *inset_; }
61 /// return the cell this cursor is in
62 idx_type idx() const { return idx_; }
63 /// return the cell this cursor is in
64 idx_type & idx() { return idx_; }
65 /// Save current cursor idx as row, col
66 void idxSave() { col_ = idx_ % ncols(); row_ = idx_ / ncols(); }
67 /// update idx to correspond to row, col
68 void idxLoad() { idx_ = col_ + ncols() * row_; }
69 /// return the last cell in this inset
70 idx_type lastidx() const { return nargs() - 1; }
71 /// return the offset of the paragraph this cursor is in
72 pit_type pit() const { return pit_; }
73 /// set the offset of the paragraph this cursor is in
74 pit_type & pit() { return pit_; }
75 /// increments the paragraph this cursor is in
77 /// decrements the paragraph this cursor is in
79 /// return the position within the paragraph
80 pos_type pos() const { return pos_; }
81 /// return the position within the paragraph
82 pos_type & pos() { return pos_; }
83 /// return the last position within the paragraph
84 pos_type lastpos() const;
85 /// return the number of embedded cells
87 /// return the number of columns
89 /// return the number of rows
91 /// return the grid row of the current cell
93 /// return the grid column of the current cell
97 /// texted specific stuff
99 /// see comment for the member
100 bool boundary() const { return boundary_; }
101 /// see comment for the member
102 bool & boundary() { return boundary_; }
106 LyXText const * text() const;
108 UpdatableInset * asUpdatableInset() const;
110 Paragraph & paragraph();
112 Paragraph const & paragraph() const;
115 /// mathed specific stuff
117 /// returns cell corresponding to this position
118 MathArray & cell() const;
120 MathInset * asMathInset() const;
123 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
125 /// pointer to 'owning' inset. This is some kind of cache.
128 /// cell index of a position in this inset
130 /// row position in inset
132 /// column position in inset
134 /// paragraph in this cell (used by texted)
136 /// true of 'pit' was properly initialized
138 /// position in this cell
141 * When the cursor position is i, is the cursor is after the i-th char
142 * or before the i+1-th char ? Normally, these two interpretations are
143 * equivalent, except when the fonts of the i-th and i+1-th char
145 * We use boundary_ to distinguish between the two options:
146 * If boundary_=true, then the cursor is after the i-th char
147 * and if boundary_=false, then the cursor is before the i+1-th char.
149 * We currently use the boundary only when the language direction of
150 * the i-th char is different than the one of the i+1-th char.
151 * In this case it is important to distinguish between the two
152 * cursor interpretations, in order to give a reasonable behavior to
158 /// test for equality
159 bool operator==(CursorSlice const &, CursorSlice const &);
160 /// test for inequality
161 bool operator!=(CursorSlice const &, CursorSlice const &);
163 bool operator<(CursorSlice const &, CursorSlice const &);
165 bool operator>(CursorSlice const &, CursorSlice const &);
167 bool operator<=(CursorSlice const &, CursorSlice const &);