]> git.lyx.org Git - lyx.git/blob - src/cursor_slice.h
6824916a3765363ec61f493840a720cd9c20b39a
[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 André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CURSORSLICE_H
13 #define CURSORSLICE_H
14
15 #include <iosfwd>
16 #include <cstddef>
17
18 class InsetBase;
19 class UpdatableInset;
20 class MathInset;
21 class LyXText;
22 class MathArray;
23
24
25 /// This encapsulates a single slice of a document iterator as used e.g.
26 /// for cursors.
27
28 // After IU, the distinction of MathInset and UpdatableInset as well as
29 // that of MathArray and LyXText should vanish. They are conceptually the
30 // same (now...)
31
32 class CursorSlice {
33 public:
34         /// type for cell number in inset
35         typedef size_t idx_type;
36         /// type for paragraph numbers positions within a cell
37         typedef size_t par_type;
38         /// type for cursor positions within a cell
39         typedef size_t pos_type;
40
41         ///
42         CursorSlice();
43         ///
44         explicit CursorSlice(InsetBase *);
45
46         ///
47         /// texted specific stuff
48         ///
49         ///
50         LyXText * text() const;
51         ///
52         UpdatableInset * asUpdatableInset() const;
53
54         ///
55         /// mathed specific stuff
56         ///
57         /// returns cell corresponding to this position
58         MathArray & cell() const;
59         /// returns cell corresponding to this position
60         MathArray & cell(idx_type idx) const;
61         /// gets screen position of the thing
62         void getPos(int & x, int & y) const;
63         /// set position
64         void setPos(int pos);
65         ///
66         MathInset * asMathInset() const;
67
68         ///
69         friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
70 public:
71         /// pointer to an inset
72         InsetBase * inset_;
73         /// cell index of a position in this inset
74         idx_type idx_;
75         /// paragraph in this cell (used by texted)
76         par_type par_;
77         /// position in this cell
78         pos_type pos_;
79 };
80
81 /// test for equality
82 bool operator==(CursorSlice const &, CursorSlice const &);
83 /// test for inequality
84 bool operator!=(CursorSlice const &, CursorSlice const &);
85 /// test for order
86 bool operator<(CursorSlice const &, CursorSlice const &);
87
88 #endif