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/convert.h"
28 #include <boost/assert.hpp>
31 // An updatable inset is highly editable by definition
32 InsetBase::EDITABLE UpdatableInset::editable() const
34 return HIGHLY_EDITABLE;
38 void UpdatableInset::scroll(BufferView & bv, double s) const
45 int const workW = bv.workWidth();
46 int xo_ = theCoords.getInsets().x(this);
47 int const tmp_xo_ = xo_ - scx;
49 if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
51 if (s > 0.0 && xo_ > 0)
54 scx = int(s * workW / 2);
59 if (tmp_xo_ + scx + width() < workW / 2)
60 scx = workW / 2 - tmp_xo_ - width();
64 void UpdatableInset::scroll(BufferView & bv, int offset) const
66 int const xo_ = theCoords.getInsets().x(this);
68 if (!scx && xo_ >= 20)
70 if (xo_ + offset > 20)
79 if (!scx && xo_ + width() < bv.workWidth() - 20)
81 if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
82 scx += bv.workWidth() - width() - xo_ - 20;
90 void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
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(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
101 scroll(cur.bv(), convert<int>(cmd.argument));
107 InsetBase::dispatch(cur, cmd);
112 void UpdatableInset::getCursorDim(int &, int &) const