When one inserts a minipage of, say, 30% of page width, the button of
the collapsable inset is set on the left and the resulting insettext
area is unusable. The following patches cure that, but since I do not
really understand how this stuff works (what is the special
parameter?), I'd rather have external advice.

Martin, does the patch look right?

Index: src/insets/insetcollapsable.C
===================================================================
--- src/insets/insetcollapsable.C	(revision 16320)
+++ src/insets/insetcollapsable.C	(working copy)
@@ -139,7 +139,8 @@ void InsetCollapsable::metrics(MetricsIn
 		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;
Index: src/insets/insetcollapsable.h
===================================================================
--- src/insets/insetcollapsable.h	(revision 16320)
+++ src/insets/insetcollapsable.h	(working copy)
@@ -88,6 +88,8 @@ protected:
 	InsetBase * editXY(LCursor & cur, int x, int y);
 	///
 	void setInlined() { status_ = Inlined; }
+	/// Is the width forced to some value?
+	virtual bool hasFixedWidth() const { return false; }
 
 protected:
 	///
Index: src/insets/insetbox.C
===================================================================
--- src/insets/insetbox.C	(revision 16320)
+++ src/insets/insetbox.C	(working copy)
@@ -153,10 +153,16 @@ void InsetBox::setButtonLabel()
 }
 
 
+bool InsetBox::hasFixedWidth() const
+{
+	return params_.inner_box || params_.special != "width";
+}
+
+
 void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 {
 	MetricsInfo mi = m;
-	if (params_.inner_box || params_.special != "width")
+	if (hasFixedWidth())
 		mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
 	InsetCollapsable::metrics(mi, dim);
 	dim_ = dim;
Index: src/insets/insetbox.h
===================================================================
--- src/insets/insetbox.h	(revision 16320)
+++ src/insets/insetbox.h	(working copy)
@@ -111,6 +111,8 @@ public:
 protected:
 	InsetBox(InsetBox const &);
 	virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+	/// Is the width forced to some value?
+	virtual bool hasFixedWidth() const;
 private:
 	friend class InsetBoxParams;
 
Index: src/insets/insetcollapsable.C
===================================================================
--- src/insets/insetcollapsable.C	(revision 16318)
+++ src/insets/insetcollapsable.C	(working copy)
@@ -161,7 +161,8 @@ bool InsetCollapsable::metrics(MetricsIn
 		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;
@@ -356,9 +357,10 @@ void InsetCollapsable::doDispatch(LCurso
 			break;
 		}
 
-		if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
-			// Left button is clicked, the user asks to toggle the inset
-			// visual state.
+		if (cmd.button() == mouse_button::button1 && hitButton(cmd)
+			&& !cur.selection()) {
+			// Left button is clicked, the user asks to
+			// toggle the inset visual state.
 			cur.dispatched();
 			cur.updateFlags(Update::Force | Update::FitCursor);
 			if (status() == Collapsed) {
Index: src/insets/insetcollapsable.h
===================================================================
--- src/insets/insetcollapsable.h	(revision 16318)
+++ src/insets/insetcollapsable.h	(working copy)
@@ -98,6 +98,8 @@ protected:
 	InsetBase * editXY(LCursor & cur, int x, int y);
 	///
 	void setInlined() { status_ = Inlined; }
+	/// Is the width forced to some value?
+	virtual bool hasFixedWidth() const { return false; }
 	///
 	docstring floatName(std::string const & type, BufferParams const &);
 
Index: src/insets/insetbox.C
===================================================================
--- src/insets/insetbox.C	(revision 16318)
+++ src/insets/insetbox.C	(working copy)
@@ -169,10 +169,16 @@ void InsetBox::setButtonLabel()
 }
 
 
+bool InsetBox::hasFixedWidth() const
+{
+      return params_.inner_box || params_.special != "width";
+}
+
+
 bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 {
 	MetricsInfo mi = m;
-	if (params_.inner_box || params_.special != "width")
+	if (hasFixedWidth())
 		mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
 	InsetCollapsable::metrics(mi, dim);
 	bool const changed = dim_ != dim;
Index: src/insets/insetbox.h
===================================================================
--- src/insets/insetbox.h	(revision 16318)
+++ src/insets/insetbox.h	(working copy)
@@ -108,6 +108,8 @@ public:
 protected:
 	InsetBox(InsetBox const &);
 	virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+	/// Is the width forced to some value?
+	virtual bool hasFixedWidth() const;
 private:
 	friend class InsetBoxParams;
 

Reply via email to