2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcollapsable.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
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>
|
|
|
|
|
|
|
|
|
|
#include "insetcollapsable.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "buffer.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-11-06 16:43:12 +00:00
|
|
|
|
#include "cursor.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "lyxlex.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
2003-02-25 14:51:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::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
|
|
|
|
|
{
|
|
|
|
|
return (autoOpen_ && status_ != Inlined) ? Open : status_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetCollapsable::InsetCollapsable
|
|
|
|
|
(BufferParams const & bp, CollapseStatus status)
|
2005-09-28 15:02:47 +00:00
|
|
|
|
: InsetText(bp), label("Label"), status_(status),
|
|
|
|
|
openinlined_(false), autoOpen_(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);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
setFrameColor(LColor::collapsableframe);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
setInsetName("Collapsable");
|
2003-12-12 14:02:14 +00:00
|
|
|
|
setButtonLabel();
|
2000-03-08 13:52:57 +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;
|
|
|
|
|
case Inlined:
|
2004-02-03 16:44:57 +00:00
|
|
|
|
os << "inlined";
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetCollapsable::read(Buffer const & buf, LyXLex & 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();
|
|
|
|
|
|
|
|
|
|
if (tmp_token == "inlined") {
|
|
|
|
|
status_ = Inlined;
|
|
|
|
|
token_found = true;
|
|
|
|
|
} else if (tmp_token == "collapsed") {
|
|
|
|
|
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;
|
2003-09-16 15:39:33 +00:00
|
|
|
|
font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return dim;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void 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);
|
2004-03-27 13:29:17 +00:00
|
|
|
|
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
2005-09-28 15:02:47 +00:00
|
|
|
|
|
|
|
|
|
if (status() == Inlined) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::metrics(mi, dim);
|
2003-12-02 07:15:42 +00:00
|
|
|
|
} else {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim = dimensionCollapsed();
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Open) {
|
2004-03-27 13:29:17 +00:00
|
|
|
|
InsetText::metrics(mi, textdim_);
|
|
|
|
|
openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
|
2004-03-10 08:50:46 +00:00
|
|
|
|
if (openinlined_) {
|
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);
|
2004-03-10 08:50:46 +00:00
|
|
|
|
}
|
2003-12-02 07:15:42 +00:00
|
|
|
|
}
|
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;
|
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
|
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Inlined) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetText::draw(pi, xx, y);
|
2003-03-20 14:13:49 +00:00
|
|
|
|
} else {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Dimension dimc = dimensionCollapsed();
|
|
|
|
|
int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
button_dim.x1 = xx + 0;
|
|
|
|
|
button_dim.x2 = xx + dimc.width();
|
|
|
|
|
button_dim.y1 = top;
|
|
|
|
|
button_dim.y2 = top + dimc.height();
|
|
|
|
|
|
|
|
|
|
pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_);
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Open) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int textx, texty;
|
|
|
|
|
if (openinlined_) {
|
|
|
|
|
textx = xx + dimc.width();
|
|
|
|
|
texty = top + textdim_.asc;
|
|
|
|
|
} else {
|
|
|
|
|
textx = xx;
|
|
|
|
|
texty = top + dimc.height() + textdim_.asc;
|
|
|
|
|
}
|
|
|
|
|
InsetText::draw(pi, textx, texty);
|
2003-12-02 07:15:42 +00:00
|
|
|
|
}
|
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;
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Open) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (openinlined_)
|
|
|
|
|
x += dimensionCollapsed().wid;
|
|
|
|
|
else
|
|
|
|
|
y += dimensionCollapsed().des + textdim_.asc;
|
|
|
|
|
}
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() != Collapsed)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetText::drawSelection(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-15 15:49:40 +00:00
|
|
|
|
void InsetCollapsable::cursorPos
|
|
|
|
|
(CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2005-09-28 15:02:47 +00:00
|
|
|
|
BOOST_ASSERT(status() != Collapsed);
|
|
|
|
|
|
|
|
|
|
InsetText::cursorPos(sl, boundary, x, y);
|
|
|
|
|
|
|
|
|
|
if (status() == Open) {
|
|
|
|
|
if (openinlined_)
|
|
|
|
|
x += dimensionCollapsed().wid;
|
|
|
|
|
else
|
|
|
|
|
y += dimensionCollapsed().height() - ascent()
|
|
|
|
|
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-25 19:13:07 +00:00
|
|
|
|
InsetBase::EDITABLE InsetCollapsable::editable() const
|
2003-03-20 14:13:49 +00:00
|
|
|
|
{
|
2005-09-28 15:02:47 +00:00
|
|
|
|
return status() != Collapsed ? 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
|
|
|
|
{
|
2005-09-28 15:02:47 +00:00
|
|
|
|
return status() != Collapsed;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-01 14:51:52 +00:00
|
|
|
|
string const InsetCollapsable::getNewLabel(string const & l) const
|
|
|
|
|
{
|
2004-03-08 21:14:45 +00:00
|
|
|
|
string 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)) {
|
2004-03-08 21:14:45 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
void InsetCollapsable::edit(LCursor & 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
|
|
|
|
|
2005-07-15 00:39:44 +00:00
|
|
|
|
InsetBase * InsetCollapsable::editXY(LCursor & 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;
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Collapsed)
|
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
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void InsetCollapsable::doDispatch(LCursor & 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:
|
2005-09-28 15:02:47 +00:00
|
|
|
|
if (status() == Inlined)
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2005-09-28 15:02:47 +00:00
|
|
|
|
else if (status() == Open && !hitButton(cmd))
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
else
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.noUpdate();
|
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:
|
2004-03-30 12:36:33 +00:00
|
|
|
|
if (status_ == Inlined)
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2005-09-28 15:02:47 +00:00
|
|
|
|
else if (status() && !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) {
|
|
|
|
|
showInsetDialog(&cur.bv());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2005-09-28 15:02:47 +00:00
|
|
|
|
switch (status()) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case Collapsed:
|
2005-07-15 11:43:07 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
|
2005-05-13 08:18:03 +00:00
|
|
|
|
setStatus(cur, Open);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
edit(cur, true);
|
2004-08-13 14:56:06 +00:00
|
|
|
|
cur.bv().cursor() = cur;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case Open: {
|
2004-08-13 14:56:06 +00:00
|
|
|
|
if (hitButton(cmd)) {
|
2005-07-15 11:43:07 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setStatus(cur, Collapsed);
|
2004-08-13 14:56:06 +00:00
|
|
|
|
cur.bv().cursor() = cur;
|
2004-03-30 12:36:33 +00:00
|
|
|
|
} else {
|
2005-07-15 11:43:07 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2003-12-12 15:21:31 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case Inlined:
|
2005-07-15 11:43:07 +00:00
|
|
|
|
//lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-03-30 12:36:33 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
|
|
|
|
if (cmd.argument == "open")
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setStatus(cur, Open);
|
|
|
|
|
else if (cmd.argument == "close")
|
|
|
|
|
setStatus(cur, Collapsed);
|
2005-10-24 09:42:20 +00:00
|
|
|
|
else if (cmd.argument == "toggle" || cmd.argument.empty())
|
|
|
|
|
if (isOpen()) {
|
|
|
|
|
setStatus(cur, Collapsed);
|
|
|
|
|
cur.forwardPosNoDescend();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
|
bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
|
|
|
|
if (cmd.argument == "open" || cmd.argument == "close" ||
|
|
|
|
|
cmd.argument == "toggle")
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
else
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return InsetText::getStatus(cur, cmd, flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-12 14:02:14 +00:00
|
|
|
|
void InsetCollapsable::setLabel(string const & l)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
|
|
|
|
label = l;
|
|
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
2005-05-06 20:00:31 +00:00
|
|
|
|
void InsetCollapsable::setStatus(LCursor & 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);
|
2003-09-16 15:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-12 14:02:14 +00:00
|
|
|
|
void InsetCollapsable::setLabelFont(LyXFont & font)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{
|
2003-12-12 14:02:14 +00:00
|
|
|
|
labelfont_ = font;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|