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