[gtk+] style: Make padding a shorthand



commit a35aa96149f3a7e6fafe083b3f5d97fb151f57d8
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 22 05:42:17 2011 +0200

    style: Make padding a shorthand
    
    ... and add the real properties:
    - padding-top
    - padding-left
    - padding-bottom
    - padding-right

 gtk/gtkcssprovider.c   |   24 ++++++++++++++++++++++++
 gtk/gtkstylecontext.c  |   25 ++++++++++++-------------
 gtk/gtkstyleproperty.c |   45 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 79 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 37091b2..42f48ab 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -667,6 +667,30 @@
  *         </entry>
  *       </row>
  *       <row>
+ *         <entry>padding-top</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-top: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-left</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-left: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-bottom</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-bottom: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-right</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-right: 5;</entry>
+ *       </row>
+ *       <row>
  *         <entry>padding</entry>
  *       </row>
  *       <row>
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 134a0f2..7f6ebff 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -3515,28 +3515,27 @@ gtk_style_context_get_padding (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
-  const GValue *value;
-  GtkBorder *b;
+  int top, left, bottom, right;
 
   g_return_if_fail (padding != NULL);
-  *padding = fallback_border;
-
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
   priv = context->priv;
   g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
-  value = _gtk_style_properties_peek_property (data->store,
-                                               "padding",
-                                               state,
-                                               NULL);
+  gtk_style_properties_get (data->store,
+                            state,
+                            "padding-top", &top,
+                            "padding-left", &left,
+                            "padding-bottom", &bottom,
+                            "padding-right", &right,
+                            NULL);
 
-  if (value)
-    {
-      b = g_value_get_boxed (value);
-      *padding = *b;
-    }
+  padding->top = top;
+  padding->left = left;
+  padding->bottom = bottom;
+  padding->right = right;
 }
 
 /**
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 8925ba4..9f58bd5 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -1237,6 +1237,25 @@ pack_border_width (GValue             *value,
                "border-bottom-width", "border-right-width");
 }
 
+static GParameter *
+unpack_padding (const GValue *value,
+                guint        *n_params)
+{
+  return unpack_border (value, n_params,
+                        "padding-top", "padding-left",
+                        "padding-bottom", "padding-right");
+}
+
+static void
+pack_padding (GValue             *value,
+              GtkStyleProperties *props,
+              GtkStateFlags       state)
+{
+  pack_border (value, props, state,
+               "padding-top", "padding-left",
+               "padding-bottom", "padding-right");
+}
+
 /*** API ***/
 
 static void
@@ -1440,10 +1459,32 @@ gtk_style_property_init (void)
                                                               "Margin",
                                                               GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("padding",
+                                          g_param_spec_int ("padding-top",
+                                                            "padding top",
+                                                            "Padding at top",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-left",
+                                                            "padding left",
+                                                            "Padding at left",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-bottom",
+                                                            "padding bottom",
+                                                            "Padding at bottom",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-right",
+                                                            "padding right",
+                                                            "Padding at right",
+                                                            0, G_MAXINT, 0, 0));
+  _gtk_style_property_register           (g_param_spec_boxed ("padding",
                                                               "Padding",
                                                               "Padding",
-                                                              GTK_TYPE_BORDER, 0));
+                                                              GTK_TYPE_BORDER, 0),
+                                          NULL,
+                                          unpack_padding,
+                                          pack_padding);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-top-width",
                                                             "border top width",



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