2000-03-08 13:52:57 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-03-14 14:53:55 +00:00
|
|
|
* Copyright 1998-2001 The LyX Team.
|
2000-03-08 13:52:57 +00:00
|
|
|
*
|
2000-06-28 16:03:01 +00:00
|
|
|
* ======================================================
|
|
|
|
*/
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetcollapsable.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Painter.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
#include "insets/insettext.h"
|
2000-04-24 20:58:23 +00:00
|
|
|
#include "support/LOstream.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
#include "debug.h"
|
2000-07-07 07:46:37 +00:00
|
|
|
#include "lyxtext.h"
|
2001-07-24 09:12:20 +00:00
|
|
|
#include "font.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
class LyXText;
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
using std::ostream;
|
2000-07-05 14:57:48 +00:00
|
|
|
using std::endl;
|
2000-07-17 18:27:53 +00:00
|
|
|
using std::max;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
InsetCollapsable::InsetCollapsable(bool collapsed)
|
|
|
|
: UpdatableInset(), collapsed_(collapsed),
|
2001-07-23 12:47:25 +00:00
|
|
|
button_length(0), button_top_y(0), button_bottom_y(0),
|
2001-07-24 15:07:09 +00:00
|
|
|
label("Label"), draw_label(label), autocollapse(false),
|
2001-07-23 13:44:23 +00:00
|
|
|
oldWidth(0), need_update(FULL),
|
2001-07-23 12:47:25 +00:00
|
|
|
inlined(false), change_label_with_text(false)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
inset.setOwner(this);
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.setAutoBreakRows(true);
|
|
|
|
inset.setDrawFrame(0, InsetText::ALWAYS);
|
|
|
|
inset.setFrameColor(0, LColor::collapsableframe);
|
2001-04-02 14:02:58 +00:00
|
|
|
setInsetName("Collapsable");
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in, bool same_id)
|
|
|
|
: UpdatableInset(in, same_id), collapsed_(in.collapsed_),
|
|
|
|
framecolor(in.framecolor), labelfont(in.labelfont),
|
|
|
|
button_length(0), button_top_y(0), button_bottom_y(0),
|
|
|
|
label(in.label), draw_label(label), autocollapse(in.autocollapse),
|
|
|
|
oldWidth(0), need_update(FULL),
|
|
|
|
inlined(in.inlined), change_label_with_text(in.change_label_with_text)
|
|
|
|
{
|
|
|
|
inset.init(&(in.inset), same_id);
|
|
|
|
inset.setOwner(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetCollapsable::clone(Buffer const &, bool same_id) const
|
|
|
|
{
|
|
|
|
return new InsetCollapsable(*const_cast<InsetCollapsable *>(this),
|
|
|
|
same_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetCollapsable::insertInset(BufferView * bv, Inset * in)
|
2000-07-04 19:16:35 +00:00
|
|
|
{
|
2001-07-19 08:52:59 +00:00
|
|
|
if (!insetAllowed(in->lyxCode())) {
|
2001-04-02 14:02:58 +00:00
|
|
|
lyxerr << "InsetCollapsable::InsertInset: "
|
|
|
|
"Unable to insert inset." << endl;
|
|
|
|
return false;
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.insertInset(bv, in);
|
2000-07-04 19:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::write(Buffer const * buf, ostream & os) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
os << "collapsed " << tostr(collapsed_) << "\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.writeParagraphData(buf, os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (lex.IsOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.GetString();
|
|
|
|
if (token == "collapsed") {
|
|
|
|
lex.next();
|
2001-07-12 14:35:38 +00:00
|
|
|
collapsed_ = lex.GetBool();
|
2001-04-02 14:02:58 +00:00
|
|
|
} else {
|
|
|
|
lyxerr << "InsetCollapsable::Read: Missing collapsed!"
|
2001-04-04 20:34:04 +00:00
|
|
|
<< endl;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.read(buf, lex);
|
2001-07-23 12:47:25 +00:00
|
|
|
if (collapsed_ && change_label_with_text) {
|
|
|
|
draw_label = get_new_label();
|
|
|
|
} else {
|
|
|
|
draw_label = label;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 09:12:20 +00:00
|
|
|
//int InsetCollapsable::ascent_collapsed(Painter & pain) const
|
|
|
|
int InsetCollapsable::ascent_collapsed(Painter & /*pain*/) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
int width = 0;
|
|
|
|
int ascent = 0;
|
|
|
|
int descent = 0;
|
2001-07-24 09:12:20 +00:00
|
|
|
#if 0
|
2001-07-23 12:47:25 +00:00
|
|
|
pain.buttonText(0, 0, draw_label, labelfont, false,
|
2001-04-04 20:34:04 +00:00
|
|
|
width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
#else
|
|
|
|
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
return ascent;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 09:12:20 +00:00
|
|
|
//int InsetCollapsable::descent_collapsed(Painter & pain) const
|
|
|
|
int InsetCollapsable::descent_collapsed(Painter & /*pain*/) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
int width = 0;
|
|
|
|
int ascent = 0;
|
|
|
|
int descent = 0;
|
2001-07-24 09:12:20 +00:00
|
|
|
#if 0
|
2001-07-23 12:47:25 +00:00
|
|
|
pain.buttonText(0, 0, draw_label, labelfont, false,
|
2001-04-04 20:34:04 +00:00
|
|
|
width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
#else
|
|
|
|
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
return descent;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 09:12:20 +00:00
|
|
|
//int InsetCollapsable::width_collapsed(Painter & pain) const
|
|
|
|
int InsetCollapsable::width_collapsed(Painter & /*pain*/) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
int width;
|
|
|
|
int ascent;
|
|
|
|
int descent;
|
2001-07-24 09:12:20 +00:00
|
|
|
#if 0
|
2001-07-23 12:47:25 +00:00
|
|
|
pain.buttonText(TEXT_TO_INSET_OFFSET, 0, draw_label, labelfont, false,
|
2001-04-04 20:34:04 +00:00
|
|
|
width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
#else
|
|
|
|
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
return width + (2*TEXT_TO_INSET_OFFSET);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
int InsetCollapsable::ascent(BufferView * bv, LyXFont const &) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-23 13:44:23 +00:00
|
|
|
return ascent_collapsed(bv->painter());
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_)
|
2001-07-23 13:44:23 +00:00
|
|
|
return descent_collapsed(bv->painter());
|
2001-03-28 09:28:48 +00:00
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
return descent_collapsed(bv->painter())
|
2001-04-04 20:34:04 +00:00
|
|
|
+ inset.descent(bv, font)
|
|
|
|
+ inset.ascent(bv, font)
|
|
|
|
+ TEXT_TO_BOTTOM_OFFSET;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_)
|
2001-07-23 13:44:23 +00:00
|
|
|
return width_collapsed(bv->painter());
|
|
|
|
|
|
|
|
int widthCollapsed = width_collapsed(bv->painter());
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
return (inset.width(bv, font) > widthCollapsed) ?
|
|
|
|
inset.width(bv, font) : widthCollapsed;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
void InsetCollapsable::draw_collapsed(Painter & pain, int baseline, float & x) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-24 09:12:20 +00:00
|
|
|
#if 0
|
2001-04-02 14:02:58 +00:00
|
|
|
int width = 0;
|
|
|
|
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
2001-07-23 12:47:25 +00:00
|
|
|
baseline, draw_label, labelfont, true, width);
|
2001-07-24 09:12:20 +00:00
|
|
|
#else
|
|
|
|
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
|
|
|
baseline, draw_label, labelfont);
|
|
|
|
#endif
|
|
|
|
#if 0
|
2001-04-02 14:02:58 +00:00
|
|
|
x += width + TEXT_TO_INSET_OFFSET;
|
2001-07-24 09:12:20 +00:00
|
|
|
#else
|
|
|
|
x += width_collapsed(pain) + TEXT_TO_INSET_OFFSET;
|
|
|
|
#endif
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-26 17:47:40 +00:00
|
|
|
void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
|
2001-07-23 12:47:25 +00:00
|
|
|
int baseline, float & x, bool cleared) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
if (nodraw())
|
|
|
|
return;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
Painter & pain = bv->painter();
|
2000-06-21 15:07:57 +00:00
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
button_length = width_collapsed(pain);
|
2001-04-02 14:02:58 +00:00
|
|
|
button_top_y = -ascent(bv, f);
|
2001-07-23 13:44:23 +00:00
|
|
|
button_bottom_y = -ascent(bv, f) + ascent_collapsed(pain) +
|
|
|
|
descent_collapsed(pain);
|
2001-04-04 20:34:04 +00:00
|
|
|
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_) {
|
2001-07-23 13:44:23 +00:00
|
|
|
draw_collapsed(pain, baseline, x);
|
2001-04-02 14:02:58 +00:00
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
float old_x = x;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
UpdatableInset::draw(bv, f, baseline, x, cleared);
|
|
|
|
#else
|
|
|
|
if (!owner())
|
|
|
|
x += static_cast<float>(scroll());
|
|
|
|
#endif
|
2001-04-04 20:34:04 +00:00
|
|
|
if (!cleared && (inset.need_update == InsetText::FULL ||
|
|
|
|
inset.need_update == InsetText::INIT ||
|
|
|
|
top_x != int(x) ||
|
2001-04-27 14:03:25 +00:00
|
|
|
top_baseline != baseline))
|
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
// we don't need anymore to clear here we just have to tell
|
|
|
|
// the underlying LyXText that it should do the RowClear!
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
2001-07-06 15:57:54 +00:00
|
|
|
bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
|
2001-04-27 14:03:25 +00:00
|
|
|
return;
|
|
|
|
#else
|
|
|
|
int w = owner() ? width(bv, f) : pain.paperWidth();
|
2001-04-02 14:02:58 +00:00
|
|
|
int h = ascent(bv, f) + descent(bv, f);
|
2001-04-04 20:34:04 +00:00
|
|
|
int const tx = (needFullRow() && !owner()) ? 0 : int(x);
|
|
|
|
int const ty = max(0, baseline - ascent(bv, f));
|
2001-04-24 15:25:26 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if ((ty + h) > pain.paperHeight())
|
|
|
|
h = pain.paperHeight();
|
|
|
|
if ((top_x + w) > pain.paperWidth())
|
|
|
|
w = pain.paperWidth();
|
|
|
|
if (baseline < 0)
|
|
|
|
h += (baseline - ascent(bv, f));
|
|
|
|
pain.fillRectangle(tx, ty - 1, w, h + 2);
|
|
|
|
cleared = true;
|
2001-04-27 14:03:25 +00:00
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
top_x = int(x);
|
|
|
|
top_baseline = baseline;
|
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
int const bl = baseline - ascent(bv, f) + ascent_collapsed(pain);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-07-23 13:44:23 +00:00
|
|
|
draw_collapsed(pain, bl, old_x);
|
2001-04-02 14:02:58 +00:00
|
|
|
inset.draw(bv, f,
|
2001-07-23 13:44:23 +00:00
|
|
|
bl + descent_collapsed(pain) + inset.ascent(bv, f),
|
2001-04-04 20:34:04 +00:00
|
|
|
x, cleared);
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update = NONE;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
|
2001-07-20 14:18:48 +00:00
|
|
|
unsigned int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset::edit(bv, xp, yp, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_) {
|
2001-07-23 12:47:25 +00:00
|
|
|
draw_label = label;
|
2001-07-12 14:35:38 +00:00
|
|
|
collapsed_ = false;
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!bv->lockInset(this))
|
|
|
|
return;
|
|
|
|
bv->updateInset(this, false);
|
2001-07-24 15:07:09 +00:00
|
|
|
inset.edit(bv);
|
2001-07-11 12:10:46 +00:00
|
|
|
} else {
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!bv->lockInset(this))
|
|
|
|
return;
|
2001-07-24 15:07:09 +00:00
|
|
|
if (yp <= button_bottom_y) {
|
|
|
|
inset.edit(bv);
|
|
|
|
} else {
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
int yy = ascent(bv, font) + yp -
|
|
|
|
(ascent_collapsed(bv->painter()) +
|
|
|
|
descent_collapsed(bv->painter()) +
|
|
|
|
inset.ascent(bv, font));
|
|
|
|
inset.edit(bv, xp, yy, button);
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::edit(BufferView * bv, bool front)
|
|
|
|
{
|
|
|
|
UpdatableInset::edit(bv, front);
|
|
|
|
|
|
|
|
if (collapsed_) {
|
2001-07-23 12:47:25 +00:00
|
|
|
draw_label = label;
|
2001-07-20 14:18:48 +00:00
|
|
|
collapsed_ = false;
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
return;
|
2001-07-24 10:13:19 +00:00
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
2001-07-20 14:18:48 +00:00
|
|
|
bv->updateInset(this, false);
|
|
|
|
inset.edit(bv, front);
|
|
|
|
} else {
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
return;
|
|
|
|
inset.edit(bv, front);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
Inset::EDITABLE InsetCollapsable::editable() const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_)
|
2000-03-08 13:52:57 +00:00
|
|
|
return IS_EDITABLE;
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::insetUnlock(BufferView * bv)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (autocollapse) {
|
2001-07-23 12:47:25 +00:00
|
|
|
if (change_label_with_text) {
|
|
|
|
draw_label = get_new_label();
|
|
|
|
} else {
|
|
|
|
draw_label = label;
|
|
|
|
}
|
2001-07-12 14:35:38 +00:00
|
|
|
collapsed_ = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.insetUnlock(bv);
|
2001-04-27 14:03:25 +00:00
|
|
|
if (scroll())
|
|
|
|
scroll(bv, 0.0F);
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->updateInset(this, false);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::insetButtonPress(BufferView * bv, int x, int y,
|
2001-04-04 20:34:04 +00:00
|
|
|
int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
if (!collapsed_ && (y > button_bottom_y)) {
|
2001-07-20 14:18:48 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
int yy = ascent(bv, font) + y -
|
2001-07-23 13:44:23 +00:00
|
|
|
(ascent_collapsed(bv->painter()) +
|
|
|
|
descent_collapsed(bv->painter()) +
|
2001-07-20 14:18:48 +00:00
|
|
|
inset.ascent(bv, font));
|
|
|
|
inset.insetButtonPress(bv, x, yy, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::insetButtonRelease(BufferView * bv,
|
2000-04-24 20:58:23 +00:00
|
|
|
int x, int y, int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if ((x >= 0) && (x < button_length) &&
|
2001-04-04 20:34:04 +00:00
|
|
|
(y >= button_top_y) && (y <= button_bottom_y)) {
|
2001-07-12 14:35:38 +00:00
|
|
|
if (collapsed_) {
|
2001-07-23 12:47:25 +00:00
|
|
|
draw_label = label;
|
2001-07-12 14:35:38 +00:00
|
|
|
collapsed_ = false;
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.insetButtonRelease(bv, 0, 0, button);
|
2001-07-24 10:13:19 +00:00
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->updateInset(this, false);
|
|
|
|
} else {
|
2001-07-23 12:47:25 +00:00
|
|
|
if (change_label_with_text) {
|
|
|
|
draw_label = get_new_label();
|
|
|
|
} else {
|
|
|
|
draw_label = label;
|
|
|
|
}
|
2001-07-12 14:35:38 +00:00
|
|
|
collapsed_ = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->unlockInset(this);
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
} else if (!collapsed_ && (y > button_bottom_y)) {
|
2001-07-20 14:18:48 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
int yy = ascent(bv, font) + y -
|
2001-07-23 13:44:23 +00:00
|
|
|
(ascent_collapsed(bv->painter()) +
|
|
|
|
descent_collapsed(bv->painter()) +
|
2001-07-20 14:18:48 +00:00
|
|
|
inset.ascent(bv, font));
|
|
|
|
inset.insetButtonRelease(bv, x, yy, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::insetMotionNotify(BufferView * bv,
|
2000-04-24 20:58:23 +00:00
|
|
|
int x, int y, int state)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-07-24 15:07:09 +00:00
|
|
|
if (y > button_bottom_y) {
|
2001-07-20 14:18:48 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
int yy = ascent(bv, font) + y -
|
2001-07-23 13:44:23 +00:00
|
|
|
(ascent_collapsed(bv->painter()) +
|
|
|
|
descent_collapsed(bv->painter()) +
|
2001-07-20 14:18:48 +00:00
|
|
|
inset.ascent(bv, font));
|
|
|
|
inset.insetMotionNotify(bv, x, yy, state);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::insetKeyPress(XKeyEvent * xke)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.insetKeyPress(xke);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetCollapsable::latex(Buffer const * buf, ostream & os,
|
2001-04-04 20:34:04 +00:00
|
|
|
bool fragile, bool free_spc) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.latex(buf, os, fragile, free_spc);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
int InsetCollapsable::getMaxWidth(BufferView * bv,
|
2000-04-24 20:58:23 +00:00
|
|
|
UpdatableInset const * inset) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
int const w = UpdatableInset::getMaxWidth(bv, inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (w < 0) {
|
|
|
|
// What does a negative max width signify? (Lgb)
|
|
|
|
// Use the max width of the draw-area (Jug)
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
// should be at least 30 pixels !!!
|
2001-07-23 13:44:23 +00:00
|
|
|
return max(30, w - width_collapsed(bv->painter()));
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2000-07-04 15:46:55 +00:00
|
|
|
void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
|
2001-04-04 20:34:04 +00:00
|
|
|
bool reinit)
|
2000-06-26 15:10:49 +00:00
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
inset.update(bv, font, reinit);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
UpdatableInset::RESULT
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetCollapsable::localDispatch(BufferView * bv, kb_action action,
|
2000-07-15 23:51:46 +00:00
|
|
|
string const & arg)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset::RESULT result = inset.localDispatch(bv, action, arg);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (result == FINISHED)
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return result;
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetCollapsable::lockInsetInInset(BufferView * bv, UpdatableInset * in)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (&inset == in)
|
|
|
|
return true;
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.lockInsetInInset(bv, in);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in,
|
2000-07-04 11:30:07 +00:00
|
|
|
bool lr)
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (&inset == in) {
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return true;
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.unlockInsetInInset(bv, in, lr);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetCollapsable::updateInsetInInset(BufferView * bv, Inset *in)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (&inset == in)
|
|
|
|
return true;
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.updateInsetInInset(bv, in);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
unsigned int InsetCollapsable::insetInInsetY()
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.insetInInsetY() - (top_baseline - inset.y());
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::validate(LaTeXFeatures & features) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.validate(features);
|
2000-06-26 15:10:49 +00:00
|
|
|
}
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.getCursorPos(bv, x , y);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::toggleInsetCursor(BufferView * bv)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.toggleInsetCursor(bv);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetCollapsable::showInsetCursor(BufferView * bv, bool show)
|
|
|
|
{
|
|
|
|
inset.showInsetCursor(bv, show);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::hideInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
inset.hideInsetCursor(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
UpdatableInset * InsetCollapsable::getLockingInset() const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset * in = inset.getLockingInset();
|
2001-07-13 10:26:31 +00:00
|
|
|
if (const_cast<InsetText *>(&inset) == in)
|
2001-07-12 12:26:06 +00:00
|
|
|
return const_cast<InsetCollapsable *>(this);
|
2001-04-02 14:02:58 +00:00
|
|
|
return in;
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset * InsetCollapsable::getFirstLockingInsetOfType(Inset::Code c)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
if (c == lyxCode())
|
2001-04-02 14:02:58 +00:00
|
|
|
return this;
|
2001-06-28 10:25:20 +00:00
|
|
|
return inset.getFirstLockingInsetOfType(c);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font,
|
2001-05-28 15:11:24 +00:00
|
|
|
bool toggleall, bool selectall)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
inset.setFont(bv, font, toggleall, selectall);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
bool InsetCollapsable::doClearArea() const
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
return inset.doClearArea();
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-22 15:07:07 +00:00
|
|
|
LyXText * InsetCollapsable::getLyXText(BufferView const * bv,
|
2001-04-04 20:34:04 +00:00
|
|
|
bool const recursive) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
return inset.getLyXText(bv, recursive);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
void InsetCollapsable::deleteLyXText(BufferView * bv, bool recursive) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
inset.deleteLyXText(bv, recursive);
|
2000-07-14 14:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-07 14:51:20 +00:00
|
|
|
void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const
|
2000-07-14 14:57:20 +00:00
|
|
|
{
|
2001-06-07 14:51:20 +00:00
|
|
|
inset.resizeLyXText(bv, force);
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
oldWidth = width(bv, font);
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
2001-04-04 23:00:42 +00:00
|
|
|
|
|
|
|
|
2001-04-05 08:03:26 +00:00
|
|
|
std::vector<string> const InsetCollapsable::getLabelList() const
|
2001-04-04 23:00:42 +00:00
|
|
|
{
|
|
|
|
return inset.getLabelList();
|
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
bool InsetCollapsable::nodraw() const
|
|
|
|
{
|
|
|
|
return inset.nodraw();
|
|
|
|
}
|
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
int InsetCollapsable::scroll(bool recursive) const
|
|
|
|
{
|
|
|
|
int sx = UpdatableInset::scroll(false);
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
sx += inset.scroll(recursive);
|
|
|
|
|
|
|
|
return sx;
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * InsetCollapsable::getParFromID(int id) const
|
|
|
|
{
|
|
|
|
return inset.getParFromID(id);
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * InsetCollapsable::firstParagraph() const
|
|
|
|
{
|
|
|
|
return inset.firstParagraph();
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
|
|
|
|
{
|
|
|
|
return inset.cursor(bv);
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Inset * InsetCollapsable::getInsetFromID(int id_arg) const
|
|
|
|
{
|
|
|
|
if (id_arg == id())
|
|
|
|
return const_cast<InsetCollapsable *>(this);
|
|
|
|
return inset.getInsetFromID(id_arg);
|
|
|
|
}
|
2001-07-12 14:35:38 +00:00
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
void InsetCollapsable::open(BufferView * bv, bool flag)
|
2001-07-12 14:35:38 +00:00
|
|
|
{
|
2001-07-19 08:52:59 +00:00
|
|
|
if (flag == !collapsed_)
|
2001-07-12 14:35:38 +00:00
|
|
|
return;
|
2001-07-19 08:52:59 +00:00
|
|
|
collapsed_ = !flag;
|
2001-07-23 12:47:25 +00:00
|
|
|
if (collapsed_ && change_label_with_text) {
|
|
|
|
draw_label = get_new_label();
|
|
|
|
} else {
|
|
|
|
draw_label = label;
|
|
|
|
}
|
2001-07-12 14:35:38 +00:00
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
2001-07-23 12:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::setLabel(string const & l, bool flag)
|
|
|
|
{
|
|
|
|
label = l;
|
|
|
|
change_label_with_text = flag;
|
|
|
|
if (collapsed_ && change_label_with_text) {
|
|
|
|
draw_label = get_new_label();
|
|
|
|
} else {
|
|
|
|
draw_label = label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string InsetCollapsable::get_new_label() const
|
|
|
|
{
|
|
|
|
string la;
|
2001-07-24 15:07:09 +00:00
|
|
|
Paragraph::size_type const max_length = 15;
|
2001-07-23 12:47:25 +00:00
|
|
|
|
2001-07-24 10:13:19 +00:00
|
|
|
int n = std::min(max_length, inset.paragraph()->size());
|
2001-07-23 12:47:25 +00:00
|
|
|
int i,j;
|
|
|
|
for(i=0,j=0; i < n && j < inset.paragraph()->size(); ++j) {
|
|
|
|
if (inset.paragraph()->isInset(j))
|
|
|
|
continue;
|
|
|
|
la += inset.paragraph()->getChar(j);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if ((i > 0) && (j < inset.paragraph()->size()))
|
|
|
|
la += "...";
|
|
|
|
if (la.empty())
|
|
|
|
la = label;
|
|
|
|
return la;
|
|
|
|
}
|