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