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
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 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__
|
2001-06-25 00:06:33 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "inset.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"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "lyxfont.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "lyxcursor.h"
|
|
|
|
#include "lyxtext.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
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
// Initialization of the counter for the inset id's,
|
|
|
|
unsigned int Inset::inset_id = 0;
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
Inset::Inset()
|
|
|
|
: top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0),
|
|
|
|
background_color_(LColor::inherit)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
Inset::Inset(Inset const & in, bool same_id)
|
2001-07-24 22:08:49 +00:00
|
|
|
: top_x(0), top_baseline(0), scx(0), owner_(0), name_(in.name_),
|
2001-07-24 15:07:09 +00:00
|
|
|
background_color_(in.background_color_)
|
|
|
|
{
|
|
|
|
if (same_id)
|
|
|
|
id_ = in.id();
|
|
|
|
else
|
|
|
|
id_ = inset_id++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool Inset::deletable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool Inset::directWrite() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void Inset::validate(LaTeXFeatures &) const
|
2001-04-04 20:34:04 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool Inset::autoDelete() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-04 20:34:04 +00:00
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void Inset::edit(BufferView *, bool)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
#if 0
|
2001-06-28 10:25:20 +00:00
|
|
|
LyXFont const Inset::convertFont(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-03 18:28:11 +00:00
|
|
|
#if 1
|
|
|
|
return font;
|
|
|
|
#else
|
2001-04-04 20:34:04 +00:00
|
|
|
return LyXFont(font);
|
2001-08-03 18:28:11 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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-07-24 10:13:19 +00:00
|
|
|
void Inset::setBackgroundColor(LColor::color color)
|
|
|
|
{
|
|
|
|
background_color_ = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LColor::color Inset::backgroundColor() const
|
|
|
|
{
|
|
|
|
if (background_color_ == LColor::inherit) {
|
|
|
|
if (owner())
|
|
|
|
return owner()->backgroundColor();
|
|
|
|
else
|
|
|
|
return LColor::background;
|
|
|
|
} else
|
|
|
|
return background_color_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
int Inset::id() const
|
|
|
|
{
|
|
|
|
return id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inset::id(int id_arg)
|
|
|
|
{
|
|
|
|
id_ = id_arg;
|
|
|
|
}
|
|
|
|
|
2001-08-01 15:42:53 +00:00
|
|
|
void Inset::setFont(BufferView *, LyXFont const &, bool, bool )
|
|
|
|
{}
|
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
// some stuff for inset locking
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
UpdatableInset::UpdatableInset()
|
|
|
|
: Inset(), cursor_visible_(false), block_drawing_(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
|
|
|
|
: Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Inset Button Press x=" << x
|
2001-04-04 20:34:04 +00:00
|
|
|
<< ", y=" << y << ", button=" << button << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Inset Button Release x=" << x
|
2001-04-04 20:34:04 +00:00
|
|
|
<< ", y=" << y << ", button=" << button << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void UpdatableInset::insetKeyPress(XKeyEvent *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Inset Keypress" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
|
2001-04-04 20:34:04 +00:00
|
|
|
<< ", y=" << y << ", state=" << state << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void UpdatableInset::insetUnlock(BufferView *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Inset Unlock" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// An updatable inset is highly editable by definition
|
2001-06-28 10:25:20 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void UpdatableInset::fitInsetCursor(BufferView *) const
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void UpdatableInset::edit(BufferView *, bool)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2001-06-28 10:25:20 +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
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
LyXCursor const & Inset::cursor(BufferView * bv) const
|
|
|
|
{
|
|
|
|
return bv->text->cursor;
|
|
|
|
}
|
2001-07-17 15:39:12 +00:00
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
string const UpdatableInset::selectNextWord(BufferView *bv,
|
|
|
|
float & value) const
|
2001-07-17 15:39:12 +00:00
|
|
|
{
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
|
|
value = 0;
|
|
|
|
return string();
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
bool UpdatableInset::searchForward(BufferView * bv, string const &,
|
|
|
|
bool const &, bool const &)
|
|
|
|
{
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
bool UpdatableInset::searchBackward(BufferView * bv, string const &,
|
|
|
|
bool const &, bool const &)
|
|
|
|
{
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
|
|
return false;
|
|
|
|
}
|