From e2847d9637bd2394177675d1b8d6f4862796c4de Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 27 Jun 2011 23:24:22 -0400 Subject: [PATCH] Convert GailRadioButton to GtkRadioButtonAccessible --- gtk/a11y/Makefile.am | 4 +- gtk/a11y/gail.c | 3 - gtk/a11y/gailradiobutton.c | 130 ---------------------------- gtk/a11y/gailradiobutton.h | 53 ------------ gtk/a11y/gtkradiobuttonaccessible.c | 116 +++++++++++++++++++++++++ gtk/a11y/gtkradiobuttonaccessible.h | 53 ++++++++++++ gtk/gtkradiobutton.c | 3 + 7 files changed, 174 insertions(+), 188 deletions(-) delete mode 100644 gtk/a11y/gailradiobutton.c delete mode 100644 gtk/a11y/gailradiobutton.h create mode 100644 gtk/a11y/gtkradiobuttonaccessible.c create mode 100644 gtk/a11y/gtkradiobuttonaccessible.h diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am index 1756bef44..71defa078 100644 --- a/gtk/a11y/Makefile.am +++ b/gtk/a11y/Makefile.am @@ -31,7 +31,7 @@ gail_c_sources = \ gailnotebookpage.c \ gtkpanedaccessible.c \ gtkprogressbaraccessible.c \ - gailradiobutton.c \ + gtkradiobuttonaccessible.c \ gailradiomenuitem.c \ gailradiosubmenuitem.c \ gtkrangeaccessible.c \ @@ -83,7 +83,7 @@ gail_private_h_sources = \ gailnotebookpage.h \ gtkpanedaccessible.h \ gtkprogressbaraccessible.h \ - gailradiobutton.h \ + gtkradiobuttonaccessible.h \ gailradiomenuitem.h \ gailradiosubmenuitem.h \ gtkrangeaccessible.h \ diff --git a/gtk/a11y/gail.c b/gtk/a11y/gail.c index 3c4e13bc1..fcc27dc4f 100644 --- a/gtk/a11y/gail.c +++ b/gtk/a11y/gail.c @@ -37,7 +37,6 @@ #include "gailmenushell.h" #include "gailmenuitem.h" #include "gailnotebook.h" -#include "gailradiobutton.h" #include "gailradiomenuitem.h" #include "gailrenderercell.h" #include "gailscalebutton.h" @@ -110,7 +109,6 @@ GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCALE_BUTTON, GailScaleButton, gail_scale_butt GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_STATUSBAR, GailStatusbar, gail_statusbar, GTK_TYPE_STATUSBAR) GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_NOTEBOOK, GailNotebook, gail_notebook, GTK_TYPE_NOTEBOOK) GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_TREE_VIEW, GailTreeView, gail_tree_view, GTK_TYPE_TREE_VIEW) -GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_RADIO_BUTTON, GailRadioButton, gail_radio_button, GTK_TYPE_RADIO_BUTTON) GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_SCROLLED_WINDOW, GailScrolledWindow, gail_scrolled_window, GTK_TYPE_SCROLLED_WINDOW) GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_CHECK_MENU_ITEM, GailCheckMenuItem, gail_check_menu_item, gail_check_menu_item_new) GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_RADIO_MENU_ITEM, GailRadioMenuItem, gail_radio_menu_item, gail_radio_menu_item_new) @@ -876,7 +874,6 @@ gail_accessibility_module_init (void) GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_TOGGLE, gail_boolean_cell); GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER_PIXBUF, gail_image_cell); GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CELL_RENDERER, gail_renderer_cell); - GAIL_WIDGET_SET_FACTORY (GTK_TYPE_RADIO_BUTTON, gail_radio_button); GAIL_WIDGET_SET_FACTORY (GTK_TYPE_SCROLLED_WINDOW, gail_scrolled_window); GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CHECK_MENU_ITEM, gail_check_menu_item); GAIL_WIDGET_SET_FACTORY (GTK_TYPE_RADIO_MENU_ITEM, gail_radio_menu_item); diff --git a/gtk/a11y/gailradiobutton.c b/gtk/a11y/gailradiobutton.c deleted file mode 100644 index 46b85a002..000000000 --- a/gtk/a11y/gailradiobutton.c +++ /dev/null @@ -1,130 +0,0 @@ -/* GAIL - The GNOME Accessibility Implementation Library - * Copyright 2001 Sun Microsystems Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include -#include "gailradiobutton.h" - -static void gail_radio_button_class_init (GailRadioButtonClass *klass); -static void gail_radio_button_init (GailRadioButton *radio_button); -static void gail_radio_button_initialize (AtkObject *accessible, - gpointer data); - -static AtkRelationSet* gail_radio_button_ref_relation_set (AtkObject *obj); - -G_DEFINE_TYPE (GailRadioButton, gail_radio_button, GAIL_TYPE_TOGGLE_BUTTON) - -static void -gail_radio_button_class_init (GailRadioButtonClass *klass) -{ - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - - class->initialize = gail_radio_button_initialize; - class->ref_relation_set = gail_radio_button_ref_relation_set; -} - -static void -gail_radio_button_init (GailRadioButton *radio_button) -{ - radio_button->old_group = NULL; -} - -static void -gail_radio_button_initialize (AtkObject *accessible, - gpointer data) -{ - ATK_OBJECT_CLASS (gail_radio_button_parent_class)->initialize (accessible, data); - - accessible->role = ATK_ROLE_RADIO_BUTTON; -} - -AtkRelationSet* -gail_radio_button_ref_relation_set (AtkObject *obj) -{ - GtkWidget *widget; - AtkRelationSet *relation_set; - GSList *list; - GailRadioButton *radio_button; - - g_return_val_if_fail (GAIL_IS_RADIO_BUTTON (obj), NULL); - - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); - if (widget == NULL) - { - /* - * State is defunct - */ - return NULL; - } - radio_button = GAIL_RADIO_BUTTON (obj); - - relation_set = ATK_OBJECT_CLASS (gail_radio_button_parent_class)->ref_relation_set (obj); - - /* - * If the radio button'group has changed remove the relation - */ - list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); - - if (radio_button->old_group != list) - { - AtkRelation *relation; - - relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF); - atk_relation_set_remove (relation_set, relation); - } - - if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF)) - { - /* - * Get the members of the button group - */ - - radio_button->old_group = list; - if (list) - { - AtkObject **accessible_array; - guint list_length; - AtkRelation* relation; - gint i = 0; - - list_length = g_slist_length (list); - accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) * - list_length); - while (list != NULL) - { - GtkWidget* list_item = list->data; - - accessible_array[i++] = gtk_widget_get_accessible (list_item); - - list = list->next; - } - relation = atk_relation_new (accessible_array, list_length, - ATK_RELATION_MEMBER_OF); - g_free (accessible_array); - - atk_relation_set_add (relation_set, relation); - /* - * Unref the relation so that it is not leaked. - */ - g_object_unref (relation); - } - } - return relation_set; -} diff --git a/gtk/a11y/gailradiobutton.h b/gtk/a11y/gailradiobutton.h deleted file mode 100644 index 1615e44d6..000000000 --- a/gtk/a11y/gailradiobutton.h +++ /dev/null @@ -1,53 +0,0 @@ -/* GAIL - The GNOME Accessibility Implementation Library - * Copyright 2001 Sun Microsystems Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GAIL_RADIO_BUTTON_H__ -#define __GAIL_RADIO_BUTTON_H__ - -#include "gailtogglebutton.h" - -G_BEGIN_DECLS - -#define GAIL_TYPE_RADIO_BUTTON (gail_radio_button_get_type ()) -#define GAIL_RADIO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_RADIO_BUTTON, GailRadioButton)) -#define GAIL_RADIO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_RADIO_BUTTON, GailRadioButtonClass)) -#define GAIL_IS_RADIO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_RADIO_BUTTON)) -#define GAIL_IS_RADIO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_RADIO_BUTTON)) -#define GAIL_RADIO_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_RADIO_BUTTON, GailRadioButtonClass)) - -typedef struct _GailRadioButton GailRadioButton; -typedef struct _GailRadioButtonClass GailRadioButtonClass; - -struct _GailRadioButton -{ - GailToggleButton parent; - - GSList *old_group; -}; - -GType gail_radio_button_get_type (void); - -struct _GailRadioButtonClass -{ - GailToggleButtonClass parent_class; -}; - -G_END_DECLS - -#endif /* __GAIL_RADIO_BUTTON_H__ */ diff --git a/gtk/a11y/gtkradiobuttonaccessible.c b/gtk/a11y/gtkradiobuttonaccessible.c new file mode 100644 index 000000000..50e99b37f --- /dev/null +++ b/gtk/a11y/gtkradiobuttonaccessible.c @@ -0,0 +1,116 @@ +/* GAIL - The GNOME Accessibility Implementation Library + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include +#include "gtkradiobuttonaccessible.h" + + +G_DEFINE_TYPE (GtkRadioButtonAccessible, gtk_radio_button_accessible, GAIL_TYPE_TOGGLE_BUTTON) + +static void +gtk_radio_button_accessible_initialize (AtkObject *accessible, + gpointer data) +{ + ATK_OBJECT_CLASS (gtk_radio_button_accessible_parent_class)->initialize (accessible, data); + + accessible->role = ATK_ROLE_RADIO_BUTTON; +} + +static AtkRelationSet * +gtk_radio_button_accessible_ref_relation_set (AtkObject *obj) +{ + GtkWidget *widget; + AtkRelationSet *relation_set; + GSList *list; + GtkRadioButtonAccessible *radio_button; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + if (widget == NULL) + return NULL; + + radio_button = GTK_RADIO_BUTTON_ACCESSIBLE (obj); + + relation_set = ATK_OBJECT_CLASS (gtk_radio_button_accessible_parent_class)->ref_relation_set (obj); + + /* If the radio button'group has changed remove the relation */ + list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + + if (radio_button->old_group != list) + { + AtkRelation *relation; + + relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF); + atk_relation_set_remove (relation_set, relation); + } + + if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF)) + { + /* + * Get the members of the button group + */ + radio_button->old_group = list; + if (list) + { + AtkObject **accessible_array; + guint list_length; + AtkRelation* relation; + gint i = 0; + + list_length = g_slist_length (list); + accessible_array = g_new (AtkObject *, list_length); + while (list != NULL) + { + GtkWidget* list_item = list->data; + + accessible_array[i++] = gtk_widget_get_accessible (list_item); + + list = list->next; + } + relation = atk_relation_new (accessible_array, list_length, + ATK_RELATION_MEMBER_OF); + g_free (accessible_array); + + atk_relation_set_add (relation_set, relation); + /* + * Unref the relation so that it is not leaked. + */ + g_object_unref (relation); + } + } + + return relation_set; +} + +static void +gtk_radio_button_accessible_class_init (GtkRadioButtonAccessibleClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + class->initialize = gtk_radio_button_accessible_initialize; + class->ref_relation_set = gtk_radio_button_accessible_ref_relation_set; +} + +static void +gtk_radio_button_accessible_init (GtkRadioButtonAccessible *radio_button) +{ + radio_button->old_group = NULL; +} + diff --git a/gtk/a11y/gtkradiobuttonaccessible.h b/gtk/a11y/gtkradiobuttonaccessible.h new file mode 100644 index 000000000..44f47c54e --- /dev/null +++ b/gtk/a11y/gtkradiobuttonaccessible.h @@ -0,0 +1,53 @@ +/* GAIL - The GNOME Accessibility Implementation Library + * Copyright 2001 Sun Microsystems Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_RADIO_BUTTON_ACCESSIBLE_H__ +#define __GTK_RADIO_BUTTON_ACCESSIBLE_H__ + +#include "gailtogglebutton.h" + +G_BEGIN_DECLS + +#define GTK_TYPE_RADIO_BUTTON_ACCESSIBLE (gtk_radio_button_accessible_get_type ()) +#define GTK_RADIO_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RADIO_BUTTON_ACCESSIBLE, GtkRadioButtonAccessible)) +#define GTK_RADIO_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RADIO_BUTTON_ACCESSIBLE, GtkRadioButtonAccessibleClass)) +#define GTK_IS_RADIO_BUTTON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RADIO_BUTTON_ACCESSIBLE)) +#define GTK_IS_RADIO_BUTTON_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RADIO_BUTTON_ACCESSIBLE)) +#define GTK_RADIO_BUTTON_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RADIO_BUTTON_ACCESSIBLE, GtkRadioButtonAccessibleClass)) + +typedef struct _GtkRadioButtonAccessible GtkRadioButtonAccessible; +typedef struct _GtkRadioButtonAccessibleClass GtkRadioButtonAccessibleClass; + +struct _GtkRadioButtonAccessible +{ + GailToggleButton parent; + + GSList *old_group; +}; + +struct _GtkRadioButtonAccessibleClass +{ + GailToggleButtonClass parent_class; +}; + +GType gtk_radio_button_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_RADIO_BUTTON_ACCESSIBLE_H__ */ diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c index b080dc29f..cb1ba20d5 100644 --- a/gtk/gtkradiobutton.c +++ b/gtk/gtkradiobutton.c @@ -33,6 +33,7 @@ #include "gtkmarshalers.h" #include "gtkprivate.h" #include "gtkintl.h" +#include "a11y/gtkradiobuttonaccessible.h" /** * SECTION:gtkradiobutton @@ -195,6 +196,8 @@ gtk_radio_button_class_init (GtkRadioButtonClass *class) G_TYPE_NONE, 0); g_type_class_add_private (class, sizeof (GtkRadioButtonPrivate)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_RADIO_BUTTON_ACCESSIBLE); } static void -- 2.43.2