1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 10:58:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "lyxinset.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyxinset.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "BufferView.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
#include "Painter.h"
|
2000-08-07 15:21:05 +00:00
|
|
|
#include "commandtags.h"
|
|
|
|
#include "support/lstrings.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
// Insets default methods
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
bool Inset::Deletable() const
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Inset::DirectWrite() const
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
Inset::EDITABLE Inset::Editable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return NOT_EDITABLE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void Inset::Validate(LaTeXFeatures &) const
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Inset::AutoDelete() const
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void Inset::Edit(BufferView *, int, int, unsigned int)
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXFont const Inset::ConvertFont(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return LyXFont(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const Inset::EditMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return _("Opened inset");
|
2000-04-04 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2000-07-07 15:00:56 +00:00
|
|
|
|
2001-02-22 14:09:20 +00:00
|
|
|
LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
|
2000-07-07 15:00:56 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
if (owner())
|
|
|
|
return owner()->getLyXText(bv, false);
|
|
|
|
else
|
|
|
|
return bv->text;
|
2000-07-07 15:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
// some stuff for inset locking
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
lyxerr.debug() << "Inset Button Press x=" << x
|
|
|
|
<< ", y=" << y << ", button=" << button << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
lyxerr.debug() << "Inset Button Release x=" << x
|
|
|
|
<< ", y=" << y << ", button=" << button << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UpdatableInset::InsetKeyPress(XKeyEvent *)
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
lyxerr.debug() << "Inset Keypress" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
lyxerr.debug() << "Inset Motion Notify x=" << x
|
|
|
|
<< ", y=" << y << ", state=" << state << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void UpdatableInset::InsetUnlock(BufferView *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
lyxerr.debug() << "Inset Unlock" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// An updatable inset is highly editable by definition
|
2000-03-08 13:52:57 +00:00
|
|
|
Inset::EDITABLE UpdatableInset::Editable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return HIGHLY_EDITABLE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void UpdatableInset::ToggleInsetCursor(BufferView *)
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2000-10-03 13:55:48 +00:00
|
|
|
void UpdatableInset::ShowInsetCursor(BufferView *, bool)
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void UpdatableInset::HideInsetCursor(BufferView *)
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void UpdatableInset::draw(BufferView *, LyXFont const &,
|
2001-04-04 20:34:04 +00:00
|
|
|
int /* baseline */, float & x,
|
|
|
|
bool/*cleared*/) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
x += float(scx);
|
|
|
|
// ATTENTION: don't do the following here!!!
|
|
|
|
// top_x = int(x);
|
|
|
|
// top_baseline = baseline;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool, bool )
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-04-26 17:47:40 +00:00
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
void UpdatableInset::scroll(BufferView * bv, float s) const
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
LyXFont font;
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
scx = 0;
|
|
|
|
return;
|
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
int const workW = bv->workWidth();
|
|
|
|
int const tmp_top_x = top_x - scx;
|
|
|
|
|
|
|
|
if (tmp_top_x > 0 &&
|
|
|
|
(tmp_top_x + width(bv, font)) < workW)
|
|
|
|
return;
|
|
|
|
if (s > 0 && top_x > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
|
|
|
|
//int const save_scx = scx;
|
2000-08-07 15:21:05 +00:00
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
scx = int(s * workW / 2);
|
|
|
|
// if (!display())
|
|
|
|
// scx += 20;
|
2000-08-07 15:21:05 +00:00
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
|
|
|
|
scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
|
|
|
|
}
|
2001-04-24 15:25:26 +00:00
|
|
|
|
|
|
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
2000-08-07 15:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatableInset::scroll(BufferView * bv, int offset) const
|
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
if (offset > 0) {
|
|
|
|
if (!scx && top_x >= 20)
|
|
|
|
return;
|
|
|
|
if ((top_x + offset) > 20)
|
|
|
|
scx = 0;
|
|
|
|
// scx += offset - (top_x - scx + offset - 20);
|
|
|
|
else
|
|
|
|
scx += offset;
|
2000-08-07 15:21:05 +00:00
|
|
|
} else {
|
2001-04-04 20:34:04 +00:00
|
|
|
LyXFont const font;
|
|
|
|
if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
|
|
|
|
return;
|
|
|
|
if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
|
|
|
|
scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
|
|
|
|
} else {
|
|
|
|
scx += offset;
|
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
2000-08-07 15:21:05 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
/// An updatable inset could handle lyx editing commands
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT
|
2000-08-07 15:21:05 +00:00
|
|
|
UpdatableInset::LocalDispatch(BufferView * bv,
|
2001-02-23 16:10:03 +00:00
|
|
|
kb_action action, string const & arg)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
|
|
|
|
if (arg.find('.') != arg.npos) {
|
|
|
|
float const xx = static_cast<float>(strToDbl(arg));
|
|
|
|
scroll(bv, xx);
|
|
|
|
} else {
|
|
|
|
int const xx = strToInt(arg);
|
|
|
|
scroll(bv, xx);
|
|
|
|
}
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
|
|
|
|
return DISPATCHED;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2001-04-04 20:34:04 +00:00
|
|
|
return UNDISPATCHED;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
if (owner())
|
|
|
|
return static_cast<UpdatableInset*>
|
|
|
|
(owner())->getMaxWidth(bv, this);
|
|
|
|
return bv->workWidth();
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|