2 * \file updatableinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Lars Gullik Bjønnes
9 * \author Matthias Ettrich
11 * Full author contact details are available in file CREDITS.
16 #include "updatableinset.h"
18 #include "BufferView.h"
20 #include "dispatchresult.h"
21 #include "funcrequest.h"
24 #include "support/lstrings.h"
26 #include <boost/assert.hpp>
29 using lyx::support::strToDbl;
30 using lyx::support::strToInt;
33 // An updatable inset is highly editable by definition
34 InsetOld::EDITABLE UpdatableInset::editable() const
36 return HIGHLY_EDITABLE;
40 void UpdatableInset::scroll(BufferView * bv, float s) const
47 int const workW = bv->workWidth();
48 int const tmp_xo_ = xo_ - scx;
50 if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
55 scx = int(s * workW / 2);
58 if (tmp_xo_ + scx + width() < workW / 2)
59 scx = workW / 2 - tmp_xo_ - width();
63 void UpdatableInset::scroll(BufferView * bv, int offset) const
66 if (!scx && xo_ >= 20)
68 if (xo_ + offset > 20)
75 if (!scx && xo_ + width() < bv->workWidth() - 20)
77 if (xo_ - scx + offset + width() < bv->workWidth() - 20) {
78 scx += bv->workWidth() - width() - xo_ - 20;
86 /// An updatable inset could handle lyx editing commands
88 UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
91 case LFUN_MOUSE_RELEASE:
92 return DispatchResult(editable() == IS_EDITABLE);
94 case LFUN_SCROLL_INSET:
95 if (!cmd.argument.empty()) {
96 if (cmd.argument.find('.') != cmd.argument.npos)
97 scroll(cmd.view(), static_cast<float>(strToDbl(cmd.argument)));
99 scroll(cmd.view(), strToInt(cmd.argument));
100 cmd.view()->update();
101 return DispatchResult(true, true);
105 return DispatchResult(false);
110 void UpdatableInset::getCursorDim(int &, int &) const