2000-03-08 13:52:57 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 The LyX Team.
|
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetcollapsable.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Painter.h"
|
2000-04-24 20:58:23 +00:00
|
|
|
#include "support/LOstream.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
using std::ostream;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-03-31 10:35:53 +00:00
|
|
|
InsetCollapsable::InsetCollapsable(Buffer * bf)
|
|
|
|
: InsetText(bf)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
|
|
|
collapsed = true;
|
|
|
|
label = "Label";
|
2000-04-19 14:42:19 +00:00
|
|
|
autocollapse = true;
|
2000-03-08 13:52:57 +00:00
|
|
|
autoBreakRows = true;
|
|
|
|
framecolor = LColor::footnoteframe;
|
2000-05-15 14:49:36 +00:00
|
|
|
widthOffset = 6; // 2+2 (behind+back), 1+1 (frame)
|
2000-04-19 14:42:19 +00:00
|
|
|
button_length = button_top_y = button_bottom_y = 0;
|
|
|
|
setInsetName("Collapsable");
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-09 16:13:43 +00:00
|
|
|
Inset * InsetCollapsable::Clone() const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-03-28 16:18:02 +00:00
|
|
|
InsetCollapsable * result = new InsetCollapsable(buffer);
|
2000-04-10 14:29:05 +00:00
|
|
|
result->init(buffer, this);
|
2000-03-28 16:18:02 +00:00
|
|
|
|
2000-03-31 10:35:53 +00:00
|
|
|
result->collapsed = collapsed;
|
2000-03-08 13:52:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void InsetCollapsable::Write(ostream & os) const
|
|
|
|
{
|
|
|
|
os << getInsetName() << "\n\ncollapsed ";
|
|
|
|
if (display())
|
|
|
|
os << "false\n";
|
|
|
|
else
|
|
|
|
os << "true\n";
|
|
|
|
WriteParagraphData(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::Read(LyXLex & lex)
|
|
|
|
{
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.GetString();
|
|
|
|
if (token == "collapsed") {
|
|
|
|
lex.next();
|
|
|
|
collapsed = lex.GetBool();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InsetText::Read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
|
|
|
|
{
|
|
|
|
int width = 0, ascent = 0, descent = 0;
|
|
|
|
pain.buttonText(0, 0, label.c_str(), labelfont, false,
|
|
|
|
width, ascent, descent);
|
|
|
|
return ascent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
|
|
|
|
{
|
|
|
|
int width = 0, ascent = 0, descent = 0;
|
|
|
|
pain.buttonText(0, 0, label.c_str(), labelfont, false,
|
|
|
|
width, ascent, descent);
|
|
|
|
return descent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
|
|
|
|
{
|
|
|
|
int width, ascent, descent;
|
|
|
|
pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
|
|
|
|
width, ascent, descent);
|
|
|
|
return width + (2*TEXT_TO_INSET_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
if (collapsed)
|
|
|
|
return ascent_collapsed(pain, font);
|
|
|
|
else
|
|
|
|
return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
if (collapsed)
|
|
|
|
return descent_collapsed(pain, font);
|
|
|
|
else
|
|
|
|
return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
if (collapsed)
|
|
|
|
return width_collapsed(pain, font);
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
return InsetText::width(pain, font) + width_collapsed(pain,font) +
|
|
|
|
widthOffset;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const & font,
|
2000-03-08 13:52:57 +00:00
|
|
|
int baseline, float & x) const
|
|
|
|
{
|
|
|
|
int width = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
|
|
|
baseline-ascent(pain, font)+ascent_collapsed(pain, font),
|
2000-03-08 13:52:57 +00:00
|
|
|
label.c_str(), labelfont, true, width);
|
|
|
|
x += width + (2 * TEXT_TO_INSET_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
|
|
|
|
int baseline, float & x) const
|
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
button_length = width_collapsed(pain, labelfont) + 2;
|
|
|
|
button_top_y = -ascent_collapsed(pain, f);
|
|
|
|
button_bottom_y = descent_collapsed(pain, f);
|
2000-03-08 13:52:57 +00:00
|
|
|
if (collapsed) {
|
|
|
|
draw_collapsed(pain, f, baseline, x);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
int top_x = int(x);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
draw_collapsed(pain, f, baseline, x);
|
2000-05-15 14:49:36 +00:00
|
|
|
x -= TEXT_TO_INSET_OFFSET;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
int w = InsetText::width(pain, f) + TEXT_TO_INSET_OFFSET;
|
2000-04-24 20:58:23 +00:00
|
|
|
int h = ascent(pain,f) + descent(pain, f);
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
|
|
pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2000-04-19 14:42:19 +00:00
|
|
|
drawTextXOffset = int(x) - top_x;
|
2000-03-08 13:52:57 +00:00
|
|
|
InsetText::draw(pain, f, baseline, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
void InsetCollapsable::Edit(BufferView * bv, int x, int y, unsigned int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (collapsed && autocollapse) {
|
2000-03-08 13:52:57 +00:00
|
|
|
collapsed = false;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
InsetText::Edit(bv, 0, 0, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
} else if (!collapsed) {
|
|
|
|
InsetText::Edit(bv, x, y, button);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset::EDITABLE InsetCollapsable::Editable() const
|
|
|
|
{
|
|
|
|
if (collapsed)
|
|
|
|
return IS_EDITABLE;
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
void InsetCollapsable::InsetUnlock(BufferView * bv)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (autocollapse) {
|
2000-03-08 13:52:57 +00:00
|
|
|
collapsed = true;
|
|
|
|
}
|
|
|
|
InsetText::InsetUnlock(bv);
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
void InsetCollapsable::UpdateLocal(BufferView * bv, bool flag)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
|
|
|
InsetText::UpdateLocal(bv, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
void InsetCollapsable::InsetButtonPress(BufferView * bv,int x,int y,int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!collapsed && (x >= button_length)) {
|
|
|
|
InsetText::InsetButtonPress(bv, x, y, button);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
void InsetCollapsable::InsetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, int button)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if ((x >= 0) && (x < button_length) &&
|
|
|
|
(y >= button_top_y) && (y < button_bottom_y)) {
|
|
|
|
if (collapsed) {
|
|
|
|
collapsed = false;
|
|
|
|
InsetText::InsetButtonRelease(bv, 0, 0, button);
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else {
|
|
|
|
collapsed = true;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
bv->unlockInset(this);
|
|
|
|
}
|
|
|
|
} else if (!collapsed && (x >= button_length) && (y >= button_top_y)) {
|
|
|
|
InsetText::InsetButtonRelease(bv, x, y, button);
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
void InsetCollapsable::InsetMotionNotify(BufferView * bv,
|
|
|
|
int x, int y, int state)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (x >= button_length) {
|
|
|
|
InsetText::InsetMotionNotify(bv, x, y, state);
|
2000-03-09 16:04:28 +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
|
|
|
|
|
|
|
int InsetCollapsable::getMaxWidth(Painter & pain,
|
|
|
|
UpdatableInset const * inset) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
if ((this == inset) && !owner())
|
|
|
|
return pain.paperWidth();
|
|
|
|
if (this == inset)
|
2000-04-24 20:58:23 +00:00
|
|
|
return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain,inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
if (owner())
|
2000-04-24 20:58:23 +00:00
|
|
|
return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain,inset)-
|
2000-05-15 14:49:36 +00:00
|
|
|
width_collapsed(pain, labelfont) - widthOffset;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
return pain.paperWidth()-width_collapsed(pain, labelfont) - widthOffset;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
int InsetCollapsable::getMaxTextWidth(Painter & pain,
|
2000-05-15 14:49:36 +00:00
|
|
|
UpdatableInset const * inset) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
return getMaxWidth(pain, inset) -
|
2000-05-15 14:49:36 +00:00
|
|
|
width_collapsed(pain, labelfont) - widthOffset;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|