* de.po: sync with branch.
[lyx.git] / src / CursorSlice.h
blob19a6e1f581f69a55deac74e540aed0bb979535c8
1 // -*- C++ -*-
2 /**
3 * \file CursorSlice.h
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
9 * \author John Levon
10 * \author André Pönitz
11 * \author Dekel Tsur
12 * \author Jürgen Vigna
14 * Full author contact details are available in file CREDITS.
17 #ifndef CURSORSLICE_H
18 #define CURSORSLICE_H
20 #include "support/types.h"
21 #include "support/strfwd.h"
22 #include "insets/Inset.h"
25 namespace lyx {
27 class Inset;
28 class MathData;
29 class Text;
30 class Paragraph;
32 /// This encapsulates a single slice of a document iterator as used e.g.
33 /// for cursors.
35 // After IU, the distinction of MathInset and InsetOld as well as
36 // that of MathData and Text should vanish. They are conceptually the
37 // same (now...)
39 class CursorSlice {
40 public:
41 /// Those needs inset_ access.
42 ///@{
43 friend class DocIterator;
44 friend class StableDocIterator;
45 ///@}
47 /// type for cell number in inset
48 typedef size_t idx_type;
49 /// type for row indices
50 typedef size_t row_type;
51 /// type for col indices
52 typedef size_t col_type;
54 ///
55 CursorSlice();
56 ///
57 explicit CursorSlice(Inset &);
59 /// comparison operators.
60 //@{
61 friend bool operator==(CursorSlice const &, CursorSlice const &);
62 friend bool operator!=(CursorSlice const &, CursorSlice const &);
63 friend bool operator<(CursorSlice const &, CursorSlice const &);
64 friend bool operator>(CursorSlice const &, CursorSlice const &);
65 friend bool operator<=(CursorSlice const &, CursorSlice const &);
66 //@}
68 /// the current inset
69 Inset & inset() const { return *inset_; }
70 /// return the cell this cursor is in
71 idx_type idx() const { return idx_; }
72 /// return the cell this cursor is in
73 idx_type & idx() { return idx_; }
74 /// return the last cell in this inset
75 idx_type lastidx() const { return nargs() - 1; }
76 /// return the offset of the paragraph this cursor is in
77 pit_type pit() const { return pit_; }
78 /// set the offset of the paragraph this cursor is in
79 pit_type & pit() { return pit_; }
80 /// return the last paragraph offset within the ParagraphList
81 pit_type lastpit() const;
82 /// increments the paragraph this cursor is in
83 void incrementPar();
84 /// decrements the paragraph this cursor is in
85 void decrementPar();
86 /// return the position within the paragraph
87 pos_type pos() const { return pos_; }
88 /// return the position within the paragraph
89 pos_type & pos() { return pos_; }
90 /// return the last position within the paragraph
91 pos_type lastpos() const;
92 /// return the number of embedded cells
93 size_t nargs() const { return inset_->nargs(); }
94 /// return the number of columns (1 in non-grid-like insets)
95 size_t ncols() const { return inset_->ncols(); }
96 /// return the number of rows (1 in non-grid-like insets)
97 size_t nrows() const { return inset_->nrows(); }
98 /*!
99 * \return the grid row of the current cell.
100 * This does only make sense in grid like insets.
102 row_type row() const;
104 * \return the grid column of the current cell.
105 * This does only make sense in grid like insets.
107 col_type col() const;
110 /// texted specific stuff
112 /// returns text corresponding to this position
113 Text * text() const { return inset_->getText(idx_); }
114 /// paragraph in this cell
115 Paragraph & paragraph() const;
118 /// mathed specific stuff
120 /// returns the owning inset if it is a InsetMath, else 0
121 InsetMath * asInsetMath() const { return inset_->asInsetMath(); }
122 /// returns cell corresponding to this position
123 MathData & cell() const;
125 /// write some debug information to \p os
126 friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
127 /// move to next position
128 void forwardPos();
129 /// move to previous position
130 void backwardPos();
131 /// move to next cell
132 void forwardIdx();
133 /// move to previous cell
134 void backwardIdx();
135 /// are we at the end of this slice
136 bool at_end() const;
137 /// are we at the start of this slice
138 bool at_begin() const;
140 private:
142 /// pointer to 'owning' inset. This is some kind of cache.
143 Inset * inset_;
146 * Cell index of a position in this inset.
147 * This is the primary cell information also for grid like insets,
148 * although we have the convenience functions row() and col() for
149 * those * and column changes every time the number of columns ornumber
150 * of rows changes. Normally the cursor should stay in the same cell,
151 * so these changes should typically be performed like the following:
152 * \code
153 * row_type const r = cur.row();
154 * col_type const c = cur.col();
155 * // change nrows() and/or ncols()
156 * cur.idx = index(r, c);
157 * \endcode
159 idx_type idx_;
160 /// paragraph in this cell (used by texted)
161 pit_type pit_;
162 /// position in this cell
163 pos_type pos_;
167 } // namespace lyx
169 #endif