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