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