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-06-28 13:35:52 +00:00
|
|
|
#include "support/lstrings.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-06-12 11:27:15 +00:00
|
|
|
InsetCollapsable::InsetCollapsable() : InsetText()
|
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-06-26 15:10:49 +00:00
|
|
|
widthOffset = 2 * TEXT_TO_INSET_OFFSET + 2; // 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-06-12 11:27:15 +00:00
|
|
|
InsetCollapsable * result = new InsetCollapsable();
|
|
|
|
result->init(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-06-28 13:35:52 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetCollapsable::Write(Buffer const * buf, ostream & os) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-06-28 13:35:52 +00:00
|
|
|
os << "collapsed " << tostr(!display()) << "\n";
|
|
|
|
WriteParagraphData(buf, os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetCollapsable::Read(Buffer const * buf, LyXLex & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.GetString();
|
|
|
|
if (token == "collapsed") {
|
|
|
|
lex.next();
|
|
|
|
collapsed = lex.GetBool();
|
|
|
|
}
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetText::Read(buf, lex);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool cleared) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
Painter & pain = bv->painter();
|
|
|
|
|
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-05-17 14:43:09 +00:00
|
|
|
top_x = int(x);
|
|
|
|
top_baseline = baseline;
|
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-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-06-26 15:10:49 +00:00
|
|
|
int w = InsetText::width(pain, f) + (2 * TEXT_TO_INSET_OFFSET);
|
2000-04-24 20:58:23 +00:00
|
|
|
int h = ascent(pain,f) + descent(pain, f);
|
2000-06-23 15:02:46 +00:00
|
|
|
int save_x = static_cast<int>(x);
|
2000-05-15 14:49:36 +00:00
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2000-06-23 15:02:46 +00:00
|
|
|
InsetText::draw(bv, f, baseline, x, cleared);
|
|
|
|
pain.rectangle(save_x, baseline - ascent(pain, f), w, h, framecolor);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2000-06-21 15:07:57 +00:00
|
|
|
UpdateLocal(bv, FULL, false);
|
2000-03-08 13:52:57 +00:00
|
|
|
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-06-21 15:07:57 +00:00
|
|
|
UpdateLocal(bv, FULL, false);
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2000-06-21 15:07:57 +00:00
|
|
|
UpdateLocal(bv, FULL, false);
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
|
|
|
collapsed = true;
|
2000-06-21 15:07:57 +00:00
|
|
|
UpdateLocal(bv, FULL, false);
|
2000-04-19 14:42:19 +00:00
|
|
|
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
|
|
|
}
|
2000-06-26 15:10:49 +00:00
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
void InsetCollapsable::update(BufferView * bv,
|
|
|
|
LyXFont const & font, bool dodraw)
|
2000-06-26 15:10:49 +00:00
|
|
|
{
|
|
|
|
drawTextXOffset = width_collapsed(bv->painter(), font);
|
|
|
|
InsetText::update(bv, font, dodraw);
|
|
|
|
}
|