| 1 |
/* GTK+ - accessibility implementations |
| 2 |
* Copyright 2001 Sun Microsystems Inc. |
| 3 |
* |
| 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. |
| 8 |
* |
| 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. |
| 13 |
* |
| 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/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <gtk/gtk.h> |
| 21 |
#include <glib/gi18n-lib.h> |
| 22 |
#include "gtkmenubuttonaccessible.h" |
| 23 |
|
| 24 |
|
| 25 |
G_DEFINE_TYPE (GtkMenuButtonAccessible, gtk_menu_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE) |
| 26 |
|
| 27 |
static void |
| 28 |
gtk_menu_button_accessible_initialize (AtkObject *accessible, |
| 29 |
gpointer data) |
| 30 |
{ |
| 31 |
ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->initialize (accessible, data); |
| 32 |
} |
| 33 |
|
| 34 |
static gint |
| 35 |
gtk_menu_button_accessible_get_n_children (AtkObject* obj) |
| 36 |
{ |
| 37 |
GtkWidget *widget; |
| 38 |
GtkWidget *submenu; |
| 39 |
gint count = 0; |
| 40 |
|
| 41 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 42 |
if (widget == NULL) |
| 43 |
return count; |
| 44 |
|
| 45 |
submenu = GTK_WIDGET (gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget))); |
| 46 |
if (submenu) |
| 47 |
{ |
| 48 |
GList *children; |
| 49 |
|
| 50 |
children = gtk_container_get_children (GTK_CONTAINER (submenu)); |
| 51 |
count = g_list_length (children); |
| 52 |
g_list_free (children); |
| 53 |
} |
| 54 |
return count; |
| 55 |
} |
| 56 |
|
| 57 |
static AtkObject * |
| 58 |
gtk_menu_button_accessible_ref_child (AtkObject *obj, |
| 59 |
gint i) |
| 60 |
{ |
| 61 |
AtkObject *accessible = NULL; |
| 62 |
GtkWidget *widget; |
| 63 |
GtkWidget *submenu; |
| 64 |
|
| 65 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 66 |
if (widget == NULL) |
| 67 |
return NULL; |
| 68 |
|
| 69 |
submenu = GTK_WIDGET (gtk_menu_button_get_popup (GTK_MENU_BUTTON (widget))); |
| 70 |
if (submenu) |
| 71 |
{ |
| 72 |
GList *children; |
| 73 |
GList *tmp_list; |
| 74 |
|
| 75 |
children = gtk_container_get_children (GTK_CONTAINER (submenu)); |
| 76 |
tmp_list = g_list_nth (children, i); |
| 77 |
if (tmp_list) |
| 78 |
{ |
| 79 |
accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data)); |
| 80 |
g_object_ref (accessible); |
| 81 |
} |
| 82 |
g_list_free (children); |
| 83 |
} |
| 84 |
|
| 85 |
return accessible; |
| 86 |
} |
| 87 |
|
| 88 |
static const gchar * |
| 89 |
gtk_menu_button_accessible_get_name (AtkObject *obj) |
| 90 |
{ |
| 91 |
const gchar *name = NULL; |
| 92 |
GtkWidget *widget; |
| 93 |
|
| 94 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 95 |
if (widget == NULL) |
| 96 |
return NULL; |
| 97 |
|
| 98 |
name = ATK_OBJECT_CLASS (gtk_menu_button_accessible_parent_class)->get_name (obj); |
| 99 |
if (name != NULL) |
| 100 |
return name; |
| 101 |
|
| 102 |
return _("Menu"); |
| 103 |
} |
| 104 |
|
| 105 |
static void |
| 106 |
gtk_menu_button_accessible_class_init (GtkMenuButtonAccessibleClass *klass) |
| 107 |
{ |
| 108 |
AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
| 109 |
|
| 110 |
class->get_name = gtk_menu_button_accessible_get_name; |
| 111 |
class->initialize = gtk_menu_button_accessible_initialize; |
| 112 |
class->get_n_children = gtk_menu_button_accessible_get_n_children; |
| 113 |
class->ref_child = gtk_menu_button_accessible_ref_child; |
| 114 |
} |
| 115 |
|
| 116 |
static void |
| 117 |
gtk_menu_button_accessible_init (GtkMenuButtonAccessible *menu_button) |
| 118 |
{ |
| 119 |
} |