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"
26 // only needed for gcc 2.95, remove when support terminated
27 template <typename A, typename B>
28 bool ptr_cmp(A const * a, B const * b)
34 // The public inheritance should go in favour of a suitable data member
35 // (or maybe private inheritance) at some point of time.
36 class DocumentIterator : public std::vector<CursorSlice>
39 /// type for cell number in inset
40 typedef CursorSlice::idx_type idx_type;
41 /// type for paragraph numbers positions within a cell
42 typedef CursorSlice::par_type par_type;
43 /// type for cursor positions within a cell
44 typedef CursorSlice::pos_type pos_type;
45 /// type for row indices
46 typedef CursorSlice::row_type row_type;
47 /// type for col indices
48 typedef CursorSlice::col_type col_type;
54 explicit DocumentIterator(BufferView & bv);
56 BufferView & bv() const { return *bv_; }
59 // access to slice at tip
62 CursorSlice & top() { return back(); }
64 CursorSlice const & top() const { return back(); }
65 /// how many nested insets do we have?
66 size_t depth() const { return size(); }
67 /// the containing inset
68 InsetBase * inset() const { return back().inset(); }
69 /// return the cell of the inset this cursor is in
70 idx_type idx() const { return back().idx(); }
71 /// return the cell of the inset this cursor is in
72 idx_type & idx() { return back().idx(); }
73 /// return the last possible cell in this inset
74 idx_type lastidx() const;
75 /// return the paragraph this cursor is in
76 par_type par() const { return back().par(); }
77 /// return the paragraph this cursor is in
78 par_type & par() { return back().par(); }
79 /// return the last possible paragraph in this inset
80 par_type lastpar() const;
81 /// return the position within the paragraph
82 pos_type pos() const { return back().pos(); }
83 /// return the position within the paragraph
84 pos_type & pos() { return back().pos(); }
85 /// return the last position within the paragraph
86 pos_type lastpos() const;
87 /// return the display row of the cursor with in the top par
88 row_type crow() const;
89 /// return the display row of the cursor with in the top par
90 row_type lastcrow() const;
92 /// return the number of embedded cells
94 /// return the number of embedded cells
96 /// return the number of embedded cells
98 /// return the grid row of the top cell
100 /// return the last row of the top grid
101 row_type lastrow() const { return nrows() - 1; }
102 /// return the grid column of the top cell
103 col_type col() const;
104 /// return the last column of the top grid
105 col_type lastcol() const { return ncols() - 1; }
106 /// the inset just behind the cursor
107 InsetBase * nextInset();
108 /// the inset just in front of the cursor
109 InsetBase * prevInset();
110 /// the inset just in front of the cursor
111 InsetBase const * prevInset() const;
113 /// are we in mathed?
114 bool inMathed() const;
115 /// are we in texted?
116 bool inTexted() const;
119 // math-specific part
121 /// return the mathed cell this cursor is in
122 MathArray const & cell() const;
123 /// return the mathed cell this cursor is in
125 /// the mathatom left of the cursor
126 MathAtom const & prevAtom() const;
127 /// the mathatom left of the cursor
128 MathAtom & prevAtom();
129 /// the mathatom right of the cursor
130 MathAtom const & nextAtom() const;
131 /// the mathatom right of the cursor
132 MathAtom & nextAtom();
135 // text-specific part
137 /// see comment for boundary_ below
138 bool boundary() const { return top().boundary(); }
139 /// see comment for boundary_ below
140 bool & boundary() { return top().boundary(); }
141 /// the paragraph we're in
142 Paragraph & paragraph();
143 /// the paragraph we're in
144 Paragraph const & paragraph() const;
145 /// the row in the paragraph we're in
147 /// the row in the paragraph we're in
148 Row const & textRow() const;
150 LyXText * text() const;
152 CursorSlice const & innerTextSlice() const;
154 InsetBase * innerInsetOfType(int code) const;
156 LyXText * innerText() const;
161 /// move on one position
163 /// move on one paragraph
167 /// move on one inset
177 DocumentIterator bufferBegin(BufferView & bv);
179 DocumentIterator bufferEnd();
181 DocumentIterator insetBegin(BufferView & bv, InsetBase * inset);
183 DocumentIterator insetEnd();