]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
eb68e226db539b46c313eec9bfe510c0f419d906
[lyx.git] / src / insets / updatableinset.C
1 /**
2  * \file updatableinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Matthias Ettrich
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "updatableinset.h"
17
18 #include "BufferView.h"
19 #include "coordcache.h"
20 #include "cursor.h"
21 #include "debug.h"
22 #include "dispatchresult.h"
23 #include "funcrequest.h"
24 #include "lyxtext.h"
25
26 #include "support/lstrings.h"
27
28 #include <boost/assert.hpp>
29
30 using lyx::support::strToDbl;
31 using lyx::support::strToInt;
32
33
34
35 // An updatable inset is highly editable by definition
36 InsetBase::EDITABLE UpdatableInset::editable() const
37 {
38         return HIGHLY_EDITABLE;
39 }
40
41
42 void UpdatableInset::scroll(BufferView & bv, float s) const
43 {
44         if (!s) {
45                 scx = 0;
46                 return;
47         }
48
49         int const workW = bv.workWidth();
50         int xo_ = theCoords.insets_.x(this);
51         int const tmp_xo_ = xo_ - scx;
52
53         if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
54                 return;
55         if (s > 0 && xo_ > 0)
56                 return;
57
58         scx = int(s * workW / 2);
59
60 #ifdef WITH_WARNINGS
61 #warning metrics?
62 #endif
63         if (tmp_xo_ + scx + width() < workW / 2)
64                 scx = workW / 2 - tmp_xo_ - width();
65 }
66
67
68 void UpdatableInset::scroll(BufferView & bv, int offset) const
69 {
70         int const xo_ = theCoords.insets_.x(this);
71         if (offset > 0) {
72                 if (!scx && xo_ >= 20)
73                         return;
74                 if (xo_ + offset > 20)
75                         scx = 0;
76                 // scx = - xo_;
77                 else
78                         scx += offset;
79         } else {
80 #ifdef WITH_WARNINGS
81 #warning metrics?
82 #endif
83                 if (!scx && xo_ + width() < bv.workWidth() - 20)
84                         return;
85                 if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
86                         scx += bv.workWidth() - width() - xo_ - 20;
87                 } else {
88                         scx += offset;
89                 }
90         }
91 }
92
93
94 void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
95 {
96         switch (cmd.action) {
97         //case LFUN_MOUSE_RELEASE:
98         //      return DispatchResult(editable() == IS_EDITABLE);
99
100         case LFUN_SCROLL_INSET:
101                 if (cmd.argument.empty()) {
102                         if (cmd.argument.find('.') != cmd.argument.npos)
103                                 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
104                         else
105                                 scroll(cur.bv(), strToInt(cmd.argument));
106                         cur.bv().update();
107                 }
108                 break;
109
110         default:
111                 InsetBase::dispatch(cur, cmd);
112         }
113 }
114
115
116 void UpdatableInset::getCursorDim(int &, int &) const
117 {
118         BOOST_ASSERT(false);
119 }