widgetpath: allow GTypes non-derived from GTK_TYPE_WIDGET

This makes things like GtkCellRenderer or GtkNumerableIcon more easily
themeable.

https://bugzilla.gnome.org/show_bug.cgi?id=637169
This commit is contained in:
Cosimo Cecchi 2010-12-13 17:54:02 +01:00
parent 806c04411d
commit b792a31995
9 changed files with 47 additions and 36 deletions

View 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

View 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

View 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;

View 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);

View 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);

View 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;

View 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++)
{

View 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);

View 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));