1 /* GTK+ - accessibility implementations
2 * Copyright 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include <glib/gi18n-lib.h>
22 #include "gtkexpanderaccessible.h"
24 static void atk_action_interface_init (AtkActionIface *iface);
26 G_DEFINE_TYPE_WITH_CODE (GtkExpanderAccessible, gtk_expander_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
27 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
30 gtk_expander_accessible_get_full_text (GtkExpander *widget)
32 GtkWidget *label_widget;
34 label_widget = gtk_expander_get_label_widget (widget);
36 if (!GTK_IS_LABEL (label_widget))
39 return gtk_label_get_text (GTK_LABEL (label_widget));
43 gtk_expander_accessible_get_name (AtkObject *obj)
48 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
52 name = ATK_OBJECT_CLASS (gtk_expander_accessible_parent_class)->get_name (obj);
56 return gtk_expander_accessible_get_full_text (GTK_EXPANDER (widget));
60 gtk_expander_accessible_get_n_children (AtkObject *obj)
66 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
70 children = gtk_container_get_children (GTK_CONTAINER(widget));
71 count = g_list_length (children);
72 g_list_free (children);
74 /* See if there is a label - if there is, reduce our count by 1
75 * since we don't want the label included with the children.
77 if (gtk_expander_get_label_widget (GTK_EXPANDER (widget)))
84 gtk_expander_accessible_ref_child (AtkObject *obj,
87 GList *children, *tmp_list;
88 AtkObject *accessible;
93 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
97 children = gtk_container_get_children (GTK_CONTAINER (widget));
99 /* See if there is a label - if there is, we need to skip it
100 * since we don't want the label included with the children.
102 label = gtk_expander_get_label_widget (GTK_EXPANDER (widget));
105 for (index = 0; index <= i; index++)
107 tmp_list = g_list_nth (children, index);
108 if (label == GTK_WIDGET (tmp_list->data))
116 tmp_list = g_list_nth (children, i);
119 g_list_free (children);
122 accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
124 g_list_free (children);
125 g_object_ref (accessible);
130 gtk_expander_accessible_initialize (AtkObject *obj,
133 ATK_OBJECT_CLASS (gtk_expander_accessible_parent_class)->initialize (obj, data);
135 obj->role = ATK_ROLE_TOGGLE_BUTTON;
139 gtk_expander_accessible_notify_gtk (GObject *obj,
143 GtkExpander *expander;
145 expander = GTK_EXPANDER (obj);
146 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (expander));
148 if (g_strcmp0 (pspec->name, "label") == 0)
150 if (atk_obj->name == NULL)
151 g_object_notify (G_OBJECT (atk_obj), "accessible-name");
152 g_signal_emit_by_name (atk_obj, "visible-data-changed");
154 else if (g_strcmp0 (pspec->name, "expanded") == 0)
156 atk_object_notify_state_change (atk_obj, ATK_STATE_CHECKED,
157 gtk_expander_get_expanded (expander));
158 atk_object_notify_state_change (atk_obj, ATK_STATE_EXPANDED,
159 gtk_expander_get_expanded (expander));
160 g_signal_emit_by_name (atk_obj, "visible-data-changed");
163 GTK_WIDGET_ACCESSIBLE_CLASS (gtk_expander_accessible_parent_class)->notify_gtk (obj, pspec);
167 gtk_expander_accessible_ref_state_set (AtkObject *obj)
169 AtkStateSet *state_set;
171 GtkExpander *expander;
173 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
177 state_set = ATK_OBJECT_CLASS (gtk_expander_accessible_parent_class)->ref_state_set (obj);
179 expander = GTK_EXPANDER (widget);
181 atk_state_set_add_state (state_set, ATK_STATE_EXPANDABLE);
183 if (gtk_expander_get_expanded (expander))
185 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
186 atk_state_set_add_state (state_set, ATK_STATE_EXPANDED);
193 gtk_expander_accessible_class_init (GtkExpanderAccessibleClass *klass)
195 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
196 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
198 widget_class->notify_gtk = gtk_expander_accessible_notify_gtk;
200 class->get_name = gtk_expander_accessible_get_name;
201 class->get_n_children = gtk_expander_accessible_get_n_children;
202 class->ref_child = gtk_expander_accessible_ref_child;
203 class->ref_state_set = gtk_expander_accessible_ref_state_set;
205 class->initialize = gtk_expander_accessible_initialize;
209 gtk_expander_accessible_init (GtkExpanderAccessible *expander)
214 gtk_expander_accessible_do_action (AtkAction *action,
219 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
223 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
229 gtk_widget_activate (widget);
234 gtk_expander_accessible_get_n_actions (AtkAction *action)
240 gtk_expander_accessible_get_keybinding (AtkAction *action,
243 gchar *return_value = NULL;
247 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
254 label = gtk_expander_get_label_widget (GTK_EXPANDER (widget));
255 if (GTK_IS_LABEL (label))
259 key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
260 if (key_val != GDK_KEY_VoidSymbol)
261 return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
268 gtk_expander_accessible_action_get_name (AtkAction *action,
277 gtk_expander_accessible_action_get_localized_name (AtkAction *action,
281 return C_("Action name", "Activate");
286 gtk_expander_accessible_action_get_description (AtkAction *action,
290 return C_("Action description", "Activates the expander");
295 atk_action_interface_init (AtkActionIface *iface)
297 iface->do_action = gtk_expander_accessible_do_action;
298 iface->get_n_actions = gtk_expander_accessible_get_n_actions;
299 iface->get_keybinding = gtk_expander_accessible_get_keybinding;
300 iface->get_name = gtk_expander_accessible_action_get_name;
301 iface->get_localized_name = gtk_expander_accessible_action_get_localized_name;
302 iface->get_description = gtk_expander_accessible_action_get_description;