1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
/* GTK+ - accessibility implementations
* Copyright 2001, 2002, 2003 Sun Microsystems Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkwindow.h>
#include "gtktoplevelaccessible.h"
struct _GtkToplevelAccessiblePrivate
{
GList *window_list;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkToplevelAccessible, gtk_toplevel_accessible, ATK_TYPE_OBJECT)
static void
gtk_toplevel_accessible_initialize (AtkObject *accessible,
gpointer data)
{
ATK_OBJECT_CLASS (gtk_toplevel_accessible_parent_class)->initialize (accessible, data);
accessible->role = ATK_ROLE_APPLICATION;
accessible->accessible_parent = NULL;
}
static void
gtk_toplevel_accessible_object_finalize (GObject *obj)
{
GtkToplevelAccessible *toplevel = GTK_TOPLEVEL_ACCESSIBLE (obj);
if (toplevel->priv->window_list)
g_list_free (toplevel->priv->window_list);
G_OBJECT_CLASS (gtk_toplevel_accessible_parent_class)->finalize (obj);
}
static int
gtk_toplevel_accessible_get_n_children (AtkObject *obj)
{
GtkToplevelAccessible *toplevel = GTK_TOPLEVEL_ACCESSIBLE (obj);
return g_list_length (toplevel->priv->window_list);
}
static AtkObject *
gtk_toplevel_accessible_ref_child (AtkObject *obj,
int i)
{
GtkToplevelAccessible *toplevel;
GtkWidget *widget;
AtkObject *atk_obj;
toplevel = GTK_TOPLEVEL_ACCESSIBLE (obj);
widget = g_list_nth_data (toplevel->priv->window_list, i);
if (!widget)
return NULL;
atk_obj = gtk_widget_get_accessible (widget);
g_object_ref (atk_obj);
return atk_obj;
}
static const char *
gtk_toplevel_accessible_get_name (AtkObject *obj)
{
return g_get_prgname ();
}
static void
gtk_toplevel_accessible_class_init (GtkToplevelAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
class->initialize = gtk_toplevel_accessible_initialize;
class->get_n_children = gtk_toplevel_accessible_get_n_children;
class->ref_child = gtk_toplevel_accessible_ref_child;
class->get_parent = NULL;
class->get_name = gtk_toplevel_accessible_get_name;
g_object_class->finalize = gtk_toplevel_accessible_object_finalize;
}
static void
remove_child (GtkToplevelAccessible *toplevel,
GtkWindow *window)
{
AtkObject *atk_obj = ATK_OBJECT (toplevel);
GList *l;
guint window_count = 0;
AtkObject *child;
if (toplevel->priv->window_list)
{
GtkWindow *tmp_window;
for (l = toplevel->priv->window_list; l; l = l->next)
{
tmp_window = GTK_WINDOW (l->data);
if (window == tmp_window)
{
/* Remove the window from the window_list & emit the signal */
toplevel->priv->window_list = g_list_delete_link (toplevel->priv->window_list, l);
child = gtk_widget_get_accessible (GTK_WIDGET (window));
g_signal_emit_by_name (atk_obj, "children-changed::remove",
window_count, child, NULL);
atk_object_set_parent (child, NULL);
break;
}
window_count++;
}
}
}
static gboolean
show_event_watcher (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
GtkToplevelAccessible *toplevel = GTK_TOPLEVEL_ACCESSIBLE (data);
AtkObject *atk_obj = ATK_OBJECT (toplevel);
GObject *object;
GtkWidget *widget;
int n_children;
AtkObject *child;
object = g_value_get_object (param_values + 0);
if (!GTK_IS_WINDOW (object))
return TRUE;
widget = GTK_WIDGET (object);
if (gtk_widget_get_parent (widget))
return TRUE;
child = gtk_widget_get_accessible (widget);
if (atk_object_get_role (child) == ATK_ROLE_REDUNDANT_OBJECT ||
atk_object_get_role (child) == ATK_ROLE_TOOL_TIP)
return TRUE;
/* Add the window to the list & emit the signal */
toplevel->priv->window_list = g_list_append (toplevel->priv->window_list, widget);
n_children = g_list_length (toplevel->priv->window_list);
atk_object_set_parent (child, atk_obj);
g_signal_emit_by_name (atk_obj, "children-changed::add",
n_children - 1, child, NULL);
g_signal_connect_swapped (G_OBJECT(object), "destroy",
G_CALLBACK (remove_child), toplevel);
return TRUE;
}
static gboolean
hide_event_watcher (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
GtkToplevelAccessible *toplevel = GTK_TOPLEVEL_ACCESSIBLE (data);
GObject *object;
object = g_value_get_object (param_values + 0);
if (!GTK_IS_WINDOW (object))
return TRUE;
remove_child (toplevel, GTK_WINDOW (object));
return TRUE;
}
static void
gtk_toplevel_accessible_init (GtkToplevelAccessible *toplevel)
{
GtkWindow *window;
GtkWidget *widget;
GList *l;
guint signal_id;
toplevel->priv = gtk_toplevel_accessible_get_instance_private (toplevel);
l = toplevel->priv->window_list = gtk_window_list_toplevels ();
while (l)
{
window = GTK_WINDOW (l->data);
widget = GTK_WIDGET (window);
if (!window ||
!gtk_widget_get_visible (widget) ||
gtk_widget_get_parent (GTK_WIDGET (window)))
{
GList *temp_l = l->next;
toplevel->priv->window_list = g_list_delete_link (toplevel->priv->window_list, l);
l = temp_l;
}
else
{
g_signal_connect_swapped (G_OBJECT (window), "destroy",
G_CALLBACK (remove_child), toplevel);
l = l->next;
}
}
g_type_class_ref (GTK_TYPE_WINDOW);
signal_id = g_signal_lookup ("show", GTK_TYPE_WINDOW);
g_signal_add_emission_hook (signal_id, 0,
show_event_watcher, toplevel, (GDestroyNotify) NULL);
signal_id = g_signal_lookup ("hide", GTK_TYPE_WINDOW);
g_signal_add_emission_hook (signal_id, 0,
hide_event_watcher, toplevel, (GDestroyNotify) NULL);
}
/**
* gtk_toplevel_accessible_get_children:
*
* Returns: (transfer none) (element-type Gtk.Window): List of
* children.
*/
GList *
gtk_toplevel_accessible_get_children (GtkToplevelAccessible *accessible)
{
return accessible->priv->window_list;
}
|