Jürgen Spitzmüller wrote:
> Attached is an almost-working solution

The attached patch fixes all remaining issues.

Opinions? José?

Jürgen
Index: src/insets/insetbase.h
===================================================================
--- src/insets/insetbase.h	(Revision 17877)
+++ src/insets/insetbase.h	(Arbeitskopie)
@@ -357,6 +357,8 @@
 	/// if this inset has paragraphs should they be output all as default
 	/// paragraphs with the default layout of the text class?
 	virtual bool forceDefaultParagraphs(idx_type) const { return false; }
+	/// Is the width forced to some value?
+	virtual bool hasFixedWidth() const { return false; }
 
 	///
 	virtual docstring const & getInsetName() const;
Index: src/insets/insetcollapsable.C
===================================================================
--- src/insets/insetcollapsable.C	(Revision 17877)
+++ src/insets/insetcollapsable.C	(Arbeitskopie)
@@ -173,6 +173,8 @@
 			} 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);
 			}
 		}
 	}
Index: src/insets/insettext.h
===================================================================
--- src/insets/insettext.h	(Revision 17877)
+++ src/insets/insettext.h	(Arbeitskopie)
@@ -159,14 +159,14 @@
 	///
 	mutable pit_type old_pit;
 	///
-	static int border_;
-	///
 	bool wide_inset_;
 public:
 	///
 	mutable LyXText text_;
 	///
 	mutable LyXFont font_;
+	///
+	static int border_;
 };
 
 } // namespace lyx
Index: src/insets/insetcollapsable.h
===================================================================
--- src/insets/insetcollapsable.h	(Revision 17877)
+++ src/insets/insetcollapsable.h	(Arbeitskopie)
@@ -98,8 +98,6 @@
 	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 &) const;
 
Index: src/insets/insetbox.C
===================================================================
--- src/insets/insetbox.C	(Revision 17877)
+++ src/insets/insetbox.C	(Arbeitskopie)
@@ -14,6 +14,7 @@
 
 #include "insetbox.h"
 
+#include "BufferView.h"
 #include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
@@ -25,6 +26,7 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
+#include "TextMetrics.h"
 
 #include "support/translator.h"
 
@@ -177,8 +179,13 @@
 bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 {
 	MetricsInfo mi = m;
+	// first round in order to know the minimum size.
+	InsetCollapsable::metrics(mi, dim);
+	TextMetrics & tm = mi.base.bv->textMetrics(&text_);
 	if (hasFixedWidth())
-		mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
+		mi.base.textwidth =
+			std::max(tm.width() + 2 * border_ + (int) (2.5 * TEXT_TO_INSET_OFFSET),
+				 params_.width.inPixels(m.base.textwidth));
 	InsetCollapsable::metrics(mi, dim);
 	bool const changed = dim_ != dim;
 	dim_ = dim;
Index: src/insets/insettext.C
===================================================================
--- src/insets/insettext.C	(Revision 17877)
+++ src/insets/insettext.C	(Arbeitskopie)
@@ -198,8 +198,9 @@
 		int const w = tm.width() + 2 * border_;
 		int const a = tm.ascent() + border_;
 		int const h = a + tm.descent() + border_;
-		pi.pain.rectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
-			frameColor());
+		pi.pain.rectangle(x, y - a,
+				  ((wide() || hasFixedWidth()) ? tm.maxWidth() : w),
+				  h, frameColor());
 	}
 }
 
@@ -211,8 +212,9 @@
 	int const w = tm.width() + 2 * border_;
 	int const a = tm.ascent() + border_;
 	int const h = a + tm.descent() + border_;
-	pi.pain.fillRectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
-		backgroundColor());
+	pi.pain.fillRectangle(x, y - a,
+			      ((wide() || hasFixedWidth()) ? tm.maxWidth() : w),
+			      h, backgroundColor());
 	text_.drawSelection(pi, x + border_, y);
 }
 

Reply via email to