[gtk+/a11y] Convert GailRange to GtkRangeAccessible
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/a11y] Convert GailRange to GtkRangeAccessible
- Date: Tue, 28 Jun 2011 02:56:27 +0000 (UTC)
commit cd0a103f24bc4bf7a14ee0e26a1e98b4190fe8cf
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 27 22:39:43 2011 -0400
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(-)
---
diff --git a/gtk/a11y/Makefile.am b/gtk/a11y/Makefile.am
index a224898..80f1df1 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/gtkrangeaccessible.c b/gtk/a11y/gtkrangeaccessible.c
new file mode 100644
index 0000000..24477fb
--- /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 <string.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#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 0000000..80dd277
--- /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 7e3de32..46dbd44 100644
--- a/gtk/a11y/gtkscaleaccessible.c
+++ b/gtk/a11y/gtkscaleaccessible.c
@@ -22,7 +22,7 @@
#include <gtk/gtk.h>
#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 648130b..a677cd6 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 9193cd4..d6bb541 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 a593652..afbe807 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 94239e7..2e43316 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]