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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/* 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 <string.h>
#include <gtk/gtk.h>
#include "gtknotebookpageaccessible.h"
struct _GtkNotebookPageAccessiblePrivate
{
GtkAccessible *notebook;
GtkWidget *child;
};
static void atk_component_interface_init (AtkComponentIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkNotebookPageAccessible, gtk_notebook_page_accessible, ATK_TYPE_OBJECT,
G_ADD_PRIVATE (GtkNotebookPageAccessible)
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
static GtkWidget *
find_label_child (GtkContainer *container)
{
GList *children, *tmp_list;
GtkWidget *child;
children = gtk_container_get_children (container);
child = NULL;
for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
{
if (GTK_IS_LABEL (tmp_list->data))
{
child = GTK_WIDGET (tmp_list->data);
break;
}
else if (GTK_IS_CONTAINER (tmp_list->data))
{
child = find_label_child (GTK_CONTAINER (tmp_list->data));
if (child)
break;
}
}
g_list_free (children);
return child;
}
static GtkWidget *
get_label_from_notebook_page (GtkNotebookPageAccessible *page)
{
GtkWidget *child;
GtkNotebook *notebook;
notebook = GTK_NOTEBOOK (gtk_accessible_get_widget (page->priv->notebook));
if (!notebook)
return NULL;
if (!gtk_notebook_get_show_tabs (notebook))
return NULL;
child = gtk_notebook_get_tab_label (notebook, page->priv->child);
if (GTK_IS_LABEL (child))
return child;
if (GTK_IS_CONTAINER (child))
child = find_label_child (GTK_CONTAINER (child));
return child;
}
static const gchar *
gtk_notebook_page_accessible_get_name (AtkObject *accessible)
{
GtkWidget *label;
if (accessible->name != NULL)
return accessible->name;
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible));
if (GTK_IS_LABEL (label))
return gtk_label_get_text (GTK_LABEL (label));
return NULL;
}
static AtkObject *
gtk_notebook_page_accessible_get_parent (AtkObject *accessible)
{
GtkNotebookPageAccessible *page;
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
return ATK_OBJECT (page->priv->notebook);
}
static gint
gtk_notebook_page_accessible_get_n_children (AtkObject *accessible)
{
return 1;
}
static AtkObject *
gtk_notebook_page_accessible_ref_child (AtkObject *accessible,
gint i)
{
AtkObject *child_obj;
GtkNotebookPageAccessible *page = NULL;
if (i != 0)
return NULL;
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
if (!page->priv->child)
return NULL;
child_obj = gtk_widget_get_accessible (page->priv->child);
g_object_ref (child_obj);
return child_obj;
}
static AtkStateSet *
gtk_notebook_page_accessible_ref_state_set (AtkObject *accessible)
{
GtkNotebookPageAccessible *page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
AtkStateSet *state_set, *label_state_set, *merged_state_set;
AtkObject *atk_label;
GtkWidget *label;
AtkObject *selected;
state_set = ATK_OBJECT_CLASS (gtk_notebook_page_accessible_parent_class)->ref_state_set (accessible);
atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
selected = atk_selection_ref_selection (ATK_SELECTION (page->priv->notebook), 0);
if (selected)
{
if (selected == accessible)
atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
g_object_unref (selected);
}
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible));
if (label)
{
atk_label = gtk_widget_get_accessible (label);
label_state_set = atk_object_ref_state_set (atk_label);
merged_state_set = atk_state_set_or_sets (state_set, label_state_set);
g_object_unref (label_state_set);
g_object_unref (state_set);
}
else
{
AtkObject *child;
child = atk_object_ref_accessible_child (accessible, 0);
if (!child)
return state_set;
merged_state_set = state_set;
state_set = atk_object_ref_state_set (child);
if (atk_state_set_contains_state (state_set, ATK_STATE_VISIBLE))
{
atk_state_set_add_state (merged_state_set, ATK_STATE_VISIBLE);
if (atk_state_set_contains_state (state_set, ATK_STATE_ENABLED))
atk_state_set_add_state (merged_state_set, ATK_STATE_ENABLED);
if (atk_state_set_contains_state (state_set, ATK_STATE_SHOWING))
atk_state_set_add_state (merged_state_set, ATK_STATE_SHOWING);
}
g_object_unref (state_set);
g_object_unref (child);
}
return merged_state_set;
}
static gint
gtk_notebook_page_accessible_get_index_in_parent (AtkObject *accessible)
{
GtkNotebookPageAccessible *page;
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (accessible);
if (!page->priv->child)
return -1;
return gtk_notebook_page_num (GTK_NOTEBOOK (gtk_accessible_get_widget (page->priv->notebook)),
page->priv->child);
}
static void
gtk_notebook_page_accessible_class_init (GtkNotebookPageAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
class->get_name = gtk_notebook_page_accessible_get_name;
class->get_parent = gtk_notebook_page_accessible_get_parent;
class->get_n_children = gtk_notebook_page_accessible_get_n_children;
class->ref_child = gtk_notebook_page_accessible_ref_child;
class->ref_state_set = gtk_notebook_page_accessible_ref_state_set;
class->get_index_in_parent = gtk_notebook_page_accessible_get_index_in_parent;
}
static void
gtk_notebook_page_accessible_init (GtkNotebookPageAccessible *page)
{
page->priv = gtk_notebook_page_accessible_get_instance_private (page);
}
static void
notify_tab_label (GObject *object,
GParamSpec *pspec,
AtkObject *atk_obj)
{
if (atk_obj->name == NULL)
g_object_notify (G_OBJECT (atk_obj), "accessible-name");
g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
AtkObject *
gtk_notebook_page_accessible_new (GtkNotebookAccessible *notebook,
GtkWidget *child)
{
GObject *object;
AtkObject *atk_object;
GtkNotebookPageAccessible *page;
g_return_val_if_fail (GTK_IS_NOTEBOOK_ACCESSIBLE (notebook), NULL);
g_return_val_if_fail (GTK_WIDGET (child), NULL);
object = g_object_new (GTK_TYPE_NOTEBOOK_PAGE_ACCESSIBLE, NULL);
page = GTK_NOTEBOOK_PAGE_ACCESSIBLE (object);
page->priv->notebook = GTK_ACCESSIBLE (notebook);
page->priv->child = child;
atk_object = ATK_OBJECT (page);
atk_object->role = ATK_ROLE_PAGE_TAB;
atk_object->layer = ATK_LAYER_WIDGET;
atk_object_set_parent (gtk_widget_get_accessible (child), atk_object);
g_signal_connect (gtk_accessible_get_widget (page->priv->notebook),
"child-notify::tab-label",
G_CALLBACK (notify_tab_label), page);
return atk_object;
}
void
gtk_notebook_page_accessible_invalidate (GtkNotebookPageAccessible *page)
{
AtkObject *obj = ATK_OBJECT (page);
GtkWidget *notebook;
notebook = gtk_accessible_get_widget (page->priv->notebook);
if (notebook)
g_signal_handlers_disconnect_by_func (notebook, notify_tab_label, page);
atk_object_notify_state_change (obj, ATK_STATE_DEFUNCT, TRUE);
atk_object_set_parent (obj, NULL);
page->priv->notebook = NULL;
atk_object_set_parent (gtk_widget_get_accessible (page->priv->child), NULL);
page->priv->child = NULL;
}
static AtkObject*
gtk_notebook_page_accessible_ref_accessible_at_point (AtkComponent *component,
gint x,
gint y,
AtkCoordType coord_type)
{
/* There is only one child so we return it */
AtkObject* child;
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
return child;
}
static void
gtk_notebook_page_accessible_get_extents (AtkComponent *component,
gint *x,
gint *y,
gint *width,
gint *height,
AtkCoordType coord_type)
{
GtkWidget *label;
AtkObject *atk_label;
label = get_label_from_notebook_page (GTK_NOTEBOOK_PAGE_ACCESSIBLE (component));
if (!label)
{
AtkObject *child;
*width = 0;
*height = 0;
child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0);
if (!child)
return;
atk_component_get_extents (ATK_COMPONENT (child), x, y, NULL, NULL,
coord_type);
g_object_unref (child);
}
else
{
atk_label = gtk_widget_get_accessible (label);
atk_component_get_extents (ATK_COMPONENT (atk_label),
x, y, width, height, coord_type);
}
}
static void
atk_component_interface_init (AtkComponentIface *iface)
{
/* We use the default implementations for contains, get_position, get_size */
iface->ref_accessible_at_point = gtk_notebook_page_accessible_ref_accessible_at_point;
iface->get_extents = gtk_notebook_page_accessible_get_extents;
}
|