Am 15.05.2013 01:05, schrieb Uwe Stöhr:

- insert a new box via the toolbar button
- open its box dialog and delete there the width number and press apply
result: you cannot compile the file because minipages requires a width.

In LyX 2.0.x we do in this case use 0pt as width. This must also be done when 
your patches are
applied. The attached patch combines your patches, update them against latest 
master and does this.
Is this OK? If so i will change lyx2lyx and tex2lyx.

Attached is now a correct patch file.

regards Uwe

 src/Length.cpp                   | 11 ++++++++--
 src/frontends/qt4/GuiBox.cpp     | 44 +++++++++++++++++++++-------------------
 src/frontends/qt4/qt_helpers.cpp | 20 +++++++++++-------
 src/frontends/qt4/qt_helpers.h   | 10 ++++++---
 src/insets/InsetBox.cpp          |  9 ++++----
 src/lengthcommon.cpp             | 10 +++++++--
 6 files changed, 64 insertions(+), 40 deletions(-)

diff --git a/src/Length.cpp b/src/Length.cpp
index f8eb920..10cdd29 100644
--- a/src/Length.cpp
+++ b/src/Length.cpp
@@ -67,7 +67,8 @@ void Length::swap(Length & rhs)
 string const Length::asString() const
 {
 	ostringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != UNIT_NONE)
+		os << val_ << unit_name[unit_]; // setw?
 	return os.str();
 }
 
@@ -75,7 +76,8 @@ string const Length::asString() const
 docstring const Length::asDocstring() const
 {
 	odocstringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != UNIT_NONE)
+		os << val_ << unit_name[unit_]; // setw?
 	return os.str();
 }
 
@@ -102,6 +104,8 @@ string const Length::asLatexString() const
 	case PPH:
 		os << val_ / 100.0 << "\\paperheight";
 		break;
+	case UNIT_NONE:
+		break;
 	default:
 		os << val_ << unit_name[unit_];
 	  break;
@@ -363,6 +367,9 @@ GlueLength::GlueLength(string const & data)
 
 string const GlueLength::asString() const
 {
+	if (len_.empty())
+		return string();
+
 	ostringstream buffer;
 
 	buffer << len_.value();
diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp
index 01f748f..a6b4e14 100644
--- a/src/frontends/qt4/GuiBox.cpp
+++ b/src/frontends/qt4/GuiBox.cpp
@@ -305,16 +305,18 @@ void GuiBox::paramsToDialog(Inset const * inset)
 	Length::UNIT const default_unit = Length::defaultUnit();
 
 	// the width can only be selected for makebox or framebox
-	widthCB->setEnabled(inner_type == "makebox" 
-	                    || (type == "Boxed" && !ibox && !pagebreakCB->isChecked()));
-	// "-999col%" is the code for no width
-	if ((params.width).asString() == "-999col%")
-		widthCB->setCheckState(Qt::Unchecked);
-	else {
+	widthCB->setEnabled(inner_type == "makebox"
+	                    || (type == "Boxed" 
+				&& !ibox && !pagebreakCB->isChecked()));
+	if (params.width.empty()) {
+		widthCB->setChecked(false);
+		lengthToWidgets(widthED, widthUnitsLC,
+			params.width, default_unit);
+	} else {
 		if (widthCB->isEnabled())
 			widthCB->setChecked(true);
 		lengthToWidgets(widthED, widthUnitsLC,
-			(params.width).asString(), default_unit);
+			params.width, default_unit);
 		QString const special = toqstr(params.special);
 		if (!special.isEmpty() && special != "none")
 			widthUnitsLC->setCurrentItem(special);
@@ -325,7 +327,7 @@ void GuiBox::paramsToDialog(Inset const * inset)
 
 	lengthToWidgets(heightED, heightUnitsLC,
 		(params.height).asString(), default_unit);
-	
+
 	QString const height_special = toqstr(params.height_special);
 	if (!height_special.isEmpty() && height_special != "none")
 		heightUnitsLC->setCurrentItem(height_special);
@@ -369,21 +371,21 @@ docstring GuiBox::dialogToParams() const
 		widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
 	QString value = widthED->text();
 
-	if (widthCB->isChecked()) {
-	 if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
-		 params.special = fromqstr(unit);
-		 // Note: the unit is simply ignored in this case
-		 params.width = Length(value.toDouble(), Length::IN);
-	 } else {
-		 params.special = "none";
-		 params.width = Length(widgetsToLength(widthED, widthUnitsLC));
-	 }
-	} else {
-		if (widthCB->isEnabled()) {
-			// use the code "-999col%" for the case that no width was selected
+	if (widthED->isEnabled()) {
+		if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
+			params.special = fromqstr(unit);
+			// Note: the unit is simply ignored in this case
+			params.width = Length(value.toDouble(), Length::IN);
+		} else {
 			params.special = "none";
-			params.width = Length("-999col%");
+			// we must specify a valid length in this case
+			if (value.isEmpty())
+				widthED->setText("0");
+			params.width = Length(widgetsToLength(widthED, widthUnitsLC));
 		}
+	} else {
+		params.special = "none";
+		params.width = Length();
 	}
 
 	// the height parameter is omitted if the value
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index d674452..4c69aeb 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -118,12 +118,18 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
 
 
 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-                     Length const & len, Length::UNIT /*defaultUnit*/)
+	Length const & len, Length::UNIT /*defaultUnit*/)
 {
-	combo->setCurrentItem(len.unit());
-	QLocale loc;
-	loc.setNumberOptions(QLocale::OmitGroupSeparator);
-	input->setText(loc.toString(Length(len).value()));
+	if (len.empty()) {
+		// no length (UNIT_NONE)
+		combo->setCurrentItem(Length::defaultUnit());
+		input->setText("");
+	} else {
+		combo->setCurrentItem(len.unit());
+		QLocale loc;
+		loc.setNumberOptions(QLocale::OmitGroupSeparator);
+		input->setText(loc.toString(Length(len).value()));
+	}
 }
 
 
