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