1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #undef GTK_DISABLE_DEPRECATED
27 #include <gdk/gdkkeysyms.h>
29 #include "gailoptionmenu.h"
31 static void gail_option_menu_class_init (GailOptionMenuClass *klass);
32 static void gail_option_menu_init (GailOptionMenu *menu);
33 static void gail_option_menu_real_initialize (AtkObject *obj,
36 static gint gail_option_menu_get_n_children (AtkObject *obj);
37 static AtkObject* gail_option_menu_ref_child (AtkObject *obj,
39 static gint gail_option_menu_real_add_gtk (GtkContainer *container,
42 static gint gail_option_menu_real_remove_gtk (GtkContainer *container,
47 static void atk_action_interface_init (AtkActionIface *iface);
49 static gboolean gail_option_menu_do_action (AtkAction *action,
51 static gboolean idle_do_action (gpointer data);
52 static gint gail_option_menu_get_n_actions (AtkAction *action);
53 static G_CONST_RETURN gchar* gail_option_menu_get_description (AtkAction *action,
55 static G_CONST_RETURN gchar* gail_option_menu_action_get_name (AtkAction *action,
57 static gboolean gail_option_menu_set_description (AtkAction *action,
60 static void gail_option_menu_changed (GtkOptionMenu *option_menu);
62 G_DEFINE_TYPE_WITH_CODE (GailOptionMenu, gail_option_menu, GAIL_TYPE_BUTTON,
63 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
66 gail_option_menu_class_init (GailOptionMenuClass *klass)
68 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
69 GailContainerClass *container_class;
71 container_class = (GailContainerClass *) klass;
73 class->get_n_children = gail_option_menu_get_n_children;
74 class->ref_child = gail_option_menu_ref_child;
75 class->initialize = gail_option_menu_real_initialize;
77 container_class->add_gtk = gail_option_menu_real_add_gtk;
78 container_class->remove_gtk = gail_option_menu_real_remove_gtk;
82 gail_option_menu_init (GailOptionMenu *menu)
87 gail_option_menu_real_initialize (AtkObject *obj,
90 GtkOptionMenu *option_menu;
92 ATK_OBJECT_CLASS (gail_option_menu_parent_class)->initialize (obj, data);
94 option_menu = GTK_OPTION_MENU (data);
96 g_signal_connect (option_menu, "changed",
97 G_CALLBACK (gail_option_menu_changed), NULL);
99 obj->role = ATK_ROLE_COMBO_BOX;
103 gail_option_menu_get_n_children (AtkObject *obj)
106 GtkOptionMenu *option_menu;
109 g_return_val_if_fail (GAIL_IS_OPTION_MENU (obj), 0);
111 widget = GTK_ACCESSIBLE (obj)->widget;
118 option_menu = GTK_OPTION_MENU (widget);
119 if (gtk_option_menu_get_menu (option_menu))
126 gail_option_menu_ref_child (AtkObject *obj,
130 AtkObject *accessible;
132 g_return_val_if_fail (GAIL_IS_OPTION_MENU (obj), NULL);
134 widget = GTK_ACCESSIBLE (obj)->widget;
143 accessible = g_object_ref (gtk_widget_get_accessible (gtk_option_menu_get_menu (GTK_OPTION_MENU (widget))));
151 gail_option_menu_real_add_gtk (GtkContainer *container,
155 AtkObject* atk_parent = ATK_OBJECT (data);
156 AtkObject* atk_child = gtk_widget_get_accessible (widget);
158 GAIL_CONTAINER_CLASS (gail_option_menu_parent_class)->add_gtk (container, widget, data);
160 g_object_notify (G_OBJECT (atk_child), "accessible_parent");
162 g_signal_emit_by_name (atk_parent, "children_changed::add",
169 gail_option_menu_real_remove_gtk (GtkContainer *container,
173 AtkPropertyValues values = { NULL };
174 AtkObject* atk_parent = ATK_OBJECT (data);
175 AtkObject *atk_child = gtk_widget_get_accessible (widget);
177 g_value_init (&values.old_value, G_TYPE_POINTER);
178 g_value_set_pointer (&values.old_value, atk_parent);
180 values.property_name = "accessible-parent";
181 g_signal_emit_by_name (atk_child,
182 "property_change::accessible-parent", &values, NULL);
183 g_signal_emit_by_name (atk_parent, "children_changed::remove",
190 atk_action_interface_init (AtkActionIface *iface)
192 iface->do_action = gail_option_menu_do_action;
193 iface->get_n_actions = gail_option_menu_get_n_actions;
194 iface->get_description = gail_option_menu_get_description;
195 iface->get_name = gail_option_menu_action_get_name;
196 iface->set_description = gail_option_menu_set_description;
200 gail_option_menu_do_action (AtkAction *action,
205 gboolean return_value = TRUE;
207 button = GAIL_BUTTON (action);
208 widget = GTK_ACCESSIBLE (action)->widget;
215 if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
221 if (button->action_idle_handler)
222 return_value = FALSE;
224 button->action_idle_handler = gdk_threads_add_idle (idle_do_action, button);
227 return_value = FALSE;
234 idle_do_action (gpointer data)
239 GailButton *gail_button;
241 gail_button = GAIL_BUTTON (data);
242 gail_button->action_idle_handler = 0;
244 widget = GTK_ACCESSIBLE (gail_button)->widget;
245 if (widget == NULL /* State is defunct */ ||
246 !gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
249 button = GTK_BUTTON (widget);
251 button->in_button = TRUE;
252 g_signal_emit_by_name (button, "enter");
254 * Simulate a button press event. calling gtk_button_pressed() does
255 * not get the job done for a GtkOptionMenu.
257 tmp_event.button.type = GDK_BUTTON_PRESS;
258 tmp_event.button.window = widget->window;
259 tmp_event.button.button = 1;
260 tmp_event.button.send_event = TRUE;
261 tmp_event.button.time = GDK_CURRENT_TIME;
262 tmp_event.button.axes = NULL;
264 gtk_widget_event (widget, &tmp_event);
270 gail_option_menu_get_n_actions (AtkAction *action)
275 static G_CONST_RETURN gchar*
276 gail_option_menu_get_description (AtkAction *action,
280 G_CONST_RETURN gchar *return_value;
282 button = GAIL_BUTTON (action);
287 return_value = button->press_description;
296 static G_CONST_RETURN gchar*
297 gail_option_menu_action_get_name (AtkAction *action,
300 G_CONST_RETURN gchar *return_value;
306 * This action simulates a button press by simulating moving the
307 * mouse into the button followed by pressing the left mouse button.
309 return_value = "press";
319 gail_option_menu_set_description (AtkAction *action,
326 button = GAIL_BUTTON (action);
331 value = &button->press_description;
341 *value = g_strdup (desc);
349 gail_option_menu_changed (GtkOptionMenu *option_menu)
351 GailOptionMenu *gail_option_menu;
353 gail_option_menu = GAIL_OPTION_MENU (gtk_widget_get_accessible (GTK_WIDGET (option_menu)));
354 g_object_notify (G_OBJECT (gail_option_menu), "accessible-name");