]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
convert graphics for .tex export, fixes bug 1231
[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 "cursor.h"
20 #include "debug.h"
21 #include "dispatchresult.h"
22 #include "funcrequest.h"
23 #include "lyxtext.h"
24
25 #include "support/lstrings.h"
26
27 #include <boost/assert.hpp>
28
29 using lyx::support::strToDbl;
30 using lyx::support::strToInt;
31
32
33
34 // An updatable inset is highly editable by definition
35 InsetOld::EDITABLE UpdatableInset::editable() const
36 {
37         return HIGHLY_EDITABLE;
38 }
39
40
41 void UpdatableInset::scroll(BufferView & bv, float s) const
42 {
43         if (!s) {
44                 scx = 0;
45                 return;
46         }
47
48         int const workW = bv.workWidth();
49         int const tmp_xo_ = xo_ - scx;
50
51         if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
52                 return;
53         if (s > 0 && xo_ > 0)
54                 return;
55
56         scx = int(s * workW / 2);
57
58 #ifdef WITH_WARNINGS
59 #warning metrics?
60 #endif
61         if (tmp_xo_ + scx + width() < workW / 2)
62                 scx = workW / 2 - tmp_xo_ - width();
63 }
64
65
66 void UpdatableInset::scroll(BufferView & bv, int offset) const
67 {
68         if (offset > 0) {
69                 if (!scx && xo_ >= 20)
70                         return;
71                 if (xo_ + offset > 20)
72                         scx = 0;
73                 // scx = - xo_;
74                 else
75                         scx += offset;
76         } else {
77 #warning metrics?
78                 if (!scx && xo_ + width() < bv.workWidth() - 20)
79                         return;
80                 if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
81                         scx += bv.workWidth() - width() - xo_ - 20;
82                 } else {
83                         scx += offset;
84                 }
85         }
86 }
87
88
89 void UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
90 {
91         switch (cmd.action) {
92         //case LFUN_MOUSE_RELEASE:
93         //      return DispatchResult(editable() == IS_EDITABLE);
94
95         case LFUN_SCROLL_INSET:
96                 if (cmd.argument.empty()) {
97                         if (cmd.argument.find('.') != cmd.argument.npos)
98                                 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
99                         else
100                                 scroll(cur.bv(), strToInt(cmd.argument));
101                         cur.bv().update();
102                 }
103                 break;
104
105         default:
106                 InsetOld::dispatch(cur, cmd);
107         }
108 }
109
110
111 void UpdatableInset::getCursorDim(int &, int &) const
112 {
113         BOOST_ASSERT(false);
114 }