]> git.lyx.org Git - lyx.git/blob - src/cursor_slice.h
303a0e39cddc5c1f02d8a63c2a4c64d1820f15f8
[lyx.git] / src / cursor_slice.h
1 // -*- C++ -*-
2 /**
3  * \file cursor_slice.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 CURSORSLICE_H
18 #define CURSORSLICE_H
19
20 #include <iosfwd>
21 #include <cstddef>
22
23 #include "support/types.h"
24
25 class BufferView;
26 class InsetBase;
27 class MathInset;
28 class MathArray;
29 class LyXText;
30 class UpdatableInset;
31
32
33 /// This encapsulates a single slice of a document iterator as used e.g.
34 /// for cursors.
35
36 // After IU, the distinction of MathInset and UpdatableInset as well as
37 // that of MathArray and LyXText should vanish. They are conceptually the
38 // same (now...)
39
40 class CursorSlice {
41 public:
42         /// type for cell number in inset
43         typedef size_t idx_type;
44         /// type for paragraph numbers positions within a cell
45         typedef lyx::paroffset_type par_type;
46         /// type for cursor positions within a cell
47         typedef lyx::pos_type pos_type;
48         /// type for row indices
49         typedef size_t row_type;
50         /// type for col indices
51         typedef size_t col_type;
52
53         ///
54         CursorSlice();
55         ///
56         explicit CursorSlice(InsetBase *);
57
58         /// set the paragraph that contains this cursor
59         void idx(idx_type idx);
60         /// return the paragraph this cursor is in
61         idx_type idx() const;
62         /// return the paragraph this cursor is in
63         idx_type & idx();
64         /// set the paragraph that contains this cursor
65         void par(par_type par);
66         /// return the paragraph this cursor is in
67         par_type par() const;
68         /// return the paragraph this cursor is in
69         par_type & par();
70         /// set the position within the paragraph
71         void pos(pos_type pos);
72         /// return the position within the paragraph
73         pos_type pos() const;
74         /// return the position within the paragraph
75         pos_type & pos();
76         /// return the last position within the paragraph
77         pos_type lastpos() const;
78         /// return the grid row of the current cell
79         row_type row() const;
80         /// return the grid row of the current cell
81         col_type col() const;
82
83         /// FIXME
84         void boundary(bool b);
85         /// FIXME
86         bool boundary() const;
87         ///
88         /// texted specific stuff
89         ///
90         ///
91         LyXText * text() const;
92         ///
93         UpdatableInset * asUpdatableInset() const;
94
95         ///
96         /// mathed specific stuff
97         ///
98         /// returns cell corresponding to this position
99         MathArray & cell() const;
100         /// gets screen position of the thing
101         void getScreenPos(int & x, int & y) const;
102         ///
103         MathInset * asMathInset() const;
104
105         ///
106         friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
107 public:
108         /// pointer to an inset
109         InsetBase * inset_;
110         /// cell index of a position in this inset
111         idx_type idx_;
112         /// paragraph in this cell (used by texted)
113         par_type par_;
114         /// position in this cell
115         pos_type pos_;
116         /**
117          * When the cursor position is i, is the cursor is after the i-th char
118          * or before the i+1-th char ? Normally, these two interpretations are
119          * equivalent, except when the fonts of the i-th and i+1-th char
120          * differ.
121          * We use boundary_ to distinguish between the two options:
122          * If boundary_=true, then the cursor is after the i-th char
123          * and if boundary_=false, then the cursor is before the i+1-th char.
124          *
125          * We currently use the boundary only when the language direction of
126          * the i-th char is different than the one of the i+1-th char.
127          * In this case it is important to distinguish between the two
128          * cursor interpretations, in order to give a reasonable behavior to
129          * the user.
130          */
131         bool boundary_;
132 };
133
134 /// test for equality
135 bool operator==(CursorSlice const &, CursorSlice const &);
136 /// test for inequality
137 bool operator!=(CursorSlice const &, CursorSlice const &);
138 /// test for order
139 bool operator<(CursorSlice const &, CursorSlice const &);
140 /// test for order
141 bool operator>(CursorSlice const &, CursorSlice const &);
142
143 #include <vector>
144
145
146 // this is used for traversing math insets
147 typedef std::vector<CursorSlice> CursorBase;
148 /// move on one step
149 void increment(CursorBase &);
150 ///
151 CursorBase ibegin(InsetBase * p);
152 ///
153 CursorBase iend(InsetBase * p);
154 ///
155 CursorSlice & cursorTip(BufferView &);
156
157
158
159 #endif