]> git.lyx.org Git - lyx.git/blob - src/lyxcursor.h
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[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         /// FIXME
107         bool boundary_;
108         /// the pixel x position
109         int x_;
110         /// the stored next-row x position 
111         int ix_;
112         /// the cached x position
113         int x_fix_;
114         /// the pixel y position
115         int y_;
116         /// the stored next-row y position
117         int iy_;
118         /// the containing row
119         Row * row_;
120         /// the containing row for the next line 
121         Row * irow_;
122 };
123
124 /// these three dictate the others
125 inline
126 bool operator==(LyXCursor const & a, LyXCursor const & b)
127 {
128         return (a.par() == b.par())
129                 && (a.pos() == b.pos())
130                 && a.boundary() == b.boundary();
131 }
132
133 inline
134 bool operator!=(LyXCursor const & a, LyXCursor const & b)
135 {
136         return !(a == b);
137 }
138
139 /// only compares y() and pos(). Can this be done in another way?
140 inline
141 bool operator<(LyXCursor const & a, LyXCursor const & b)
142 {
143         return (a.y() < b.y() && a.pos() < b.pos());
144 }
145
146 inline
147 bool operator>(LyXCursor const & a, LyXCursor const & b)
148 {
149         return b < a;
150 }
151
152 inline
153 bool operator>=(LyXCursor const & a, LyXCursor const & b)
154 {
155         return !(a < b);
156 }
157
158
159 inline
160 bool operator<=(LyXCursor const & a, LyXCursor const & b)
161 {
162         return !(a > b);
163 }
164
165 #endif // LYXCURSOR_H