summaryrefslogtreecommitdiff
path: root/legacy/elementary/src/lib/elm_interface_atspi_accessible.c
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2016-03-23 10:59:41 +0000
committerTom Hacohen <tom@stosb.com>2016-03-23 10:59:41 +0000
commit9340855597e7e465435c69b6278650346688da14 (patch)
tree2e5cfa138107091924528bb39711a1f7679abbaa /legacy/elementary/src/lib/elm_interface_atspi_accessible.c
parent7e411ecf76a6a73fe37968cce99679c13990c234 (diff)
parentf8d1db017edab8809e597591456751837deba68d (diff)
Merge elementary into the EFL.
This merges elementary into the efl repository while maintaining all of Elementary's history.
Diffstat (limited to '')
-rw-r--r--legacy/elementary/src/lib/elm_interface_atspi_accessible.c610
1 files changed, 610 insertions, 0 deletions
diff --git a/legacy/elementary/src/lib/elm_interface_atspi_accessible.c b/legacy/elementary/src/lib/elm_interface_atspi_accessible.c
new file mode 100644
index 0000000000..1e9d1a225e
--- /dev/null
+++ b/legacy/elementary/src/lib/elm_interface_atspi_accessible.c
@@ -0,0 +1,610 @@
1#ifdef HAVE_CONFIG_H
2 #include "elementary_config.h"
3#endif
4
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6
7#include <Elementary.h>
8#include "elm_widget.h"
9#include "elm_priv.h"
10
11const char* Atspi_Name[] = {
12 "invalid",
13 "accelerator label",
14 "alert",
15 "animation",
16 "arrow",
17 "calendar",
18 "canvas",
19 "check box",
20 "check menu item",
21 "color chooser",
22 "column header",
23 "combo box",
24 "dateeditor",
25 "desktop icon",
26 "desktop frame",
27 "dial",
28 "dialog",
29 "directory pane",
30 "drawing area",
31 "file chooser",
32 "filler",
33 "focus traversable",
34 "font chooser",
35 "frame",
36 "glass pane",
37 "html container",
38 "icon",
39 "image",
40 "internal frame",
41 "label",
42 "layered pane",
43 "list",
44 "list item",
45 "menu",
46 "menu bar",
47 "menu item",
48 "option pane",
49 "page tab",
50 "page tab list",
51 "panel",
52 "password text",
53 "popup menu",
54 "progress bar",
55 "push button",
56 "radio button",
57 "radio menu item",
58 "root pane",
59 "row header",
60 "scroll bar",
61 "scroll pane",
62 "separator",
63 "slider",
64 "spin button",
65 "split pane",
66 "status bar",
67 "table",
68 "table cell",
69 "table column header",
70 "table row header",
71 "tearoff menu item",
72 "terminal",
73 "text",
74 "toggle button",
75 "tool bar",
76 "tool tip",
77 "tree",
78 "tree table",
79 "unknown",
80 "viewport",
81 "window",
82 "extended",
83 "header",
84 "footer",
85 "paragraph",
86 "ruler",
87 "application",
88 "autocomplete",
89 "editbar",
90 "embedded",
91 "entry",
92 "chart",
93 "caption",
94 "document frame",
95 "heading",
96 "page",
97 "section",
98 "redundant object",
99 "form",
100 "link",
101 "input method window",
102 "table row",
103 "tree item",
104 "document spreadsheet",
105 "document presentation",
106 "document text",
107 "document web",
108 "document email",
109 "comment",
110 "list box",
111 "grouping",
112 "image map",
113 "notification",
114 "info bar",
115 "last defined"
116};
117
118struct _Elm_Atspi_Event_Handler
119{
120 Eo_Event_Cb cb;
121 void *data;
122};
123
124struct _Elm_Interface_Atspi_Accessible_Data
125{
126 Elm_Atspi_Role role;
127 const char *name;
128 const char *description;
129 const char *translation_domain;
130 Elm_Atspi_Relation_Set relations;
131 Elm_Atspi_Type type: 2;
132};
133
134typedef struct _Elm_Interface_Atspi_Accessible_Data Elm_Interface_Atspi_Accessible_Data;
135
136
137static Eina_List *global_callbacks;
138static Eo *root;
139
140EOLIAN static int
141_elm_interface_atspi_accessible_index_in_parent_get(Eo *obj, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
142{
143 Eina_List *l, *children = NULL;
144 Eo *chld, *parent = NULL;
145 int ret = 0;
146
147 parent = elm_interface_atspi_accessible_parent_get(obj);
148 if (!parent) return -1;
149
150 children = elm_interface_atspi_accessible_children_get(parent);
151 if (!children) return -1;
152
153 EINA_LIST_FOREACH(children, l, chld)
154 {
155 if (obj == chld)
156 break;
157 ret++;
158 }
159 if (ret == (int)eina_list_count(children))
160 {
161 ERR("Object %s not present in its AT-SPI parents (%s) children list! This should never happen.", eo_class_name_get(eo_class_get(obj)), eo_class_name_get(eo_class_get(parent)));
162 ret = -1;
163 }
164 eina_list_free(children);
165 return ret;
166}
167
168EOLIAN static Elm_Interface_Atspi_Accessible *
169_elm_interface_atspi_accessible_parent_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
170{
171 Elm_Atspi_Type type;
172 Eo *parent = obj;
173
174 do {
175 parent = eo_parent_get(obj);
176 if (eo_isa(parent, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
177 {
178 type = elm_interface_atspi_accessible_type_get(parent);
179 if (type != ELM_ATSPI_TYPE_SKIPPED) break;
180 }
181 } while (parent);
182
183 return eo_isa(parent, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN) ? parent : NULL;
184}
185
186EOLIAN static void
187_elm_interface_atspi_accessible_parent_set(Eo *obj, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED, Elm_Interface_Atspi_Accessible *new_parent EINA_UNUSED)
188{
189 WRN("The %s object does not implement the \"accessible_parent_set\" function.",
190 eo_class_name_get(eo_class_get(obj)));
191}
192
193EOLIAN Eina_List*
194_elm_interface_atspi_accessible_attributes_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
195{
196 WRN("The %s object does not implement the \"accessible_attributes_set\" function.",
197 eo_class_name_get(eo_class_get(obj)));
198 return NULL;
199}
200
201EOLIAN static Elm_Atspi_Role
202_elm_interface_atspi_accessible_role_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
203{
204 return pd->role;
205}
206
207EOLIAN static void
208_elm_interface_atspi_accessible_role_set(Eo *obj, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED, Elm_Atspi_Role role)
209{
210 if (pd->role != role)
211 {
212 pd->role = role;
213 elm_interface_atspi_accessible_role_changed_signal_emit(obj);
214 }
215}
216
217EOLIAN const char *
218_elm_interface_atspi_accessible_role_name_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
219{
220 Elm_Atspi_Role role;
221
222 role = elm_interface_atspi_accessible_role_get(obj);
223
224 return role > ELM_ATSPI_ROLE_LAST_DEFINED ? "" : Atspi_Name[role];
225}
226
227EOLIAN char *
228_elm_interface_atspi_accessible_name_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd)
229{
230 if (pd->name)
231 {
232#ifdef ENABLE_NLS
233 if (pd->translation_domain)
234 return strdup(dgettext(pd->translation_domain, pd->name));
235 else
236 return strdup(pd->name);
237#else
238 return strdup(pd->name);
239#endif
240 }
241
242 return NULL;
243}
244
245EOLIAN static void
246_elm_interface_atspi_accessible_name_set(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd, char *val)
247{
248 eina_stringshare_replace(&pd->name, val);
249}
250
251const char * _elm_interface_atspi_accessible_description_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd)
252{
253#ifdef ENABLE_NLS
254 if (pd->translation_domain)
255 return dgettext(pd->translation_domain, pd->description);
256#endif
257 return pd->description;
258}
259
260EOLIAN static void
261_elm_interface_atspi_accessible_description_set(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd, const char *val)
262{
263 eina_stringshare_replace(&pd->description, val);
264}
265
266EOLIAN static const char *
267_elm_interface_atspi_accessible_localized_role_name_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
268{
269 const char *ret = NULL;
270 ret = elm_interface_atspi_accessible_role_name_get(obj);
271#ifdef ENABLE_NLS
272 ret = gettext(ret);
273#endif
274 return ret;
275}
276
277EOLIAN static Eina_List *
278_elm_interface_atspi_accessible_children_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
279{
280 Eina_List *children = NULL;
281 Eina_Iterator *iter = NULL;
282 Eo *chld;
283
284 // By default use Eo_Base object hierarchy
285 iter = eo_children_iterator_new(obj);
286 if (!iter) return NULL;
287
288 EINA_ITERATOR_FOREACH(iter, chld)
289 {
290 if (eo_isa(chld, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
291 children = eina_list_append(children, chld);
292 }
293 eina_iterator_free(iter);
294
295 return children;
296}
297
298EOLIAN static Elm_Atspi_State_Set
299_elm_interface_atspi_accessible_state_set_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
300{
301 return 0;
302}
303
304EOLIAN Elm_Atspi_Relation_Set
305_elm_interface_atspi_accessible_relation_set_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED)
306{
307 return elm_atspi_relation_set_clone(pd->relations);
308}
309
310EAPI void elm_atspi_attributes_list_free(Eina_List *list)
311{
312 Elm_Atspi_Attribute *attr;
313 EINA_LIST_FREE(list, attr)
314 {
315 eina_stringshare_del(attr->key);
316 eina_stringshare_del(attr->value);
317 free(attr);
318 }
319}
320
321EOLIAN void
322_elm_interface_atspi_accessible_event_emit(Eo *class EINA_UNUSED, void *pd EINA_UNUSED, Eo *accessible, const Eo_Event_Description *event, void *event_info)
323{
324 Eina_List *l;
325 Elm_Atspi_Event_Handler *hdl;
326 Elm_Atspi_Type type;
327
328 if (!accessible || !event || !eo_isa(accessible, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
329 {
330 CRI("Invalid parameters, event: %s, obj: %s", event ? event->name : "NULL", accessible ? eo_class_name_get(accessible) : "NULL");
331 return;
332 }
333
334 type = elm_interface_atspi_accessible_type_get(accessible);
335 if (type != ELM_ATSPI_TYPE_REGULAR)
336 return;
337
338 if (event == ELM_INTERFACE_ATSPI_ACCESSIBLE_EVENT_CHILDREN_CHANGED)
339 {
340 Elm_Atspi_Event_Children_Changed_Data *atspi_data = event_info;
341 type = elm_interface_atspi_accessible_type_get(atspi_data->child);
342 if (type != ELM_ATSPI_TYPE_REGULAR)
343 return;
344 }
345
346 Eo_Event ev;
347 ev.obj = accessible;
348 ev.desc = event;
349 ev.event_info = event_info;
350 EINA_LIST_FOREACH(global_callbacks, l, hdl)
351 {
352 if (hdl->cb)
353 hdl->cb(hdl->data, &ev);
354 }
355}
356
357EOLIAN Elm_Atspi_Event_Handler *
358_elm_interface_atspi_accessible_event_handler_add(Eo *class EINA_UNUSED, void *pd EINA_UNUSED, Eo_Event_Cb cb, void *data)
359{
360 Elm_Atspi_Event_Handler *ret = calloc(1, sizeof(Elm_Atspi_Event_Handler));
361
362 ret->cb = cb;
363 ret->data = data;
364
365 global_callbacks = eina_list_append(global_callbacks, ret);
366
367 return ret;
368}
369
370EOLIAN void
371_elm_interface_atspi_accessible_event_handler_del(Eo *class EINA_UNUSED, void *pd EINA_UNUSED, Elm_Atspi_Event_Handler *handler)
372{
373 Eina_List *l, *l2;
374 Elm_Atspi_Event_Handler *hdl;
375 EINA_LIST_FOREACH_SAFE(global_callbacks, l, l2, hdl)
376 {
377 if (hdl == handler)
378 {
379 global_callbacks = eina_list_remove_list(global_callbacks, l);
380 free(hdl);
381 break;
382 }
383 }
384}
385
386EOLIAN void
387_elm_interface_atspi_accessible_translation_domain_set(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd, const char *domain)
388{
389 eina_stringshare_replace(&pd->translation_domain, domain);
390}
391
392
393EOLIAN const char*
394_elm_interface_atspi_accessible_translation_domain_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd)
395{
396 return pd->translation_domain;
397}
398
399EAPI void
400elm_atspi_relation_free(Elm_Atspi_Relation *relation)
401{
402 eina_list_free(relation->objects);
403 free(relation);
404}
405
406EAPI Elm_Atspi_Relation *
407elm_atspi_relation_clone(const Elm_Atspi_Relation *relation)
408{
409 Elm_Atspi_Relation *ret = calloc(1, sizeof(Elm_Atspi_Relation));
410 if (!ret) return NULL;
411
412 ret->type = relation->type;
413 ret->objects = eina_list_clone(relation->objects);
414 return ret;
415}
416
417static Eina_Bool
418_on_rel_obj_del(void *data, const Eo_Event *event)
419{
420 Elm_Atspi_Relation_Set *set = data;
421 Elm_Atspi_Relation *rel;
422 Eina_List *l, *l2, *p, *p2;
423 Eo *rel_obj;
424
425 EINA_LIST_FOREACH_SAFE(*set, l, l2, rel)
426 {
427 EINA_LIST_FOREACH_SAFE(rel->objects, p, p2, rel_obj)
428 {
429 if (rel_obj == event->obj)
430 rel->objects = eina_list_remove_list(rel->objects, p);
431 }
432 if (!rel->objects)
433 {
434 *set = eina_list_remove_list(*set, l);
435 free(rel);
436 }
437 }
438 return EINA_TRUE;
439}
440
441EAPI Eina_Bool
442elm_atspi_relation_set_relation_append(Elm_Atspi_Relation_Set *set, Elm_Atspi_Relation_Type type, const Eo *rel_obj)
443{
444 Elm_Atspi_Relation *rel;
445 Eina_List *l;
446
447 if (!eo_isa(rel_obj, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
448 return EINA_FALSE;
449
450 EINA_LIST_FOREACH(*set, l, rel)
451 {
452 if (rel->type == type)
453 {
454 if (!eina_list_data_find(rel->objects, rel_obj))
455 {
456 rel->objects = eina_list_append(rel->objects, rel_obj);
457 eo_event_callback_add((Eo *) rel_obj, EO_BASE_EVENT_DEL, _on_rel_obj_del, set);
458 }
459 return EINA_TRUE;
460 }
461 }
462
463 rel = calloc(1, sizeof(Elm_Atspi_Relation));
464 if (!rel) return EINA_FALSE;
465
466 rel->type = type;
467 rel->objects = eina_list_append(rel->objects, rel_obj);
468 *set = eina_list_append(*set, rel);
469
470 eo_event_callback_add((Eo *) rel_obj, EO_BASE_EVENT_DEL, _on_rel_obj_del, set);
471 return EINA_TRUE;
472}
473
474EAPI void
475elm_atspi_relation_set_relation_remove(Elm_Atspi_Relation_Set *set, Elm_Atspi_Relation_Type type, const Eo *rel_obj)
476{
477 Eina_List *l;
478 Elm_Atspi_Relation *rel;
479
480 EINA_LIST_FOREACH(*set, l, rel)
481 {
482 if (rel->type == type)
483 {
484 if (eina_list_data_find(rel->objects, rel_obj))
485 {
486 eo_event_callback_del((Eo *) rel_obj, EO_BASE_EVENT_DEL, _on_rel_obj_del, set);
487 rel->objects = eina_list_remove(rel->objects, rel_obj);
488 }
489 if (!rel->objects)
490 {
491 *set = eina_list_remove(*set, rel);
492 elm_atspi_relation_free(rel);
493 }
494 return;
495 }
496 }
497}
498
499EAPI void
500elm_atspi_relation_set_relation_type_remove(Elm_Atspi_Relation_Set *set, Elm_Atspi_Relation_Type type)
501{
502 Eina_List *l;
503 Elm_Atspi_Relation *rel;
504 Eo *obj;
505
506 EINA_LIST_FOREACH(*set, l, rel)
507 {
508 if (rel->type == type)
509 {
510 EINA_LIST_FOREACH(rel->objects, l, obj)
511 eo_event_callback_del(obj, EO_BASE_EVENT_DEL, _on_rel_obj_del, set);
512 *set = eina_list_remove(*set, rel);
513 elm_atspi_relation_free(rel);
514 return;
515 }
516 }
517}
518
519EAPI void
520elm_atspi_relation_set_free(Elm_Atspi_Relation_Set set)
521{
522 Elm_Atspi_Relation *rel;
523 Eina_List *l;
524 Eo *obj;
525
526 EINA_LIST_FREE(set, rel)
527 {
528 EINA_LIST_FOREACH(rel->objects, l, obj)
529 eo_event_callback_del(obj, EO_BASE_EVENT_DEL, _on_rel_obj_del, set);
530 elm_atspi_relation_free(rel);
531 }
532}
533
534EAPI Elm_Atspi_Relation_Set
535elm_atspi_relation_set_clone(const Elm_Atspi_Relation_Set set)
536{
537 Elm_Atspi_Relation_Set ret = NULL;
538 Eina_List *l;
539 Elm_Atspi_Relation *rel;
540
541 EINA_LIST_FOREACH(set, l, rel)
542 {
543 Elm_Atspi_Relation *cpy = elm_atspi_relation_clone(rel);
544 ret = eina_list_append(ret, cpy);
545 }
546
547 return ret;
548}
549
550EOLIAN static Eina_Bool
551_elm_interface_atspi_accessible_relationship_append(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *sd, Elm_Atspi_Relation_Type type, const Elm_Interface_Atspi_Accessible *relation_obj)
552{
553 return elm_atspi_relation_set_relation_append(&sd->relations, type, relation_obj);
554}
555
556EOLIAN static void
557_elm_interface_atspi_accessible_relationship_remove(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *sd, Elm_Atspi_Relation_Type type, const Elm_Interface_Atspi_Accessible *relation_obj)
558{
559 if (relation_obj)
560 elm_atspi_relation_set_relation_remove(&sd->relations, type, relation_obj);
561 else
562 elm_atspi_relation_set_relation_type_remove(&sd->relations, type);
563}
564
565EOLIAN static void
566_elm_interface_atspi_accessible_relationships_clear(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *sd)
567{
568 elm_atspi_relation_set_free(sd->relations);
569 sd->relations = NULL;
570}
571
572EOLIAN Eo*
573_elm_interface_atspi_accessible_root_get(Eo *class EINA_UNUSED, void *pd EINA_UNUSED)
574{
575 if (!root)
576 root = eo_add(ELM_ATSPI_APP_OBJECT_CLASS, NULL);
577
578 return root;
579}
580
581EOLIAN Elm_Atspi_Type
582_elm_interface_atspi_accessible_type_get(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd)
583{
584 return pd->type;
585}
586
587EOLIAN void
588_elm_interface_atspi_accessible_type_set(Eo *obj, Elm_Interface_Atspi_Accessible_Data *pd, Elm_Atspi_Type val)
589{
590 Elm_Interface_Atspi_Accessible *parent;
591 if (val == pd->type)
592 return;
593
594 parent = elm_interface_atspi_accessible_parent_get(obj);
595
596 switch (val)
597 {
598 case ELM_ATSPI_TYPE_DISABLED:
599 case ELM_ATSPI_TYPE_SKIPPED:
600 if (parent) elm_interface_atspi_accessible_children_changed_del_signal_emit(parent, obj);
601 elm_interface_atspi_accessible_removed(obj);
602 break;
603 case ELM_ATSPI_TYPE_REGULAR:
604 if (parent) elm_interface_atspi_accessible_children_changed_added_signal_emit(parent, obj);
605 elm_interface_atspi_accessible_added(obj);
606 }
607 pd->type = val;
608}
609
610#include "elm_interface_atspi_accessible.eo.c"