]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
the convert patch
[lyx.git] / src / insets / insetcollapsable.C
index f8de8e7f6c5ac35791dceaa6c9f348f4c8176615..17bf4215ca2097927b45b30401b05bf67d839cb7 100644 (file)
@@ -50,8 +50,8 @@ void leaveInset(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);
@@ -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;
 }
@@ -242,35 +273,37 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
 
 InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const
 {
-       cur.push(const_cast<InsetCollapsable&>(*this));
        //lyxerr << "InsetCollapsable: edit xy" << endl;
        if (status_ == Collapsed) {
                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 << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd
-//            << "  button y: " << button_dim.y2
-//            << "  coll/inline/open: " << status_ << 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();
+                       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:
@@ -283,7 +316,6 @@ 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;
@@ -296,14 +328,14 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                                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;
@@ -327,7 +359,7 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               InsetText::priv_dispatch(cur, cmd);
+               InsetText::doDispatch(cur, cmd);
                break;
        }
 }
@@ -363,9 +395,9 @@ void InsetCollapsable::setLabel(string const & l)
 }
 
 
-void InsetCollapsable::setStatus(CollapseStatus st)
+void InsetCollapsable::setStatus(CollapseStatus status)
 {
-       status_ = st;
+       status_ = status;
        setButtonLabel();
 }
 
@@ -376,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);
 }
@@ -386,9 +418,3 @@ void InsetCollapsable::scroll(BufferView & bv, int offset) const
 {
        UpdatableInset::scroll(bv, offset);
 }
-
-
-Box const & InsetCollapsable::buttonDim() const
-{
-       return button_dim;
-}