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