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 int UpdatableInset::scroll(bool) const
44 void UpdatableInset::setScroll(int maxwidth, double s) const
46 lyxerr << "UpdatableInset::setScroll: (int) " << maxwidth << std::endl;
52 int xo_ = theCoords.getInsets().x(this);
53 int const tmp_xo_ = xo_ - scx;
55 if (tmp_xo_ > 0 && tmp_xo_ + width() < maxwidth)
57 if (s > 0.0 && xo_ > 0)
60 scx = int(s * maxwidth / 2);
65 if (tmp_xo_ + scx + width() < maxwidth / 2)
66 scx = maxwidth / 2 - tmp_xo_ - width();
70 void UpdatableInset::setScroll(int maxwidth, int offset) const
72 lyxerr << "UpdatableInset::setScroll: (double) " << maxwidth << std::endl;
73 int const xo_ = theCoords.getInsets().x(this);
75 if (!scx && xo_ >= 20)
77 if (xo_ + offset > 20)
86 if (!scx && xo_ + width() < maxwidth - 20)
89 if (xo_ - scx + offset + width() < maxwidth - 20)
90 scx += maxwidth - width() - xo_ - 20;
97 void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
100 case LFUN_SCROLL_INSET:
101 if (cmd.argument.empty()) {
102 const int maxwidth = cur.bv().workWidth();
103 if (cmd.argument.find('.') != cmd.argument.npos)
104 setScroll(maxwidth, static_cast<float>(convert<double>(cmd.argument)));
106 setScroll(maxwidth, convert<int>(cmd.argument));
112 InsetBase::dispatch(cur, cmd);
117 void UpdatableInset::getCursorDim(int &, int &) const