diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 9e053f31ef..be082f840e 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5050,6 +5050,7 @@ gtk_widget_style_get gtk_widget_style_get_property gtk_widget_style_get_valist gtk_widget_style_attach +gtk_widget_class_set_accessible_type gtk_widget_get_accessible gtk_widget_child_focus gtk_widget_child_notify diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index cde5ce5c5a..5bac657ba3 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -3462,6 +3462,7 @@ gtk_widget_class_install_style_property gtk_widget_class_install_style_property_parser gtk_widget_class_list_style_properties gtk_widget_class_path +gtk_widget_class_set_accessible_type gtk_widget_compute_expand gtk_widget_create_pango_context gtk_widget_create_pango_layout diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index e81f7f4c87..def8ab4915 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -408,7 +408,7 @@ struct _GtkWidgetPrivate struct _GtkWidgetClassPrivate { - int dummy; + GType accessible_type; }; enum { @@ -938,6 +938,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) klass->show_help = gtk_widget_real_show_help; /* Accessibility support */ + klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE; klass->get_accessible = gtk_widget_real_get_accessible; klass->adjust_size_request = gtk_widget_real_adjust_size_request; @@ -11916,6 +11917,33 @@ G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition, gtk_requisition_copy, gtk_requisition_free) +/** + * gtk_widget_class_set_accessible_type: + * @widget_class: class to set the accessible type for + * @type: The object type that implements the accessible for @widget_class + * + * Sets the type to be used for creating accessibles for widgets of + * @widget_class. The given @type must be a subtype of the type used for + * accessibles of the parent class. + * + * This function should only be called from class init functions of widgets. + * + * Since: 3.2 + **/ +void +gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class, + GType type) +{ + GtkWidgetClassPrivate *priv; + + g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class)); + g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type)); + + priv = widget_class->priv; + + priv->accessible_type = type; +} + /** * gtk_widget_get_accessible: * @widget: a #GtkWidget @@ -11959,15 +11987,27 @@ gtk_widget_real_get_accessible (GtkWidget *widget) quark_accessible_object); if (!accessible) { + GtkWidgetClass *widget_class; AtkObjectFactory *factory; AtkRegistry *default_registry; - default_registry = atk_get_default_registry (); - factory = atk_registry_get_factory (default_registry, - G_TYPE_FROM_INSTANCE (widget)); - accessible = - atk_object_factory_create_accessible (factory, - G_OBJECT (widget)); + widget_class = GTK_WIDGET_GET_CLASS (widget); + + if (widget_class->priv->accessible_type == GTK_TYPE_ACCESSIBLE) + { + default_registry = atk_get_default_registry (); + factory = atk_registry_get_factory (default_registry, + G_TYPE_FROM_INSTANCE (widget)); + accessible = + atk_object_factory_create_accessible (factory, + G_OBJECT (widget)); + } + else + { + accessible = g_object_new (widget_class->priv->accessible_type, NULL); + atk_object_initialize (accessible, widget); + } + g_object_set_qdata (G_OBJECT (widget), quark_accessible_object, accessible); diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 09d8a8e0a4..8aa1e1f640 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -722,6 +722,8 @@ void gtk_widget_set_support_multidevice (GtkWidget *widget, gboolean support_multidevice); /* Accessibility support */ +void gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class, + GType type); AtkObject* gtk_widget_get_accessible (GtkWidget *widget);