]> Pileus Git - ~andy/gtk/commitdiff
widgetpath: allow GTypes non-derived from GTK_TYPE_WIDGET
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 13 Dec 2010 16:54:02 +0000 (17:54 +0100)
committerCosimo Cecchi <cosimoc@gnome.org>
Fri, 17 Dec 2010 17:30:57 +0000 (18:30 +0100)
This makes things like GtkCellRenderer or GtkNumerableIcon more easily
themeable.

https://bugzilla.gnome.org/show_bug.cgi?id=637169

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkcssprovider.c
gtk/gtkstylecontext.c
gtk/gtkstyleprovider.c
gtk/gtkwidget.c
gtk/gtkwidgetpath.c
gtk/gtkwidgetpath.h
gtk/tests/stylecontext.c

index e16eb06bf32c8cb0c49cb80c3da18ef499516b12..a96ec2112867634a24601a87e058e4b92b6ce696 100644 (file)
@@ -5383,7 +5383,7 @@ GtkWidgetPath
 gtk_widget_path_append_type
 gtk_widget_path_copy
 gtk_widget_path_free
-gtk_widget_path_get_widget_type
+gtk_widget_path_get_object_type
 gtk_widget_path_has_parent
 gtk_widget_path_is_type
 gtk_widget_path_iter_add_class
@@ -5391,7 +5391,7 @@ gtk_widget_path_iter_add_region
 gtk_widget_path_iter_clear_classes
 gtk_widget_path_iter_clear_regions
 gtk_widget_path_iter_get_name
-gtk_widget_path_iter_get_widget_type
+gtk_widget_path_iter_get_object_type
 gtk_widget_path_iter_has_class
 gtk_widget_path_iter_has_name
 gtk_widget_path_iter_has_qclass
@@ -5403,7 +5403,7 @@ gtk_widget_path_iter_list_regions
 gtk_widget_path_iter_remove_class
 gtk_widget_path_iter_remove_region
 gtk_widget_path_iter_set_name
-gtk_widget_path_iter_set_widget_type
+gtk_widget_path_iter_set_object_type
 gtk_widget_path_length
 gtk_widget_path_new
 gtk_widget_path_prepend_type
index ad10d607e3fd3f1c84507a88ef3634f46a77f418..d93271540e1c773eaf5d7f5c6cb8ac3afb071109 100644 (file)
@@ -3498,7 +3498,7 @@ gtk_widget_path_append_type
 gtk_widget_path_copy
 gtk_widget_path_free
 gtk_widget_path_get_type G_GNUC_CONST
-gtk_widget_path_get_widget_type
+gtk_widget_path_get_object_type
 gtk_widget_path_has_parent
 gtk_widget_path_is_type
 gtk_widget_path_iter_add_class
@@ -3506,7 +3506,7 @@ gtk_widget_path_iter_add_region
 gtk_widget_path_iter_clear_classes
 gtk_widget_path_iter_clear_regions
 gtk_widget_path_iter_get_name
-gtk_widget_path_iter_get_widget_type
+gtk_widget_path_iter_get_object_type
 gtk_widget_path_iter_has_class
 gtk_widget_path_iter_has_name
 gtk_widget_path_iter_has_qclass
@@ -3518,7 +3518,7 @@ gtk_widget_path_iter_list_regions
 gtk_widget_path_iter_remove_class
 gtk_widget_path_iter_remove_region
 gtk_widget_path_iter_set_name
-gtk_widget_path_iter_set_widget_type
+gtk_widget_path_iter_set_object_type
 gtk_widget_path_length
 gtk_widget_path_new
 gtk_widget_path_prepend_type
