]> git.lyx.org Git - lyx.git/blob - src/lyxcursor.h
remerge
[lyx.git] / src / lyxcursor.h
1 // -*- C++ -*-
2 /**
3  * \file lyxcursor.h
4  * Copyright 1995-2001 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Matthias Ettrich
8  */
9
10 #ifndef LYXCURSOR_H
11 #define LYXCURSOR_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "support/types.h"
18
19 class Paragraph;
20 class Row;
21
22 /** 
23  * The cursor class describes the position of a cursor within a document.
24  * Several cursors exist within LyX; for example, when locking an inset,
25  * the position of the cursor in the containing inset is stored.
26  *
27  * FIXME: true ?
28  */
29 class LyXCursor {
30 public:
31         LyXCursor();
32         /// set the paragraph that contains this cursor
33         void par(Paragraph * p);
34         /// return the paragraph this cursor is in
35         Paragraph * par() const;
36         /// set the position within the paragraph
37         void pos(lyx::pos_type p);
38         /// return the position within the paragraph
39         lyx::pos_type pos() const;
40         /// FIXME
41         void boundary(bool b);
42         /// FIXME
43         bool boundary() const;
44         /// set the x position in pixels
45         void x(int i);
46         /// return the x position in pixels
47         int x() const;
48         /// set the stored next-line position when at the end of a row
49         void ix(int i);
50         /**
51          * Return the x position of the start of the next row, when this
52          * cursor is at the end of the previous row, for insets that take
53          * a full row.
54          *
55          * FIXME: explain why we need this ?
56          */
57         int ix() const;
58         /// set the cached x position
59         void x_fix(int i);
60         /**
61          * Return the cached x position of the cursor. This is used for when
62          * we have text like :
63          *
64          * blah blah blah blah| blah blah blah
65          * blah blah blah
66          * blah blah blah blah blah blah
67          *
68          * When we move onto row 3, we would like to be vertically aligned
69          * with where we were in row 1, despite the fact that row 2 is 
70          * shorter than x()
71          */
72         int x_fix() const;
73         /// set the y position in pixels
74         void y(int i);
75         /// return the y position in pixels
76         int y() const;
77         /// set the stored next-line y position when at the end of a row
78         void iy(int i);
79         /**
80          * Return the y position of the start of the next row, when this
81          * cursor is at the end of the previous row, for insets that take
82          * a full row.
83          *
84          * FIXME: explain why we need this ? especially for y...
85          */
86         int iy() const;
87         /// set the row of the paragraph the cursor is in
88         void row(Row * r);
89         /// return the row of the paragraph this cursor is in
90         Row * row() const;
91         /// set the stored next row
92         void irow(Row * r);
93         /**
94          * Return the next row, when this
95          * cursor is at the end of the previous row, for insets that take
96          * a full row.
97          *
98          * FIXME: explain why we need this ? especially for y...
99          */
100         Row * irow() const;
101 private:
102         /// The paragraph the cursor is in.
103         Paragraph * par_;
104         /// The position inside the paragraph
105         lyx::pos_type pos_;
106         /**
107          * When the cursor position is i, is the cursor is after the i-th char
108          * or before the i+1-th char ? Normally, these two interpretations are
109          * equivalent, except when the fonts of the i-th and i+1-th char
110          * differ.
111          * We use boundary_ to distinguish between the two options:
112          * If boundary_=true, then the cursor is after the i-th char
113          * and if boundary_=false, then the cursor is before the i+1-th char.
114          *
115          * We currently use the boundary only when the language direction of
116          * the i-th char is different than the one of the i+1-th char.
117          * In this case it is important to distinguish between the two
118          * cursor interpretations, in order to give a reasonable behavior to
119          * the user.
120          */
121         bool boundary_;
122         /// the pixel x position
123         int x_;
124         /// the stored next-row x position 
125         int ix_;
126         /// the cached x position
127         int x_fix_;
128         /// the pixel y position
129         int y_;
130         /// the stored next-row y position
131         int iy_;
132         /// the containing row
133         Row * row_;
134         /// the containing row for the next line 
135         Row * irow_;
136 };
137
138 /// these three dictate the others
139 inline
140 bool operator==(LyXCursor const & a, LyXCursor const & b)
141 {
142         return (a.par() == b.par())
143                 && (a.pos() == b.pos())
144                 && a.boundary() == b.boundary();
145 }
146
147 inline
148 bool operator!=(LyXCursor const & a, LyXCursor const & b)
149 {
150         return !(a == b);
151 }
152
153 /// only compares y() and pos(). Can this be done in another way?
154 inline
155 bool operator<(LyXCursor const & a, LyXCursor const & b)
156 {
157         return (a.y() < b.y() && a.pos() < b.pos());
158 }
159
160 inline
161 bool operator>(LyXCursor const & a, LyXCursor const & b)
162 {
163         return b < a;
164 }
165
166 inline
167 bool operator>=(LyXCursor const & a, LyXCursor const & b)
168 {
169         return !(a < b);
170 }
171
172
173 inline
174 bool operator<=(LyXCursor const & a, LyXCursor const & b)
175 {
176         return !(a > b);
177 }
178
179 #endif // LYXCURSOR_H