X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetcollapsable.C;h=17bf4215ca2097927b45b30401b05bf67d839cb7;hb=342cdf432246110db37bee4e0aebb4b72c933ddb;hp=d36a7a4c5892beb03f0b9e73d5621c0f54240794;hpb=36666181380871d06a96797c7cc80b72369717c9;p=lyx.git diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index d36a7a4c58..17bf4215ca 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -39,7 +39,7 @@ using std::min; using std::ostream; -void getOutOfInset(LCursor & cur, InsetBase const & in) +void leaveInset(LCursor & cur, InsetBase const & in) { for (unsigned int i = 0; i != cur.size(); ++i) { if (&cur[i].inset() == &in) { @@ -50,12 +50,12 @@ void getOutOfInset(LCursor & cur, InsetBase const & in) } -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(); @@ -122,9 +122,11 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex) } -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; } @@ -134,14 +136,14 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const 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); @@ -156,43 +158,72 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const } -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; } @@ -240,39 +271,39 @@ void InsetCollapsable::edit(LCursor & cur, bool left) } -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(this); } + cur.push(const_cast(*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: @@ -285,27 +316,26 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -315,20 +345,21 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) setStatus(Open); else if (cmd.argument == "close") { setStatus(Collapsed); - getOutOfInset(cur, *this); + leaveInset(cur, *this); } else if (cmd.argument == "toggle" || cmd.argument.empty()) { if (isOpen()) { setStatus(Collapsed); - getOutOfInset(cur, *this); + 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; } } @@ -364,9 +395,9 @@ void InsetCollapsable::setLabel(string const & l) } -void InsetCollapsable::setStatus(CollapseStatus st) +void InsetCollapsable::setStatus(CollapseStatus status) { - status_ = st; + status_ = status; setButtonLabel(); } @@ -377,7 +408,7 @@ void InsetCollapsable::setLabelFont(LyXFont & font) } -void InsetCollapsable::scroll(BufferView & bv, float sx) const +void InsetCollapsable::scroll(BufferView & bv, double sx) const { UpdatableInset::scroll(bv, sx); } @@ -387,9 +418,3 @@ void InsetCollapsable::scroll(BufferView & bv, int offset) const { UpdatableInset::scroll(bv, offset); } - - -Box const & InsetCollapsable::buttonDim() const -{ - return button_dim; -}