[gtk+] GtkSwitch: Add an AtkAction implementation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkSwitch: Add an AtkAction implementation
- Date: Fri, 18 Feb 2011 04:07:01 +0000 (UTC)
commit 6d3b8c2c6b44b9a5f17480c24b5af957c9a3ce3c
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Feb 17 23:06:33 2011 -0500
GtkSwitch: Add an AtkAction implementation
gtk/gtkswitch.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 122 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index 2f0b42e..a425d4d 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -598,7 +598,6 @@ static AtkObject *
gtk_switch_get_accessible (GtkWidget *widget)
{
static gboolean first_time = TRUE;
- AtkObject *acc;
if (G_UNLIKELY (first_time))
{
@@ -918,11 +917,21 @@ gtk_switch_activatable_interface_init (GtkActivatableIface *iface)
/* accessibility: object */
-/* dummy typedefs */
-typedef struct _GtkSwitchAccessible GtkSwitchAccessible;
-typedef struct _GtkSwitchAccessibleClass GtkSwitchAccessibleClass;
+typedef struct _GtkSwitchAccessible GtkSwitchAccessible;
+typedef struct _GtkSwitchAccessibleClass GtkSwitchAccessibleClass;
-ATK_DEFINE_TYPE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_SWITCH);
+struct _GtkSwitchAccessible
+{
+ GtkAccessible object;
+
+ gchar *description;
+ guint action_idle;
+};
+
+static void atk_action_interface_init (AtkActionIface *iface);
+
+ATK_DEFINE_TYPE_WITH_CODE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_SWITCH,
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
static AtkStateSet *
gtk_switch_accessible_ref_state_set (AtkObject *accessible)
@@ -943,6 +952,19 @@ gtk_switch_accessible_ref_state_set (AtkObject *accessible)
}
static void
+gtk_switch_accessible_finalize (GObject *obj)
+{
+ GtkSwitchAccessible *accessible = (GtkSwitchAccessible *)obj;
+
+ g_free (accessible->description);
+
+ if (accessible->action_idle)
+ g_source_remove (accessible->action_idle);
+
+ G_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->finalize (obj);
+}
+
+static void
_gtk_switch_accessible_initialize (AtkObject *accessible,
gpointer widget)
{
@@ -956,8 +978,11 @@ _gtk_switch_accessible_initialize (AtkObject *accessible,
static void
_gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ object_class->finalize = gtk_switch_accessible_finalize;
+
atk_class->initialize = _gtk_switch_accessible_initialize;
atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
}
@@ -965,6 +990,98 @@ _gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
static void
_gtk_switch_accessible_init (GtkSwitchAccessible *self)
{
+ self->description = NULL;
+ self->action_idle = 0;
+}
+
+/* accessibility: action interface */
+
+static gint
+gtk_switch_action_get_n_actions (AtkAction *action)
+{
+ return 1;
+}
+
+static const gchar *
+gtk_switch_action_get_name (AtkAction *action,
+ gint i)
+{
+ return "toggle";
+}
+
+static const gchar *
+gtk_switch_action_get_description (AtkAction *action,
+ gint i)
+{
+ GtkSwitchAccessible *accessible = (GtkSwitchAccessible*)action;
+
+ return accessible->description;
+}
+
+static gboolean
+gtk_switch_action_set_description (AtkAction *action,
+ gint i,
+ const gchar *description)
+{
+ GtkSwitchAccessible *accessible = (GtkSwitchAccessible*)action;
+
+ g_free (accessible->description);
+ accessible->description = g_strdup (description);
+
+ return TRUE;
+}
+
+static gboolean
+idle_do_action (gpointer data)
+{
+ GtkSwitchAccessible *accessible = data;
+ GtkWidget *widget;
+ GtkSwitch *sw;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (data));
+ sw = GTK_SWITCH (widget);
+
+ accessible->action_idle = 0;
+
+ if (widget == NULL ||
+ !gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
+ return FALSE;
+
+ gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+
+ return FALSE;
+}
+
+static gboolean
+gtk_switch_action_do_action (AtkAction *action,
+ gint i)
+{
+ GtkSwitchAccessible *accessible;
+ GtkWidget *widget;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
+ if (widget == NULL)
+ return FALSE;
+
+ if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
+ return FALSE;
+
+ accessible = (GtkSwitchAccessible *)action;
+
+ if (!accessible->action_idle)
+ accessible->action_idle = gdk_threads_add_idle (idle_do_action, accessible);
+
+ return TRUE;
+}
+
+static void
+atk_action_interface_init (AtkActionIface *iface)
+{
+ iface->do_action = gtk_switch_action_do_action;
+ iface->get_n_actions = gtk_switch_action_get_n_actions;
+ iface->get_name = gtk_switch_action_get_name;
+ iface->get_description = gtk_switch_action_get_description;
+ iface->set_description = gtk_switch_action_set_description;
}
/* accessibility: factory */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]