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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
/* GAIL - The GNOME Accessibility Implementation Library
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "gailcombo.h"
static void gail_combo_class_init (GailComboClass *klass);
static void gail_combo_init (GailCombo *combo);
static void gail_combo_real_initialize (AtkObject *obj,
gpointer data);
static void gail_combo_selection_changed_gtk (GtkWidget *widget,
gpointer data);
static gint gail_combo_get_n_children (AtkObject *obj);
static AtkObject* gail_combo_ref_child (AtkObject *obj,
gint i);
static void gail_combo_finalize (GObject *object);
static void atk_action_interface_init (AtkActionIface *iface);
static gboolean gail_combo_do_action (AtkAction *action,
gint i);
static gboolean idle_do_action (gpointer data);
static gint gail_combo_get_n_actions (AtkAction *action)
;
static G_CONST_RETURN gchar* gail_combo_get_description(AtkAction *action,
gint i);
static G_CONST_RETURN gchar* gail_combo_get_name (AtkAction *action,
gint i);
static gboolean gail_combo_set_description(AtkAction *action,
gint i,
const gchar *desc);
static void atk_selection_interface_init (AtkSelectionIface *iface);
static gboolean gail_combo_add_selection (AtkSelection *selection,
gint i);
static gboolean gail_combo_clear_selection (AtkSelection *selection);
static AtkObject* gail_combo_ref_selection (AtkSelection *selection,
gint i);
static gint gail_combo_get_selection_count (AtkSelection *selection);
static gboolean gail_combo_is_child_selected (AtkSelection *selection,
gint i);
static gboolean gail_combo_remove_selection (AtkSelection *selection,
gint i);
static gint _gail_combo_button_release (gpointer data);
static gint _gail_combo_popup_release (gpointer data);
G_DEFINE_TYPE_WITH_CODE (GailCombo, gail_combo, GAIL_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
static void
gail_combo_class_init (GailComboClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
gobject_class->finalize = gail_combo_finalize;
class->get_n_children = gail_combo_get_n_children;
class->ref_child = gail_combo_ref_child;
class->initialize = gail_combo_real_initialize;
}
static void
gail_combo_init (GailCombo *combo)
{
combo->press_description = NULL;
combo->old_selection = NULL;
combo->deselect_idle_handler = 0;
combo->select_idle_handler = 0;
}
static void
gail_combo_real_initialize (AtkObject *obj,
gpointer data)
{
GtkCombo *combo;
GtkList *list;
GList *slist;
GailCombo *gail_combo;
ATK_OBJECT_CLASS (gail_combo_parent_class)->initialize (obj, data);
combo = GTK_COMBO (data);
list = GTK_LIST (combo->list);
slist = list->selection;
gail_combo = GAIL_COMBO (obj);
if (slist && slist->data)
{
gail_combo->old_selection = slist->data;
}
g_signal_connect (combo->list,
"selection_changed",
G_CALLBACK (gail_combo_selection_changed_gtk),
data);
atk_object_set_parent (gtk_widget_get_accessible (combo->entry), obj);
atk_object_set_parent (gtk_widget_get_accessible (combo->popup), obj);
obj->role = ATK_ROLE_COMBO_BOX;
}
static gboolean
notify_deselect (gpointer data)
{
GailCombo *combo;
combo = GAIL_COMBO (data);
combo->old_selection = NULL;
combo->deselect_idle_handler = 0;
g_signal_emit_by_name (data, "selection_changed");
return FALSE;
}
static gboolean
notify_select (gpointer data)
{
GailCombo *combo;
combo = GAIL_COMBO (data);
combo->select_idle_handler = 0;
g_signal_emit_by_name (data, "selection_changed");
return FALSE;
}
static void
gail_combo_selection_changed_gtk (GtkWidget *widget,
gpointer data)
{
GtkCombo *combo;
GtkList *list;
GList *slist;
AtkObject *obj;
GailCombo *gail_combo;
combo = GTK_COMBO (data);
list = GTK_LIST (combo->list);
slist = list->selection;
obj = gtk_widget_get_accessible (GTK_WIDGET (data));
gail_combo = GAIL_COMBO (obj);
if (slist && slist->data)
{
if (slist->data != gail_combo->old_selection)
{
gail_combo->old_selection = slist->data;
if (gail_combo->select_idle_handler == 0)
gail_combo->select_idle_handler = gdk_threads_add_idle (notify_select, gail_combo);
}
if (gail_combo->deselect_idle_handler)
{
g_source_remove (gail_combo->deselect_idle_handler);
gail_combo->deselect_idle_handler = 0;
}
}
else
{
if (gail_combo->deselect_idle_handler == 0)
gail_combo->deselect_idle_handler = gdk_threads_add_idle (notify_deselect, gail_combo);
if (gail_combo->select_idle_handler)
{
g_source_remove (gail_combo->select_idle_handler);
gail_combo->select_idle_handler = 0;
}
}
}
/*
* The children of a GailCombo are the list of items and the entry field
*/
static gint
gail_combo_get_n_children (AtkObject* obj)
{
gint n_children = 2;
GtkWidget *widget;
g_return_val_if_fail (GAIL_IS_COMBO (obj), 0);
widget = GTK_ACCESSIBLE (obj)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return 0;
return n_children;
}
static AtkObject*
gail_combo_ref_child (AtkObject *obj,
gint i)
{
AtkObject *accessible;
GtkWidget *widget;
g_return_val_if_fail (GAIL_IS_COMBO (obj), NULL);
if (i < 0 || i > 1)
return NULL;
widget = GTK_ACCESSIBLE (obj)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return NULL;
if (i == 0)
accessible = gtk_widget_get_accessible (GTK_COMBO (widget)->popup);
else
accessible = gtk_widget_get_accessible (GTK_COMBO (widget)->entry);
g_object_ref (accessible);
return accessible;
}
static void
atk_action_interface_init (AtkActionIface *iface)
{
iface->do_action = gail_combo_do_action;
iface->get_n_actions = gail_combo_get_n_actions;
iface->get_description = gail_combo_get_description;
iface->get_name = gail_combo_get_name;
iface->set_description = gail_combo_set_description;
}
static gboolean
gail_combo_do_action (AtkAction *action,
gint i)
{
GailCombo *combo;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (action)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return FALSE;
if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
return FALSE;
combo = GAIL_COMBO (action);
if (i == 0)
{
if (combo->action_idle_handler)
return FALSE;
combo->action_idle_handler = gdk_threads_add_idle (idle_do_action, combo);
return TRUE;
}
else
return FALSE;
}
/*
* This action is the pressing of the button on the combo box.
* The behavior is different depending on whether the list is being
* displayed or removed.
*
* A button press event is simulated on the appropriate widget and
* a button release event is simulated in an idle function.
*/
static gboolean
idle_do_action (gpointer data)
{
GtkCombo *combo;
GtkWidget *action_widget;
GtkWidget *widget;
GailCombo *gail_combo;
gboolean do_popup;
GdkEvent tmp_event;
gail_combo = GAIL_COMBO (data);
gail_combo->action_idle_handler = 0;
widget = GTK_ACCESSIBLE (gail_combo)->widget;
if (widget == NULL /* State is defunct */ ||
!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
return FALSE;
combo = GTK_COMBO (widget);
do_popup = !gtk_widget_get_mapped (combo->popwin);
tmp_event.button.type = GDK_BUTTON_PRESS;
tmp_event.button.window = widget->window;
tmp_event.button.button = 1;
tmp_event.button.send_event = TRUE;
tmp_event.button.time = GDK_CURRENT_TIME;
tmp_event.button.axes = NULL;
if (do_popup)
{
/* Pop up list */
action_widget = combo->button;
gtk_widget_event (action_widget, &tmp_event);
/* FIXME !*/
g_idle_add (_gail_combo_button_release, combo);
}
else
{
/* Pop down list */
tmp_event.button.window = combo->list->window;
gdk_window_set_user_data (combo->list->window, combo->button);
action_widget = combo->popwin;
gtk_widget_event (action_widget, &tmp_event);
/* FIXME !*/
g_idle_add (_gail_combo_popup_release, combo);
}
return FALSE;
}
static gint
gail_combo_get_n_actions (AtkAction *action)
{
/*
* The default behavior of a combo box is to have one action -
*/
return 1;
}
static G_CONST_RETURN gchar*
gail_combo_get_description (AtkAction *action,
gint i)
{
if (i == 0)
{
GailCombo *combo;
combo = GAIL_COMBO (action);
return combo->press_description;
}
else
return NULL;
}
static G_CONST_RETURN gchar*
gail_combo_get_name (AtkAction *action,
gint i)
{
if (i == 0)
return "press";
else
return NULL;
}
static void
atk_selection_interface_init (AtkSelectionIface *iface)
{
iface->add_selection = gail_combo_add_selection;
iface->clear_selection = gail_combo_clear_selection;
iface->ref_selection = gail_combo_ref_selection;
iface->get_selection_count = gail_combo_get_selection_count;
iface->is_child_selected = gail_combo_is_child_selected;
iface->remove_selection = gail_combo_remove_selection;
/*
* select_all_selection does not make sense for a combo box
* so no implementation is provided.
*/
}
static gboolean
gail_combo_add_selection (AtkSelection *selection,
gint i)
{
GtkCombo *combo;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return FALSE;
combo = GTK_COMBO (widget);
gtk_list_select_item (GTK_LIST (combo->list), i);
return TRUE;
}
static gboolean
gail_combo_clear_selection (AtkSelection *selection)
{
GtkCombo *combo;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return FALSE;
combo = GTK_COMBO (widget);
gtk_list_unselect_all (GTK_LIST (combo->list));
return TRUE;
}
static AtkObject*
gail_combo_ref_selection (AtkSelection *selection,
gint i)
{
GtkCombo *combo;
GList * list;
GtkWidget *item;
AtkObject *obj;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return NULL;
combo = GTK_COMBO (widget);
/*
* A combo box can have only one selection.
*/
if (i != 0)
return NULL;
list = GTK_LIST (combo->list)->selection;
if (list == NULL)
return NULL;
item = GTK_WIDGET (list->data);
obj = gtk_widget_get_accessible (item);
g_object_ref (obj);
return obj;
}
static gint
gail_combo_get_selection_count (AtkSelection *selection)
{
GtkCombo *combo;
GList * list;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return 0;
combo = GTK_COMBO (widget);
/*
* The number of children currently selected is either 1 or 0 so we
* do not bother to count the elements of the selected list.
*/
list = GTK_LIST (combo->list)->selection;
if (list == NULL)
return 0;
else
return 1;
}
static gboolean
gail_combo_is_child_selected (AtkSelection *selection,
gint i)
{
GtkCombo *combo;
GList * list;
GtkWidget *item;
gint j;
GtkWidget *widget;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
/*
* State is defunct
*/
return FALSE;
combo = GTK_COMBO (widget);
list = GTK_LIST (combo->list)->selection;
if (list == NULL)
return FALSE;
item = GTK_WIDGET (list->data);
j = g_list_index (GTK_LIST (combo->list)->children, item);
return (j == i);
}
static gboolean
gail_combo_remove_selection (AtkSelection *selection,
gint i)
{
if (atk_selection_is_child_selected (selection, i))
atk_selection_clear_selection (selection);
return TRUE;
}
static gint
_gail_combo_popup_release (gpointer data)
{
GtkCombo *combo;
GtkWidget *action_widget;
GdkEvent tmp_event;
GDK_THREADS_ENTER ();
combo = GTK_COMBO (data);
if (combo->current_button == 0)
{
GDK_THREADS_LEAVE ();
return FALSE;
}
tmp_event.button.type = GDK_BUTTON_RELEASE;
tmp_event.button.button = 1;
tmp_event.button.time = GDK_CURRENT_TIME;
action_widget = combo->button;
gtk_widget_event (action_widget, &tmp_event);
GDK_THREADS_LEAVE ();
return FALSE;
}
static gint
_gail_combo_button_release (gpointer data)
{
GtkCombo *combo;
GtkWidget *action_widget;
GdkEvent tmp_event;
GDK_THREADS_ENTER ();
combo = GTK_COMBO (data);
if (combo->current_button == 0)
{
GDK_THREADS_LEAVE ();
return FALSE;
}
tmp_event.button.type = GDK_BUTTON_RELEASE;
tmp_event.button.button = 1;
tmp_event.button.window = combo->list->window;
tmp_event.button.time = GDK_CURRENT_TIME;
gdk_window_set_user_data (combo->list->window, combo->button);
action_widget = combo->list;
gtk_widget_event (action_widget, &tmp_event);
GDK_THREADS_LEAVE ();
return FALSE;
}
static gboolean
gail_combo_set_description (AtkAction *action,
gint i,
const gchar *desc)
{
if (i == 0)
{
GailCombo *combo;
combo = GAIL_COMBO (action);
g_free (combo->press_description);
combo->press_description = g_strdup (desc);
return TRUE;
}
else
return FALSE;
}
static void
gail_combo_finalize (GObject *object)
{
GailCombo *combo = GAIL_COMBO (object);
g_free (combo->press_description);
if (combo->action_idle_handler)
{
g_source_remove (combo->action_idle_handler);
combo->action_idle_handler = 0;
}
if (combo->deselect_idle_handler)
{
g_source_remove (combo->deselect_idle_handler);
combo->deselect_idle_handler = 0;
}
if (combo->select_idle_handler)
{
g_source_remove (combo->select_idle_handler);
combo->select_idle_handler = 0;
}
G_OBJECT_CLASS (gail_combo_parent_class)->finalize (object);
}
|