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