]> git.lyx.org Git - lyx.git/blob - src/cursor.C
d823670c4cc722e7705175b3deb73e7d1ecf3e73
[lyx.git] / src / cursor.C
1 /**
2  * \file cursor.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "buffer.h"
14 #include "BufferView.h"
15 #include "cursor.h"
16 #include "debug.h"
17 #include "dispatchresult.h"
18 #include "iterators.h"
19 #include "lyxtext.h"
20 #include "paragraph.h"
21
22 #include "insets/updatableinset.h"
23 #include "insets/insettext.h"
24
25 #include <boost/assert.hpp>
26
27 using std::vector;
28 using std::endl;
29
30
31 std::ostream & operator<<(std::ostream & os, CursorItem const & item)
32 {
33         os << " inset: " << item.inset_
34            << " idx: " << item.idx_
35            << " text: " << item.text_
36            << " par: " << item.par_
37            << " pos: " << item.pos_;
38         return os;
39 }
40
41
42 std::ostream & operator<<(std::ostream & os, LCursor const & cursor)
43 {
44         for (size_t i = 0, n = cursor.data_.size(); i != n; ++i)
45                 os << "   " << cursor.data_[i];
46         return os;
47 }
48
49
50 DispatchResult LCursor::dispatch(FuncRequest const & cmd)
51 {
52         for (int i = data_.size() - 1; i >= 0; --i) {
53                 CursorItem & citem = data_[i];
54
55                 lyxerr << "trying to dispatch to inset" << citem.inset_ << endl;
56                 DispatchResult res = citem.inset_->dispatch(cmd);
57                 lyxerr << "   result: " << res.val() << endl;
58
59                 switch (res.val()) {
60                         case FINISHED:
61                                 pop();
62                                 return DispatchResult(true, true);
63
64                         case FINISHED_RIGHT: {
65                                 pop();
66                                 //InsetText * inset = static_cast<InsetText *>(innerInset());
67                                 //if (inset)
68                                 //      inset->moveRightIntern(bv_, false, false);
69                                 //else
70                                 //      bv_->text->cursorRight(bv_);
71                                 innerText()->cursorRight(bv_);
72                                 return DispatchResult(true);
73                         }
74
75                         case FINISHED_UP: {
76                                 pop();
77                                 //InsetText * inset = static_cast<InsetText *>(inset());
78                                 //if (inset)
79                                 //      result = inset->moveUp(bv);
80                                 return DispatchResult(true);
81                         }
82
83                         case FINISHED_DOWN: {
84                                 pop();
85                                 //InsetText * inset = static_cast<InsetText *>(inset());
86                                 //if (inset)
87                                 //      result = inset->moveDown(bv);
88                                 return DispatchResult(true);
89                         }
90
91                         default:
92                                 break;
93                 }
94
95                 lyxerr << "# unhandled result: " << res.val() << endl;
96         }
97
98         lyxerr << "trying to dispatch to main text " << bv_->text << endl;
99         DispatchResult res = bv_->text->dispatch(cmd);
100         lyxerr << "   result: " << res.val() << endl;
101         return res;
102 }
103
104
105 LCursor::LCursor(BufferView * bv)
106         : bv_(bv)
107 {}
108
109
110 void LCursor::push(InsetOld * inset, LyXText * text)
111 {
112         data_.push_back(CursorItem(inset, text));
113 }
114
115
116 void LCursor::pop()
117 {
118         BOOST_ASSERT(!data_.empty());
119         data_.pop_back();
120 }
121
122
123 InsetOld * LCursor::innerInset() const
124 {
125         return data_.empty() ? 0 : data_.back().inset_;
126 }
127
128
129 LyXText * LCursor::innerText() const
130 {
131         return data_.empty() ? bv_->text : data_.back().text_;
132 }