using std::ostream;
-void leaveInset(LCursor & cur, InsetBase const & in)
+InsetCollapsable::CollapseStatus InsetCollapsable::status() const
{
- for (size_t i = 0; i != cur.depth(); ++i) {
- if (&cur[i].inset() == &in) {
- cur.resize(i);
- return;
- }
- }
+ return (autoOpen_ && status_ != Inlined) ? Open : status_;
}
InsetCollapsable::InsetCollapsable
(BufferParams const & bp, CollapseStatus status)
- : InsetText(bp), label("Label"), status_(status), openinlined_(false)
+ : InsetText(bp), label("Label"), status_(status),
+ openinlined_(false), autoOpen_(false)
{
setAutoBreakRows(true);
setDrawFrame(true);
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
+ autoOpen_ = mi.base.bv->cursor().isInside(this);
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
- if (status_ == Inlined) {
+
+ if (status() == Inlined) {
InsetText::metrics(mi, dim);
} else {
dim = dimensionCollapsed();
- if (status_ == Open) {
+ if (status() == Open) {
InsetText::metrics(mi, textdim_);
+ bool oldopeninlined = openinlined_;
openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
+ if (openinlined_ != oldopeninlined)
+ InsetText::metrics(mi, textdim_);
if (openinlined_) {
dim.wid += textdim_.wid;
dim.des = max(dim.des - textdim_.asc + dim.asc, textdim_.des);
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
const int xx = x + TEXT_TO_INSET_OFFSET;
- if (status_ == Inlined) {
+ if (status() == Inlined) {
InsetText::draw(pi, xx, y);
} else {
Dimension dimc = dimensionCollapsed();
button_dim.y2 = top + dimc.height();
pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_);
- if (status_ == Open) {
+ if (status() == Open) {
int textx, texty;
if (openinlined_) {
textx = xx + dimc.width();
void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
{
x += TEXT_TO_INSET_OFFSET;
- if (status_ == Open) {
+ if (status() == Open) {
if (openinlined_)
x += dimensionCollapsed().wid;
else
y += dimensionCollapsed().des + textdim_.asc;
}
- if (status_ != Collapsed)
+ if (status() != Collapsed)
InsetText::drawSelection(pi, x, y);
}
-void InsetCollapsable::getCursorPos
- (CursorSlice const & sl, int & x, int & y) const
+void InsetCollapsable::cursorPos
+ (CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- if (status_ == Collapsed) {
- x = xo();
- y = yo();
- return;
- }
-
- InsetText::getCursorPos(sl, x, y);
- if (status_ == Open) {
+ 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;
+ y += dimensionCollapsed().height() - ascent()
+ + TEXT_TO_INSET_OFFSET + textdim_.asc;
}
-
x += TEXT_TO_INSET_OFFSET;
}
InsetBase::EDITABLE InsetCollapsable::editable() const
{
- return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
+ return status() != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
}
bool InsetCollapsable::descendable() const
{
- return status_ != Collapsed;
+ return status() != Collapsed;
}
pos_type const n = min(max_length, p_siz);
pos_type i = 0;
pos_type j = 0;
- for( ; i < n && j < p_siz; ++j) {
+ for (; i < n && j < p_siz; ++j) {
if (paragraphs().begin()->isInset(j))
continue;
label += paragraphs().begin()->getChar(j);
//lyxerr << "InsetCollapsable: edit left/right" << endl;
cur.push(*this);
InsetText::edit(cur, left);
- open();
}
-InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const
+InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
{
//lyxerr << "InsetCollapsable: edit xy" << endl;
- if (status_ == Collapsed) {
- return const_cast<InsetCollapsable*>(this);
- }
- cur.push(const_cast<InsetCollapsable&>(*this));
+ if (status() == Collapsed)
+ return this;
+ cur.push(*this);
return InsetText::editXY(cur, x, y);
}
void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
- << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
+ //lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
+ // << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- if (status_ == Inlined)
+ if (status() == Inlined)
InsetText::doDispatch(cur, cmd);
- else if (status_ == Open && !hitButton(cmd))
+ else if (status() == Open && !hitButton(cmd))
InsetText::doDispatch(cur, cmd);
else
cur.noUpdate();
break;
case LFUN_MOUSE_MOTION:
+ case LFUN_MOUSE_DOUBLE:
+ case LFUN_MOUSE_TRIPLE:
if (status_ == Inlined)
InsetText::doDispatch(cur, cmd);
- else if (status_ == Open && !hitButton(cmd))
+ else if (status() && !hitButton(cmd))
InsetText::doDispatch(cur, cmd);
else
cur.undispatched();
break;
}
- switch (status_) {
+ switch (status()) {
case Collapsed:
- lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
+ //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
+ setStatus(cur, Open);
edit(cur, true);
cur.bv().cursor() = cur;
break;
case Open: {
if (hitButton(cmd)) {
- lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
- setStatus(Collapsed);
- leaveInset(cur, *this);
+ //lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
+ setStatus(cur, Collapsed);
cur.bv().cursor() = cur;
} else {
- lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
+ //lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
InsetText::doDispatch(cur, cmd);
}
break;
}
case Inlined:
- lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
+ //lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
InsetText::doDispatch(cur, cmd);
break;
}
case LFUN_INSET_TOGGLE:
if (cmd.argument == "open")
- setStatus(Open);
- else if (cmd.argument == "close") {
- setStatus(Collapsed);
- leaveInset(cur, *this);
- } else if (cmd.argument == "toggle"
- || cmd.argument.empty()) {
+ setStatus(cur, Open);
+ else if (cmd.argument == "close")
+ setStatus(cur, Collapsed);
+ else if (cmd.argument == "toggle" || cmd.argument.empty())
if (isOpen()) {
- setStatus(Collapsed);
- leaveInset(cur, *this);
- } else
- setStatus(Open);
- } else // if assign or anything else
+ setStatus(cur, Collapsed);
+ cur.forwardPosNoDescend();
+ }
+ else
+ setStatus(cur, Open);
+ else // if assign or anything else
cur.undispatched();
cur.dispatched();
break;
}
-int InsetCollapsable::scroll(bool recursive) const
-{
- int sx = UpdatableInset::scroll(false);
-
- if (recursive)
- sx += InsetText::scroll(false);
-
- return sx;
-}
-
-
-void InsetCollapsable::open()
-{
- if (status_ == Collapsed) // ...but not inlined
- setStatus(Open);
-}
-
-
-void InsetCollapsable::close()
-{
- setStatus(Collapsed);
-}
-
-
void InsetCollapsable::setLabel(string const & l)
{
label = l;
}
-void InsetCollapsable::setStatus(CollapseStatus status)
+void InsetCollapsable::setStatus(LCursor & cur, CollapseStatus status)
{
status_ = status;
setButtonLabel();
+ if (status_ == Collapsed)
+ cur.leaveInset(*this);
}
labelfont_ = font;
}
-
-void InsetCollapsable::scroll(BufferView & bv, double sx) const
-{
- UpdatableInset::scroll(bv, sx);
-}
-
-
-void InsetCollapsable::scroll(BufferView & bv, int offset) const
-{
- UpdatableInset::scroll(bv, offset);
-}