-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathatspi-accessible.c
2007 lines (1796 loc) · 61.2 KB
/
atspi-accessible.c
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
* Copyright 2001, 2002 Sun Microsystems Inc.,
* Copyright 2001, 2002 Ximian, Inc.
* Copyright 2010, 2011 Novell, 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.1 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "atspi-accessible-private.h"
#include "atspi-private.h"
#include <string.h>
/**
* AtspiAccessible:
*
* The base interface which is implemented by all accessible objects.
*
* All objects support interfaces for querying their contained 'children'
* and position in the accessible-object hierarchy, whether or not they
* actually have children.
*/
enum
{
REGION_CHANGED,
MODE_CHANGED,
LAST_SIGNAL
};
static gboolean enable_caching = FALSE;
static guint quark_locale;
static guint atspi_accessible_signals[LAST_SIGNAL] = {
0,
};
static gboolean
screen_reader_signal_watcher (GSignalInvocationHint *signal_hint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
GObject *object;
AtspiAccessible *accessible;
GSignalQuery signal_query;
const char *name;
DBusMessage *signal;
DBusMessageIter iter, iter_struct, iter_variant, iter_array;
dbus_int32_t detail1 = 0, detail2 = 0;
const char *detail = "";
gchar *dbus_name;
object = g_value_get_object (param_values + 0);
g_return_val_if_fail (ATSPI_IS_ACCESSIBLE (object), FALSE);
g_signal_query (signal_hint->signal_id, &signal_query);
name = signal_query.signal_name;
if (signal_hint->detail)
detail = g_quark_to_string (signal_hint->detail);
if (n_param_values > 1)
detail1 = g_value_get_int (param_values + 1);
if (n_param_values > 2 && G_VALUE_HOLDS_INT (param_values + 2))
detail2 = g_value_get_int (param_values + 2);
accessible = ATSPI_ACCESSIBLE (object);
g_return_val_if_fail (accessible->parent.app != NULL, FALSE);
dbus_name = _atspi_strdup_and_adjust_for_dbus (name);
signal = dbus_message_new_signal (ATSPI_DBUS_PATH_SCREEN_READER,
ATSPI_DBUS_INTERFACE_EVENT_SCREEN_READER,
dbus_name);
g_free (dbus_name);
dbus_message_iter_init_append (signal, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &detail);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &detail1);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &detail2);
dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(so)",
&iter_variant);
dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL,
&iter_struct);
dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &accessible->parent.app->bus_name);
dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &accessible->parent.path);
dbus_message_iter_close_container (&iter_variant, &iter_struct);
dbus_message_iter_close_container (&iter, &iter_variant);
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}",
&iter_array);
dbus_message_iter_close_container (&iter, &iter_array);
dbus_connection_send (_atspi_bus (), signal, NULL);
dbus_message_unref (signal);
return TRUE;
}
static void
atspi_action_interface_init (AtspiAction *action)
{
}
static void
atspi_collection_interface_init (AtspiCollection *component)
{
}
static void
atspi_component_interface_init (AtspiComponent *component)
{
}
static void
atspi_document_interface_init (AtspiDocument *document)
{
}
static void
atspi_editable_text_interface_init (AtspiEditableText *editable_text)
{
}
static void
atspi_hypertext_interface_init (AtspiHypertext *hypertext)
{
}
static void
atspi_image_interface_init (AtspiImage *image)
{
}
static void
atspi_selection_interface_init (AtspiSelection *selection)
{
}
static void
atspi_table_interface_init (AtspiTable *table)
{
}
static void
atspi_table_cell_interface_init (AtspiTableCell *cell)
{
}
static void
atspi_text_interface_init (AtspiText *text)
{
}
static void
atspi_value_interface_init (AtspiValue *value)
{
}
G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT, G_ADD_PRIVATE (AtspiAccessible) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE_CELL, atspi_table_cell_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init) G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
#ifdef DEBUG_REF_COUNTS
static gint accessible_count = 0;
#endif
static void
atspi_accessible_unref (GObject *accessible)
{
if (accessible != NULL)
g_object_unref (accessible);
}
static void
atspi_accessible_init (AtspiAccessible *accessible)
{
#ifdef DEBUG_REF_COUNTS
accessible_count++;
g_hash_table_insert (_atspi_get_live_refs (), accessible, NULL);
g_print ("at-spi: init: %d objects\n", accessible_count);
#endif
accessible->priv = atspi_accessible_get_instance_private (accessible);
accessible->children = g_ptr_array_new_with_free_func ((GDestroyNotify) atspi_accessible_unref);
}
static void
atspi_accessible_dispose (GObject *object)
{
AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
AtspiEvent e;
AtspiAccessible *parent;
gint i;
/* TODO: Only fire if object not already marked defunct */
memset (&e, 0, sizeof (e));
e.type = "object:state-changed:defunct";
e.source = accessible;
e.detail1 = 1;
e.detail2 = 0;
_atspi_send_event (&e);
g_clear_object (&accessible->states);
parent = accessible->accessible_parent;
if (parent)
{
accessible->accessible_parent = NULL;
if (parent->children)
g_ptr_array_remove (parent->children, accessible);
g_object_unref (parent);
}
if (accessible->children)
for (i = accessible->children->len - 1; i >= 0; i--)
{
AtspiAccessible *child = g_ptr_array_index (accessible->children, i);
if (child && child->accessible_parent == accessible)
{
child->accessible_parent = NULL;
g_object_unref (accessible);
}
}
if (accessible->children)
{
g_ptr_array_free (accessible->children, TRUE);
accessible->children = NULL;
}
G_OBJECT_CLASS (atspi_accessible_parent_class)->dispose (object);
}
static void
atspi_accessible_finalize (GObject *object)
{
AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
g_free (accessible->description);
g_free (accessible->name);
if (accessible->attributes)
g_hash_table_unref (accessible->attributes);
if (accessible->priv->cache)
g_hash_table_destroy (accessible->priv->cache);
#ifdef DEBUG_REF_COUNTS
accessible_count--;
g_hash_table_remove (_atspi_get_live_refs (), accessible);
g_print ("at-spi: finalize: %d objects\n", accessible_count);
#endif
G_OBJECT_CLASS (atspi_accessible_parent_class)->finalize (object);
/* TODO: remove emission hook */
}
static void
atspi_accessible_class_init (AtspiAccessibleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = atspi_accessible_dispose;
object_class->finalize = atspi_accessible_finalize;
quark_locale = g_quark_from_string ("accessible-locale");
/**
* AtspiAccessible::region-changed:
* @atspiaccessible: the object which received the signal
* @arg1: an integer specifying the current offset of the text being read,
* if the object is textual.
* @arg2: an integer specifying the ending offset of the text being read,
* if the object is textual.
*
* The signal "region-changed" is emitted by a screen reader to indicate
* that it is now reading or tracking a new object, or, a new piece of
* text within an object. This allows a magnifier to gain the information
* needed to highlight the object that the screen reader is reading.
*/
atspi_accessible_signals[REGION_CHANGED] =
g_signal_new ("region_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (AtspiAccessibleClass, region_changed),
NULL, NULL,
atspi_marshal_VOID__INT_INT,
G_TYPE_NONE,
2, G_TYPE_INT, G_TYPE_INT);
/**
* AtspiAccessible::mode-changed:
* @atspiaccessible: the object which received the signal
* @arg1: a boolean specifying whether the mode is being toggled on or off.
* @why: an optional string explaining why the mode changed.
*
* The signal "mode-changed" is emitted by a screen reader to indicate
* that its mode has changed. This signal supports the following details:
* focus-tracking
* flat-review
* mouse-review
* say-all
* caret-tracking
*/
atspi_accessible_signals[MODE_CHANGED] =
g_signal_new ("mode_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (AtspiAccessibleClass, mode_changed),
NULL, NULL,
atspi_marshal_VOID__INT_STRING,
G_TYPE_NONE,
2, G_TYPE_INT, G_TYPE_STRING);
g_signal_add_emission_hook (atspi_accessible_signals[REGION_CHANGED], 0,
screen_reader_signal_watcher, NULL,
(GDestroyNotify) NULL);
g_signal_add_emission_hook (atspi_accessible_signals[MODE_CHANGED], 0,
screen_reader_signal_watcher, NULL,
(GDestroyNotify) NULL);
}
/**
* atspi_accessible_get_name:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the name of an #AtspiAccessible object.
*
* Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
* or NULL on exception.
**/
gchar *
atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, g_strdup (""));
gchar *name = NULL;
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
{
g_free (obj->name);
obj->name = NULL;
if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
"s", &name))
return g_strdup ("");
_atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
if (!obj->name)
obj->name = name;
else
free (name);
}
return g_strdup (obj->name);
}
/**
* atspi_accessible_get_description:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the description of an #AtspiAccessible object.
*
* Returns: a UTF-8 string describing the #AtspiAccessible object
* or NULL on exception.
**/
gchar *
atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, g_strdup (""));
gchar *description = NULL;
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
{
g_free (obj->description);
obj->description = NULL;
if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
"Description", error, "s",
&obj->description))
return g_strdup ("");
_atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
if (!obj->description)
obj->description = description;
else
free (description);
}
return g_strdup (obj->description);
}
const char *str_parent = "Parent";
/**
* atspi_accessible_get_parent:
* @obj: a pointer to the #AtspiAccessible object to query.
*
* Gets an #AtspiAccessible object's parent container.
*
* Returns: (nullable) (transfer full): a pointer to the
* #AtspiAccessible object which contains the given
* #AtspiAccessible instance, or NULL if the @obj has no
* parent container.
*
**/
AtspiAccessible *
atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, NULL);
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
{
DBusMessage *message, *reply;
DBusMessageIter iter, iter_variant;
if (!obj->parent.app)
return NULL;
message = dbus_message_new_method_call (obj->parent.app->bus_name,
obj->parent.path,
DBUS_INTERFACE_PROPERTIES, "Get");
if (!message)
return NULL;
dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
DBUS_TYPE_STRING, &str_parent,
DBUS_TYPE_INVALID);
reply = _atspi_dbus_send_with_reply_and_block (message, error);
if (!reply)
return NULL;
if (strcmp (dbus_message_get_signature (reply), "v") != 0)
{
dbus_message_unref (reply);
return NULL;
}
dbus_message_iter_init (reply, &iter);
dbus_message_iter_recurse (&iter, &iter_variant);
g_clear_object (&obj->accessible_parent);
obj->accessible_parent = _atspi_dbus_consume_accessible (&iter_variant);
dbus_message_unref (reply);
_atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
}
if (!obj->accessible_parent)
return NULL;
return g_object_ref (obj->accessible_parent);
}
/**
* atspi_accessible_get_child_count:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the number of children contained by an #AtspiAccessible object.
*
* Returns: a #long indicating the number of #AtspiAccessible children
* contained by an #AtspiAccessible object or -1 on exception.
*
**/
gint
atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, -1);
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
{
dbus_int32_t ret;
if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
"ChildCount", error, "i", &ret))
return -1;
return ret;
}
if (!obj->children)
return 0; /* assume it's disposed */
return obj->children->len;
}
/**
* atspi_accessible_get_child_at_index:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
* @child_index: a #long indicating which child is specified.
*
* Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
*
* Returns: (transfer full): a pointer to the #AtspiAccessible child object at
* index @child_index or NULL on exception.
**/
AtspiAccessible *
atspi_accessible_get_child_at_index (AtspiAccessible *obj,
gint child_index,
GError **error)
{
AtspiAccessible *child;
DBusMessage *reply;
g_return_val_if_fail (obj != NULL, NULL);
if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
{
if (!obj->children)
return NULL; /* assume disposed */
if (child_index < obj->children->len)
{
child = g_ptr_array_index (obj->children, child_index);
if (child)
return g_object_ref (child);
}
}
reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
"GetChildAtIndex", error, "i", child_index);
child = _atspi_dbus_return_accessible_from_message (reply);
if (!child)
return NULL;
if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
{
if (child_index >= obj->children->len)
g_ptr_array_set_size (obj->children, child_index + 1);
else if (g_ptr_array_index (obj->children, child_index))
g_object_unref (g_ptr_array_index (obj->children, child_index));
g_ptr_array_index (obj->children, child_index) = g_object_ref (child);
}
return child;
}
/**
* atspi_accessible_get_index_in_parent:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the index of an #AtspiAccessible object within its parent's
* #AtspiAccessible children list.
*
* Returns: a #glong indicating the index of the #AtspiAccessible object
* in its parent,
* or -1 if @obj has no containing parent or on exception.
**/
gint
atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
{
gint i = 0;
dbus_int32_t ret = -1;
g_return_val_if_fail (obj != NULL, -1);
if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
{
if (!obj->accessible_parent)
return -1;
if (!_atspi_accessible_test_cache (obj->accessible_parent, ATSPI_CACHE_CHILDREN) || !obj->accessible_parent->children)
goto dbus;
for (i = 0; i < obj->accessible_parent->children->len; i++)
if (g_ptr_array_index (obj->accessible_parent->children, i) == obj)
return i;
}
dbus:
_atspi_dbus_call (obj, atspi_interface_accessible,
"GetIndexInParent", NULL, "=>i", &ret);
return ret;
}
typedef struct
{
dbus_uint32_t type;
GArray *targets;
} Accessibility_Relation;
/**
* atspi_accessible_get_relation_set:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
* relationships with other #AtspiAccessible objects.
*
* Returns: (element-type AtspiRelation*) (transfer full): a #GArray of
* #AtspiRelation pointers or NULL on exception.
**/
GArray *
atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
{
DBusMessage *reply;
DBusMessageIter iter, iter_array;
GArray *ret;
g_return_val_if_fail (obj != NULL, NULL);
reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
if (!reply)
return NULL;
_ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
dbus_message_iter_init (reply, &iter);
dbus_message_iter_recurse (&iter, &iter_array);
while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
{
AtspiRelation *relation;
relation = _atspi_relation_new_from_iter (&iter_array);
ret = g_array_append_val (ret, relation);
dbus_message_iter_next (&iter_array);
}
dbus_message_unref (reply);
return ret;
}
/**
* atspi_accessible_get_role:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the UI role played by an #AtspiAccessible object.
* This role's name can be obtained via atspi_accessible_get_role_name ().
*
* Returns: the #AtspiRole of an #AtspiAccessible object.
*
**/
AtspiRole
atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
{
dbus_uint32_t role;
/* TODO: Make this a property */
if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
{
obj->role = role;
_atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
}
}
return obj->role;
}
/**
* atspi_accessible_get_role_name:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets a UTF-8 string corresponding to the name of the role played by an object.
* This method will return useful values for roles that fall outside the
* enumeration used in atspi_accessible_get_role ().
*
* Returns: a UTF-8 string specifying the type of UI role played by an
* #AtspiAccessible object.
*
**/
gchar *
atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
{
gchar *retval = NULL;
AtspiRole role;
g_return_val_if_fail (obj != NULL, NULL);
role = atspi_accessible_get_role (obj, error);
if (role >= 0 && role < ATSPI_ROLE_COUNT && role != ATSPI_ROLE_EXTENDED)
return atspi_role_get_name (role);
_atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
if (!retval)
retval = g_strdup ("");
return retval;
}
/**
* atspi_accessible_get_localized_role_name:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets a UTF-8 string corresponding to the name of the role played by an
* object, translated to the current locale.
* This method will return useful values for roles that fall outside the
* enumeration used in atspi_accessible_getRole ().
*
* Returns: a localized, UTF-8 string specifying the type of UI role played
* by an #AtspiAccessible object.
*
**/
gchar *
atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
{
char *retval = NULL;
AtspiRole role;
g_return_val_if_fail (obj != NULL, NULL);
role = atspi_accessible_get_role (obj, error);
if (role >= 0 && role < ATSPI_ROLE_COUNT && role != ATSPI_ROLE_EXTENDED)
return atspi_role_get_localized_name (role);
_atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
if (!retval)
return g_strdup ("");
return retval;
}
static AtspiStateSet *
defunct_set ()
{
AtspiStateSet *set = atspi_state_set_new (NULL);
atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
return set;
}
/**
* atspi_accessible_get_state_set:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the states currently held by an object.
*
* Returns: (transfer full): a pointer to an #AtspiStateSet representing an
* object's current state set.
**/
AtspiStateSet *
atspi_accessible_get_state_set (AtspiAccessible *obj)
{
/* TODO: Should take a GError **, but would be an API break */
if (!obj->parent.app || !obj->parent.app->bus)
return defunct_set ();
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
{
DBusMessage *reply;
DBusMessageIter iter;
reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
"GetState", NULL, "");
_ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
dbus_message_iter_init (reply, &iter);
_atspi_dbus_set_state (obj, &iter);
dbus_message_unref (reply);
_atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
}
return g_object_ref (obj->states);
}
/**
* atspi_accessible_get_attributes:
* @obj: The #AtspiAccessible being queried.
*
* Gets the #AttributeSet representing any assigned
* name-value pair attributes or annotations for this object.
* For typographic, textual, or textually-semantic attributes, see
* atspi_text_get_attributes instead.
*
* Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
* attributes assigned to this object.
*/
GHashTable *
atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
{
DBusMessage *message;
g_return_val_if_fail (obj != NULL, NULL);
if (obj->priv->cache)
{
GValue *val = g_hash_table_lookup (obj->priv->cache, "Attributes");
if (val)
return g_value_dup_boxed (val);
}
if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
{
message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
"GetAttributes", error, "");
g_clear_pointer (&(obj->attributes), g_hash_table_unref);
obj->attributes = _atspi_dbus_return_hash_from_message (message);
_atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
}
if (!obj->attributes)
return NULL;
return g_hash_table_ref (obj->attributes);
}
static void
add_to_attribute_array (gpointer key, gpointer value, gpointer data)
{
GArray **array = (GArray **) data;
gchar *str = g_strconcat (key, ":", value, NULL);
*array = g_array_append_val (*array, str);
}
/**
* atspi_accessible_get_attributes_as_array:
* @obj: The #AtspiAccessible being queried.
*
* Gets a #GArray representing any assigned
* name-value pair attributes or annotations for this object.
* For typographic, textual, or textually-semantic attributes, see
* atspi_text_get_attributes_as_array instead.
*
* Returns: (element-type gchar*) (transfer full): The name-value-pair
* attributes assigned to this object.
*/
GArray *
atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
{
DBusMessage *message;
g_return_val_if_fail (obj != NULL, NULL);
if (obj->priv->cache)
{
GValue *val = g_hash_table_lookup (obj->priv->cache, "Attributes");
if (val)
{
GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
GHashTable *attributes = g_value_get_boxed (val);
g_hash_table_foreach (attributes, add_to_attribute_array, &array);
return array;
}
}
message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
return _atspi_dbus_return_attribute_array_from_message (message);
}
/**
* atspi_accessible_get_application:
* @obj: The #AtspiAccessible being queried.
*
* Gets the containing #AtspiApplication for an object.
*
* Returns: (transfer full): the containing #AtspiApplication instance for
* this object.
*/
AtspiAccessible *
atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
{
AtspiAccessible *parent;
g_object_ref (obj);
for (;;)
{
parent = atspi_accessible_get_parent (obj, NULL);
if (!parent && obj->parent.app &&
atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
{
AtspiAccessible *root = g_object_ref (obj->parent.app->root);
if (root)
{
g_object_unref (obj);
if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
{
g_object_unref (root);
return NULL;
}
return root;
}
}
if (!parent || parent == obj ||
atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
{
if (parent)
g_object_unref (parent);
return obj;
}
g_object_unref (obj);
obj = parent;
}
}
/* Application-specific methods */
/**
* atspi_accessible_get_toolkit_name:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the toolkit name for an #AtspiAccessible object.
* Only works on application root objects.
*
* Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
**/
gchar *
atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, NULL);
if (!obj->parent.app)
return NULL;
if (!obj->parent.app->toolkit_name)
_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
error, "s", &obj->parent.app->toolkit_name);
return g_strdup (obj->parent.app->toolkit_name);
}
/**
* atspi_accessible_get_toolkit_version:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the toolkit version for an #AtspiAccessible object.
* Only works on application root objects.
*
* Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
**/
gchar *
atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, NULL);
if (!obj->parent.app)
return NULL;
if (!obj->parent.app->toolkit_version)
_atspi_dbus_get_property (obj, atspi_interface_application, "Version",
error, "s", &obj->parent.app->toolkit_version);
return g_strdup (obj->parent.app->toolkit_version);
}
/**
* atspi_accessible_get_atspi_version:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the AT-SPI IPC specification version supported by the application
* pointed to by the #AtspiAccessible object.
* Only works on application root objects.
*
* Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
**/
gchar *
atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, NULL);
if (!obj->parent.app)
return NULL;
if (!obj->parent.app->atspi_version)
_atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
error, "s", &obj->parent.app->atspi_version);
return g_strdup (obj->parent.app->atspi_version);
}
/**
* atspi_accessible_get_id:
* @obj: a pointer to the #AtspiAccessible object on which to operate.
*
* Gets the application id for a #AtspiAccessible object.
* Only works on application root objects.
*
* Returns: a positive #gint indicating the id for the #AtspiAccessible object
* or -1 on exception.
**/
gint
atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
{
gint ret = -1;
g_return_val_if_fail (obj != NULL, -1);
if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
return -1;
return ret;
}
/* Interface query methods */
static gboolean
_atspi_accessible_is_a (AtspiAccessible *accessible,
const char *interface_name)
{
int n;
if (accessible == NULL)
{
return FALSE;
}
if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
{
DBusMessage *reply;
DBusMessageIter iter;
reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
"GetInterfaces", NULL, "");
_ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
dbus_message_iter_init (reply, &iter);
_atspi_dbus_set_interfaces (accessible, &iter);
dbus_message_unref (reply);
}
n = _atspi_get_iface_num (interface_name);
if (n == -1)
return FALSE;
return (gboolean) ((accessible->interfaces & (1 << n)) ? TRUE : FALSE);
}
/**