index 1ea5ed9ae2cc564b4ac923e6e4405170346700a3..90a50d310a4b0fa3e84302112f919389195e2238 100644 (file)
@@ -1073,7 +1073,7 @@ compare_selector_element (GtkWidgetPath   *path,
     {
       GType type;
 
-      type = gtk_widget_path_iter_get_widget_type (path, index);
+      type = gtk_widget_path_iter_get_object_type (path, index);
 
       if (!g_type_is_a (type, elem->type))
         return FALSE;
index 3abea8b12f59892f3f41ff4b6499ce6f8bb6d44d..8217b37d73ebec6a5907f24ec21842389ed110aa 100644 (file)
@@ -2386,7 +2386,15 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
   if (!priv->widget_path)
     return;
 
-  widget_type = gtk_widget_path_get_widget_type (priv->widget_path);
+  widget_type = gtk_widget_path_get_object_type (priv->widget_path);
+
+  if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
+    {
+      g_warning ("%s: can't get style properties for non-widget class `%s'",
+                 G_STRLOC,
+                 g_type_name (widget_type));
+      return;
+    }
 
   widget_class = g_type_class_ref (widget_type);
   pspec = gtk_widget_class_find_style_property (widget_class, property_name);
@@ -2433,6 +2441,7 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
   GtkStyleContextPrivate *priv;
   const gchar *prop_name;
   GtkStateFlags state;
+  GType widget_type;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
@@ -2442,6 +2451,16 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
   if (!priv->widget_path)
     return;
 
+  widget_type = gtk_widget_path_get_object_type (priv->widget_path);
+
+  if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
+    {
+      g_warning ("%s: can't get style properties for non-widget class `%s'",
+                 G_STRLOC,
+                 g_type_name (widget_type));
+      return;
+    }
+
   state = gtk_style_context_get_state (context);
 
   while (prop_name)
@@ -2449,11 +2468,8 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
       GtkWidgetClass *widget_class;
       GParamSpec *pspec;
       const GValue *peek_value;
-      GType widget_type;
       gchar *error;
 
-      widget_type = gtk_widget_path_get_widget_type (priv->widget_path);
-
       widget_class = g_type_class_ref (widget_type);
       pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
       g_type_class_unref (widget_class);
index 8ed0d975ca8c611ba74a48b33e6f02e7b79fd632..5cd63e4f06dc524e38d8707e9d48a457f2edcec6 100644 (file)
@@ -107,7 +107,7 @@ gtk_style_provider_get_style_property (GtkStyleProvider *provider,
   g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), FALSE);
   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
   g_return_val_if_fail (path != NULL, FALSE);
-  g_return_val_if_fail (g_type_is_a (gtk_widget_path_get_widget_type (path), pspec->owner_type), FALSE);
+  g_return_val_if_fail (g_type_is_a (gtk_widget_path_get_object_type (path), pspec->owner_type), FALSE);
   g_return_val_if_fail (value != NULL, FALSE);
 
   iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);
index 3e3f7a0a934a70cb80da7eb3d090360dcdc72834..31672e01ff3cb6d00b8d989a7c2d0973071e3737 100644 (file)
@@ -13754,7 +13754,7 @@ gtk_widget_get_path (GtkWidget *widget)
    * implementation with a wrong widget type in the widget path
    */
   if (widget->priv->path &&
-      G_OBJECT_TYPE (widget) != gtk_widget_path_get_widget_type (widget->priv->path))
+      G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
     {
       gtk_widget_path_free (widget->priv->path);
       widget->priv->path = NULL;
index d25f55097570fac444e8ba752607e802fe5e3068..6636abdd14c18ed58a643d24c18ec080d8cc761d 100644 (file)
@@ -239,7 +239,6 @@ gtk_widget_path_prepend_type (GtkWidgetPath *path,
   GtkPathElement new = { 0 };
 
   g_return_if_fail (path != NULL);
-  g_return_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET));
 
   new.type = type;
   g_array_prepend_val (path->elems, new);
@@ -263,7 +262,6 @@ gtk_widget_path_append_type (GtkWidgetPath *path,
   GtkPathElement new = { 0 };
 
   g_return_val_if_fail (path != NULL, 0);
-  g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), 0);
 
   new.type = type;
   g_array_append_val (path->elems, new);
@@ -272,11 +270,11 @@ gtk_widget_path_append_type (GtkWidgetPath *path,
 }
 
 /**
- * gtk_widget_path_iter_get_widget_type:
+ * gtk_widget_path_iter_get_object_type:
  * @path: a #GtkWidgetPath
- * @pos: position to get the widget type for, -1 for the path head
+ * @pos: position to get the object type for, -1 for the path head
  *
- * Returns the widget #GType that is at position @pos in the widget
+ * Returns the object #GType that is at position @pos in the widget
  * hierarchy defined in @path.
  *
  * Returns: a widget type
@@ -284,7 +282,7 @@ gtk_widget_path_append_type (GtkWidgetPath *path,
  * Since: 3.0
  **/
 GType
