4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "cursor_slice.h"
27 // only needed for gcc 2.95, remove when support terminated
28 template <typename A, typename B>
29 bool ptr_cmp(A const * a, B const * b)
35 // The public inheritance should go in favour of a suitable data member
36 // (or maybe private inheritance) at some point of time.
37 class DocumentIterator : public std::vector<CursorSlice>
40 /// type for cell number in inset
41 typedef CursorSlice::idx_type idx_type;
42 /// type for paragraph numbers positions within a cell
43 typedef CursorSlice::par_type par_type;
44 /// type for cursor positions within a cell
45 typedef CursorSlice::pos_type pos_type;
46 /// type for row indices
47 typedef CursorSlice::row_type row_type;
48 /// type for col indices
49 typedef CursorSlice::col_type col_type;
55 explicit DocumentIterator(InsetBase & inset);
58 // access to slice at tip
61 CursorSlice & top() { return back(); }
63 CursorSlice const & top() const { return back(); }
64 /// how many nested insets do we have?
65 size_t depth() const { return size(); }
66 /// the containing inset
67 InsetBase & inset() const { return back().inset(); }
68 /// return the cell of the inset this cursor is in
69 idx_type idx() const { return back().idx(); }
70 /// return the cell of the inset this cursor is in
71 idx_type & idx() { return back().idx(); }
72 /// return the last possible cell in this inset
73 idx_type lastidx() const;
74 /// return the paragraph this cursor is in
75 par_type par() const { return back().par(); }
76 /// return the paragraph this cursor is in
77 par_type & par() { return back().par(); }
78 /// return the last possible paragraph in this inset
79 par_type lastpar() const;
80 /// return the position within the paragraph
81 pos_type pos() const { return back().pos(); }
82 /// return the position within the paragraph
83 pos_type & pos() { return back().pos(); }
84 /// return the last position within the paragraph
85 pos_type lastpos() const;
86 /// return the display row of the cursor with in the top par
87 row_type crow() const;
88 /// return the display row of the cursor with in the top par
89 row_type lastcrow() const;
91 /// return the number of embedded cells
93 /// return the number of embedded cells
95 /// return the number of embedded cells
97 /// return the grid row of the top cell
99 /// return the last row of the top grid
100 row_type lastrow() const { return nrows() - 1; }
101 /// return the grid column of the top cell
102 col_type col() const;
103 /// return the last column of the top grid
104 col_type lastcol() const { return ncols() - 1; }
105 /// the inset just behind the cursor
106 InsetBase * nextInset();
107 /// the inset just in front of the cursor
108 InsetBase * prevInset();
109 /// the inset just in front of the cursor
110 InsetBase const * prevInset() const;
112 /// are we in mathed?
113 bool inMathed() const;
114 /// are we in texted?
115 bool inTexted() const;
118 // math-specific part
120 /// return the mathed cell this cursor is in
121 MathArray const & cell() const;
122 /// return the mathed cell this cursor is in
124 /// the mathatom left of the cursor
125 MathAtom const & prevAtom() const;
126 /// the mathatom left of the cursor
127 MathAtom & prevAtom();
128 /// the mathatom right of the cursor
129 MathAtom const & nextAtom() const;
130 /// the mathatom right of the cursor
131 MathAtom & nextAtom();
134 // text-specific part
136 /// see comment for boundary_ below
137 bool boundary() const { return top().boundary(); }
138 /// see comment for boundary_ below
139 bool & boundary() { return top().boundary(); }
140 /// the paragraph we're in
141 Paragraph & paragraph();
142 /// the paragraph we're in
143 Paragraph const & paragraph() const;
144 /// the row in the paragraph we're in
146 /// the row in the paragraph we're in
147 Row const & textRow() const;
149 LyXText * text() const;
151 InsetBase * innerInsetOfType(int code) const;
153 LyXText * innerText() const;
158 /// move on one position
160 /// move on one paragraph
164 /// move on one inset
167 friend std::ostream &
168 operator<<(std::ostream & os, DocumentIterator const & cur);
172 // The difference to a ('non stable') DocumentIterator is the removed
173 // (overwritte by 0...) part of the CursorSlice data items. So this thing
174 // is suitable for external storage, but not for iteration as such.
176 class StableDocumentIterator {
179 StableDocumentIterator() {}
180 /// non-explicit intended
181 StableDocumentIterator(const DocumentIterator & it);
183 DocumentIterator asDocumentIterator(InsetBase * start) const;
185 size_t size() const { return data_.size(); }
187 friend std::ostream &
188 operator<<(std::ostream & os, StableDocumentIterator const & cur);
190 friend std::istream &
191 operator>>(std::istream & is, StableDocumentIterator & cur);
193 std::vector<CursorSlice> data_;
196 bool operator==(StableDocumentIterator const &, StableDocumentIterator const &);