]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
Fix bug 2884 and 3437:
[lyx.git] / src / insets / insetcollapsable.C
index ecbc58f9bbed30ba61dea020a2a4d06c4e475c6e..0c480765c7af010bc22a93af0a9ce36a13356b55 100644 (file)
@@ -152,7 +152,7 @@ Dimension InsetCollapsable::dimensionCollapsed() const
 bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        autoOpen_ = mi.base.bv->cursor().isInside(this);
-       mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+       mi.base.textwidth -= (int) (1.5 * TEXT_TO_INSET_OFFSET);
 
        if (status() == Inlined) {
                InsetText::metrics(mi, dim);
@@ -161,7 +161,8 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
                if (status() == Open) {
                        InsetText::metrics(mi, textdim_);
                        // This expression should not contain mi.base.texwidth
-                       openinlined_ = textdim_.wid < 0.5 * mi.base.bv->workWidth();
+                       openinlined_ = !hasFixedWidth() 
+                               && textdim_.wid < 0.5 * mi.base.bv->workWidth();
                        if (openinlined_) {
                                // Correct for button width, and re-fit
                                mi.base.textwidth -= dim.wid;
@@ -172,13 +173,15 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
                        } else {
                                dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
                                dim.wid = max(dim.wid, textdim_.wid);
+                               if (hasFixedWidth())
+                                       dim.wid = max(dim.wid, mi.base.textwidth);
                        }
                }
        }
        dim.asc += TEXT_TO_INSET_OFFSET;
        dim.des += TEXT_TO_INSET_OFFSET;
-       dim.wid += 2 * TEXT_TO_INSET_OFFSET;
-       mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
+       dim.wid += (int) (1.5 * TEXT_TO_INSET_OFFSET);
+       mi.base.textwidth += (int) (1.5 * TEXT_TO_INSET_OFFSET);
        bool const changed = dim_ != dim;
        dim_ = dim;
        return changed;
@@ -305,7 +308,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 || button_dim.contains(x, y))
+       if (status() == Collapsed || (button_dim.contains(x, y) && status() != Inlined))
                return this;
        cur.push(*this);
        return InsetText::editXY(cur, x, y);
@@ -319,9 +322,13 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
-               if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
+               if (cmd.button() == mouse_button::button1 && hitButton(cmd) && status() != Inlined) {
+                       // reset selection if necessary (see bug 3060)
+                       if (cur.selection())
+                               cur.bv().cursor().clearSelection();
+                       else
+                               cur.noUpdate();
                        cur.dispatched();
-                       cur.noUpdate();
                        break;
                }
                if (status() == Inlined)
@@ -436,6 +443,9 @@ void InsetCollapsable::setStatus(LCursor & cur, CollapseStatus status)
        setButtonLabel();
        if (status_ == Collapsed)
                cur.leaveInset(*this);
+       // Because we save CollapseStatus in lyx file, change of status
+       // should lead to a dirty buffer. (This fixes bug 2993).
+       cur.bv().buffer()->markDirty();
 }
 
 
@@ -444,7 +454,7 @@ void InsetCollapsable::setLabelFont(LyXFont & font)
        labelfont_ = font;
 }
 
-docstring InsetCollapsable::floatName(string const & type, BufferParams const & bp)
+docstring InsetCollapsable::floatName(string const & type, BufferParams const & bp) const
 {
        FloatList const & floats = bp.getLyXTextClass().floats();
        FloatList::const_iterator it = floats[type];