2003-02-20 17:50:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* \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
|
2003-08-19 10:04:35 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-02-20 17:50:06 +00:00
|
|
|
|
* \author Matthias Ettrich
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-20 17:50:06 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
|
|
|
|
#include "updatableinset.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-08-14 14:03:42 +00:00
|
|
|
|
#include "coordcache.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-02-20 17:39:48 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-02-20 17:39:48 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include "support/convert.h"
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
2003-11-13 08:50:26 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
|
// An updatable inset is highly editable by definition
|
2004-11-25 19:13:07 +00:00
|
|
|
|
InsetBase::EDITABLE UpdatableInset::editable() const
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
void UpdatableInset::scroll(BufferView & bv, double s) const
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!s) {
|
|
|
|
|
scx = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
int const workW = bv.workWidth();
|
2005-01-31 16:29:48 +00:00
|
|
|
|
int xo_ = theCoords.getInsets().x(this);
|
2003-11-10 15:38:20 +00:00
|
|
|
|
int const tmp_xo_ = xo_ - scx;
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
2005-01-27 21:05:44 +00:00
|
|
|
|
if (s > 0.0 && xo_ > 0)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
scx = int(s * workW / 2);
|
|
|
|
|
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (tmp_xo_ + scx + width() < workW / 2)
|
|
|
|
|
scx = workW / 2 - tmp_xo_ - width();
|
2003-02-20 17:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
void UpdatableInset::scroll(BufferView & bv, int offset) const
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
2005-01-31 16:29:48 +00:00
|
|
|
|
int const xo_ = theCoords.getInsets().x(this);
|
2003-02-20 17:39:48 +00:00
|
|
|
|
if (offset > 0) {
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (!scx && xo_ >= 20)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (xo_ + offset > 20)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
scx = 0;
|
2003-11-10 15:38:20 +00:00
|
|
|
|
// scx = - xo_;
|
2003-02-20 17:39:48 +00:00
|
|
|
|
else
|
|
|
|
|
scx += offset;
|
|
|
|
|
} else {
|
2005-01-18 14:15:57 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
2005-01-18 14:15:57 +00:00
|
|
|
|
#endif
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (!scx && xo_ + width() < bv.workWidth() - 20)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
|
|
|
|
|
scx += bv.workWidth() - width() - xo_ - 20;
|
2003-02-20 17:39:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
scx += offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
switch (cmd.action) {
|
2004-02-16 11:58:51 +00:00
|
|
|
|
//case LFUN_MOUSE_RELEASE:
|
|
|
|
|
// return DispatchResult(editable() == IS_EDITABLE);
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
case LFUN_SCROLL_INSET:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (cmd.argument.empty()) {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (cmd.argument.find('.') != cmd.argument.npos)
|
2005-01-27 21:05:44 +00:00
|
|
|
|
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
|
2003-11-10 09:06:48 +00:00
|
|
|
|
else
|
2005-01-27 21:05:44 +00:00
|
|
|
|
scroll(cur.bv(), convert<int>(cmd.argument));
|
2005-05-09 17:29:22 +00:00
|
|
|
|
} else
|
|
|
|
|
cur.noUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
default:
|
2004-11-25 19:13:07 +00:00
|
|
|
|
InsetBase::dispatch(cur, cmd);
|
2003-02-20 17:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-13 08:50:26 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-21 14:59:24 +00:00
|
|
|
|
void UpdatableInset::getCursorDim(int &, int &) const
|
2003-11-13 08:50:26 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
|
}
|