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"
|
|
|
|
|
#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
|
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2003-11-13 08:50:26 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::strToDbl;
|
|
|
|
|
using lyx::support::strToInt;
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// An updatable inset is highly editable by definition
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::EDITABLE UpdatableInset::editable() const
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UpdatableInset::scroll(BufferView * bv, float s) const
|
|
|
|
|
{
|
|
|
|
|
if (!s) {
|
|
|
|
|
scx = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int const workW = bv->workWidth();
|
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;
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (s > 0 && xo_ > 0)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
scx = int(s * workW / 2);
|
|
|
|
|
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
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
|
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
|
void UpdatableInset::scroll(BufferView * bv, int offset) const
|
|
|
|
|
{
|
|
|
|
|
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 {
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (!scx && xo_ + width() < bv->workWidth() - 20)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
return;
|
2003-11-10 15:38:20 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// An updatable inset could handle lyx editing commands
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2003-11-10 09:06:48 +00:00
|
|
|
|
UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2003-11-01 15:45:19 +00:00
|
|
|
|
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:
|
|
|
|
|
if (!cmd.argument.empty()) {
|
|
|
|
|
if (cmd.argument.find('.') != cmd.argument.npos)
|
|
|
|
|
scroll(cmd.view(), static_cast<float>(strToDbl(cmd.argument)));
|
|
|
|
|
else
|
|
|
|
|
scroll(cmd.view(), strToInt(cmd.argument));
|
2003-11-10 13:23:14 +00:00
|
|
|
|
cmd.view()->update();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-02-20 17:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
default:
|
|
|
|
|
return DispatchResult(false);
|
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);
|
|
|
|
|
}
|