[gtk+] style: Convert border-width to a shorthand



commit f5c7cefccabab420e3042325622bdc29fa49ca60
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 22 00:10:43 2011 +0200

    style: Convert border-width to a shorthand
    
    Add the corresponding properties it refers to, too:
    - border-top-width
    - border-left-width
    - border-bottom-width
    - border-right-width

 gtk/gtkcssprovider.c          |   31 +++++++++++-
 gtk/gtkstylecontext.c         |   25 +++++-----
 gtk/gtkstyleproperty.c        |  103 ++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkstylepropertyprivate.h |    2 +-
 4 files changed, 143 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 6f8cbe4..37091b2 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -690,10 +690,37 @@
  *         </entry>
  *       </row>
  *       <row>
- *         <entry>border-width</entry>
+ *         <entry>border-top-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-top-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-left-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-left-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-bottom-width</entry>
  *         <entry>integer</entry>
  *         <entry>#gint</entry>
- *         <entry>border-width: 5;</entry>
+ *         <entry>border-bottom-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-right-width</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>border-right-width: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>border-width</entry>
+ *         <entry morerows="1">#GtkBorder</entry>
+ *         <entry morerows="1"><literallayout>border-width: 1;
+ * border-width: 1 2;
+ * border-width: 1 2 3;
+ * border-width: 1 2 3 5;</literallayout>
+ *         </entry>
  *       </row>
  *       <row>
  *         <entry>border-radius</entry>
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index e96faea..134a0f2 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -3474,28 +3474,27 @@ gtk_style_context_get_border (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
-  const GValue *value;
-  GtkBorder *b;
+  int top, left, bottom, right;
 
   g_return_if_fail (border != NULL);
-  *border = 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,
-                                               "border-width",
-                                               state,
-                                               NULL);
+  gtk_style_properties_get (data->store,
+                            state,
+                            "border-top-width", &top,
+                            "border-left-width", &left,
+                            "border-bottom-width", &bottom,
+                            "border-right-width", &right,
+                            NULL);
 
-  if (value)
-    {
-      b = g_value_get_boxed (value);
-      *border = *b;
-    }
+  border->top = top;
+  border->left = left;
+  border->bottom = bottom;
+  border->right = right;
 }
 
 /**
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 2d6bda6..8925ba4 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -1160,6 +1160,83 @@ bindings_value_to_string (const GValue *value)
   return g_string_free (str, FALSE);
 }
 
+/*** PACKING ***/
+
+static GParameter *
+unpack_border (const GValue *value,
+               guint        *n_params,
+               const char   *top,
+               const char   *left,
+               const char   *bottom,
+               const char   *right)
+{
+  GParameter *parameter = g_new0 (GParameter, 4);
+  GtkBorder *border = g_value_get_boxed (value);
+
+  parameter[0].name = top;
+  g_value_init (&parameter[0].value, G_TYPE_INT);
+  g_value_set_int (&parameter[0].value, border->top);
+  parameter[1].name = left;
+  g_value_init (&parameter[1].value, G_TYPE_INT);
+  g_value_set_int (&parameter[1].value, border->left);
+  parameter[2].name = bottom;
+  g_value_init (&parameter[2].value, G_TYPE_INT);
+  g_value_set_int (&parameter[2].value, border->bottom);
+  parameter[3].name = right;
+  g_value_init (&parameter[3].value, G_TYPE_INT);
+  g_value_set_int (&parameter[3].value, border->right);
+
+  *n_params = 4;
+  return parameter;
+}
+
+static void
+pack_border (GValue             *value,
+             GtkStyleProperties *props,
+             GtkStateFlags       state,
+             const char         *top,
+             const char         *left,
+             const char         *bottom,
+             const char         *right)
+{
+  GtkBorder border;
+  int t, l, b, r;
+
+  gtk_style_properties_get (props,
+                            state,
+                            top, &t,
+                            left, &l,
+                            bottom, &b,
+                            right, &r,
+                            NULL);
+
+  border.top = t;
+  border.left = l;
+  border.bottom = b;
+  border.right = r;
+
+  g_value_set_boxed (value, &border);
+}
+
+static GParameter *
+unpack_border_width (const GValue *value,
+                     guint        *n_params)
+{
+  return unpack_border (value, n_params,
+                        "border-top-width", "border-left-width",
+                        "border-bottom-width", "border-right-width");
+}
+
+static void
+pack_border_width (GValue             *value,
+                   GtkStyleProperties *props,
+                   GtkStateFlags       state)
+{
+  pack_border (value, props, state,
+               "border-top-width", "border-left-width",
+               "border-bottom-width", "border-right-width");
+}
+
 /*** API ***/
 
 static void
@@ -1368,10 +1445,32 @@ gtk_style_property_init (void)
                                                               "Padding",
                                                               GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("border-width",
+                                          g_param_spec_int ("border-top-width",
+                                                            "border top width",
+                                                            "Border width at top",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-left-width",
+                                                            "border left width",
+                                                            "Border width at left",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-bottom-width",
+                                                            "border bottom width",
+                                                            "Border width at bottom",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-right-width",
+                                                            "border right width",
+                                                            "Border width at right",
+                                                            0, G_MAXINT, 0, 0));
+  _gtk_style_property_register           (g_param_spec_boxed ("border-width",
                                                               "Border width",
                                                               "Border width, in pixels",
-                                                              GTK_TYPE_BORDER, 0));
+                                                              GTK_TYPE_BORDER, 0),
+                                          NULL,
+                                          unpack_border_width,
+                                          pack_border_width);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-radius",
                                                             "Border radius",
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index 38850a1..a1d222e 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -30,7 +30,7 @@ typedef GParameter *     (* GtkStyleUnpackFunc)            (const GValue
                                                             guint                  *n_params);
 typedef void             (* GtkStylePackFunc)              (GValue                 *value,
                                                             GtkStyleProperties     *props,
-                                                            GtkStateFlags           flags);
+                                                            GtkStateFlags           state);
 
 struct _GtkStyleProperty
 {



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