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
|
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>
|
|
|
|
|
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"
|
2007-11-03 18:50:54 +00:00
|
|
|
#include "Dimension.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2006-10-08 08:47:26 +00:00
|
|
|
#include "FloatList.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-10-30 12:30:46 +00:00
|
|
|
#include "Language.h"
|
2007-08-22 18:55:03 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2009-02-06 17:56:47 +00:00
|
|
|
#include "paragraph_funcs.h"
|
2007-10-30 12:30:46 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2009-02-06 17:56:47 +00:00
|
|
|
#include "sgml.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.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"
|
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
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
InsetCollapsable::CollapseStatus InsetCollapsable::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_;
|
2009-02-21 16:27:00 +00:00
|
|
|
return auto_open_[&bv] ? Open : status_;
|
2007-08-16 16:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
InsetCollapsable::Geometry InsetCollapsable::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)
|
2008-03-05 00:21:05 +00:00
|
|
|
return openinlined_ ? LeftButton : TopButton;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 00:04:28 +00:00
|
|
|
InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
|
|
|
{
|
|
|
|
switch (decoration()) {
|
|
|
|
case InsetLayout::CLASSIC:
|
|
|
|
if (status_ == Open)
|
|
|
|
return openinlined_ ? LeftButton : TopButton;
|
|
|
|
return ButtonOnly;
|
|
|
|
|
|
|
|
case InsetLayout::MINIMALISTIC:
|
|
|
|
return status_ == Open ? NoButton : ButtonOnly ;
|
|
|
|
|
|
|
|
case InsetLayout::CONGLOMERATE:
|
|
|
|
return status_ == Open ? SubLabel : Corners ;
|
|
|
|
|
|
|
|
case InsetLayout::DEFAULT:
|
|
|
|
break; // this shouldn't happen
|
|
|
|
}
|
|
|
|
|
|
|
|
// dummy return value to shut down a warning,
|
|
|
|
// this is dead code.
|
|
|
|
return NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-04 19:34:14 +00:00
|
|
|
InsetCollapsable::InsetCollapsable(Buffer const & buf, InsetText::UsePlain ltype)
|
|
|
|
: InsetText(buf, ltype), status_(Inset::Open),
|
2009-02-21 16:27:00 +00:00
|
|
|
openinlined_(false), mouse_hover_(false)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2009-04-04 19:34:14 +00:00
|
|
|
setLayout(&buf.params().documentClass());
|
2004-03-25 09:16:36 +00:00
|
|
|
setAutoBreakRows(true);
|
2004-08-14 15:55:22 +00:00
|
|
|
setDrawFrame(true);
|
2007-10-25 12:41:02 +00:00
|
|
|
setFrameColor(Color_collapsableframe);
|
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),
|
2008-10-27 10:36:38 +00:00
|
|
|
status_(rhs.status_),
|
|
|
|
layout_(rhs.layout_),
|
|
|
|
labelstring_(rhs.labelstring_),
|
|
|
|
button_dim(rhs.button_dim),
|
|
|
|
openinlined_(rhs.openinlined_),
|
2009-02-21 16:27:00 +00:00
|
|
|
auto_open_(rhs.auto_open_),
|
2008-10-27 10:36:38 +00:00
|
|
|
// the sole purpose of this copy constructor
|
|
|
|
mouse_hover_(false)
|
2006-12-05 05:36:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
|
|
|
|
{
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension dim = dimensionCollapsed(bv);
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == NoButton)
|
2008-04-11 15:11:27 +00:00
|
|
|
return translateIfPossible(layout_->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();
|
|
|
|
|
2008-04-27 14:47:07 +00:00
|
|
|
OutputParams rp(&buffer().params().encoding());
|
|
|
|
odocstringstream ods;
|
|
|
|
InsetText::plaintext(ods, rp);
|
2009-05-07 18:04:05 +00:00
|
|
|
docstring const content_tip = ods.str();
|
|
|
|
return support::wrapParas(content_tip, 4);
|
2007-12-25 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCollapsable::setLayout(BufferParams const & bp)
|
2007-08-13 12:13:17 +00:00
|
|
|
{
|
2008-02-28 01:42:02 +00:00
|
|
|
setLayout(bp.documentClassPtr());
|
2007-11-03 09:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 01:42:02 +00:00
|
|
|
void InsetCollapsable::setLayout(DocumentClass const * const dc)
|
2007-11-03 09:03:08 +00:00
|
|
|
{
|
2008-03-05 00:21:05 +00:00
|
|
|
if (dc) {
|
2008-02-28 01:42:02 +00:00
|
|
|
layout_ = &(dc->insetLayout(name()));
|
2008-04-11 15:11:27 +00:00
|
|
|
labelstring_ = translateIfPossible(layout_->labelstring());
|
2008-02-05 10:34:01 +00:00
|
|
|
} else {
|
2008-08-01 20:57:27 +00:00
|
|
|
layout_ = &DocumentClass::plainInsetLayout();
|
2008-02-05 10:34:01 +00:00
|
|
|
labelstring_ = _("UNDEFINED");
|
|
|
|
}
|
2007-11-02 21:27:41 +00:00
|
|
|
|
|
|
|
setButtonLabel();
|
2007-08-13 12:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetCollapsable::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";
|
2008-07-29 12:07:08 +00:00
|
|
|
text().write(buffer(), os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetCollapsable::read(Lexer & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetCollapsable::read");
|
|
|
|
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-24 15:44:11 +00:00
|
|
|
// this must be set before we enter InsetText::read()
|
2008-02-27 20:43:16 +00:00
|
|
|
setLayout(buffer().params());
|
|
|
|
InsetText::read(lex);
|
2008-10-17 04:35:08 +00:00
|
|
|
// set button label again as the inset contents was not read yet at
|
|
|
|
// setLayout() time.
|
|
|
|
setButtonLabel();
|
2008-02-20 16:56:33 +00:00
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
// Force default font, if so requested
|
|
|
|
// This avoids paragraphs in buffer language that would have a
|
|
|
|
// foreign language after a document language change, and it ensures
|
|
|
|
// that all new text in ERT and similar gets the "latex" language,
|
|
|
|
// since new text inherits the language from the last position of the
|
|
|
|
// existing text. As a side effect this makes us also robust against
|
|
|
|
// bugs in LyX that might lead to font changes in ERT in .lyx files.
|
|
|
|
resetParagraphsFont();
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(layout_, /**/);
|
2004-11-30 01:59:49 +00:00
|
|
|
Dimension dim;
|
2008-02-22 02:32:52 +00:00
|
|
|
theFontMetrics(layout_->labelfont()).buttonText(
|
2009-02-25 22:35:41 +00:00
|
|
|
buttonLabel(bv), dim.wid, dim.asc, dim.des);
|
2004-11-30 01:59:49 +00:00
|
|
|
return dim;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(layout_, /**/);
|
2007-11-03 09:03:08 +00:00
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
auto_open_[mi.base.bv] = 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;
|
2008-02-22 02:32:52 +00:00
|
|
|
mi.base.font = layout_->font();
|
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
|
2008-02-22 02:32:52 +00:00
|
|
|
FontInfo font(layout_->labelfont());
|
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:
|
2009-02-25 22:35:41 +00:00
|
|
|
dim = dimensionCollapsed(bv);
|
|
|
|
if (geometry(bv) == TopButton
|
|
|
|
|| geometry(bv) == LeftButton) {
|
2007-09-05 13:45:58 +00:00
|
|
|
Dimension textdim;
|
|
|
|
InsetText::metrics(mi, textdim);
|
|
|
|
openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
|
2004-03-10 08:50:46 +00:00
|
|
|
if (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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(layout_, /**/);
|
2009-02-25 22:35:41 +00:00
|
|
|
BufferView const & bv = *pi.base.bv;
|
2007-11-03 09:03:08 +00:00
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
auto_open_[&bv] = bv.cursor().isInside(this);
|
2007-08-16 16:36:50 +00:00
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
FontInfo tmpfont = pi.base.font;
|
2008-02-22 02:32:52 +00:00
|
|
|
pi.base.font = layout_->font();
|
2007-10-30 12:30:46 +00:00
|
|
|
pi.base.font.realize(tmpfont);
|
|
|
|
|
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-02-21 16:27:00 +00:00
|
|
|
if (geometry(*pi.base.bv) == TopButton ||
|
|
|
|
geometry(*pi.base.bv) == LeftButton ||
|
|
|
|
geometry(*pi.base.bv) == ButtonOnly) {
|
2007-09-17 21:45:14 +00:00
|
|
|
button_dim.x1 = x + 0;
|
|
|
|
button_dim.x2 = x + dimc.width();
|
2007-09-06 12:25:30 +00:00
|
|
|
button_dim.y1 = y - dimc.asc;
|
|
|
|
button_dim.y2 = y + dimc.des;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
pi.pain.buttonText(x, y, buttonLabel(bv), layout_->labelfont(),
|
2007-11-03 00:35:07 +00:00
|
|
|
mouse_hover_);
|
2007-09-01 11:40:09 +00:00
|
|
|
} else {
|
|
|
|
button_dim.x1 = 0;
|
|
|
|
button_dim.y1 = 0;
|
|
|
|
button_dim.x2 = 0;
|
|
|
|
button_dim.y2 = 0;
|
2007-08-18 23:26:07 +00:00
|
|
|
}
|
2006-03-10 16:10:35 +00:00
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension const textdim = InsetText::dimension(bv);
|
2007-09-09 20:21:43 +00:00
|
|
|
int const baseline = y;
|
2007-08-18 23:26:07 +00:00
|
|
|
int textx, texty;
|
2009-02-25 22:35:41 +00:00
|
|
|
switch (geometry(bv)) {
|
2007-08-18 23:26:07 +00:00
|
|
|
case LeftButton:
|
2007-09-17 21:45:14 +00:00
|
|
|
textx = x + dimc.width();
|
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 TopButton:
|
2007-09-17 21:45:14 +00:00
|
|
|
textx = x;
|
|
|
|
texty = baseline + dimc.des + textdim.asc;
|
2007-08-18 23:26:07 +00:00
|
|
|
InsetText::draw(pi, textx, texty);
|
|
|
|
break;
|
|
|
|
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;
|
2007-08-18 23:26:07 +00:00
|
|
|
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
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
int desc = textdim.descent();
|
2009-02-25 22:35:41 +00:00
|
|
|
if (geometry(bv) == Corners)
|
2007-08-19 15:45:35 +00:00
|
|
|
desc -= 3;
|
|
|
|
|
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;
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx1, y + desc - 4,
|
|
|
|
xx1, y + desc,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
2007-11-07 21:57:19 +00:00
|
|
|
if (status_ == Open)
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx1, y + desc,
|
|
|
|
xx2, y + desc,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
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,
|
|
|
|
xx1 + 4, y + desc,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx2 - 4, y + desc,
|
|
|
|
xx2, y + desc,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
2008-02-22 16:26:40 +00:00
|
|
|
pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
|
|
|
|
y + desc - 4, layout_->labelfont().color());
|
2007-08-19 15:45:35 +00:00
|
|
|
|
2007-09-01 17:55:21 +00:00
|
|
|
// the label below the text. Can be toggled.
|
2009-02-25 22:35:41 +00:00
|
|
|
if (geometry(bv) == SubLabel) {
|
2008-02-22 02:32:52 +00:00
|
|
|
FontInfo font(layout_->labelfont());
|
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;
|
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,
|
2009-02-25 22:35:41 +00:00
|
|
|
buttonLabel(bv), font, Color_none, Color_none);
|
2007-10-06 08:15:40 +00:00
|
|
|
desc += d;
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2007-09-25 06:49:04 +00:00
|
|
|
y -= textdim.asc;
|
2007-08-19 15:45:35 +00:00
|
|
|
y += 3;
|
2008-02-22 02:32:52 +00:00
|
|
|
pi.pain.line(xx1, y + 4, xx1, y, layout_->labelfont().color());
|
|
|
|
pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont().color());
|
2007-09-18 20:18:50 +00:00
|
|
|
pi.pain.line(xx2, y + 4, xx2, y,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
2007-09-01 20:38:25 +00:00
|
|
|
pi.pain.line(xx2 - 4, y, xx2, y,
|
2008-02-22 02:32:52 +00:00
|
|
|
layout_->labelfont().color());
|
2007-08-19 15:45:35 +00:00
|
|
|
}
|
2007-08-18 23:26:07 +00:00
|
|
|
break;
|
2003-03-20 14:13:49 +00:00
|
|
|
}
|
2007-10-30 12:30:46 +00:00
|
|
|
|
|
|
|
pi.base.font = tmpfont;
|
2003-03-20 14:13: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
|
|
|
{
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == ButtonOnly)
|
2007-09-20 14:11:37 +00:00
|
|
|
status_ = Open;
|
2009-02-21 16:27:00 +00:00
|
|
|
LASSERT(geometry(bv) != ButtonOnly, /**/);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
InsetText::cursorPos(bv, sl, boundary, x, y);
|
2007-09-17 21:45:14 +00:00
|
|
|
Dimension const textdim = InsetText::dimension(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
bool InsetCollapsable::editable() const
|
2003-03-20 14:13:49 +00:00
|
|
|
{
|
2009-04-22 20:55:13 +00:00
|
|
|
return geometry() != ButtonOnly;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 00:04:28 +00:00
|
|
|
bool InsetCollapsable::descendable() const
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2009-02-27 00:04:28 +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();
|
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) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 21:49:34 +00:00
|
|
|
void InsetCollapsable::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
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);
|
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
|
|
|
|
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;
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(cur.bv()) == ButtonOnly
|
2007-08-16 16:36:50 +00:00
|
|
|
|| (button_dim.contains(x, y)
|
2009-02-21 16:27:00 +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
|
|
|
|
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:
|
2008-08-12 14:13:16 +00:00
|
|
|
if (hitButton(cmd)) {
|
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.
|
2008-08-12 14:13:16 +00:00
|
|
|
cur.noUpdate();
|
|
|
|
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
|
|
|
|
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:
|
2008-08-12 14:13:16 +00:00
|
|
|
if (hitButton(cmd))
|
|
|
|
cur.noUpdate();
|
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:
|
2008-08-12 14:13:16 +00:00
|
|
|
if (!hitButton(cmd)) {
|
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
|
|
|
|
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.
|
|
|
|
cur.noUpdate();
|
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();
|
|
|
|
cur.updateFlags(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())
|
2007-11-07 21:57:19 +00:00
|
|
|
if (status_ == Open) {
|
2005-10-24 09:42:20 +00:00
|
|
|
setStatus(cur, Collapsed);
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(cur.bv()) == ButtonOnly)
|
2007-08-20 04:56:04 +00:00
|
|
|
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;
|
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_PASTE:
|
|
|
|
case LFUN_CLIPBOARD_PASTE:
|
2009-05-16 15:39:03 +00:00
|
|
|
case LFUN_SELECTION_PASTE:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_PRIMARY_SELECTION_PASTE: {
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
|
|
|
// Since we can only store plain text, we must reset all
|
|
|
|
// attributes.
|
|
|
|
// FIXME: Change only the pasted paragraphs
|
|
|
|
|
|
|
|
resetParagraphsFont();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
default:
|
2008-02-22 02:32:52 +00:00
|
|
|
if (layout_ && layout_->isForceLtr()) {
|
2007-10-30 12:30:46 +00:00
|
|
|
// Force any new text to latex_language
|
|
|
|
// FIXME: This should only be necessary in constructor, but
|
|
|
|
// new paragraphs that are created by pressing enter at the
|
|
|
|
// start of an existing paragraph get the buffer language
|
|
|
|
// and not latex_language, so we take this brute force
|
|
|
|
// approach.
|
|
|
|
cur.current_font.setLanguage(latex_language);
|
|
|
|
cur.real_current_font.setLanguage(latex_language);
|
|
|
|
}
|
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-10-11 10:13:45 +00:00
|
|
|
bool InsetCollapsable::allowMultiPar() const
|
|
|
|
{
|
2008-02-22 02:32:52 +00:00
|
|
|
return layout_->isMultiPar();
|
2007-10-11 10:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
void InsetCollapsable::resetParagraphsFont()
|
|
|
|
{
|
2009-03-02 10:24:07 +00:00
|
|
|
Font font(inherit_font, buffer().params().language);
|
2008-02-22 02:32:52 +00:00
|
|
|
if (layout_->isForceLtr())
|
2007-10-30 12:30:46 +00:00
|
|
|
font.setLanguage(latex_language);
|
2008-02-22 02:32:52 +00:00
|
|
|
if (layout_->isPassThru()) {
|
2007-10-30 12:30:46 +00:00
|
|
|
ParagraphList::iterator par = paragraphs().begin();
|
|
|
|
ParagraphList::iterator const end = paragraphs().end();
|
|
|
|
while (par != end) {
|
|
|
|
par->resetFonts(font);
|
|
|
|
par->params().clear();
|
|
|
|
++par;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
2008-09-04 21:50:14 +00:00
|
|
|
// FIXME At present, these are being enabled and disabled according to
|
|
|
|
// whether PASSTHRU has been set in the InsetLayout. This makes some
|
|
|
|
// sense, but there are other checks that should really be done. E.g.,
|
|
|
|
// one should not be able to inset IndexPrint inside an optional argument!!
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_ACCENT_ACUTE:
|
|
|
|
case LFUN_ACCENT_BREVE:
|
|
|
|
case LFUN_ACCENT_CARON:
|
|
|
|
case LFUN_ACCENT_CEDILLA:
|
|
|
|
case LFUN_ACCENT_CIRCLE:
|
|
|
|
case LFUN_ACCENT_CIRCUMFLEX:
|
|
|
|
case LFUN_ACCENT_DOT:
|
|
|
|
case LFUN_ACCENT_GRAVE:
|
|
|
|
case LFUN_ACCENT_HUNGARIAN_UMLAUT:
|
|
|
|
case LFUN_ACCENT_MACRON:
|
|
|
|
case LFUN_ACCENT_OGONEK:
|
|
|
|
case LFUN_ACCENT_TIE:
|
|
|
|
case LFUN_ACCENT_TILDE:
|
|
|
|
case LFUN_ACCENT_UMLAUT:
|
|
|
|
case LFUN_ACCENT_UNDERBAR:
|
|
|
|
case LFUN_ACCENT_UNDERDOT:
|
|
|
|
case LFUN_APPENDIX:
|
|
|
|
case LFUN_BOX_INSERT:
|
|
|
|
case LFUN_BRANCH_INSERT:
|
|
|
|
case LFUN_CAPTION_INSERT:
|
|
|
|
case LFUN_DEPTH_DECREMENT:
|
|
|
|
case LFUN_DEPTH_INCREMENT:
|
|
|
|
case LFUN_ERT_INSERT:
|
|
|
|
case LFUN_FILE_INSERT:
|
|
|
|
case LFUN_FLEX_INSERT:
|
|
|
|
case LFUN_FLOAT_INSERT:
|
2008-06-02 11:31:03 +00:00
|
|
|
case LFUN_FLOAT_LIST_INSERT:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_FLOAT_WIDE_INSERT:
|
|
|
|
case LFUN_FONT_BOLD:
|
2008-09-15 16:49:11 +00:00
|
|
|
case LFUN_FONT_BOLDSYMBOL:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_FONT_TYPEWRITER:
|
|
|
|
case LFUN_FONT_DEFAULT:
|
|
|
|
case LFUN_FONT_EMPH:
|
|
|
|
case LFUN_FONT_NOUN:
|
|
|
|
case LFUN_FONT_ROMAN:
|
|
|
|
case LFUN_FONT_SANS:
|
|
|
|
case LFUN_FONT_FRAK:
|
|
|
|
case LFUN_FONT_ITAL:
|
|
|
|
case LFUN_FONT_SIZE:
|
|
|
|
case LFUN_FONT_STATE:
|
|
|
|
case LFUN_FONT_UNDERLINE:
|
2009-05-03 22:45:14 +00:00
|
|
|
case LFUN_FONT_STRIKEOUT:
|
2009-05-05 09:26:28 +00:00
|
|
|
case LFUN_FONT_UULINE:
|
|
|
|
case LFUN_FONT_UWAVE:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_FOOTNOTE_INSERT:
|
|
|
|
case LFUN_HYPERLINK_INSERT:
|
|
|
|
case LFUN_INDEX_INSERT:
|
|
|
|
case LFUN_INDEX_PRINT:
|
|
|
|
case LFUN_INSET_INSERT:
|
|
|
|
case LFUN_LABEL_GOTO:
|
|
|
|
case LFUN_LABEL_INSERT:
|
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2009-05-17 21:28:35 +00:00
|
|
|
case LFUN_LINE_INSERT:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_MARGINALNOTE_INSERT:
|
|
|
|
case LFUN_MATH_DISPLAY:
|
|
|
|
case LFUN_MATH_INSERT:
|
|
|
|
case LFUN_MATH_MATRIX:
|
|
|
|
case LFUN_MATH_MODE:
|
|
|
|
case LFUN_MENU_OPEN:
|
2009-05-17 21:28:35 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
|
|
|
case LFUN_NEWPAGE_INSERT:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_NOACTION:
|
|
|
|
case LFUN_NOMENCL_INSERT:
|
|
|
|
case LFUN_NOMENCL_PRINT:
|
|
|
|
case LFUN_NOTE_INSERT:
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
case LFUN_OPTIONAL_INSERT:
|
2009-01-30 00:56:37 +00:00
|
|
|
case LFUN_PHANTOM_INSERT:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_REFERENCE_NEXT:
|
|
|
|
case LFUN_SERVER_GOTO_FILE_ROW:
|
|
|
|
case LFUN_SERVER_NOTIFY:
|
|
|
|
case LFUN_SERVER_SET_XY:
|
|
|
|
case LFUN_SPACE_INSERT:
|
2007-12-06 11:04:56 +00:00
|
|
|
case LFUN_SPECIALCHAR_INSERT:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_TABULAR_INSERT:
|
2009-05-17 21:28:35 +00:00
|
|
|
case LFUN_TEXTSTYLE_APPLY:
|
|
|
|
case LFUN_TEXTSTYLE_UPDATE:
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_TOC_INSERT:
|
|
|
|
case LFUN_WRAP_INSERT:
|
2008-02-24 15:44:11 +00:00
|
|
|
if (layout_->isPassThru()) {
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2008-02-24 15:44:11 +00:00
|
|
|
return true;
|
2008-03-26 23:41:35 +00:00
|
|
|
}
|
|
|
|
return InsetText::getStatus(cur, cmd, flag);
|
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;
|
|
|
|
|
2007-10-30 12:30:46 +00:00
|
|
|
case LFUN_LANGUAGE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(!layout_->isForceLtr());
|
2007-10-30 12:30:46 +00:00
|
|
|
return InsetText::getStatus(cur, cmd, flag);
|
|
|
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(layout_->isMultiPar());
|
2007-10-30 12:30:46 +00:00
|
|
|
return true;
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
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-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
|
|
|
|
|
|
|
|
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();
|
2008-05-07 19:20:01 +00:00
|
|
|
if (status_ == Collapsed) {
|
2005-05-06 20:00:31 +00:00
|
|
|
cur.leaveInset(*this);
|
2008-05-07 19:20:01 +00:00
|
|
|
mouse_hover_ = false;
|
|
|
|
}
|
2003-09-16 15:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 16:26:40 +00:00
|
|
|
docstring InsetCollapsable::floatName(
|
|
|
|
string const & type, BufferParams const & bp) const
|
2006-10-08 08:47:26 +00:00
|
|
|
{
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = bp.documentClass().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
|
|
|
|
|
|
|
|
2008-02-22 16:24:55 +00:00
|
|
|
InsetLayout::InsetDecoration InsetCollapsable::decoration() const
|
2007-08-25 20:12:50 +00:00
|
|
|
{
|
2008-02-22 16:15:21 +00:00
|
|
|
if (!layout_)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CLASSIC;
|
2008-02-22 16:24:55 +00:00
|
|
|
InsetLayout::InsetDecoration const dec = layout_->decoration();
|
2008-02-22 16:15:21 +00:00
|
|
|
switch (dec) {
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::CLASSIC:
|
|
|
|
case InsetLayout::MINIMALISTIC:
|
|
|
|
case InsetLayout::CONGLOMERATE:
|
2008-02-22 16:15:21 +00:00
|
|
|
return dec;
|
2008-10-25 13:41:02 +00:00
|
|
|
case InsetLayout::DEFAULT:
|
2008-02-22 16:15:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-03 09:03:08 +00:00
|
|
|
if (lyxCode() == FLEX_CODE)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CONGLOMERATE;
|
|
|
|
return InsetLayout::CLASSIC;
|
2007-08-25 20:12:50 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:02:38 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetCollapsable::latex(odocstream & os,
|
2007-08-20 19:02:38 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
2007-11-03 09:03:08 +00:00
|
|
|
// FIXME: What should we do layout_ is 0?
|
|
|
|
// 1) assert
|
2009-02-03 21:11:05 +00:00
|
|
|
// 2) throw an error
|
2007-11-03 09:03:08 +00:00
|
|
|
if (!layout_)
|
|
|
|
return 0;
|
|
|
|
|
2007-08-20 19:02:38 +00:00
|
|
|
// This implements the standard way of handling the LaTeX output of
|
|
|
|
// a collapsable inset, either a command or an environment. Standard
|
|
|
|
// collapsable insets should not redefine this, non-standard ones may
|
|
|
|
// call this.
|
2008-02-22 02:32:52 +00:00
|
|
|
if (!layout_->latexname().empty()) {
|
2008-10-25 14:02:25 +00:00
|
|
|
if (layout_->latextype() == InsetLayout::COMMAND) {
|
2007-08-20 19:02:38 +00:00
|
|
|
// FIXME UNICODE
|
2007-11-01 06:25:47 +00:00
|
|
|
if (runparams.moving_arg)
|
|
|
|
os << "\\protect";
|
2008-02-22 02:32:52 +00:00
|
|
|
os << '\\' << from_utf8(layout_->latexname());
|
|
|
|
if (!layout_->latexparam().empty())
|
|
|
|
os << from_utf8(layout_->latexparam());
|
2007-08-20 19:02:38 +00:00
|
|
|
os << '{';
|
2008-10-25 14:02:25 +00:00
|
|
|
} else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
|
2008-02-22 02:32:52 +00:00
|
|
|
os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n";
|
|
|
|
if (!layout_->latexparam().empty())
|
|
|
|
os << from_utf8(layout_->latexparam());
|
2007-08-20 19:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-20 17:05:28 +00:00
|
|
|
OutputParams rp = runparams;
|
2008-02-22 02:32:52 +00:00
|
|
|
if (layout_->isPassThru())
|
2007-10-20 17:05:28 +00:00
|
|
|
rp.verbatim = true;
|
2008-02-22 02:32:52 +00:00
|
|
|
if (layout_->isNeedProtect())
|
2007-11-01 06:25:47 +00:00
|
|
|
rp.moving_arg = true;
|
2008-02-27 20:43:16 +00:00
|
|
|
int i = InsetText::latex(os, rp);
|
2008-02-22 02:32:52 +00:00
|
|
|
if (!layout_->latexname().empty()) {
|
2008-10-25 14:02:25 +00:00
|
|
|
if (layout_->latextype() == InsetLayout::COMMAND) {
|
2007-08-20 19:02:38 +00:00
|
|
|
os << "}";
|
2008-10-25 14:02:25 +00:00
|
|
|
} else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
|
2008-02-22 02:32:52 +00:00
|
|
|
os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n";
|
2007-08-20 19:02:38 +00:00
|
|
|
i += 4;
|
|
|
|
}
|
2007-09-16 10:36:57 +00:00
|
|
|
}
|
2007-08-20 19:02:38 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-06 17:56:47 +00:00
|
|
|
// FIXME It seems as if it ought to be possible to do this more simply,
|
|
|
|
// maybe by calling InsetText::docbook() in the middle there.
|
|
|
|
int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
ParagraphList::const_iterator const beg = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator par = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator const end = paragraphs().end();
|
|
|
|
|
|
|
|
if (!undefined())
|
|
|
|
sgml::openTag(os, getLayout().latexname(),
|
|
|
|
par->getID(buffer(), runparams) + getLayout().latexparam());
|
|
|
|
|
|
|
|
for (; par != end; ++par) {
|
|
|
|
par->simpleDocBookOnePar(buffer(), os, runparams,
|
|
|
|
outerFont(distance(beg, par),
|
|
|
|
paragraphs()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!undefined())
|
|
|
|
sgml::closeTag(os, getLayout().latexname());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-22 18:55:03 +00:00
|
|
|
void InsetCollapsable::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2008-09-25 13:05:43 +00:00
|
|
|
string const preamble = getLayout().preamble();
|
|
|
|
if (!preamble.empty())
|
|
|
|
features.addPreambleSnippet(preamble);
|
|
|
|
features.require(getLayout().requires());
|
2007-08-22 18:55:03 +00:00
|
|
|
InsetText::validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 16:31:59 +00:00
|
|
|
bool InsetCollapsable::undefined() const
|
|
|
|
{
|
2008-02-22 03:27:42 +00:00
|
|
|
docstring const & n = getLayout().name();
|
2008-08-01 20:57:27 +00:00
|
|
|
return n.empty() || n == DocumentClass::plainInsetLayout().name();
|
2008-02-21 16:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 22:57:22 +00:00
|
|
|
docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
|
|
|
|
int y) const
|
|
|
|
{
|
2008-10-25 13:41:02 +00:00
|
|
|
if (decoration() == InsetLayout::CONGLOMERATE)
|
2008-03-25 06:17:18 +00:00
|
|
|
return from_ascii("context-conglomerate");
|
|
|
|
|
2009-02-21 16:27:00 +00:00
|
|
|
if (geometry(bv) == NoButton)
|
2008-03-21 18:02:47 +00:00
|
|
|
return from_ascii("context-collapsable");
|
|
|
|
|
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)
|
2008-03-24 16:33:56 +00:00
|
|
|
return from_ascii("context-collapsable");
|
2008-03-08 22:57:22 +00:00
|
|
|
|
|
|
|
return InsetText::contextMenu(bv, x, y);
|
|
|
|
}
|
|
|
|
|
2009-02-06 17:56:47 +00:00
|
|
|
void InsetCollapsable::tocString(odocstream & os) const
|
|
|
|
{
|
|
|
|
if (!getLayout().isInToc())
|
|
|
|
return;
|
|
|
|
os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|