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