]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
removing update calls
[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 "debug.h"
20 #include "dispatchresult.h"
21 #include "funcrequest.h"
22 #include "lyxtext.h"
23
24 #include "support/lstrings.h"
25
26
27 using lyx::support::strToDbl;
28 using lyx::support::strToInt;
29
30
31 // An updatable inset is highly editable by definition
32 InsetOld::EDITABLE UpdatableInset::editable() const
33 {
34         return HIGHLY_EDITABLE;
35 }
36
37
38 void UpdatableInset::fitInsetCursor(BufferView *) const
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 const tmp_xo_ = xo_ - scx;
51
52         if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
53                 return;
54         if (s > 0 && xo_ > 0)
55                 return;
56
57         scx = int(s * workW / 2);
58
59 #warning metrics?
60         if (tmp_xo_ + scx + width() < workW / 2)
61                 scx = workW / 2 - tmp_xo_ - width();
62 }
63
64
65 void UpdatableInset::scroll(BufferView * bv, int offset) const
66 {
67         if (offset > 0) {
68                 if (!scx && xo_ >= 20)
69                         return;
70                 if (xo_ + offset > 20)
71                         scx = 0;
72                 // scx = - xo_;
73                 else
74                         scx += offset;
75         } else {
76 #warning metrics?
77                 if (!scx && xo_ + width() < bv->workWidth() - 20)
78                         return;
79                 if (xo_ - scx + offset + width() < bv->workWidth() - 20) {
80                         scx += bv->workWidth() - width() - xo_ - 20;
81                 } else {
82                         scx += offset;
83                 }
84         }
85 }
86
87
88 ///  An updatable inset could handle lyx editing commands
89 DispatchResult
90 UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
91 {
92         switch (cmd.action) {
93         case LFUN_MOUSE_RELEASE:
94                 return DispatchResult(editable() == IS_EDITABLE);
95
96         case LFUN_SCROLL_INSET:
97                 if (!cmd.argument.empty()) {
98                         if (cmd.argument.find('.') != cmd.argument.npos)
99                                 scroll(cmd.view(), static_cast<float>(strToDbl(cmd.argument)));
100                         else
101                                 scroll(cmd.view(), strToInt(cmd.argument));
102                         cmd.view()->update();
103                         return DispatchResult(true, true);
104                 }
105
106         default:
107                 return DispatchResult(false);
108         }
109 }