4 * Copyright 1995-2001 the LyX Team
5 * Read the file COPYING
7 * \author Matthias Ettrich
14 #include "ParagraphList.h"
15 #include "support/types.h"
18 * The cursor class describes the position of a cursor within a document.
19 * Several cursors exist within LyX; for example, when locking an inset,
20 * the position of the cursor in the containing inset is stored.
27 /// set the paragraph that contains this cursor
28 void par(ParagraphList::iterator pit);
29 /// return the paragraph this cursor is in
30 ParagraphList::iterator par() const;
31 /// set the position within the paragraph
32 void pos(lyx::pos_type p);
33 /// return the position within the paragraph
34 lyx::pos_type pos() const;
36 void boundary(bool b);
38 bool boundary() const;
39 /// set the x position in pixels
41 /// return the x position in pixels
43 /// set the stored next-line position when at the end of a row
46 * Return the x position of the start of the next row, when this
47 * cursor is at the end of the previous row, for insets that take
50 * FIXME: explain why we need this ?
53 /// set the cached x position
56 * Return the cached x position of the cursor. This is used for when
59 * blah blah blah blah| blah blah blah
61 * blah blah blah blah blah blah
63 * When we move onto row 3, we would like to be vertically aligned
64 * with where we were in row 1, despite the fact that row 2 is
68 /// set the y position in pixels
70 /// return the y position in pixels
72 /// set the stored next-line y position when at the end of a row
75 * Return the y position of the start of the next row, when this
76 * cursor is at the end of the previous row, for insets that take
79 * FIXME: explain why we need this ? especially for y...
82 /// set the row of the paragraph the cursor is in
83 void row(RowList::iterator r);
84 /// return the row of the paragraph this cursor is in
85 RowList::iterator row() const;
86 /// set the stored next row
87 void irow(RowList::iterator r);
89 * Return the next row, when this
90 * cursor is at the end of the previous row, for insets that take
93 * FIXME: explain why we need this ? especially for y...
95 RowList::iterator irow() const;
97 /// The paragraph the cursor is in.
98 ParagraphList::iterator par_;
99 /// The position inside the paragraph
102 * When the cursor position is i, is the cursor is after the i-th char
103 * or before the i+1-th char ? Normally, these two interpretations are
104 * equivalent, except when the fonts of the i-th and i+1-th char
106 * We use boundary_ to distinguish between the two options:
107 * If boundary_=true, then the cursor is after the i-th char
108 * and if boundary_=false, then the cursor is before the i+1-th char.
110 * We currently use the boundary only when the language direction of
111 * the i-th char is different than the one of the i+1-th char.
112 * In this case it is important to distinguish between the two
113 * cursor interpretations, in order to give a reasonable behavior to
117 /// the pixel x position
119 /// the stored next-row x position
121 /// the cached x position
123 /// the pixel y position
125 /// the stored next-row y position
127 /// the containing row
128 RowList::iterator row_;
129 /// the containing row for the next line
130 RowList::iterator irow_;
133 /// these three dictate the others
135 bool operator==(LyXCursor const & a, LyXCursor const & b)
137 return (a.par() == b.par())
138 && (a.pos() == b.pos())
139 && a.boundary() == b.boundary();
143 bool operator!=(LyXCursor const & a, LyXCursor const & b)
148 /// only compares y() and pos(). Can this be done in another way?
150 bool operator<(LyXCursor const & a, LyXCursor const & b)
152 return (a.y() < b.y() && a.pos() < b.pos());
156 bool operator>(LyXCursor const & a, LyXCursor const & b)
162 bool operator>=(LyXCursor const & a, LyXCursor const & b)
169 bool operator<=(LyXCursor const & a, LyXCursor const & b)
174 #endif // LYXCURSOR_H