]> git.lyx.org Git - lyx.git/blob - src/lyxcursor.h
Add a couple of new functions.
[lyx.git] / src / lyxcursor.h
1 // -*- C++ -*-
2 /**
3  * \file lyxcursor.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
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
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #ifndef LYXCURSOR_H
18 #define LYXCURSOR_H
19
20 #include "ParagraphList.h"
21 #include "support/types.h"
22
23 /**
24  * The cursor class describes the position of a cursor within a document.
25  * Several cursors exist within LyX; for example, when locking an inset,
26  * the position of the cursor in the containing inset is stored.
27  *
28  * FIXME: true ?
29  */
30 class LyXCursor {
31 public:
32         LyXCursor();
33         /// set the paragraph that contains this cursor
34         void par(ParagraphList::iterator pit);
35         /// return the paragraph this cursor is in
36         ParagraphList::iterator par() const;
37         /// set the position within the paragraph
38         void pos(lyx::pos_type p);
39         /// return the position within the paragraph
40         lyx::pos_type pos() const;
41         /// FIXME
42         void boundary(bool b);
43         /// FIXME
44         bool boundary() const;
45         /// set the x position in pixels
46         void x(int i);
47         /// return the x position in pixels
48         int x() const;
49         /// set the stored next-line position when at the end of a row
50         void ix(int i);
51         /**
52          * Return the x position of the start of the next row, when this
53          * cursor is at the end of the previous row, for insets that take
54          * a full row.
55          *
56          * FIXME: explain why we need this ?
57          */
58         int ix() const;
59         /// set the cached x position
60         void x_fix(int i);
61         /**
62          * Return the cached x position of the cursor. This is used for when
63          * we have text like :
64          *
65          * blah blah blah blah| blah blah blah
66          * blah blah blah
67          * blah blah blah blah blah blah
68          *
69          * When we move onto row 3, we would like to be vertically aligned
70          * with where we were in row 1, despite the fact that row 2 is
71          * shorter than x()
72          */
73         int x_fix() const;
74         /// set the y position in pixels
75         void y(int i);
76         /// return the y position in pixels
77         int y() const;
78         /// set the stored next-line y position when at the end of a row
79         void iy(int i);
80         /**
81          * Return the y position of the start of the next row, when this
82          * cursor is at the end of the previous row, for insets that take
83          * a full row.
84          *
85          * FIXME: explain why we need this ? especially for y...
86          */
87         int iy() const;
88 private:
89         /// The paragraph the cursor is in.
90         ParagraphList::iterator par_;
91         /// The position inside the paragraph
92         lyx::pos_type pos_;
93         /**
94          * When the cursor position is i, is the cursor is after the i-th char
95          * or before the i+1-th char ? Normally, these two interpretations are
96          * equivalent, except when the fonts of the i-th and i+1-th char
97          * differ.
98          * We use boundary_ to distinguish between the two options:
99          * If boundary_=true, then the cursor is after the i-th char
100          * and if boundary_=false, then the cursor is before the i+1-th char.
101          *
102          * We currently use the boundary only when the language direction of
103          * the i-th char is different than the one of the i+1-th char.
104          * In this case it is important to distinguish between the two
105          * cursor interpretations, in order to give a reasonable behavior to
106          * the user.
107          */
108         bool boundary_;
109         /// the pixel x position
110         int x_;
111         /// the stored next-row x position
112         int ix_;
113         /// the cached x position
114         int x_fix_;
115         /// the pixel y position
116         int y_;
117         /// the stored next-row y position
118         int iy_;
119 };
120
121 /// 
122 bool operator==(LyXCursor const & a, LyXCursor const & b);
123 ///
124 bool operator!=(LyXCursor const & a, LyXCursor const & b);
125
126 #endif // LYXCURSOR_H