]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
the AM_* flags patch
[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/convert.h"
27
28 #include <boost/assert.hpp>
29
30
31 // An updatable inset is highly editable by definition
32 InsetBase::EDITABLE UpdatableInset::editable() const
33 {
34         return HIGHLY_EDITABLE;
35 }
36
37
38 void UpdatableInset::scroll(BufferView & bv, double s) const
39 {
40         if (!s) {
41                 scx = 0;
42                 return;
43         }
44
45         int const workW = bv.workWidth();
46         int xo_ = theCoords.getInsets().x(this);
47         int const tmp_xo_ = xo_ - scx;
48
49         if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
50                 return;
51         if (s > 0.0 && xo_ > 0)
52                 return;
53
54         scx = int(s * workW / 2);
55
56 #ifdef WITH_WARNINGS
57 #warning metrics?
58 #endif
59         if (tmp_xo_ + scx + width() < workW / 2)
60                 scx = workW / 2 - tmp_xo_ - width();
61 }
62
63
64 void UpdatableInset::scroll(BufferView & bv, int offset) const
65 {
66         int const xo_ = theCoords.getInsets().x(this);
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 #ifdef WITH_WARNINGS
77 #warning metrics?
78 #endif
79                 if (!scx && xo_ + width() < bv.workWidth() - 20)
80                         return;
81                 if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
82                         scx += bv.workWidth() - width() - xo_ - 20;
83                 } else {
84                         scx += offset;
85                 }
86         }
87 }
88
89
90 void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
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(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
100                         else
101                                 scroll(cur.bv(), convert<int>(cmd.argument));
102                 } else
103                         cur.noUpdate();
104                 break;
105
106         default:
107                 InsetBase::dispatch(cur, cmd);
108         }
109 }
110
111
112 void UpdatableInset::getCursorDim(int &, int &) const
113 {
114         BOOST_ASSERT(false);
115 }