-gtk_widget_path_iter_get_widget_type (const GtkWidgetPath *path,
+gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
                                       gint                 pos)
 {
   GtkPathElement *elem;
@@ -300,18 +298,18 @@ gtk_widget_path_iter_get_widget_type (const GtkWidgetPath *path,
 }
 
 /**
- * gtk_widget_path_iter_set_widget_type:
+ * gtk_widget_path_iter_set_object_type:
  * @path: a #GtkWidgetPath
  * @pos: position to modify, -1 for the path head
- * @type: widget type to set
+ * @type: object type to set
  *
- * Sets the widget type for a given position in the widget hierarchy
- * defined by @path. @type must be a #GtkWidget derived #GType.
+ * Sets the object type for a given position in the widget hierarchy
+ * defined by @path.
  *
  * Since: 3.0
  **/
 void
-gtk_widget_path_iter_set_widget_type (GtkWidgetPath *path,
+gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
                                       gint           pos,
                                       GType          type)
 {
@@ -319,7 +317,6 @@ gtk_widget_path_iter_set_widget_type (GtkWidgetPath *path,
 
   g_return_if_fail (path != NULL);
   g_return_if_fail (path->elems->len != 0);
-  g_return_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET));
 
   if (pos < 0 || pos > path->elems->len)
     pos = path->elems->len - 1;
@@ -959,18 +956,18 @@ gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
 }
 
 /**
- * gtk_widget_path_get_widget_type:
+ * gtk_widget_path_get_object_type:
  * @path: a #GtkWidget
  *
- * Returns the topmost widget type, that is, the widget type this path
+ * Returns the topmost object type, that is, the object type this path
  * is representing.
  *
- * Returns: The widget type
+ * Returns: The object type
  *
  * Since: 3.0
  **/
 GType
-gtk_widget_path_get_widget_type (const GtkWidgetPath *path)
+gtk_widget_path_get_object_type (const GtkWidgetPath *path)
 {
   GtkPathElement *elem;
 
@@ -1000,7 +997,6 @@ gtk_widget_path_is_type (const GtkWidgetPath *path,
   GtkPathElement *elem;
 
   g_return_val_if_fail (path != NULL, FALSE);
-  g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
 
   elem = &g_array_index (path->elems, GtkPathElement,
                          path->elems->len - 1);
@@ -1031,7 +1027,6 @@ gtk_widget_path_has_parent (const GtkWidgetPath *path,
   guint i;
 
   g_return_val_if_fail (path != NULL, FALSE);
-  g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
 
   for (i = 0; i < path->elems->len - 1; i++)
     {
index 87b44b8ef99bbb975e0918a5a86d54eae4ce299c..2c9c981e41cd2eaec08ca93a08823cb6cd057572 100644 (file)
@@ -46,9 +46,9 @@ gint            gtk_widget_path_append_type         (GtkWidgetPath       *path,
 void            gtk_widget_path_prepend_type        (GtkWidgetPath       *path,
                                                      GType                type);
 
-GType               gtk_widget_path_iter_get_widget_type (const GtkWidgetPath *path,
+GType               gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
                                                           gint                 pos);
-void                gtk_widget_path_iter_set_widget_type (GtkWidgetPath       *path,
+void                gtk_widget_path_iter_set_object_type (GtkWidgetPath       *path,
                                                           gint                 pos,
                                                           GType                type);
 
@@ -103,7 +103,7 @@ gboolean gtk_widget_path_iter_has_qregion   (const GtkWidgetPath *path,
                                              GQuark               qname,
                                              GtkRegionFlags      *flags);
 
-GType           gtk_widget_path_get_widget_type (const GtkWidgetPath *path);
+GType           gtk_widget_path_get_object_type (const GtkWidgetPath *path);
 
 gboolean        gtk_widget_path_is_type    (const GtkWidgetPath *path,
                                             GType                type);
index 69b9510bfd057861efd8458b5ddc0932ab7914e6..b1e413f197e378a0ac18bd30fb30f99f55905d45 100644 (file)
@@ -274,14 +274,14 @@ test_path (void)
   pos = gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
   g_assert_cmpint (pos, ==, 0);
   g_assert_cmpint (gtk_widget_path_length (path), ==, 1);
-  g_assert (gtk_widget_path_iter_get_widget_type (path, 0) == GTK_TYPE_WINDOW);
+  g_assert (gtk_widget_path_iter_get_object_type (path, 0) == GTK_TYPE_WINDOW);
   g_assert (gtk_widget_path_is_type (path, GTK_TYPE_WIDGET));
   g_assert (gtk_widget_path_iter_get_name (path, 0) == NULL);
 
   pos = gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
   g_assert_cmpint (pos, ==, 1);
   g_assert_cmpint (gtk_widget_path_length (path), ==, 2);
-  gtk_widget_path_iter_set_widget_type (path, pos, GTK_TYPE_BUTTON);
+  gtk_widget_path_iter_set_object_type (path, pos, GTK_TYPE_BUTTON);
   g_assert (gtk_widget_path_is_type (path, GTK_TYPE_BUTTON));
   g_assert (gtk_widget_path_has_parent (path, GTK_TYPE_WIDGET));
   g_assert (gtk_widget_path_has_parent (path, GTK_TYPE_WINDOW));