]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkstatusbaraccessible.c
Convert GailExpander to GtkExpanderAccessible
[~andy/gtk] / gtk / a11y / gtkstatusbaraccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001, 2002, 2003 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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <gtk/gtk.h>
24 #include "gtkstatusbaraccessible.h"
25
26
27 G_DEFINE_TYPE (GtkStatusbarAccessible, gtk_statusbar_accessible, GTK_TYPE_BOX_ACCESSIBLE)
28
29 static void
30 text_changed (GtkStatusbar *statusbar,
31               guint         context_id,
32               const gchar  *text,
33               AtkObject    *obj)
34 {
35   if (!obj->name)
36     g_object_notify (G_OBJECT (obj), "accessible-name");
37   g_signal_emit_by_name (obj, "visible-data-changed");
38 }
39
40 static void
41 gtk_statusbar_accessible_initialize (AtkObject *obj,
42                                      gpointer   data)
43 {
44   GtkWidget *statusbar = data;
45
46   ATK_OBJECT_CLASS (gtk_statusbar_accessible_parent_class)->initialize (obj, data);
47
48   g_signal_connect_after (statusbar, "text-pushed",
49                           G_CALLBACK (text_changed), obj);
50   g_signal_connect_after (statusbar, "text-popped",
51                           G_CALLBACK (text_changed), obj);
52
53   obj->role = ATK_ROLE_STATUSBAR;
54 }
55
56 static GtkWidget *
57 find_label_child (GtkContainer *container)
58 {
59   GList *children, *tmp_list;
60   GtkWidget *child;
61
62   children = gtk_container_get_children (container);
63
64   child = NULL;
65   for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
66     {
67       if (GTK_IS_LABEL (tmp_list->data))
68         {
69           child = GTK_WIDGET (tmp_list->data);
70           break;
71         }
72       else if (GTK_IS_CONTAINER (tmp_list->data))
73         {
74           child = find_label_child (GTK_CONTAINER (tmp_list->data));
75           if (child)
76             break;
77         }
78     }
79   g_list_free (children);
80
81   return child;
82 }
83
84 static GtkWidget *
85 get_label_from_statusbar (GtkStatusbar *statusbar)
86 {
87   GtkWidget *box;
88
89   box = gtk_statusbar_get_message_area (statusbar);
90
91   return find_label_child (GTK_CONTAINER (box));
92 }
93
94 static const gchar *
95 gtk_statusbar_accessible_get_name (AtkObject *obj)
96 {
97   const gchar *name;
98   GtkWidget *widget;
99   GtkWidget *label;
100
101   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
102   if (widget == NULL)
103     return NULL;
104
105   name = ATK_OBJECT_CLASS (gtk_statusbar_accessible_parent_class)->get_name (obj);
106   if (name != NULL)
107     return name;
108
109   label = get_label_from_statusbar (GTK_STATUSBAR (widget));
110   if (GTK_IS_LABEL (label))
111     return gtk_label_get_label (GTK_LABEL (label));
112
113   return NULL;
114 }
115
116 static gint
117 gtk_statusbar_accessible_get_n_children (AtkObject *obj)
118 {
119   return 0;
120 }
121
122 static AtkObject*
123 gtk_statusbar_accessible_ref_child (AtkObject *obj,
124                                     gint       i)
125 {
126   return NULL;
127 }
128
129 static void
130 gtk_statusbar_accessible_class_init (GtkStatusbarAccessibleClass *klass)
131 {
132   AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
133   GailContainerClass *container_class = (GailContainerClass*)klass;
134
135   class->get_name = gtk_statusbar_accessible_get_name;
136   class->get_n_children = gtk_statusbar_accessible_get_n_children;
137   class->ref_child = gtk_statusbar_accessible_ref_child;
138   class->initialize = gtk_statusbar_accessible_initialize;
139   /*
140    * As we report the statusbar as having no children
141    * we are not interested in add and remove signals
142    */
143   container_class->add_gtk = NULL;
144   container_class->remove_gtk = NULL;
145 }
146
147 static void
148 gtk_statusbar_accessible_init (GtkStatusbarAccessible *bar)
149 {
150 }