]> git.lyx.org Git - features.git/commitdiff
the autoopen patch (fixes bug 1921)
authorJürgen Spitzmüller <spitz@lyx.org>
Wed, 28 Sep 2005 15:02:47 +0000 (15:02 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Wed, 28 Sep 2005 15:02:47 +0000 (15:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10495 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/cursor.C
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h

index 32655b8321c87f163a564d3dadb08c8d8e30dc6b..68bc45e1647e07903fd09c1d04fa78057a5f4d99 100644 (file)
@@ -1,3 +1,8 @@
+2005-09-28  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * cursor.C (setSelection): do not open collapsable insets;
+       the insets do by themselves now (autoopen).
+
 2005-09-28  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * buffer.C: format is up to 244.
index 2ed2722129c922d21fd898a360bfdeba1cd33107..816981e2a333784e462abaa6a21225a3d112e529 100644 (file)
@@ -468,9 +468,6 @@ void LCursor::setSelection(DocIterator const & where, size_t n)
        selection() = true;
        anchor_ = where;
        pos() += n;
-       // Open all collapsed insets
-       for (int i = depth() - 1; i >= 0; --i)
-               operator[](i).inset().setStatus(*this, InsetBase::Open);
 }
 
 
index 9b79976ce33f9bfc7cbf032701fcd94bafad1d0d..4396aa92597d59842ff7dd823832847dfb65c4d2 100644 (file)
@@ -1,3 +1,9 @@
+2005-09-28  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * insetcollapsable.[Ch]: implement Alfredo Braunstein's approach
+       of autoopen, which means that collapsables automatically open
+       whenever the cursor enters (and close again on leave) (fixes bug 1921).
+
 2005-09-28  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * insetspace.C: rename '\,' to '\thinspace{}' (avoid parsing error)
index d688cf3301000cb3a66f251afc6034b8bb693c0d..6bcb0ff6e8d9ca70c738f2df97b2286f1ea76e68 100644 (file)
@@ -40,9 +40,16 @@ using std::min;
 using std::ostream;
 
 
+InsetCollapsable::CollapseStatus InsetCollapsable::status() const
+{
+       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);
@@ -122,12 +129,14 @@ Dimension InsetCollapsable::dimensionCollapsed() const
 
 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_);
                        openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
                        if (openinlined_) {
@@ -151,7 +160,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 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();
@@ -162,7 +171,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                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();
@@ -181,13 +190,13 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 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);
 }
 
@@ -195,32 +204,30 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, 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();
-       } else {
-               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;
-               }
-               x += TEXT_TO_INSET_OFFSET;
+       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;
        }
+       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;
 }
 
 
@@ -262,7 +269,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
 InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
 {
        //lyxerr << "InsetCollapsable: edit xy" << endl;
-       if (status_ == Collapsed)
+       if (status() == Collapsed)
                return this;
        cur.push(*this);
        return InsetText::editXY(cur, x, y);
@@ -276,9 +283,9 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        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();
@@ -289,7 +296,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
        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();
@@ -301,7 +308,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
                        break;
                }
 
-               switch (status_) {
+               switch (status()) {
 
                case Collapsed:
                        //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
index 6b351bf9d1a42f0fb3ff8bd6fcb973f16944175e..22697c4828e5bfb0c626e932baae3f2b77ff4087 100644 (file)
@@ -69,7 +69,7 @@ public:
        ///
        bool inlined() const { return status_ == Inlined; }
        ///
-       CollapseStatus status() const { return status_; }
+       CollapseStatus status() const;
        ///
        bool allowSpellCheck() const { return true; }
        ///
@@ -107,6 +107,8 @@ private:
        mutable CollapseStatus status_;
        /// a substatus of the Open status, determined automatically in metrics
        mutable bool openinlined_;
+       /// the inset will automatically open when the cursor is inside
+       mutable bool autoOpen_;
        ///
        mutable Dimension textdim_;
 };