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
|
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
#define SCROLL_INSET
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#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
|
|
|
#ifdef SCROLL_INSET
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* Insets default methods */
|
|
|
|
|
|
|
|
bool Inset::Deletable() const
|
|
|
|
{
|
2000-08-07 15:21:05 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Inset::DirectWrite() const
|
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Inset::AutoDelete() const
|
|
|
|
{
|
2000-08-07 15:21:05 +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)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
LyXFont Inset::ConvertFont(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-08-07 15:21:05 +00:00
|
|
|
return LyXFont(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
char const * Inset::EditMessage() const
|
|
|
|
{
|
2000-08-07 15:21:05 +00:00
|
|
|
return _("Opened inset");
|
2000-04-04 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2000-07-07 15:00:56 +00:00
|
|
|
|
|
|
|
LyXText * Inset::getLyXText(BufferView * bv) const
|
|
|
|
{
|
|
|
|
if (owner())
|
|
|
|
return owner()->getLyXText(bv);
|
|
|
|
else
|
|
|
|
return bv->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* some stuff for inset locking */
|
|
|
|
|
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
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
{
|
2000-08-07 15:21:05 +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 *)
|
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
{
|
2000-08-07 15:21:05 +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
|
|
|
{
|
2000-08-07 15:21:05 +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 *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void UpdatableInset::ShowInsetCursor(BufferView *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void UpdatableInset::HideInsetCursor(BufferView *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void UpdatableInset::draw(BufferView *, LyXFont const &,
|
2000-06-26 15:10:49 +00:00
|
|
|
int /* baseline */, float & x, bool/*cleared*/) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-08-07 15:21:05 +00:00
|
|
|
x += float(scx);
|
2000-05-15 14:49:36 +00:00
|
|
|
// ATTENTION: don't do the following here!!!
|
2000-04-20 13:48:34 +00:00
|
|
|
// top_x = int(x);
|
|
|
|
// top_baseline = baseline;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 16:05:26 +00:00
|
|
|
void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
#ifdef SCROLL_INSET
|
|
|
|
void UpdatableInset::scroll(BufferView * bv, float s) const
|
|
|
|
{
|
|
|
|
LyXFont font;
|
|
|
|
|
|
|
|
if (((top_x - scx) > 0) &&
|
|
|
|
(top_x - scx + width(bv, font)) < bv->workWidth())
|
|
|
|
return;
|
|
|
|
if ((s > 0) && (top_x > 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
|
|
|
|
int save_scx = scx;
|
|
|
|
|
|
|
|
scx = int(s*bv->workWidth()/2);
|
|
|
|
// if (!display())
|
|
|
|
// scx += 20;
|
|
|
|
|
|
|
|
if ((top_x - save_scx + scx + width(bv, font)) < (bv->workWidth()/2)) {
|
|
|
|
scx += (bv->workWidth()/2) - (top_x - save_scx + scx + width(bv,font));
|
|
|
|
}
|
|
|
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatableInset::scroll(BufferView * bv, int offset) const
|
|
|
|
{
|
|
|
|
if (offset > 0) {
|
|
|
|
if (!scx && top_x > 0)
|
|
|
|
return;
|
|
|
|
if ((top_x + offset) > 20)
|
|
|
|
scx += offset - (top_x - scx + offset - 20);
|
|
|
|
else
|
|
|
|
scx += offset;
|
|
|
|
} else {
|
|
|
|
LyXFont 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
/// An updatable inset could handle lyx editing commands
|
|
|
|
#ifdef SCROLL_INSET
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT
|
2000-08-07 15:21:05 +00:00
|
|
|
UpdatableInset::LocalDispatch(BufferView * bv,
|
2000-02-25 13:35:38 +00:00
|
|
|
int action, string const & arg)
|
2000-02-25 12:06:15 +00:00
|
|
|
#else
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
UpdatableInset::LocalDispatch(BufferView *, int, string const &)
|
2000-02-25 12:06:15 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#ifdef SCROLL_INSET
|
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
|
|
|
|
if (arg.find('.') != arg.npos) {
|
|
|
|
float xx = static_cast<float>(strToDbl(arg));
|
|
|
|
scroll(bv, xx);
|
|
|
|
} else {
|
|
|
|
int xx = strToInt(arg);
|
|
|
|
scroll(bv, xx);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
bv->updateInset(this, false);
|
|
|
|
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
#endif
|
|
|
|
return UNDISPATCHED;
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (owner())
|
2000-05-15 14:49:36 +00:00
|
|
|
return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
|
2000-03-08 13:52:57 +00:00
|
|
|
return pain.paperWidth();
|
|
|
|
}
|