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"
27 using lyx::support::strToDbl;
28 using lyx::support::strToInt;
31 // An updatable inset is highly editable by definition
32 InsetOld::EDITABLE UpdatableInset::editable() const
34 return HIGHLY_EDITABLE;
38 void UpdatableInset::fitInsetCursor(BufferView *) const
42 void UpdatableInset::scroll(BufferView * bv, float s) const
49 int const workW = bv->workWidth();
50 int const tmp_xo_ = xo_ - scx;
52 if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
57 scx = int(s * workW / 2);
60 if (tmp_xo_ + scx + width() < workW / 2)
61 scx = workW / 2 - tmp_xo_ - width();
65 void UpdatableInset::scroll(BufferView * bv, int offset) const
68 if (!scx && xo_ >= 20)
70 if (xo_ + offset > 20)
77 if (!scx && xo_ + width() < bv->workWidth() - 20)
79 if (xo_ - scx + offset + width() < bv->workWidth() - 20) {
80 scx += bv->workWidth() - width() - xo_ - 20;
88 /// An updatable inset could handle lyx editing commands
90 UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
93 case LFUN_MOUSE_RELEASE:
94 return DispatchResult(editable() == IS_EDITABLE);
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)));
101 scroll(cmd.view(), strToInt(cmd.argument));
102 cmd.view()->update();
103 return DispatchResult(true, true);
107 return DispatchResult(false);