From 7f58482d4efc833dc8abbf96381dfc84f597f8b9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 27 Jun 2011 22:39:43 -0400 Subject: Convert GailRange to GtkRangeAccessible --- gtk/a11y/Makefile.am | 4 +- gtk/a11y/gailrange.c | 445 -------------------------------------- gtk/a11y/gailrange.h | 56 ----- gtk/a11y/gtkrangeaccessible.c | 365 +++++++++++++++++++++++++++++++ gtk/a11y/gtkrangeaccessible.h | 54 +++++ gtk/a11y/gtkscaleaccessible.c | 2 +- gtk/a11y/gtkscaleaccessible.h | 7 +- gtk/a11y/gtkscrollbaraccessible.c | 2 +- gtk/a11y/gtkscrollbaraccessible.h | 6 +- gtk/gtkrange.c | 3 + 10 files changed, 432 insertions(+), 512 deletions(-) delete mode 100644 gtk/a11y/gailrange.c delete mode 100644 gtk/a11y/gailrange.h create mode 100644 gtk/a11y/gtkrangeaccessible.c create mode 100644 gtk/a11y/gtkrangeaccessible.h diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am index a2248985a4..80f1df1794 100644 --- a/gtk/a11y/Makefile.am +++ b/gtk/a11y/Makefile.am @@ -34,7 +34,7 @@ gail_c_sources = \ gailradiobutton.c \ gailradiomenuitem.c \ gailradiosubmenuitem.c \ - gailrange.c \ + gtkrangeaccessible.c \ gailrenderercell.c \ gtkscaleaccessible.c \ gailscalebutton.c \ @@ -86,7 +86,7 @@ gail_private_h_sources = \ gailradiobutton.h \ gailradiomenuitem.h \ gailradiosubmenuitem.h \ - gailrange.h \ + gtkrangeaccessible.h \ gailrenderercell.h \ gtkscaleaccessible.h \ gailscalebutton.h \ diff --git a/gtk/a11y/gailrange.c b/gtk/a11y/gailrange.c deleted file mode 100644 index 63b6f4bfc4..0000000000 --- a/gtk/a11y/gailrange.c +++ /dev/null @@ -1,445 +0,0 @@ -/* GAIL - The GNOME Accessibility Implementation Library - * Copyright 2001, 2002, 2003 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 -#include -#include "gailrange.h" -#include "gailadjustment.h" -#include "gail-private-macros.h" - -static void gail_range_class_init (GailRangeClass *klass); - -static void gail_range_init (GailRange *range); - -static void gail_range_real_initialize (AtkObject *obj, - gpointer data); - -static void gail_range_finalize (GObject *object); - -static void gail_range_real_notify_gtk (GObject *obj, - GParamSpec *pspec); - -static void atk_value_interface_init (AtkValueIface *iface); -static void gail_range_get_current_value (AtkValue *obj, - GValue *value); -static void gail_range_get_maximum_value (AtkValue *obj, - GValue *value); -static void gail_range_get_minimum_value (AtkValue *obj, - GValue *value); -static void gail_range_get_minimum_increment (AtkValue *obj, - GValue *value); -static gboolean gail_range_set_current_value (AtkValue *obj, - const GValue *value); -static void gail_range_value_changed (GtkAdjustment *adjustment, - gpointer data); - -static void atk_action_interface_init (AtkActionIface *iface); -static gboolean gail_range_do_action (AtkAction *action, - gint i); -static gboolean idle_do_action (gpointer data); -static gint gail_range_get_n_actions (AtkAction *action); -static const gchar* gail_range_get_keybinding (AtkAction *action, - gint i); -static const gchar* gail_range_action_get_name (AtkAction *action, - gint i); - -G_DEFINE_TYPE_WITH_CODE (GailRange, gail_range, GAIL_TYPE_WIDGET, - G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init) - G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init)) - -static void -gail_range_class_init (GailRangeClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - GailWidgetClass *widget_class; - - widget_class = (GailWidgetClass*)klass; - - widget_class->notify_gtk = gail_range_real_notify_gtk; - - class->initialize = gail_range_real_initialize; - - gobject_class->finalize = gail_range_finalize; -} - -static void -gail_range_init (GailRange *range) -{ -} - -static void -gail_range_real_initialize (AtkObject *obj, - gpointer data) -{ - GailRange *range = GAIL_RANGE (obj); - GtkAdjustment *adj; - GtkRange *gtk_range; - - ATK_OBJECT_CLASS (gail_range_parent_class)->initialize (obj, data); - - gtk_range = GTK_RANGE (data); - /* - * If a GtkAdjustment already exists for the GtkRange, - * create the GailAdjustment - */ - adj = gtk_range_get_adjustment (gtk_range); - if (adj) - { - range->adjustment = gail_adjustment_new (adj); - g_signal_connect (adj, - "value-changed", - G_CALLBACK (gail_range_value_changed), - range); - } - else - range->adjustment = NULL; - range->activate_keybinding=NULL; - /* - * Assumed to GtkScale (either GtkHScale or GtkVScale) - */ - obj->role = ATK_ROLE_SLIDER; -} - -static void -atk_value_interface_init (AtkValueIface *iface) -{ - iface->get_current_value = gail_range_get_current_value; - iface->get_maximum_value = gail_range_get_maximum_value; - iface->get_minimum_value = gail_range_get_minimum_value; - iface->get_minimum_increment = gail_range_get_minimum_increment; - iface->set_current_value = gail_range_set_current_value; -} - -static void -gail_range_get_current_value (AtkValue *obj, - GValue *value) -{ - GailRange *range; - - g_return_if_fail (GAIL_IS_RANGE (obj)); - - range = GAIL_RANGE (obj); - if (range->adjustment == NULL) - /* - * Adjustment has not been specified - */ - return; - - atk_value_get_current_value (ATK_VALUE (range->adjustment), value); -} - -static void -gail_range_get_maximum_value (AtkValue *obj, - GValue *value) -{ - GailRange *range; - GtkRange *gtk_range; - GtkAdjustment *gtk_adjustment; - gdouble max = 0; - - g_return_if_fail (GAIL_IS_RANGE (obj)); - - range = GAIL_RANGE (obj); - if (range->adjustment == NULL) - /* - * Adjustment has not been specified - */ - return; - - atk_value_get_maximum_value (ATK_VALUE (range->adjustment), value); - - gtk_range = GTK_RANGE (gtk_accessible_get_widget (GTK_ACCESSIBLE (range))); - g_return_if_fail (gtk_range); - - gtk_adjustment = gtk_range_get_adjustment (gtk_range); - max = g_value_get_double (value); - max -= gtk_adjustment_get_page_size (gtk_adjustment); - - if (gtk_range_get_restrict_to_fill_level (gtk_range)) - max = MIN (max, gtk_range_get_fill_level (gtk_range)); - - g_value_set_double (value, max); -} - -static void -gail_range_get_minimum_value (AtkValue *obj, - GValue *value) -{ - GailRange *range; - - g_return_if_fail (GAIL_IS_RANGE (obj)); - - range = GAIL_RANGE (obj); - if (range->adjustment == NULL) - /* - * Adjustment has not been specified - */ - return; - - atk_value_get_minimum_value (ATK_VALUE (range->adjustment), value); -} - -static void -gail_range_get_minimum_increment (AtkValue *obj, GValue *value) -{ - GailRange *range; - - g_return_if_fail (GAIL_IS_RANGE (obj)); - - range = GAIL_RANGE (obj); - if (range->adjustment == NULL) - /* - * Adjustment has not been specified - */ - return; - - atk_value_get_minimum_increment (ATK_VALUE (range->adjustment), value); -} - -static gboolean gail_range_set_current_value (AtkValue *obj, - const GValue *value) -{ - GtkWidget *widget; - - g_return_val_if_fail (GAIL_IS_RANGE (obj), FALSE); - - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); - if (widget == NULL) - return FALSE; - - if (G_VALUE_HOLDS_DOUBLE (value)) - { - GtkRange *range = GTK_RANGE (widget); - gdouble new_value; - - new_value = g_value_get_double (value); - gtk_range_set_value (range, new_value); - return TRUE; - } - else - { - return FALSE; - } -} - -static void -gail_range_finalize (GObject *object) -{ - GailRange *range = GAIL_RANGE (object); - - if (range->adjustment) - { - /* - * The GtkAdjustment may live on so we need to dicsonnect the - * signal handler - */ - if (GAIL_ADJUSTMENT (range->adjustment)->adjustment) - { - g_signal_handlers_disconnect_by_func (GAIL_ADJUSTMENT (range->adjustment)->adjustment, - (void *)gail_range_value_changed, - range); - } - g_object_unref (range->adjustment); - range->adjustment = NULL; - } - range->activate_keybinding=NULL; - if (range->action_idle_handler) - { - g_source_remove (range->action_idle_handler); - range->action_idle_handler = 0; - } - - G_OBJECT_CLASS (gail_range_parent_class)->finalize (object); -} - - -static void -gail_range_real_notify_gtk (GObject *obj, - GParamSpec *pspec) -{ - GtkAdjustment *adj; - GtkWidget *widget = GTK_WIDGET (obj); - GailRange *range = GAIL_RANGE (gtk_widget_get_accessible (widget)); - - if (strcmp (pspec->name, "adjustment") == 0) - { - /* - * Get rid of the GailAdjustment for the GtkAdjustment - * which was associated with the range. - */ - if (range->adjustment) - { - g_object_unref (range->adjustment); - range->adjustment = NULL; - } - /* - * Create the GailAdjustment when notify for "adjustment" property - * is received - */ - adj = gtk_range_get_adjustment (GTK_RANGE (widget)); - range->adjustment = gail_adjustment_new (adj); - g_signal_connect (adj, - "value-changed", - G_CALLBACK (gail_range_value_changed), - range); - } - else - GAIL_WIDGET_CLASS (gail_range_parent_class)->notify_gtk (obj, pspec); -} - -static void -gail_range_value_changed (GtkAdjustment *adjustment, - gpointer data) -{ - GailRange *range; - - g_return_if_fail (adjustment != NULL); - gail_return_if_fail (data != NULL); - - range = GAIL_RANGE (data); - - g_object_notify (G_OBJECT (range), "accessible-value"); -} - -static void -atk_action_interface_init (AtkActionIface *iface) -{ - iface->do_action = gail_range_do_action; - iface->get_n_actions = gail_range_get_n_actions; - iface->get_keybinding = gail_range_get_keybinding; - iface->get_name = gail_range_action_get_name; -} - -static gboolean -gail_range_do_action (AtkAction *action, - gint i) -{ - GailRange *range; - GtkWidget *widget; - gboolean return_value = TRUE; - - range = GAIL_RANGE (action); - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action)); - if (widget == NULL) - /* - * State is defunct - */ - return FALSE; - if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget)) - return FALSE; - if(i==0) - { - if (range->action_idle_handler) - return_value = FALSE; - else - range->action_idle_handler = gdk_threads_add_idle (idle_do_action, range); - } - else - return_value = FALSE; - return return_value; -} - -static gboolean -idle_do_action (gpointer data) -{ - GailRange *range; - GtkWidget *widget; - - range = GAIL_RANGE (data); - range->action_idle_handler = 0; - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range)); - if (widget == NULL /* State is defunct */ || - !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget)) - return FALSE; - - gtk_widget_activate (widget); - - return FALSE; -} - -static gint -gail_range_get_n_actions (AtkAction *action) -{ - return 1; -} - -static const gchar* -gail_range_get_keybinding (AtkAction *action, - gint i) -{ - GailRange *range; - gchar *return_value = NULL; - range = GAIL_RANGE (action); - if(i==0) - { - GtkWidget *widget; - GtkWidget *label; - AtkRelationSet *set; - AtkRelation *relation; - GPtrArray *target; - gpointer target_object; - guint key_val; - - range = GAIL_RANGE (action); - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range)); - if (widget == NULL) - return NULL; - set = atk_object_ref_relation_set (ATK_OBJECT (action)); - - if (!set) - return NULL; - label = NULL; - relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY); - if (relation) - { - target = atk_relation_get_target (relation); - target_object = g_ptr_array_index (target, 0); - label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object)); - } - g_object_unref (set); - if (GTK_IS_LABEL (label)) - { - key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); - if (key_val != GDK_KEY_VoidSymbol) - return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK); - } - g_free (range->activate_keybinding); - range->activate_keybinding = return_value; - } - return return_value; -} - -static const gchar* -gail_range_action_get_name (AtkAction *action, - gint i) -{ - const gchar *return_value; - - if (i==0) - return_value = "activate"; - else - return_value = NULL; - - return return_value; -} - diff --git a/gtk/a11y/gailrange.h b/gtk/a11y/gailrange.h deleted file mode 100644 index 818d76c6ed..0000000000 --- a/gtk/a11y/gailrange.h +++ /dev/null @@ -1,56 +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_RANGE_H__ -#define __GAIL_RANGE_H__ - -#include "gailwidget.h" - -G_BEGIN_DECLS - -#define GAIL_TYPE_RANGE (gail_range_get_type ()) -#define GAIL_RANGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_RANGE, GailRange)) -#define GAIL_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_RANGE, GailRangeClass)) -#define GAIL_IS_RANGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_RANGE)) -#define GAIL_IS_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_RANGE)) -#define GAIL_RANGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_RANGE, GailRangeClass)) - -typedef struct _GailRange GailRange; -typedef struct _GailRangeClass GailRangeClass; - -struct _GailRange -{ - GailWidget parent; - - AtkObject *adjustment; - gchar *activate_keybinding; - guint action_idle_handler; - -}; - -GType gail_range_get_type (void); - -struct _GailRangeClass -{ - GailWidgetClass parent_class; -}; - -G_END_DECLS - -#endif /* __GAIL_RANGE_H__ */ diff --git a/gtk/a11y/gtkrangeaccessible.c b/gtk/a11y/gtkrangeaccessible.c new file mode 100644 index 0000000000..24477fbfdd --- /dev/null +++ b/gtk/a11y/gtkrangeaccessible.c @@ -0,0 +1,365 @@ +/* GAIL - The GNOME Accessibility Implementation Library + * Copyright 2001, 2002, 2003 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 +#include +#include "gtkrangeaccessible.h" +#include "gailadjustment.h" + + +static void atk_action_interface_init (AtkActionIface *iface); +static void atk_value_interface_init (AtkValueIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkRangeAccessible, gtk_range_accessible, GAIL_TYPE_WIDGET, + G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init) + G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init)) + +static void +gtk_range_accessible_value_changed (GtkAdjustment *adjustment, + gpointer data) +{ + g_object_notify (G_OBJECT (data), "accessible-value"); +} + +static void +gtk_range_accessible_initialize (AtkObject *obj, + gpointer data) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj); + GtkAdjustment *adj; + GtkRange *gtk_range; + + ATK_OBJECT_CLASS (gtk_range_accessible_parent_class)->initialize (obj, data); + + gtk_range = GTK_RANGE (data); + /* + * If a GtkAdjustment already exists for the GtkRange, + * create the GailAdjustment + */ + adj = gtk_range_get_adjustment (gtk_range); + if (adj) + { + range->adjustment = gail_adjustment_new (adj); + g_signal_connect (adj, + "value-changed", + G_CALLBACK (gtk_range_accessible_value_changed), + range); + } + else + range->adjustment = NULL; + + obj->role = ATK_ROLE_SLIDER; +} + +static void +gtk_range_accessible_finalize (GObject *object) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (object); + + if (range->adjustment) + { + /* The GtkAdjustment may live on so we need to disconnect + * the signal handler + */ + if (GAIL_ADJUSTMENT (range->adjustment)->adjustment) + g_signal_handlers_disconnect_by_func (GAIL_ADJUSTMENT (range->adjustment)->adjustment, + (void *)gtk_range_accessible_value_changed, + range); + + g_object_unref (range->adjustment); + range->adjustment = NULL; + } + + if (range->action_idle_handler) + { + g_source_remove (range->action_idle_handler); + range->action_idle_handler = 0; + } + + G_OBJECT_CLASS (gtk_range_accessible_parent_class)->finalize (object); +} + +static void +gtk_range_accessible_notify_gtk (GObject *obj, + GParamSpec *pspec) +{ + GtkAdjustment *adj; + GtkWidget *widget = GTK_WIDGET (obj); + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (gtk_widget_get_accessible (widget)); + + if (strcmp (pspec->name, "adjustment") == 0) + { + /* Get rid of the GailAdjustment for the GtkAdjustment + * which was associated with the range. + */ + if (range->adjustment) + { + g_object_unref (range->adjustment); + range->adjustment = NULL; + } + + /* Create the GailAdjustment when notify for "adjustment" property + * is received + */ + adj = gtk_range_get_adjustment (GTK_RANGE (widget)); + range->adjustment = gail_adjustment_new (adj); + g_signal_connect (adj, + "value-changed", + G_CALLBACK (gtk_range_accessible_value_changed), + range); + } + else + GAIL_WIDGET_CLASS (gtk_range_accessible_parent_class)->notify_gtk (obj, pspec); +} + + +static void +gtk_range_accessible_class_init (GtkRangeAccessibleClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + GailWidgetClass *widget_class = (GailWidgetClass*)klass; + + widget_class->notify_gtk = gtk_range_accessible_notify_gtk; + + class->initialize = gtk_range_accessible_initialize; + + gobject_class->finalize = gtk_range_accessible_finalize; +} + +static void +gtk_range_accessible_init (GtkRangeAccessible *range) +{ +} + +static void +gtk_range_accessible_get_current_value (AtkValue *obj, + GValue *value) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj); + + if (range->adjustment == NULL) + return; + + atk_value_get_current_value (ATK_VALUE (range->adjustment), value); +} + +static void +gtk_range_accessible_get_maximum_value (AtkValue *obj, + GValue *value) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj); + GtkRange *gtk_range; + GtkAdjustment *gtk_adjustment; + gdouble max = 0; + + if (range->adjustment == NULL) + return; + + atk_value_get_maximum_value (ATK_VALUE (range->adjustment), value); + + gtk_range = GTK_RANGE (gtk_accessible_get_widget (GTK_ACCESSIBLE (range))); + + gtk_adjustment = gtk_range_get_adjustment (gtk_range); + max = g_value_get_double (value); + max -= gtk_adjustment_get_page_size (gtk_adjustment); + + if (gtk_range_get_restrict_to_fill_level (gtk_range)) + max = MIN (max, gtk_range_get_fill_level (gtk_range)); + + g_value_set_double (value, max); +} + +static void +gtk_range_accessible_get_minimum_value (AtkValue *obj, + GValue *value) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj); + + if (range->adjustment == NULL) + return; + + atk_value_get_minimum_value (ATK_VALUE (range->adjustment), value); +} + +static void +gtk_range_accessible_get_minimum_increment (AtkValue *obj, + GValue *value) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj); + + if (range->adjustment == NULL) + return; + + atk_value_get_minimum_increment (ATK_VALUE (range->adjustment), value); +} + +static gboolean +gtk_range_accessible_set_current_value (AtkValue *obj, + const GValue *value) +{ + GtkWidget *widget; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); + if (widget == NULL) + return FALSE; + + if (G_VALUE_HOLDS_DOUBLE (value)) + { + GtkRange *range = GTK_RANGE (widget); + gdouble new_value; + + new_value = g_value_get_double (value); + gtk_range_set_value (range, new_value); + + return TRUE; + } + else + { + return FALSE; + } +} + +static void +atk_value_interface_init (AtkValueIface *iface) +{ + iface->get_current_value = gtk_range_accessible_get_current_value; + iface->get_maximum_value = gtk_range_accessible_get_maximum_value; + iface->get_minimum_value = gtk_range_accessible_get_minimum_value; + iface->get_minimum_increment = gtk_range_accessible_get_minimum_increment; + iface->set_current_value = gtk_range_accessible_set_current_value; +} + +static gboolean +idle_do_action (gpointer data) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (data); + GtkWidget *widget; + + range->action_idle_handler = 0; + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range)); + if (widget == NULL) + return FALSE; + + if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget)) + return FALSE; + + gtk_widget_activate (widget); + + return TRUE; +} + +static gboolean +gtk_range_accessible_do_action (AtkAction *action, + gint i) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (action); + GtkWidget *widget; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action)); + if (widget == NULL) + return FALSE; + + if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget)) + return FALSE; + + if (i != 0) + return FALSE; + + if (range->action_idle_handler) + return FALSE; + + range->action_idle_handler = gdk_threads_add_idle (idle_do_action, range); + + return TRUE; +} + +static gint +gtk_range_accessible_get_n_actions (AtkAction *action) +{ + return 1; +} + +static const gchar * +gtk_range_accessible_get_keybinding (AtkAction *action, + gint i) +{ + GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (action); + GtkWidget *widget; + GtkWidget *label; + AtkRelationSet *set; + AtkRelation *relation; + GPtrArray *target; + gpointer target_object; + guint key_val; + gchar *return_value = NULL; + + if (i != 0) + return NULL; + + widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range)); + if (widget == NULL) + return NULL; + + set = atk_object_ref_relation_set (ATK_OBJECT (action)); + + if (!set) + return NULL; + + label = NULL; + relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY); + if (relation) + { + target = atk_relation_get_target (relation); + target_object = g_ptr_array_index (target, 0); + label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object)); + } + g_object_unref (set); + + if (GTK_IS_LABEL (label)) + { + key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); + if (key_val != GDK_KEY_VoidSymbol) + return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK); + } + + return return_value; +} + +static const gchar * +gtk_range_accessible_action_get_name (AtkAction *action, + gint i) +{ + if (i != 0) + return NULL; + + return "activate"; +} + +static void +atk_action_interface_init (AtkActionIface *iface) +{ + iface->do_action = gtk_range_accessible_do_action; + iface->get_n_actions = gtk_range_accessible_get_n_actions; + iface->get_keybinding = gtk_range_accessible_get_keybinding; + iface->get_name = gtk_range_accessible_action_get_name; +} diff --git a/gtk/a11y/gtkrangeaccessible.h b/gtk/a11y/gtkrangeaccessible.h new file mode 100644 index 0000000000..80dd277006 --- /dev/null +++ b/gtk/a11y/gtkrangeaccessible.h @@ -0,0 +1,54 @@ +/* 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_RANGE_ACCESSIBLE_H__ +#define __GTK_RANGE_ACCESSIBLE_H__ + +#include "gailwidget.h" + +G_BEGIN_DECLS + +#define GTK_TYPE_RANGE_ACCESSIBLE (gtk_range_accessible_get_type ()) +#define GTK_RANGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessible)) +#define GTK_RANGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessibleClass)) +#define GTK_IS_RANGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RANGE_ACCESSIBLE)) +#define GTK_IS_RANGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RANGE_ACCESSIBLE)) +#define GTK_RANGE_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessibleClass)) + +typedef struct _GtkRangeAccessible GtkRangeAccessible; +typedef struct _GtkRangeAccessibleClass GtkRangeAccessibleClass; + +struct _GtkRangeAccessible +{ + GailWidget parent; + + AtkObject *adjustment; + guint action_idle_handler; +}; + +struct _GtkRangeAccessibleClass +{ + GailWidgetClass parent_class; +}; + +GType gtk_range_accessible_get_type (void); + +G_END_DECLS + +#endif /* __GTK_RANGE_ACCESSIBLE_H__ */ diff --git a/gtk/a11y/gtkscaleaccessible.c b/gtk/a11y/gtkscaleaccessible.c index 7e3de32da3..46dbd449da 100644 --- a/gtk/a11y/gtkscaleaccessible.c +++ b/gtk/a11y/gtkscaleaccessible.c @@ -22,7 +22,7 @@ #include #include "gtkscaleaccessible.h" -G_DEFINE_TYPE (GtkScaleAccessible, gtk_scale_accessible, GAIL_TYPE_RANGE) +G_DEFINE_TYPE (GtkScaleAccessible, gtk_scale_accessible, GTK_TYPE_RANGE_ACCESSIBLE) static const gchar * gtk_scale_accessible_get_description (AtkObject *object) diff --git a/gtk/a11y/gtkscaleaccessible.h b/gtk/a11y/gtkscaleaccessible.h index 648130b77e..a677cd6591 100644 --- a/gtk/a11y/gtkscaleaccessible.h +++ b/gtk/a11y/gtkscaleaccessible.h @@ -20,8 +20,7 @@ #ifndef __GTK_SCALE_ACCESSIBLE_H__ #define __GTK_SCALE_ACCESSIBLE_H__ -#include "gailrange.h" -#include "gailtextutil.h" +#include "gtkrangeaccessible.h" G_BEGIN_DECLS @@ -37,12 +36,12 @@ typedef struct _GtkScaleAccessibleClass GtkScaleAccessibleClass; struct _GtkScaleAccessible { - GailRange parent; + GtkRangeAccessible parent; }; struct _GtkScaleAccessibleClass { - GailRangeClass parent_class; + GtkRangeAccessibleClass parent_class; }; GType gtk_scale_accessible_get_type (void); diff --git a/gtk/a11y/gtkscrollbaraccessible.c b/gtk/a11y/gtkscrollbaraccessible.c index 9193cd4e5f..d6bb541018 100644 --- a/gtk/a11y/gtkscrollbaraccessible.c +++ b/gtk/a11y/gtkscrollbaraccessible.c @@ -23,7 +23,7 @@ #include "gtkscrollbaraccessible.h" -G_DEFINE_TYPE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GAIL_TYPE_RANGE) +G_DEFINE_TYPE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GTK_TYPE_RANGE_ACCESSIBLE) static void gtk_scrollbar_accessible_init (GtkScrollbarAccessible *accessible) diff --git a/gtk/a11y/gtkscrollbaraccessible.h b/gtk/a11y/gtkscrollbaraccessible.h index a5936525f5..afbe80730c 100644 --- a/gtk/a11y/gtkscrollbaraccessible.h +++ b/gtk/a11y/gtkscrollbaraccessible.h @@ -20,7 +20,7 @@ #ifndef __GTK_SCROLLBAR_ACCESSIBLE_H__ #define __GTK_SCROLLBAR_ACCESSIBLE_H__ -#include "gailrange.h" +#include "gtkrangeaccessible.h" G_BEGIN_DECLS @@ -36,12 +36,12 @@ typedef struct _GtkScrollbarAccessibleClass GtkScrollbarAccessibleClass; struct _GtkScrollbarAccessible { - GailRange parent; + GtkRangeAccessible parent; }; struct _GtkScrollbarAccessibleClass { - GailRangeClass parent_class; + GtkRangeAccessibleClass parent_class; }; GType gtk_scrollbar_accessible_get_type (void); diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index 94239e7b92..2e4331610d 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -40,6 +40,7 @@ #include "gtkprivate.h" #include "gtkintl.h" #include "gtktypebuiltins.h" +#include "a11y/gtkrangeaccessible.h" /** * SECTION:gtkrange @@ -600,6 +601,8 @@ gtk_range_class_init (GtkRangeClass *class) GTK_PARAM_READABLE)); g_type_class_add_private (class, sizeof (GtkRangePrivate)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_RANGE_ACCESSIBLE); } static void -- cgit v1.2.1