2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2017-10-16 08:12:21 +00:00
|
|
|
* \file InsetCollapsible.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* 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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +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>
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
#include "InsetCollapsible.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2018-10-04 17:36:01 +00:00
|
|
|
#include "BufferParams.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
#include "BufferView.h"
|
2018-10-04 17:36:01 +00:00
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-03 18:50:54 +00:00
|
|
|
#include "Dimension.h"
|
2018-10-04 17:36:01 +00:00
|
|
|
#include "Format.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-02-22 03:34:03 +00:00
|
|
|
#include "InsetLayout.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2009-07-14 18:27:54 +00:00
|
|
|
#include "OutputParams.h"
|
2018-10-04 17:36:01 +00:00
|
|
|
#include "TextClass.h"
|
2017-01-09 12:28:48 +00:00
|
|
|
#include "TocBackend.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "frontends/Painter.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lassert.h"
|
2009-05-07 18:04:05 +00:00
|
|
|
#include "support/lstrings.h"
|
2016-05-23 09:01:29 +00:00
|
|
|
#include "support/RefChanger.h"
|
2018-10-04 17:36:01 +00:00
|
|
|
#include "support/TempFile.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2008-04-10 21:49:34 +00:00
|
|
|
namespace lyx {
|
2001-04-04 20:34:04 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::InsetCollapsible(Buffer * buf, InsetText::UsePlain ltype)
|
2016-02-03 09:37:29 +00:00
|
|
|
: InsetText(buf, ltype), status_(Open)
|
2009-07-14 18:56:13 +00:00
|
|
|
{
|
|
|
|
setDrawFrame(true);
|
2017-10-16 08:12:21 +00:00
|
|
|
setFrameColor(Color_collapsibleframe);
|
2009-07-14 18:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-01 23:04:08 +00:00
|
|
|
// The sole purpose of this copy constructor is to make sure
|
2016-04-19 13:45:08 +00:00
|
|
|
// that the view_ map is not copied and remains empty.
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::InsetCollapsible(InsetCollapsible const & rhs)
|
2009-07-14 18:56:13 +00:00
|
|
|
: InsetText(rhs),
|
|
|
|
status_(rhs.status_),
|
2016-04-19 13:45:08 +00:00
|
|
|
labelstring_(rhs.labelstring_)
|
2018-10-04 17:36:01 +00:00
|
|
|
{
|
|
|
|
tempfile_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-15 22:43:35 +00:00
|
|
|
InsetCollapsible & InsetCollapsible::operator=(InsetCollapsible const & that)
|
2018-10-04 17:36:01 +00:00
|
|
|
{
|
|
|
|
if (&that == this)
|
|
|
|
return *this;
|
|
|
|
*this = InsetCollapsible(that);
|
|
|
|
return *this;
|
|
|
|
}
|
2009-07-14 18:56:13 +00:00
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::~InsetCollapsible()
|
2010-04-30 14:55:37 +00:00
|
|
|
{
|
2016-04-19 13:45:08 +00:00
|
|
|
map<BufferView const *, View>::iterator it = view_.begin();
|
|
|
|
map<BufferView const *, View>::iterator end = view_.end();
|
2010-04-30 14:55:37 +00:00
|
|
|
for (; it != end; ++it)
|
2016-04-19 13:45:08 +00:00
|
|
|
if (it->second.mouse_hover_)
|
2010-04-30 14:55:37 +00:00
|
|
|
it->first->clearLastInset(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::CollapseStatus InsetCollapsible::status(BufferView const & bv) const
|
2005-09-28 15:02:47 +00:00
|
|
|
{
|
2008-10-25 13:41:02 +00:00
|
|
|
if (decoration() == InsetLayout::CONGLOMERATE)
|
2008-03-25 06:17:18 +00:00
|
|
|
return status_;
|
2016-04-19 13:45:08 +00:00
|
|
|
return view_[&bv].auto_open_ ? Open : status_;
|
2007-08-16 16:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::Geometry InsetCollapsible::geometry(BufferView const & bv) const
|
2007-08-16 16:36:50 +00:00
|
|
|
{
|
|
|
|
switch (decoration()) {
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::CLASSIC:
|
2009-02-21 16:27:00 +00:00
|
|
|
if (status(bv) == Open)
|
2016-04-19 13:45:08 +00:00
|
|
|
return view_[&bv].openinlined_ ? LeftButton : TopButton;
|
2008-03-05 00:21:05 +00:00
|
|
|
return ButtonOnly;
|
2007-08-17 12:11:32 +00:00
|
|
|
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::MINIMALISTIC:
|
2009-02-21 16:27:00 +00:00
|
|
|
return status(bv) == Open ? NoButton : ButtonOnly ;
|
2007-08-17 12:11:32 +00:00
|
|
|
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::CONGLOMERATE:
|
2009-02-21 16:27:00 +00:00
|
|
|
return status(bv) == Open ? SubLabel : Corners ;
|
2008-02-22 16:15:21 +00:00
|
|
|
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::DEFAULT:
|
2008-02-22 16:15:21 +00:00
|
|
|
break; // this shouldn't happen
|
2007-08-16 16:36:50 +00:00
|
|
|
}
|
2007-08-17 12:11:32 +00:00
|
|
|
|
|
|
|
// dummy return value to shut down a warning,
|
|
|
|
// this is dead code.
|
|
|
|
return NoButton;
|
2005-09-28 15:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
docstring InsetCollapsible::toolTip(BufferView const & bv, int x, int y) const
|
2007-12-25 18:53:38 +00:00
|
|
|
{
|
2010-11-17 17:25:22 +00:00
|
|
|
Dimension const dim = dimensionCollapsed(bv);
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == NoButton)
|
2009-07-13 00:28:22 +00:00
|
|
|
return translateIfPossible(getLayout().labelstring());
|
2009-02-21 16:27:00 +00:00
|
|
|
if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
|
2007-12-25 18:53:38 +00:00
|
|
|
return docstring();
|
|
|
|
|
2010-04-26 00:43:08 +00:00
|
|
|
return toolTipText();
|
2007-12-25 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::write(ostream & os) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2004-02-03 16:44:57 +00:00
|
|
|
os << "status ";
|
2003-12-12 14:02:14 +00:00
|
|
|
switch (status_) {
|
|
|
|
case Open:
|
2004-02-03 16:44:57 +00:00
|
|
|
os << "open";
|
2003-12-12 14:02:14 +00:00
|
|
|
break;
|
|
|
|
case Collapsed:
|
2004-02-03 16:44:57 +00:00
|
|
|
os << "collapsed";
|
2003-12-12 14:02:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-02-03 16:44:57 +00:00
|
|
|
os << "\n";
|
2009-08-09 15:29:34 +00:00
|
|
|
text().write(os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::read(Lexer & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2017-10-16 08:12:21 +00:00
|
|
|
lex.setContext("InsetCollapsible::read");
|
2008-04-05 10:34:29 +00:00
|
|
|
string tmp_token;
|
|
|
|
status_ = Collapsed;
|
2008-04-05 20:24:05 +00:00
|
|
|
lex >> "status" >> tmp_token;
|
2008-04-05 10:34:29 +00:00
|
|
|
if (tmp_token == "open")
|
|
|
|
status_ = Open;
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetText::read(lex);
|
2008-10-17 04:35:08 +00:00
|
|
|
setButtonLabel();
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
Dimension dim;
|
2012-11-26 08:10:14 +00:00
|
|
|
FontInfo labelfont(getLabelfont());
|
|
|
|
labelfont.realize(sane_font);
|
|
|
|
theFontMetrics(labelfont).buttonText(
|
2017-06-15 13:30:23 +00:00
|
|
|
buttonLabel(bv), TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
|
2004-11-30 01:59:49 +00:00
|
|
|
return dim;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
|
2005-09-28 15:02:47 +00:00
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
FontInfo tmpfont = mi.base.font;
|
2012-11-26 08:10:14 +00:00
|
|
|
mi.base.font = getFont();
|
2007-10-30 12:30:46 +00:00
|
|
|
mi.base.font.realize(tmpfont);
|
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
BufferView const & bv = *mi.base.bv;
|
|
|
|
|
|
|
|
switch (geometry(bv)) {
|
2007-08-31 07:15:32 +00:00
|
|
|
case NoButton:
|
2007-08-19 15:45:35 +00:00
|
|
|
InsetText::metrics(mi, dim);
|
|
|
|
break;
|
2007-08-31 07:15:32 +00:00
|
|
|
case Corners:
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::metrics(mi, dim);
|
2007-08-31 12:05:41 +00:00
|
|
|
dim.des -= 3;
|
2007-09-18 20:48:39 +00:00
|
|
|
dim.asc -= 1;
|
2007-08-16 16:36:50 +00:00
|
|
|
break;
|
2007-08-31 12:05:41 +00:00
|
|
|
case SubLabel: {
|
|
|
|
InsetText::metrics(mi, dim);
|
|
|
|
// consider width of the inset label
|
2012-11-26 08:10:14 +00:00
|
|
|
FontInfo font(getLabelfont());
|
2007-10-28 18:51:54 +00:00
|
|
|
font.realize(sane_font);
|
2007-08-31 12:05:41 +00:00
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
2009-02-25 22:35:41 +00:00
|
|
|
theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
|
2007-10-06 08:15:40 +00:00
|
|
|
dim.des += a + d;
|
2007-08-31 12:05:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-31 07:15:32 +00:00
|
|
|
case TopButton:
|
|
|
|
case LeftButton:
|
|
|
|
case ButtonOnly:
|
2015-10-07 09:15:35 +00:00
|
|
|
if (hasFixedWidth()){
|
2016-04-19 13:45:08 +00:00
|
|
|
int const mindim = view_[&bv].button_dim_.x2 - view_[&bv].button_dim_.x1;
|
2015-10-07 09:30:04 +00:00
|
|
|
if (mi.base.textwidth < mindim)
|
|
|
|
mi.base.textwidth = mindim;
|
2015-10-07 09:15:35 +00:00
|
|
|
}
|
2009-02-25 22:35:41 +00:00
|
|
|
dim = dimensionCollapsed(bv);
|
2016-02-03 09:37:29 +00:00
|
|
|
if (geometry(bv) == TopButton || geometry(bv) == LeftButton) {
|
2007-09-05 13:45:58 +00:00
|
|
|
Dimension textdim;
|
|
|
|
InsetText::metrics(mi, textdim);
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[&bv].openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
|
|
|
|
if (view_[&bv].openinlined_) {
|
2007-09-01 09:24:20 +00:00
|
|
|
// Correct for button width.
|
2007-09-05 13:45:58 +00:00
|
|
|
dim.wid += textdim.wid;
|
|
|
|
dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
|
|
|
|
dim.asc = textdim.asc;
|
2004-03-10 08:50:46 +00:00
|
|
|
} else {
|
2007-11-02 16:34:37 +00:00
|
|
|
dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
|
2007-09-05 13:45:58 +00:00
|
|
|
dim.wid = max(dim.wid, textdim.wid);
|
2004-03-10 08:50:46 +00:00
|
|
|
}
|
2003-12-02 07:15:42 +00:00
|
|
|
}
|
2007-08-16 16:36:50 +00:00
|
|
|
break;
|
2003-07-18 07:47:07 +00:00
|
|
|
}
|
2007-10-30 12:30:46 +00:00
|
|
|
|
|
|
|
mi.base.font = tmpfont;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::setMouseHover(BufferView const * bv, bool mouse_hover)
|
2010-10-24 19:24:36 +00:00
|
|
|
const
|
2006-12-04 04:31:18 +00:00
|
|
|
{
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[bv].mouse_hover_ = mouse_hover;
|
2006-12-04 04:31:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2009-02-25 22:35:41 +00:00
|
|
|
BufferView const & bv = *pi.base.bv;
|
2007-11-03 09:03:08 +00:00
|
|
|
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[&bv].auto_open_ = bv.cursor().isInside(this);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
2016-05-23 09:01:29 +00:00
|
|
|
Changer dummy = pi.base.font.change(getFont(), true);
|
2007-10-30 12:30:46 +00:00
|
|
|
|
2007-08-18 23:26:07 +00:00
|
|
|
// Draw button first -- top, left or only
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension dimc = dimensionCollapsed(bv);
|
2007-09-05 22:08:41 +00:00
|
|
|
|
2009-07-16 07:44:35 +00:00
|
|
|
if (geometry(bv) == TopButton ||
|
|
|
|
geometry(bv) == LeftButton ||
|
|
|
|
geometry(bv) == ButtonOnly) {
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[&bv].button_dim_.x1 = x + 0;
|
|
|
|
view_[&bv].button_dim_.x2 = x + dimc.width();
|
|
|
|
view_[&bv].button_dim_.y1 = y - dimc.asc;
|
|
|
|
view_[&bv].button_dim_.y2 = y + dimc.des;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2012-11-26 08:10:14 +00:00
|
|
|
FontInfo labelfont = getLabelfont();
|
2009-07-13 06:46:52 +00:00
|
|
|
labelfont.setColor(labelColor());
|
2016-07-19 20:29:57 +00:00
|
|
|
labelfont.realize(pi.base.font);
|
2009-07-13 06:46:52 +00:00
|
|
|
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
|
2017-06-15 13:30:23 +00:00
|
|
|
view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
|
|
|
|
Color_buttonframe, TEXT_TO_INSET_OFFSET);
|
2016-05-23 09:01:29 +00:00
|
|
|
// Draw the change tracking cue on the label, unless RowPainter already
|
|
|
|
// takes care of it.
|
|
|
|
if (canPaintChange(bv))
|
|
|
|
pi.change_.paintCue(pi, x, y, x + dimc.width(), labelfont);
|
2007-09-01 11:40:09 +00:00
|
|
|
} else {
|
2016-04-19 13:45:08 +00:00
|
|
|
view_[&bv].button_dim_.x1 = 0;
|
|
|
|
view_[&bv].button_dim_.y1 = 0;
|
|
|
|
view_[&bv].button_dim_.x2 = 0;
|
|
|
|
view_[&bv].button_dim_.y2 = 0;
|
2007-08-18 23:26:07 +00:00
|
|
|
}
|
2006-03-10 16:10:35 +00:00
|
|
|
|
2016-12-06 08:48:49 +00:00
|
|
|
Dimension const textdim = dimensionHelper(bv);
|
2007-09-09 20:21:43 +00:00
|
|
|
int const baseline = y;
|
2007-08-18 23:26:07 +00:00
|
|
|
int textx, texty;
|
2016-05-23 09:01:29 +00:00
|
|
|
Geometry g = geometry(bv);
|
|
|
|
switch (g) {
|
2007-08-18 23:26:07 +00:00
|
|
|
case LeftButton:
|
2016-05-23 09:01:29 +00:00
|
|
|
case TopButton: {
|
|
|
|
if (g == LeftButton) {
|
|
|
|
textx = x + dimc.width();
|
|
|
|
texty = baseline;
|
|
|
|
} else {
|
|
|
|
textx = x;
|
|
|
|
texty = baseline + dimc.des + textdim.asc;
|
|
|
|
}
|
|
|
|
// Do not draw the cue for INSERTED -- it is already in the button and
|
|
|
|
// that's enough.
|
2018-02-22 05:44:39 +00:00
|
|
|
Changer cdummy = (pi.change_.type == Change::INSERTED)
|
2016-11-20 18:53:16 +00:00
|
|
|
? make_change(pi.change_, Change())
|
|
|
|
: Changer();
|
2007-08-18 23:26:07 +00:00
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
break;
|
2016-05-23 09:01:29 +00:00
|
|
|
}
|
2007-08-18 23:26:07 +00:00
|
|
|
case ButtonOnly:
|
|
|
|
break;
|
|
|
|
case NoButton:
|
2007-09-17 21:45:14 +00:00
|
|
|
textx = x;
|
2007-09-06 12:00:32 +00:00
|
|
|
texty = baseline;
|
2007-08-18 23:26:07 +00:00
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
break;
|
|
|
|
case SubLabel:
|
|
|
|
case Corners:
|
2007-09-17 21:45:14 +00:00
|
|
|
textx = x;
|
2007-09-06 14:17:03 +00:00
|
|
|
texty = baseline;
|
2018-02-22 05:44:39 +00:00
|
|
|
// We will take care of the frame and the change tracking cue
|
|
|
|
// ourselves, below.
|
|
|
|
{
|
|
|
|
Changer cdummy = make_change(pi.change_, Change());
|
2017-10-16 08:12:21 +00:00
|
|
|
const_cast<InsetCollapsible *>(this)->setDrawFrame(false);
|
2016-05-23 09:01:29 +00:00
|
|
|
InsetText::draw(pi, textx, texty);
|
2017-10-16 08:12:21 +00:00
|
|
|
const_cast<InsetCollapsible *>(this)->setDrawFrame(true);
|
2016-05-23 09:01:29 +00:00
|
|
|
}
|
2007-08-19 15:45:35 +00:00
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
int desc = textdim.descent();
|
2016-05-23 09:01:29 +00:00
|
|
|
if (g == Corners)
|
2007-08-19 15:45:35 +00:00
|
|
|
desc -= 3;
|
|
|
|
|
2016-05-23 09:01:29 +00:00
|
|
|
// Colour the frame according to the change type. (Like for tables.)
|
|
|
|
Color colour = pi.change_.changed() ? pi.change_.color()
|
|
|
|
: Color_foreground;
|
2007-09-17 21:45:14 +00:00
|
|
|
const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
|
2007-09-18 20:18:50 +00:00
|
|
|
const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
|
2016-02-03 09:42:01 +00:00
|
|
|
pi.pain.line(xx1, y + desc - 4,
|
2016-05-23 09:01:29 +00:00
|
|
|
xx1, y + desc, colour);
|
2007-11-07 21:57:19 +00:00
|
|
|
if (status_ == Open)
|
2016-02-03 09:42:01 +00:00
|
|
|
pi.pain.line(xx1, y + desc,
|
2016-05-23 09:01:29 +00:00
|
|
|
xx2, y + desc, colour);
|
2007-08-19 15:45:35 +00:00
|
|
|
else {
|
|
|
|
// Make status_ value visible:
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx1, y + desc,
|
2016-05-23 09:01:29 +00:00
|
|
|
xx1 + 4, y + desc, colour);
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx2 - 4, y + desc,
|
2016-05-23 09:01:29 +00:00
|
|
|
xx2, y + desc, colour);
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
2016-02-03 09:42:01 +00:00
|
|
|
pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
|
2016-05-23 09:01:29 +00:00
|
|
|
y + desc - 4, colour);
|
2007-08-19 15:45:35 +00:00
|
|
|
|
2007-09-01 17:55:21 +00:00
|
|
|
// the label below the text. Can be toggled.
|
2016-05-23 09:01:29 +00:00
|
|
|
if (g == SubLabel) {
|
2012-11-26 08:10:14 +00:00
|
|
|
FontInfo font(getLabelfont());
|
2016-05-23 09:01:29 +00:00
|
|
|
if (pi.change_.changed())
|
|
|
|
font.setPaintColor(colour);
|
2007-10-28 18:51:54 +00:00
|
|
|
font.realize(sane_font);
|
2007-08-19 15:45:35 +00:00
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
2017-06-08 14:47:26 +00:00
|
|
|
Color const col = pi.full_repaint ? Color_none : pi.backgroundColor(this);
|
2009-02-25 22:35:41 +00:00
|
|
|
theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
|
2007-10-06 08:15:40 +00:00
|
|
|
int const ww = max(textdim.wid, w);
|
|
|
|
pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
|
2017-06-08 14:47:26 +00:00
|
|
|
buttonLabel(bv), font, col, Color_none);
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 09:01:29 +00:00
|
|
|
int const y1 = y - textdim.asc + 3;
|
2007-09-18 20:18:50 +00:00
|
|
|
// a visual cue when the cursor is inside the inset
|
2009-02-25 22:35:41 +00:00
|
|
|
Cursor const & cur = bv.cursor();
|
2007-08-19 15:45:35 +00:00
|
|
|
if (cur.isInside(this)) {
|
2016-05-23 09:01:29 +00:00
|
|
|
pi.pain.line(xx1, y1 + 4, xx1, y1, colour);
|
|
|
|
pi.pain.line(xx1 + 4, y1, xx1, y1, colour);
|
|
|
|
pi.pain.line(xx2, y1 + 4, xx2, y1, colour);
|
|
|
|
pi.pain.line(xx2 - 4, y1, xx2, y1, colour);
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
2016-05-23 09:01:29 +00:00
|
|
|
// Strike through the inset if deleted and not already handled by
|
|
|
|
// RowPainter.
|
|
|
|
if (pi.change_.deleted() && canPaintChange(bv))
|
|
|
|
pi.change_.paintCue(pi, xx1, y1, xx2, y + desc);
|
2007-08-18 23:26:07 +00:00
|
|
|
break;
|
2003-03-20 14:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::cursorPos(BufferView const & bv,
|
2006-10-17 16:23:27 +00:00
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2004-11-30 01:59:49 +00:00
|
|
|
{
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == ButtonOnly)
|
2007-09-20 14:11:37 +00:00
|
|
|
status_ = Open;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
InsetText::cursorPos(bv, sl, boundary, x, y);
|
2016-12-06 08:48:49 +00:00
|
|
|
Dimension const textdim = dimensionHelper(bv);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
switch (geometry(bv)) {
|
2007-08-16 16:36:50 +00:00
|
|
|
case LeftButton:
|
2009-02-25 22:35:41 +00:00
|
|
|
x += dimensionCollapsed(bv).wid;
|
2007-08-16 16:36:50 +00:00
|
|
|
break;
|
2007-09-05 14:15:07 +00:00
|
|
|
case TopButton: {
|
2009-02-25 22:35:41 +00:00
|
|
|
y += dimensionCollapsed(bv).des + textdim.asc;
|
2007-08-16 16:36:50 +00:00
|
|
|
break;
|
2007-09-05 14:15:07 +00:00
|
|
|
}
|
2007-08-16 16:36:50 +00:00
|
|
|
case NoButton:
|
|
|
|
case SubLabel:
|
|
|
|
case Corners:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
case ButtonOnly:
|
|
|
|
// Cannot get here
|
|
|
|
break;
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::editable() const
|
2003-03-20 14:13:49 +00:00
|
|
|
{
|
2018-10-04 17:36:01 +00:00
|
|
|
if (tempfile_)
|
|
|
|
return false;
|
|
|
|
|
2016-02-03 09:37:29 +00:00
|
|
|
switch (decoration()) {
|
|
|
|
case InsetLayout::CLASSIC:
|
|
|
|
case InsetLayout::MINIMALISTIC:
|
|
|
|
return status_ == Open;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::descendable(BufferView const & bv) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2018-10-04 17:36:01 +00:00
|
|
|
if (tempfile_)
|
|
|
|
return false;
|
|
|
|
|
2009-10-24 00:02:41 +00:00
|
|
|
return geometry(bv) != ButtonOnly;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::clickable(BufferView const & bv, int x, int y) const
|
2003-07-30 14:43:14 +00:00
|
|
|
{
|
2016-04-19 13:45:08 +00:00
|
|
|
return view_[&bv].button_dim_.contains(x, y);
|
2010-10-24 20:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
docstring const InsetCollapsible::getNewLabel(docstring const & l) const
|
2003-12-01 14:51:52 +00:00
|
|
|
{
|
2017-09-06 08:02:51 +00:00
|
|
|
odocstringstream label;
|
2003-12-01 14:51:52 +00:00
|
|
|
pos_type const max_length = 15;
|
2004-03-25 09:16:36 +00:00
|
|
|
pos_type const p_siz = paragraphs().begin()->size();
|
2007-12-12 19:28:07 +00:00
|
|
|
pos_type const n = min(max_length, p_siz);
|
2003-12-01 14:51:52 +00:00
|
|
|
pos_type i = 0;
|
|
|
|
pos_type j = 0;
|
2005-07-15 15:49:40 +00:00
|
|
|
for (; i < n && j < p_siz; ++j) {
|
2017-10-22 17:08:10 +00:00
|
|
|
if (paragraphs().begin()->isDeleted(j))
|
|
|
|
continue;
|
2017-09-06 08:02:51 +00:00
|
|
|
if (paragraphs().begin()->isInset(j)) {
|
|
|
|
if (!paragraphs().begin()->getInset(j)->isChar())
|
|
|
|
continue;
|
|
|
|
paragraphs().begin()->getInset(j)->toString(label);
|
|
|
|
} else
|
|
|
|
label.put(paragraphs().begin()->getChar(j));
|
2003-12-01 14:51:52 +00:00
|
|
|
++i;
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
|
2017-09-06 08:02:51 +00:00
|
|
|
label << "...";
|
2003-12-01 14:51:52 +00:00
|
|
|
}
|
2017-09-06 08:02:51 +00:00
|
|
|
docstring const lbl = label.str();
|
|
|
|
return lbl.empty() ? l : lbl;
|
2003-12-01 14:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2003-10-15 08:49:44 +00:00
|
|
|
{
|
2017-10-16 08:12:21 +00:00
|
|
|
//lyxerr << "InsetCollapsible: edit left/right" << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
cur.push(*this);
|
2008-02-10 19:52:45 +00:00
|
|
|
InsetText::edit(cur, front, entry_from);
|
2003-10-15 08:49:44 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
Inset * InsetCollapsible::editXY(Cursor & cur, int x, int y)
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2017-10-16 08:12:21 +00:00
|
|
|
//lyxerr << "InsetCollapsible: edit xy" << endl;
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(cur.bv()) == ButtonOnly
|
2019-03-15 00:28:01 +00:00
|
|
|
|| !descendable(cur.bv())
|
2016-04-19 13:45:08 +00:00
|
|
|
|| (view_[&cur.bv()].button_dim_.contains(x, y)
|
2016-02-03 09:37:29 +00:00
|
|
|
&& geometry(cur.bv()) != NoButton))
|
2005-07-15 00:39:44 +00:00
|
|
|
return this;
|
|
|
|
cur.push(*this);
|
2004-03-25 09:16:36 +00:00
|
|
|
return InsetText::editXY(cur, x, y);
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2017-10-16 08:12:21 +00:00
|
|
|
//lyxerr << "InsetCollapsible::doDispatch (begin): cmd: " << cmd
|
2005-07-15 11:43:07 +00:00
|
|
|
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
2016-02-03 09:37:29 +00:00
|
|
|
bool const hitButton = clickable(cur.bv(), cmd.x(), cmd.y());
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2004-03-30 12:36:33 +00:00
|
|
|
case LFUN_MOUSE_PRESS:
|
2016-02-03 09:37:29 +00:00
|
|
|
if (hitButton) {
|
2008-03-25 10:54:38 +00:00
|
|
|
switch (cmd.button()) {
|
|
|
|
case mouse_button::button1:
|
2008-08-13 15:01:12 +00:00
|
|
|
case mouse_button::button3:
|
2008-08-12 14:13:16 +00:00
|
|
|
// Pass the command to the enclosing InsetText,
|
|
|
|
// so that the cursor gets set.
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
2008-04-01 10:29:48 +00:00
|
|
|
case mouse_button::none:
|
2008-03-25 10:54:38 +00:00
|
|
|
case mouse_button::button2:
|
2008-04-01 10:29:48 +00:00
|
|
|
case mouse_button::button4:
|
|
|
|
case mouse_button::button5:
|
2008-03-25 10:54:38 +00:00
|
|
|
// Nothing to do.
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2008-08-12 14:13:16 +00:00
|
|
|
break;
|
2008-03-25 10:54:38 +00:00
|
|
|
}
|
2009-02-21 16:27:00 +00:00
|
|
|
} else if (geometry(cur.bv()) != ButtonOnly)
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-08-14 15:55:22 +00:00
|
|
|
else
|
2006-04-15 15:10:03 +00:00
|
|
|
cur.undispatched();
|
2004-03-30 12:36:33 +00:00
|
|
|
break;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
2005-04-22 14:59:13 +00:00
|
|
|
case LFUN_MOUSE_DOUBLE:
|
|
|
|
case LFUN_MOUSE_TRIPLE:
|
2016-02-03 09:37:29 +00:00
|
|
|
if (hitButton)
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2009-02-21 16:27:00 +00:00
|
|
|
else if (geometry(cur.bv()) != ButtonOnly)
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-11-30 01:59:49 +00:00
|
|
|
else
|
|
|
|
cur.undispatched();
|
2004-03-30 12:36:33 +00:00
|
|
|
break;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
case LFUN_MOUSE_RELEASE:
|
2016-02-03 09:37:29 +00:00
|
|
|
if (!hitButton) {
|
2006-11-17 17:42:52 +00:00
|
|
|
// The mouse click has to be within the inset!
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(cur.bv()) != ButtonOnly)
|
2008-08-12 14:13:16 +00:00
|
|
|
InsetText::doDispatch(cur, cmd);
|
|
|
|
else
|
2016-02-03 09:42:01 +00:00
|
|
|
cur.undispatched();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2006-11-17 17:42:52 +00:00
|
|
|
}
|
2008-03-25 21:44:30 +00:00
|
|
|
if (cmd.button() != mouse_button::button1) {
|
2008-08-12 14:13:16 +00:00
|
|
|
// Nothing to do.
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2004-03-30 12:36:33 +00:00
|
|
|
}
|
2008-03-25 21:44:30 +00:00
|
|
|
// if we are selecting, we do not want to
|
|
|
|
// toggle the inset.
|
|
|
|
if (cur.selection())
|
|
|
|
break;
|
|
|
|
// Left button is clicked, the user asks to
|
|
|
|
// toggle the inset visual state.
|
|
|
|
cur.dispatched();
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.screenUpdateFlags(Update::Force | Update::FitCursor);
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(cur.bv()) == ButtonOnly) {
|
2008-03-25 21:44:30 +00:00
|
|
|
setStatus(cur, Open);
|
|
|
|
edit(cur, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setStatus(cur, Collapsed);
|
|
|
|
cur.bv().cursor() = cur;
|
2004-03-30 12:36:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
2006-09-01 15:41:38 +00:00
|
|
|
if (cmd.argument() == "open")
|
2005-05-06 20:00:31 +00:00
|
|
|
setStatus(cur, Open);
|
2006-09-01 15:41:38 +00:00
|
|
|
else if (cmd.argument() == "close")
|
2005-05-06 20:00:31 +00:00
|
|
|
setStatus(cur, Collapsed);
|
2006-09-01 15:41:38 +00:00
|
|
|
else if (cmd.argument() == "toggle" || cmd.argument().empty())
|
2010-11-29 15:19:20 +00:00
|
|
|
if (status_ == Open)
|
2005-10-24 09:42:20 +00:00
|
|
|
setStatus(cur, Collapsed);
|
2010-11-29 15:19:20 +00:00
|
|
|
else
|
2005-10-24 09:42:20 +00:00
|
|
|
setStatus(cur, Open);
|
2005-05-06 20:00:31 +00:00
|
|
|
else // if assign or anything else
|
2004-04-07 05:28:51 +00:00
|
|
|
cur.undispatched();
|
2004-03-30 12:36:33 +00:00
|
|
|
cur.dispatched();
|
|
|
|
break;
|
|
|
|
|
2018-10-04 17:36:01 +00:00
|
|
|
case LFUN_INSET_EDIT: {
|
|
|
|
cur.push(*this);
|
|
|
|
text().selectAll(cur);
|
|
|
|
string const format =
|
|
|
|
cur.buffer()->params().documentClass().outputFormat();
|
|
|
|
string const ext = theFormats().extension(format);
|
|
|
|
tempfile_.reset(new support::TempFile("ert_editXXXXXX." + ext));
|
|
|
|
support::FileName const tempfilename = tempfile_->name();
|
|
|
|
string const name = tempfilename.toFilesystemEncoding();
|
|
|
|
ofdocstream os(name.c_str());
|
|
|
|
os << cur.selectionAsString(false);
|
|
|
|
os.close();
|
|
|
|
// Since we lock the inset while the external file is edited,
|
|
|
|
// we need to move the cursor outside and clear any selection inside
|
|
|
|
cur.clearSelection();
|
|
|
|
cur.pop();
|
|
|
|
cur.leaveInset(*this);
|
|
|
|
theFormats().edit(buffer(), tempfilename, format);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_INSET_END_EDIT: {
|
|
|
|
support::FileName const tempfilename = tempfile_->name();
|
|
|
|
docstring const s = tempfilename.fileContents("UTF-8");
|
|
|
|
cur.recordUndoInset(this);
|
|
|
|
cur.push(*this);
|
|
|
|
text().selectAll(cur);
|
|
|
|
cap::replaceSelection(cur);
|
|
|
|
cur.text()->insertStringAsLines(cur, s, cur.current_font);
|
|
|
|
// FIXME (gb) it crashes without this
|
|
|
|
cur.fixIfBroken();
|
|
|
|
tempfile_.reset();
|
|
|
|
cur.pop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-03-30 12:36:33 +00:00
|
|
|
break;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_TOGGLE:
|
2008-04-15 14:25:57 +00:00
|
|
|
if (cmd.argument() == "open")
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(status_ != Open);
|
2008-04-15 14:25:57 +00:00
|
|
|
else if (cmd.argument() == "close")
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(status_ == Open);
|
2008-04-15 14:25:57 +00:00
|
|
|
else if (cmd.argument() == "toggle" || cmd.argument().empty()) {
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2008-04-15 14:25:57 +00:00
|
|
|
flag.setOnOff(status_ == Open);
|
|
|
|
} else
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2005-04-22 08:57:22 +00:00
|
|
|
return true;
|
2018-10-04 17:36:01 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_EDIT:
|
|
|
|
flag.setEnabled(getLayout().editExternally() && tempfile_ == 0);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LFUN_INSET_END_EDIT:
|
|
|
|
flag.setEnabled(getLayout().editExternally() && tempfile_ != 0);
|
|
|
|
return true;
|
2005-04-22 08:57:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetText::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::setLabel(docstring const & l)
|
2001-07-24 22:08:49 +00:00
|
|
|
{
|
2007-11-03 00:35:07 +00:00
|
|
|
labelstring_ = l;
|
2001-07-24 22:08:49 +00:00
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
docstring InsetCollapsible::getLabel() const
|
2009-07-14 16:01:07 +00:00
|
|
|
{
|
2009-12-18 00:29:22 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
2015-11-22 22:48:24 +00:00
|
|
|
return labelstring_.empty() ?
|
2010-12-14 23:18:48 +00:00
|
|
|
translateIfPossible(il.labelstring()) : labelstring_;
|
2015-11-22 22:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
docstring const InsetCollapsible::buttonLabel(BufferView const & bv) const
|
2015-11-22 22:48:24 +00:00
|
|
|
{
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
docstring const label = getLabel();
|
2009-12-18 00:29:22 +00:00
|
|
|
if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
|
|
|
|
return label;
|
|
|
|
return getNewLabel(label);
|
2009-07-14 16:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::setStatus(Cursor & cur, CollapseStatus status)
|
2003-09-16 15:39:33 +00:00
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
status_ = status;
|
2003-12-12 14:02:14 +00:00
|
|
|
setButtonLabel();
|
2010-05-03 23:01:47 +00:00
|
|
|
if (status_ == Collapsed)
|
2005-05-06 20:00:31 +00:00
|
|
|
cur.leaveInset(*this);
|
2003-09-16 15:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetLayout::InsetDecoration InsetCollapsible::decoration() const
|
2007-08-25 20:12:50 +00:00
|
|
|
{
|
2009-07-13 00:28:22 +00:00
|
|
|
InsetLayout::InsetDecoration const dec = getLayout().decoration();
|
2009-07-13 14:06:05 +00:00
|
|
|
return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
|
2007-08-25 20:12:50 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:02:38 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
string InsetCollapsible::contextMenu(BufferView const & bv, int x,
|
2008-03-08 22:57:22 +00:00
|
|
|
int y) const
|
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
string context_menu = contextMenuName();
|
|
|
|
string const it_context_menu = InsetText::contextMenuName();
|
2008-10-25 13:41:02 +00:00
|
|
|
if (decoration() == InsetLayout::CONGLOMERATE)
|
2010-11-30 00:05:06 +00:00
|
|
|
return context_menu + ";" + it_context_menu;
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
string const ic_context_menu = InsetCollapsible::contextMenuName();
|
2010-11-30 00:05:06 +00:00
|
|
|
if (ic_context_menu != context_menu)
|
|
|
|
context_menu += ";" + ic_context_menu;
|
2008-03-25 06:17:18 +00:00
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == NoButton)
|
2010-11-30 00:05:06 +00:00
|
|
|
return context_menu + ";" + it_context_menu;
|
2008-03-21 18:02:47 +00:00
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension dim = dimensionCollapsed(bv);
|
2008-03-21 18:02:47 +00:00
|
|
|
if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
|
2010-11-30 00:05:06 +00:00
|
|
|
return context_menu;
|
2010-11-29 21:27:25 +00:00
|
|
|
|
2010-11-30 00:05:06 +00:00
|
|
|
return it_context_menu;
|
2010-11-29 21:27:25 +00:00
|
|
|
}
|
2008-03-08 22:57:22 +00:00
|
|
|
|
2010-11-29 21:27:25 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
string InsetCollapsible::contextMenuName() const
|
2010-11-29 21:27:25 +00:00
|
|
|
{
|
|
|
|
if (decoration() == InsetLayout::CONGLOMERATE)
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-conglomerate";
|
2010-11-29 21:27:25 +00:00
|
|
|
else
|
2017-10-16 08:12:21 +00:00
|
|
|
return "context-collapsible";
|
2008-03-08 22:57:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 21:48:28 +00:00
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
bool InsetCollapsible::canPaintChange(BufferView const & bv) const
|
2016-05-22 21:48:28 +00:00
|
|
|
{
|
2016-05-23 09:01:29 +00:00
|
|
|
// return false to let RowPainter draw the change tracking cue consistently
|
|
|
|
// with the surrounding text, when the inset is inline: for buttons, for
|
|
|
|
// non-allowMultiPar insets.
|
2016-05-22 21:48:28 +00:00
|
|
|
switch (geometry(bv)) {
|
|
|
|
case Corners:
|
|
|
|
case SubLabel:
|
2016-05-23 09:01:29 +00:00
|
|
|
return allowMultiPar();
|
2016-05-22 21:48:28 +00:00
|
|
|
case ButtonOnly:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
void InsetCollapsible::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const
|
2017-01-09 12:28:48 +00:00
|
|
|
{
|
|
|
|
bool doing_output = output_active && producesOutput();
|
|
|
|
InsetLayout const & layout = getLayout();
|
2017-11-24 20:34:25 +00:00
|
|
|
if (!layout.addToToc())
|
|
|
|
return InsetText::addToToc(cpit, doing_output, utype, backend);
|
|
|
|
|
|
|
|
TocBuilder & b = backend.builder(layout.tocType());
|
|
|
|
// Cursor inside the inset
|
|
|
|
DocIterator pit = cpit;
|
|
|
|
pit.push_back(CursorSlice(const_cast<InsetCollapsible &>(*this)));
|
|
|
|
docstring const label = getLabel();
|
|
|
|
b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active);
|
|
|
|
// Proceed with the rest of the inset.
|
|
|
|
InsetText::addToToc(cpit, doing_output, utype, backend);
|
|
|
|
if (layout.isTocCaption()) {
|
|
|
|
docstring str;
|
|
|
|
text().forOutliner(str, TOC_ENTRY_LENGTH);
|
|
|
|
b.argumentItem(str);
|
|
|
|
}
|
|
|
|
b.pop();
|
2017-01-09 12:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|