[gtk+] style: Make margin a shorthand



commit 21236cf27099a80e36365aeb576fbf3e523f5450
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 22 05:55:12 2011 +0200

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

 gtk/gtkcssprovider.c   |   24 ++++++++++++++++++++++++
 gtk/gtkstylecontext.c  |   26 ++++++++++++--------------
 gtk/gtkstyleproperty.c |   45 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 79 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 42f48ab..501d283 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -653,6 +653,30 @@
  *         <entry>font: Sans 15;</entry>
  *       </row>
  *       <row>
+ *         <entry>margin-top</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>margin-top: 0;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>margin-left</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>margin-left: 1;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>margin-bottom</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>margin-bottom: 2;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>margin-right</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>margin-right: 4;</entry>
+ *       </row>
+ *       <row>
  *         <entry>margin</entry>
  *         <entry morerows="1"><literallayout>@width
  * @vertical_width @horizontal_width
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7f6ebff..b93dc36 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -506,7 +506,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static GQuark provider_list_quark = 0;
 static GdkRGBA fallback_color = { 1.0, 0.75, 0.75, 1.0 };
-static GtkBorder fallback_border = { 0 };
 
 static void gtk_style_context_finalize (GObject *object);
 
@@ -3556,28 +3555,27 @@ gtk_style_context_get_margin (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
-  const GValue *value;
-  GtkBorder *b;
+  int top, left, bottom, right;
 
   g_return_if_fail (margin != NULL);
-  *margin = 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,
-                                               "margin",
-                                               state,
-                                               NULL);
+  gtk_style_properties_get (data->store,
+                            state,
+                            "margin-top", &top,
+                            "margin-left", &left,
+                            "margin-bottom", &bottom,
+                            "margin-right", &right,
+                            NULL);
 
-  if (value)
-    {
-      b = g_value_get_boxed (value);
-      *margin = *b;
-    }
+  margin->top = top;
+  margin->left = left;
+  margin->bottom = bottom;
+  margin->right = right;
 }
 
 /**
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 9f58bd5..abed616 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -1256,6 +1256,25 @@ pack_padding (GValue             *value,
                "padding-bottom", "padding-right");
 }
 
+static GParameter *
+unpack_margin (const GValue *value,
+               guint        *n_params)
+{
+  return unpack_border (value, n_params,
+                        "margin-top", "margin-left",
+                        "margin-bottom", "margin-right");
+}
+
+static void
+pack_margin (GValue             *value,
+             GtkStyleProperties *props,
+             GtkStateFlags       state)
+{
+  pack_border (value, props, state,
+               "margin-top", "margin-left",
+               "margin-bottom", "margin-right");
+}
+
 /*** API ***/
 
 static void
@@ -1454,10 +1473,32 @@ gtk_style_property_init (void)
   gtk_style_properties_register_property (NULL, pspec);
 
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("margin",
+                                          g_param_spec_int ("margin-top",
+                                                            "margin top",
+                                                            "Margin at top",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("margin-left",
+                                                            "margin left",
+                                                            "Margin at left",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("margin-bottom",
+                                                            "margin bottom",
+                                                            "Margin at bottom",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("margin-right",
+                                                            "margin right",
+                                                            "Margin at right",
+                                                            0, G_MAXINT, 0, 0));
+  _gtk_style_property_register           (g_param_spec_boxed ("margin",
                                                               "Margin",
                                                               "Margin",
-                                                              GTK_TYPE_BORDER, 0));
+                                                              GTK_TYPE_BORDER, 0),
+                                          NULL,
+                                          unpack_margin,
+                                          pack_margin);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("padding-top",
                                                             "padding top",



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