list: Add item loop feature
[platform/upstream/elementary.git] / src / lib / elm_widget.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #include <Elementary.h>
6
7 #include "elm_priv.h"
8 #include "elm_widget_container.h"
9 #include "elm_interface_scrollable.h"
10
11 #define MY_CLASS ELM_OBJ_WIDGET_CLASS
12
13 #define MY_CLASS_NAME "Elm_Widget"
14 #define MY_CLASS_NAME_LEGACY "elm_widget"
15
16 #define ELM_WIDGET_DATA_GET(o, wd)                             \
17   Elm_Widget_Smart_Data *wd = eo_data_scope_get(o, MY_CLASS)
18
19 #define API_ENTRY                                    \
20   ELM_WIDGET_DATA_GET(obj, sd);                      \
21   if ((!sd) || (!_elm_widget_is(obj)))
22 #define INTERNAL_ENTRY                               \
23   ELM_WIDGET_DATA_GET(obj, sd);                      \
24   if (!sd) return
25
26 #define ELM_WIDGET_FOCUS_GET(obj)                                    \
27   ((_elm_access_auto_highlight_get()) ? (elm_widget_highlight_get(obj)) : \
28                                         (elm_widget_focus_get(obj)))
29
30 const char SIG_WIDGET_FOCUSED[] = "focused";
31 const char SIG_WIDGET_UNFOCUSED[] = "unfocused";
32 const char SIG_WIDGET_LANG_CHANGED[] = "language,changed";
33 const char SIG_WIDGET_ACCESS_CHANGED[] = "access,changed";
34
35 typedef struct _Elm_Event_Cb_Data         Elm_Event_Cb_Data;
36 typedef struct _Elm_Label_Data            Elm_Label_Data;
37 typedef struct _Elm_Translate_String_Data Elm_Translate_String_Data;
38
39 struct _Elm_Event_Cb_Data
40 {
41    Elm_Event_Cb func;
42    const void  *data;
43 };
44
45 struct _Elm_Label_Data
46 {
47    const char *part;
48    const char *text;
49 };
50
51 struct _Elm_Translate_String_Data
52 {
53    EINA_INLIST;
54    Eina_Stringshare *id;
55    Eina_Stringshare *domain;
56    Eina_Stringshare *string;
57    Eina_Bool   preset : 1;
58 };
59
60 /* local subsystem globals */
61 static unsigned int focus_order = 0;
62
63 static inline Eina_Bool
64 _elm_widget_is(const Evas_Object *obj)
65 {
66    return eo_isa(obj, MY_CLASS);
67 }
68
69 static inline Eina_Bool
70 _is_focusable(Evas_Object *obj)
71 {
72    API_ENTRY return EINA_FALSE;
73    return sd->can_focus || (sd->child_can_focus);
74 }
75
76 static inline Eina_Bool
77 _elm_scrollable_is(const Evas_Object *obj)
78 {
79    INTERNAL_ENTRY EINA_FALSE;
80    return
81       eo_isa(obj, ELM_INTERFACE_SCROLLABLE_CLASS);
82 }
83
84 void
85 _elm_widget_item_highlight_in_theme(Evas_Object *obj, Elm_Object_Item *it)
86 {
87    const char *str;
88
89    if (!it) return;
90    str = edje_object_data_get(VIEW(it), "focus_highlight");
91    if ((str) && (!strcmp(str, "on")))
92      elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
93    else
94      elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
95 }
96
97 void
98 _elm_widget_focus_highlight_start(const Evas_Object *obj)
99 {
100    Evas_Object *top = elm_widget_top_get(obj);
101
102    if (top && eo_isa(top, ELM_OBJ_WIN_CLASS))
103      _elm_win_focus_highlight_start(top);
104 }
105
106 EAPI Eina_Bool
107 elm_widget_focus_highlight_enabled_get(const Evas_Object *obj)
108 {
109    const Evas_Object *win = elm_widget_top_get(obj);
110
111    if (win && eo_isa(win, ELM_OBJ_WIN_CLASS))
112      return elm_win_focus_highlight_enabled_get(win);
113    return EINA_FALSE;
114 }
115
116 /**
117  * @internal
118  *
119  * Resets the mirrored mode from the system mirror mode for widgets that are in
120  * automatic mirroring mode. This function does not call elm_widget_theme.
121  *
122  * @param obj The widget.
123  * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
124  */
125 static void
126 _elm_widget_mirrored_reload(Evas_Object *obj)
127 {
128    API_ENTRY return;
129    Eina_Bool mirrored = elm_config_mirrored_get();
130
131    if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
132      {
133         sd->is_mirrored = mirrored;
134      }
135 }
136
137 EOLIAN static Eina_Bool
138 _elm_widget_on_focus_region(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Coord *x EINA_UNUSED, Evas_Coord *y EINA_UNUSED, Evas_Coord *w EINA_UNUSED, Evas_Coord *h EINA_UNUSED)
139 {
140    WRN("The %s widget does not implement the \"on_focus_region\" function.",
141        eo_class_name_get(eo_class_get(obj)));
142
143    return EINA_FALSE;
144 }
145
146 static void
147 _parents_focus(Evas_Object *obj)
148 {
149    for (; obj; obj = elm_widget_parent_get(obj))
150      {
151         INTERNAL_ENTRY;
152         if (sd->focused) return;
153         sd->focused = 1;
154      }
155 }
156
157 static void
158 _parents_unfocus(Evas_Object *obj)
159 {
160    for (; obj; obj = elm_widget_parent_get(obj))
161      {
162         INTERNAL_ENTRY;
163         if (!sd->focused) return;
164         sd->focused = 0;
165      }
166 }
167
168 static void
169 _on_sub_obj_hide(void *data EINA_UNUSED,
170               Evas *e EINA_UNUSED,
171               Evas_Object *obj,
172               void *event_info EINA_UNUSED)
173 {
174    elm_widget_focus_hide_handle(obj);
175 }
176
177 static void
178 _on_sub_obj_del(void *data,
179              Evas *e EINA_UNUSED,
180              Evas_Object *obj,
181              void *event_info EINA_UNUSED)
182 {
183    ELM_WIDGET_DATA_GET(data, sd);
184
185    if (_elm_widget_is(obj))
186      {
187         if (elm_widget_focus_get(obj)) _parents_unfocus(sd->obj);
188      }
189    if (obj == sd->resize_obj)
190      {
191         /* already dels sub object */
192         elm_widget_resize_object_set(sd->obj, NULL, EINA_TRUE);
193         return;
194      }
195    else if (obj == sd->hover_obj)
196      {
197         sd->hover_obj = NULL;
198         return;
199      }
200    else
201      {
202         if (!elm_widget_sub_object_del(sd->obj, obj))
203           ERR("failed to remove sub object %p from %p\n", obj, sd->obj);
204      }
205 }
206
207 static const Evas_Smart_Cb_Description _smart_callbacks[] =
208 {
209    /* FIXME: complete later */
210    {NULL, NULL}
211 };
212
213 static void
214 _obj_mouse_down(void *data,
215                 Evas *e EINA_UNUSED,
216                 Evas_Object *obj EINA_UNUSED,
217                 void *event_info)
218 {
219    ELM_WIDGET_DATA_GET(data, sd);
220    Evas_Event_Mouse_Down *ev = event_info;
221    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
222      sd->still_in = EINA_TRUE;
223 }
224
225 static void
226 _obj_mouse_move(void *data,
227                 Evas *e EINA_UNUSED,
228                 Evas_Object *obj,
229                 void *event_info)
230 {
231    ELM_WIDGET_DATA_GET(data, sd);
232    Evas_Event_Mouse_Move *ev = event_info;
233    if (!sd->still_in) return;
234
235    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
236      sd->still_in = EINA_FALSE;
237    else
238      {
239         Evas_Coord x, y, w, h;
240         evas_object_geometry_get(obj, &x, &y, &w, &h);
241         if (ELM_RECTS_POINT_OUT(x, y, w, h, ev->cur.canvas.x, ev->cur.canvas.y))
242           sd->still_in = EINA_FALSE;
243      }
244 }
245
246 static void
247 _obj_mouse_up(void *data,
248               Evas *e EINA_UNUSED,
249               Evas_Object *obj,
250               void *event_info EINA_UNUSED)
251 {
252    ELM_WIDGET_DATA_GET(data, sd);
253    if (sd->still_in &&
254        (_elm_config->focus_move_policy == ELM_FOCUS_MOVE_POLICY_CLICK))
255      elm_widget_focus_mouse_up_handle(obj);
256
257    sd->still_in = EINA_FALSE;
258 }
259
260 static void
261 _obj_mouse_in(void *data EINA_UNUSED,
262               Evas *e EINA_UNUSED,
263               Evas_Object *obj,
264               void *event_info EINA_UNUSED)
265 {
266    if (_elm_config->focus_move_policy == ELM_FOCUS_MOVE_POLICY_IN)
267      elm_widget_focus_mouse_up_handle(obj);
268 }
269
270 EOLIAN static void
271 _elm_widget_evas_smart_add(Eo *obj, Elm_Widget_Smart_Data *priv)
272 {
273
274    priv->obj = obj;
275    priv->mirrored_auto_mode = EINA_TRUE; /* will follow system locale
276                                           * settings */
277    elm_widget_can_focus_set(obj, EINA_TRUE);
278    priv->is_mirrored = elm_config_mirrored_get();
279
280    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
281                                   _obj_mouse_down, obj);
282    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
283                                   _obj_mouse_move, obj);
284    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
285                                   _obj_mouse_up, obj);
286    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_IN,
287                                   _obj_mouse_in, obj);
288    /* just a helper for inheriting classes */
289    if (priv->resize_obj)
290      {
291         Evas_Object *r_obj = priv->resize_obj;
292         priv->resize_obj = NULL;
293
294         elm_widget_resize_object_set(obj, r_obj, EINA_TRUE);
295      }
296 }
297
298 static void
299 _if_focused_revert(Evas_Object *obj,
300                    Eina_Bool can_focus_only)
301 {
302    Evas_Object *top;
303    Evas_Object *newest = NULL;
304    unsigned int newest_focus_order = 0;
305
306    INTERNAL_ENTRY;
307
308    if (!sd->focused) return;
309    if (!sd->parent_obj) return;
310
311    top = elm_widget_top_get(sd->parent_obj);
312    if (top)
313      {
314         newest = elm_widget_newest_focus_order_get
315            (top, &newest_focus_order, can_focus_only);
316         if (newest)
317           {
318              elm_object_focus_set(newest, EINA_FALSE);
319              elm_object_focus_set(newest, EINA_TRUE);
320           }
321      }
322 }
323
324 EOLIAN static void
325 _elm_widget_evas_smart_del(Eo *obj, Elm_Widget_Smart_Data *sd)
326 {
327    Evas_Object *sobj;
328    Elm_Translate_String_Data *ts;
329    Elm_Event_Cb_Data *ecb;
330
331    if (sd->hover_obj)
332      {
333         /* detach it from us */
334         evas_object_event_callback_del_full
335           (sd->hover_obj, EVAS_CALLBACK_DEL, _on_sub_obj_del, obj);
336         sd->hover_obj = NULL;
337      }
338
339    while (sd->subobjs)
340      {
341         sobj = eina_list_data_get(sd->subobjs);
342
343         /* let the objects clean-up themselves and get rid of this list */
344         if (!elm_widget_sub_object_del(obj, sobj))
345           {
346              ERR("failed to remove sub object %p from %p\n", sobj, obj);
347              sd->subobjs = eina_list_remove_list
348                  (sd->subobjs, sd->subobjs);
349           }
350         evas_object_del(sobj);
351      }
352    sd->tooltips = eina_list_free(sd->tooltips); /* should be empty anyway */
353    sd->cursors = eina_list_free(sd->cursors); /* should be empty anyway */
354    while (sd->translate_strings)
355      {
356         ts = EINA_INLIST_CONTAINER_GET(sd->translate_strings,
357                                        Elm_Translate_String_Data);
358         eina_stringshare_del(ts->id);
359         eina_stringshare_del(ts->domain);
360         eina_stringshare_del(ts->string);
361         sd->translate_strings = eina_inlist_remove(sd->translate_strings,
362                                                    sd->translate_strings);
363         free(ts);
364      }
365
366    EINA_LIST_FREE(sd->event_cb, ecb)
367       free(ecb);
368
369    eina_stringshare_del(sd->style);
370    if (sd->theme) elm_theme_free(sd->theme);
371    _if_focused_revert(obj, EINA_TRUE);
372    elm_widget_focus_custom_chain_unset(obj);
373    eina_stringshare_del(sd->access_info);
374    evas_object_smart_data_set(obj, NULL);
375 }
376
377 static void
378 _smart_reconfigure(Elm_Widget_Smart_Data *sd)
379 {
380    if (sd->resize_obj)
381      {
382         evas_object_move(sd->resize_obj, sd->x, sd->y);
383         evas_object_resize(sd->resize_obj, sd->w, sd->h);
384      }
385    if (sd->hover_obj)
386      {
387         evas_object_move(sd->hover_obj, sd->x, sd->y);
388         evas_object_resize(sd->hover_obj, sd->w, sd->h);
389      }
390 }
391
392 EOLIAN static void
393 _elm_widget_evas_smart_move(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Coord x, Evas_Coord y)
394 {
395    sd->x = x;
396    sd->y = y;
397
398    _smart_reconfigure(sd);
399 }
400
401 EOLIAN static void
402 _elm_widget_evas_smart_resize(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Coord w, Evas_Coord h)
403 {
404    sd->w = w;
405    sd->h = h;
406
407    _smart_reconfigure(sd);
408 }
409
410 EOLIAN static void
411 _elm_widget_evas_smart_show(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
412 {
413    Eina_Iterator *it;
414    Evas_Object *o;
415
416    it = evas_object_smart_iterator_new(obj);
417    EINA_ITERATOR_FOREACH(it, o)
418      {
419        if (evas_object_data_get(o, "_elm_leaveme")) continue;
420        evas_object_show(o);
421      }
422    eina_iterator_free(it);
423 }
424
425 EOLIAN static void
426 _elm_widget_evas_smart_hide(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
427 {
428    Eina_Iterator *it;
429    Evas_Object *o;
430
431    it = evas_object_smart_iterator_new(obj);
432    EINA_ITERATOR_FOREACH(it, o)
433      {
434         if (evas_object_data_get(o, "_elm_leaveme")) continue;
435         evas_object_hide(o);
436      }
437    eina_iterator_free(it);
438 }
439
440 EOLIAN static void
441 _elm_widget_evas_smart_color_set(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, int r, int g, int b, int a)
442 {
443    Eina_Iterator *it;
444    Evas_Object *o;
445
446    it = evas_object_smart_iterator_new(obj);
447    EINA_ITERATOR_FOREACH(it, o)
448      {
449        if (evas_object_data_get(o, "_elm_leaveme")) continue;
450        evas_object_color_set(o, r, g, b, a);
451      }
452    eina_iterator_free(it);
453 }
454
455 EOLIAN static void
456 _elm_widget_evas_smart_clip_set(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *clip)
457 {
458    Eina_Iterator *it;
459    Evas_Object *o;
460
461    it = evas_object_smart_iterator_new(obj);
462    EINA_ITERATOR_FOREACH(it, o)
463      {
464        if (evas_object_data_get(o, "_elm_leaveme")) continue;
465        evas_object_clip_set(o, clip);
466      }
467    eina_iterator_free(it);
468 }
469
470 EOLIAN static void
471 _elm_widget_evas_smart_clip_unset(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
472 {
473    Eina_Iterator *it;
474    Evas_Object *o;
475
476    it = evas_object_smart_iterator_new(obj);
477    EINA_ITERATOR_FOREACH(it, o)
478      {
479        if (evas_object_data_get(o, "_elm_leaveme")) continue;
480        evas_object_clip_unset(o);
481      }
482    eina_iterator_free(it);
483 }
484
485 EOLIAN static void
486 _elm_widget_evas_smart_calculate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
487 {
488    /* a NO-OP, on the base */
489 }
490
491 EOLIAN static void
492 _elm_widget_evas_smart_member_add(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *child)
493 {
494    int r, g, b, a;
495    eo_do_super(obj, MY_CLASS, evas_obj_smart_member_add(child));
496
497    if (evas_object_data_get(child, "_elm_leaveme")) return;
498
499    evas_object_color_get(obj, &r, &g, &b, &a);
500    evas_object_color_set(child, r, g, b, a);
501
502    evas_object_clip_set(child, evas_object_clip_get(obj));
503
504    if (evas_object_visible_get(obj))
505      evas_object_show(child);
506    else
507      evas_object_hide(child);
508 }
509
510 EOLIAN static void
511 _elm_widget_evas_smart_member_del(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *child)
512 {
513    if (!evas_object_data_get(child, "_elm_leaveme"))
514       evas_object_clip_unset(child);
515    eo_do_super(obj, MY_CLASS, evas_obj_smart_member_del(child));
516 }
517
518 // internal funcs
519 /**
520  * @internal
521  *
522  * Check if the widget has its own focus next function.
523  *
524  * @param obj The widget.
525  * @return focus next function is implemented/unimplemented.
526  * (@c EINA_TRUE = implemented/@c EINA_FALSE = unimplemented.)
527  */
528 static inline Eina_Bool
529 _elm_widget_focus_chain_manager_is(const Evas_Object *obj)
530 {
531    ELM_WIDGET_CHECK(obj) EINA_FALSE;
532
533    Eina_Bool manager_is = EINA_FALSE;
534    eo_do((Eo *)obj, elm_obj_widget_focus_next_manager_is(&manager_is));
535    return manager_is;
536 }
537
538 static inline Eina_Bool
539 _internal_elm_widget_focus_direction_manager_is(const Evas_Object *obj)
540 {
541    ELM_WIDGET_CHECK(obj) EINA_FALSE;
542
543    Eina_Bool manager_is = EINA_FALSE;
544    eo_do((Eo *)obj, elm_obj_widget_focus_direction_manager_is(&manager_is));
545    return manager_is;
546 }
547
548 static void
549 _propagate_x_drag_lock(Evas_Object *obj,
550                        int dir)
551 {
552    INTERNAL_ENTRY;
553    if (sd->parent_obj)
554      {
555         ELM_WIDGET_DATA_GET(sd->parent_obj, sd2);
556         if (sd2)
557           {
558              sd2->child_drag_x_locked += dir;
559              _propagate_x_drag_lock(sd->parent_obj, dir);
560           }
561      }
562 }
563
564 static void
565 _propagate_y_drag_lock(Evas_Object *obj,
566                        int dir)
567 {
568    INTERNAL_ENTRY;
569    if (sd->parent_obj)
570      {
571         ELM_WIDGET_DATA_GET(sd->parent_obj, sd2);
572         if (sd2)
573           {
574              sd2->child_drag_y_locked += dir;
575              _propagate_y_drag_lock(sd->parent_obj, dir);
576           }
577      }
578 }
579
580 static void
581 _propagate_event(void *data,
582                  Evas *e EINA_UNUSED,
583                  Evas_Object *obj,
584                  void *event_info)
585 {
586    INTERNAL_ENTRY;
587    Evas_Callback_Type type = (Evas_Callback_Type)(uintptr_t)data;
588    Evas_Event_Flags *event_flags = NULL;
589
590    switch (type)
591      {
592       case EVAS_CALLBACK_KEY_DOWN:
593            {
594               Evas_Event_Key_Down *ev = event_info;
595               event_flags = &(ev->event_flags);
596            }
597          break;
598
599       case EVAS_CALLBACK_KEY_UP:
600            {
601               Evas_Event_Key_Up *ev = event_info;
602               event_flags = &(ev->event_flags);
603            }
604          break;
605
606       case EVAS_CALLBACK_MOUSE_WHEEL:
607            {
608               Evas_Event_Mouse_Wheel *ev = event_info;
609               event_flags = &(ev->event_flags);
610            }
611          break;
612
613       default:
614          break;
615      }
616
617    elm_widget_event_propagate(obj, type, event_info, event_flags);
618 }
619
620 /**
621  * @internal
622  *
623  * If elm_widget_focus_region_get() returns EINA_FALSE, this function will
624  * ignore region show action.
625  */
626 EOLIAN static void
627 _elm_widget_focus_region_show(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
628 {
629    Evas_Coord x, y, w, h, ox, oy;
630    Evas_Object *o;
631
632    o = elm_widget_parent_get(obj);
633    if (!o) return;
634
635    if (!elm_widget_focus_region_get(obj, &x, &y, &w, &h))
636      return;
637
638    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
639
640    while (o)
641      {
642         Evas_Coord px, py;
643
644         if (_elm_scrollable_is(o) && !elm_widget_disabled_get(o))
645           {
646              eo_do(o, elm_interface_scrollable_content_region_show(x, y, w, h));
647
648              if (!elm_widget_focus_region_get(o, &x, &y, &w, &h))
649                {
650                   o = elm_widget_parent_get(o);
651                   continue;
652                }
653           }
654         else
655           {
656              evas_object_geometry_get(o, &px, &py, NULL, NULL);
657              x += ox - px;
658              y += oy - py;
659              ox = px;
660              oy = py;
661           }
662         o = elm_widget_parent_get(o);
663      }
664 }
665
666 EOLIAN static Eina_Bool
667 _elm_widget_focus_highlight_style_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, const char *style)
668 {
669    if (eina_stringshare_replace(&sd->focus_highlight_style, style)) return EINA_TRUE;
670    return EINA_FALSE;
671 }
672
673 EOLIAN static const char*
674 _elm_widget_focus_highlight_style_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
675 {
676    return sd->focus_highlight_style;
677 }
678
679 static void
680 _parent_focus(Evas_Object *obj)
681 {
682    API_ENTRY return;
683
684    if (sd->focused) return;
685
686    Evas_Object *o = elm_widget_parent_get(obj);
687    sd->focus_order_on_calc = EINA_TRUE;
688
689    if (o) _parent_focus(o);
690
691    if (!sd->focus_order_on_calc)
692      return;  /* we don't want to override it if by means of any of the
693                  callbacks below one gets to calculate our order
694                  first. */
695
696    focus_order++;
697    sd->focus_order = focus_order;
698
699    if (sd->top_win_focused)
700      {
701         sd->focused = EINA_TRUE;
702         eo_do(obj, elm_obj_widget_on_focus(NULL));
703         elm_widget_focus_region_show(obj);
704      }
705    sd->focus_order_on_calc = EINA_FALSE;
706
707    if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
708      _elm_access_highlight_set(obj);
709 }
710
711 static void
712 _elm_object_focus_chain_del_cb(void *data,
713                                Evas *e EINA_UNUSED,
714                                Evas_Object *obj,
715                                void *event_info EINA_UNUSED)
716 {
717    ELM_WIDGET_DATA_GET(data, sd);
718
719    sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
720 }
721
722 EOLIAN static void
723 _elm_widget_parent_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *parent EINA_UNUSED)
724 {
725 }
726
727 EAPI Eina_Bool
728 elm_widget_api_check(int ver)
729 {
730    if (ver != ELM_INTERNAL_API_VERSION)
731      {
732         CRI("Elementary widget api versions do not match");
733         return EINA_FALSE;
734      }
735    return EINA_TRUE;
736 }
737
738 EAPI Eina_Bool
739 elm_widget_access(Evas_Object *obj,
740                   Eina_Bool is_access)
741 {
742    const Eina_List *l;
743    Evas_Object *child;
744    Eina_Bool ret = EINA_TRUE;
745
746    API_ENTRY return EINA_FALSE;
747    EINA_LIST_FOREACH(sd->subobjs, l, child)
748      {
749         if (elm_widget_is(child))
750           ret &= elm_widget_access(child, is_access);
751      }
752
753    eo_do(obj, elm_obj_widget_access(is_access));
754    evas_object_smart_callback_call(obj, SIG_WIDGET_ACCESS_CHANGED, NULL);
755
756    return ret;
757 }
758
759 EOLIAN static void
760 _elm_widget_access(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Eina_Bool is_access EINA_UNUSED)
761 {
762 }
763
764 EAPI Eina_Bool
765 elm_widget_theme(Evas_Object *obj)
766 {
767    const Eina_List *l;
768    Evas_Object *child;
769    Elm_Tooltip *tt;
770    Elm_Cursor *cur;
771    Eina_Bool ret = EINA_TRUE;
772
773    API_ENTRY return EINA_FALSE;
774
775    EINA_LIST_FOREACH(sd->subobjs, l, child)
776      if (_elm_widget_is(child))
777        ret &= elm_widget_theme(child);
778
779    if (sd->hover_obj) ret &= elm_widget_theme(sd->hover_obj);
780
781    EINA_LIST_FOREACH(sd->tooltips, l, tt)
782      elm_tooltip_theme(tt);
783    EINA_LIST_FOREACH(sd->cursors, l, cur)
784      elm_cursor_theme(cur);
785
786    Eina_Bool ret2;
787    eo_do(obj, elm_obj_widget_theme_apply(&ret2));
788    ret &= ret2;
789
790    return ret;
791 }
792
793 EAPI void
794 elm_widget_theme_specific(Evas_Object *obj,
795                           Elm_Theme *th,
796                           Eina_Bool force)
797 {
798    const Eina_List *l;
799    Evas_Object *child;
800    Elm_Tooltip *tt;
801    Elm_Cursor *cur;
802    Elm_Theme *th2, *thdef;
803
804    API_ENTRY return;
805
806    thdef = elm_theme_default_get();
807    if (!th) th = thdef;
808    if (!force)
809      {
810         th2 = sd->theme;
811         if (!th2) th2 = thdef;
812         while (th2)
813           {
814              if (th2 == th)
815                {
816                   force = EINA_TRUE;
817                   break;
818                }
819              if (th2 == thdef) break;
820              th2 = th2->ref_theme;
821              if (!th2) th2 = thdef;
822           }
823      }
824    if (!force) return;
825    EINA_LIST_FOREACH(sd->subobjs, l, child)
826      {
827         if (elm_widget_is(child))
828           elm_widget_theme_specific(child, th, force);
829      }
830    if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
831    EINA_LIST_FOREACH(sd->tooltips, l, tt)
832      elm_tooltip_theme(tt);
833    EINA_LIST_FOREACH(sd->cursors, l, cur)
834      elm_cursor_theme(cur);
835    eo_do(obj, elm_obj_widget_theme_apply(NULL));
836 }
837
838 EOLIAN static Eina_Bool
839 _elm_widget_theme_apply(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
840 {
841    _elm_widget_mirrored_reload(obj);
842
843    elm_widget_disabled_set(obj, elm_widget_disabled_get(obj));
844
845    return EINA_TRUE;
846 }
847
848 /**
849  * @internal
850  *
851  * Returns the widget's mirrored mode.
852  *
853  * @param obj The widget.
854  * @return mirrored mode of the object.
855  *
856  **/
857 EOLIAN static Eina_Bool
858 _elm_widget_mirrored_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
859 {
860    return sd->is_mirrored;
861 }
862
863 /**
864  * @internal
865  *
866  * Sets the widget's mirrored mode.
867  *
868  * @param obj The widget.
869  * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
870  */
871 EOLIAN static void
872 _elm_widget_mirrored_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool mirrored)
873 {
874    mirrored = !!mirrored;
875
876    if (sd->is_mirrored == mirrored) return;
877
878    sd->is_mirrored = mirrored;
879    elm_widget_theme(obj);
880 }
881
882 /**
883  * Returns the widget's mirrored mode setting.
884  *
885  * @param obj The widget.
886  * @return mirrored mode setting of the object.
887  *
888  **/
889 EOLIAN static Eina_Bool
890 _elm_widget_mirrored_automatic_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
891 {
892    return sd->mirrored_auto_mode;
893 }
894
895 /**
896  * @internal
897  *
898  * Sets the widget's mirrored mode setting.
899  * When widget in automatic mode, it follows the system mirrored mode set by
900  * elm_mirrored_set().
901  * @param obj The widget.
902  * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
903  */
904 EOLIAN static void
905 _elm_widget_mirrored_automatic_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool automatic)
906 {
907    if (sd->mirrored_auto_mode != automatic)
908      {
909         sd->mirrored_auto_mode = automatic;
910
911         if (automatic)
912           {
913              elm_widget_mirrored_set(obj, elm_config_mirrored_get());
914           }
915      }
916 }
917
918 EOLIAN static void
919 _elm_widget_on_show_region_hook_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, region_hook_func_type func, void *data)
920 {
921    sd->on_show_region = func;
922    sd->on_show_region_data = data;
923 }
924
925 /*
926  * @internal
927  *
928  * Add myself as a sub object of parent object
929  *
930  * @see elm_widget_sub_object_add()
931  */
932 EAPI Eina_Bool
933 elm_widget_sub_object_parent_add(Evas_Object *sobj)
934 {
935    Eina_Bool ret = EINA_FALSE;
936    Eo *parent;
937
938    eo_do(sobj, eo_parent_get(&parent));
939    eo_do(parent, elm_obj_widget_sub_object_add(sobj, &ret));
940
941    return ret;
942 }
943
944 /*
945  * @internal
946  *
947  * Add sobj to obj's sub object.
948  *
949  * What does elementary sub object mean? This is unique in elementary, it
950  * handles overall elementary policies between parent and sub objects.
951  *   focus, access, deletion, theme, scale, mirror, scrollable child get,
952  *   translate, name find, display mode set, orientation set, tree dump
953  *   AUTOMATICALLY.
954  *
955  * @see elm_widget_sub_object_parent_add()
956  */
957 EOLIAN static Eina_Bool
958 _elm_widget_sub_object_add(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Object *sobj)
959 {
960    Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
961
962    EINA_SAFETY_ON_TRUE_RETURN_VAL(obj == sobj, EINA_FALSE);
963
964    if (sobj == sd->parent_obj)
965      {
966         /* in this case, sobj must be an elm widget, or something
967          * very wrong is happening */
968         if (!_elm_widget_is(sobj)) return EINA_FALSE;
969
970         if (!elm_widget_sub_object_del(sobj, obj)) return EINA_FALSE;
971         WRN("You passed a parent object of obj = %p as the sub object = %p!",
972             obj, sobj);
973      }
974
975    if (_elm_widget_is(sobj))
976      {
977         ELM_WIDGET_DATA_GET(sobj, sdc);
978
979         if (sdc->parent_obj == obj) goto end;
980         if (sdc->parent_obj)
981           {
982              if (!elm_widget_sub_object_del(sdc->parent_obj, sobj))
983                return EINA_FALSE;
984           }
985         sdc->parent_obj = obj;
986         sdc->orient_mode = sd->orient_mode;
987         _elm_widget_top_win_focused_set(sobj, sd->top_win_focused);
988
989         /* update child focusable-ness on self and parents, now that a
990          * focusable child got in */
991         if (!sd->child_can_focus && (_is_focusable(sobj)))
992           {
993              Elm_Widget_Smart_Data *sdp = sd;
994
995              sdp->child_can_focus = EINA_TRUE;
996              while (sdp->parent_obj)
997                {
998                   sdp = eo_data_scope_get(sdp->parent_obj, MY_CLASS);
999
1000                   if (sdp->child_can_focus) break;
1001
1002                   sdp->child_can_focus = EINA_TRUE;
1003                }
1004           }
1005      }
1006    else
1007      {
1008         void *data = evas_object_data_get(sobj, "elm-parent");
1009
1010         if (data)
1011           {
1012              if (data == obj) goto end;
1013              if (!elm_widget_sub_object_del(data, sobj)) return EINA_FALSE;
1014           }
1015      }
1016    sd->subobjs = eina_list_append(sd->subobjs, sobj);
1017    evas_object_data_set(sobj, "elm-parent", obj);
1018    evas_object_event_callback_add
1019      (sobj, EVAS_CALLBACK_DEL, _on_sub_obj_del, obj);
1020    if (_elm_widget_is(sobj))
1021      {
1022         ELM_WIDGET_DATA_GET(sobj, sdc);
1023
1024         /* NOTE: In the following two lines, 'sobj' is correct. Do not change it.
1025          * Due to elementary's scale policy, scale and pscale can be different in
1026          * some cases. This happens when sobj's previous parent and new parent have
1027          * different scale value.
1028          * For example, if sobj's previous parent's scale is 5 and new parent's scale
1029          * is 2 while sobj's scale is 0. Then 'pscale' is 5 and 'scale' is 2. So we
1030          * need to reset sobj's scale to 5.
1031          * Note that each widget's scale is 0 by default.
1032          */
1033         double scale, pscale = elm_widget_scale_get(sobj);
1034         Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
1035
1036         evas_object_event_callback_add
1037           (sobj, EVAS_CALLBACK_HIDE, _on_sub_obj_hide, NULL);
1038
1039         scale = elm_widget_scale_get(sobj);
1040         th = elm_widget_theme_get(sobj);
1041         mirrored = elm_widget_mirrored_get(sobj);
1042
1043         if (!sdc->on_create)
1044           {
1045              if ((scale != pscale) || (th != pth) || (pmirrored != mirrored))
1046                elm_widget_theme(sobj);
1047           }
1048
1049         if (elm_widget_focus_get(sobj)) _parents_focus(obj);
1050
1051         elm_widget_display_mode_set(sobj,
1052               evas_object_size_hint_display_mode_get(obj));
1053      }
1054
1055 end:
1056    return EINA_TRUE;
1057 }
1058
1059 EOLIAN static Eina_Bool
1060 _elm_widget_sub_object_del(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Object *sobj)
1061 {
1062    Evas_Object *sobj_parent;
1063
1064    if (!sobj) return EINA_FALSE;
1065
1066    EINA_SAFETY_ON_TRUE_RETURN_VAL(obj == sobj, EINA_FALSE);
1067
1068    sobj_parent = evas_object_data_del(sobj, "elm-parent");
1069    if (sobj_parent != obj)
1070      {
1071         static int abort_on_warn = -1;
1072
1073         ERR("removing sub object %p (%s) from parent %p (%s), "
1074             "but elm-parent is different %p (%s)!",
1075             sobj, elm_widget_type_get(sobj), obj, elm_widget_type_get(obj),
1076             sobj_parent, elm_widget_type_get(sobj_parent));
1077
1078         if (EINA_UNLIKELY(abort_on_warn == -1))
1079           {
1080              if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1081              else abort_on_warn = 0;
1082           }
1083         if (abort_on_warn == 1) abort();
1084
1085         return EINA_FALSE;
1086      }
1087
1088    if (_elm_widget_is(sobj))
1089      {
1090         if (elm_widget_focus_get(sobj))
1091           {
1092              elm_widget_tree_unfocusable_set(sobj, EINA_TRUE);
1093              elm_widget_tree_unfocusable_set(sobj, EINA_FALSE);
1094           }
1095         if ((sd->child_can_focus) && (_is_focusable(sobj)))
1096           {
1097              Evas_Object *parent = obj;
1098
1099              /* update child focusable-ness on self and parents, now that a
1100               * focusable child is gone */
1101              while (parent)
1102                {
1103                   const Eina_List *l;
1104                   Evas_Object *subobj;
1105
1106                   ELM_WIDGET_DATA_GET(parent, sdp);
1107
1108                   sdp->child_can_focus = EINA_FALSE;
1109                   EINA_LIST_FOREACH(sdp->subobjs, l, subobj)
1110                     {
1111                        if ((subobj != sobj) && (_is_focusable(subobj)))
1112                          {
1113                             sdp->child_can_focus = EINA_TRUE;
1114                             break;
1115                          }
1116                     }
1117
1118                   /* break again, child_can_focus went back to
1119                    * original value */
1120                   if (sdp->child_can_focus) break;
1121                   parent = sdp->parent_obj;
1122                }
1123           }
1124
1125         ELM_WIDGET_DATA_GET(sobj, sdc);
1126         sdc->parent_obj = NULL;
1127      }
1128
1129    if (sd->resize_obj == sobj) sd->resize_obj = NULL;
1130
1131    sd->subobjs = eina_list_remove(sd->subobjs, sobj);
1132
1133    evas_object_event_callback_del_full
1134      (sobj, EVAS_CALLBACK_DEL, _on_sub_obj_del, obj);
1135    if (_elm_widget_is(sobj))
1136      evas_object_event_callback_del_full
1137        (sobj, EVAS_CALLBACK_HIDE, _on_sub_obj_hide, NULL);
1138
1139    return EINA_TRUE;
1140 }
1141
1142 /*
1143  * @internal
1144  *
1145  * a resize object is added to and deleted from the smart member and the sub object
1146  * of the parent if the third argument, Eina_Bool sub_obj, is set as EINA_TRUE.
1147  */
1148 EOLIAN static void
1149 _elm_widget_resize_object_set(Eo *obj, Elm_Widget_Smart_Data *sd,
1150                              Evas_Object *sobj,
1151                              Eina_Bool sub_obj)
1152 {
1153    Evas_Object *parent;
1154
1155    if (sd->resize_obj == sobj) return;
1156
1157    // orphan previous resize obj
1158    if (sd->resize_obj && sub_obj)
1159      {
1160         evas_object_clip_unset(sd->resize_obj);
1161         evas_object_smart_member_del(sd->resize_obj);
1162
1163         if (_elm_widget_is(sd->resize_obj))
1164           {
1165              if (elm_widget_focus_get(sd->resize_obj)) _parents_unfocus(obj);
1166           }
1167         elm_widget_sub_object_del(obj, sd->resize_obj);
1168      }
1169
1170    sd->resize_obj = sobj;
1171    if (!sobj) return;
1172
1173    // orphan new resize obj
1174    parent = evas_object_data_get(sobj, "elm-parent");
1175    if (parent && parent != obj)
1176      {
1177         ELM_WIDGET_DATA_GET(parent, sdp);
1178
1179         /* should be there, just being paranoid */
1180         if (sdp)
1181           {
1182              if (sdp->resize_obj == sobj)
1183                elm_widget_resize_object_set(parent, NULL, sub_obj);
1184              else if (sub_obj)
1185                elm_widget_sub_object_del(parent, sobj);
1186           }
1187      }
1188    if (sub_obj)
1189      {
1190         elm_widget_sub_object_add(obj, sobj);
1191         evas_object_smart_member_add(sobj, obj);
1192      }
1193
1194    _smart_reconfigure(sd);
1195 }
1196
1197 /*
1198  * @internal
1199  *
1200  * WARNING: the programmer is responsible, in the scenario of
1201  * exchanging a hover object, of cleaning the old hover "target"
1202  * before
1203  */
1204 EOLIAN static void
1205 _elm_widget_hover_object_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Object *sobj)
1206 {
1207    if (sd->hover_obj)
1208      {
1209         evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1210                                             _on_sub_obj_del, obj);
1211      }
1212    sd->hover_obj = sobj;
1213    if (sd->hover_obj)
1214      {
1215         evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1216                                        _on_sub_obj_del, obj);
1217         _smart_reconfigure(sd);
1218      }
1219 }
1220
1221 EOLIAN static void
1222 _elm_widget_can_focus_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool can_focus)
1223 {
1224    can_focus = !!can_focus;
1225
1226    if (sd->can_focus == can_focus) return;
1227    sd->can_focus = can_focus;
1228    if (sd->can_focus)
1229      {
1230         /* update child_can_focus of parents */
1231         Evas_Object *o = obj;
1232
1233         for (;;)
1234           {
1235              o = elm_widget_parent_get(o);
1236              if (!o) break;
1237              sd = eo_data_scope_get(o, MY_CLASS);
1238              if (!sd || sd->child_can_focus) break;
1239              sd->child_can_focus = EINA_TRUE;
1240           }
1241
1242         evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1243                                        _propagate_event,
1244                                        (void *)(uintptr_t)EVAS_CALLBACK_KEY_DOWN);
1245         evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1246                                        _propagate_event,
1247                                        (void *)(uintptr_t)EVAS_CALLBACK_KEY_UP);
1248         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1249                                        _propagate_event,
1250                                        (void *)(uintptr_t)EVAS_CALLBACK_MOUSE_WHEEL);
1251      }
1252    else
1253      {
1254         evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1255                                        _propagate_event);
1256         evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1257                                        _propagate_event);
1258         evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1259                                        _propagate_event);
1260      }
1261 }
1262
1263 EOLIAN static Eina_Bool
1264 _elm_widget_can_focus_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1265 {
1266    return sd->can_focus;
1267 }
1268
1269 EOLIAN static Eina_Bool
1270 _elm_widget_child_can_focus_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1271 {
1272    return sd->child_can_focus;
1273 }
1274
1275 /**
1276  * @internal
1277  *
1278  * This API makes the widget object and its children to be unfocusable.
1279  *
1280  * This API can be helpful for an object to be deleted.
1281  * When an object will be deleted soon, it and its children may not
1282  * want to get focus (by focus reverting or by other focus controls).
1283  * Then, just use this API before deleting.
1284  *
1285  * @param obj The widget root of sub-tree
1286  * @param tree_unfocusable If true, set the object sub-tree as unfocusable
1287  *
1288  * @ingroup Widget
1289  */
1290 EOLIAN static void
1291 _elm_widget_tree_unfocusable_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool tree_unfocusable)
1292 {
1293    tree_unfocusable = !!tree_unfocusable;
1294    if (sd->tree_unfocusable == tree_unfocusable) return;
1295    sd->tree_unfocusable = tree_unfocusable;
1296    elm_widget_focus_tree_unfocusable_handle(obj);
1297 }
1298
1299 /**
1300  * @internal
1301  *
1302  * This returns true, if the object sub-tree is unfocusable.
1303  *
1304  * @param obj The widget root of sub-tree
1305  * @return EINA_TRUE if the object sub-tree is unfocusable
1306  *
1307  * @ingroup Widget
1308  */
1309 EOLIAN static Eina_Bool
1310 _elm_widget_tree_unfocusable_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1311 {
1312    return sd->tree_unfocusable;
1313 }
1314
1315 /**
1316  * @internal
1317  *
1318  * Get the list of focusable child objects.
1319  *
1320  * This function retruns list of child objects which can get focus.
1321  *
1322  * @param obj The parent widget
1323  * @retrun list of focusable child objects.
1324  *
1325  * @ingroup Widget
1326  */
1327 EOLIAN static Eina_List*
1328 _elm_widget_can_focus_child_list_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1329 {
1330    const Eina_List *l;
1331    Eina_List *child_list = NULL;
1332    Evas_Object *child;
1333
1334    EINA_LIST_FOREACH(sd->subobjs, l, child)
1335      {
1336         if (!_elm_widget_is(child)) continue;
1337         if ((elm_widget_can_focus_get(child)) &&
1338             (evas_object_visible_get(child)) &&
1339             (!elm_widget_disabled_get(child)))
1340           child_list = eina_list_append(child_list, child);
1341         else
1342           {
1343              Eina_List *can_focus_list;
1344              can_focus_list = elm_widget_can_focus_child_list_get(child);
1345              if (can_focus_list)
1346                child_list = eina_list_merge(child_list, can_focus_list);
1347           }
1348      }
1349
1350    return child_list;
1351 }
1352
1353 EOLIAN static void
1354 _elm_widget_highlight_ignore_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Eina_Bool ignore)
1355 {
1356    sd->highlight_ignore = !!ignore;
1357 }
1358
1359 EOLIAN static Eina_Bool
1360 _elm_widget_highlight_ignore_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1361 {
1362    return sd->highlight_ignore;
1363 }
1364
1365 EOLIAN static void
1366 _elm_widget_highlight_in_theme_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Eina_Bool highlight)
1367 {
1368    sd->highlight_in_theme = !!highlight;
1369    /* FIXME: if focused, it should switch from one mode to the other */
1370 }
1371
1372 EOLIAN static Eina_Bool
1373 _elm_widget_highlight_in_theme_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1374 {
1375    return sd->highlight_in_theme;
1376 }
1377
1378 EOLIAN static void
1379 _elm_widget_access_highlight_in_theme_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Eina_Bool highlight)
1380 {
1381    sd->access_highlight_in_theme = !!highlight;
1382 }
1383
1384 EOLIAN static Eina_Bool
1385 _elm_widget_access_highlight_in_theme_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1386 {
1387    return sd->access_highlight_in_theme;
1388 }
1389
1390 EOLIAN static Eina_Bool
1391 _elm_widget_focus_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1392 {
1393    return sd->focused;
1394 }
1395
1396 EOLIAN static Eina_Bool
1397 _elm_widget_highlight_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1398 {
1399    return sd->highlighted;
1400 }
1401
1402 EOLIAN static Evas_Object*
1403 _elm_widget_focused_object_get(Eo *obj, Elm_Widget_Smart_Data *sd)
1404 {
1405    const Evas_Object *subobj;
1406    const Eina_List *l;
1407
1408    if (!sd->focused) return NULL;
1409    EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1410      {
1411         Evas_Object *fobj;
1412         if (!_elm_widget_is(subobj)) continue;
1413         fobj = elm_widget_focused_object_get(subobj);
1414         if (fobj) return fobj;
1415      }
1416    return (Evas_Object *)obj;
1417 }
1418
1419 EOLIAN static Evas_Object*
1420 _elm_widget_top_get(Eo *obj, Elm_Widget_Smart_Data *sd)
1421 {
1422    if (sd->parent_obj)
1423      {
1424         Evas_Object *int_ret = NULL;
1425         eo_do((Eo *) sd->parent_obj, elm_obj_widget_top_get(&int_ret));
1426         return int_ret;
1427      }
1428    return (Evas_Object *)obj;
1429 }
1430
1431 EAPI Eina_Bool
1432 elm_widget_is(const Evas_Object *obj)
1433 {
1434    return _elm_widget_is(obj);
1435 }
1436
1437 EAPI Evas_Object *
1438 elm_widget_parent_widget_get(const Evas_Object *obj)
1439 {
1440    Evas_Object *parent;
1441
1442    if (_elm_widget_is(obj))
1443      {
1444         ELM_WIDGET_DATA_GET(obj, sd);
1445         if (!sd) return NULL;
1446         parent = sd->parent_obj;
1447      }
1448    else
1449      {
1450         parent = evas_object_data_get(obj, "elm-parent");
1451         if (!parent) parent = evas_object_smart_parent_get(obj);
1452      }
1453
1454    while (parent)
1455      {
1456         Evas_Object *elm_parent;
1457         if (_elm_widget_is(parent)) break;
1458         elm_parent = evas_object_data_get(parent, "elm-parent");
1459         if (elm_parent) parent = elm_parent;
1460         else parent = evas_object_smart_parent_get(parent);
1461      }
1462    return parent;
1463 }
1464
1465 EOLIAN static Evas_Object *
1466 _elm_widget_parent2_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1467 {
1468    return sd->parent2;
1469 }
1470
1471 EOLIAN static void
1472 _elm_widget_parent2_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Object *parent)
1473 {
1474    sd->parent2 = parent;
1475 }
1476
1477 EOLIAN static void
1478 _elm_widget_event_callback_add(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Event_Cb func, const void *data)
1479 {
1480    EINA_SAFETY_ON_NULL_RETURN(func);
1481
1482    Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1483    ecb->func = func;
1484    ecb->data = data;
1485    sd->event_cb = eina_list_append(sd->event_cb, ecb);
1486 }
1487
1488 EOLIAN static void*
1489 _elm_widget_event_callback_del(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Event_Cb func, const void *data)
1490 {
1491    EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1492    Eina_List *l;
1493    Elm_Event_Cb_Data *ecd;
1494    EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1495      if ((ecd->func == func) && (ecd->data == data))
1496        {
1497           free(ecd);
1498           sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1499           return (void *)data;
1500        }
1501
1502    return NULL;
1503 }
1504
1505 EOLIAN static Eina_Bool
1506 _elm_widget_event_propagate(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
1507 {
1508    Evas_Object *parent = obj;
1509    Elm_Event_Cb_Data *ecd;
1510    Eina_List *l, *l_prev;
1511
1512    while (parent &&
1513           (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1514      {
1515         ELM_WIDGET_CHECK(parent) EINA_FALSE;
1516         Elm_Widget_Smart_Data *sd = eo_data_scope_get(parent, MY_CLASS);
1517
1518         Eina_Bool int_ret = EINA_FALSE;
1519         eo_do(parent, elm_obj_widget_event(obj, type, event_info, &int_ret));
1520         if (int_ret) return EINA_TRUE;
1521
1522         EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1523           {
1524              if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1525                  (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1526                 return EINA_TRUE;
1527           }
1528         parent = sd->parent_obj;
1529      }
1530
1531    return EINA_FALSE;
1532 }
1533
1534 /**
1535  * @internal
1536  *
1537  * Set custom focus chain.
1538  *
1539  * This function i set one new and overwrite any previous custom focus chain
1540  * with the list of objects. The previous list will be deleted and this list
1541  * will be managed. After setted, don't modity it.
1542  *
1543  * @note On focus cycle, only will be evaluated children of this container.
1544  *
1545  * @param obj The container widget
1546  * @param objs Chain of objects to pass focus
1547  * @ingroup Widget
1548  */
1549 EOLIAN static void
1550 _elm_widget_focus_custom_chain_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_List *objs)
1551 {
1552    if (!_elm_widget_focus_chain_manager_is(obj)) return;
1553
1554    elm_widget_focus_custom_chain_unset(obj);
1555
1556    Eina_List *l;
1557    Evas_Object *o;
1558
1559    EINA_LIST_FOREACH(objs, l, o)
1560      {
1561         evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1562                                        _elm_object_focus_chain_del_cb, obj);
1563      }
1564
1565    sd->focus_chain = objs;
1566 }
1567
1568 /**
1569  * @internal
1570  *
1571  * Get custom focus chain
1572  *
1573  * @param obj The container widget
1574  * @ingroup Widget
1575  */
1576 EOLIAN static const Eina_List*
1577 _elm_widget_focus_custom_chain_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1578 {
1579    return (const Eina_List *)sd->focus_chain;
1580 }
1581
1582 /**
1583  * @internal
1584  *
1585  * Unset custom focus chain
1586  *
1587  * @param obj The container widget
1588  * @ingroup Widget
1589  */
1590 EOLIAN static void
1591 _elm_widget_focus_custom_chain_unset(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
1592 {
1593    Eina_List *l, *l_next;
1594    Evas_Object *o;
1595
1596    EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1597      {
1598         evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1599                                             _elm_object_focus_chain_del_cb, obj);
1600         sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1601      }
1602 }
1603
1604 /**
1605  * @internal
1606  *
1607  * Append object to custom focus chain.
1608  *
1609  * @note If relative_child equal to NULL or not in custom chain, the object
1610  * will be added in end.
1611  *
1612  * @note On focus cycle, only will be evaluated children of this container.
1613  *
1614  * @param obj The container widget
1615  * @param child The child to be added in custom chain
1616  * @param relative_child The relative object to position the child
1617  * @ingroup Widget
1618  */
1619 EOLIAN static void
1620 _elm_widget_focus_custom_chain_append(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Object *child, Evas_Object *relative_child)
1621 {
1622    EINA_SAFETY_ON_NULL_RETURN(child);
1623
1624    if (!_elm_widget_focus_chain_manager_is(obj)) return;
1625
1626    evas_object_event_callback_add(child, EVAS_CALLBACK_DEL,
1627                                   _elm_object_focus_chain_del_cb, obj);
1628
1629    if (!relative_child)
1630      sd->focus_chain = eina_list_append(sd->focus_chain, child);
1631    else
1632      sd->focus_chain = eina_list_append_relative(sd->focus_chain,
1633                                                  child, relative_child);
1634 }
1635
1636 /**
1637  * @internal
1638  *
1639  * Prepend object to custom focus chain.
1640  *
1641  * @note If relative_child equal to NULL or not in custom chain, the object
1642  * will be added in begin.
1643  *
1644  * @note On focus cycle, only will be evaluated children of this container.
1645  *
1646  * @param obj The container widget
1647  * @param child The child to be added in custom chain
1648  * @param relative_child The relative object to position the child
1649  * @ingroup Widget
1650  */
1651 EOLIAN static void
1652 _elm_widget_focus_custom_chain_prepend(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Object *child, Evas_Object *relative_child)
1653 {
1654    EINA_SAFETY_ON_NULL_RETURN(child);
1655
1656    if (!_elm_widget_focus_chain_manager_is(obj)) return;
1657
1658    evas_object_event_callback_add(child, EVAS_CALLBACK_DEL,
1659                                   _elm_object_focus_chain_del_cb, obj);
1660
1661    if (!relative_child)
1662      sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1663    else
1664      sd->focus_chain = eina_list_prepend_relative(sd->focus_chain,
1665                                                   child, relative_child);
1666 }
1667
1668 /**
1669  * @internal
1670  *
1671  * Give focus to next object in object tree.
1672  *
1673  * Give focus to next object in focus chain of one object sub-tree.
1674  * If the last object of chain already have focus, the focus will go to the
1675  * first object of chain.
1676  *
1677  * @param obj The widget root of sub-tree
1678  * @param dir Direction to cycle the focus
1679  *
1680  * @ingroup Widget
1681  */
1682 EOLIAN static void
1683 _elm_widget_focus_cycle(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Elm_Focus_Direction dir)
1684 {
1685    Evas_Object *target = NULL;
1686    if (!_elm_widget_is(obj))
1687      return;
1688    elm_widget_focus_next_get(obj, dir, &target);
1689    if (target)
1690      {
1691         /* access */
1692         if (_elm_config->access_mode)
1693           {
1694              /* highlight cycle does not steal a focus, only after window gets
1695                 the ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE message,
1696                 target will steal focus, or focus its own job. */
1697              if (!_elm_access_auto_highlight_get())
1698                elm_widget_focus_steal(target);
1699
1700              _elm_access_highlight_set(target);
1701              elm_widget_focus_region_show(target);
1702           }
1703         else elm_widget_focus_steal(target);
1704      }
1705 }
1706
1707 /**
1708  * @internal
1709  *
1710  * Give focus to near object(in object tree) in one direction.
1711  *
1712  * Give focus to near object(in object tree) in direction of current
1713  * focused object.  If none focusable object in given direction or
1714  * none focused object in object tree, the focus will not change.
1715  *
1716  * @param obj The reference widget
1717  * @param degree Degree changes clockwise. i.e. 0-degree: Up,
1718  *               90-degree: Right, 180-degree: Down, and 270-degree: Left
1719  * @return EINA_TRUE if focus is moved.
1720  *
1721  * @ingroup Widget
1722  */
1723 EOLIAN static Eina_Bool
1724 _elm_widget_focus_direction_go(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, double degree)
1725 {
1726    Evas_Object *target = NULL;
1727    Evas_Object *current_focused = NULL;
1728    double weight = 0.0;
1729
1730    if (!_elm_widget_is(obj)) return EINA_FALSE;
1731    if (!elm_widget_focus_get(obj)) return EINA_FALSE;
1732
1733    current_focused = elm_widget_focused_object_get(obj);
1734
1735    if (elm_widget_focus_direction_get
1736          (obj, current_focused, degree, &target, &weight))
1737      {
1738         elm_widget_focus_steal(target);
1739         return EINA_TRUE;
1740      }
1741
1742    return EINA_FALSE;
1743 }
1744
1745 static double
1746 _direction_weight_get(const Evas_Object *obj1,
1747                       const Evas_Object *obj2,
1748                       double degree)
1749 {
1750    Evas_Coord obj_x1, obj_y1, w1, h1, obj_x2, obj_y2, w2, h2;
1751    double x1, yy1, x2, yy2, xx1, yyy1, xx2, yyy2;
1752    double ax, ay, cx, cy;
1753    double weight = -1.0, g = 0.0;
1754
1755    if (obj1 == obj2) return 0.0;
1756
1757    degree -= 90.0;
1758    while (degree >= 360.0)
1759      degree -= 360.0;
1760    while (degree < 0.0)
1761      degree += 360.0;
1762
1763    evas_object_geometry_get(obj1, &obj_x1, &obj_y1, &w1, &h1);
1764    cx = obj_x1 + (w1 / 2.0);
1765    cy = obj_y1 + (h1 / 2.0);
1766    evas_object_geometry_get(obj2, &obj_x2, &obj_y2, &w2, &h2);
1767
1768    /* For overlapping cases. */
1769    if (ELM_RECTS_INTERSECT(obj_x1, obj_y1, w1, h1, obj_x2, obj_y2, w2, h2))
1770      return 0.0;
1771
1772    /* Change all points to relative one. */
1773    x1 = obj_x1 - cx;
1774    xx1 = x1 + w1;
1775    yy1 = obj_y1 - cy;
1776    yyy1 = yy1 + h1;
1777    x2 = obj_x2 - cx;
1778    xx2 = x2 + w2;
1779    yy2 = obj_y2 - cy;
1780    yyy2 = yy2 + h2;
1781
1782    /* Get crossing points (ax, ay) between obj1 and a line extending
1783     * to the direction of current degree. */
1784    if (degree == 0.0)
1785      {
1786         ax = xx1;
1787         ay = 0.0;
1788      }
1789    else if (degree == 90.0)
1790      {
1791         ax = 0.0;
1792         ay = yyy1;
1793      }
1794    else if (degree == 180.0)
1795      {
1796         ax = x1;
1797         ay = 0.0;
1798      }
1799    else if (degree == 270.0)
1800      {
1801         ax = 0.0;
1802         ay = yy1;
1803      }
1804    else
1805      {
1806         g = tan(degree * (M_PI / 180.0));
1807         if ((degree > 0.0) && (degree < 90.0))
1808           {
1809              ay = g * xx1;
1810              if (ay <= yyy1) ax = xx1;
1811              else
1812                {
1813                   ax = yyy1 / g;
1814                   ay = yyy1;
1815                }
1816           }
1817         else if ((degree > 90.0) && (degree < 180.0))
1818           {
1819              ay = g * x1;
1820              if (ay <= yyy1) ax = x1;
1821              else
1822                {
1823                   ax = yyy1 / g;
1824                   ay = yyy1;
1825                }
1826           }
1827         else if ((degree > 180.0) && (degree < 270.0))
1828           {
1829              ay = g * x1;
1830              if (ay >= yy1) ax = x1;
1831              else
1832                {
1833                   ax = yy1 / g;
1834                   ay = yy1;
1835                }
1836           }
1837         else
1838           {
1839              ay = g * xx1;
1840              if (ay >= yy1) ax = xx1;
1841              else
1842                {
1843                   ax = yy1 / g;
1844                   ay = yy1;
1845                }
1846           }
1847      }
1848
1849    /* Filter obj2, if it is not in the specific derection. */
1850    int i = 0;
1851    double rx[4] = {0.0, 0.0, 0.0, 0.0}, ry[4] = {0.0, 0.0, 0.0, 0.0};
1852    double t1, t2, u1, v1, u2, v2;
1853
1854    if ((degree == 45.0) || (degree == 225.0) || (degree == 135.0) ||
1855        (degree == 315.0))
1856      {
1857         u1 = 1.0;
1858         v1 = 0.0;
1859         u2 = 0.0;
1860         v2 = 1.0;
1861      }
1862    else
1863      {
1864         double g2 = tan((degree + 45.0) * (M_PI / 180.0));
1865         u1 = (-1.0 * g2);
1866         u2 = (1.0 / g2);
1867         v1 = v2 = 1.0;
1868      }
1869    t1 = (u1 * ax) + (v1 * ay);
1870    t2 = (u2 * ax) + (v2 * ay);
1871
1872 #define _R(x) (int)((x + 0.05) * 10.0)
1873
1874    if ((_R(t1 * ((u1 * x2) + (v1 * yy2))) > 0) && (_R(t2 * ((u2 * x2) +
1875                                                             (v2 * yy2))) > 0))
1876      {
1877         rx[i] = x2;
1878         ry[i++] = yy2;
1879      }
1880    if ((_R(t1 * ((u1 * x2) + (v1 * yyy2))) > 0) && (_R(t2 * ((u2 * x2) +
1881                                                              (v2 * yyy2))) > 0))
1882      {
1883         rx[i] = x2;
1884         ry[i++] = yyy2;
1885      }
1886    if ((_R(t1 * ((u1 * xx2) + (v1 * yy2))) > 0) && (_R(t2 * ((u2 * xx2) +
1887                                                              (v2 * yy2))) > 0))
1888      {
1889         rx[i] = xx2;
1890         ry[i++] = yy2;
1891      }
1892    if ((_R(t1 * ((u1 * xx2) + (v1 * yyy2))) > 0) &&
1893        (_R(t2 * ((u2 * xx2) + (v2 * yyy2))) > 0))
1894      {
1895         rx[i] = xx2;
1896         ry[i++] = yyy2;
1897      }
1898    if (i == 0)
1899      {
1900         if (degree == 0.0)
1901           {
1902              if ((_R(xx2) < 0) || (_R(yy2) > 0) || (_R(yyy2) < 0)) return 0.0;
1903           }
1904         else if (degree == 90.0)
1905           {
1906              if ((_R(yyy2) < 0) || (_R(x2) > 0) || (_R(xx2) < 0)) return 0.0;
1907           }
1908         else if (degree == 180.0)
1909           {
1910              if ((_R(x2) > 0) || (_R(yy2) > 0) || (_R(yyy2) < 0)) return 0.0;
1911           }
1912         else if (degree == 270.0)
1913           {
1914              if ((_R(yy2) > 0) || (_R(x2) > 0) || (_R(xx2) < 0)) return 0.0;
1915           }
1916         else
1917           {
1918              if ((_R(g * x2) >= _R(yy2)) && (_R((g * x2)) <= _R(yyy2)))
1919                {
1920                   if (!((_R(ax * x2) > 0) && (_R(ay * (g * x2)) > 0)))
1921                     return 0.0;
1922                }
1923              else if ((_R(g * xx2) >= _R(yy2)) && (_R((g * xx2)) <= _R(yyy2)))
1924                {
1925                   if (!((_R(ax * xx2) > 0) && (_R(ay * (g * xx2)) > 0)))
1926                     return 0.0;
1927                }
1928              else if ((_R((1.0 / g) * yy2) >= _R(xx2)) && (_R((1.0 / g) * yy2)
1929                                                            <= _R(xx2)))
1930                {
1931                   if (!((_R(ax * ((1.0 / g) * yy2)) > 0)
1932                         && (_R(ay * yy2) > 0)))
1933                     return 0.0;
1934                }
1935              else if ((_R((1.0 / g) * yyy2) >= _R(xx2)) &&
1936                       (_R((1.0 / g) * yyy2) <= _R(xx2)))
1937                {
1938                   if (!((_R(ax * ((1.0 / g) * yyy2)) > 0)
1939                         && (_R(ay * yyy2) > 0))) return 0.0;
1940                }
1941              else return 0.0;
1942           }
1943      }
1944
1945    /* Calculate the weight for obj2. */
1946    if (degree == 0.0)
1947      {
1948         if (_R(xx1) > _R(x2)) weight = -1.0;
1949         else if ((_R(yy2) >= _R(yy1)) && (_R(yyy2) <= _R(yyy1)))
1950           weight = (x2 - xx1) * (x2 - xx1);
1951         else if (_R(yy2) > 0)
1952           weight = ((x2 - xx1) * (x2 - xx1)) + (yy2 * yy2);
1953         else if (_R(yyy2) < 0)
1954           weight = ((x2 - xx1) * (x2 - xx1)) + (yyy2 * yyy2);
1955         else weight = (x2 - xx1) * (x2 - xx1);
1956      }
1957    else if (degree == 90.0)
1958      {
1959         if (_R(yyy1) > _R(yy2)) weight = -1.0;
1960         else if ((_R(x2) >= _R(x1)) && (_R(xx2) <= _R(xx1)))
1961           weight = (yy2 - yyy1) * (yy2 - yyy1);
1962         else if (_R(x2) > 0)
1963           weight = (x2 * x2) + ((yy2 - yyy1) * (yy2 - yyy1));
1964         else if (_R(xx2) < 0)
1965           weight = (xx2 * xx2) + ((yy2 - yyy1) * (yy2 - yyy1));
1966         else weight = (yy2 - yyy1) * (yy2 - yyy1);
1967      }
1968    else if (degree == 180.0)
1969      {
1970         if (_R(x1) < _R(xx2)) weight = -1.0;
1971         else if ((_R(yy2) >= _R(yy1)) && (_R(yyy2) <= _R(yyy1)))
1972           weight = (x1 - xx2) * (x1 - xx2);
1973         else if (_R(yy2) > 0)
1974           weight = ((x1 - xx2) * (x1 - xx2)) + (yy2 * yy2);
1975         else if (_R(yyy2) < 0)
1976           weight = ((x1 - xx2) * (x1 - xx2)) + (yyy2 * yyy2);
1977         else weight = (x1 - xx2) * (x1 - xx2);
1978      }
1979    else if (degree == 270.0)
1980      {
1981         if (_R(yy1) < _R(yyy2)) weight = -1.0;
1982         else if ((_R(x2) >= _R(x1)) && (_R(xx2) <= _R(xx1)))
1983           weight = (yy1 - yyy2) * (yy1 - yyy2);
1984         else if (_R(x2) > 0)
1985           weight = (x2 * x2) + ((yy1 - yyy2) * (yy1 - yyy2));
1986         else if (_R(xx2) < 0)
1987           weight = (xx2 * xx2) + ((yy1 - yyy2) * (yy1 - yyy2));
1988         else weight = (yy1 - yyy2) * (yy1 - yyy2);
1989      }
1990    else
1991      {
1992         int j = 0, k = 0;
1993         double sx[4] = {0.0, 0.0, 0.0, 0.0}, sy[4] = {0.0, 0.0, 0.0, 0.0};
1994         double t_weight[4] = {-1.0, -1.0, -1.0, -1.0};
1995         if ((_R(g * x2) >= _R(yy2)) && (_R(g * x2) <= _R(yyy2)))
1996           {
1997              sx[j] = x2;
1998              sy[j] = g * x2;
1999              t_weight[j++] = ((ax - x2) * (ax - x2)) +
2000                ((ay - (g * x2)) * (ay - (g * x2)));
2001           }
2002         if ((_R(g * xx2) >= _R(yy2)) && (_R(g * xx2) <= _R(yyy2)))
2003           {
2004              sx[j] = xx2;
2005              sy[j] = g * xx2;
2006              t_weight[j++] = ((ax - xx2) * (ax - xx2)) +
2007                ((ay - (g * xx2)) * (ay - (g * xx2)));
2008           }
2009         if ((_R((1.0 / g) * yy2) >= _R(x2)) && (_R((1.0 / g) * yy2) <= _R(xx2)))
2010           {
2011              sx[j] = (1.0 / g) * yy2;
2012              sy[j] = yy2;
2013              t_weight[j++] =
2014                ((ax - ((1.0 / g) * yy2)) * (ax - ((1.0 / g) * yy2))) +
2015                ((ay - yy2) * (ay - yy2));
2016           }
2017         if ((_R((1.0 / g) * yyy2) >= _R(x2)) && (_R((1.0 / g) * yyy2)
2018                                                  <= _R(xx2)))
2019           {
2020              sx[j] = (1.0 / g) * yyy2;
2021              sy[j] = yyy2;
2022              t_weight[j++] =
2023                ((ax - ((1.0 / g) * yyy2)) * (ax - ((1.0 / g) * yyy2))) +
2024                ((ay - yyy2) * (ay - yyy2));
2025           }
2026
2027         if ((j > 2) || ((j == 2) && ((_R(sx[0]) != _R(sx[1])) ||
2028                                      (_R(sy[0]) != _R(sy[1])))))
2029           {
2030              for (; k < j; k++)
2031                {
2032                   if (_R(t_weight[k]) == 0) return -1.0;
2033                   if ((1 / weight) < (1 / t_weight[k])) weight = t_weight[k];
2034                }
2035           }
2036         else
2037           {
2038              for (; k < i; k++)
2039                {
2040                   double ccx, ccy, t1_weight, x_diff, y_diff;
2041                   ccx = ((1.0 / g) * rx[k] + ry[k]) / (g + (1.0 / g));
2042                   ccy = g * ccx;
2043                   x_diff = rx[k] - ccx;
2044                   if (x_diff < 0) x_diff *= -1.0;
2045                   y_diff = ry[k] - ccy;
2046                   if (y_diff < 0) y_diff *= -1.0;
2047                   t1_weight =
2048                     (((ax - ccx) * (ax - ccx)) + ((ay - ccy) * (ay - ccy))) +
2049                     ((x_diff * x_diff * x_diff) + (y_diff * y_diff * y_diff));
2050                   if ((_R(t1_weight) != 0) && ((1 / weight) < (1 / t1_weight)))
2051                     weight = t1_weight;
2052                }
2053           }
2054      }
2055    /* Return the current object's weight. */
2056    if (weight == -1.0) return 0.0;
2057    if (_R(weight) == 0) return -1.0;
2058
2059 #undef _R
2060
2061    return 1.0 / weight;
2062 }
2063
2064 /**
2065  * @internal
2066  *
2067  * Get near object in one direction of base object.
2068  *
2069  * Get near object(in the object sub-tree) in one direction of
2070  * base object. Return the near object by reference.
2071  * By initializing weight, you can filter objects locating far
2072  * from base object. If object is in the specific direction,
2073  * weight is (1/(distance^2)). If object is not exactly in one
2074  * direction, some penalty will be added.
2075  *
2076  * @param obj The widget root of sub-tree
2077  * @param base The base object of the direction
2078  * @param degree Degree changes clockwise. i.e. 0-degree: Up,
2079  *               90-degree: Right, 180-degree: Down, and 270-degree: Left
2080  * @param direction The near object in one direction
2081  * @param weight The weight is bigger when the object is located near
2082  * @return EINA_TRUE if near object is updated.
2083  *
2084  * @ingroup Widget
2085  */
2086
2087 EOLIAN static Eina_Bool
2088 _elm_widget_focus_direction_get(Eo *obj, Elm_Widget_Smart_Data *sd, const Evas_Object *base, double degree, Evas_Object **direction, double *weight)
2089 {
2090    double c_weight;
2091
2092    /* -1 means the best was already decided. Don't need any more searching. */
2093    if (!direction || !weight || !base || (obj == base))
2094      return EINA_FALSE;
2095
2096    /* Ignore if disabled */
2097    if ((!evas_object_visible_get(obj))
2098        || (elm_widget_disabled_get(obj))
2099        || (elm_widget_tree_unfocusable_get(obj)))
2100      return EINA_FALSE;
2101
2102    /* Try use hook */
2103    if (_internal_elm_widget_focus_direction_manager_is(obj))
2104      {
2105         Eina_Bool int_ret = EINA_FALSE;
2106         eo_do((Eo *)obj, elm_obj_widget_focus_direction(base, degree, direction, weight, &int_ret));
2107         return int_ret;
2108      }
2109
2110    if (!elm_widget_can_focus_get(obj) || elm_widget_focus_get(obj))
2111      return EINA_FALSE;
2112
2113    c_weight = _direction_weight_get(base, obj, degree);
2114    if ((c_weight == -1.0) ||
2115        ((c_weight != 0.0) && (*weight != -1.0) &&
2116         ((int)(*weight * 1000000) <= (int)(c_weight * 1000000))))
2117      {
2118         if (*direction &&
2119             ((int)(*weight * 1000000) == (int)(c_weight * 1000000)))
2120           {
2121              ELM_WIDGET_DATA_GET(*direction, sd1);
2122              if (sd1)
2123                {
2124                   if (sd->focus_order <= sd1->focus_order)
2125                     return EINA_FALSE;
2126                }
2127           }
2128         *direction = (Evas_Object *)obj;
2129         *weight = c_weight;
2130         return EINA_TRUE;
2131      }
2132
2133    return EINA_FALSE;
2134 }
2135
2136 /**
2137  * @internal
2138  *
2139  * Get near object in one direction of base object in list.
2140  *
2141  * Get near object in one direction of base object in the specific
2142  * object list. Return the near object by reference.
2143  * By initializing weight, you can filter objects locating far
2144  * from base object. If object is in the specific direction,
2145  * weight is (1/(distance^2)). If object is not exactly in one
2146  * direction, some penalty will be added.
2147  *
2148  * @param obj The widget root of sub-tree
2149  * @param base The base object of the direction
2150  * @param items list with ordered objects
2151  * @param list_data_get function to get the object from one item of list
2152  * @param degree Degree changes clockwise. i.e. 0-degree: Up,
2153  *               90-degree: Right, 180-degree: Down, and 270-degree: Left
2154  * @param direction The near object in one direction
2155  * @param weight The weight is bigger when the object is located near
2156  * @return EINA_TRUE if near object is updated.
2157  *
2158  * @ingroup Widget
2159  */
2160 EOLIAN static Eina_Bool
2161 _elm_widget_focus_list_direction_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const Evas_Object *base, const Eina_List *items, list_data_get_func_type list_data_get, double degree, Evas_Object **direction, double *weight)
2162 {
2163    if (!direction || !weight || !base || !items)
2164      return EINA_FALSE;
2165
2166    const Eina_List *l = items;
2167    Evas_Object *current_best = *direction;
2168
2169    for (; l; l = eina_list_next(l))
2170      {
2171         Evas_Object *cur = list_data_get(l);
2172         if (cur && _elm_widget_is(cur))
2173           elm_widget_focus_direction_get(cur, base, degree, direction, weight);
2174      }
2175    if (current_best != *direction) return EINA_TRUE;
2176
2177    return EINA_FALSE;
2178 }
2179
2180 /**
2181  * @internal
2182  *
2183  * Get next object in focus chain of object tree.
2184  *
2185  * Get next object in focus chain of one object sub-tree.
2186  * Return the next object by reference. If don't have any candidate to receive
2187  * focus before chain end, the first candidate will be returned.
2188  *
2189  * @param obj The widget root of sub-tree
2190  * @param dir Direction of focus chain
2191  * @param next The next object in focus chain
2192  * @return EINA_TRUE if don't need focus chain restart/loop back
2193  *         to use 'next' obj.
2194  *
2195  * @ingroup Widget
2196  */
2197 EOLIAN static Eina_Bool
2198 _elm_widget_focus_next_get(Eo *obj, Elm_Widget_Smart_Data *sd, Elm_Focus_Direction dir, Evas_Object **next)
2199 {
2200    Elm_Access_Info *ac;
2201
2202    if (!next)
2203      return EINA_FALSE;
2204    *next = NULL;
2205
2206    /* Ignore if disabled */
2207    if (_elm_config->access_mode && _elm_access_auto_highlight_get())
2208      {
2209         if (!evas_object_visible_get(obj)
2210             || (elm_widget_tree_unfocusable_get(obj)))
2211           return EINA_FALSE;
2212      }
2213    else
2214      {
2215         if ((!evas_object_visible_get(obj))
2216             || (elm_widget_disabled_get(obj))
2217             || (elm_widget_tree_unfocusable_get(obj)))
2218           return EINA_FALSE;
2219      }
2220
2221    /* Try use hook */
2222    if (_elm_widget_focus_chain_manager_is(obj))
2223      {
2224         Eina_Bool int_ret = EINA_FALSE;
2225         eo_do((Eo *)obj, elm_obj_widget_focus_next(dir, next, &int_ret));
2226         if (!int_ret && elm_widget_focus_get(obj))
2227           {
2228              Evas_Object *o = NULL;
2229              if (dir == ELM_FOCUS_PREVIOUS)
2230                o = sd->focus_previous;
2231              else if (dir == ELM_FOCUS_NEXT)
2232                o = sd->focus_next;
2233              else if (dir == ELM_FOCUS_UP)
2234                o = sd->focus_up;
2235              else if (dir == ELM_FOCUS_DOWN)
2236                o = sd->focus_down;
2237              else if (dir == ELM_FOCUS_RIGHT)
2238                o = sd->focus_right;
2239              else if (dir == ELM_FOCUS_LEFT)
2240                o = sd->focus_left;
2241
2242              if (o)
2243                {
2244                   *next = o;
2245                   return EINA_TRUE;
2246                }
2247           }
2248         return int_ret;
2249      }
2250
2251    /* access object does not check sd->can_focus, because an object could
2252       have highlight even though the object is not focusable. */
2253    if (_elm_config->access_mode && _elm_access_auto_highlight_get())
2254      {
2255         ac = _elm_access_info_get(obj);
2256         if (!ac) return EINA_FALSE;
2257
2258         /* check whether the hover object is visible or not */
2259         if (!evas_object_visible_get(ac->hoverobj))
2260           return EINA_FALSE;
2261      }
2262    else if (!elm_widget_can_focus_get(obj))
2263      return EINA_FALSE;
2264
2265    if (elm_widget_focus_get(obj))
2266      {
2267         if (dir == ELM_FOCUS_PREVIOUS)
2268           *next = sd->focus_previous;
2269         else if (dir == ELM_FOCUS_NEXT)
2270           *next = sd->focus_next;
2271         else if (dir == ELM_FOCUS_UP)
2272           *next = sd->focus_up;
2273         else if (dir == ELM_FOCUS_DOWN)
2274           *next = sd->focus_down;
2275         else if (dir == ELM_FOCUS_RIGHT)
2276           *next = sd->focus_right;
2277         else if (dir == ELM_FOCUS_LEFT)
2278           *next = sd->focus_left;
2279
2280         if (*next) return EINA_TRUE;
2281      }
2282
2283    /* Return */
2284    *next = (Evas_Object *)obj;
2285    return !ELM_WIDGET_FOCUS_GET(obj);
2286 }
2287
2288 /**
2289  * @internal
2290  *
2291  * Get next object in focus chain of object tree in list.
2292  *
2293  * Get next object in focus chain of one object sub-tree ordered by one list.
2294  * Return the next object by reference. If don't have any candidate to receive
2295  * focus before list end, the first candidate will be returned.
2296  *
2297  * @param obj The widget root of sub-tree
2298  * @param items list with ordered objects
2299  * @param list_data_get function to get the object from one item of list
2300  * @param dir Direction of focus chain
2301  * @param next The next object in focus chain
2302  * @return EINA_TRUE if don't need focus chain restart/loop back
2303  *         to use 'next' obj.
2304  *
2305  * @ingroup Widget
2306  */
2307 EOLIAN static Eina_Bool
2308 _elm_widget_focus_list_next_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const Eina_List *items, list_data_get_func_type list_data_get, Elm_Focus_Direction dir, Evas_Object **next)
2309 {
2310    Eina_List *(*list_next)(const Eina_List *list) = NULL;
2311    Evas_Object *focused_object = NULL;
2312
2313    if (!next)
2314      return EINA_FALSE;
2315    *next = NULL;
2316
2317    if (!_elm_widget_is(obj))
2318      return EINA_FALSE;
2319
2320    if (!items)
2321      return EINA_FALSE;
2322
2323    /* When Up, Down, Right, or Left, try direction_get first. */
2324    focused_object = elm_widget_focused_object_get(obj);
2325    if (focused_object)
2326      {
2327         if((dir == ELM_FOCUS_UP)
2328            || (dir == ELM_FOCUS_DOWN)
2329            || (dir == ELM_FOCUS_RIGHT)
2330            || (dir == ELM_FOCUS_LEFT))
2331           {
2332              *next = elm_widget_focus_next_object_get(focused_object, dir);
2333              if (*next) return EINA_TRUE;
2334              else
2335                {
2336                   Evas_Object *n = NULL;
2337                   double degree;
2338                   double weight = 0.0;
2339
2340                   if (dir == ELM_FOCUS_UP) degree = 0.0;
2341                   else if (dir == ELM_FOCUS_DOWN) degree = 180.0;
2342                   else if (dir == ELM_FOCUS_RIGHT) degree = 90.0;
2343                   else if (dir == ELM_FOCUS_LEFT) degree = 270.0;
2344
2345                   if (elm_widget_focus_list_direction_get(obj, focused_object,
2346                                                           items, list_data_get,
2347                                                           degree, &n, &weight))
2348                     {
2349                        *next = n;
2350                        return EINA_TRUE;
2351                     }
2352                }
2353           }
2354      }
2355
2356    /* Direction */
2357    if (dir == ELM_FOCUS_PREVIOUS)
2358      {
2359         items = eina_list_last(items);
2360         list_next = eina_list_prev;
2361      }
2362    else if ((dir == ELM_FOCUS_NEXT)
2363             || (dir == ELM_FOCUS_UP)
2364             || (dir == ELM_FOCUS_DOWN)
2365             || (dir == ELM_FOCUS_RIGHT)
2366             || (dir == ELM_FOCUS_LEFT))
2367      list_next = eina_list_next;
2368    else
2369      return EINA_FALSE;
2370
2371    const Eina_List *l = items;
2372
2373    /* Recovery last focused sub item */
2374    if (ELM_WIDGET_FOCUS_GET(obj))
2375      {
2376         for (; l; l = list_next(l))
2377           {
2378              Evas_Object *cur = list_data_get(l);
2379              if (ELM_WIDGET_FOCUS_GET(cur)) break;
2380           }
2381
2382          /* Focused object, but no focused sub item */
2383          if (!l) l = items;
2384      }
2385
2386    const Eina_List *start = l;
2387    Evas_Object *to_focus = NULL;
2388
2389    /* Iterate sub items */
2390    /* Go to the end of list */
2391    for (; l; l = list_next(l))
2392      {
2393         Evas_Object *tmp = NULL;
2394         Evas_Object *cur = list_data_get(l);
2395
2396         if (!cur) continue;
2397         if (!_elm_widget_is(cur)) continue;
2398         if (elm_widget_parent_get(cur) != obj)
2399           continue;
2400
2401         /* Try Focus cycle in subitem */
2402         if (elm_widget_focus_next_get(cur, dir, &tmp))
2403           {
2404              *next = tmp;
2405              return EINA_TRUE;
2406           }
2407         else if ((dir == ELM_FOCUS_UP)
2408                  || (dir == ELM_FOCUS_DOWN)
2409                  || (dir == ELM_FOCUS_RIGHT)
2410                  || (dir == ELM_FOCUS_LEFT))
2411           {
2412              if (tmp && elm_widget_focus_get(cur))
2413                {
2414                   *next = tmp;
2415                   return EINA_FALSE;
2416                }
2417           }
2418         else if ((tmp) && (!to_focus))
2419           to_focus = tmp;
2420      }
2421
2422    l = items;
2423
2424    /* Get First possible */
2425    for (; l != start; l = list_next(l))
2426      {
2427         Evas_Object *tmp = NULL;
2428         Evas_Object *cur = list_data_get(l);
2429
2430         if (elm_widget_parent_get(cur) != obj)
2431           continue;
2432
2433         /* Try Focus cycle in subitem */
2434         elm_widget_focus_next_get(cur, dir, &tmp);
2435         if (tmp)
2436           {
2437              *next = tmp;
2438              return EINA_FALSE;
2439           }
2440      }
2441
2442    *next = to_focus;
2443    return EINA_FALSE;
2444 }
2445
2446 /**
2447  * @internal
2448  *
2449  * Get next object which was set with specific focus direction.
2450  *
2451  * Get next object which was set by elm_widget_focus_next_object_set
2452  * with specific focus directioin.
2453  *
2454  * @param obj The widget
2455  * @param dir Direction of focus
2456  * @return Widget which was registered with sepecific focus direction.
2457  *
2458  * @ingroup Widget
2459  */
2460 EOLIAN static Evas_Object*
2461 _elm_widget_focus_next_object_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Focus_Direction dir)
2462 {
2463    Evas_Object *ret;
2464
2465    if (dir == ELM_FOCUS_PREVIOUS)
2466      ret = sd->focus_previous;
2467    else if (dir == ELM_FOCUS_NEXT)
2468      ret = sd->focus_next;
2469    else if (dir == ELM_FOCUS_UP)
2470      ret = sd->focus_up;
2471    else if (dir == ELM_FOCUS_DOWN)
2472      ret = sd->focus_down;
2473    else if (dir == ELM_FOCUS_RIGHT)
2474      ret = sd->focus_right;
2475    else if (dir == ELM_FOCUS_LEFT)
2476      ret = sd->focus_left;
2477
2478    return ret;
2479 }
2480
2481 /**
2482  * @internal
2483  *
2484  * Set next object with specific focus direction.
2485  *
2486  * When a widget is set with specific focus direction, this widget will be
2487  * the first candidate when finding the next focus object.
2488  * Focus next object can be registered with six directions that are previous,
2489  * next, up, down, right, and left.
2490  *
2491  * @param obj The widget
2492  * @param next Next focus object
2493  * @param dir Direction of focus
2494  *
2495  * @ingroup Widget
2496  */
2497 EOLIAN static void
2498 _elm_widget_focus_next_object_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Object *next, Elm_Focus_Direction dir)
2499 {
2500
2501    if (dir == ELM_FOCUS_PREVIOUS)
2502      sd->focus_previous = next;
2503    else if (dir == ELM_FOCUS_NEXT)
2504      sd->focus_next = next;
2505    else if (dir == ELM_FOCUS_UP)
2506      sd->focus_up = next;
2507    else if (dir == ELM_FOCUS_DOWN)
2508      sd->focus_down = next;
2509    else if (dir == ELM_FOCUS_RIGHT)
2510      sd->focus_right = next;
2511    else if (dir == ELM_FOCUS_LEFT)
2512      sd->focus_left = next;
2513 }
2514
2515 EOLIAN static void
2516 _elm_widget_parent_highlight_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool highlighted)
2517 {
2518    highlighted = !!highlighted;
2519
2520    Evas_Object *o = elm_widget_parent_get(obj);
2521
2522    if (o) elm_widget_parent_highlight_set(o, highlighted);
2523
2524    sd->highlighted = highlighted;
2525 }
2526
2527 EOLIAN static void
2528 _elm_widget_signal_emit(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *emission, const char *source)
2529 {
2530    if (evas_object_smart_type_check(obj, "elm_layout"))
2531      elm_layout_signal_emit(obj, emission, source);
2532    else if (evas_object_smart_type_check(obj, "elm_icon"))
2533      {
2534         WRN("Deprecated function. This functionality on icon objects"
2535             " will be dropped on a next release.");
2536         _elm_icon_signal_emit(obj, emission, source);
2537      }
2538 }
2539
2540 EOLIAN static void
2541 _elm_widget_signal_callback_add(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *emission, const char *source, Edje_Signal_Cb func, void *data)
2542 {
2543    EINA_SAFETY_ON_NULL_RETURN(func);
2544
2545    if (evas_object_smart_type_check(obj, "elm_layout"))
2546      elm_layout_signal_callback_add(obj, emission, source, func, data);
2547    else if (evas_object_smart_type_check(obj, "elm_icon"))
2548      {
2549         WRN("Deprecated function. This functionality on icon objects"
2550             " will be dropped on a next release.");
2551
2552         _elm_icon_signal_callback_add(obj, emission, source, func, data);
2553      }
2554 }
2555
2556 EOLIAN static void*
2557 _elm_widget_signal_callback_del(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *emission, const char *source, Edje_Signal_Cb func)
2558 {
2559    void *data = NULL;
2560
2561    if (evas_object_smart_type_check(obj, "elm_layout"))
2562      data = elm_layout_signal_callback_del(obj, emission, source, func);
2563    else if (evas_object_smart_type_check(obj, "elm_icon"))
2564      {
2565         WRN("Deprecated function. This functionality on icon objects"
2566             " will be dropped on a next release.");
2567
2568         data = _elm_icon_signal_callback_del(obj, emission, source, func);
2569      }
2570
2571    return data;
2572 }
2573
2574 EOLIAN static void
2575 _elm_widget_focus_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool focus)
2576 {
2577    if (!sd->focused)
2578      {
2579         focus_order++;
2580         sd->focus_order = focus_order;
2581         sd->focused = EINA_TRUE;
2582         eo_do(obj, elm_obj_widget_on_focus(NULL));
2583      }
2584
2585    if (focus)
2586      {
2587         if ((_is_focusable(sd->resize_obj)) &&
2588             (!elm_widget_disabled_get(sd->resize_obj)))
2589           {
2590              elm_widget_focus_set(sd->resize_obj, focus);
2591           }
2592         else
2593           {
2594              const Eina_List *l;
2595              Evas_Object *child;
2596
2597              EINA_LIST_FOREACH(sd->subobjs, l, child)
2598                {
2599                   if (!_elm_widget_is(child)) continue;
2600                   if ((_is_focusable(child)) &&
2601                       (!elm_widget_disabled_get(child)))
2602                     {
2603                        elm_widget_focus_set(child, focus);
2604                        break;
2605                     }
2606                }
2607           }
2608      }
2609    else
2610      {
2611         const Eina_List *l;
2612         Evas_Object *child;
2613
2614         EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
2615           {
2616              if (!_elm_widget_is(child)) continue;
2617              if ((_is_focusable(child)) &&
2618                  (!elm_widget_disabled_get(child)))
2619                {
2620                   elm_widget_focus_set(child, focus);
2621                   break;
2622                }
2623           }
2624      }
2625 }
2626
2627 EOLIAN static Evas_Object*
2628 _elm_widget_parent_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
2629 {
2630    return sd->parent_obj;
2631 }
2632
2633 EOLIAN static void
2634 _elm_widget_focused_object_clear(Eo *obj, Elm_Widget_Smart_Data *sd)
2635 {
2636    if (!sd->focused) return;
2637    if (sd->resize_obj && elm_widget_is(sd->resize_obj) &&
2638          elm_widget_focus_get(sd->resize_obj))
2639      {
2640         eo_do(sd->resize_obj, elm_obj_widget_focused_object_clear());
2641      }
2642    else
2643      {
2644         const Eina_List *l;
2645         Evas_Object *child;
2646         EINA_LIST_FOREACH(sd->subobjs, l, child)
2647           {
2648              if (_elm_widget_is(child) && elm_widget_focus_get(child))
2649                {
2650                   eo_do(child, elm_obj_widget_focused_object_clear());
2651                   break;
2652                }
2653           }
2654      }
2655    sd->focused = EINA_FALSE;
2656    eo_do(obj, elm_obj_widget_on_focus(NULL));
2657 }
2658
2659 EOLIAN static void
2660 _elm_widget_focus_steal(Eo *obj, Elm_Widget_Smart_Data *sd)
2661 {
2662    Evas_Object *parent, *parent2, *o;
2663
2664    if (sd->focused) return;
2665    if (sd->disabled) return;
2666    if (!sd->can_focus) return;
2667    if (sd->tree_unfocusable) return;
2668    parent = obj;
2669    for (;; )
2670      {
2671         o = elm_widget_parent_get(parent);
2672         if (!o) break;
2673         sd = eo_data_scope_get(o, MY_CLASS);
2674         if (sd->disabled || sd->tree_unfocusable) return;
2675         if (sd->focused) break;
2676         parent = o;
2677      }
2678    if ((!elm_widget_parent_get(parent)) &&
2679        (!elm_widget_parent2_get(parent)))
2680      eo_do(parent, elm_obj_widget_focused_object_clear());
2681    else
2682      {
2683         parent2 = elm_widget_parent_get(parent);
2684         if (!parent2) parent2 = elm_widget_parent2_get(parent);
2685         parent = parent2;
2686         sd = eo_data_scope_get(parent, MY_CLASS);
2687         if (sd)
2688           {
2689              if (sd->resize_obj && elm_widget_is(sd->resize_obj) &&
2690                    elm_widget_focus_get(sd->resize_obj))
2691                {
2692                   eo_do(sd->resize_obj, elm_obj_widget_focused_object_clear());
2693                }
2694              else
2695                {
2696                   const Eina_List *l;
2697                   Evas_Object *child;
2698                   EINA_LIST_FOREACH(sd->subobjs, l, child)
2699                     {
2700                        if (_elm_widget_is(child) && elm_widget_focus_get(child))
2701                          {
2702                             eo_do(child, elm_obj_widget_focused_object_clear());
2703                             break;
2704                          }
2705                     }
2706                }
2707           }
2708      }
2709    _parent_focus(obj);
2710    return;
2711 }
2712
2713 EOLIAN static void
2714 _elm_widget_focus_restore(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
2715 {
2716    Evas_Object *newest = NULL;
2717    unsigned int newest_focus_order = 0;
2718
2719    newest = elm_widget_newest_focus_order_get(obj, &newest_focus_order, EINA_TRUE);
2720    if (newest)
2721      {
2722         elm_object_focus_set(newest, EINA_FALSE);
2723         elm_object_focus_set(newest, EINA_TRUE);
2724      }
2725 }
2726
2727 void
2728 _elm_widget_top_win_focused_set(Evas_Object *obj,
2729                                 Eina_Bool top_win_focused)
2730 {
2731    const Eina_List *l;
2732    Evas_Object *child;
2733    API_ENTRY return;
2734
2735    if (sd->top_win_focused == top_win_focused) return;
2736    EINA_LIST_FOREACH(sd->subobjs, l, child)
2737      {
2738         if (elm_widget_is(child))
2739           _elm_widget_top_win_focused_set(child, top_win_focused);
2740      }
2741    sd->top_win_focused = top_win_focused;
2742 }
2743
2744 Eina_Bool
2745 _elm_widget_top_win_focused_get(const Evas_Object *obj)
2746 {
2747    API_ENTRY return EINA_FALSE;
2748    return sd->top_win_focused;
2749 }
2750
2751 EOLIAN static void
2752 _elm_widget_disabled_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool disabled)
2753 {
2754    if (sd->disabled == disabled) return;
2755    sd->disabled = !!disabled;
2756    elm_widget_focus_disabled_handle(obj);
2757    eo_do(obj, elm_obj_widget_disable(NULL));
2758 }
2759
2760 EOLIAN static Eina_Bool
2761 _elm_widget_disabled_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
2762 {
2763    return sd->disabled;
2764 }
2765
2766 EOLIAN static void
2767 _elm_widget_show_region_set(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool forceshow)
2768 {
2769
2770    Evas_Object *parent_obj, *child_obj;
2771    Evas_Coord px, py, cx, cy, nx, ny;
2772
2773
2774    evas_smart_objects_calculate(evas_object_evas_get(obj));
2775
2776    if (!forceshow && (x == sd->rx) && (y == sd->ry) &&
2777        (w == sd->rw) && (h == sd->rh)) return;
2778
2779    sd->rx = x;
2780    sd->ry = y;
2781    sd->rw = w;
2782    sd->rh = h;
2783    if (sd->on_show_region)
2784      {
2785         sd->on_show_region
2786            (sd->on_show_region_data, obj);
2787
2788         if (_elm_scrollable_is(obj))
2789           {
2790              eo_do(obj, elm_interface_scrollable_content_pos_get(&nx, &ny));
2791              x -= nx;
2792              y -= ny;
2793           }
2794      }
2795
2796    do
2797      {
2798         parent_obj = sd->parent_obj;
2799         child_obj = sd->obj;
2800         if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
2801         sd = eo_data_scope_get(parent_obj, MY_CLASS);
2802         if (!sd) break;
2803
2804         evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
2805         evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
2806
2807         x += (cx - px);
2808         y += (cy - py);
2809         sd->rx = x;
2810         sd->ry = y;
2811         sd->rw = w;
2812         sd->rh = h;
2813
2814         if (sd->on_show_region)
2815           {
2816              sd->on_show_region
2817                (sd->on_show_region_data, parent_obj);
2818           }
2819      }
2820    while (parent_obj);
2821 }
2822
2823 EOLIAN static void
2824 _elm_widget_show_region_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2825 {
2826    if (x) *x = sd->rx;
2827    if (y) *y = sd->ry;
2828    if (w) *w = sd->rw;
2829    if (h) *h = sd->rh;
2830 }
2831
2832 /**
2833  * @internal
2834  *
2835  * Get the focus region of the given widget.
2836  *
2837  * @return show region or not
2838  * (@c EINA_TRUE = show region/@c EINA_FALSE = do not show region). Default is @c EINA_FALSE.
2839  *
2840  * The focus region is the area of a widget that should brought into the
2841  * visible area when the widget is focused. Mostly used to show the part of
2842  * an entry where the cursor is, for example. The area returned is relative
2843  * to the object @p obj.
2844  *
2845  * @param obj The widget object
2846  * @param x Where to store the x coordinate of the area
2847  * @param y Where to store the y coordinate of the area
2848  * @param w Where to store the width of the area
2849  * @param h Where to store the height of the area
2850  *
2851  * @ingroup Widget
2852  */
2853 EOLIAN static Eina_Bool
2854 _elm_widget_focus_region_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2855 {
2856    Eina_Bool int_ret = EINA_FALSE;
2857    eo_do((Eo *)obj, elm_obj_widget_on_focus_region(x, y, w, h, &int_ret));
2858    if (!int_ret)
2859      {
2860         evas_object_geometry_get(obj, NULL, NULL, w, h);
2861         if (x) *x = 0;
2862         if (y) *y = 0;
2863      }
2864    return EINA_TRUE;
2865 }
2866
2867 EOLIAN static void
2868 _elm_widget_parents_bounce_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Eina_Bool *horiz, Eina_Bool *vert)
2869 {
2870    Evas_Object *parent_obj = obj;
2871    Eina_Bool h, v;
2872
2873    *horiz = EINA_FALSE;
2874    *vert = EINA_FALSE;
2875
2876    do
2877      {
2878         parent_obj = elm_widget_parent_get(parent_obj);
2879         if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
2880
2881         if (_elm_scrollable_is(parent_obj))
2882           {
2883              eo_do(parent_obj, elm_interface_scrollable_bounce_allow_get(&h, &v));
2884              if (h) *horiz = EINA_TRUE;
2885              if (v) *vert = EINA_TRUE;
2886           }
2887      }
2888    while (parent_obj);
2889 }
2890
2891 EOLIAN static Eina_List*
2892 _elm_widget_scrollable_children_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
2893 {
2894    Eina_List *ret;
2895    ret = NULL;
2896
2897    Eina_List *l;
2898    Evas_Object *child;
2899
2900
2901    EINA_LIST_FOREACH(sd->subobjs, l, child)
2902      {
2903         if (elm_widget_is(child) && _elm_scrollable_is(child))
2904           ret = eina_list_append(ret, child);
2905      }
2906
2907    return ret;
2908 }
2909
2910 EOLIAN static void
2911 _elm_widget_scroll_hold_push(Eo *obj, Elm_Widget_Smart_Data *sd)
2912 {
2913    sd->scroll_hold++;
2914    if (sd->scroll_hold == 1)
2915      {
2916         if (_elm_scrollable_is(obj))
2917            eo_do(obj, elm_interface_scrollable_hold_set(EINA_TRUE));
2918         else
2919           {
2920              Eina_List *scr_children, *l;
2921              Evas_Object *child;
2922
2923              scr_children = elm_widget_scrollable_children_get(obj);
2924              EINA_LIST_FOREACH(scr_children, l, child)
2925                {
2926                   eo_do(child, elm_interface_scrollable_hold_set(EINA_TRUE));
2927                }
2928              eina_list_free(scr_children);
2929           }
2930      }
2931    if (sd->parent_obj) eo_do(sd->parent_obj, elm_obj_widget_scroll_hold_push());
2932    // FIXME: on delete/reparent hold pop
2933 }
2934
2935 EOLIAN static void
2936 _elm_widget_scroll_hold_pop(Eo *obj, Elm_Widget_Smart_Data *sd)
2937 {
2938    sd->scroll_hold--;
2939    if (!sd->scroll_hold)
2940      {
2941         if (_elm_scrollable_is(obj))
2942            eo_do(obj, elm_interface_scrollable_hold_set(EINA_FALSE));
2943         else
2944           {
2945              Eina_List *scr_children, *l;
2946              Evas_Object *child;
2947
2948              scr_children = elm_widget_scrollable_children_get(obj);
2949              EINA_LIST_FOREACH(scr_children, l, child)
2950                {
2951                   eo_do(child, elm_interface_scrollable_hold_set(EINA_FALSE));
2952                }
2953              eina_list_free(scr_children);
2954           }
2955      }
2956    if (sd->parent_obj) eo_do(sd->parent_obj, elm_obj_widget_scroll_hold_pop());
2957    if (sd->scroll_hold < 0) sd->scroll_hold = 0;
2958 }
2959
2960 EOLIAN static int
2961 _elm_widget_scroll_hold_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
2962 {
2963    return sd->scroll_hold;
2964 }
2965
2966 EOLIAN static void
2967 _elm_widget_scroll_freeze_push(Eo *obj, Elm_Widget_Smart_Data *sd)
2968 {
2969    sd->scroll_freeze++;
2970    if (sd->scroll_freeze == 1)
2971      {
2972         if (_elm_scrollable_is(obj))
2973            eo_do(obj, elm_interface_scrollable_freeze_set(EINA_TRUE));
2974         else
2975           {
2976              Eina_List *scr_children, *l;
2977              Evas_Object *child;
2978
2979              scr_children = elm_widget_scrollable_children_get(obj);
2980              EINA_LIST_FOREACH(scr_children, l, child)
2981                {
2982                   eo_do(child, elm_interface_scrollable_freeze_set(EINA_TRUE));
2983                }
2984              eina_list_free(scr_children);
2985           }
2986      }
2987    if (sd->parent_obj) eo_do(sd->parent_obj, elm_obj_widget_scroll_freeze_push());
2988    // FIXME: on delete/reparent freeze pop
2989 }
2990
2991 EOLIAN static void
2992 _elm_widget_scroll_freeze_pop(Eo *obj, Elm_Widget_Smart_Data *sd)
2993 {
2994    sd->scroll_freeze--;
2995    if (!sd->scroll_freeze)
2996      {
2997         if (_elm_scrollable_is(obj))
2998            eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
2999         else
3000           {
3001              Eina_List *scr_children, *l;
3002              Evas_Object *child;
3003
3004              scr_children = elm_widget_scrollable_children_get(obj);
3005              EINA_LIST_FOREACH(scr_children, l, child)
3006                {
3007                   eo_do(child, elm_interface_scrollable_freeze_set(EINA_FALSE));
3008                }
3009              eina_list_free(scr_children);
3010           }
3011      }
3012    if (sd->parent_obj) eo_do(sd->parent_obj, elm_obj_widget_scroll_freeze_pop());
3013    if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
3014 }
3015
3016 EOLIAN static int
3017 _elm_widget_scroll_freeze_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3018 {
3019    return sd->scroll_freeze;
3020 }
3021
3022 EOLIAN static void
3023 _elm_widget_scale_set(Eo *obj, Elm_Widget_Smart_Data *sd, double scale)
3024 {
3025    if (scale <= 0.0) scale = 0.0;
3026    if (sd->scale != scale)
3027      {
3028         sd->scale = scale;
3029         elm_widget_theme(obj);
3030      }
3031 }
3032
3033 EOLIAN static double
3034 _elm_widget_scale_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3035 {
3036    // FIXME: save walking up the tree by storing/caching parent scale
3037    if (sd->scale == 0.0)
3038      {
3039         if (sd->parent_obj && elm_widget_is(sd->parent_obj))
3040           {
3041              return elm_widget_scale_get(sd->parent_obj);
3042           }
3043         else
3044           {
3045              return 1.0;
3046           }
3047      }
3048    return sd->scale;
3049 }
3050
3051 EOLIAN static void
3052 _elm_widget_theme_set(Eo *obj, Elm_Widget_Smart_Data *sd, Elm_Theme *th)
3053 {
3054    Eina_Bool apply = EINA_FALSE;
3055    if (sd->theme != th)
3056      {
3057         if (elm_widget_theme_get(obj) != th) apply = EINA_TRUE;
3058         if (sd->theme) elm_theme_free(sd->theme);
3059         sd->theme = th;
3060         if (th) th->ref++;
3061         if (apply) elm_widget_theme(obj);
3062      }
3063 }
3064
3065 EOLIAN static void
3066 _elm_widget_part_text_set(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *part, const char *label)
3067 {
3068    if (evas_object_smart_type_check(obj, "elm_layout"))
3069      elm_layout_text_set(obj, part, label);
3070 }
3071
3072 EOLIAN static const char*
3073 _elm_widget_part_text_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *part)
3074 {
3075    if (evas_object_smart_type_check(obj, "elm_layout"))
3076      return elm_layout_text_get(obj, part);
3077
3078    return NULL;
3079 }
3080
3081 static Elm_Translate_String_Data *
3082 _translate_string_data_get(Eina_Inlist *translate_strings, const char *part)
3083 {
3084    Elm_Translate_String_Data *ts;
3085    Eina_Stringshare *str;
3086
3087    if (!translate_strings) return NULL;
3088
3089    str = eina_stringshare_add(part);
3090    EINA_INLIST_FOREACH(translate_strings, ts)
3091      {
3092         if (ts->id == str) break;
3093      }
3094
3095    eina_stringshare_del(str);
3096
3097    return ts;
3098 }
3099
3100 static Elm_Translate_String_Data *
3101 _part_text_translatable_set(Eina_Inlist **translate_strings, const char *part, Eina_Bool translatable, Eina_Bool preset)
3102 {
3103    Eina_Inlist *t;
3104    Elm_Translate_String_Data *ts;
3105    t = *translate_strings;
3106    ts = _translate_string_data_get(t, part);
3107
3108    if (translatable)
3109      {
3110         if (!ts)
3111           {
3112              ts = ELM_NEW(Elm_Translate_String_Data);
3113              if (!ts) return NULL;
3114
3115              ts->id = eina_stringshare_add(part);
3116              t = eina_inlist_append(t, (Eina_Inlist*) ts);
3117           }
3118         if (preset) ts->preset = EINA_TRUE;
3119      }
3120    //Delete this exist one if this part has been not preset.
3121    //see elm_widget_part_text_translatable_set()
3122    else if ((preset) || (!ts->preset))
3123      {
3124         if (ts)
3125           {
3126              t = eina_inlist_remove(t, EINA_INLIST_GET(ts));
3127              eina_stringshare_del(ts->id);
3128              eina_stringshare_del(ts->domain);
3129              eina_stringshare_del(ts->string);
3130              ELM_SAFE_FREE(ts, free);
3131           }
3132      }
3133
3134    *translate_strings = t;
3135
3136    return ts;
3137 }
3138
3139 EOLIAN static void
3140 _elm_widget_domain_translatable_part_text_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *part, const char *domain, const char *label)
3141 {
3142
3143    Elm_Translate_String_Data *ts;
3144
3145    if (!label)
3146      {
3147         _part_text_translatable_set(&sd->translate_strings, part, EINA_FALSE,
3148                                     EINA_FALSE);
3149      }
3150    else
3151      {
3152         ts = _part_text_translatable_set(&sd->translate_strings, part,
3153                                          EINA_TRUE, EINA_FALSE);
3154         if (!ts) return;
3155         if (!ts->string) ts->string = eina_stringshare_add(label);
3156         else eina_stringshare_replace(&ts->string, label);
3157         if (!ts->domain) ts->domain = eina_stringshare_add(domain);
3158         else eina_stringshare_replace(&ts->domain, domain);
3159 #ifdef HAVE_GETTEXT
3160         if (label[0]) label = dgettext(domain, label);
3161 #endif
3162      }
3163
3164    sd->on_translate = EINA_TRUE;
3165    eo_do(obj, elm_obj_widget_part_text_set(part, label));
3166    sd->on_translate = EINA_FALSE;
3167 }
3168
3169 EOLIAN static const char*
3170 _elm_widget_translatable_part_text_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, const char *part)
3171 {
3172    Elm_Translate_String_Data *ts;
3173
3174    ts = _translate_string_data_get(sd->translate_strings, part);
3175    if (ts) return ts->string;
3176    else return NULL;
3177 }
3178
3179 EOLIAN static void
3180 _elm_widget_domain_part_text_translatable_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *part, const char *domain, Eina_Bool translatable)
3181 {
3182    Elm_Translate_String_Data *ts;
3183    const char *text;
3184
3185    ts = _part_text_translatable_set(&sd->translate_strings, part,
3186                                     translatable, EINA_TRUE);
3187    if (!ts) return;
3188    if (!ts->domain) ts->domain = eina_stringshare_add(domain);
3189    else eina_stringshare_replace(&ts->domain, domain);
3190
3191    eo_do(obj, elm_obj_widget_part_text_get(part, &text));
3192    if (!text || !text[0]) return;
3193
3194    if (!ts->string) ts->string = eina_stringshare_add(text);
3195
3196 //Try to translate text since we don't know the text is already translated.
3197 #ifdef HAVE_GETTEXT
3198    text = dgettext(domain, text);
3199 #endif
3200    sd->on_translate = EINA_TRUE;
3201    eo_do(obj, elm_obj_widget_part_text_set(part, text));
3202    sd->on_translate = EINA_FALSE;
3203 }
3204
3205 EAPI void
3206 elm_widget_translate(Evas_Object *obj)
3207 {
3208    ELM_WIDGET_CHECK(obj);
3209    eo_do(obj, elm_obj_widget_translate(NULL));
3210 }
3211
3212 static const char*
3213 _part_text_translate(Eina_Inlist *translate_strings,
3214                      const char *part,
3215                      const char *text)
3216 {
3217    Elm_Translate_String_Data *ts;
3218    ts = _translate_string_data_get(translate_strings, part);
3219    if (!ts) return text;
3220
3221    if (!ts->string) ts->string = eina_stringshare_add(text);
3222    else eina_stringshare_replace(&ts->string, text);
3223 #ifdef HAVE_GETTEXT
3224    if (text && text[0])
3225      text = dgettext(ts->domain, text);
3226 #endif
3227    return text;
3228 }
3229
3230 EOLIAN static const char*
3231 _elm_widget_part_text_translate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, const char *part, const char *text)
3232 {
3233
3234
3235    if (!sd->translate_strings || sd->on_translate) return text;
3236    return _part_text_translate(sd->translate_strings, part, text);
3237 }
3238
3239 EOLIAN static Eina_Bool
3240 _elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3241 {
3242    const Eina_List *l;
3243    Evas_Object *child;
3244    API_ENTRY return EINA_FALSE;
3245
3246    EINA_LIST_FOREACH(sd->subobjs, l, child)
3247      {
3248         if (elm_widget_is(child))
3249           elm_widget_translate(child);
3250      }
3251
3252    if (sd->hover_obj) elm_widget_translate(sd->hover_obj);
3253
3254 #ifdef HAVE_GETTEXT
3255    Elm_Translate_String_Data *ts;
3256    EINA_INLIST_FOREACH(sd->translate_strings, ts)
3257      {
3258         if (!ts->string) continue;
3259         const char *s = dgettext(ts->domain, ts->string);
3260         sd->on_translate = EINA_TRUE;
3261         eo_do(obj, elm_obj_widget_part_text_set(ts->id, s));
3262         sd->on_translate = EINA_FALSE;
3263      }
3264 #endif
3265    evas_object_smart_callback_call(obj, SIG_WIDGET_LANG_CHANGED, NULL);
3266    return EINA_TRUE;
3267 }
3268
3269 EAPI void
3270 elm_widget_content_part_set(Evas_Object *obj,
3271                             const char *part,
3272                             Evas_Object *content)
3273 {
3274    ELM_WIDGET_CHECK(obj);
3275    eo_do(obj, elm_obj_container_content_set(part, content, NULL));
3276 }
3277
3278 EAPI Evas_Object *
3279 elm_widget_content_part_get(const Evas_Object *obj,
3280                             const char *part)
3281 {
3282    ELM_WIDGET_CHECK(obj) NULL;
3283    Evas_Object *ret = NULL;
3284    eo_do((Eo *) obj, elm_obj_container_content_get(part, &ret));
3285    return ret;
3286 }
3287
3288 EAPI Evas_Object *
3289 elm_widget_content_part_unset(Evas_Object *obj,
3290                               const char *part)
3291 {
3292    ELM_WIDGET_CHECK(obj) NULL;
3293    Evas_Object *ret = NULL;
3294    eo_do(obj, elm_obj_container_content_unset(part, &ret));
3295    return ret;
3296 }
3297
3298 EOLIAN static void
3299 _elm_widget_access_info_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, const char *txt)
3300 {
3301    eina_stringshare_del(sd->access_info);
3302    if (!txt) sd->access_info = NULL;
3303    else sd->access_info = eina_stringshare_add(txt);
3304 }
3305
3306 EOLIAN static const char*
3307 _elm_widget_access_info_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3308 {
3309    return sd->access_info;
3310 }
3311
3312 EOLIAN static Elm_Theme*
3313 _elm_widget_theme_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3314 {
3315    if (!sd->theme)
3316      {
3317         if (sd->parent_obj && elm_widget_is(sd->parent_obj))
3318            return elm_widget_theme_get(sd->parent_obj);
3319         else return NULL;
3320      }
3321    return sd->theme;
3322 }
3323
3324 EOLIAN static Eina_Bool
3325 _elm_widget_style_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *style)
3326 {
3327    if (eina_stringshare_replace(&sd->style, style))
3328       return elm_widget_theme(obj);
3329
3330    return EINA_TRUE;
3331 }
3332
3333 EOLIAN static const char*
3334 _elm_widget_style_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3335 {
3336    const char *ret;
3337    ret = "default";
3338    if (sd->style) ret = sd->style;
3339
3340    return ret;
3341 }
3342
3343 EOLIAN static void
3344 _elm_widget_tooltip_add(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Tooltip *tt)
3345 {
3346    sd->tooltips = eina_list_append(sd->tooltips, tt);
3347 }
3348
3349 EOLIAN static void
3350 _elm_widget_tooltip_del(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Tooltip *tt)
3351 {
3352    sd->tooltips = eina_list_remove(sd->tooltips, tt);
3353 }
3354
3355 EOLIAN static void
3356 _elm_widget_cursor_add(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Cursor *cur)
3357 {
3358    sd->cursors = eina_list_append(sd->cursors, cur);
3359 }
3360
3361 EOLIAN static void
3362 _elm_widget_cursor_del(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Elm_Cursor *cur)
3363 {
3364    sd->cursors = eina_list_remove(sd->cursors, cur);
3365 }
3366
3367 EOLIAN static void
3368 _elm_widget_drag_lock_x_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool lock)
3369 {
3370    if (sd->drag_x_locked == lock) return;
3371    sd->drag_x_locked = lock;
3372    if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
3373    else _propagate_x_drag_lock(obj, -1);
3374 }
3375
3376 EOLIAN static void
3377 _elm_widget_drag_lock_y_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool lock)
3378 {
3379    if (sd->drag_y_locked == lock) return;
3380    sd->drag_y_locked = lock;
3381    if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
3382    else _propagate_y_drag_lock(obj, -1);
3383 }
3384
3385 EOLIAN static Eina_Bool
3386 _elm_widget_drag_lock_x_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3387 {
3388    return sd->drag_x_locked;
3389 }
3390
3391 EOLIAN static Eina_Bool
3392 _elm_widget_drag_lock_y_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3393 {
3394    return sd->drag_y_locked;
3395 }
3396
3397 EOLIAN static int
3398 _elm_widget_drag_child_locked_x_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3399 {
3400    return sd->child_drag_x_locked;
3401 }
3402
3403 EOLIAN static int
3404 _elm_widget_drag_child_locked_y_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3405 {
3406    return sd->child_drag_y_locked;
3407 }
3408
3409 EOLIAN static void
3410 _elm_widget_item_loop_enabled_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd EINA_UNUSED, Eina_Bool enable EINA_UNUSED)
3411 {
3412         return;
3413 }
3414
3415 EOLIAN static Eina_Bool
3416 _elm_widget_item_loop_enabled_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd EINA_UNUSED)
3417 {
3418         return EINA_FALSE;
3419 }
3420
3421 EOLIAN static Eina_Bool
3422 _elm_widget_theme_object_set(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
3423 {
3424    if (!_elm_theme_object_set(obj, edj, wname, welement, wstyle))
3425      {
3426         return EINA_FALSE;
3427      }
3428
3429    if (sd->orient_mode != -1)
3430      {
3431         char buf[128];
3432         snprintf(buf, sizeof(buf), "elm,state,orient,%d", sd->orient_mode);
3433         eo_do(obj, elm_obj_widget_signal_emit(buf, "elm"));
3434      }
3435
3436    return EINA_TRUE;
3437 }
3438
3439 EOLIAN static void
3440 _elm_widget_eo_base_dbg_info_get(Eo *eo_obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Eo_Dbg_Info *root)
3441 {
3442    eo_do_super(eo_obj, MY_CLASS, eo_dbg_info_get(root));
3443    Eo_Dbg_Info *group = EO_DBG_INFO_LIST_APPEND(root, MY_CLASS_NAME);
3444
3445    EO_DBG_INFO_APPEND(group, "Wid-Type", EINA_VALUE_TYPE_STRING, elm_widget_type_get(eo_obj));
3446    EO_DBG_INFO_APPEND(group, "Style", EINA_VALUE_TYPE_STRING, elm_widget_style_get(eo_obj));
3447    EO_DBG_INFO_APPEND(group, "Layer", EINA_VALUE_TYPE_INT,
3448          (int) evas_object_layer_get(eo_obj));
3449    EO_DBG_INFO_APPEND(group, "Scale", EINA_VALUE_TYPE_DOUBLE,
3450          evas_object_scale_get(eo_obj));
3451    EO_DBG_INFO_APPEND(group, "Has focus", EINA_VALUE_TYPE_CHAR,
3452          elm_object_focus_get(eo_obj));
3453    EO_DBG_INFO_APPEND(group, "Disabled", EINA_VALUE_TYPE_CHAR,
3454          elm_widget_disabled_get(eo_obj));
3455    EO_DBG_INFO_APPEND(group, "Mirrored", EINA_VALUE_TYPE_CHAR,
3456          elm_widget_mirrored_get(eo_obj));
3457    EO_DBG_INFO_APPEND(group, "Automatic mirroring", EINA_VALUE_TYPE_CHAR,
3458          elm_widget_mirrored_automatic_get(eo_obj));
3459 }
3460
3461 EAPI Eina_Bool
3462 elm_widget_is_check(const Evas_Object *obj)
3463 {
3464    static int abort_on_warn = -1;
3465    if (elm_widget_is(obj))
3466      return EINA_TRUE;
3467
3468    ERR("Passing Object: %p.", obj);
3469    if (abort_on_warn == -1)
3470      {
3471         if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
3472         else abort_on_warn = 0;
3473      }
3474    if (abort_on_warn == 1) abort();
3475    return EINA_FALSE;
3476 }
3477
3478 EAPI const char *
3479 elm_widget_type_get(const Evas_Object *obj)
3480 {
3481    API_ENTRY return NULL;
3482
3483    return eo_class_name_get(eo_class_get(obj));
3484 }
3485
3486 EAPI Eina_Bool
3487 elm_widget_type_check(const Evas_Object *obj,
3488                       const char *type,
3489                       const char *func)
3490 {
3491    const char *provided, *expected = "(unknown)";
3492    static int abort_on_warn = -1;
3493
3494    provided = elm_widget_type_get(obj);
3495    /* TODO: eventually migrate to check_ptr version */
3496    if (evas_object_smart_type_check(obj, type)) return EINA_TRUE;
3497    if (type) expected = type;
3498    if ((!provided) || (!provided[0]))
3499      {
3500         provided = evas_object_type_get(obj);
3501         if ((!provided) || (!provided[0]))
3502           provided = "(unknown)";
3503      }
3504    ERR("Passing Object: %p in function: %s, of type: '%s' when expecting"
3505        " type: '%s'", obj, func, provided, expected);
3506    if (abort_on_warn == -1)
3507      {
3508         if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
3509         else abort_on_warn = 0;
3510      }
3511    if (abort_on_warn == 1) abort();
3512    return EINA_FALSE;
3513 }
3514
3515 static Evas_Object *
3516 _widget_name_find(const Evas_Object *obj,
3517                   const char *name,
3518                   int recurse)
3519 {
3520    Eina_List *l;
3521    Evas_Object *child;
3522    const char *s;
3523    INTERNAL_ENTRY NULL;
3524
3525    if (!_elm_widget_is(obj)) return NULL;
3526    EINA_LIST_FOREACH(sd->subobjs, l, child)
3527      {
3528         s = evas_object_name_get(child);
3529         if ((s) && (!strcmp(s, name))) return child;
3530         if ((recurse != 0) &&
3531             ((child = _widget_name_find(child, name, recurse - 1))))
3532           return child;
3533      }
3534    if (sd->hover_obj)
3535      {
3536         s = evas_object_name_get(sd->hover_obj);
3537         if ((s) && (!strcmp(s, name))) return sd->hover_obj;
3538         if ((recurse != 0) &&
3539             ((child = _widget_name_find(sd->hover_obj, name, recurse - 1))))
3540           return child;
3541      }
3542    return NULL;
3543 }
3544
3545 EOLIAN static Evas_Object*
3546 _elm_widget_name_find(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, const char *name, int recurse)
3547 {
3548    if (!name) return NULL;
3549    return _widget_name_find(obj, name, recurse);
3550 }
3551
3552 /**
3553  * @internal
3554  *
3555  * Split string in words
3556  *
3557  * @param str Source string
3558  * @return List of const words
3559  *
3560  * @see elm_widget_stringlist_free()
3561  * @ingroup Widget
3562  */
3563 EAPI Eina_List *
3564 elm_widget_stringlist_get(const char *str)
3565 {
3566    Eina_List *list = NULL;
3567    const char *s, *b;
3568    if (!str) return NULL;
3569    for (b = s = str; 1; s++)
3570      {
3571         if ((*s == ' ') || (!*s))
3572           {
3573              char *t = malloc(s - b + 1);
3574              if (t)
3575                {
3576                   strncpy(t, b, s - b);
3577                   t[s - b] = 0;
3578                   list = eina_list_append(list, eina_stringshare_add(t));
3579                   free(t);
3580                }
3581              b = s + 1;
3582           }
3583         if (!*s) break;
3584      }
3585    return list;
3586 }
3587
3588 EAPI void
3589 elm_widget_stringlist_free(Eina_List *list)
3590 {
3591    const char *s;
3592    EINA_LIST_FREE(list, s)
3593      eina_stringshare_del(s);
3594 }
3595
3596 EOLIAN static void
3597 _elm_widget_focus_hide_handle(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3598 {
3599    if (!_elm_widget_is(obj))
3600      return;
3601    _if_focused_revert(obj, EINA_TRUE);
3602 }
3603
3604 EAPI void
3605 elm_widget_focus_mouse_up_handle(Evas_Object *obj)
3606 {
3607    Evas_Object *o = obj;
3608    do
3609      {
3610         if (_elm_widget_is(o)) break;
3611         o = evas_object_smart_parent_get(o);
3612      }
3613    while (o);
3614
3615    eo_do(o, elm_obj_widget_focus_mouse_up_handle());
3616 }
3617
3618 EOLIAN static void
3619 _elm_widget_focus_mouse_up_handle(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3620 {
3621    if (!obj) return;
3622    if (!_is_focusable(obj)) return;
3623    elm_widget_focus_steal(obj);
3624 }
3625
3626 EOLIAN static void
3627 _elm_widget_focus_tree_unfocusable_handle(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3628 {
3629    if (!elm_widget_parent_get(obj))
3630      elm_widget_focused_object_clear(obj);
3631    else
3632      _if_focused_revert(obj, EINA_TRUE);
3633 }
3634
3635 EOLIAN static void
3636 _elm_widget_focus_disabled_handle(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3637 {
3638    elm_widget_focus_tree_unfocusable_handle(obj);
3639 }
3640
3641 EOLIAN static unsigned int
3642 _elm_widget_focus_order_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3643 {
3644    return sd->focus_order;
3645 }
3646
3647 EOLIAN static Evas_Object*
3648 _elm_widget_newest_focus_order_get(Eo *obj, Elm_Widget_Smart_Data *sd, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
3649 {
3650    const Eina_List *l;
3651    Evas_Object *child, *cur, *best;
3652
3653    if (!evas_object_visible_get(obj)
3654        || (elm_widget_disabled_get(obj))
3655        || (elm_widget_tree_unfocusable_get(obj)))
3656      return NULL;
3657
3658    best = NULL;
3659    if (*newest_focus_order < sd->focus_order)
3660      {
3661         if (!can_focus_only || elm_widget_can_focus_get(obj))
3662           {
3663              *newest_focus_order = sd->focus_order;
3664              best = obj;
3665           }
3666      }
3667    EINA_LIST_FOREACH(sd->subobjs, l, child)
3668      {
3669         if (!_elm_widget_is(child)) continue;
3670
3671         cur = elm_widget_newest_focus_order_get
3672            (child, newest_focus_order, can_focus_only);
3673         if (!cur) continue;
3674         best = cur;
3675      }
3676    return best;
3677 }
3678
3679 /*
3680  * @internal
3681  *
3682  * Get the focus highlight geometry of an widget.
3683  *
3684  * @param obj Widget object for the focus highlight
3685  * @param x Focus highlight x coordinate
3686  * @param y Focus highlight y coordinate
3687  * @param w Focus highlight object width
3688  * @param h Focus highlight object height
3689  * @param is_next @c EINA_TRUE if this request is for the new focused object,
3690  * @c EINA_FALSE if this request is for the previously focused object. This
3691  * information becomes important when the focus highlight is changed inside one
3692  * widget.
3693  *
3694  * @ingroup Widget
3695  */
3696 /*
3697  * @internal
3698  *
3699  * Get the 'focus_part' geometry if there is any
3700  *
3701  * This queries if there is a 'focus_part' request from the edc style. If edc
3702  * style offers 'focus_part' edje data item, this function requests for the
3703  * geometry of a specific part which is described in 'focus_part' edje data.
3704  *
3705  * @param obj Widget object for the focus highlight
3706  * @param x Focus highlight x coordinate
3707  * @param y Focus highlight y coordinate
3708  * @param w Focus highlight object width
3709  * @param h Focus highlight object height
3710  *
3711  * x, y, w, h already contain the object's geometry. If there is a 'focus_part'
3712  * support, these values will be updated accordingly or the values will be
3713  * remained as they were.
3714  *
3715  * @ingroup Widget
3716  */
3717 EAPI void
3718 elm_widget_focus_highlight_focus_part_geometry_get(const Evas_Object *obj,
3719                                                    Evas_Coord *x,
3720                                                    Evas_Coord *y,
3721                                                    Evas_Coord *w,
3722                                                    Evas_Coord *h)
3723 {
3724    Evas_Coord tx = 0, ty = 0, tw = 0, th = 0;
3725    const char *target_hl_part = NULL;
3726    const Evas_Object *edje_obj = NULL;
3727
3728    if (obj && eo_isa(obj, EDJE_OBJ_CLASS))
3729      {
3730         edje_obj = obj;
3731         if (!(target_hl_part = edje_object_data_get(edje_obj, "focus_part")))
3732           return;
3733      }
3734    else if (obj && eo_isa(obj, ELM_OBJ_LAYOUT_CLASS))
3735      {
3736         edje_obj = elm_layout_edje_get(obj);
3737         if (!(target_hl_part = elm_layout_data_get(obj, "focus_part")))
3738           return;
3739      }
3740    else
3741      return;
3742
3743   edje_object_part_geometry_get(edje_obj, target_hl_part,
3744                                 &tx, &ty, &tw, &th);
3745   *x += tx;
3746   *y += ty;
3747   if (tw != *w) *w = tw;
3748   if (th != *h) *h = th;
3749 }
3750
3751 EOLIAN static void
3752 _elm_widget_focus_highlight_geometry_get(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h, Eina_Bool is_next)
3753 {
3754    (void)is_next;
3755
3756
3757    evas_object_geometry_get(obj, x, y, w, h);
3758    elm_widget_focus_highlight_focus_part_geometry_get(sd->resize_obj, x, y, w, h);
3759 }
3760
3761 EOLIAN static Elm_Object_Item*
3762 _elm_widget_focused_item_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
3763 {
3764    return NULL;
3765 }
3766
3767 EAPI void
3768 elm_widget_activate(Evas_Object *obj, Elm_Activate act)
3769 {
3770    Evas_Object *parent;
3771    Eina_Bool ret;
3772
3773    ELM_WIDGET_CHECK(obj);
3774
3775    ret = EINA_FALSE;
3776
3777    eo_do(obj, elm_obj_widget_activate(act, &ret));
3778
3779    if (ret) return;
3780
3781    parent = elm_widget_parent_get(obj);
3782    if (parent)
3783      elm_widget_activate(parent, act);
3784
3785    return;
3786 }
3787
3788 /**
3789  * @internal
3790  *
3791  * Sets the widget and child widget's Evas_Display_Mode.
3792  *
3793  * @param obj The widget.
3794  * @param dispmode Evas_Display_Mode to set widget's mode.
3795  *
3796  * Widgets are resized by several reasons.
3797  * Evas_Display_Mode can help for widgets to get one more reason of resize.
3798  * For example, elm conform widget resizes it's contents when keypad state changed.
3799  * After keypad showing, conform widget can change child's Evas_Display_Mode.
3800  * @ingroup Widget
3801  */
3802 EOLIAN static void
3803 _elm_widget_display_mode_set(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Display_Mode dispmode)
3804 {
3805    Evas_Display_Mode prev_dispmode;
3806    Evas_Object *child;
3807    Eina_List *l;
3808
3809    prev_dispmode = evas_object_size_hint_display_mode_get(obj);
3810
3811    if ((prev_dispmode == dispmode) ||
3812        (prev_dispmode == EVAS_DISPLAY_MODE_DONT_CHANGE)) return;
3813
3814    evas_object_size_hint_display_mode_set(obj, dispmode);
3815
3816    EINA_LIST_FOREACH (sd->subobjs, l, child)
3817      {
3818         if (elm_widget_is(child))
3819           elm_widget_display_mode_set(child, dispmode);
3820      }
3821 }
3822
3823 EOLIAN static void
3824 _elm_widget_orientation_mode_disabled_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Bool disabled)
3825 {
3826    int orient_mode = -1;
3827
3828    if (!disabled)
3829      {
3830         //Get current orient mode from it's parent otherwise, 0.
3831         sd->orient_mode = 0;
3832         ELM_WIDGET_DATA_GET(sd->parent_obj, sd_parent);
3833         if (!sd_parent) orient_mode = 0;
3834         else orient_mode = sd_parent->orient_mode;
3835      }
3836    eo_do(obj, elm_obj_widget_orientation_set(orient_mode));
3837 }
3838
3839 EOLIAN static Eina_Bool
3840 _elm_widget_orientation_mode_disabled_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3841 {
3842    if (sd->orient_mode == -1) return EINA_TRUE;
3843    else return EINA_FALSE;
3844 }
3845
3846 EOLIAN static void
3847 _elm_widget_orientation_set(Eo *obj, Elm_Widget_Smart_Data *sd, int orient_mode)
3848 {
3849    Evas_Object *child;
3850    Eina_List *l;
3851
3852    sd->orient_mode = orient_mode;
3853
3854    EINA_LIST_FOREACH (sd->subobjs, l, child)
3855      {
3856         if (elm_widget_is(child))
3857           elm_widget_orientation_set(child, orient_mode);
3858      }
3859
3860    if (orient_mode != -1)
3861      {
3862         char buf[128];
3863         snprintf(buf, sizeof(buf), "elm,state,orient,%d", orient_mode);
3864         eo_do(obj, elm_obj_widget_signal_emit(buf, "elm"));
3865      }
3866 }
3867
3868 static void
3869 _track_obj_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
3870
3871 static void
3872 _track_obj_update(Evas_Object *track, Evas_Object *obj)
3873 {
3874    //Geometry
3875    Evas_Coord x, y, w, h;
3876    evas_object_geometry_get(obj, &x, &y, &w, &h);
3877    evas_object_move(track, x, y);
3878    evas_object_resize(track, w, h);
3879
3880    //Visibility
3881    if (evas_object_visible_get(obj)) evas_object_show(track);
3882    else evas_object_hide(track);
3883 }
3884
3885 static void
3886 _track_obj_view_update(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
3887                        void *event_info EINA_UNUSED)
3888 {
3889    Evas_Object *track = data;
3890    _track_obj_update(track, obj);
3891 }
3892
3893 static void
3894 _track_obj_view_del(void *data, Evas *e EINA_UNUSED,
3895                     Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
3896 {
3897    Elm_Widget_Item *item = data;
3898
3899    while (evas_object_ref_get(item->track_obj) > 0)
3900      evas_object_unref(item->track_obj);
3901
3902    evas_object_event_callback_del(item->track_obj, EVAS_CALLBACK_DEL,
3903                                   _track_obj_del);
3904    evas_object_del(item->track_obj);
3905    item->track_obj = NULL;
3906 }
3907
3908 static void
3909 _track_obj_del(void *data, Evas *e EINA_UNUSED,
3910                     Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
3911 {
3912    Elm_Widget_Item *item = data;
3913    item->track_obj = NULL;
3914
3915    if (!item->view) return;
3916
3917    evas_object_event_callback_del(item->view, EVAS_CALLBACK_RESIZE,
3918                                   _track_obj_view_update);
3919    evas_object_event_callback_del(item->view, EVAS_CALLBACK_MOVE,
3920                                   _track_obj_view_update);
3921    evas_object_event_callback_del(item->view, EVAS_CALLBACK_SHOW,
3922                                   _track_obj_view_update);
3923    evas_object_event_callback_del(item->view, EVAS_CALLBACK_HIDE,
3924                                   _track_obj_view_update);
3925    evas_object_event_callback_del(item->view, EVAS_CALLBACK_DEL,
3926                                   _track_obj_view_del);
3927 }
3928
3929 static void
3930 _elm_widget_item_signal_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *emission,
3931                            const char *source)
3932 {
3933    Elm_Widget_Item_Signal_Data *wisd = data;
3934    wisd->func(wisd->data, wisd->item, emission, source);
3935 }
3936
3937 static void *
3938 _elm_widget_item_signal_callback_list_get(Elm_Widget_Item *item, Eina_List *position)
3939 {
3940    Elm_Widget_Item_Signal_Data *wisd = eina_list_data_get(position);
3941    void *data;
3942
3943    item->signals = eina_list_remove_list(item->signals, position);
3944    data = wisd->data;
3945
3946    if (_elm_widget_is(item->view))
3947      elm_object_signal_callback_del(item->view,
3948                                     wisd->emission, wisd->source,
3949                                     _elm_widget_item_signal_cb);
3950    else if (!strcmp(eo_class_name_get(eo_class_get(item->view)),
3951                     "edje"))
3952      edje_object_signal_callback_del_full(item->view,
3953                                           wisd->emission, wisd->source,
3954                                           _elm_widget_item_signal_cb, wisd);
3955
3956    eina_stringshare_del(wisd->emission);
3957    eina_stringshare_del(wisd->source);
3958    free(wisd);
3959
3960    return data;
3961 }
3962
3963 /**
3964  * @internal
3965  *
3966  * Allocate a new Elm_Widget_Item-derived structure.
3967  *
3968  * The goal of this structure is to provide common ground for actions
3969  * that a widget item have, such as the owner widget, callback to
3970  * notify deletion, data pointer and maybe more.
3971  *
3972  * @param widget the owner widget that holds this item, must be an elm_widget!
3973  * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
3974  *        be used to allocate memory.
3975  *
3976  * @return allocated memory that is already zeroed out, or NULL on errors.
3977  *
3978  * @see elm_widget_item_new() convenience macro.
3979  * @see elm_widget_item_del() to release memory.
3980  * @ingroup Widget
3981  */
3982 EAPI Elm_Widget_Item *
3983 _elm_widget_item_new(Evas_Object *widget,
3984                      size_t alloc_size)
3985 {
3986    if (!_elm_widget_is(widget))
3987      return NULL;
3988
3989    Elm_Widget_Item *item;
3990
3991    EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
3992    EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
3993
3994    item = calloc(1, alloc_size);
3995    EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
3996
3997    EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
3998    item->widget = widget;
3999    return item;
4000 }
4001
4002 EAPI void
4003 _elm_widget_item_free(Elm_Widget_Item *item)
4004 {
4005    Elm_Translate_String_Data *ts;
4006
4007    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4008
4009    if (item->del_func)
4010      item->del_func((void *)item->data, item->widget, item);
4011
4012    evas_object_del(item->view);
4013
4014    eina_stringshare_del(item->access_info);
4015
4016    while (item->signals)
4017      _elm_widget_item_signal_callback_list_get(item, item->signals);
4018
4019    while (item->translate_strings)
4020      {
4021         ts = EINA_INLIST_CONTAINER_GET(item->translate_strings,
4022                                        Elm_Translate_String_Data);
4023         eina_stringshare_del(ts->id);
4024         eina_stringshare_del(ts->domain);
4025         eina_stringshare_del(ts->string);
4026         item->translate_strings = eina_inlist_remove(item->translate_strings,
4027                                                      item->translate_strings);
4028         free(ts);
4029      }
4030    eina_hash_free(item->labels);
4031
4032    EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
4033    free(item);
4034 }
4035
4036 /**
4037  * @internal
4038  *
4039  * Releases widget item memory, calling back del_cb() if it exists.
4040  *
4041  * If there is a Elm_Widget_Item::del_cb, then it will be called prior
4042  * to memory release. Note that elm_widget_item_pre_notify_del() calls
4043  * this function and then unset it, thus being useful for 2 step
4044  * cleanup whenever the del_cb may use any of the data that must be
4045  * deleted from item.
4046  *
4047  * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
4048  * is presented!
4049  *
4050  * @param item a valid #Elm_Widget_Item to be deleted.
4051  * @see elm_widget_item_del() convenience macro.
4052  * @ingroup Widget
4053  */
4054 EAPI void
4055 _elm_widget_item_del(Elm_Widget_Item *item)
4056 {
4057    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4058    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4059    item->on_deletion = EINA_TRUE;
4060
4061    //Widget item delete callback
4062    if (item->del_pre_func)
4063      {
4064         if (item->del_pre_func((Elm_Object_Item *)item))
4065           _elm_widget_item_free(item);
4066      }
4067    else
4068      _elm_widget_item_free(item);
4069 }
4070
4071 /**
4072  * @internal
4073  *
4074  * Set the function to notify to widgets when item is being deleted by user.
4075  *
4076  * @param item a valid #Elm_Widget_Item to be notified
4077  * @see elm_widget_item_del_pre_hook_set() convenience macro.
4078  * @ingroup Widget
4079  */
4080 EAPI void
4081 _elm_widget_item_del_pre_hook_set(Elm_Widget_Item *item,
4082                                   Elm_Widget_Del_Pre_Cb func)
4083 {
4084    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4085    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4086    item->del_pre_func = func;
4087 }
4088 /**
4089  * @internal
4090  *
4091  * Set the function to set the style of item
4092  *
4093  * @param item a valid #Elm_Widget_Item to be notified
4094  * @see elm_widget_item_style_set_hook_set() convenience macro.
4095  * @ingroup Widget
4096  */
4097 EAPI void
4098 _elm_widget_item_style_set_hook_set(Elm_Widget_Item *item,
4099                                   Elm_Widget_Style_Set_Cb func)
4100 {
4101    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4102    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4103    item->style_set_func = func;
4104 }
4105
4106 /**
4107  * @internal
4108  *
4109  * Set the function to get the style of item
4110  *
4111  * @param item a valid #Elm_Widget_Item to be notified
4112  * @see elm_widget_item_style_get_hook_set() convenience macro.
4113  * @ingroup Widget
4114  */
4115 EAPI void
4116 _elm_widget_item_style_get_hook_set(Elm_Widget_Item *item,
4117                                   Elm_Widget_Style_Get_Cb func)
4118 {
4119    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4120    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4121    item->style_get_func = func;
4122 }
4123
4124 /**
4125  * @internal
4126  *
4127  * Set the function to set the focus on widget item.
4128  *
4129  * @param item a valid #Elm_Widget_Item to be notified
4130  * @see elm_widget_item_focus_set_hook_set() convenience macro.
4131  * @ingroup Widget
4132  */
4133 EAPI void
4134 _elm_widget_item_focus_set_hook_set(Elm_Widget_Item *item, Elm_Widget_Focus_Set_Cb func)
4135 {
4136    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4137    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4138    item->focus_set_func = func;
4139 }
4140
4141 /**
4142  * @internal
4143  *
4144  * Set the function to set the focus on widget item.
4145  *
4146  * @param item a valid #Elm_Widget_Item to be notified
4147  * @see elm_widget_item_focus_get_hook_set() convenience macro.
4148  * @ingroup Widget
4149  */
4150 EAPI void
4151 _elm_widget_item_focus_get_hook_set(Elm_Widget_Item *item,
4152                                   Elm_Widget_Focus_Get_Cb func)
4153 {
4154    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4155    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4156    item->focus_get_func = func;
4157 }
4158
4159 /**
4160  * @internal
4161  *
4162  * Notify object will be deleted without actually deleting it.
4163  *
4164  * This function will callback Elm_Widget_Item::del_cb if it is set
4165  * and then unset it so it is not called twice (ie: from
4166  * elm_widget_item_del()).
4167  *
4168  * @param item a valid #Elm_Widget_Item to be notified
4169  * @see elm_widget_item_pre_notify_del() convenience macro.
4170  * @ingroup Widget
4171  */
4172 EAPI void
4173 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
4174 {
4175    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4176    if (!item->del_func) return;
4177    item->del_func((void *)item->data, item->widget, item);
4178    item->del_func = NULL;
4179 }
4180
4181 /**
4182  * @internal
4183  *
4184  * Set the function to notify when item is being deleted.
4185  *
4186  * This function will complain if there was a callback set already,
4187  * however it will set the new one.
4188  *
4189  * The callback will be called from elm_widget_item_pre_notify_del()
4190  * or elm_widget_item_del() will be called with:
4191  *   - data: the Elm_Widget_Item::data value.
4192  *   - obj: the Elm_Widget_Item::widget evas object.
4193  *   - event_info: the item being deleted.
4194  *
4195  * @param item a valid #Elm_Widget_Item to be notified
4196  * @see elm_widget_item_del_cb_set() convenience macro.
4197  * @ingroup Widget
4198  */
4199 EAPI void
4200 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
4201                             Evas_Smart_Cb func)
4202 {
4203    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4204    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4205
4206    if ((item->del_func) && (item->del_func != func))
4207      WRN("You're replacing a previously set del_cb %p of item %p with %p",
4208          item->del_func, item, func);
4209
4210    item->del_func = func;
4211 }
4212
4213 /**
4214  * @internal
4215  *
4216  * Retrieves owner widget of this item.
4217  *
4218  * @param item a valid #Elm_Widget_Item to get data from.
4219  * @return owner widget of this item.
4220  * @ingroup Widget
4221  */
4222 EAPI Evas_Object *
4223 _elm_widget_item_widget_get(const Elm_Widget_Item *item)
4224 {
4225    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4226    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4227
4228    return item->widget;
4229 }
4230
4231 /**
4232  * @internal
4233  *
4234  * Set user-data in this item.
4235  *
4236  * User data may be used to identify this item or just store any
4237  * application data. It is automatically given as the first parameter
4238  * of the deletion notify callback.
4239  *
4240  * @param item a valid #Elm_Widget_Item to store data in.
4241  * @param data user data to store.
4242  * @see elm_widget_item_del_cb_set() convenience macro.
4243  * @ingroup Widget
4244  */
4245 EAPI void
4246 _elm_widget_item_data_set(Elm_Widget_Item *item,
4247                           const void *data)
4248 {
4249    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4250    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4251
4252    if ((item->data) && (item->data != data))
4253      DBG("Replacing item %p data %p with %p", item, item->data, data);
4254    item->data = data;
4255 }
4256
4257 /**
4258  * @internal
4259  *
4260  * Retrieves user-data of this item.
4261  *
4262  * @param item a valid #Elm_Widget_Item to get data from.
4263  * @see elm_widget_item_data_set()
4264  * @ingroup Widget
4265  */
4266 EAPI void *
4267 _elm_widget_item_data_get(const Elm_Widget_Item *item)
4268 {
4269    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4270    return (void *)item->data;
4271 }
4272
4273 EAPI void
4274 _elm_widget_item_disabled_set(Elm_Widget_Item *item,
4275                               Eina_Bool disabled)
4276 {
4277    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4278    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4279
4280    if (item->disabled == disabled) return;
4281    item->disabled = !!disabled;
4282    if (item->disable_func) item->disable_func(item);
4283 }
4284
4285 EAPI Eina_Bool
4286 _elm_widget_item_disabled_get(const Elm_Widget_Item *item)
4287 {
4288    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
4289    return item->disabled;
4290 }
4291
4292 EAPI void
4293 _elm_widget_item_style_set(Elm_Widget_Item *item, const char *style)
4294 {
4295    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4296    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4297    item->style_set_func(item, style);
4298 }
4299
4300 EAPI const char *
4301 _elm_widget_item_style_get(Elm_Widget_Item *item)
4302 {
4303    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4304    return item->style_get_func(item);
4305 }
4306
4307 EAPI void
4308 _elm_widget_item_disable_hook_set(Elm_Widget_Item *item,
4309                                   Elm_Widget_Disable_Cb func)
4310 {
4311    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4312    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4313    item->disable_func = func;
4314 }
4315
4316 EAPI void
4317 _elm_widget_item_focus_set(Elm_Widget_Item *item, Eina_Bool focused)
4318 {
4319    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4320    item->focus_set_func(item, focused);
4321 }
4322
4323 EAPI Eina_Bool
4324 _elm_widget_item_focus_get(const Elm_Widget_Item *item)
4325 {
4326    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
4327    return item->focus_get_func(item);
4328 }
4329
4330 EAPI void
4331 _elm_widget_item_domain_translatable_part_text_set(Elm_Widget_Item *item,
4332                                                    const char *part,
4333                                                    const char *domain,
4334                                                    const char *label)
4335 {
4336    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4337    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4338    Elm_Translate_String_Data *ts;
4339
4340    if (!label)
4341      {
4342         _part_text_translatable_set(&item->translate_strings, part, EINA_FALSE,
4343                                     EINA_FALSE);
4344      }
4345    else
4346      {
4347         ts = _part_text_translatable_set(&item->translate_strings, part,
4348                                          EINA_TRUE, EINA_FALSE);
4349         if (!ts) return;
4350         if (!ts->string) ts->string = eina_stringshare_add(label);
4351         else eina_stringshare_replace(&ts->string, label);
4352         if (!ts->domain) ts->domain = eina_stringshare_add(domain);
4353         else eina_stringshare_replace(&ts->domain, domain);
4354 #ifdef HAVE_GETTEXT
4355         if (label[0]) label = dgettext(domain, label);
4356 #endif
4357      }
4358    item->on_translate = EINA_TRUE;
4359    _elm_widget_item_part_text_set(item, part, label);
4360    item->on_translate = EINA_FALSE;
4361 }
4362
4363 EAPI const char *
4364 _elm_widget_item_translatable_part_text_get(const Elm_Widget_Item *item,
4365                                             const char *part)
4366 {
4367    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4368    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4369
4370    Elm_Translate_String_Data *ts;
4371    ts = _translate_string_data_get(item->translate_strings, part);
4372    if (ts) return ts->string;
4373    return NULL;
4374 }
4375
4376 EAPI void
4377 _elm_widget_item_domain_part_text_translatable_set(Elm_Widget_Item *item,
4378                                                    const char *part,
4379                                                    const char *domain,
4380                                                    Eina_Bool translatable)
4381 {
4382    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4383    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4384    Elm_Translate_String_Data *ts;
4385    const char *text;
4386
4387    ts = _part_text_translatable_set(&item->translate_strings, part,
4388                                     translatable, EINA_TRUE);
4389    if (!ts) return;
4390    if (!ts->domain) ts->domain = eina_stringshare_add(domain);
4391    else eina_stringshare_replace(&ts->domain, domain);
4392
4393    text = _elm_widget_item_part_text_get(item, part);
4394    if (!text || !text[0]) return;
4395
4396    if (!ts->string) ts->string = eina_stringshare_add(text);
4397
4398 //Try to translate text since we don't know the text is already translated.
4399 #ifdef HAVE_GETTEXT
4400    text = dgettext(domain, text);
4401 #endif
4402    item->on_translate = EINA_TRUE;
4403    _elm_widget_item_part_text_set(item, part, text);
4404    item->on_translate = EINA_FALSE;
4405 }
4406
4407 EAPI void
4408 _elm_widget_item_track_cancel(Elm_Widget_Item *item)
4409 {
4410    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4411    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4412
4413    if (!item->track_obj) return;
4414
4415    while (evas_object_ref_get(item->track_obj) > 0)
4416      evas_object_unref(item->track_obj);
4417
4418    evas_object_del(item->track_obj);
4419 }
4420
4421 EAPI Evas_Object *
4422 elm_widget_item_track(Elm_Widget_Item *item)
4423 {
4424    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4425    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4426
4427    if (item->track_obj)
4428      {
4429         evas_object_ref(item->track_obj);
4430         return item->track_obj;
4431      }
4432
4433    if (!item->view)
4434      {
4435         WRN("view obj of the item(%p) is invalid. Please make sure the view obj is created!", item);
4436         return NULL;
4437      }
4438
4439    Evas_Object *track =
4440       evas_object_rectangle_add(evas_object_evas_get(item->widget));
4441    evas_object_color_set(track, 0, 0, 0, 0);
4442    evas_object_pass_events_set(track, EINA_TRUE);
4443    _track_obj_update(track, item->view);
4444    evas_object_event_callback_add(track, EVAS_CALLBACK_DEL, _track_obj_del,
4445                                   item);
4446
4447    evas_object_event_callback_add(item->view, EVAS_CALLBACK_RESIZE,
4448                                   _track_obj_view_update, track);
4449    evas_object_event_callback_add(item->view, EVAS_CALLBACK_MOVE,
4450                                   _track_obj_view_update, track);
4451    evas_object_event_callback_add(item->view, EVAS_CALLBACK_SHOW,
4452                                   _track_obj_view_update, track);
4453    evas_object_event_callback_add(item->view, EVAS_CALLBACK_HIDE,
4454                                   _track_obj_view_update, track);
4455    evas_object_event_callback_add(item->view, EVAS_CALLBACK_DEL,
4456                                   _track_obj_view_del, item);
4457
4458    evas_object_ref(track);
4459
4460    item->track_obj = track;
4461
4462    return track;
4463 }
4464
4465 void
4466 elm_widget_item_untrack(Elm_Widget_Item *item)
4467 {
4468    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4469    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4470
4471    if (!item->track_obj) return;
4472    evas_object_unref(item->track_obj);
4473
4474    if (evas_object_ref_get(item->track_obj) == 0)
4475      evas_object_del(item->track_obj);
4476 }
4477
4478 int
4479 elm_widget_item_track_get(const Elm_Widget_Item *item)
4480 {
4481    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, 0);
4482    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, 0);
4483
4484    if (!item->track_obj) return 0;
4485    return evas_object_ref_get(item->track_obj);
4486 }
4487
4488 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
4489
4490 struct _Elm_Widget_Item_Tooltip
4491 {
4492    Elm_Widget_Item            *item;
4493    Elm_Tooltip_Item_Content_Cb func;
4494    Evas_Smart_Cb               del_cb;
4495    const void                 *data;
4496 };
4497
4498 static Evas_Object *
4499 _elm_widget_item_tooltip_label_create(void *data,
4500                                       Evas_Object *obj EINA_UNUSED,
4501                                       Evas_Object *tooltip,
4502                                       void *item EINA_UNUSED)
4503 {
4504    Evas_Object *label = elm_label_add(tooltip);
4505    if (!label)
4506      return NULL;
4507    elm_object_style_set(label, "tooltip");
4508    elm_object_text_set(label, data);
4509    return label;
4510 }
4511
4512 static Evas_Object *
4513 _elm_widget_item_tooltip_trans_label_create(void *data,
4514                                             Evas_Object *obj EINA_UNUSED,
4515                                             Evas_Object *tooltip,
4516                                             void *item EINA_UNUSED)
4517 {
4518    Evas_Object *label = elm_label_add(tooltip);
4519    if (!label)
4520      return NULL;
4521    elm_object_style_set(label, "tooltip");
4522    elm_object_translatable_text_set(label, data);
4523    return label;
4524 }
4525
4526 static void
4527 _elm_widget_item_tooltip_label_del_cb(void *data,
4528                                       Evas_Object *obj EINA_UNUSED,
4529                                       void *event_info EINA_UNUSED)
4530 {
4531    eina_stringshare_del(data);
4532 }
4533
4534 /**
4535  * @internal
4536  *
4537  * Set the text to be shown in the widget item.
4538  *
4539  * @param item Target item
4540  * @param text The text to set in the content
4541  *
4542  * Setup the text as tooltip to object. The item can have only one tooltip,
4543  * so any previous tooltip data is removed.
4544  *
4545  * @ingroup Widget
4546  */
4547 EAPI void
4548 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
4549                                   const char *text)
4550 {
4551    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4552    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4553    EINA_SAFETY_ON_NULL_RETURN(text);
4554
4555    text = eina_stringshare_add(text);
4556    _elm_widget_item_tooltip_content_cb_set
4557      (item, _elm_widget_item_tooltip_label_create, text,
4558      _elm_widget_item_tooltip_label_del_cb);
4559 }
4560
4561 EAPI void
4562 _elm_widget_item_tooltip_translatable_text_set(Elm_Widget_Item *item,
4563                                                const char *text)
4564 {
4565    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4566    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4567    EINA_SAFETY_ON_NULL_RETURN(text);
4568
4569    text = eina_stringshare_add(text);
4570    _elm_widget_item_tooltip_content_cb_set
4571      (item, _elm_widget_item_tooltip_trans_label_create, text,
4572      _elm_widget_item_tooltip_label_del_cb);
4573 }
4574
4575 static Evas_Object *
4576 _elm_widget_item_tooltip_create(void *data,
4577                                 Evas_Object *obj,
4578                                 Evas_Object *tooltip)
4579 {
4580    Elm_Widget_Item_Tooltip *wit = data;
4581    return wit->func((void *)wit->data, obj, tooltip, wit->item);
4582 }
4583
4584 static void
4585 _elm_widget_item_tooltip_del_cb(void *data,
4586                                 Evas_Object *obj,
4587                                 void *event_info EINA_UNUSED)
4588 {
4589    Elm_Widget_Item_Tooltip *wit = data;
4590    if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
4591    free(wit);
4592 }
4593
4594 /**
4595  * @internal
4596  *
4597  * Set the content to be shown in the tooltip item
4598  *
4599  * Setup the tooltip to item. The item can have only one tooltip,
4600  * so any previous tooltip data is removed. @p func(with @p data) will
4601  * be called every time that need show the tooltip and it should
4602  * return a valid Evas_Object. This object is then managed fully by
4603  * tooltip system and is deleted when the tooltip is gone.
4604  *
4605  * @param item the widget item being attached a tooltip.
4606  * @param func the function used to create the tooltip contents.
4607  * @param data what to provide to @a func as callback data/context.
4608  * @param del_cb called when data is not needed anymore, either when
4609  *        another callback replaces @func, the tooltip is unset with
4610  *        elm_widget_item_tooltip_unset() or the owner @a item
4611  *        dies. This callback receives as the first parameter the
4612  *        given @a data, and @c event_info is the item.
4613  *
4614  * @ingroup Widget
4615  */
4616 EAPI void
4617 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
4618                                         Elm_Tooltip_Item_Content_Cb func,
4619                                         const void *data,
4620                                         Evas_Smart_Cb del_cb)
4621 {
4622    Elm_Widget_Item_Tooltip *wit;
4623
4624    ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
4625    //ELM_WIDGET_ITEM_RETURN_IF_GOTO(item, error_noitem);
4626
4627    if (!func)
4628      {
4629         _elm_widget_item_tooltip_unset(item);
4630         return;
4631      }
4632
4633    wit = ELM_NEW(Elm_Widget_Item_Tooltip);
4634    if (!wit) goto error;
4635    wit->item = item;
4636    wit->func = func;
4637    wit->data = data;
4638    wit->del_cb = del_cb;
4639
4640    elm_object_sub_tooltip_content_cb_set
4641      (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
4642      _elm_widget_item_tooltip_del_cb);
4643
4644    return;
4645
4646 error_noitem:
4647    if (del_cb) del_cb((void *)data, NULL, item);
4648    return;
4649 error:
4650    if (del_cb) del_cb((void *)data, item->widget, item);
4651 }
4652
4653 /**
4654  * @internal
4655  *
4656  * Unset tooltip from item
4657  *
4658  * @param item widget item to remove previously set tooltip.
4659  *
4660  * Remove tooltip from item. The callback provided as del_cb to
4661  * elm_widget_item_tooltip_content_cb_set() will be called to notify
4662  * it is not used anymore.
4663  *
4664  * @see elm_widget_item_tooltip_content_cb_set()
4665  *
4666  * @ingroup Widget
4667  */
4668 EAPI void
4669 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
4670 {
4671    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4672    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4673
4674    elm_object_tooltip_unset(item->view);
4675 }
4676
4677 /**
4678  * @internal
4679  *
4680  * Sets a different style for this item tooltip.
4681  *
4682  * @note before you set a style you should define a tooltip with
4683  *       elm_widget_item_tooltip_content_cb_set() or
4684  *       elm_widget_item_tooltip_text_set()
4685  *
4686  * @param item widget item with tooltip already set.
4687  * @param style the theme style to use (default, transparent, ...)
4688  *
4689  * @ingroup Widget
4690  */
4691 EAPI void
4692 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
4693                                    const char *style)
4694 {
4695    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4696    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4697
4698    elm_object_tooltip_style_set(item->view, style);
4699 }
4700
4701 EAPI Eina_Bool
4702 _elm_widget_item_tooltip_window_mode_set(Elm_Widget_Item *item,
4703                                          Eina_Bool disable)
4704 {
4705    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
4706    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, EINA_FALSE);
4707
4708    return elm_object_tooltip_window_mode_set(item->view, disable);
4709 }
4710
4711 EAPI Eina_Bool
4712 _elm_widget_item_tooltip_window_mode_get(const Elm_Widget_Item *item)
4713 {
4714    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
4715    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, EINA_FALSE);
4716
4717    return elm_object_tooltip_window_mode_get(item->view);
4718 }
4719
4720 /**
4721  * @internal
4722  *
4723  * Get the style for this item tooltip.
4724  *
4725  * @param item widget item with tooltip already set.
4726  * @return style the theme style in use, defaults to "default". If the
4727  *         object does not have a tooltip set, then NULL is returned.
4728  *
4729  * @ingroup Widget
4730  */
4731 EAPI const char *
4732 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
4733 {
4734    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4735
4736    return elm_object_tooltip_style_get(item->view);
4737 }
4738
4739 EAPI void
4740 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
4741                             const char *cursor)
4742 {
4743    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4744    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4745
4746    elm_object_sub_cursor_set(item->view, item->widget, cursor);
4747 }
4748
4749 EAPI const char *
4750 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
4751 {
4752    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4753    return elm_object_cursor_get(item->view);
4754 }
4755
4756 EAPI void
4757 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
4758 {
4759    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4760    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4761
4762    elm_object_cursor_unset(item->view);
4763 }
4764
4765 /**
4766  * @internal
4767  *
4768  * Sets a different style for this item cursor.
4769  *
4770  * @note before you set a style you should define a cursor with
4771  *       elm_widget_item_cursor_set()
4772  *
4773  * @param item widget item with cursor already set.
4774  * @param style the theme style to use (default, transparent, ...)
4775  *
4776  * @ingroup Widget
4777  */
4778 EAPI void
4779 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
4780                                   const char *style)
4781 {
4782    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4783    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4784
4785    elm_object_cursor_style_set(item->view, style);
4786 }
4787
4788 /**
4789  * @internal
4790  *
4791  * Get the style for this item cursor.
4792  *
4793  * @param item widget item with cursor already set.
4794  * @return style the theme style in use, defaults to "default". If the
4795  *         object does not have a cursor set, then NULL is returned.
4796  *
4797  * @ingroup Widget
4798  */
4799 EAPI const char *
4800 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
4801 {
4802    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4803    return elm_object_cursor_style_get(item->view);
4804 }
4805
4806 /**
4807  * @internal
4808  *
4809  * Set if the cursor set should be searched on the theme or should use
4810  * the provided by the engine, only.
4811  *
4812  * @note before you set if should look on theme you should define a cursor
4813  * with elm_object_cursor_set(). By default it will only look for cursors
4814  * provided by the engine.
4815  *
4816  * @param item widget item with cursor already set.
4817  * @param engine_only boolean to define it cursors should be looked only
4818  * between the provided by the engine or searched on widget's theme as well.
4819  *
4820  * @ingroup Widget
4821  */
4822 EAPI void
4823 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
4824                                         Eina_Bool engine_only)
4825 {
4826    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4827    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4828
4829    elm_object_cursor_theme_search_enabled_set(item->view, !engine_only);
4830 }
4831
4832 /**
4833  * @internal
4834  *
4835  * Get the cursor engine only usage for this item cursor.
4836  *
4837  * @param item widget item with cursor already set.
4838  * @return engine_only boolean to define it cursors should be looked only
4839  * between the provided by the engine or searched on widget's theme as well. If
4840  *         the object does not have a cursor set, then EINA_FALSE is returned.
4841  *
4842  * @ingroup Widget
4843  */
4844 EAPI Eina_Bool
4845 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
4846 {
4847    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
4848    return !elm_object_cursor_theme_search_enabled_get(item->view);
4849 }
4850
4851 EAPI void
4852 _elm_widget_item_part_content_set(Elm_Widget_Item *item,
4853                                   const char *part,
4854                                   Evas_Object *content)
4855 {
4856    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4857    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4858    if (!item->content_set_func)
4859      {
4860         ERR("%s does not support elm_object_item_part_content_set() API.",
4861             elm_widget_type_get(item->widget));
4862         return;
4863      }
4864    item->content_set_func((Elm_Object_Item *)item, part, content);
4865 }
4866
4867 EAPI Evas_Object *
4868 _elm_widget_item_part_content_get(const Elm_Widget_Item *item,
4869                                   const char *part)
4870 {
4871    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4872    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4873    if (!item->content_get_func)
4874      {
4875         ERR("%s does not support elm_object_item_part_content_get() API.",
4876             elm_widget_type_get(item->widget));
4877         return NULL;
4878      }
4879    return item->content_get_func((Elm_Object_Item *)item, part);
4880 }
4881
4882 EAPI Evas_Object *
4883 _elm_widget_item_part_content_unset(Elm_Widget_Item *item,
4884                                     const char *part)
4885 {
4886    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4887    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4888    if (!item->content_unset_func)
4889      {
4890         ERR("%s does not support elm_object_item_part_content_unset() API.",
4891             elm_widget_type_get(item->widget));
4892         return NULL;
4893      }
4894    return item->content_unset_func((Elm_Object_Item *)item, part);
4895 }
4896
4897 EAPI void
4898 _elm_widget_item_part_text_set(Elm_Widget_Item *item,
4899                                const char *part,
4900                                const char *label)
4901 {
4902    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4903    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4904    if (!item->text_set_func)
4905      {
4906         ERR("%s does not support elm_object_item_part_text_set() API.",
4907             elm_widget_type_get(item->widget));
4908         return;
4909      }
4910    item->text_set_func((Elm_Object_Item *)item, part, label);
4911 }
4912
4913 EAPI const char *
4914 _elm_widget_item_part_text_get(const Elm_Widget_Item *item,
4915                                const char *part)
4916 {
4917    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4918    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
4919    if (!item->text_get_func)
4920      {
4921         ERR("%s does not support elm_object_item_part_text_get() API.",
4922             elm_widget_type_get(item->widget));
4923         return NULL;
4924      }
4925    return item->text_get_func((Elm_Object_Item *)item, part);
4926 }
4927
4928 static void
4929 _elm_widget_item_part_text_custom_free(void *data)
4930 {
4931    Elm_Label_Data *label;
4932    label = data;
4933    eina_stringshare_del(label->part);
4934    eina_stringshare_del(label->text);
4935    free(label);
4936 }
4937
4938 EAPI void
4939 _elm_widget_item_part_text_custom_set(Elm_Widget_Item *item,
4940                                       const char *part,
4941                                       const char *text)
4942 {
4943    Elm_Label_Data *label;
4944    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4945    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4946
4947    if (!item->text_get_func)
4948      {
4949         ERR("%s does not support elm_object_item_part_text_get() API.",
4950             elm_widget_type_get(item->widget));
4951         return;
4952      }
4953    if (!item->labels)
4954      item->labels =
4955         eina_hash_stringshared_new(_elm_widget_item_part_text_custom_free);
4956    label = eina_hash_find(item->labels, part);
4957    if (!label)
4958      {
4959         label = malloc(sizeof(Elm_Label_Data));
4960         label->part = eina_stringshare_add(part);
4961         label->text = eina_stringshare_add(text);
4962         eina_hash_add(item->labels, part, label);
4963      }
4964    else
4965      eina_stringshare_replace(&label->text, text);
4966 }
4967
4968 EAPI const char *
4969 _elm_widget_item_part_text_custom_get(Elm_Widget_Item *item,
4970                                       const char *part)
4971 {
4972    Elm_Label_Data *label;
4973    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
4974    label = eina_hash_find(item->labels, part);
4975    return label ? label->text : NULL;
4976 }
4977
4978 static Eina_Bool
4979 _elm_widget_item_part_text_custom_foreach(const Eina_Hash *labels EINA_UNUSED,
4980                                           const void *key EINA_UNUSED,
4981                                           void *data,
4982                                           void *func_data)
4983 {
4984    Elm_Label_Data *label;
4985    Elm_Widget_Item *item;
4986    label = data;
4987    item = func_data;
4988    item->text_set_func((Elm_Object_Item *)item, label->part, label->text);
4989    return EINA_TRUE;
4990 }
4991
4992 EAPI void
4993 _elm_widget_item_part_text_custom_update(Elm_Widget_Item *item)
4994 {
4995    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
4996    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
4997    if (item->labels)
4998      eina_hash_foreach(item->labels,
4999                        _elm_widget_item_part_text_custom_foreach, item);
5000 }
5001
5002 EAPI void
5003 _elm_widget_item_content_set_hook_set(Elm_Widget_Item *item,
5004                                       Elm_Widget_Content_Set_Cb func)
5005 {
5006    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5007    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5008
5009    item->content_set_func = func;
5010 }
5011
5012 EAPI void
5013 _elm_widget_item_content_get_hook_set(Elm_Widget_Item *item,
5014                                       Elm_Widget_Content_Get_Cb func)
5015 {
5016    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5017    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5018
5019    item->content_get_func = func;
5020 }
5021
5022 EAPI void
5023 _elm_widget_item_content_unset_hook_set(Elm_Widget_Item *item,
5024                                         Elm_Widget_Content_Unset_Cb func)
5025 {
5026    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5027    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5028
5029    item->content_unset_func = func;
5030 }
5031
5032 EAPI void
5033 _elm_widget_item_text_set_hook_set(Elm_Widget_Item *item,
5034                                    Elm_Widget_Text_Set_Cb func)
5035 {
5036    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5037    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5038
5039    item->text_set_func = func;
5040 }
5041
5042 EAPI void
5043 _elm_widget_item_text_get_hook_set(Elm_Widget_Item *item,
5044                                    Elm_Widget_Text_Get_Cb func)
5045 {
5046    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5047    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5048
5049    item->text_get_func = func;
5050 }
5051
5052 EAPI void
5053 _elm_widget_item_signal_emit(Elm_Widget_Item *item,
5054                              const char *emission,
5055                              const char *source)
5056 {
5057    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5058    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5059
5060    if (item->signal_emit_func)
5061      item->signal_emit_func((Elm_Object_Item *)item, emission, source);
5062 }
5063
5064 EAPI void
5065 _elm_widget_item_signal_emit_hook_set(Elm_Widget_Item *item,
5066                                       Elm_Widget_Signal_Emit_Cb func)
5067 {
5068    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5069    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5070
5071    item->signal_emit_func = func;
5072 }
5073
5074 EAPI void
5075 _elm_widget_item_signal_callback_add(Elm_Widget_Item *item,
5076                                      const char *emission,
5077                                      const char *source,
5078                                      Elm_Widget_Item_Signal_Cb func,
5079                                      void *data)
5080 {
5081    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5082    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5083    EINA_SAFETY_ON_NULL_RETURN(func);
5084
5085    Elm_Widget_Item_Signal_Data *wisd;
5086
5087    wisd = malloc(sizeof(Elm_Widget_Item_Signal_Data));
5088    if (!wisd) return;
5089
5090    wisd->item = item;
5091    wisd->func = func;
5092    wisd->data = data;
5093    wisd->emission = eina_stringshare_add(emission);
5094    wisd->source = eina_stringshare_add(source);
5095
5096    if (_elm_widget_is(item->view))
5097      elm_object_signal_callback_add(item->view, emission, source, _elm_widget_item_signal_cb, wisd);
5098    else if (!strcmp(eo_class_name_get(eo_class_get(item->view)), "edje"))
5099      edje_object_signal_callback_add(item->view, emission, source, _elm_widget_item_signal_cb, wisd);
5100    else
5101      {
5102         WRN("The %s widget item doesn't support signal callback add!",
5103             eo_class_name_get(eo_class_get(item->widget)));
5104         free(wisd);
5105         return;
5106      }
5107
5108    item->signals = eina_list_append(item->signals, wisd);
5109 }
5110
5111 EAPI void *
5112 _elm_widget_item_signal_callback_del(Elm_Widget_Item *item,
5113                                     const char *emission,
5114                                     const char *source,
5115                                     Elm_Widget_Item_Signal_Cb func)
5116 {
5117    Elm_Widget_Item_Signal_Data *wisd;
5118    Eina_List *l;
5119
5120    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
5121    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item, NULL);
5122    EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
5123
5124    EINA_LIST_FOREACH(item->signals, l, wisd)
5125      {
5126         if ((wisd->func == func) &&
5127             !strcmp(wisd->emission, emission) &&
5128             !strcmp(wisd->source, source))
5129           return _elm_widget_item_signal_callback_list_get(item, l);
5130      }
5131
5132    return NULL;
5133 }
5134
5135 EAPI void
5136 _elm_widget_item_access_info_set(Elm_Widget_Item *item,
5137                                  const char *txt)
5138 {
5139    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5140    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5141
5142    eina_stringshare_del(item->access_info);
5143    if (!txt) item->access_info = NULL;
5144    else item->access_info = eina_stringshare_add(txt);
5145 }
5146
5147 EAPI void
5148 _elm_widget_item_translate(Elm_Widget_Item *item)
5149 {
5150    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
5151    ELM_WIDGET_ITEM_RETURN_IF_ONDEL(item);
5152
5153 #ifdef HAVE_GETTEXT
5154    Elm_Translate_String_Data *ts;
5155    EINA_INLIST_FOREACH(item->translate_strings, ts)
5156      {
5157         if (!ts->string) continue;
5158         const char *s = dgettext(ts->domain, ts->string);
5159         item->on_translate = EINA_TRUE;
5160         _elm_widget_item_part_text_set(item, ts->id, s);
5161         item->on_translate = EINA_FALSE;
5162      }
5163 #endif
5164 }
5165
5166 /* happy debug functions */
5167 #ifdef ELM_DEBUG
5168 static void
5169 _sub_obj_tree_dump(const Evas_Object *obj,
5170                    int lvl)
5171 {
5172    int i;
5173
5174    for (i = 0; i < lvl * 3; i++)
5175      putchar(' ');
5176
5177    if (_elm_widget_is(obj))
5178      {
5179         Eina_List *l;
5180         INTERNAL_ENTRY;
5181         DBG("+ %s(%p)\n",
5182             elm_widget_type_get(obj),
5183             obj);
5184         EINA_LIST_FOREACH(sd->subobjs, l, obj)
5185           _sub_obj_tree_dump(obj, lvl + 1);
5186      }
5187    else
5188      DBG("+ %s(%p)\n", evas_object_type_get(obj), obj);
5189 }
5190
5191 static void
5192 _sub_obj_tree_dot_dump(const Evas_Object *obj,
5193                        FILE *output)
5194 {
5195    if (!_elm_widget_is(obj))
5196      return;
5197    INTERNAL_ENTRY;
5198
5199    Eina_Bool visible = evas_object_visible_get(obj);
5200    Eina_Bool disabled = elm_widget_disabled_get(obj);
5201    Eina_Bool focused = elm_widget_focus_get(obj);
5202    Eina_Bool can_focus = elm_widget_can_focus_get(obj);
5203
5204    if (sd->parent_obj)
5205      {
5206         fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
5207
5208         if (focused)
5209           fprintf(output, ", style=bold");
5210
5211         if (!visible)
5212           fprintf(output, ", color=gray28");
5213
5214         fprintf(output, " ];\n");
5215      }
5216
5217    fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
5218                    "disabled: %d|focused: %d/%d|focus order:%d}\"",
5219            obj, obj, elm_widget_type_get(obj),
5220            evas_object_name_get(obj), visible, disabled, focused, can_focus,
5221            sd->focus_order);
5222
5223    if (focused)
5224      fprintf(output, ", style=bold");
5225
5226    if (!visible)
5227      fprintf(output, ", fontcolor=gray28");
5228
5229    if ((disabled) || (!visible))
5230      fprintf(output, ", color=gray");
5231
5232    fprintf(output, " ];\n");
5233
5234    Eina_List *l;
5235    Evas_Object *o;
5236    EINA_LIST_FOREACH(sd->subobjs, l, o)
5237      _sub_obj_tree_dot_dump(o, output);
5238 }
5239
5240 #endif
5241
5242 EAPI void
5243 elm_widget_tree_dump(const Evas_Object *top)
5244 {
5245 #ifdef ELM_DEBUG
5246    if (!_elm_widget_is(top))
5247      return;
5248    _sub_obj_tree_dump(top, 0);
5249 #else
5250    (void)top;
5251    return;
5252 #endif
5253 }
5254
5255 EAPI void
5256 elm_widget_tree_dot_dump(const Evas_Object *top,
5257                          FILE *output)
5258 {
5259 #ifdef ELM_DEBUG
5260    if (!_elm_widget_is(top))
5261      return;
5262    fprintf(output, "graph " " { node [shape=record];\n");
5263    _sub_obj_tree_dot_dump(top, output);
5264    fprintf(output, "}\n");
5265 #else
5266    (void)top;
5267    (void)output;
5268    return;
5269 #endif
5270 }
5271
5272 static Eina_Bool
5273 _atspi_obj_create(void *data)
5274 {
5275    Elm_Atspi_Object *parent = NULL;
5276    Elm_Atspi_Object *obj = _elm_atspi_factory_construct(data);
5277    if (obj)
5278      {
5279        eo_do(obj, elm_atspi_obj_parent_get(&parent));
5280        eo_do(parent, eo_event_callback_call(ELM_ATSPI_OBJECT_EVENT_CHILD_ADDED, obj, NULL));
5281      }
5282    return EINA_FALSE;
5283 }
5284
5285 EOLIAN static void
5286 _elm_widget_eo_base_constructor(Eo *obj, Elm_Widget_Smart_Data *sd)
5287 {
5288    Eo *parent;
5289
5290    sd->on_create = EINA_TRUE;
5291    eo_do_super(obj, MY_CLASS, eo_constructor());
5292    eo_do(obj,
5293          evas_obj_type_set(MY_CLASS_NAME_LEGACY),
5294          eo_parent_get(&parent));
5295    eo_do(obj, elm_obj_widget_parent_set(parent));
5296    sd->on_create = EINA_FALSE;
5297
5298    if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
5299      ecore_idle_enterer_add(_atspi_obj_create, obj);
5300 }
5301
5302 EOLIAN static Eina_Bool
5303 _elm_widget_on_focus(Eo *obj, Elm_Widget_Smart_Data *sd)
5304 {
5305    if (elm_widget_can_focus_get(obj))
5306      {
5307         if (elm_widget_focus_get(obj))
5308           {
5309              if (!sd->resize_obj)
5310                evas_object_focus_set(obj, EINA_TRUE);
5311              evas_object_smart_callback_call(obj, SIG_WIDGET_FOCUSED, NULL);
5312           }
5313         else
5314           {
5315              if (!sd->resize_obj)
5316                evas_object_focus_set(obj, EINA_FALSE);
5317              evas_object_smart_callback_call(obj, SIG_WIDGET_UNFOCUSED, NULL);
5318           }
5319      }
5320    else
5321      return EINA_FALSE;
5322
5323    return EINA_TRUE;
5324 }
5325
5326 EOLIAN static Eina_Bool
5327 _elm_widget_disable(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
5328 {
5329    return EINA_FALSE;
5330 }
5331
5332 EOLIAN static Eina_Bool
5333 _elm_widget_event(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *source EINA_UNUSED, Evas_Callback_Type type EINA_UNUSED, void *event_info EINA_UNUSED)
5334 {
5335    return EINA_FALSE;
5336 }
5337
5338 EOLIAN static Eina_Bool
5339 _elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
5340 {
5341    WRN("The %s widget does not implement the \"focus_next/focus_next_manager_is\" functions.",
5342        eo_class_name_get(eo_class_get(obj)));
5343    return EINA_FALSE;
5344 }
5345
5346 static Eina_Bool
5347 _elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
5348 {
5349    WRN("The %s widget does not implement the \"focus_direction/focus_direction_manager_is\" functions.",
5350        eo_class_name_get(eo_class_get(obj)));
5351    return EINA_FALSE;
5352 }
5353
5354 EOLIAN static Eina_Bool
5355 _elm_widget_activate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Elm_Activate act EINA_UNUSED)
5356 {
5357    WRN("The %s widget does not implement the \"activate\" functions.",
5358        eo_class_name_get(eo_class_get(obj)));
5359    return EINA_TRUE;
5360 }
5361
5362 EOLIAN static void
5363 _elm_widget_class_constructor(Eo_Class *klass)
5364 {
5365    evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
5366 }
5367
5368 #include "elm_widget.eo.c"