[virt-tools-list] [PATCH 3/4] ovBox: Make get_preferred_width/height differentiate between min and natural

Hans de Goede hdegoede at redhat.com
Mon Apr 22 19:08:57 UTC 2013


gtk-3's widget size negotiation code differentiates between the minimum
size and the natural size of a widget, fix ovBox to pass this along from
its underlying widget to its parent.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/view/ovBox.c | 61 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 16 deletions(-)

diff --git a/src/view/ovBox.c b/src/view/ovBox.c
index a3b1130..185b0b7 100644
--- a/src/view/ovBox.c
+++ b/src/view/ovBox.c
@@ -481,9 +481,9 @@ ViewOvBoxUnrealize(GtkWidget *widget) // IN
 /*
  *-----------------------------------------------------------------------------
  *
- * ViewOvBoxSizeRequest --
+ * ViewOvBoxRealSizeRequest --
  *
- *      "size_request" method of a ViewOvBox.
+ *      "size_request" method, generalized to work with both gtk-2 and 3.
  *
  * Results:
  *      None
@@ -494,12 +494,12 @@ ViewOvBoxUnrealize(GtkWidget *widget) // IN
  *-----------------------------------------------------------------------------
  */
 static void
-ViewOvBoxSizeRequest(GtkWidget *widget,           // IN
-                     GtkRequisition *requisition) // OUT
+ViewOvBoxRealSizeRequest(GtkWidget *widget,           // IN
+   GtkRequisition *min_in, GtkRequisition *nat_in,      // IN
+   GtkRequisition *min_out, GtkRequisition *nat_out)    // OUT
 {
    ViewOvBox *that;
    ViewOvBoxPrivate *priv;
-   GtkRequisition underR;
    gboolean expand;
    gboolean fill;
    guint padding;
@@ -509,10 +509,8 @@ ViewOvBoxSizeRequest(GtkWidget *widget,           // IN
    priv = that->priv;
 
 #if GTK_CHECK_VERSION(3, 0, 0)
-   gtk_widget_get_preferred_size(priv->under, NULL, &underR);
    gtk_widget_get_preferred_size(priv->over, NULL, &priv->overR);
 #else
-   gtk_widget_size_request(priv->under, &underR);
    gtk_widget_size_request(priv->over, &priv->overR);
 #endif
 
@@ -521,10 +519,19 @@ ViewOvBoxSizeRequest(GtkWidget *widget,           // IN
                            "fill", &fill,
                            "padding", &padding,
                            NULL);
-   requisition->width = MAX(underR.width,
-                            priv->overR.width + ((expand || fill) ? 0 : padding));
+
    min = ViewOvBoxGetActualMin(that);
-   requisition->height = MAX(underR.height + min, priv->overR.height);
+
+   if (min_out) {
+      min_out->width = MAX(min_in->width, priv->overR.width +
+                                            ((expand || fill) ? 0 : padding));
+      min_out->height = MAX(min_in->height + min, priv->overR.height);
+   }
+   if (nat_out) {
+      nat_out->width = MAX(nat_in->width, priv->overR.width +
+                                            ((expand || fill) ? 0 : padding));
+      nat_out->height = MAX(nat_in->height + min, priv->overR.height);
+   }
 }
 
 #if GTK_CHECK_VERSION(3, 0, 0)
@@ -533,11 +540,15 @@ ViewOvBox_get_preferred_width (GtkWidget *widget,
                                gint      *minimal_width,
                                gint      *natural_width)
 {
-  GtkRequisition requisition;
+   ViewOvBoxPrivate *priv = VIEW_OV_BOX(widget)->priv;
+   GtkRequisition min_in, nat_in, min_out, nat_out;
+
+   gtk_widget_get_preferred_size(priv->under, &min_in, &nat_in);
 
-  ViewOvBoxSizeRequest (widget, &requisition);
+   ViewOvBoxRealSizeRequest(widget, &min_in, &nat_in, &min_out, &nat_out);
 
-  *minimal_width = *natural_width = requisition.width;
+   *minimal_width = min_out.width;
+   *natural_width = nat_out.width;
 }
 
 static void
@@ -545,11 +556,29 @@ ViewOvBox_get_preferred_height (GtkWidget *widget,
                                 gint      *minimal_height,
                                 gint      *natural_height)
 {
-  GtkRequisition requisition;
+   ViewOvBoxPrivate *priv = VIEW_OV_BOX(widget)->priv;
+   GtkRequisition min_in, nat_in, min_out, nat_out;
+
+   gtk_widget_get_preferred_size(priv->under, &min_in, &nat_in);
+
+   ViewOvBoxRealSizeRequest(widget, &min_in, &nat_in, &min_out, &nat_out);
+
+   *minimal_height = min_out.height;
+   *natural_height = nat_out.height;
+}
+
+#else
+
+static void
+ViewOvBoxSizeRequest(GtkWidget *widget,           // IN
+                     GtkRequisition *requisition) // OUT
+{
+   ViewOvBoxPrivate *priv = VIEW_OV_BOX(widget)->priv;
+   GtkRequisition min;
 
-  ViewOvBoxSizeRequest (widget, &requisition);
+   gtk_widget_size_request(priv->under, &min);
 
-  *minimal_height = *natural_height = requisition.height;
+   ViewOvBoxRealSizeRequest(widget, &min, NULL, requisition, NULL);
 }
 #endif
 
-- 
1.8.2




More information about the virt-tools-list mailing list