]> git.lyx.org Git - lyx.git/blob - src/cursor.h
Overhaul the branches code.
[lyx.git] / src / cursor.h
1 // -*- C++ -*-
2 /**
3  * \file cursor.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 CURSOR_H
13 #define CURSOR_H
14
15 #include "textcursor.h"
16
17 #include "support/types.h"
18
19 #include <iosfwd>
20 #include <vector>
21
22 class BufferView;
23 class UpdatableInset;
24 class DispatchResult;
25 class FuncRequest;
26 class LyXText;
27 class InsetTabular;
28
29
30 /**
31  * The cursor class describes the position of a cursor within a document.
32  */
33
34 class CursorItem {
35 public:
36         ///
37         CursorItem() : inset_(0), idx_(0), par_(0), pos_(0) {}
38         ///
39         explicit CursorItem(UpdatableInset * inset)
40                 : inset_(inset), idx_(0), par_(0), pos_(0)
41         {}
42         ///
43         LyXText * text() const;
44         ///
45         friend std::ostream & operator<<(std::ostream &, CursorItem const &);
46 public:
47         ///
48         UpdatableInset * inset_;
49         ///
50         int idx_;
51         ///
52         int par_;
53         ///
54         int pos_;
55 };
56
57
58 class LCursor {
59 public:
60         /// create 'empty' cursor
61         explicit LCursor(BufferView * bv);
62         /// dispatch from innermost inset upwards
63         DispatchResult dispatch(FuncRequest const & cmd);
64         ///
65         void push(UpdatableInset * inset);
66         /// restrict cursor nesting to given size
67         void pop(int depth);
68         /// pop one level off the cursor
69         void pop();
70         ///
71         UpdatableInset * innerInset() const;
72         ///
73         UpdatableInset * innerInsetOfType(int code) const;
74         ///
75         InsetTabular * innerInsetTabular() const;
76         ///
77         LyXText * innerText() const;
78         /// returns x,y position
79         void getPos(int & x, int & y) const;
80         /// returns cursor dimension
81         void getDim(int & asc, int & desc) const;
82         /// cache the absolute coordinate from the top inset
83         void updatePos();
84         ///
85         friend std::ostream & operator<<(std::ostream &, LCursor const &);
86 public:
87         /// mainly used as stack, but wee need random access
88         std::vector<CursorItem> data_;
89         ///
90         BufferView * bv_;
91 private:
92         ///
93         int cached_y_;
94 };
95
96 #endif // LYXCURSOR_H