2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcollapsable.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
2000-06-28 16:03:01 +00:00
|
|
|
|
*/
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "insetcollapsable.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "insettext.h"
|
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "debug.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfont.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "lyxlex.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "WordLangTuple.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-03-19 14:45:22 +00:00
|
|
|
|
#include "buffer.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
2003-02-25 14:51:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
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
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
class LyXText;
|
|
|
|
|
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
|
|
|
|
|
: UpdatableInset(), collapsed_(collapsed), inset(bp),
|
2001-07-23 12:47:25 +00:00
|
|
|
|
button_length(0), button_top_y(0), button_bottom_y(0),
|
2003-03-20 14:13:49 +00:00
|
|
|
|
label("Label"),
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
|
|
|
|
autocollapse(false),
|
|
|
|
|
#endif
|
2002-05-14 11:11:02 +00:00
|
|
|
|
oldWidth(0), in_update(false), first_after_edit(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)
|
2002-03-03 20:25:07 +00:00
|
|
|
|
: UpdatableInset(in, same_id), collapsed_(in.collapsed_),
|
|
|
|
|
framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
|
2001-07-24 15:07:09 +00:00
|
|
|
|
button_length(0), button_top_y(0), button_bottom_y(0),
|
2003-03-20 14:13:49 +00:00
|
|
|
|
label(in.label),
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
2001-07-31 09:53:40 +00:00
|
|
|
|
autocollapse(in.autocollapse),
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
2002-05-14 11:11:02 +00:00
|
|
|
|
oldWidth(0), in_update(false), first_after_edit(false)
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
inset.init(&(in.inset), same_id);
|
|
|
|
|
inset.setOwner(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (token == "collapsed") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +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-07-25 22:05:53 +00:00
|
|
|
|
// Take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
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);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
int InsetCollapsable::ascent_collapsed() 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;
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(label, labelfont, width, ascent, descent);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return ascent;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
int InsetCollapsable::descent_collapsed() 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;
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(label, labelfont, width, ascent, descent);
|
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
|
2001-07-24 22:08:49 +00:00
|
|
|
|
int InsetCollapsable::width_collapsed() const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
int width;
|
|
|
|
|
int ascent;
|
|
|
|
|
int descent;
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(label, labelfont, width, ascent, descent);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
return width + 2 * TEXT_TO_INSET_OFFSET;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
int InsetCollapsable::ascent(BufferView * /*bv*/, LyXFont const &) const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return ascent_collapsed();
|
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
|
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
|
if (collapsed_)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return descent_collapsed();
|
2001-03-28 09:28:48 +00:00
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return descent_collapsed()
|
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
|
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
|
if (collapsed_)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return width_collapsed();
|
2001-07-23 13:44:23 +00:00
|
|
|
|
|
2003-03-20 14:13:49 +00:00
|
|
|
|
int const collapsed_width = width_collapsed();
|
|
|
|
|
int const contents_width = inset.width(bv, font);
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
2003-03-20 14:13:49 +00:00
|
|
|
|
return max(collapsed_width, contents_width);
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
void InsetCollapsable::draw_collapsed(Painter & pain,
|
|
|
|
|
int baseline, float & x) const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2001-07-24 22:08:49 +00:00
|
|
|
|
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
|
|
|
|
baseline, label, labelfont);
|
|
|
|
|
x += width_collapsed();
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
|
2003-03-20 14:13:49 +00:00
|
|
|
|
int baseline, float & x, bool inlined) const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
|
lyx::Assert(bv);
|
|
|
|
|
cache(bv);
|
|
|
|
|
|
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-24 22:08:49 +00:00
|
|
|
|
button_length = width_collapsed();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
button_top_y = -ascent(bv, f);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
button_bottom_y = -ascent(bv, f) + ascent_collapsed() +
|
|
|
|
|
descent_collapsed();
|
2001-04-04 20:34:04 +00:00
|
|
|
|
|
2001-07-31 09:53:40 +00:00
|
|
|
|
if (!isOpen()) {
|
2001-07-23 13:44:23 +00:00
|
|
|
|
draw_collapsed(pain, baseline, x);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
|
float old_x = x;
|
|
|
|
|
|
|
|
|
|
if (!owner())
|
2003-03-20 14:13:49 +00:00
|
|
|
|
x += scroll();
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
top_x = int(x);
|
|
|
|
|
top_baseline = baseline;
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
int const bl = baseline - ascent(bv, f) + ascent_collapsed();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-20 14:13:49 +00:00
|
|
|
|
if (inlined) {
|
|
|
|
|
inset.draw(bv, f, baseline, x);
|
|
|
|
|
} else {
|
|
|
|
|
draw_collapsed(pain, bl, old_x);
|
|
|
|
|
inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
|
|
|
|
|
// contained inset may be shorter than the button
|
|
|
|
|
if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET))
|
|
|
|
|
x = top_x + button_length + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
|
|
|
|
|
int baseline, float & x) const
|
|
|
|
|
{
|
|
|
|
|
// by default, we are not inlined-drawing
|
|
|
|
|
draw(bv, f, baseline, x, false);
|
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,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
mouse_button::state button)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2002-08-12 09:35:52 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning Fix this properly in BufferView_pimpl::workAreaButtonRelease
|
|
|
|
|
#endif
|
|
|
|
|
if (button == mouse_button::button3)
|
|
|
|
|
return;
|
2002-11-24 15:20:31 +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_) {
|
|
|
|
|
collapsed_ = false;
|
2001-08-13 11:27:53 +00:00
|
|
|
|
// set this only here as it should be recollapsed only if
|
|
|
|
|
// it was already collapsed!
|
|
|
|
|
first_after_edit = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
|
return;
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
|
|
|
|
bv->buffer()->markDirty();
|
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) {
|
2002-04-16 14:10:39 +00:00
|
|
|
|
inset.edit(bv, xp, 0, button);
|
2001-07-24 15:07:09 +00:00
|
|
|
|
} else {
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
int yy = ascent(bv, font) + yp -
|
2001-07-24 22:08:49 +00:00
|
|
|
|
(ascent_collapsed() +
|
|
|
|
|
descent_collapsed() +
|
2001-07-24 15:07:09 +00:00
|
|
|
|
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_) {
|
|
|
|
|
collapsed_ = false;
|
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
|
return;
|
2001-07-24 10:13:19 +00:00
|
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
|
|
|
|
bv->buffer()->markDirty();
|
2001-07-20 14:18:48 +00:00
|
|
|
|
inset.edit(bv, front);
|
2002-05-09 13:43:40 +00:00
|
|
|
|
first_after_edit = true;
|
2001-07-20 14:18:48 +00:00
|
|
|
|
} 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-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
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-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
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);
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetCollapsable::lfunMousePress(FuncRequest const & cmd)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (!collapsed_ && (cmd.y > button_bottom_y)) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.y = ascent(cmd.view(), font) + cmd.y -
|
2001-07-24 22:08:49 +00:00
|
|
|
|
(ascent_collapsed() +
|
|
|
|
|
descent_collapsed() +
|
2002-08-19 10:11:13 +00:00
|
|
|
|
inset.ascent(cmd.view(), font));
|
|
|
|
|
inset.localDispatch(cmd1);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
bool InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2001-12-17 13:33:22 +00:00
|
|
|
|
bool ret = false;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
if ((cmd.button() != mouse_button::button3) && (cmd.x < button_length) &&
|
|
|
|
|
(cmd.y >= button_top_y) && (cmd.y <= button_bottom_y))
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
|
if (collapsed_) {
|
|
|
|
|
collapsed_ = false;
|
2001-07-31 09:53:40 +00:00
|
|
|
|
// should not be called on inset open!
|
|
|
|
|
// inset.insetButtonRelease(bv, 0, 0, button);
|
2001-07-24 10:13:19 +00:00
|
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
|
|
|
|
bv->buffer()->markDirty();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
} else {
|
2001-07-12 14:35:38 +00:00
|
|
|
|
collapsed_ = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
bv->unlockInset(this);
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
|
|
|
|
bv->buffer()->markDirty();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
} else if (!collapsed_ && (cmd.y > button_bottom_y)) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.y = ascent(cmd.view(), font) + cmd.y -
|
2001-07-24 22:08:49 +00:00
|
|
|
|
(ascent_collapsed() +
|
|
|
|
|
descent_collapsed() +
|
2002-08-19 10:11:13 +00:00
|
|
|
|
inset.ascent(cmd.view(), font));
|
|
|
|
|
ret = (inset.localDispatch(cmd1) == DISPATCHED);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button3 && !ret)
|
2001-12-17 13:33:22 +00:00
|
|
|
|
return showInsetDialog(bv);
|
2002-05-13 08:49:43 +00:00
|
|
|
|
return ret;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetCollapsable::lfunMouseMotion(FuncRequest const & cmd)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (cmd.y > button_bottom_y) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.y = ascent(cmd.view(), font) + cmd.y -
|
2001-07-24 22:08:49 +00:00
|
|
|
|
(ascent_collapsed() +
|
|
|
|
|
descent_collapsed() +
|
2002-08-19 10:11:13 +00:00
|
|
|
|
inset.ascent(cmd.view(), font));
|
|
|
|
|
inset.localDispatch(cmd1);
|
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
|
|
|
|
int InsetCollapsable::latex(Buffer const * buf, ostream & os,
|
2002-03-21 17:09:55 +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-12-27 15:54:25 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
int InsetCollapsable::ascii(Buffer const * buf, ostream & os, int ll) const
|
2001-12-27 15:54:25 +00:00
|
|
|
|
{
|
|
|
|
|
return inset.ascii(buf, os, ll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const
|
2001-12-27 15:54:25 +00:00
|
|
|
|
{
|
|
|
|
|
return inset.linuxdoc(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) const
|
2001-12-27 15:54:25 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return inset.docbook(buf, os, mixcont);
|
2001-12-27 15:54:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2003-03-20 14:13:49 +00:00
|
|
|
|
void InsetCollapsable::update(BufferView * bv, bool reinit)
|
2000-06-26 15:10:49 +00:00
|
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
|
if (in_update) {
|
|
|
|
|
if (reinit && owner()) {
|
2003-03-20 14:13:49 +00:00
|
|
|
|
owner()->update(bv, true);
|
2001-08-07 15:07:36 +00:00
|
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
|
return;
|
2001-08-07 15:07:36 +00:00
|
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
|
in_update = true;
|
2003-03-20 14:13:49 +00:00
|
|
|
|
inset.update(bv, reinit);
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (reinit && owner()) {
|
2003-03-20 14:13:49 +00:00
|
|
|
|
owner()->update(bv, true);
|
2001-08-01 15:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
in_update = false;
|
2000-07-04 11:30:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
Inset::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
lfunMousePress(cmd);
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
lfunMouseMotion(cmd);
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
lfunMouseRelease(cmd);
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
UpdatableInset::RESULT result = inset.localDispatch(cmd);
|
|
|
|
|
if (result >= FINISHED)
|
|
|
|
|
cmd.view()->unlockInset(this);
|
|
|
|
|
first_after_edit = false;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
return UNDISPATCHED;
|
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,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool lr)
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
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-12-18 14:36:27 +00:00
|
|
|
|
if (in == this)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return true;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return inset.updateInsetInInset(bv, in);
|
2000-07-04 11:30:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
int InsetCollapsable::insetInInsetY() const
|
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
|
|
|
|
|
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
void InsetCollapsable::getCursor(BufferView & bv, int & x, int & y) const
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
2003-05-03 18:05:53 +00:00
|
|
|
|
inset.getCursor(bv, x, y);
|
2000-07-04 11:30:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const
|
2001-07-20 14:18:48 +00:00
|
|
|
|
{
|
2003-05-03 18:05:53 +00:00
|
|
|
|
inset.getCursorPos(bv, x , y);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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,
|
2002-03-21 17:09:55 +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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:09:55 +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-09-01 21:26:34 +00:00
|
|
|
|
Paragraph * InsetCollapsable::getFirstParagraph(int i) const
|
|
|
|
|
{
|
|
|
|
|
return inset.getFirstParagraph(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-24 22:08:49 +00:00
|
|
|
|
|
|
|
|
|
void InsetCollapsable::open(BufferView * bv)
|
|
|
|
|
{
|
|
|
|
|
if (!collapsed_) return;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
collapsed_ = false;
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(this);
|
2001-07-12 14:35:38 +00:00
|
|
|
|
}
|
2001-07-23 12:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetCollapsable::close(BufferView * bv) const
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
2001-07-31 09:53:40 +00:00
|
|
|
|
if (collapsed_)
|
|
|
|
|
return;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
collapsed_ = true;
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(const_cast<InsetCollapsable *>(this));
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetCollapsable::setLabel(string const & l) const
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
|
|
|
|
label = l;
|
|
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void InsetCollapsable::markErased()
|
|
|
|
|
{
|
|
|
|
|
inset.markErased();
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 15:59:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
bool InsetCollapsable::nextChange(BufferView * bv, lyx::pos_type & length)
|
|
|
|
|
{
|
|
|
|
|
bool found = inset.nextChange(bv, length);
|
2003-03-03 15:59:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (first_after_edit && !found)
|
|
|
|
|
close(bv);
|
|
|
|
|
else if (!found)
|
|
|
|
|
first_after_edit = false;
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 15:59:08 +00:00
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool cs, bool mw)
|
2001-08-07 15:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
bool found = inset.searchForward(bv, str, cs, mw);
|
|
|
|
|
if (first_after_edit && !found)
|
|
|
|
|
close(bv);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (!found)
|
|
|
|
|
first_after_edit = false;
|
2001-08-07 15:07:36 +00:00
|
|
|
|
return found;
|
|
|
|
|
}
|
2001-09-09 22:02:19 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool cs, bool mw)
|
2001-08-07 15:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
bool found = inset.searchBackward(bv, str, cs, mw);
|
|
|
|
|
if (first_after_edit && !found)
|
|
|
|
|
close(bv);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (!found)
|
|
|
|
|
first_after_edit = false;
|
2001-08-07 15:07:36 +00:00
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
WordLangTuple const
|
|
|
|
|
InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv, float & value) const
|
2001-08-07 15:07:36 +00:00
|
|
|
|
{
|
2002-08-06 22:38:44 +00:00
|
|
|
|
WordLangTuple word = inset.selectNextWordToSpellcheck(bv, value);
|
|
|
|
|
if (first_after_edit && word.word().empty())
|
2001-08-07 15:07:36 +00:00
|
|
|
|
close(bv);
|
|
|
|
|
first_after_edit = false;
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return word;
|
2001-08-07 15:07:36 +00:00
|
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::addPreview(grfx::PreviewLoader & loader) const
|
|
|
|
|
{
|
|
|
|
|
inset.addPreview(loader);
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::cache(BufferView * bv) const
|
|
|
|
|
{
|
|
|
|
|
view_ = bv->owner()->view();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * InsetCollapsable::view() const
|
|
|
|
|
{
|
2003-03-03 15:59:08 +00:00
|
|
|
|
return view_.lock().get();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|