}
-InsetCollapsable::InsetCollapsable(BufferParams const & bp,
- CollapseStatus status)
+InsetCollapsable::InsetCollapsable
+ (BufferParams const & bp, CollapseStatus status)
: InsetText(bp), label("Label"), status_(status), openinlined_(false)
{
setAutoBreakRows(true);
- setDrawFrame(InsetText::ALWAYS);
+ setDrawFrame(true);
setFrameColor(LColor::collapsableframe);
setInsetName("Collapsable");
setButtonLabel();
}
-void InsetCollapsable::dimension_collapsed(Dimension & dim) const
+Dimension InsetCollapsable::dimensionCollapsed() const
{
+ Dimension dim;
font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
+ return dim;
}
if (status_ == Inlined) {
InsetText::metrics(mi, dim);
} else {
- dimension_collapsed(dim);
+ dim = dimensionCollapsed();
if (status_ == Open) {
InsetText::metrics(mi, textdim_);
openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
if (openinlined_) {
dim.wid += textdim_.wid;
- dim.des = max(dim.des, textdim_.des);
- dim.asc = max(dim.asc, textdim_.asc);
+ dim.des = max(dim.des - textdim_.asc + dim.asc, textdim_.des);
+ dim.asc = textdim_.asc;
} else {
dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
dim.wid = max(dim.wid, textdim_.wid);
}
-void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
-{
- pi.pain.buttonText(x, y, label, labelfont_);
-}
-
-
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
- x += TEXT_TO_INSET_OFFSET;
- y += TEXT_TO_INSET_OFFSET;
-
+ const int xx = x + TEXT_TO_INSET_OFFSET;
if (status_ == Inlined) {
- InsetText::draw(pi, x, y);
+ InsetText::draw(pi, xx, y);
} else {
- Dimension dimc;
- dimension_collapsed(dimc);
- int const aa = ascent();
- button_dim.x1 = x + 0;
- button_dim.x2 = x + dimc.width();
- button_dim.y1 = y - aa + pi.base.bv->top_y();
- button_dim.y2 = y - aa + pi.base.bv->top_y() + dimc.height();
-
- draw_collapsed(pi, x, y - aa + dimc.asc);
+ 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_);
if (status_ == Open) {
- if (openinlined_)
- InsetText::draw(pi, x + dimc.width(),
- y - aa + textdim_.asc);
- else
- InsetText::draw(pi, x, dimc.height()
- + y - aa + textdim_.asc);
+ 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);
}
}
setPosCache(pi, x, y);
}
-InsetOld::EDITABLE InsetCollapsable::editable() const
+void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
+{
+ x += TEXT_TO_INSET_OFFSET;
+ if (status_ == Open) {
+ if (openinlined_)
+ x += dimensionCollapsed().wid;
+ else
+ y += dimensionCollapsed().des + textdim_.asc;
+ }
+ if (status_ != Collapsed)
+ InsetText::drawSelection(pi, x, y);
+}
+
+
+void InsetCollapsable::getCursorPos
+ (CursorSlice const & sl, int & x, int & y) const
+{
+ if (status_ == Collapsed) {
+ x = xo();
+ y = yo();
+ return;
+ }
+
+ InsetText::getCursorPos(sl, x, y);
+ if (status_ == Open) {
+ if (openinlined_)
+ x += dimensionCollapsed().wid;
+ else
+ 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;
}
}
-InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const
{
- cur.push(*this);
//lyxerr << "InsetCollapsable: edit xy" << endl;
if (status_ == Collapsed) {
- setStatus(Open);
- // We are not calling editXY() because the row cache of the
- // inset might be invalid. 'Entering from the left' should be
- // ok, though.
- InsetText::edit(cur, true);
- return this;
+ return const_cast<InsetCollapsable*>(this);
}
+ cur.push(const_cast<InsetCollapsable&>(*this));
return InsetText::editXY(cur, x, y);
}
-void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
- // << " button y: " << button_dim.y2 << endl;
+ lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
+ << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
+
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (status_ == Inlined)
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
+ else
+ cur.noUpdate();
break;
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
+ else
+ cur.undispatched();
break;
case LFUN_MOUSE_RELEASE:
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
- setStatus(Open);
edit(cur, true);
+ cur.bv().cursor() = cur;
break;
case Open: {
- FuncRequest cmd1 = cmd;
- if (hitButton(cmd1)) {
+ if (hitButton(cmd)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
- cur.undispatched();
- cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+ leaveInset(cur, *this);
+ cur.bv().cursor() = cur;
} else {
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
}
break;
}
case Inlined:
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
break;
}
break;
leaveInset(cur, *this);
} else
setStatus(Open);
- }
+ } else // if assign or anything else
+ cur.undispatched();
cur.dispatched();
break;
default:
- InsetText::priv_dispatch(cur, cmd);
+ InsetText::doDispatch(cur, cmd);
break;
}
}
}
-void InsetCollapsable::setStatus(CollapseStatus st)
+void InsetCollapsable::setStatus(CollapseStatus status)
{
- status_ = st;
+ status_ = status;
setButtonLabel();
}
}
-void InsetCollapsable::scroll(BufferView & bv, float sx) const
+void InsetCollapsable::scroll(BufferView & bv, double sx) const
{
UpdatableInset::scroll(bv, sx);
}
{
UpdatableInset::scroll(bv, offset);
}
-
-
-Box const & InsetCollapsable::buttonDim() const
-{
- return button_dim;
-}