[access] move mouse postion if an object has a highlight by highlight_cycle(); not...
[framework/uifw/elementary.git] / src / lib / elm_access.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "elm_interface_scrollable.h"
4
5 static const char ACCESS_SMART_NAME[] = "elm_access";
6
7 ELM_INTERNAL_SMART_SUBCLASS_NEW
8   (ACCESS_SMART_NAME, _elm_access, Elm_Widget_Smart_Class,
9   Elm_Widget_Smart_Class, elm_widget_smart_class_get, NULL);
10
11 struct _Func_Data
12 {
13    void                *user_data; /* Holds user data to CB */
14    Elm_Access_Action_Cb cb;
15 };
16
17 typedef struct _Func_Data Func_Data;
18
19 struct _Action_Info
20 {
21    Evas_Object      *obj;
22    Func_Data         fn[ELM_ACCESS_ACTION_LAST + 1]; /* Callback for specific action */
23 };
24
25 typedef struct _Action_Info Action_Info;
26
27 static Eina_Bool mouse_event_enable = EINA_TRUE;
28 static Eina_Bool read_mode = EINA_FALSE;
29 static Evas_Coord_Point offset;
30 static Evas_Object *s_parent; /* scrollable parent */
31 static Elm_Access_Action_Type action_type = ELM_ACCESS_ACTION_FIRST;
32
33 static Evas_Object * _elm_access_add(Evas_Object *parent);
34
35 static void
36 _elm_access_smart_add(Evas_Object *obj)
37 {
38    EVAS_SMART_DATA_ALLOC(obj, Elm_Widget_Smart_Data);
39    ELM_WIDGET_CLASS(_elm_access_parent_sc)->base.add(obj);
40
41    elm_widget_can_focus_set(obj, EINA_TRUE);
42 }
43
44 static Eina_Bool
45 _elm_access_smart_on_focus(Evas_Object *obj)
46 {
47    evas_object_focus_set(obj, elm_widget_focus_get(obj));
48
49    return EINA_TRUE;
50 }
51
52 static Eina_Bool
53 _elm_access_smart_activate(Evas_Object *obj, Elm_Activate act)
54 {
55    int type = ELM_ACCESS_ACTION_FIRST;
56
57    Action_Info *a;
58    a = evas_object_data_get(obj, "_elm_access_action_info");
59
60    switch (act)
61      {
62       case ELM_ACTIVATE_DEFAULT:
63         type = ELM_ACCESS_ACTION_ACTIVATE;
64         break;
65
66       case ELM_ACTIVATE_UP:
67         type = ELM_ACCESS_ACTION_VALUE_CHANGE;
68         break;
69
70       case ELM_ACTIVATE_DOWN:
71         type = ELM_ACCESS_ACTION_VALUE_CHANGE;
72         break;
73
74       case ELM_ACTIVATE_RIGHT:
75         break;
76
77       case ELM_ACTIVATE_LEFT:
78         break;
79
80       default:
81         break;
82      }
83
84    if ((a) && (type > ELM_ACCESS_ACTION_FIRST) &&
85               (type < ELM_ACCESS_ACTION_LAST) &&
86               (a->fn[type].cb))
87      {
88         a->fn[type].cb(a->fn[type].user_data, obj, NULL);
89         return EINA_TRUE;
90      }
91
92    /* TODO: deprecate below? and change above with _access_action_callback_call(); */
93    if (act != ELM_ACTIVATE_DEFAULT) return EINA_FALSE;
94
95    Elm_Access_Info *ac = evas_object_data_get(obj, "_elm_access");
96    if (!ac) return EINA_FALSE;
97
98    if (ac->activate)
99      ac->activate(ac->activate_data, ac->part_object,
100                   (Elm_Object_Item *)ac->widget_item);
101
102    return EINA_TRUE;
103 }
104
105 static void
106 _elm_access_smart_set_user(Elm_Widget_Smart_Class *sc)
107 {
108    sc->base.add = _elm_access_smart_add;
109
110    /* not a 'focus chain manager' */
111    sc->focus_next = NULL;
112    sc->focus_direction = NULL;
113    sc->on_focus = _elm_access_smart_on_focus;
114    sc->activate = _elm_access_smart_activate;
115
116    return;
117 }
118
119 typedef struct _Mod_Api Mod_Api;
120
121 struct _Mod_Api
122 {
123    void (*out_read) (const char *txt);
124    void (*out_read_done) (void);
125    void (*out_cancel) (void);
126    void (*out_done_callback_set) (void (*func) (void *data), const void *data);
127 };
128
129 static int initted = 0;
130 static Mod_Api *mapi = NULL;
131
132 static void
133 _access_init(void)
134 {
135    Elm_Module *m;
136    initted++;
137    if (initted > 1) return;
138    if (!(m = _elm_module_find_as("access/api"))) return;
139    m->api = malloc(sizeof(Mod_Api));
140    if (!m->api) return;
141    m->init_func(m);
142    ((Mod_Api *)(m->api)      )->out_read = // called to read out some text
143       _elm_module_symbol_get(m, "out_read");
144    ((Mod_Api *)(m->api)      )->out_read_done = // called to set a done marker so when it is reached the done callback is called
145       _elm_module_symbol_get(m, "out_read_done");
146    ((Mod_Api *)(m->api)      )->out_cancel = // called to read out some text
147       _elm_module_symbol_get(m, "out_cancel");
148    ((Mod_Api *)(m->api)      )->out_done_callback_set = // called when last read done
149       _elm_module_symbol_get(m, "out_done_callback_set");
150    mapi = m->api;
151 }
152
153 static void
154 _access_shutdown(void)
155 {
156    Elm_Module *m;
157    if (initted == 0) return;
158    if (!(m = _elm_module_find_as("access/api"))) return;
159
160    m->shutdown_func(m);
161
162    initted = 0;
163
164    free(mapi);
165    mapi = NULL;
166 }
167
168 static Elm_Access_Item *
169 _access_add_set(Elm_Access_Info *ac, int type)
170 {
171    Elm_Access_Item *ai;
172    Eina_List *l;
173
174    if (!ac) return NULL;
175    EINA_LIST_FOREACH(ac->items, l, ai)
176      {
177         if (ai->type == type)
178           {
179              if (!ai->func)
180                {
181                   if (ai->data) eina_stringshare_del(ai->data);
182                }
183              ai->func = NULL;
184              ai->data = NULL;
185              return ai;
186           }
187      }
188    ai = calloc(1, sizeof(Elm_Access_Item));
189    ai->type = type;
190    ac->items = eina_list_prepend(ac->items, ai);
191    return ai;
192 }
193
194 static Evas_Object *
195 _access_highlight_object_get(Evas_Object *obj)
196 {
197    Evas_Object *o, *ho;
198
199    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
200    if (!o) return NULL;
201
202    ho = evas_object_data_get(o, "_elm_access_target");
203
204    return ho;
205 }
206
207 static void
208 _access_highlight_read(Elm_Access_Info *ac, Evas_Object *obj)
209 {
210    int type;
211    char *txt = NULL;
212    Eina_Strbuf *strbuf;
213
214    /*FIXME: TIZEN only - read at once because Tizen TTS engine performance is not good */
215    strbuf = eina_strbuf_new();
216
217    if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
218      {
219
220         if (ac->on_highlight) ac->on_highlight(ac->on_highlight_data);
221         _elm_access_object_hilight(obj);
222
223         for (type = ELM_ACCESS_INFO_FIRST + 1; type < ELM_ACCESS_INFO_LAST; type++)
224           {
225              txt = _elm_access_text_get(ac, type, obj);
226              if (txt && (strlen(txt) > 0))
227                {
228                   if (eina_strbuf_length_get(strbuf) > 0)
229                     eina_strbuf_append_printf(strbuf, ", %s", txt);
230                   else
231                     eina_strbuf_append(strbuf, txt);
232
233                   free(txt);
234                }
235           }
236      }
237
238    txt = eina_strbuf_string_steal(strbuf);
239    eina_strbuf_free(strbuf);
240
241    _elm_access_say(txt);
242    free(txt);
243 }
244
245 static Eina_Bool
246 _access_obj_over_timeout_cb(void *data)
247 {
248    Elm_Access_Info *ac;
249    Evas_Object *ho;
250
251    if (!data) return EINA_FALSE;
252
253    ac = evas_object_data_get(data, "_elm_access");
254    if (!ac) return EINA_FALSE;
255
256    ho = _access_highlight_object_get(data);
257    if (ho != data) _access_highlight_read(ac, data);
258
259    ac->delay_timer = NULL;
260    return EINA_FALSE;
261 }
262
263 static void
264 _access_obj_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
265 {
266    Elm_Access_Info *ac;
267    if (!mouse_event_enable) return;
268
269    ac = evas_object_data_get(data, "_elm_access");
270    if (!ac) return;
271
272    if (ac->delay_timer)
273      {
274         ecore_timer_del(ac->delay_timer);
275         ac->delay_timer = NULL;
276      }
277    if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
278       ac->delay_timer = ecore_timer_add(0.2, _access_obj_over_timeout_cb, data);
279 }
280
281 static void
282 _access_obj_mouse_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
283 {
284    Elm_Access_Info *ac;
285    if (!mouse_event_enable) return;
286
287    ac = evas_object_data_get(data, "_elm_access");
288    if (!ac) return;
289
290    _elm_access_object_unhilight(data);
291    if (ac->delay_timer)
292      {
293         ecore_timer_del(ac->delay_timer);
294         ac->delay_timer = NULL;
295      }
296 }
297
298 static void
299 _access_obj_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
300 {
301    _elm_access_object_unregister(data, obj);
302
303    // _elm_access_edje_object_part_object_register(); set below object data
304    evas_object_data_del(obj, "_part_access_obj");
305 }
306
307 static void
308 _access_read_done(void *data __UNUSED__)
309 {
310    printf("read done\n");
311    // FIXME: produce event here
312 }
313
314 static void
315 _access_2nd_click_del_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
316 {
317    Ecore_Timer *t;
318
319    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
320                                        _access_2nd_click_del_cb, NULL);
321    t = evas_object_data_get(obj, "_elm_2nd_timeout");
322    if (t)
323      {
324         ecore_timer_del(t);
325         evas_object_data_del(obj, "_elm_2nd_timeout");
326      }
327 }
328
329 static Eina_Bool
330 _access_2nd_click_timeout_cb(void *data)
331 {
332    evas_object_event_callback_del_full(data, EVAS_CALLBACK_DEL,
333                                        _access_2nd_click_del_cb, NULL);
334    evas_object_data_del(data, "_elm_2nd_timeout");
335    return EINA_FALSE;
336 }
337
338 static void
339 _access_obj_hilight_del_cb(void *data __UNUSED__, Evas *e, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
340 {
341    _elm_access_object_hilight_disable(e);
342 }
343
344 static void
345 _access_obj_hilight_hide_cb(void *data __UNUSED__, Evas *e, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
346 {
347    _elm_access_object_hilight_disable(e);
348 }
349
350 static void
351 _access_obj_hilight_move_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
352 {
353    Evas_Coord x, y;
354    Evas_Object *o;
355
356    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
357    if (!o) return;
358    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
359    evas_object_move(o, x, y);
360 }
361
362 static void
363 _access_obj_hilight_resize_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
364 {
365    Evas_Coord w, h;
366    Evas_Object *o;
367
368    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
369    if (!o) return;
370    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
371    evas_object_resize(o, w, h);
372 }
373
374 void
375 _elm_access_mouse_event_enabled_set(Eina_Bool enabled)
376 {
377    enabled = !!enabled;
378    if (mouse_event_enable == enabled) return;
379    mouse_event_enable = enabled;
380 }
381
382 void
383 _elm_access_read_mode_set(Eina_Bool enabled)
384 {
385    enabled = !!enabled;
386    if (read_mode == enabled) return;
387    read_mode = enabled;
388 }
389
390 Eina_Bool
391 _elm_access_read_mode_get()
392 {
393    return read_mode;
394 }
395
396 void
397 _elm_access_shutdown()
398 {
399    _access_shutdown();
400 }
401
402 static void
403 _access_order_del_cb(void *data,
404                      Evas *e __UNUSED__,
405                      Evas_Object *obj,
406                      void *event_info __UNUSED__)
407 {
408    Elm_Widget_Item *item = data;
409
410    item->access_order = eina_list_remove(item->access_order, obj);
411 }
412
413 void
414 _elm_access_widget_item_access_order_set(Elm_Widget_Item *item,
415                                               Eina_List *objs)
416 {
417    Eina_List *l;
418    Evas_Object *o;
419
420    if (!item) return;
421
422    _elm_access_widget_item_access_order_unset(item);
423
424    EINA_LIST_FOREACH(objs, l, o)
425      {
426         evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
427                                        _access_order_del_cb, item);
428      }
429
430    item->access_order = objs;
431 }
432
433 const Eina_List *
434 _elm_access_widget_item_access_order_get(const Elm_Widget_Item *item)
435 {
436    if (!item) return NULL;
437    return item->access_order;
438 }
439
440 void
441 _elm_access_widget_item_access_order_unset(Elm_Widget_Item *item)
442 {
443    Eina_List *l, *l_next;
444    Evas_Object *o;
445
446    if (!item) return;
447
448    EINA_LIST_FOREACH_SAFE(item->access_order, l, l_next, o)
449      {
450         evas_object_event_callback_del_full
451           (o, EVAS_CALLBACK_DEL, _access_order_del_cb, item);
452         item->access_order = eina_list_remove_list(item->access_order, l);
453      }
454 }
455
456 void
457 _elm_access_highlight_object_scroll(Evas_Object *obj, int type, int x, int y)
458 {
459    Evas *evas;
460    Evas_Object *ho;
461    Evas_Coord_Rectangle ho_area;
462
463    if (!obj) return;
464
465    evas = evas_object_evas_get(obj);
466    if (!evas) return;
467
468    switch (type)
469      {
470       case 0:
471         ho = _access_highlight_object_get(obj);
472         if (!ho)
473           {
474              s_parent = NULL;
475              return;
476           }
477         else
478           {
479              /* find scrollable parent */
480              s_parent = elm_widget_parent_get(ho);
481              while (s_parent)
482                {
483                   if(!!evas_object_smart_interface_get(s_parent, ELM_SCROLLABLE_IFACE_NAME))
484                     break;
485                   s_parent = elm_widget_parent_get(s_parent);
486                }
487
488               if (!s_parent) return;
489
490               ELM_SCROLLABLE_IFACE_GET(s_parent, s_iface);
491               s_iface->repeat_events_set(s_parent, EINA_FALSE);
492
493               evas_object_geometry_get
494                 (ho, &ho_area.x, &ho_area.y, &ho_area.w, &ho_area.h);
495
496               offset.x = x - (ho_area.x + (ho_area.w / 2));
497               offset.y = y - (ho_area.y + (ho_area.h / 2));
498           }
499
500         evas_event_feed_mouse_in(evas, 0, NULL);
501         evas_event_feed_mouse_move(evas, x - offset.x, y - offset.y, 0, NULL);
502         evas_event_feed_mouse_down(evas, 1, EVAS_BUTTON_NONE, 0, NULL);
503         break;
504
505       case 1:
506         if (!s_parent) return;
507         evas_event_feed_mouse_move(evas, x - offset.x, y - offset.y, 0, NULL);
508         break;
509
510       case 2:
511         if (!s_parent) return;
512         evas_event_feed_mouse_up(evas, 1, EVAS_BUTTON_NONE, 0, NULL);
513
514         ELM_SCROLLABLE_IFACE_GET(s_parent, s_iface);
515         s_iface->repeat_events_set(s_parent, EINA_TRUE);
516         break;
517
518       default:
519         break;
520      }
521 }
522
523 static Eina_Bool
524 _access_action_callback_call(Evas_Object *obj,
525                              Elm_Access_Action_Type type,
526                              void *data)
527 {
528    Action_Info *a;
529    Eina_Bool ret;
530
531    ret = EINA_FALSE;
532    a = evas_object_data_get(obj, "_elm_access_action_info");
533
534    if (a && (a->fn[type].cb))
535      ret = a->fn[type].cb(a->fn[type].user_data, obj, data);
536
537    return ret;
538 }
539
540 static Eina_Bool
541 _access_highlight_next_get(Evas_Object *obj, Elm_Focus_Direction dir)
542 {
543    int type;
544    Evas_Object *ho, *parent, *target;
545    Eina_Bool ret;
546
547    target = NULL;
548    ret = EINA_FALSE;
549
550    if (!elm_widget_is(obj)) return ret;
551
552    ho = _access_highlight_object_get(obj);
553    if (!ho) return ret;
554
555    parent = ho;
556
557    /* find highlight root */
558    do
559      {
560         ELM_WIDGET_DATA_GET(parent, sd);
561         if (sd->highlight_root)
562           {
563              /* change highlight root */
564              obj = parent;
565              break;
566           }
567         parent = elm_widget_parent_get(parent);
568      }
569    while (parent);
570
571    _elm_access_read_mode_set(EINA_TRUE);
572
573    ret = elm_widget_focus_next_get(obj, dir, &target);
574    if (ret && target)
575      {
576         if (dir == ELM_FOCUS_NEXT)
577           type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
578         else
579           type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
580
581         if (!_access_action_callback_call(ho, type, NULL))
582           {
583              /* change highlight object */
584              action_type = type;
585
586              _elm_access_highlight_set(target);
587              ret = EINA_FALSE;
588
589              action_type = ELM_ACCESS_ACTION_FIRST;
590           }
591      }
592
593    _elm_access_read_mode_set(EINA_FALSE);
594
595    return ret;
596 }
597
598 //-------------------------------------------------------------------------//
599 EAPI void
600 _elm_access_highlight_set(Evas_Object* obj)
601 {
602    Evas *evas;
603    Elm_Access_Info *ac;
604    Evas_Object *ho;
605    Evas_Coord_Point ho_point = { 0, 0 };
606
607    if (!obj) return;
608
609    ho = _access_highlight_object_get(obj);
610    if (ho == obj) return;
611
612    ac = evas_object_data_get(obj, "_elm_access");
613    if (!ac) return;
614
615    _access_highlight_read(ac, obj);
616
617    /* move mouse position to inside of highlight object. if an object has a
618       highlight by highlight_cycle();, the mouse still positions at previous
619       position which would be made by MOUSE_IN event. */
620    evas = evas_object_evas_get(obj);
621    if (!evas) return;
622
623    evas_object_geometry_get(obj, &ho_point.x, &ho_point.y, 0, 0);
624    evas_event_feed_mouse_move(evas, ho_point.x, ho_point.y, 0, NULL);
625 }
626
627 EAPI void
628 _elm_access_clear(Elm_Access_Info *ac)
629 {
630    Elm_Access_Item *ai;
631
632    if (!ac) return;
633    if (ac->delay_timer)
634      {
635         ecore_timer_del(ac->delay_timer);
636         ac->delay_timer = NULL;
637      }
638    EINA_LIST_FREE(ac->items, ai)
639      {
640         if (!ai->func)
641           {
642              if (ai->data) eina_stringshare_del(ai->data);
643           }
644         free(ai);
645      }
646 }
647
648 EAPI void
649 _elm_access_text_set(Elm_Access_Info *ac, int type, const char *text)
650 {
651    Elm_Access_Item *ai = _access_add_set(ac, type);
652    if (!ai) return;
653    ai->data = eina_stringshare_add(text);
654 }
655
656 EAPI void
657 _elm_access_callback_set(Elm_Access_Info *ac, int type, Elm_Access_Info_Cb func, const void *data)
658 {
659    Elm_Access_Item *ai = _access_add_set(ac, type);
660    if (!ai) return;
661    ai->func = func;
662    ai->data = data;
663 }
664
665 EAPI void
666 _elm_access_on_highlight_hook_set(Elm_Access_Info           *ac,
667                                   Elm_Access_On_Highlight_Cb func,
668                                   void                      *data)
669 {
670     if (!ac) return;
671     ac->on_highlight = func;
672     ac->on_highlight_data = data;
673 }
674
675 EAPI void
676 _elm_access_activate_callback_set(Elm_Access_Info           *ac,
677                                   Elm_Access_Activate_Cb     func,
678                                   void                      *data)
679 {
680    if (!ac) return;
681    ac->activate = func;
682    ac->activate_data = data;
683 }
684
685 EAPI void
686 _elm_access_highlight_object_activate(Evas_Object *obj, Elm_Activate act)
687 {
688    Evas_Object *highlight;
689
690    highlight = _access_highlight_object_get(obj);
691    if (!highlight) return;
692
693    _elm_access_read_mode_set(EINA_FALSE);
694
695    if (!elm_object_focus_get(highlight))
696      elm_object_focus_set(highlight, EINA_TRUE);
697
698    elm_widget_activate(highlight, act);
699    return;
700 }
701
702 EAPI void
703 _elm_access_highlight_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
704 {
705    int type;
706    Evas_Object *ho, *parent;
707
708    ho = _access_highlight_object_get(obj);
709    if (!ho) return;
710
711    parent = ho;
712
713    /* find highlight root */
714    do
715      {
716         ELM_WIDGET_DATA_GET(parent, sd);
717         if (sd->highlight_root)
718           {
719              /* change highlight root */
720              obj = parent;
721              break;
722           }
723         parent = elm_widget_parent_get(parent);
724      }
725    while (parent);
726
727    _elm_access_read_mode_set(EINA_TRUE);
728
729    if (dir == ELM_FOCUS_NEXT)
730      type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
731    else
732      type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
733
734    action_type = type;
735
736    if (!_access_action_callback_call(ho, type, NULL))
737      elm_widget_focus_cycle(obj, dir);
738
739    action_type = ELM_ACCESS_ACTION_FIRST;
740
741    _elm_access_read_mode_set(EINA_FALSE);
742 }
743
744 EAPI char *
745 _elm_access_text_get(const Elm_Access_Info *ac, int type, const Evas_Object *obj)
746 {
747    Elm_Access_Item *ai;
748    Eina_List *l;
749
750    if (!ac) return NULL;
751    EINA_LIST_FOREACH(ac->items, l, ai)
752      {
753         if (ai->type == type)
754           {
755              if (ai->func) return ai->func((void *)(ai->data), (Evas_Object *)obj);
756              else if (ai->data) return strdup(ai->data);
757              return NULL;
758           }
759      }
760    return NULL;
761 }
762
763 EAPI void
764 _elm_access_read(Elm_Access_Info *ac, int type, const Evas_Object *obj)
765 {
766    char *txt = _elm_access_text_get(ac, type, obj);
767
768    if (txt && strlen(txt) == 0) return; /* Tizen only: TTS engine does not work properly */
769
770    _access_init();
771    if (mapi)
772      {
773         if (mapi->out_done_callback_set)
774            mapi->out_done_callback_set(_access_read_done, NULL);
775         if (type == ELM_ACCESS_DONE)
776           {
777              if (mapi->out_read_done) mapi->out_read_done();
778           }
779         else if (type == ELM_ACCESS_CANCEL)
780           {
781              if (mapi->out_cancel) mapi->out_cancel();
782           }
783         else
784           {
785              if (txt && mapi->out_read) mapi->out_read(txt);
786           }
787      }
788    if (txt) free(txt);
789 }
790
791 EAPI void
792 _elm_access_say(const char *txt)
793 {
794    if (!_elm_config->access_mode) return;
795
796    if (txt && strlen(txt) == 0) return; /* Tizen only: TTS engine does not work properly */
797
798    _access_init();
799    if (mapi)
800      {
801         if (mapi->out_done_callback_set)
802            mapi->out_done_callback_set(_access_read_done, NULL);
803         if (mapi->out_cancel) mapi->out_cancel();
804         if (txt)
805           {
806              if (mapi->out_read) mapi->out_read(txt);
807              //if (mapi->out_read) mapi->out_read(".\n"); /* TIZEN only: Tizen TTS engine performance is not good */
808           }
809         if (mapi->out_read_done) mapi->out_read_done();
810      }
811 }
812
813 EAPI Elm_Access_Info *
814 _elm_access_object_get(const Evas_Object *obj)
815 {
816    return evas_object_data_get(obj, "_elm_access");
817 }
818
819 EAPI void
820 _elm_access_object_hilight(Evas_Object *obj)
821 {
822    Evas_Object *o;
823    Evas_Coord x, y, w, h;
824    Elm_Access_Action_Info *a;
825
826    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
827    if (!o)
828      {
829         o = edje_object_add(evas_object_evas_get(obj));
830         evas_object_name_set(o, "_elm_access_disp");
831         evas_object_layer_set(o, ELM_OBJECT_LAYER_TOOLTIP);
832      }
833    else
834      {
835         Evas_Object *ptarget = evas_object_data_get(o, "_elm_access_target");
836         if (ptarget)
837           {
838              evas_object_data_del(o, "_elm_access_target");
839              elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
840
841              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
842                                                  _access_obj_hilight_del_cb, NULL);
843              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
844                                                  _access_obj_hilight_hide_cb, NULL);
845              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
846                                                  _access_obj_hilight_move_cb, NULL);
847              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
848                                                  _access_obj_hilight_resize_cb, NULL);
849              _access_action_callback_call(ptarget, ELM_ACCESS_ACTION_UNHIGHLIGHT, NULL);
850           }
851      }
852    evas_object_data_set(o, "_elm_access_target", obj);
853    elm_widget_parent_highlight_set(obj, EINA_TRUE);
854
855    elm_widget_theme_object_set(obj, o, "access", "base", "default");
856
857    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
858                                   _access_obj_hilight_del_cb, NULL);
859    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE,
860                                   _access_obj_hilight_hide_cb, NULL);
861    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
862                                   _access_obj_hilight_move_cb, NULL);
863    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
864                                   _access_obj_hilight_resize_cb, NULL);
865    evas_object_raise(o);
866    evas_object_geometry_get(obj, &x, &y, &w, &h);
867    evas_object_move(o, x, y);
868    evas_object_resize(o, w, h);
869
870    /* use callback, should an access object do below every time when
871         * a window gets a client message ECORE_X_ATOM_E_ILLMUE_ACTION_READ? */
872    a = calloc(1, sizeof(Elm_Access_Action_Info));
873    a->action_type = action_type;
874    if (!_access_action_callback_call(obj, ELM_ACCESS_ACTION_HIGHLIGHT, a))
875      evas_object_show(o);
876    else
877      evas_object_hide(o);
878    free(a);
879 }
880
881 EAPI void
882 _elm_access_object_unhilight(Evas_Object *obj)
883 {
884    Evas_Object *o, *ptarget;
885
886    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
887    if (!o) return;
888    ptarget = evas_object_data_get(o, "_elm_access_target");
889    if (ptarget == obj)
890      {
891         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
892                                             _access_obj_hilight_del_cb, NULL);
893         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
894                                             _access_obj_hilight_hide_cb, NULL);
895         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
896                                             _access_obj_hilight_move_cb, NULL);
897         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
898                                             _access_obj_hilight_resize_cb, NULL);
899         evas_object_del(o);
900         elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
901         _access_action_callback_call(ptarget, ELM_ACCESS_ACTION_UNHIGHLIGHT, NULL);
902      }
903 }
904
905 static void
906 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
907                 void *event_info __UNUSED__)
908 {
909    Evas_Object *accessobj;
910    Evas_Coord w, h;
911
912    accessobj = data;
913    if (!accessobj) return;
914
915    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
916    evas_object_resize(accessobj, w, h);
917 }
918
919 static void
920 _content_move(void *data, Evas *e __UNUSED__, Evas_Object *obj,
921               void *event_info __UNUSED__)
922 {
923    Evas_Object *accessobj;
924    Evas_Coord x, y;
925
926    accessobj = data;
927    if (!accessobj) return;
928
929    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
930    evas_object_move(accessobj, x, y);
931 }
932
933 static Evas_Object *
934 _access_object_register(Evas_Object *obj, Evas_Object *parent)
935 {
936    Evas_Object *ao;
937    Elm_Access_Info *ac;
938    Evas_Coord x, y, w, h;
939
940    if (!obj) return NULL;
941
942    /* create access object */
943    ao = _elm_access_add(parent);
944    if (!ao) return NULL;
945
946    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
947                                   _content_resize, ao);
948    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
949                                   _content_move, ao);
950
951    evas_object_geometry_get(obj, &x, &y, &w, &h);
952    evas_object_move(ao, x, y);
953    evas_object_resize(ao, w, h);
954    evas_object_show(ao);
955
956    /* register access object */
957    _elm_access_object_register(ao, obj);
958
959    /* set access object */
960    evas_object_data_set(obj, "_part_access_obj", ao);
961
962    /* set owner part object */
963    ac = evas_object_data_get(ao, "_elm_access");
964    ac->part_object = obj;
965
966    return ao;
967 }
968
969 static void
970 _access_object_unregister(Evas_Object *obj)
971 {
972    Elm_Access_Info *ac;
973    Evas_Object *ao;
974
975    if (!obj) return;
976
977    ao = evas_object_data_get(obj, "_part_access_obj");
978
979    if (ao)
980      {
981         evas_object_data_del(obj, "_part_access_obj");
982
983         /* delete callbacks */
984         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
985                                             _content_resize, ao);
986         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE,
987                                             _content_move, ao);
988
989         /* unregister access object */
990         _elm_access_object_unregister(ao, obj);
991
992         evas_object_del(ao);
993      }
994    else
995      {
996         /* button, check, label etc. */
997         ac = evas_object_data_get(obj, "_elm_access");
998         if (ac && ac->hoverobj)
999           _elm_access_object_unregister(obj, ac->hoverobj);
1000      }
1001 }
1002
1003 EAPI Evas_Object *
1004 _elm_access_edje_object_part_object_register(Evas_Object* obj,
1005                                              const Evas_Object *eobj,
1006                                              const char* part)
1007 {
1008    Evas_Object *ao, *po;
1009
1010    po = (Evas_Object *)edje_object_part_object_get(eobj, part);
1011    if (!obj || !po) return NULL;
1012
1013    /* check previous access object */
1014    ao = evas_object_data_get(po, "_part_access_obj");
1015    if (ao)
1016      _elm_access_edje_object_part_object_unregister(obj, eobj, part);
1017
1018    ao = _access_object_register(po, obj);
1019
1020    return ao;
1021 }
1022
1023 //FIXME: unused obj should be removed from here and each widget.
1024 EAPI void
1025 _elm_access_edje_object_part_object_unregister(Evas_Object* obj __UNUSED__,
1026                                                const Evas_Object *eobj,
1027                                                const char* part)
1028 {
1029    Evas_Object *po;
1030
1031    po = (Evas_Object *)edje_object_part_object_get(eobj, part);
1032    if (!po) return;
1033
1034    _access_object_unregister(po);
1035 }
1036
1037 EAPI void
1038 _elm_access_object_hilight_disable(Evas *e)
1039 {
1040    Evas_Object *o, *ptarget;
1041
1042    o = evas_object_name_find(e, "_elm_access_disp");
1043    if (!o) return;
1044    ptarget = evas_object_data_get(o, "_elm_access_target");
1045    if (ptarget)
1046      {
1047         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
1048                                             _access_obj_hilight_del_cb, NULL);
1049         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
1050                                             _access_obj_hilight_hide_cb, NULL);
1051         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
1052                                             _access_obj_hilight_move_cb, NULL);
1053         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
1054                                             _access_obj_hilight_resize_cb, NULL);
1055      }
1056    evas_object_del(o);
1057    elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
1058 }
1059
1060 EAPI void
1061 _elm_access_object_register(Evas_Object *obj, Evas_Object *hoverobj)
1062 {
1063    Elm_Access_Info *ac;
1064
1065    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_IN,
1066                                   _access_obj_mouse_in_cb, obj);
1067    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_OUT,
1068                                   _access_obj_mouse_out_cb, obj);
1069    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_DEL,
1070                                   _access_obj_del_cb, obj);
1071    ac = calloc(1, sizeof(Elm_Access_Info));
1072    evas_object_data_set(obj, "_elm_access", ac);
1073
1074    ac->hoverobj = hoverobj;
1075 }
1076
1077 EAPI void
1078 _elm_access_object_unregister(Evas_Object *obj, Evas_Object *hoverobj)
1079 {
1080    Elm_Access_Info *ac;
1081
1082    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_MOUSE_IN,
1083                                        _access_obj_mouse_in_cb, obj);
1084    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_MOUSE_OUT,
1085                                        _access_obj_mouse_out_cb, obj);
1086    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_DEL,
1087                                        _access_obj_del_cb, obj);
1088
1089    ac = evas_object_data_get(obj, "_elm_access");
1090    evas_object_data_del(obj, "_elm_access");
1091    if (ac)
1092      {
1093         _elm_access_clear(ac);
1094         free(ac);
1095      }
1096
1097    Action_Info *a;
1098    a = evas_object_data_get(obj, "_elm_access_action_info");
1099    if (a) free(a);
1100 }
1101
1102 EAPI void
1103 _elm_access_widget_item_register(Elm_Widget_Item *item)
1104 {
1105    Evas_Object *ao, *ho;
1106    Evas_Coord x, y, w, h;
1107    Elm_Access_Info *ac;
1108
1109    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
1110
1111    /* check previous access object */
1112    if (item->access_obj)
1113      _elm_access_widget_item_unregister(item);
1114
1115    // create access object
1116    ho = item->view;
1117    ao = _elm_access_add(item->widget);
1118    if (!ao) return;
1119
1120    evas_object_event_callback_add(ho, EVAS_CALLBACK_RESIZE,
1121                                   _content_resize, ao);
1122    evas_object_event_callback_add(ho, EVAS_CALLBACK_MOVE,
1123                                   _content_move, ao);
1124
1125    evas_object_geometry_get(ho, &x, &y, &w, &h);
1126    evas_object_move(ao, x, y);
1127    evas_object_resize(ao, w, h);
1128    evas_object_show(ao);
1129
1130    // register access object
1131    _elm_access_object_register(ao, ho);
1132
1133    item->access_obj = ao;
1134
1135    /* set owner widget item */
1136    ac = evas_object_data_get(ao, "_elm_access");
1137    ac->widget_item = item;
1138 }
1139
1140 EAPI void
1141 _elm_access_widget_item_unregister(Elm_Widget_Item *item)
1142 {
1143    Evas_Object *ho;
1144
1145    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
1146
1147    if (!item->access_obj) return;
1148
1149    ho = item->view;
1150    evas_object_event_callback_del_full(ho, EVAS_CALLBACK_RESIZE,
1151                                   _content_resize, item->access_obj);
1152    evas_object_event_callback_del_full(ho, EVAS_CALLBACK_MOVE,
1153                                   _content_move, item->access_obj);
1154
1155    _elm_access_object_unregister(item->access_obj, ho);
1156
1157    evas_object_del(item->access_obj);
1158    item->access_obj = NULL;
1159 }
1160
1161 EAPI Eina_Bool
1162 _elm_access_2nd_click_timeout(Evas_Object *obj)
1163 {
1164    Ecore_Timer *t;
1165
1166    t = evas_object_data_get(obj, "_elm_2nd_timeout");
1167    if (t)
1168      {
1169         ecore_timer_del(t);
1170         evas_object_data_del(obj, "_elm_2nd_timeout");
1171         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
1172                                             _access_2nd_click_del_cb, NULL);
1173         return EINA_TRUE;
1174      }
1175    t = ecore_timer_add(0.3, _access_2nd_click_timeout_cb, obj);
1176    evas_object_data_set(obj, "_elm_2nd_timeout", t);
1177    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
1178                                   _access_2nd_click_del_cb, NULL);
1179    return EINA_FALSE;
1180 }
1181
1182 static Evas_Object *
1183 _elm_access_add(Evas_Object *parent)
1184 {
1185    Evas_Object *obj;
1186
1187    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1188
1189    obj = elm_widget_add(_elm_access_smart_class_new(), parent);
1190    if (!obj) return NULL;
1191
1192    if (!elm_widget_sub_object_add(parent, obj))
1193      ERR("could not add %p as sub object of %p", obj, parent);
1194
1195    return obj;
1196 }
1197
1198 EAPI Evas_Object *
1199 elm_access_object_register(Evas_Object *obj, Evas_Object *parent)
1200 {
1201    return _access_object_register(obj, parent);
1202 }
1203
1204 EAPI void
1205 elm_access_object_unregister(Evas_Object *obj)
1206 {
1207    _access_object_unregister(obj);
1208 }
1209
1210 EAPI Evas_Object *
1211 elm_access_object_get(const Evas_Object *obj)
1212 {
1213    return evas_object_data_get(obj, "_part_access_obj");
1214 }
1215
1216 EAPI void
1217 elm_access_info_set(Evas_Object *obj, int type, const char *text)
1218 {
1219    _elm_access_text_set(_elm_access_object_get(obj), type, text);
1220 }
1221
1222 EAPI char *
1223 elm_access_info_get(const Evas_Object *obj, int type)
1224 {
1225    return _elm_access_text_get(_elm_access_object_get(obj), type, obj);
1226 }
1227
1228 EAPI void
1229 elm_access_info_cb_set(Evas_Object *obj, int type,
1230                           Elm_Access_Info_Cb func, const void *data)
1231 {
1232    _elm_access_callback_set(_elm_access_object_get(obj), type, func, data);
1233 }
1234
1235 EAPI void
1236 elm_access_activate_cb_set(Evas_Object *obj,
1237                            Elm_Access_Activate_Cb  func, void *data)
1238 {
1239    Elm_Access_Info *ac;
1240
1241    ac = _elm_access_object_get(obj);
1242    if (!ac) return;
1243
1244    ac->activate = func;
1245    ac->activate_data = data;
1246 }
1247
1248 EAPI void
1249 elm_access_say(const char *text)
1250 {
1251    if (!text) return;
1252
1253    _elm_access_say(text);
1254 }
1255
1256 EAPI void
1257 elm_access_highlight_set(Evas_Object* obj)
1258 {
1259    _elm_access_highlight_set(obj);
1260 }
1261
1262 EAPI Eina_Bool
1263 elm_access_action(Evas_Object *obj, const Elm_Access_Action_Type type, void *action_info)
1264 {
1265    Evas *evas;
1266    Evas_Object *ho;
1267    Elm_Access_Action_Info *a;
1268
1269    a = (Elm_Access_Action_Info *) action_info;
1270
1271    switch (type)
1272      {
1273       case ELM_ACCESS_ACTION_READ:
1274       case ELM_ACCESS_ACTION_HIGHLIGHT:
1275         evas = evas_object_evas_get(obj);
1276         if (!evas) return EINA_FALSE;
1277
1278         _elm_access_mouse_event_enabled_set(EINA_TRUE);
1279
1280         evas_event_feed_mouse_in(evas, 0, NULL);
1281         evas_event_feed_mouse_move(evas, a->x, a->y, 0, NULL);
1282         _elm_access_mouse_event_enabled_set(EINA_FALSE);
1283
1284         ho = _access_highlight_object_get(obj);
1285         if (ho)
1286           _access_action_callback_call(ho, ELM_ACCESS_ACTION_READ, a);
1287         break;
1288
1289       case ELM_ACCESS_ACTION_UNHIGHLIGHT:
1290         break;
1291
1292       case ELM_ACCESS_ACTION_HIGHLIGHT_NEXT:
1293         if (a->highlight_cycle)
1294           _elm_access_highlight_cycle(obj, ELM_FOCUS_NEXT);
1295         else
1296           return _access_highlight_next_get(obj, ELM_FOCUS_NEXT);
1297         break;
1298
1299       case ELM_ACCESS_ACTION_HIGHLIGHT_PREV:
1300         if (a->highlight_cycle)
1301           _elm_access_highlight_cycle(obj, ELM_FOCUS_PREVIOUS);
1302         else
1303           return _access_highlight_next_get(obj, ELM_FOCUS_PREVIOUS);
1304         break;
1305
1306       case ELM_ACCESS_ACTION_ACTIVATE:
1307         _elm_access_highlight_object_activate(obj, ELM_ACTIVATE_DEFAULT);
1308         break;
1309
1310       case ELM_ACCESS_ACTION_VALUE_CHANGE:
1311         _elm_access_highlight_object_activate(obj, ELM_ACTIVATE_UP);
1312         break;
1313
1314       case ELM_ACCESS_ACTION_SCROLL:
1315         break;
1316
1317       case ELM_ACCESS_ACTION_BACK:
1318         break;
1319
1320       default:
1321         break;
1322      }
1323
1324    return EINA_TRUE;
1325 }
1326
1327 EAPI void
1328 elm_access_action_cb_set(Evas_Object *obj, const Elm_Access_Action_Type type, const Elm_Access_Action_Cb cb, const void *data)
1329 {
1330    Action_Info *a;
1331    a =  evas_object_data_get(obj, "_elm_access_action_info");
1332
1333    if (!a)
1334      {
1335         a = calloc(1, sizeof(Action_Info));
1336         evas_object_data_set(obj, "_elm_access_action_info", a);
1337      }
1338
1339    a->obj = obj;
1340    a->fn[type].cb = cb;
1341    a->fn[type].user_data = (void *)data;
1342 }
1343
1344 EAPI void
1345 elm_access_external_info_set(Evas_Object *obj, const char *text)
1346 {
1347    _elm_access_text_set
1348      (_elm_access_object_get(obj), ELM_ACCESS_CONTEXT_INFO, text);
1349 }
1350
1351 EAPI char *
1352 elm_access_external_info_get(const Evas_Object *obj)
1353 {
1354    Elm_Access_Info *ac;
1355
1356    ac = _elm_access_object_get(obj);
1357    return _elm_access_text_get(ac, ELM_ACCESS_CONTEXT_INFO, obj);
1358 }