@@ -156,7 +162,7 @@ double widgetToDouble(QLineEdit const * input)
 	QString const text = input->text();
 	if (text.isEmpty())
 		return 0.0;
-	
+
 	return text.trimmed().toDouble();
 }
 
@@ -166,7 +172,7 @@ string widgetToDoubleStr(QLineEdit const * input)
 	QString const text = input->text();
 	if (text.isEmpty())
 		return string();
-	
+
 	return convert<string>(text.trimmed().toDouble());
 }
 
diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h
index 7a5f8cd..2c742e7 100644
--- a/src/frontends/qt4/qt_helpers.h
+++ b/src/frontends/qt4/qt_helpers.h
@@ -42,13 +42,17 @@ std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
 /// method to get a Length from widgets (QComboBox)
 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
 
-//FIXME It would be nice if defaultUnit were a default argument
 /// method to set widgets from a Length
+//FIXME Remove default_unit argument for the first form. FIXME Change
+// all the code to remove default_unit argument when equal to the
+// default.
 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-Length const & len, Length::UNIT default_unit);
+		     Length const & len, 
+		     Length::UNIT default_unit = Length::defaultUnit());
 /// method to set widgets from a string
 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-std::string const & len, Length::UNIT default_unit);
+		     std::string const & len, 
+		     Length::UNIT default_unit = Length::defaultUnit());
 /// method to set widgets from a docstring
 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
 docstring const & len, Length::UNIT default_unit);
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index bb8602c..a07df27 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -162,7 +162,7 @@ void InsetBox::setButtonLabel()
 
 bool InsetBox::hasFixedWidth() const
 {
-	return from_ascii(params_.width.asLatexString()) != "-9.99\\columnwidth";
+	return !params_.width.empty();
 }
 
 
@@ -273,6 +273,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
 
 	string width_string = params_.width.asLatexString();
 	bool stdwidth = false;
+	// FIXME: do not test explicitely values of width_string
 	if (params_.inner_box &&
 			(width_string.find("1.0\\columnwidth") != string::npos
 			|| width_string.find("1.0\\textwidth") != string::npos)) {
@@ -316,8 +317,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
 		os << "\\begin{framed}%\n";
 		break;
 	case Boxed:
-		// "-999col%" is the code for no width
-		if (from_ascii(width_string) != "-9.99\\columnwidth") {
+		if (width_string.empty()) {
 			os << "\\framebox";
 			if (!params_.inner_box) {
 				// Special widths, see usrguide sec. 3.5
@@ -358,8 +358,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
 		if (params_.use_parbox)
 			os << "\\parbox";
 		else if (params_.use_makebox) {
-			// "-999col%" is the code for no width
-			if (from_ascii(width_string) != "-9.99\\columnwidth") {
+			if (!width_string.empty()) {
 				os << "\\makebox";
 				// FIXME UNICODE
 				// output the width and horizontal position
diff --git a/src/lengthcommon.cpp b/src/lengthcommon.cpp
index 217c22b..72f5bbf 100644
--- a/src/lengthcommon.cpp
+++ b/src/lengthcommon.cpp
@@ -236,8 +236,11 @@ bool isValidGlueLength(string const & data, GlueLength * result)
 	// forward approach leads to very long, tedious code that would be
 	// much harder to understand and maintain. (AS)
 
-	if (data.empty())
+	if (data.empty()) {
+		if (result)
+			*result = GlueLength();
 		return true;
+	}
 	string buffer = ltrim(data);
 
 	// To make isValidGlueLength recognize negative values as
@@ -306,8 +309,11 @@ bool isValidLength(string const & data, Length * result)
 	// The parser may seem overkill for lengths without
 	// glue, but since we already have it, using it is
 	// easier than writing something from scratch.
-	if (data.empty())
+	if (data.empty()) {
+		if (result)
+			*result = Length();
 		return true;
+	}
 
 	string   buffer = data;
 	int      pattern_index = 0;

Reply via email to