[access] call a callback function with information
[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    Elm_Access_Info *ac;
603    Evas_Object *ho;
604
605    if (!obj) return;
606
607    ho = _access_highlight_object_get(obj);
608    if (ho == obj) return;
609
610    ac = evas_object_data_get(obj, "_elm_access");
611    if (!ac) return;
612
613    _access_highlight_read(ac, obj);
614 }
615
616 EAPI void
617 _elm_access_clear(Elm_Access_Info *ac)
618 {
619    Elm_Access_Item *ai;
620
621    if (!ac) return;
622    if (ac->delay_timer)
623      {
624         ecore_timer_del(ac->delay_timer);
625         ac->delay_timer = NULL;
626      }
627    EINA_LIST_FREE(ac->items, ai)
628      {
629         if (!ai->func)
630           {
631              if (ai->data) eina_stringshare_del(ai->data);
632           }
633         free(ai);
634      }
635 }
636
637 EAPI void
638 _elm_access_text_set(Elm_Access_Info *ac, int type, const char *text)
639 {
640    Elm_Access_Item *ai = _access_add_set(ac, type);
641    if (!ai) return;
642    ai->data = eina_stringshare_add(text);
643 }
644
645 EAPI void
646 _elm_access_callback_set(Elm_Access_Info *ac, int type, Elm_Access_Info_Cb func, const void *data)
647 {
648    Elm_Access_Item *ai = _access_add_set(ac, type);
649    if (!ai) return;
650    ai->func = func;
651    ai->data = data;
652 }
653
654 EAPI void
655 _elm_access_on_highlight_hook_set(Elm_Access_Info           *ac,
656                                   Elm_Access_On_Highlight_Cb func,
657                                   void                      *data)
658 {
659     if (!ac) return;
660     ac->on_highlight = func;
661     ac->on_highlight_data = data;
662 }
663
664 EAPI void
665 _elm_access_activate_callback_set(Elm_Access_Info           *ac,
666                                   Elm_Access_Activate_Cb     func,
667                                   void                      *data)
668 {
669    if (!ac) return;
670    ac->activate = func;
671    ac->activate_data = data;
672 }
673
674 EAPI void
675 _elm_access_highlight_object_activate(Evas_Object *obj, Elm_Activate act)
676 {
677    Evas_Object *highlight;
678
679    highlight = _access_highlight_object_get(obj);
680    if (!highlight) return;
681
682    _elm_access_read_mode_set(EINA_FALSE);
683
684    if (!elm_object_focus_get(highlight))
685      elm_object_focus_set(highlight, EINA_TRUE);
686
687    elm_widget_activate(highlight, act);
688    return;
689 }
690
691 EAPI void
692 _elm_access_highlight_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
693 {
694    int type;
695    Evas_Object *ho, *parent;
696
697    ho = _access_highlight_object_get(obj);
698    if (!ho) return;
699
700    parent = ho;
701
702    /* find highlight root */
703    do
704      {
705         ELM_WIDGET_DATA_GET(parent, sd);
706         if (sd->highlight_root)
707           {
708              /* change highlight root */
709              obj = parent;
710              break;
711           }
712         parent = elm_widget_parent_get(parent);
713      }
714    while (parent);
715
716    _elm_access_read_mode_set(EINA_TRUE);
717
718    if (dir == ELM_FOCUS_NEXT)
719      type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
720    else
721      type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
722
723    action_type = type;
724
725    if (!_access_action_callback_call(ho, type, NULL))
726      elm_widget_focus_cycle(obj, dir);
727
728    action_type = ELM_ACCESS_ACTION_FIRST;
729
730    _elm_access_read_mode_set(EINA_FALSE);
731 }
732
733 EAPI char *
734 _elm_access_text_get(const Elm_Access_Info *ac, int type, const Evas_Object *obj)
735 {
736    Elm_Access_Item *ai;
737    Eina_List *l;
738
739    if (!ac) return NULL;
740    EINA_LIST_FOREACH(ac->items, l, ai)
741      {
742         if (ai->type == type)
743           {
744              if (ai->func) return ai->func((void *)(ai->data), (Evas_Object *)obj);
745              else if (ai->data) return strdup(ai->data);
746              return NULL;
747           }
748      }
749    return NULL;
750 }
751
752 EAPI void
753 _elm_access_read(Elm_Access_Info *ac, int type, const Evas_Object *obj)
754 {
755    char *txt = _elm_access_text_get(ac, type, obj);
756
757    if (txt && strlen(txt) == 0) return; /* Tizen only: TTS engine does not work properly */
758
759    _access_init();
760    if (mapi)
761      {
762         if (mapi->out_done_callback_set)
763            mapi->out_done_callback_set(_access_read_done, NULL);
764         if (type == ELM_ACCESS_DONE)
765           {
766              if (mapi->out_read_done) mapi->out_read_done();
767           }
768         else if (type == ELM_ACCESS_CANCEL)
769           {
770              if (mapi->out_cancel) mapi->out_cancel();
771           }
772         else
773           {
774              if (txt && mapi->out_read) mapi->out_read(txt);
775           }
776      }
777    if (txt) free(txt);
778 }
779
780 EAPI void
781 _elm_access_say(const char *txt)
782 {
783    if (!_elm_config->access_mode) return;
784
785    if (txt && strlen(txt) == 0) return; /* Tizen only: TTS engine does not work properly */
786
787    _access_init();
788    if (mapi)
789      {
790         if (mapi->out_done_callback_set)
791            mapi->out_done_callback_set(_access_read_done, NULL);
792         if (mapi->out_cancel) mapi->out_cancel();
793         if (txt)
794           {
795              if (mapi->out_read) mapi->out_read(txt);
796              //if (mapi->out_read) mapi->out_read(".\n"); /* TIZEN only: Tizen TTS engine performance is not good */
797           }
798         if (mapi->out_read_done) mapi->out_read_done();
799      }
800 }
801
802 EAPI Elm_Access_Info *
803 _elm_access_object_get(const Evas_Object *obj)
804 {
805    return evas_object_data_get(obj, "_elm_access");
806 }
807
808 EAPI void
809 _elm_access_object_hilight(Evas_Object *obj)
810 {
811    Evas_Object *o;
812    Evas_Coord x, y, w, h;
813    Elm_Access_Action_Info *a;
814
815    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
816    if (!o)
817      {
818         o = edje_object_add(evas_object_evas_get(obj));
819         evas_object_name_set(o, "_elm_access_disp");
820         evas_object_layer_set(o, ELM_OBJECT_LAYER_TOOLTIP);
821      }
822    else
823      {
824         Evas_Object *ptarget = evas_object_data_get(o, "_elm_access_target");
825         if (ptarget)
826           {
827              evas_object_data_del(o, "_elm_access_target");
828              elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
829
830              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
831                                                  _access_obj_hilight_del_cb, NULL);
832              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
833                                                  _access_obj_hilight_hide_cb, NULL);
834              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
835                                                  _access_obj_hilight_move_cb, NULL);
836              evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
837                                                  _access_obj_hilight_resize_cb, NULL);
838              _access_action_callback_call(ptarget, ELM_ACCESS_ACTION_UNHIGHLIGHT, NULL);
839           }
840      }
841    evas_object_data_set(o, "_elm_access_target", obj);
842    elm_widget_parent_highlight_set(obj, EINA_TRUE);
843
844    elm_widget_theme_object_set(obj, o, "access", "base", "default");
845
846    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
847                                   _access_obj_hilight_del_cb, NULL);
848    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE,
849                                   _access_obj_hilight_hide_cb, NULL);
850    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
851                                   _access_obj_hilight_move_cb, NULL);
852    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
853                                   _access_obj_hilight_resize_cb, NULL);
854    evas_object_raise(o);
855    evas_object_geometry_get(obj, &x, &y, &w, &h);
856    evas_object_move(o, x, y);
857    evas_object_resize(o, w, h);
858
859    /* use callback, should an access object do below every time when
860         * a window gets a client message ECORE_X_ATOM_E_ILLMUE_ACTION_READ? */
861    a = calloc(1, sizeof(Elm_Access_Action_Info));
862    a->action_type = action_type;
863    if (!_access_action_callback_call(obj, ELM_ACCESS_ACTION_HIGHLIGHT, a))
864      evas_object_show(o);
865    else
866      evas_object_hide(o);
867    free(a);
868 }
869
870 EAPI void
871 _elm_access_object_unhilight(Evas_Object *obj)
872 {
873    Evas_Object *o, *ptarget;
874
875    o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
876    if (!o) return;
877    ptarget = evas_object_data_get(o, "_elm_access_target");
878    if (ptarget == obj)
879      {
880         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
881                                             _access_obj_hilight_del_cb, NULL);
882         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
883                                             _access_obj_hilight_hide_cb, NULL);
884         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
885                                             _access_obj_hilight_move_cb, NULL);
886         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
887                                             _access_obj_hilight_resize_cb, NULL);
888         evas_object_del(o);
889         elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
890         _access_action_callback_call(ptarget, ELM_ACCESS_ACTION_UNHIGHLIGHT, NULL);
891      }
892 }
893
894 static void
895 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
896                 void *event_info __UNUSED__)
897 {
898    Evas_Object *accessobj;
899    Evas_Coord w, h;
900
901    accessobj = data;
902    if (!accessobj) return;
903
904    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
905    evas_object_resize(accessobj, w, h);
906 }
907
908 static void
909 _content_move(void *data, Evas *e __UNUSED__, Evas_Object *obj,
910               void *event_info __UNUSED__)
911 {
912    Evas_Object *accessobj;
913    Evas_Coord x, y;
914
915    accessobj = data;
916    if (!accessobj) return;
917
918    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
919    evas_object_move(accessobj, x, y);
920 }
921
922 static Evas_Object *
923 _access_object_register(Evas_Object *obj, Evas_Object *parent)
924 {
925    Evas_Object *ao;
926    Elm_Access_Info *ac;
927    Evas_Coord x, y, w, h;
928
929    if (!obj) return NULL;
930
931    /* create access object */
932    ao = _elm_access_add(parent);
933    if (!ao) return NULL;
934
935    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
936                                   _content_resize, ao);
937    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
938                                   _content_move, ao);
939
940    evas_object_geometry_get(obj, &x, &y, &w, &h);
941    evas_object_move(ao, x, y);
942    evas_object_resize(ao, w, h);
943    evas_object_show(ao);
944
945    /* register access object */
946    _elm_access_object_register(ao, obj);
947
948    /* set access object */
949    evas_object_data_set(obj, "_part_access_obj", ao);
950
951    /* set owner part object */
952    ac = evas_object_data_get(ao, "_elm_access");
953    ac->part_object = obj;
954
955    return ao;
956 }
957
958 static void
959 _access_object_unregister(Evas_Object *obj)
960 {
961    Elm_Access_Info *ac;
962    Evas_Object *ao;
963
964    if (!obj) return;
965
966    ao = evas_object_data_get(obj, "_part_access_obj");
967
968    if (ao)
969      {
970         evas_object_data_del(obj, "_part_access_obj");
971
972         /* delete callbacks */
973         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
974                                             _content_resize, ao);
975         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE,
976                                             _content_move, ao);
977
978         /* unregister access object */
979         _elm_access_object_unregister(ao, obj);
980
981         evas_object_del(ao);
982      }
983    else
984      {
985         /* button, check, label etc. */
986         ac = evas_object_data_get(obj, "_elm_access");
987         if (ac && ac->hoverobj)
988           _elm_access_object_unregister(obj, ac->hoverobj);
989      }
990 }
991
992 EAPI Evas_Object *
993 _elm_access_edje_object_part_object_register(Evas_Object* obj,
994                                              const Evas_Object *eobj,
995                                              const char* part)
996 {
997    Evas_Object *ao, *po;
998
999    po = (Evas_Object *)edje_object_part_object_get(eobj, part);
1000    if (!obj || !po) return NULL;
1001
1002    /* check previous access object */
1003    ao = evas_object_data_get(po, "_part_access_obj");
1004    if (ao)
1005      _elm_access_edje_object_part_object_unregister(obj, eobj, part);
1006
1007    ao = _access_object_register(po, obj);
1008
1009    return ao;
1010 }
1011
1012 //FIXME: unused obj should be removed from here and each widget.
1013 EAPI void
1014 _elm_access_edje_object_part_object_unregister(Evas_Object* obj __UNUSED__,
1015                                                const Evas_Object *eobj,
1016                                                const char* part)
1017 {
1018    Evas_Object *po;
1019
1020    po = (Evas_Object *)edje_object_part_object_get(eobj, part);
1021    if (!po) return;
1022
1023    _access_object_unregister(po);
1024 }
1025
1026 EAPI void
1027 _elm_access_object_hilight_disable(Evas *e)
1028 {
1029    Evas_Object *o, *ptarget;
1030
1031    o = evas_object_name_find(e, "_elm_access_disp");
1032    if (!o) return;
1033    ptarget = evas_object_data_get(o, "_elm_access_target");
1034    if (ptarget)
1035      {
1036         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_DEL,
1037                                             _access_obj_hilight_del_cb, NULL);
1038         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_HIDE,
1039                                             _access_obj_hilight_hide_cb, NULL);
1040         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_MOVE,
1041                                             _access_obj_hilight_move_cb, NULL);
1042         evas_object_event_callback_del_full(ptarget, EVAS_CALLBACK_RESIZE,
1043                                             _access_obj_hilight_resize_cb, NULL);
1044      }
1045    evas_object_del(o);
1046    elm_widget_parent_highlight_set(ptarget, EINA_FALSE);
1047 }
1048
1049 EAPI void
1050 _elm_access_object_register(Evas_Object *obj, Evas_Object *hoverobj)
1051 {
1052    Elm_Access_Info *ac;
1053
1054    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_IN,
1055                                   _access_obj_mouse_in_cb, obj);
1056    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_OUT,
1057                                   _access_obj_mouse_out_cb, obj);
1058    evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_DEL,
1059                                   _access_obj_del_cb, obj);
1060    ac = calloc(1, sizeof(Elm_Access_Info));
1061    evas_object_data_set(obj, "_elm_access", ac);
1062
1063    ac->hoverobj = hoverobj;
1064 }
1065
1066 EAPI void
1067 _elm_access_object_unregister(Evas_Object *obj, Evas_Object *hoverobj)
1068 {
1069    Elm_Access_Info *ac;
1070
1071    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_MOUSE_IN,
1072                                        _access_obj_mouse_in_cb, obj);
1073    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_MOUSE_OUT,
1074                                        _access_obj_mouse_out_cb, obj);
1075    evas_object_event_callback_del_full(hoverobj, EVAS_CALLBACK_DEL,
1076                                        _access_obj_del_cb, obj);
1077
1078    ac = evas_object_data_get(obj, "_elm_access");
1079    evas_object_data_del(obj, "_elm_access");
1080    if (ac)
1081      {
1082         _elm_access_clear(ac);
1083         free(ac);
1084      }
1085
1086    Action_Info *a;
1087    a = evas_object_data_get(obj, "_elm_access_action_info");
1088    if (a) free(a);
1089 }
1090
1091 EAPI void
1092 _elm_access_widget_item_register(Elm_Widget_Item *item)
1093 {
1094    Evas_Object *ao, *ho;
1095    Evas_Coord x, y, w, h;
1096    Elm_Access_Info *ac;
1097
1098    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
1099
1100    /* check previous access object */
1101    if (item->access_obj)
1102      _elm_access_widget_item_unregister(item);
1103
1104    // create access object
1105    ho = item->view;
1106    ao = _elm_access_add(item->widget);
1107    if (!ao) return;
1108
1109    evas_object_event_callback_add(ho, EVAS_CALLBACK_RESIZE,
1110                                   _content_resize, ao);
1111    evas_object_event_callback_add(ho, EVAS_CALLBACK_MOVE,
1112                                   _content_move, ao);
1113
1114    evas_object_geometry_get(ho, &x, &y, &w, &h);
1115    evas_object_move(ao, x, y);
1116    evas_object_resize(ao, w, h);
1117    evas_object_show(ao);
1118
1119    // register access object
1120    _elm_access_object_register(ao, ho);
1121
1122    item->access_obj = ao;
1123
1124    /* set owner widget item */
1125    ac = evas_object_data_get(ao, "_elm_access");
1126    ac->widget_item = item;
1127 }
1128
1129 EAPI void
1130 _elm_access_widget_item_unregister(Elm_Widget_Item *item)
1131 {
1132    Evas_Object *ho;
1133
1134    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
1135
1136    if (!item->access_obj) return;
1137
1138    ho = item->view;
1139    evas_object_event_callback_del_full(ho, EVAS_CALLBACK_RESIZE,
1140                                   _content_resize, item->access_obj);
1141    evas_object_event_callback_del_full(ho, EVAS_CALLBACK_MOVE,
1142                                   _content_move, item->access_obj);
1143
1144    _elm_access_object_unregister(item->access_obj, ho);
1145
1146    evas_object_del(item->access_obj);
1147    item->access_obj = NULL;
1148 }
1149
1150 EAPI Eina_Bool
1151 _elm_access_2nd_click_timeout(Evas_Object *obj)
1152 {
1153    Ecore_Timer *t;
1154
1155    t = evas_object_data_get(obj, "_elm_2nd_timeout");
1156    if (t)
1157      {
1158         ecore_timer_del(t);
1159         evas_object_data_del(obj, "_elm_2nd_timeout");
1160         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
1161                                             _access_2nd_click_del_cb, NULL);
1162         return EINA_TRUE;
1163      }
1164    t = ecore_timer_add(0.3, _access_2nd_click_timeout_cb, obj);
1165    evas_object_data_set(obj, "_elm_2nd_timeout", t);
1166    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
1167                                   _access_2nd_click_del_cb, NULL);
1168    return EINA_FALSE;
1169 }
1170
1171 static Evas_Object *
1172 _elm_access_add(Evas_Object *parent)
1173 {
1174    Evas_Object *obj;
1175
1176    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1177
1178    obj = elm_widget_add(_elm_access_smart_class_new(), parent);
1179    if (!obj) return NULL;
1180
1181    if (!elm_widget_sub_object_add(parent, obj))
1182      ERR("could not add %p as sub object of %p", obj, parent);
1183
1184    return obj;
1185 }
1186
1187 EAPI Evas_Object *
1188 elm_access_object_register(Evas_Object *obj, Evas_Object *parent)
1189 {
1190    return _access_object_register(obj, parent);
1191 }
1192
1193 EAPI void
1194 elm_access_object_unregister(Evas_Object *obj)
1195 {
1196    _access_object_unregister(obj);
1197 }
1198
1199 EAPI Evas_Object *
1200 elm_access_object_get(const Evas_Object *obj)
1201 {
1202    return evas_object_data_get(obj, "_part_access_obj");
1203 }
1204
1205 EAPI void
1206 elm_access_info_set(Evas_Object *obj, int type, const char *text)
1207 {
1208    _elm_access_text_set(_elm_access_object_get(obj), type, text);
1209 }
1210
1211 EAPI char *
1212 elm_access_info_get(const Evas_Object *obj, int type)
1213 {
1214    return _elm_access_text_get(_elm_access_object_get(obj), type, obj);
1215 }
1216
1217 EAPI void
1218 elm_access_info_cb_set(Evas_Object *obj, int type,
1219                           Elm_Access_Info_Cb func, const void *data)
1220 {
1221    _elm_access_callback_set(_elm_access_object_get(obj), type, func, data);
1222 }
1223
1224 EAPI void
1225 elm_access_activate_cb_set(Evas_Object *obj,
1226                            Elm_Access_Activate_Cb  func, void *data)
1227 {
1228    Elm_Access_Info *ac;
1229
1230    ac = _elm_access_object_get(obj);
1231    if (!ac) return;
1232
1233    ac->activate = func;
1234    ac->activate_data = data;
1235 }
1236
1237 EAPI void
1238 elm_access_say(const char *text)
1239 {
1240    if (!text) return;
1241
1242    _elm_access_say(text);
1243 }
1244
1245 EAPI void
1246 elm_access_highlight_set(Evas_Object* obj)
1247 {
1248    _elm_access_highlight_set(obj);
1249 }
1250
1251 EAPI Eina_Bool
1252 elm_access_action(Evas_Object *obj, const Elm_Access_Action_Type type, void *action_info)
1253 {
1254    Evas *evas;
1255    Evas_Object *ho;
1256    Elm_Access_Action_Info *a;
1257
1258    a = (Elm_Access_Action_Info *) action_info;
1259
1260    switch (type)
1261      {
1262       case ELM_ACCESS_ACTION_READ:
1263       case ELM_ACCESS_ACTION_HIGHLIGHT:
1264         evas = evas_object_evas_get(obj);
1265         if (!evas) return EINA_FALSE;
1266
1267         _elm_access_mouse_event_enabled_set(EINA_TRUE);
1268
1269         evas_event_feed_mouse_in(evas, 0, NULL);
1270         evas_event_feed_mouse_move(evas, a->x, a->y, 0, NULL);
1271         _elm_access_mouse_event_enabled_set(EINA_FALSE);
1272
1273         ho = _access_highlight_object_get(obj);
1274         if (ho)
1275           _access_action_callback_call(ho, ELM_ACCESS_ACTION_READ, a);
1276         break;
1277
1278       case ELM_ACCESS_ACTION_UNHIGHLIGHT:
1279         break;
1280
1281       case ELM_ACCESS_ACTION_HIGHLIGHT_NEXT:
1282         if (a->highlight_cycle)
1283           _elm_access_highlight_cycle(obj, ELM_FOCUS_NEXT);
1284         else
1285           return _access_highlight_next_get(obj, ELM_FOCUS_NEXT);
1286         break;
1287
1288       case ELM_ACCESS_ACTION_HIGHLIGHT_PREV:
1289         if (a->highlight_cycle)
1290           _elm_access_highlight_cycle(obj, ELM_FOCUS_PREVIOUS);
1291         else
1292           return _access_highlight_next_get(obj, ELM_FOCUS_PREVIOUS);
1293         break;
1294
1295       case ELM_ACCESS_ACTION_ACTIVATE:
1296         _elm_access_highlight_object_activate(obj, ELM_ACTIVATE_DEFAULT);
1297         break;
1298
1299       case ELM_ACCESS_ACTION_VALUE_CHANGE:
1300         _elm_access_highlight_object_activate(obj, ELM_ACTIVATE_UP);
1301         break;
1302
1303       case ELM_ACCESS_ACTION_SCROLL:
1304         break;
1305
1306       case ELM_ACCESS_ACTION_BACK:
1307         break;
1308
1309       default:
1310         break;
1311      }
1312
1313    return EINA_TRUE;
1314 }
1315
1316 EAPI void
1317 elm_access_action_cb_set(Evas_Object *obj, const Elm_Access_Action_Type type, const Elm_Access_Action_Cb cb, const void *data)
1318 {
1319    Action_Info *a;
1320    a =  evas_object_data_get(obj, "_elm_access_action_info");
1321
1322    if (!a)
1323      {
1324         a = calloc(1, sizeof(Action_Info));
1325         evas_object_data_set(obj, "_elm_access_action_info", a);
1326      }
1327
1328    a->obj = obj;
1329    a->fn[type].cb = cb;
1330    a->fn[type].user_data = (void *)data;
1331 }
1332
1333 EAPI void
1334 elm_access_external_info_set(Evas_Object *obj, const char *text)
1335 {
1336    _elm_access_text_set
1337      (_elm_access_object_get(obj), ELM_ACCESS_CONTEXT_INFO, text);
1338 }
1339
1340 EAPI char *
1341 elm_access_external_info_get(const Evas_Object *obj)
1342 {
1343    Elm_Access_Info *ac;
1344
1345    ac = _elm_access_object_get(obj);
1346    return _elm_access_text_get(ac, ELM_ACCESS_CONTEXT_INFO, obj);
1347 }