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