lyx_mirror/src/insets/updatableinset.C
Georg Baum 92379230ff remove unneeded calls to BufferView::update() in insets
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9925 a592a061-630c-0410-9148-cb99ea01b6c8
2005-05-09 17:29:22 +00:00

116 lines
2.2 KiB
C

/**
* \file updatableinset.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
* \author Jürgen Vigna
* \author Lars Gullik Bjønnes
* \author Matthias Ettrich
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "updatableinset.h"
#include "BufferView.h"
#include "coordcache.h"
#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "lyxtext.h"
#include "support/convert.h"
#include <boost/assert.hpp>
// An updatable inset is highly editable by definition
InsetBase::EDITABLE UpdatableInset::editable() const
{
return HIGHLY_EDITABLE;
}
void UpdatableInset::scroll(BufferView & bv, double s) const
{
if (!s) {
scx = 0;
return;
}
int const workW = bv.workWidth();
int xo_ = theCoords.getInsets().x(this);
int const tmp_xo_ = xo_ - scx;
if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
return;
if (s > 0.0 && xo_ > 0)
return;
scx = int(s * workW / 2);
#ifdef WITH_WARNINGS
#warning metrics?
#endif
if (tmp_xo_ + scx + width() < workW / 2)
scx = workW / 2 - tmp_xo_ - width();
}
void UpdatableInset::scroll(BufferView & bv, int offset) const
{
int const xo_ = theCoords.getInsets().x(this);
if (offset > 0) {
if (!scx && xo_ >= 20)
return;
if (xo_ + offset > 20)
scx = 0;
// scx = - xo_;
else
scx += offset;
} else {
#ifdef WITH_WARNINGS
#warning metrics?
#endif
if (!scx && xo_ + width() < bv.workWidth() - 20)
return;
if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
scx += bv.workWidth() - width() - xo_ - 20;
} else {
scx += offset;
}
}
}
void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
//case LFUN_MOUSE_RELEASE:
// return DispatchResult(editable() == IS_EDITABLE);
case LFUN_SCROLL_INSET:
if (cmd.argument.empty()) {
if (cmd.argument.find('.') != cmd.argument.npos)
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
else
scroll(cur.bv(), convert<int>(cmd.argument));
} else
cur.noUpdate();
break;
default:
InsetBase::dispatch(cur, cmd);
}
}
void UpdatableInset::getCursorDim(int &, int &) const
{
BOOST_ASSERT(false);
}