]> git.lyx.org Git - features.git/blob - src/cursor_slice.h
some renaming + safety stuff
[features.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
49         ///
50         CursorSlice();
51         ///
52         explicit CursorSlice(InsetBase *);
53
54         /// set the paragraph that contains this cursor
55         void idx(idx_type idx);
56         /// return the paragraph this cursor is in
57         idx_type idx() const;
58         /// set the paragraph that contains this cursor
59         void par(par_type par);
60         /// return the paragraph this cursor is in
61         par_type par() const;
62         /// set the position within the paragraph
63         void pos(pos_type pos);
64         /// return the position within the paragraph
65         pos_type pos() const;
66
67         /// FIXME
68         void boundary(bool b);
69         /// FIXME
70         bool boundary() const;
71         ///
72         /// texted specific stuff
73         ///
74         ///
75         LyXText * text() const;
76         ///
77         UpdatableInset * asUpdatableInset() const;
78
79         ///
80         /// mathed specific stuff
81         ///
82         /// returns cell corresponding to this position
83         MathArray & cell() const;
84         /// set cell corresponding to this position
85         void cell(idx_type idx) const;
86         /// gets screen position of the thing
87         void getScreenPos(int & x, int & y) const;
88         ///
89         MathInset * asMathInset() const;
90
91         ///
92         friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
93 public:
94         /// pointer to an inset
95         InsetBase * inset_;
96         /// cell index of a position in this inset
97         idx_type idx_;
98         /// paragraph in this cell (used by texted)
99         par_type par_;
100         /// position in this cell
101         pos_type pos_;
102         /**
103          * When the cursor position is i, is the cursor is after the i-th char
104          * or before the i+1-th char ? Normally, these two interpretations are
105          * equivalent, except when the fonts of the i-th and i+1-th char
106          * differ.
107          * We use boundary_ to distinguish between the two options:
108          * If boundary_=true, then the cursor is after the i-th char
109          * and if boundary_=false, then the cursor is before the i+1-th char.
110          *
111          * We currently use the boundary only when the language direction of
112          * the i-th char is different than the one of the i+1-th char.
113          * In this case it is important to distinguish between the two
114          * cursor interpretations, in order to give a reasonable behavior to
115          * the user.
116          */
117         bool boundary_;
118 };
119
120 /// test for equality
121 bool operator==(CursorSlice const &, CursorSlice const &);
122 /// test for inequality
123 bool operator!=(CursorSlice const &, CursorSlice const &);
124 /// test for order
125 bool operator<(CursorSlice const &, CursorSlice const &);
126 /// test for order
127 bool operator>(CursorSlice const &, CursorSlice const &);
128
129 #include <vector>
130
131
132 // this is used for traversing math insets
133 typedef std::vector<CursorSlice> CursorBase;
134 /// move on one step
135 void increment(CursorBase &);
136 ///
137 CursorBase ibegin(InsetBase * p);
138 ///
139 CursorBase iend(InsetBase * p);
140 ///
141 CursorSlice & cursorTip(BufferView &);
142
143
144
145 #endif