[gtk+/wip/matthiasc/gadget] paned: Use min-width/height for separator



commit c4f2fdc547e3ae46107da7c234b7110a2637523d
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 9 00:43:02 2015 -0500

    paned: Use min-width/height for separator
    
    And deprecated the -GtkPaned-handle-size style property.
    We still use it when min-width/height are unset.

 gtk/gtkpaned.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 3343b8c..cf5be4a 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -41,6 +41,10 @@
 #include "gtkcsscustomgadgetprivate.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkstylecontextprivate.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+
+#include <math.h>
 
 /**
  * SECTION:gtkpaned
@@ -422,7 +426,7 @@ gtk_paned_class_init (GtkPanedClass *class)
                                                             0,
                                                             G_MAXINT,
                                                             5,
-                                                            GTK_PARAM_READABLE));
+                                                            GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkPaned:resize:
@@ -698,7 +702,11 @@ initiates_touch_drag (GtkPaned *paned,
 
 #define TOUCH_EXTRA_AREA_WIDTH 50
   gtk_widget_get_allocation (GTK_WIDGET (paned), &allocation);
-  gtk_widget_style_get (GTK_WIDGET (paned), "handle-size", &handle_size, NULL);
+  gtk_css_gadget_get_preferred_size (priv->handle_gadget,
+                                     priv->orientation,
+                                     -1,
+                                     NULL, &handle_size,
+                                     NULL, NULL);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
@@ -1140,6 +1148,18 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget      *widget,
     }
 }
 
+static gint
+get_number (GtkCssStyle *style,
+            guint        property)
+{
+  double d = _gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100.0);
+
+  if (d < 1)
+    return ceil (d);
+  else
+    return floor (d);
+}
+
 static void
 gtk_paned_get_handle_size (GtkCssGadget   *gadget,
                            GtkOrientation  orientation,
@@ -1155,14 +1175,28 @@ gtk_paned_get_handle_size (GtkCssGadget   *gadget,
   GtkPanedPrivate *priv = paned->priv;
   GtkStyleContext *context;
   gint handle_size;
+  GtkCssStyle *style;
+  gint min_size;
 
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (gadget));
-  gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
-  gtk_style_context_restore (context);
-
+  style = gtk_css_gadget_get_style (gadget);
   if (orientation == priv->orientation)
-    *minimum = *natural = handle_size;
+    {
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
+        min_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH);
+      else
+        min_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT);
+
+      if (min_size != 0)
+        *minimum = *natural = min_size;
+      else
+        {
+          context = gtk_widget_get_style_context (widget);
+          gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (gadget));
+          gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+          gtk_style_context_restore (context);
+          *minimum = *natural = handle_size;
+        }
+    }
   else if (orientation == GTK_ORIENTATION_HORIZONTAL)
     *minimum = *natural = gtk_widget_get_allocated_width (widget);
   else
@@ -1589,7 +1623,11 @@ gtk_paned_create_child_window (GtkPaned  *paned,
       GtkAllocation allocation;
       int handle_size;
 
-      gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+      gtk_css_gadget_get_preferred_size (priv->handle_gadget,
+                                         priv->orientation,
+                                         -1,
+                                         NULL, &handle_size,
+                                         NULL, NULL);
 
       gtk_widget_get_allocation (widget, &allocation);
       if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]