]> git.lyx.org Git - lyx.git/blob - src/cursor.C
7f7e4891e2ac82a71d29e09cb5d550ed687f4e3e
[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 Jürgen Vigna
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
24 using std::vector;
25 using std::endl;
26
27
28 DispatchResult Cursor::dispatch(FuncRequest const & cmd)
29 {
30         for (int i = data_.size() - 1; i >= 0; --i) {
31                 lyxerr << "trying to dispatch to inset" << data_[i].inset_ << endl;
32                 DispatchResult res = data_[i].inset_->dispatch(cmd);
33                 lyxerr << "   result: " << res.val() << endl;
34
35                 if (res == DISPATCHED) {
36                         //update();
37                         return DISPATCHED;
38                 }
39
40                 if (res == DISPATCHED_NOUPDATE)
41                         return DISPATCHED;
42
43                 lyxerr << "# unhandled result: " << res.val() << endl;
44         }
45         return UNDISPATCHED;
46 }
47
48
49 void buildCursor(Cursor & cursor, BufferView & bv)
50 {
51         UpdatableInset * inset = bv.theLockingInset();
52         lyxerr << "\nbuildCursor: " << inset << endl;
53         if (!inset)
54                 return;
55
56         inset = inset->getLockingInset();
57
58         bool ok = false;
59         ParIterator pit = bv.buffer()->par_iterator_begin();
60         ParIterator end = bv.buffer()->par_iterator_end();
61         for ( ; pit != end && !ok; ++pit) {
62                 InsetList::iterator     it = pit->insetlist.begin();
63                 InsetList::iterator     iend = pit->insetlist.end();
64                 for ( ; it != iend && !ok; ++it)
65                         if (it->inset == inset || it->inset == inset->owner())
66                                 ok = true;
67         }
68
69         if (!ok) {
70                 lyxerr << " tli not found! inset: " << inset << endl;
71                 return;
72         }
73
74         pit.asCursor(cursor);
75         for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) {
76                 lyxerr << " inset: " << cursor.data_[i].inset_
77                        << " idx: " << cursor.data_[i].idx_
78                        << " text: " << cursor.data_[i].text_
79                        << " par: " << cursor.data_[i].par_
80                        << " pos: " << cursor.data_[i].pos_
81                        << endl;
82         }
83 }