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"
19 #include "coordcache.h"
22 #include "dispatchresult.h"
23 #include "funcrequest.h"
26 #include "support/lstrings.h"
28 #include <boost/assert.hpp>
30 using lyx::support::strToDbl;
31 using lyx::support::strToInt;
35 // An updatable inset is highly editable by definition
36 InsetBase::EDITABLE UpdatableInset::editable() const
38 return HIGHLY_EDITABLE;
42 void UpdatableInset::scroll(BufferView & bv, float s) const
49 int const workW = bv.workWidth();
50 int xo_ = theCoords.insets_.x(this);
51 int const tmp_xo_ = xo_ - scx;
53 if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
58 scx = int(s * workW / 2);
63 if (tmp_xo_ + scx + width() < workW / 2)
64 scx = workW / 2 - tmp_xo_ - width();
68 void UpdatableInset::scroll(BufferView & bv, int offset) const
70 int const xo_ = theCoords.insets_.x(this);
72 if (!scx && xo_ >= 20)
74 if (xo_ + offset > 20)
81 if (!scx && xo_ + width() < bv.workWidth() - 20)
83 if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
84 scx += bv.workWidth() - width() - xo_ - 20;
92 void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
95 //case LFUN_MOUSE_RELEASE:
96 // return DispatchResult(editable() == IS_EDITABLE);
98 case LFUN_SCROLL_INSET:
99 if (cmd.argument.empty()) {
100 if (cmd.argument.find('.') != cmd.argument.npos)
101 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
103 scroll(cur.bv(), strToInt(cmd.argument));
109 InsetBase::dispatch(cur, cmd);
114 void UpdatableInset::getCursorDim(int &, int &) const