- width = allocation->width - padding_horizontal - 2 * border_width;
- height = allocation->height - padding_vertical - 2 * border_width;
-
- if (width > child_requisition.width)
- child_allocation.width = (child_requisition.width *
- (1.0 - alignment->xscale) +
- width * alignment->xscale);
+ width = MAX (1, allocation->width - padding_horizontal - 2 * border_width);
+ height = MAX (1, allocation->height - padding_vertical - 2 * border_width);
+
+ if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ {
+ gtk_widget_get_preferred_width (child, NULL, &child_nat_width);
+
+ child_width = MIN (width, child_nat_width);
+
+ gtk_widget_get_preferred_height_for_width (child, child_width, NULL, &child_nat_height);
+
+ child_height = MIN (height, child_nat_height);
+ }
+ else
+ {
+ gtk_widget_get_preferred_height (child, NULL, &child_nat_height);
+
+ child_height = MIN (height, child_nat_height);
+
+ gtk_widget_get_preferred_width_for_height (child, child_height, NULL, &child_nat_width);
+
+ child_width = MIN (width, child_nat_width);
+ }
+
+ if (width > child_width)
+ child_allocation.width = (child_width *
+ (1.0 - priv->xscale) +
+ width * priv->xscale);