2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetCollapsable.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
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>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>
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetCollapsable.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
2006-10-08 08:47:26 +00:00
|
|
|
|
#include "FloatList.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2006-10-08 08:47:26 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 17:34:20 +00:00
|
|
|
|
#include "Color.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
#include "MetricsInfo.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
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using graphics::PreviewLoader;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-07-17 18:27:53 +00:00
|
|
|
|
using std::max;
|
2003-12-01 14:51:52 +00:00
|
|
|
|
using std::min;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
2001-04-04 20:34:04 +00:00
|
|
|
|
|
2005-09-28 15:02:47 +00:00
|
|
|
|
InsetCollapsable::CollapseStatus InsetCollapsable::status() const
|
|
|
|
|
{
|
2007-08-16 16:36:50 +00:00
|
|
|
|
return autoOpen_ ? Open : status_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
|
|
|
|
{
|
|
|
|
|
switch (decoration()) {
|
|
|
|
|
case Classic:
|
|
|
|
|
if (status_ == Open || autoOpen_) {
|
|
|
|
|
if (openinlined_)
|
|
|
|
|
return LeftButton;
|
|
|
|
|
else
|
|
|
|
|
return TopButton;
|
|
|
|
|
} else
|
|
|
|
|
return ButtonOnly;
|
2007-08-17 12:11:32 +00:00
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
case Minimalistic:
|
|
|
|
|
return NoButton;
|
2007-08-17 12:11:32 +00:00
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
case Conglomerate:
|
2007-08-17 12:11:32 +00:00
|
|
|
|
return status_ == Open ? SubLabel : Corners;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetCollapsable::InsetCollapsable
|
|
|
|
|
(BufferParams const & bp, CollapseStatus status)
|
2007-08-19 10:08:09 +00:00
|
|
|
|
: InsetText(bp), status_(status),
|
2006-12-04 04:31:18 +00:00
|
|
|
|
openinlined_(false), autoOpen_(false), mouse_hover_(false)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
setAutoBreakRows(true);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
setDrawFrame(true);
|
2007-04-26 17:34:20 +00:00
|
|
|
|
setFrameColor(Color::collapsableframe);
|
2003-12-12 14:02:14 +00:00
|
|
|
|
setButtonLabel();
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 12:32:14 +00:00
|
|
|
|
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
|
2007-05-28 22:27:45 +00:00
|
|
|
|
: InsetText(rhs),
|
2007-04-29 12:32:14 +00:00
|
|
|
|
button_dim(rhs.button_dim),
|
|
|
|
|
topx(rhs.topx),
|
|
|
|
|
topbaseline(rhs.topbaseline),
|
2007-08-13 20:12:52 +00:00
|
|
|
|
layout_(rhs.layout_),
|
2007-04-29 12:32:14 +00:00
|
|
|
|
status_(rhs.status_),
|
|
|
|
|
openinlined_(rhs.openinlined_),
|
|
|
|
|
autoOpen_(rhs.autoOpen_),
|
|
|
|
|
textdim_(rhs.textdim_),
|
|
|
|
|
// the sole purpose of this copy constructor
|
|
|
|
|
mouse_hover_(false)
|
2006-12-05 05:36:59 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-13 12:13:17 +00:00
|
|
|
|
void InsetCollapsable::setLayout(BufferParams const & bp)
|
|
|
|
|
{
|
2007-08-19 10:08:09 +00:00
|
|
|
|
layout_ = getLayout(bp);
|
2007-08-13 12:13:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetCollapsable::write(Buffer const & buf, 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";
|
2004-03-25 09:16:36 +00:00
|
|
|
|
text_.write(buf, os);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2003-12-12 14:02:14 +00:00
|
|
|
|
bool token_found = false;
|
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();
|
2003-12-12 14:02:14 +00:00
|
|
|
|
if (token == "status") {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lex.next();
|
2003-12-12 14:02:14 +00:00
|
|
|
|
string const tmp_token = lex.getString();
|
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (tmp_token == "collapsed") {
|
2003-12-12 14:02:14 +00:00
|
|
|
|
status_ = Collapsed;
|
|
|
|
|
token_found = true;
|
|
|
|
|
} else if (tmp_token == "open") {
|
|
|
|
|
status_ = Open;
|
|
|
|
|
token_found = true;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetCollapsable::read: Missing status!"
|
|
|
|
|
<< endl;
|
|
|
|
|
// Take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
} else {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lyxerr << "InsetCollapsable::read: Missing 'status'-tag!"
|
2003-12-12 14:02:14 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
// take countermeasures
|
2001-07-25 22:05:53 +00:00
|
|
|
|
lex.pushToken(token);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::read(buf, lex);
|
2003-12-12 14:02:14 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (!token_found)
|
|
|
|
|
status_ = isOpen() ? Open : Collapsed;
|
2003-12-12 14:02:14 +00:00
|
|
|
|
|
|
|
|
|
setButtonLabel();
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Dimension InsetCollapsable::dimensionCollapsed() const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Dimension dim;
|
2007-08-13 12:13:17 +00:00
|
|
|
|
theFontMetrics(layout_.labelfont).buttonText(
|
2007-08-19 10:08:09 +00:00
|
|
|
|
layout_.labelstring, dim.wid, dim.asc, dim.des);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return dim;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2005-09-28 15:02:47 +00:00
|
|
|
|
autoOpen_ = mi.base.bv->cursor().isInside(this);
|
2007-02-07 10:39:38 +00:00
|
|
|
|
mi.base.textwidth -= (int) (1.5 * TEXT_TO_INSET_OFFSET);
|
2005-09-28 15:02:47 +00:00
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
switch (decoration()) {
|
|
|
|
|
case Minimalistic:
|
2007-08-19 15:45:35 +00:00
|
|
|
|
InsetText::metrics(mi, dim);
|
|
|
|
|
break;
|
2007-08-16 16:36:50 +00:00
|
|
|
|
case Conglomerate:
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::metrics(mi, dim);
|
2007-08-19 15:45:35 +00:00
|
|
|
|
if (status() == Open) {
|
|
|
|
|
// consider width of the inset label
|
|
|
|
|
Font font(layout_.labelfont);
|
|
|
|
|
font.realize(Font(Font::ALL_SANE));
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
|
|
|
|
docstring s = layout_.labelstring;
|
|
|
|
|
theFontMetrics(font).rectText(s, w, a, d);
|
|
|
|
|
dim.wid = max(dim.wid, w);
|
|
|
|
|
}
|
|
|
|
|
if (status() == Open)
|
|
|
|
|
dim.des += ascent();
|
|
|
|
|
else {
|
|
|
|
|
dim.des -= 3;
|
|
|
|
|
dim.asc -= 3;
|
|
|
|
|
}
|
2007-08-16 16:36:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case Classic:
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim = dimensionCollapsed();
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (geometry() == TopButton
|
|
|
|
|
|| geometry() == LeftButton) {
|
2004-03-27 13:29:17 +00:00
|
|
|
|
InsetText::metrics(mi, textdim_);
|
2006-07-17 05:30:36 +00:00
|
|
|
|
// This expression should not contain mi.base.texwidth
|
2007-05-28 22:27:45 +00:00
|
|
|
|
openinlined_ = !hasFixedWidth()
|
2006-12-29 11:52:01 +00:00
|
|
|
|
&& textdim_.wid < 0.5 * mi.base.bv->workWidth();
|
2004-03-10 08:50:46 +00:00
|
|
|
|
if (openinlined_) {
|
2006-06-20 12:39:39 +00:00
|
|
|
|
// Correct for button width, and re-fit
|
|
|
|
|
mi.base.textwidth -= dim.wid;
|
|
|
|
|
InsetText::metrics(mi, textdim_);
|
2004-03-27 13:29:17 +00:00
|
|
|
|
dim.wid += textdim_.wid;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim.des = max(dim.des - textdim_.asc + dim.asc, textdim_.des);
|
|
|
|
|
dim.asc = textdim_.asc;
|
2004-03-10 08:50:46 +00:00
|
|
|
|
} else {
|
2004-03-27 13:29:17 +00:00
|
|
|
|
dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
|
|
|
|
|
dim.wid = max(dim.wid, textdim_.wid);
|
2007-04-21 08:43:46 +00:00
|
|
|
|
if (hasFixedWidth())
|
|
|
|
|
dim.wid = max(dim.wid, mi.base.textwidth);
|
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
|
|
|
|
}
|
2004-03-27 13:29:17 +00:00
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
2007-02-07 10:39:38 +00:00
|
|
|
|
dim.wid += (int) (1.5 * TEXT_TO_INSET_OFFSET);
|
|
|
|
|
mi.base.textwidth += (int) (1.5 * TEXT_TO_INSET_OFFSET);
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
bool InsetCollapsable::setMouseHover(bool mouse_hover)
|
|
|
|
|
{
|
|
|
|
|
mouse_hover_ = mouse_hover;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
const int xx = x + TEXT_TO_INSET_OFFSET;
|
2007-08-16 16:36:50 +00:00
|
|
|
|
|
2007-08-18 23:26:07 +00:00
|
|
|
|
// Draw button first -- top, left or only
|
|
|
|
|
Dimension dimc = dimensionCollapsed();
|
|
|
|
|
int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
if (decoration() == Classic) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
button_dim.x1 = xx + 0;
|
|
|
|
|
button_dim.x2 = xx + dimc.width();
|
|
|
|
|
button_dim.y1 = top;
|
|
|
|
|
button_dim.y2 = top + dimc.height();
|
|
|
|
|
|
2007-08-19 10:08:09 +00:00
|
|
|
|
pi.pain.buttonText(xx, top + dimc.asc, layout_.labelstring, layout_.labelfont, mouse_hover_);
|
2007-08-18 23:26:07 +00:00
|
|
|
|
}
|
2006-03-10 16:10:35 +00:00
|
|
|
|
|
2007-08-18 23:26:07 +00:00
|
|
|
|
int textx, texty;
|
|
|
|
|
switch (geometry()) {
|
|
|
|
|
case LeftButton:
|
|
|
|
|
textx = xx + dimc.width();
|
|
|
|
|
texty = top + textdim_.asc;
|
|
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
|
break;
|
|
|
|
|
case TopButton:
|
|
|
|
|
textx = xx;
|
|
|
|
|
texty = top + dimc.height() + textdim_.asc;
|
|
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
|
break;
|
|
|
|
|
case ButtonOnly:
|
|
|
|
|
break;
|
|
|
|
|
case NoButton:
|
|
|
|
|
textx = xx;
|
|
|
|
|
texty = y + textdim_.asc;
|
|
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
|
break;
|
|
|
|
|
case SubLabel:
|
|
|
|
|
case Corners:
|
|
|
|
|
textx = xx;
|
|
|
|
|
texty = y + textdim_.asc;
|
|
|
|
|
const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
|
|
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
|
const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
|
2007-08-19 15:45:35 +00:00
|
|
|
|
|
|
|
|
|
int desc = InsetText::descent();
|
|
|
|
|
if (status() == Open)
|
|
|
|
|
desc -= ascent();
|
|
|
|
|
else
|
|
|
|
|
desc -= 3;
|
|
|
|
|
|
|
|
|
|
pi.pain.line(x, y + desc - 4, x, y + desc,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
if (internalStatus() == Open)
|
|
|
|
|
pi.pain.line(x, y + desc,
|
|
|
|
|
x + dim_.wid - 3, y + desc,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
else {
|
|
|
|
|
// Make status_ value visible:
|
|
|
|
|
pi.pain.line(x, y + desc,
|
|
|
|
|
x + 4, y + desc,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + dim_.wid - 7, y + desc,
|
|
|
|
|
x + dim_.wid -3, y + desc,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
}
|
|
|
|
|
pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
|
|
|
|
|
// the label of the charstyle. Can be toggled.
|
|
|
|
|
if (status() == Open) {
|
|
|
|
|
Font font(layout_.labelfont);
|
|
|
|
|
font.realize(Font(Font::ALL_SANE));
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
docstring s = layout_.labelstring;
|
|
|
|
|
theFontMetrics(font).rectText(s, w, a, d);
|
|
|
|
|
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
|
|
|
|
|
s, font, Color::none, Color::none);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a visual cue when the cursor is inside the inset
|
|
|
|
|
Cursor & cur = pi.base.bv->cursor();
|
|
|
|
|
if (cur.isInside(this)) {
|
|
|
|
|
y -= ascent();
|
|
|
|
|
y += 3;
|
|
|
|
|
pi.pain.line(x, y + 4, x, y, layout_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + 4, y, x, y, layout_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
|
|
|
|
|
layout_.labelfont.color());
|
|
|
|
|
}
|
2007-08-18 23:26:07 +00:00
|
|
|
|
break;
|
2003-03-20 14:13:49 +00:00
|
|
|
|
}
|
2004-03-27 13:29:17 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-03-20 14:13:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2007-08-16 16:36:50 +00:00
|
|
|
|
switch (geometry()) {
|
|
|
|
|
case LeftButton:
|
|
|
|
|
x += dimensionCollapsed().wid;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetText::drawSelection(pi, x, y);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case TopButton:
|
|
|
|
|
y += dimensionCollapsed().des + textdim_.asc;
|
|
|
|
|
InsetText::drawSelection(pi, x, y);
|
|
|
|
|
break;
|
|
|
|
|
case ButtonOnly:
|
|
|
|
|
break;
|
|
|
|
|
case NoButton:
|
|
|
|
|
case SubLabel:
|
|
|
|
|
case Corners:
|
|
|
|
|
InsetText::drawSelection(pi, x, y);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
void InsetCollapsable::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
|
|
|
|
{
|
2007-08-16 16:36:50 +00:00
|
|
|
|
BOOST_ASSERT(geometry() != ButtonOnly);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
|
InsetText::cursorPos(bv, sl, boundary, x, y);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
switch (geometry()) {
|
|
|
|
|
case LeftButton:
|
|
|
|
|
x += dimensionCollapsed().wid;
|
|
|
|
|
break;
|
|
|
|
|
case TopButton:
|
|
|
|
|
y += dimensionCollapsed().height() - ascent()
|
|
|
|
|
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
|
|
|
|
|
break;
|
|
|
|
|
case NoButton:
|
|
|
|
|
case SubLabel:
|
|
|
|
|
case Corners:
|
|
|
|
|
// Do nothing
|
|
|
|
|
break;
|
|
|
|
|
case ButtonOnly:
|
|
|
|
|
// Cannot get here
|
|
|
|
|
break;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-09-28 15:02:47 +00:00
|
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::EDITABLE InsetCollapsable::editable() const
|
2003-03-20 14:13:49 +00:00
|
|
|
|
{
|
2007-08-16 16:36:50 +00:00
|
|
|
|
return geometry() != ButtonOnly? HIGHLY_EDITABLE : IS_EDITABLE;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
bool InsetCollapsable::descendable() const
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2007-08-16 16:36:50 +00:00
|
|
|
|
return geometry() != ButtonOnly;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
|
bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
|
2003-07-30 14:43:14 +00:00
|
|
|
|
{
|
2003-09-02 20:42:28 +00:00
|
|
|
|
return button_dim.contains(cmd.x, cmd.y);
|
2003-07-30 14:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-08 09:36:16 +00:00
|
|
|
|
docstring const InsetCollapsable::getNewLabel(docstring const & l) const
|
2003-12-01 14:51:52 +00:00
|
|
|
|
{
|
2006-10-08 09:36:16 +00:00
|
|
|
|
docstring 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();
|
2003-12-01 14:51:52 +00:00
|
|
|
|
pos_type const n = min(max_length, p_siz);
|
|
|
|
|
pos_type i = 0;
|
|
|
|
|
pos_type j = 0;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
for (; i < n && j < p_siz; ++j) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (paragraphs().begin()->isInset(j))
|
2003-12-01 14:51:52 +00:00
|
|
|
|
continue;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
label += 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)) {
|
2006-10-08 09:56:41 +00:00
|
|
|
|
label += "...";
|
2003-12-01 14:51:52 +00:00
|
|
|
|
}
|
2004-03-08 21:14:45 +00:00
|
|
|
|
return label.empty() ? l : label;
|
2003-12-01 14:51:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetCollapsable::edit(Cursor & cur, bool left)
|
2003-10-15 08:49:44 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable: edit left/right" << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.push(*this);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::edit(cur, left);
|
2003-10-15 08:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
|
2003-11-04 12:36:59 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable: edit xy" << endl;
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (geometry() == ButtonOnly
|
|
|
|
|
|| (button_dim.contains(x, y)
|
|
|
|
|
&& decoration() != Minimalistic))
|
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
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
2005-07-15 11:43:07 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
|
|
|
|
|
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
switch (cmd.action) {
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button1
|
|
|
|
|
&& hitButton(cmd)
|
|
|
|
|
&& decoration() != Minimalistic) {
|
2007-01-04 13:53:16 +00:00
|
|
|
|
// reset selection if necessary (see bug 3060)
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
cur.bv().cursor().clearSelection();
|
|
|
|
|
else
|
|
|
|
|
cur.noUpdate();
|
2006-11-17 17:42:52 +00:00
|
|
|
|
cur.dispatched();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (decoration() == Minimalistic)
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
else if (geometry() != ButtonOnly
|
|
|
|
|
&& !hitButton(cmd))
|
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
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case LFUN_MOUSE_MOTION:
|
2005-04-22 14:59:13 +00:00
|
|
|
|
case LFUN_MOUSE_DOUBLE:
|
|
|
|
|
case LFUN_MOUSE_TRIPLE:
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (decoration() == Minimalistic)
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
else if (geometry() != ButtonOnly
|
|
|
|
|
&& !hitButton(cmd))
|
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:
|
|
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2007-08-20 04:56:04 +00:00
|
|
|
|
if (decoration() == Conglomerate) {
|
|
|
|
|
|
|
|
|
|
if (internalStatus() == Open)
|
|
|
|
|
setStatus(cur, Collapsed);
|
|
|
|
|
else
|
|
|
|
|
setStatus(cur, Open);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
// Open the Inset
|
|
|
|
|
// configuration dialog
|
|
|
|
|
showInsetDialog(&cur.bv());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-30 12:36:33 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (decoration() == Minimalistic) {
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// The mouse click has to be within the inset!
|
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-11-17 17:42:52 +00:00
|
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
2006-12-20 13:25:46 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
|
|
|
|
|
// if we are selecting, we do not want to
|
|
|
|
|
// toggle the inset.
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
break;
|
2006-12-19 15:42:10 +00:00
|
|
|
|
// Left button is clicked, the user asks to
|
|
|
|
|
// toggle the inset visual state.
|
2006-11-17 17:42:52 +00:00
|
|
|
|
cur.dispatched();
|
|
|
|
|
cur.updateFlags(Update::Force | Update::FitCursor);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (geometry() == ButtonOnly) {
|
2006-11-17 17:42:52 +00:00
|
|
|
|
setStatus(cur, Open);
|
|
|
|
|
edit(cur, true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setStatus(cur, Collapsed);
|
2003-12-12 15:21:31 +00:00
|
|
|
|
}
|
2006-11-17 17:42:52 +00:00
|
|
|
|
cur.bv().cursor() = cur;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-03-30 12:36:33 +00:00
|
|
|
|
}
|
2003-12-01 13:35:49 +00:00
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// The mouse click is within the opened inset.
|
2007-08-16 16:36:50 +00:00
|
|
|
|
if (geometry() == TopButton
|
|
|
|
|
|| geometry() == LeftButton)
|
2006-12-28 03:00:48 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
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())
|
2007-08-20 04:56:04 +00:00
|
|
|
|
if (internalStatus() == Open) {
|
2005-10-24 09:42:20 +00:00
|
|
|
|
setStatus(cur, Collapsed);
|
2007-08-20 04:56:04 +00:00
|
|
|
|
if (geometry() == ButtonOnly)
|
|
|
|
|
cur.top().forwardPos();
|
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument() == "open" || cmd.argument() == "close" ||
|
|
|
|
|
cmd.argument() == "toggle")
|
2005-04-22 08:57:22 +00:00
|
|
|
|
flag.enabled(true);
|
|
|
|
|
else
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return InsetText::getStatus(cur, cmd, flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-08 09:36:16 +00:00
|
|
|
|
void InsetCollapsable::setLabel(docstring const & l)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
2007-08-19 10:08:09 +00:00
|
|
|
|
layout_.labelstring = l;
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetCollapsable::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();
|
2005-05-06 20:00:31 +00:00
|
|
|
|
if (status_ == Collapsed)
|
|
|
|
|
cur.leaveInset(*this);
|
2007-05-23 07:43:16 +00:00
|
|
|
|
// Because the collapse status is part of the inset and thus an
|
|
|
|
|
// integral part of the Buffer contents a changed status must be
|
|
|
|
|
// signaled to all views of current buffer.
|
|
|
|
|
cur.bv().buffer()->changed();
|
2003-09-16 15:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-13 12:13:17 +00:00
|
|
|
|
void InsetCollapsable::setLabelFont(Font const & font)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{
|
2007-08-13 12:13:17 +00:00
|
|
|
|
layout_.labelfont = font;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
}
|
2006-10-08 08:47:26 +00:00
|
|
|
|
|
2007-02-16 09:11:19 +00:00
|
|
|
|
docstring InsetCollapsable::floatName(string const & type, BufferParams const & bp) const
|
2006-10-08 08:47:26 +00:00
|
|
|
|
{
|
2007-04-29 19:53:54 +00:00
|
|
|
|
FloatList const & floats = bp.getTextClass().floats();
|
2006-10-08 08:47:26 +00:00
|
|
|
|
FloatList::const_iterator it = floats[type];
|
|
|
|
|
// FIXME UNICODE
|
2007-05-01 08:26:40 +00:00
|
|
|
|
return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
|
2006-10-08 08:47:26 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|