Merge "[*][focus] merge with 63245 for fixing focus problem in twitter+Home button"
[framework/uifw/elementary.git] / src / lib / elm_widget.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 static const char SMART_NAME[] = "elm_widget";
5
6 #define API_ENTRY                                    \
7   Smart_Data * sd = evas_object_smart_data_get(obj); \
8   if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
9 #define INTERNAL_ENTRY                               \
10   Smart_Data * sd = evas_object_smart_data_get(obj); \
11   if (!sd) return;
12
13 typedef struct _Smart_Data        Smart_Data;
14 typedef struct _Edje_Signal_Data  Edje_Signal_Data;
15 typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data;
16
17 struct _Smart_Data
18 {
19    Evas_Object *obj;
20    const char  *type;
21    Evas_Object *parent_obj;
22    Evas_Coord   x, y, w, h;
23    Eina_List   *subobjs;
24    Evas_Object *resize_obj;
25    Evas_Object *hover_obj;
26    Eina_List   *tooltips, *cursors;
27    void       (*del_func)(Evas_Object *obj);
28    void       (*del_pre_func)(Evas_Object *obj);
29    void       (*focus_func)(Evas_Object *obj);
30    void       (*activate_func)(Evas_Object *obj);
31    void       (*disable_func)(Evas_Object *obj);
32    void       (*theme_func)(Evas_Object *obj);
33    Eina_Bool  (*event_func)(Evas_Object       *obj,
34                             Evas_Object       *source,
35                             Evas_Callback_Type type,
36                             void              *event_info);
37    void       (*signal_func)(Evas_Object *obj,
38                              const char  *emission,
39                              const char  *source);
40    void       (*callback_add_func)(Evas_Object   *obj,
41                                    const char    *emission,
42                                    const char    *source,
43                                    Edje_Signal_Cb func,
44                                    void          *data);
45    void       (*callback_del_func)(Evas_Object   *obj,
46                                    const char    *emission,
47                                    const char    *source,
48                                    Edje_Signal_Cb func,
49                                    void          *data);
50    void       (*changed_func)(Evas_Object *obj);
51    Eina_Bool  (*focus_next_func)(const Evas_Object  *obj,
52                                  Elm_Focus_Direction dir,
53                                  Evas_Object       **next);
54    void       (*on_focus_func)(void        *data,
55                                Evas_Object *obj);
56    void        *on_focus_data;
57    void       (*on_change_func)(void        *data,
58                                 Evas_Object *obj);
59    void        *on_change_data;
60    void       (*on_show_region_func)(void        *data,
61                                      Evas_Object *obj);
62    void        *on_show_region_data;
63    void       (*focus_region_func)(Evas_Object *obj,
64                                    Evas_Coord   x,
65                                    Evas_Coord   y,
66                                    Evas_Coord   w,
67                                    Evas_Coord   h);
68    void       (*on_focus_region_func)(const Evas_Object *obj,
69                                       Evas_Coord        *x,
70                                       Evas_Coord        *y,
71                                       Evas_Coord        *w,
72                                       Evas_Coord        *h);
73    void       (*on_text_set_func)(Evas_Object *obj,
74                                    const char  *item,
75                                    const char  *text);
76    const char *(*on_text_get_func)(const Evas_Object *obj,
77                                     const char  *item);
78    void        *data;
79    Evas_Coord   rx, ry, rw, rh;
80    int          scroll_hold;
81    int          scroll_freeze;
82    double       scale;
83    Elm_Theme   *theme;
84    const char  *style;
85    unsigned int focus_order;
86    Eina_Bool    focus_order_on_calc;
87
88    int          child_drag_x_locked;
89    int          child_drag_y_locked;
90
91    Eina_List   *edje_signals;
92
93    Eina_Bool    drag_x_locked : 1;
94    Eina_Bool    drag_y_locked : 1;
95
96    Eina_Bool    can_focus : 1;
97    Eina_Bool    child_can_focus : 1;
98    Eina_Bool    focused : 1;
99    Eina_Bool    top_win_focused : 1;
100    Eina_Bool    tree_unfocusable : 1;
101    Eina_Bool    highlight_ignore : 1;
102    Eina_Bool    highlight_in_theme : 1;
103    Eina_Bool    disabled : 1;
104    Eina_Bool    is_mirrored : 1;
105    Eina_Bool    mirrored_auto_mode : 1;   /* This is TRUE by default */
106
107    Eina_List   *focus_chain;
108    Eina_List   *event_cb;
109 };
110
111 struct _Edje_Signal_Data
112 {
113    Evas_Object   *obj;
114    Edje_Signal_Cb func;
115    const char    *emission;
116    const char    *source;
117    void          *data;
118 };
119
120 struct _Elm_Event_Cb_Data
121 {
122    Elm_Event_Cb func;
123    const void  *data;
124 };
125
126 /* local subsystem functions */
127 static void _smart_reconfigure(Smart_Data *sd);
128 static void _smart_add(Evas_Object *obj);
129 static void _smart_del(Evas_Object *obj);
130 static void _smart_move(Evas_Object *obj,
131                         Evas_Coord   x,
132                         Evas_Coord   y);
133 static void _smart_resize(Evas_Object *obj,
134                           Evas_Coord   w,
135                           Evas_Coord   h);
136 static void _smart_show(Evas_Object *obj);
137 static void _smart_hide(Evas_Object *obj);
138 static void _smart_color_set(Evas_Object *obj,
139                              int          r,
140                              int          g,
141                              int          b,
142                              int          a);
143 static void _smart_clip_set(Evas_Object *obj,
144                             Evas_Object *clip);
145 static void _smart_clip_unset(Evas_Object *obj);
146 static void _smart_calculate(Evas_Object *obj);
147 static void _smart_init(void);
148
149 static void _if_focused_revert(Evas_Object *obj,
150                                Eina_Bool    can_focus_only);
151 static Evas_Object *_newest_focus_order_get(Evas_Object  *obj,
152                                             unsigned int *newest_focus_order,
153                                             Eina_Bool     can_focus_only);
154
155 /* local subsystem globals */
156 static Evas_Smart *_e_smart = NULL;
157 static Eina_List  *widtypes = NULL;
158
159 static unsigned int focus_order = 0;
160
161 // internal funcs
162 static inline Eina_Bool
163 _elm_widget_is(const Evas_Object *obj)
164 {
165    const char *type = evas_object_type_get(obj);
166    return type == SMART_NAME;
167 }
168
169 static inline Eina_Bool
170 _is_focusable(Evas_Object *obj)
171 {
172    API_ENTRY return EINA_FALSE;
173    return sd->can_focus || (sd->child_can_focus);
174 }
175
176 static void
177 _unfocus_parents(Evas_Object *obj)
178 {
179    for (; obj; obj = elm_widget_parent_get(obj))
180      {
181         INTERNAL_ENTRY
182         if (!sd->focused) return;
183         sd->focused = 0;
184      }
185 }
186
187 static void
188 _focus_parents(Evas_Object *obj)
189 {
190    for (; obj; obj = elm_widget_parent_get(obj))
191      {
192         INTERNAL_ENTRY
193         if (sd->focused) return;
194         sd->focused = 1;
195      }
196 }
197
198 static void
199 _sub_obj_del(void        *data,
200              Evas        *e __UNUSED__,
201              Evas_Object *obj,
202              void        *event_info __UNUSED__)
203 {
204    Smart_Data *sd = data;
205
206    if (_elm_widget_is(obj))
207      {
208         if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
209      }
210    if (obj == sd->resize_obj)
211      sd->resize_obj = NULL;
212    else if (obj == sd->hover_obj)
213      sd->hover_obj = NULL;
214    else
215      sd->subobjs = eina_list_remove(sd->subobjs, obj);
216    evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
217 }
218
219 static void
220 _sub_obj_hide(void        *data __UNUSED__,
221               Evas        *e __UNUSED__,
222               Evas_Object *obj,
223               void        *event_info __UNUSED__)
224 {
225    elm_widget_focus_hide_handle(obj);
226 }
227
228 static void
229 _sub_obj_mouse_down(void        *data __UNUSED__,
230                     Evas        *e __UNUSED__,
231                     Evas_Object *obj,
232                     void        *event_info __UNUSED__)
233 {
234    elm_widget_focus_mouse_down_handle(obj);
235 }
236
237 static void
238 _propagate_x_drag_lock(Evas_Object *obj,
239                        int          dir)
240 {
241    INTERNAL_ENTRY
242    if (sd->parent_obj)
243      {
244         Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
245         if (sd2)
246           {
247              sd2->child_drag_x_locked += dir;
248              _propagate_x_drag_lock(sd->parent_obj, dir);
249           }
250      }
251 }
252
253 static void
254 _propagate_y_drag_lock(Evas_Object *obj,
255                        int          dir)
256 {
257    INTERNAL_ENTRY
258    if (sd->parent_obj)
259      {
260         Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
261         if (sd2)
262           {
263              sd2->child_drag_y_locked += dir;
264              _propagate_y_drag_lock(sd->parent_obj, dir);
265           }
266      }
267 }
268
269 static void
270 _propagate_event(void        *data,
271                  Evas        *e __UNUSED__,
272                  Evas_Object *obj,
273                  void        *event_info)
274 {
275    INTERNAL_ENTRY
276    Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
277    Evas_Event_Flags *event_flags = NULL;
278
279    switch (type)
280      {
281       case EVAS_CALLBACK_KEY_DOWN:
282           {
283             Evas_Event_Key_Down *ev = event_info;
284             event_flags = &(ev->event_flags);
285           }
286         break;
287
288       case EVAS_CALLBACK_KEY_UP:
289           {
290              Evas_Event_Key_Up *ev = event_info;
291              event_flags = &(ev->event_flags);
292           }
293         break;
294
295       case EVAS_CALLBACK_MOUSE_WHEEL:
296           {
297             Evas_Event_Mouse_Wheel *ev = event_info;
298             event_flags = &(ev->event_flags);
299           }
300         break;
301
302       default:
303         break;
304      }
305
306    elm_widget_event_propagate(obj, type, event_info, event_flags);
307 }
308
309 static void
310 _parent_focus(Evas_Object *obj)
311 {
312    API_ENTRY return;
313    if (sd->focused) return;
314
315    Evas_Object *o = elm_widget_parent_get(obj);
316    sd->focus_order_on_calc = EINA_TRUE;
317
318    if (o) _parent_focus(o);
319
320    if (!sd->focus_order_on_calc)
321      return; /* we don't want to override it if by means of any of the
322                 callbacks below one gets to calculate our order
323                 first. */
324
325    focus_order++;
326    sd->focus_order = focus_order;
327    if (sd->top_win_focused)
328      {
329         sd->focused = EINA_TRUE;
330         if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
331         if (sd->focus_func) sd->focus_func(obj);
332         _elm_widget_focus_region_show(obj);
333      }
334    sd->focus_order_on_calc = EINA_FALSE;
335 }
336
337 static void
338 _elm_object_focus_chain_del_cb(void        *data,
339                                Evas        *e __UNUSED__,
340                                Evas_Object *obj,
341                                void        *event_info __UNUSED__)
342 {
343    Smart_Data *sd = data;
344
345    sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
346 }
347
348 // exposed util funcs to elm
349 void
350 _elm_widget_type_clear(void)
351 {
352    const char **ptr;
353
354    EINA_LIST_FREE(widtypes, ptr)
355      {
356         eina_stringshare_del(*ptr);
357         *ptr = NULL;
358      }
359 }
360
361 void
362 _elm_widget_focus_region_show(const Evas_Object *obj)
363 {
364    Evas_Coord x, y, w, h, ox, oy;
365    Smart_Data *sd2;
366    Evas_Object *o;
367
368    API_ENTRY return;
369
370    o = elm_widget_parent_get(obj);
371    if (!o) return;
372
373    elm_widget_focus_region_get(obj, &x, &y, &w, &h);
374    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
375    while (o)
376      {
377         Evas_Coord px, py;
378         sd2 = evas_object_smart_data_get(o);
379         if (sd2->focus_region_func)
380           {
381              sd2->focus_region_func(o, x, y, w, h);
382              elm_widget_focus_region_get(o, &x, &y, &w, &h);
383           }
384         else
385           {
386              evas_object_geometry_get(o, &px, &py, NULL, NULL);
387              x += ox - px;
388              y += oy - py;
389              ox = px;
390              oy = py;
391           }
392         o = elm_widget_parent_get(o);
393      }
394 }
395
396 /**
397  * @defgroup Widget Widget
398  *
399  * @internal
400  * Exposed api for making widgets
401  */
402 EAPI void
403 elm_widget_type_register(const char **ptr)
404 {
405    widtypes = eina_list_append(widtypes, (void *)ptr);
406 }
407
408 /**
409  * @defgroup Widget Widget
410  *
411  * @internal
412  * Disposed api for making widgets
413  */
414 EAPI void
415 elm_widget_type_unregister(const char **ptr)
416 {
417    widtypes = eina_list_remove(widtypes, (void *)ptr);
418 }
419
420 EAPI Eina_Bool
421 elm_widget_api_check(int ver)
422 {
423    if (ver != ELM_INTERNAL_API_VERSION)
424      {
425         CRITICAL("Elementary widget api versions do not match");
426         return EINA_FALSE;
427      }
428    return EINA_TRUE;
429 }
430
431 EAPI Evas_Object *
432 elm_widget_add(Evas *evas)
433 {
434    Evas_Object *obj;
435    _smart_init();
436    obj = evas_object_smart_add(evas, _e_smart);
437    elm_widget_mirrored_set(obj, elm_mirrored_get());
438    return obj;
439 }
440
441 EAPI void
442 elm_widget_del_hook_set(Evas_Object *obj,
443                         void       (*func)(Evas_Object *obj))
444 {
445    API_ENTRY return;
446    sd->del_func = func;
447 }
448
449 EAPI void
450 elm_widget_del_pre_hook_set(Evas_Object *obj,
451                             void       (*func)(Evas_Object *obj))
452 {
453    API_ENTRY return;
454    sd->del_pre_func = func;
455 }
456
457 EAPI void
458 elm_widget_focus_hook_set(Evas_Object *obj,
459                           void       (*func)(Evas_Object *obj))
460 {
461    API_ENTRY return;
462    sd->focus_func = func;
463 }
464
465 EAPI void
466 elm_widget_activate_hook_set(Evas_Object *obj,
467                              void       (*func)(Evas_Object *obj))
468 {
469    API_ENTRY return;
470    sd->activate_func = func;
471 }
472
473 EAPI void
474 elm_widget_disable_hook_set(Evas_Object *obj,
475                             void       (*func)(Evas_Object *obj))
476 {
477    API_ENTRY return;
478    sd->disable_func = func;
479 }
480
481 EAPI void
482 elm_widget_theme_hook_set(Evas_Object *obj,
483                           void       (*func)(Evas_Object *obj))
484 {
485    API_ENTRY return;
486    sd->theme_func = func;
487 }
488
489 EAPI void
490 elm_widget_event_hook_set(Evas_Object *obj,
491                           Eina_Bool  (*func)(Evas_Object       *obj,
492                                              Evas_Object       *source,
493                                              Evas_Callback_Type type,
494                                              void              *event_info))
495 {
496    API_ENTRY return;
497    sd->event_func = func;
498 }
499
500 EAPI void
501 elm_widget_text_set_hook_set(Evas_Object *obj,
502                               void       (*func)(Evas_Object *obj,
503                                                  const char  *item,
504                                                  const char  *text))
505 {
506    API_ENTRY return;
507    sd->on_text_set_func = func;
508 }
509
510 EAPI void
511 elm_widget_text_get_hook_set(Evas_Object *obj,
512                               const char *(*func)(const Evas_Object *obj,
513                                                   const char  *item))
514 {
515    API_ENTRY return;
516    sd->on_text_get_func = func;
517 }
518
519 EAPI void
520 elm_widget_changed_hook_set(Evas_Object *obj,
521                             void       (*func)(Evas_Object *obj))
522 {
523    API_ENTRY return;
524    sd->changed_func = func;
525 }
526
527 EAPI void
528 elm_widget_signal_emit_hook_set(Evas_Object *obj,
529                                 void       (*func)(Evas_Object *obj,
530                                                    const char *emission,
531                                                    const char *source))
532 {
533    API_ENTRY return;
534    sd->signal_func = func;
535 }
536
537 EAPI void
538 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
539                                         void       (*func)(Evas_Object   *obj,
540                                                            const char    *emission,
541                                                            const char    *source,
542                                                            Edje_Signal_Cb func_cb,
543                                                            void          *data))
544 {
545    API_ENTRY return;
546    sd->callback_add_func = func;
547 }
548
549 EAPI void
550 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
551                                         void       (*func)(Evas_Object   *obj,
552                                                            const char    *emission,
553                                                            const char    *source,
554                                                            Edje_Signal_Cb func_cb,
555                                                            void          *data))
556 {
557    API_ENTRY return;
558    sd->callback_del_func = func;
559 }
560
561 EAPI void
562 elm_widget_theme(Evas_Object *obj)
563 {
564    const Eina_List *l;
565    Evas_Object *child;
566    Elm_Tooltip *tt;
567    Elm_Cursor *cur;
568
569    API_ENTRY return;
570    EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
571    if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
572    if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
573    EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
574    EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
575    if (sd->theme_func) sd->theme_func(obj);
576 }
577
578 EAPI void
579 elm_widget_theme_specific(Evas_Object *obj,
580                           Elm_Theme   *th,
581                           Eina_Bool    force)
582 {
583    const Eina_List *l;
584    Evas_Object *child;
585    Elm_Tooltip *tt;
586    Elm_Cursor *cur;
587    Elm_Theme *th2, *thdef;
588
589    API_ENTRY return;
590    thdef = elm_theme_default_get();
591    if (!th) th = thdef;
592    if (!force)
593      {
594         th2 = sd->theme;
595         if (!th2) th2 = thdef;
596         while (th2)
597           {
598              if (th2 == th)
599                {
600                   force = EINA_TRUE;
601                   break;
602                }
603              if (th2 == thdef) break;
604              th2 = th2->ref_theme;
605              if (!th2) th2 = thdef;
606           }
607      }
608    if (!force) return;
609    EINA_LIST_FOREACH(sd->subobjs, l, child)
610      elm_widget_theme_specific(child, th, force);
611    if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
612    if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
613    EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
614    EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
615    if (sd->theme_func) sd->theme_func(obj);
616 }
617
618 /**
619  * @internal
620  *
621  * Set hook to get next object in object focus chain.
622  *
623  * @param obj The widget object.
624  * @param func The hook to be used with this widget.
625  *
626  * @ingroup Widget
627  */
628 EAPI void
629 elm_widget_focus_next_hook_set(Evas_Object *obj,
630                                Eina_Bool  (*func)(const Evas_Object   *obj,
631                                                    Elm_Focus_Direction dir,
632                                                    Evas_Object       **next))
633 {
634    API_ENTRY return;
635    sd->focus_next_func = func;
636 }
637
638 /**
639  * Returns the widget's mirrored mode.
640  *
641  * @param obj The widget.
642  * @return mirrored mode of the object.
643  *
644  **/
645 EAPI Eina_Bool
646 elm_widget_mirrored_get(const Evas_Object *obj)
647 {
648    API_ENTRY return EINA_FALSE;
649    return sd->is_mirrored;
650 }
651
652 /**
653  * Sets the widget's mirrored mode.
654  *
655  * @param obj The widget.
656  * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
657  */
658 EAPI void
659 elm_widget_mirrored_set(Evas_Object *obj,
660                         Eina_Bool    mirrored)
661 {
662    API_ENTRY return;
663    if (sd->is_mirrored != mirrored)
664      {
665         sd->is_mirrored = mirrored;
666         elm_widget_theme(obj);
667      }
668 }
669
670 /**
671  * @internal
672  * Resets the mirrored mode from the system mirror mode for widgets that are in
673  * automatic mirroring mode. This function does not call elm_widget_theme.
674  *
675  * @param obj The widget.
676  * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
677  */
678 void
679 _elm_widget_mirrored_reload(Evas_Object *obj)
680 {
681    API_ENTRY return;
682    Eina_Bool mirrored = elm_mirrored_get();
683    if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
684      {
685         sd->is_mirrored = mirrored;
686      }
687 }
688
689 /**
690  * Returns the widget's mirrored mode setting.
691  *
692  * @param obj The widget.
693  * @return mirrored mode setting of the object.
694  *
695  **/
696 EAPI Eina_Bool
697 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
698 {
699    API_ENTRY return EINA_FALSE;
700    return sd->mirrored_auto_mode;
701 }
702
703 /**
704  * Sets the widget's mirrored mode setting.
705  * When widget in automatic mode, it follows the system mirrored mode set by
706  * elm_mirrored_set().
707  * @param obj The widget.
708  * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
709  */
710 EAPI void
711 elm_widget_mirrored_automatic_set(Evas_Object *obj,
712                                   Eina_Bool    automatic)
713 {
714    API_ENTRY return;
715    if (sd->mirrored_auto_mode != automatic)
716      {
717         sd->mirrored_auto_mode = automatic;
718
719         if (automatic)
720           {
721              elm_widget_mirrored_set(obj, elm_mirrored_get());
722           }
723      }
724 }
725
726 EAPI void
727 elm_widget_on_focus_hook_set(Evas_Object *obj,
728                              void       (*func)(void *data,
729                                                 Evas_Object *obj),
730                              void        *data)
731 {
732    API_ENTRY return;
733    sd->on_focus_func = func;
734    sd->on_focus_data = data;
735 }
736
737 EAPI void
738 elm_widget_on_change_hook_set(Evas_Object *obj,
739                               void       (*func)(void *data,
740                                                  Evas_Object *obj),
741                               void        *data)
742 {
743    API_ENTRY return;
744    sd->on_change_func = func;
745    sd->on_change_data = data;
746 }
747
748 EAPI void
749 elm_widget_on_show_region_hook_set(Evas_Object *obj,
750                                    void       (*func)(void *data,
751                                                       Evas_Object *obj),
752                                    void        *data)
753 {
754    API_ENTRY return;
755    sd->on_show_region_func = func;
756    sd->on_show_region_data = data;
757 }
758
759 /**
760  * @internal
761  *
762  * Set the hook to use to show the focused region.
763  *
764  * Whenever a new widget gets focused or it's needed to show the focused
765  * area of the current one, this hook will be called on objects that may
766  * want to move their children into their visible area.
767  * The area given in the hook function is relative to the @p obj widget.
768  *
769  * @param obj The widget object
770  * @param func The function to call to show the specified area.
771  *
772  * @ingroup Widget
773  */
774 EAPI void
775 elm_widget_focus_region_hook_set(Evas_Object *obj,
776                                  void       (*func)(Evas_Object *obj,
777                                                     Evas_Coord x,
778                                                     Evas_Coord y,
779                                                     Evas_Coord w,
780                                                     Evas_Coord h))
781 {
782    API_ENTRY return;
783    sd->focus_region_func = func;
784 }
785
786 /**
787  * @internal
788  *
789  * Set the hook to retrieve the focused region of a widget.
790  *
791  * This hook will be called by elm_widget_focus_region_get() whenever
792  * it's needed to get the focused area of a widget. The area must be relative
793  * to the widget itself and if no hook is set, it will default to the entire
794  * object.
795  *
796  * @param obj The widget object
797  * @param func The function used to retrieve the focus region.
798  *
799  * @ingroup Widget
800  */
801 EAPI void
802 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
803                                     void       (*func)(const Evas_Object *obj,
804                                                        Evas_Coord *x,
805                                                        Evas_Coord *y,
806                                                        Evas_Coord *w,
807                                                        Evas_Coord *h))
808 {
809    API_ENTRY return;
810    sd->on_focus_region_func = func;
811 }
812
813 EAPI void
814 elm_widget_data_set(Evas_Object *obj,
815                     void        *data)
816 {
817    API_ENTRY return;
818    sd->data = data;
819 }
820
821 EAPI void *
822 elm_widget_data_get(const Evas_Object *obj)
823 {
824    API_ENTRY return NULL;
825    return sd->data;
826 }
827
828 EAPI void
829 elm_widget_sub_object_add(Evas_Object *obj,
830                           Evas_Object *sobj)
831 {
832    API_ENTRY return;
833    double scale, pscale = elm_widget_scale_get(sobj);
834    Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
835    Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
836
837    if (_elm_widget_is(sobj))
838      {
839         Smart_Data *sd2 = evas_object_smart_data_get(sobj);
840         if (sd2)
841           {
842              if (sd2->parent_obj == obj)
843                return;
844              if (sd2->parent_obj)
845                elm_widget_sub_object_del(sd2->parent_obj, sobj);
846              sd2->parent_obj = obj;
847              sd2->top_win_focused = sd->top_win_focused;
848              if (!sd->child_can_focus && (_is_focusable(sobj)))
849                sd->child_can_focus = EINA_TRUE;
850           }
851      }
852    else
853      {
854         void *data = evas_object_data_get(sobj, "elm-parent");
855         if (data)
856           {
857              if (data == obj) return;
858              evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
859                                             _sub_obj_del);
860           }
861      }
862
863    sd->subobjs = eina_list_append(sd->subobjs, sobj);
864    evas_object_data_set(sobj, "elm-parent", obj);
865    evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
866    if (_elm_widget_is(sobj))
867      evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
868    evas_object_smart_callback_call(obj, "sub-object-add", sobj);
869    scale = elm_widget_scale_get(sobj);
870    th = elm_widget_theme_get(sobj);
871    mirrored = elm_widget_mirrored_get(sobj);
872    if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
873    if (elm_widget_focus_get(sobj)) _focus_parents(obj);
874 }
875
876 EAPI void
877 elm_widget_sub_object_del(Evas_Object *obj,
878                           Evas_Object *sobj)
879 {
880    Evas_Object *sobj_parent;
881    API_ENTRY return;
882    if (!sobj) return;
883
884    sobj_parent = evas_object_data_del(sobj, "elm-parent");
885    if (sobj_parent != obj)
886      {
887         static int abort_on_warn = -1;
888         ERR("removing sub object %p from parent %p, "
889             "but elm-parent is different %p!",
890             sobj, obj, sobj_parent);
891         if (EINA_UNLIKELY(abort_on_warn == -1))
892           {
893              if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
894              else abort_on_warn = 0;
895           }
896         if (abort_on_warn == 1) abort();
897      }
898    if (_elm_widget_is(sobj))
899      {
900         Smart_Data *sd2 = evas_object_smart_data_get(sobj);
901         if (sd2)
902           {
903              sd2->parent_obj = NULL;
904              if (sd2->resize_obj == sobj)
905                sd2->resize_obj = NULL;
906              else
907                sd->subobjs = eina_list_remove(sd->subobjs, sobj);
908           }
909         else
910           sd->subobjs = eina_list_remove(sd->subobjs, sobj);
911         if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
912         if ((sd->child_can_focus) && (_is_focusable(sobj)))
913           {
914              Evas_Object *subobj;
915              const Eina_List *l;
916              sd->child_can_focus = EINA_FALSE;
917              EINA_LIST_FOREACH(sd->subobjs, l, subobj)
918                {
919                   if (_is_focusable(subobj))
920                     {
921                        sd->child_can_focus = EINA_TRUE;
922                        break;
923                     }
924                }
925           }
926      }
927    else
928      sd->subobjs = eina_list_remove(sd->subobjs, sobj);
929    evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
930                                        _sub_obj_del, sd);
931    if (_elm_widget_is(sobj))
932      evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
933                                          _sub_obj_hide, sd);
934    evas_object_smart_callback_call(obj, "sub-object-del", sobj);
935 }
936
937 EAPI void
938 elm_widget_resize_object_set(Evas_Object *obj,
939                              Evas_Object *sobj)
940 {
941    API_ENTRY return;
942    // orphan previous resize obj
943    if (sd->resize_obj)
944      {
945         evas_object_clip_unset(sd->resize_obj);
946         evas_object_data_del(sd->resize_obj, "elm-parent");
947         if (_elm_widget_is(sd->resize_obj))
948           {
949              Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
950              if (sd2) sd2->parent_obj = NULL;
951              evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
952                                                  _sub_obj_hide, sd);
953           }
954         evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
955                                             _sub_obj_del, sd);
956         evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
957                                             _sub_obj_mouse_down, sd);
958         evas_object_smart_member_del(sd->resize_obj);
959         if (_elm_widget_is(sd->resize_obj))
960           {
961              if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
962           }
963      }
964    // orphan new resize obj
965    if (sobj)
966      {
967         evas_object_data_del(sobj, "elm-parent");
968         if (_elm_widget_is(sobj))
969           {
970              Smart_Data *sd2 = evas_object_smart_data_get(sobj);
971              if (sd2) sd2->parent_obj = NULL;
972              evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
973                                                  _sub_obj_hide, sd);
974           }
975         evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
976                                             _sub_obj_del, sd);
977         evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
978                                             _sub_obj_mouse_down, sd);
979         evas_object_smart_member_del(sobj);
980         if (_elm_widget_is(sobj))
981           {
982              if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
983           }
984      }
985    // set the resize obj up
986    sd->resize_obj = sobj;
987    if (sd->resize_obj)
988      {
989         if (_elm_widget_is(sd->resize_obj))
990           {
991              Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
992              if (sd2)
993                {
994                   sd2->parent_obj = obj;
995                   sd2->top_win_focused = sd->top_win_focused;
996                }
997              evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
998                                             _sub_obj_hide, sd);
999           }
1000         evas_object_clip_set(sobj, evas_object_clip_get(obj));
1001         evas_object_smart_member_add(sobj, obj);
1002         evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1003                                        _sub_obj_del, sd);
1004         evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
1005                                        _sub_obj_mouse_down, sd);
1006         _smart_reconfigure(sd);
1007         evas_object_data_set(sobj, "elm-parent", obj);
1008         evas_object_smart_callback_call(obj, "sub-object-add", sobj);
1009         if (_elm_widget_is(sobj))
1010           {
1011              if (elm_widget_focus_get(sobj)) _focus_parents(obj);
1012           }
1013      }
1014 }
1015
1016 EAPI void
1017 elm_widget_hover_object_set(Evas_Object *obj,
1018                             Evas_Object *sobj)
1019 {
1020    API_ENTRY return;
1021    if (sd->hover_obj)
1022      {
1023         evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1024                                             _sub_obj_del, sd);
1025      }
1026    sd->hover_obj = sobj;
1027    if (sd->hover_obj)
1028      {
1029         evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1030                                        _sub_obj_del, sd);
1031         _smart_reconfigure(sd);
1032      }
1033 }
1034
1035 EAPI void
1036 elm_widget_can_focus_set(Evas_Object *obj,
1037                          Eina_Bool    can_focus)
1038 {
1039    API_ENTRY return;
1040    sd->can_focus = can_focus;
1041    if (can_focus)
1042      {
1043         evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1044                                        _propagate_event,
1045                                        (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1046         evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1047                                        _propagate_event,
1048                                        (void *)(long)EVAS_CALLBACK_KEY_UP);
1049         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1050                                        _propagate_event,
1051                                        (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1052      }
1053    else
1054      {
1055         evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1056                                        _propagate_event);
1057         evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1058                                        _propagate_event);
1059         evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1060                                        _propagate_event);
1061      }
1062 }
1063
1064 EAPI Eina_Bool
1065 elm_widget_can_focus_get(const Evas_Object *obj)
1066 {
1067    API_ENTRY return EINA_FALSE;
1068    return sd->can_focus;
1069 }
1070
1071 EAPI Eina_Bool
1072 elm_widget_child_can_focus_get(const Evas_Object *obj)
1073 {
1074    API_ENTRY return EINA_FALSE;
1075    return sd->child_can_focus;
1076 }
1077
1078 /**
1079  * @internal
1080  *
1081  * This API makes the widget object and its children to be unfocusable.
1082  *
1083  * This API can be helpful for an object to be deleted.
1084  * When an object will be deleted soon, it and its children may not
1085  * want to get focus (by focus reverting or by other focus controls).
1086  * Then, just use this API before deleting.
1087  *
1088  * @param obj The widget root of sub-tree
1089  * @param tree_unfocusable If true, set the object sub-tree as unfocusable
1090  *
1091  * @ingroup Widget
1092  */
1093 EAPI void
1094 elm_widget_tree_unfocusable_set(Evas_Object *obj,
1095                                 Eina_Bool    tree_unfocusable)
1096 {
1097    API_ENTRY return;
1098
1099    if (sd->tree_unfocusable == tree_unfocusable) return;
1100    sd->tree_unfocusable = !!tree_unfocusable;
1101    elm_widget_focus_tree_unfocusable_handle(obj);
1102 }
1103
1104 /**
1105  * @internal
1106  *
1107  * This returns true, if the object sub-tree is unfocusable.
1108  *
1109  * @param obj The widget root of sub-tree
1110  * @return EINA_TRUE if the object sub-tree is unfocusable
1111  *
1112  * @ingroup Widget
1113  */
1114 EAPI Eina_Bool
1115 elm_widget_tree_unfocusable_get(const Evas_Object *obj)
1116 {
1117    API_ENTRY return EINA_FALSE;
1118    return sd->tree_unfocusable;
1119 }
1120
1121 EAPI void
1122 elm_widget_highlight_ignore_set(Evas_Object *obj,
1123                                 Eina_Bool    ignore)
1124 {
1125    API_ENTRY return;
1126    sd->highlight_ignore = !!ignore;
1127 }
1128
1129 EAPI Eina_Bool
1130 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1131 {
1132    API_ENTRY return EINA_FALSE;
1133    return sd->highlight_ignore;
1134 }
1135
1136 EAPI void
1137 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1138                                   Eina_Bool    highlight)
1139 {
1140    API_ENTRY return;
1141    sd->highlight_in_theme = !!highlight;
1142    /* FIXME: if focused, it should switch from one mode to the other */
1143 }
1144
1145 EAPI Eina_Bool
1146 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1147 {
1148    API_ENTRY return EINA_FALSE;
1149    return sd->highlight_in_theme;
1150 }
1151
1152 EAPI Eina_Bool
1153 elm_widget_focus_get(const Evas_Object *obj)
1154 {
1155    API_ENTRY return EINA_FALSE;
1156    return sd->focused;
1157 }
1158
1159 EAPI Evas_Object *
1160 elm_widget_focused_object_get(const Evas_Object *obj)
1161 {
1162    const Evas_Object *subobj;
1163    const Eina_List *l;
1164    API_ENTRY return NULL;
1165
1166    if (!sd->focused) return NULL;
1167    EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1168      {
1169         Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1170         if (fobj) return fobj;
1171      }
1172    return (Evas_Object *)obj;
1173 }
1174
1175 EAPI Evas_Object *
1176 elm_widget_top_get(const Evas_Object *obj)
1177 {
1178    API_ENTRY return NULL;
1179    if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1180    return (Evas_Object *)obj;
1181 }
1182
1183 EAPI Eina_Bool
1184 elm_widget_is(const Evas_Object *obj)
1185 {
1186    return _elm_widget_is(obj);
1187 }
1188
1189 EAPI Evas_Object *
1190 elm_widget_parent_widget_get(const Evas_Object *obj)
1191 {
1192    Evas_Object *parent;
1193
1194    if (_elm_widget_is(obj))
1195      {
1196         Smart_Data *sd = evas_object_smart_data_get(obj);
1197         if (!sd) return NULL;
1198         parent = sd->parent_obj;
1199      }
1200    else
1201      {
1202         parent = evas_object_data_get(obj, "elm-parent");
1203         if (!parent) parent = evas_object_smart_parent_get(obj);
1204      }
1205
1206    while (parent)
1207      {
1208         Evas_Object *elm_parent;
1209         if (_elm_widget_is(parent)) break;
1210         elm_parent = evas_object_data_get(parent, "elm-parent");
1211         if (elm_parent) parent = elm_parent;
1212         else parent = evas_object_smart_parent_get(parent);
1213      }
1214    return parent;
1215 }
1216
1217 EAPI void
1218 elm_widget_event_callback_add(Evas_Object *obj,
1219                               Elm_Event_Cb func,
1220                               const void  *data)
1221 {
1222    API_ENTRY return;
1223    EINA_SAFETY_ON_NULL_RETURN(func);
1224    Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1225    ecb->func = func;
1226    ecb->data = data;
1227    sd->event_cb = eina_list_append(sd->event_cb, ecb);
1228 }
1229
1230 EAPI void *
1231 elm_widget_event_callback_del(Evas_Object *obj,
1232                               Elm_Event_Cb func,
1233                               const void  *data)
1234 {
1235    API_ENTRY return NULL;
1236    EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1237    Eina_List *l;
1238    Elm_Event_Cb_Data *ecd;
1239    EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1240      if ((ecd->func == func) && (ecd->data == data))
1241        {
1242           free(ecd);
1243           sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1244           return (void *)data;
1245        }
1246    return NULL;
1247 }
1248
1249 EAPI Eina_Bool
1250 elm_widget_event_propagate(Evas_Object       *obj,
1251                            Evas_Callback_Type type,
1252                            void              *event_info,
1253                            Evas_Event_Flags  *event_flags)
1254 {
1255    API_ENTRY return EINA_FALSE; //TODO reduce.
1256    if (!_elm_widget_is(obj)) return EINA_FALSE;
1257    Evas_Object *parent = obj;
1258    Elm_Event_Cb_Data *ecd;
1259    Eina_List *l, *l_prev;
1260
1261    while (parent &&
1262           (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1263      {
1264         sd = evas_object_smart_data_get(parent);
1265         if ((!sd) || (!_elm_widget_is(obj)))
1266           return EINA_FALSE; //Not Elm Widget
1267
1268         if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1269           return EINA_TRUE;
1270
1271         EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1272           {
1273              if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1274                  (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1275                return EINA_TRUE;
1276           }
1277         parent = sd->parent_obj;
1278      }
1279
1280    return EINA_FALSE;
1281 }
1282
1283 /**
1284  * @internal
1285  *
1286  * Set custom focus chain.
1287  *
1288  * This function i set one new and overwrite any previous custom focus chain
1289  * with the list of objects. The previous list will be deleted and this list
1290  * will be managed. After setted, don't modity it.
1291  *
1292  * @note On focus cycle, only will be evaluated children of this container.
1293  *
1294  * @param obj The container widget
1295  * @param objs Chain of objects to pass focus
1296  * @ingroup Widget
1297  */
1298 EAPI void
1299 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1300                                   Eina_List   *objs)
1301 {
1302    API_ENTRY return;
1303    if (!sd->focus_next_func)
1304      return;
1305
1306    elm_widget_focus_custom_chain_unset(obj);
1307
1308    Eina_List *l;
1309    Evas_Object *o;
1310
1311    EINA_LIST_FOREACH(objs, l, o)
1312      {
1313         evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1314                                        _elm_object_focus_chain_del_cb, sd);
1315      }
1316
1317    sd->focus_chain = objs;
1318 }
1319
1320 /**
1321  * @internal
1322  *
1323  * Get custom focus chain
1324  *
1325  * @param obj The container widget
1326  * @ingroup Widget
1327  */
1328 EAPI const Eina_List *
1329 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1330 {
1331    API_ENTRY return NULL;
1332    return (const Eina_List *)sd->focus_chain;
1333 }
1334
1335 /**
1336  * @internal
1337  *
1338  * Unset custom focus chain
1339  *
1340  * @param obj The container widget
1341  * @ingroup Widget
1342  */
1343 EAPI void
1344 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1345 {
1346    API_ENTRY return;
1347    Eina_List *l, *l_next;
1348    Evas_Object *o;
1349
1350    EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1351      {
1352         evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1353                                             _elm_object_focus_chain_del_cb, sd);
1354         sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1355      }
1356 }
1357
1358 /**
1359  * @internal
1360  *
1361  * Append object to custom focus chain.
1362  *
1363  * @note If relative_child equal to NULL or not in custom chain, the object
1364  * will be added in end.
1365  *
1366  * @note On focus cycle, only will be evaluated children of this container.
1367  *
1368  * @param obj The container widget
1369  * @param child The child to be added in custom chain
1370  * @param relative_child The relative object to position the child
1371  * @ingroup Widget
1372  */
1373 EAPI void
1374 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1375                                      Evas_Object *child,
1376                                      Evas_Object *relative_child)
1377 {
1378    API_ENTRY return;
1379    EINA_SAFETY_ON_NULL_RETURN(child);
1380    if (!sd->focus_next_func)
1381      return;
1382
1383    evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1384                                        _elm_object_focus_chain_del_cb, sd);
1385
1386    if (!relative_child)
1387      {
1388         sd->focus_chain = eina_list_append(sd->focus_chain, child);
1389         return;
1390      }
1391
1392    sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1393    return;
1394 }
1395
1396 /**
1397  * @internal
1398  *
1399  * Prepend object to custom focus chain.
1400  *
1401  * @note If relative_child equal to NULL or not in custom chain, the object
1402  * will be added in begin.
1403  *
1404  * @note On focus cycle, only will be evaluated children of this container.
1405  *
1406  * @param obj The container widget
1407  * @param child The child to be added in custom chain
1408  * @param relative_child The relative object to position the child
1409  * @ingroup Widget
1410  */
1411 EAPI void
1412 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1413                                       Evas_Object *child,
1414                                       Evas_Object *relative_child)
1415 {
1416    API_ENTRY return;
1417    EINA_SAFETY_ON_NULL_RETURN(child);
1418    if (!sd->focus_next_func)
1419      return;
1420
1421    evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1422                                        _elm_object_focus_chain_del_cb, sd);
1423
1424    if (!relative_child)
1425      {
1426         sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1427         return;
1428      }
1429
1430    sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1431    return;
1432 }
1433
1434 /**
1435  * @internal
1436  *
1437  * Give focus to next object in object tree.
1438  *
1439  * Give focus to next object in focus chain of one object sub-tree.
1440  * If the last object of chain already have focus, the focus will go to the
1441  * first object of chain.
1442  *
1443  * @param obj The widget root of sub-tree
1444  * @param dir Direction to cycle the focus
1445  *
1446  * @ingroup Widget
1447  */
1448 EAPI void
1449 elm_widget_focus_cycle(Evas_Object        *obj,
1450                        Elm_Focus_Direction dir)
1451 {
1452    Evas_Object *target = NULL;
1453    if (!_elm_widget_is(obj))
1454      return;
1455    elm_widget_focus_next_get(obj, dir, &target);
1456    if (target)
1457      elm_widget_focus_steal(target);
1458 }
1459
1460 /**
1461  * @internal
1462  *
1463  * Give focus to near object in one direction.
1464  *
1465  * Give focus to near object in direction of one object.
1466  * If none focusable object in given direction, the focus will not change.
1467  *
1468  * @param obj The reference widget
1469  * @param x Horizontal component of direction to focus
1470  * @param y Vertical component of direction to focus
1471  *
1472  * @ingroup Widget
1473  */
1474 EAPI void
1475 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1476                               int          x __UNUSED__,
1477                               int          y __UNUSED__)
1478 {
1479    return; /* TODO */
1480 }
1481
1482 /**
1483  * @internal
1484  *
1485  * Get next object in focus chain of object tree.
1486  *
1487  * Get next object in focus chain of one object sub-tree.
1488  * Return the next object by reference. If don't have any candidate to receive
1489  * focus before chain end, the first candidate will be returned.
1490  *
1491  * @param obj The widget root of sub-tree
1492  * @param dir Direction os focus chain
1493  * @param next The next object in focus chain
1494  * @return EINA_TRUE if don't need focus chain restart/loop back
1495  *         to use 'next' obj.
1496  *
1497  * @ingroup Widget
1498  */
1499 EAPI Eina_Bool
1500 elm_widget_focus_next_get(const Evas_Object  *obj,
1501                           Elm_Focus_Direction dir,
1502                           Evas_Object       **next)
1503 {
1504    if (!next)
1505      return EINA_FALSE;
1506    *next = NULL;
1507
1508    API_ENTRY return EINA_FALSE;
1509
1510    /* Ignore if disabled */
1511    if ((!evas_object_visible_get(obj))
1512        || (elm_widget_disabled_get(obj))
1513        || (elm_widget_tree_unfocusable_get(obj)))
1514      return EINA_FALSE;
1515
1516    /* Try use hook */
1517    if (sd->focus_next_func)
1518      return sd->focus_next_func(obj, dir, next);
1519
1520    if (!elm_widget_can_focus_get(obj))
1521      return EINA_FALSE;
1522
1523    /* Return */
1524    *next = (Evas_Object *)obj;
1525    return !elm_widget_focus_get(obj);
1526 }
1527
1528 /**
1529  * @internal
1530  *
1531  * Get next object in focus chain of object tree in list.
1532  *
1533  * Get next object in focus chain of one object sub-tree ordered by one list.
1534  * Return the next object by reference. If don't have any candidate to receive
1535  * focus before list end, the first candidate will be returned.
1536  *
1537  * @param obj The widget root of sub-tree
1538  * @param dir Direction os focus chain
1539  * @param items list with ordered objects
1540  * @param list_data_get function to get the object from one item of list
1541  * @param next The next object in focus chain
1542  * @return EINA_TRUE if don't need focus chain restart/loop back
1543  *         to use 'next' obj.
1544  *
1545  * @ingroup Widget
1546  */
1547 EAPI Eina_Bool
1548 elm_widget_focus_list_next_get(const Evas_Object  *obj,
1549                                const Eina_List    *items,
1550                                void *(*list_data_get)(const Eina_List * list),
1551                                Elm_Focus_Direction dir,
1552                                Evas_Object       **next)
1553 {
1554    Eina_List *(*list_next)(const Eina_List * list);
1555
1556    if (!next)
1557      return EINA_FALSE;
1558    *next = NULL;
1559
1560    if (!_elm_widget_is(obj))
1561      return EINA_FALSE;
1562
1563    if (!items)
1564      return EINA_FALSE;
1565
1566    /* Direction */
1567    if (dir == ELM_FOCUS_PREVIOUS)
1568      {
1569         items = eina_list_last(items);
1570         list_next = eina_list_prev;
1571      }
1572    else if (dir == ELM_FOCUS_NEXT)
1573      list_next = eina_list_next;
1574    else
1575      return EINA_FALSE;
1576
1577    const Eina_List *l = items;
1578
1579    /* Recovery last focused sub item */
1580    if (elm_widget_focus_get(obj))
1581      for (; l; l = list_next(l))
1582        {
1583           Evas_Object *cur = list_data_get(l);
1584           if (elm_widget_focus_get(cur)) break;
1585        }
1586
1587    const Eina_List *start = l;
1588    Evas_Object *to_focus = NULL;
1589
1590    /* Interate sub items */
1591    /* Go to end of list */
1592    for (; l; l = list_next(l))
1593      {
1594         Evas_Object *tmp = NULL;
1595         Evas_Object *cur = list_data_get(l);
1596
1597         if (elm_widget_parent_get(cur) != obj)
1598           continue;
1599
1600         /* Try Focus cycle in subitem */
1601         if (elm_widget_focus_next_get(cur, dir, &tmp))
1602           {
1603              *next = tmp;
1604              return EINA_TRUE;
1605           }
1606         else if ((tmp) && (!to_focus))
1607           to_focus = tmp;
1608      }
1609
1610    l = items;
1611
1612    /* Get First possible */
1613    for (; l != start; l = list_next(l))
1614      {
1615         Evas_Object *tmp = NULL;
1616         Evas_Object *cur = list_data_get(l);
1617
1618         if (elm_widget_parent_get(cur) != obj)
1619           continue;
1620
1621         /* Try Focus cycle in subitem */
1622         elm_widget_focus_next_get(cur, dir, &tmp);
1623         if (tmp)
1624           {
1625              *next = tmp;
1626              return EINA_FALSE;
1627           }
1628      }
1629
1630    *next = to_focus;
1631    return EINA_FALSE;
1632 }
1633
1634 EAPI void
1635 elm_widget_signal_emit(Evas_Object *obj,
1636                        const char  *emission,
1637                        const char  *source)
1638 {
1639    API_ENTRY return;
1640    if (!sd->signal_func) return;
1641    sd->signal_func(obj, emission, source);
1642 }
1643
1644 static void
1645 _edje_signal_callback(void        *data,
1646                       Evas_Object *obj __UNUSED__,
1647                       const char  *emission,
1648                       const char  *source)
1649 {
1650    Edje_Signal_Data *esd = data;
1651    esd->func(esd->data, esd->obj, emission, source);
1652 }
1653
1654 EAPI void
1655 elm_widget_signal_callback_add(Evas_Object   *obj,
1656                                const char    *emission,
1657                                const char    *source,
1658                                Edje_Signal_Cb func,
1659                                void          *data)
1660 {
1661    Edje_Signal_Data *esd;
1662    API_ENTRY return;
1663    if (!sd->callback_add_func) return;
1664    EINA_SAFETY_ON_NULL_RETURN(func);
1665
1666    esd = ELM_NEW(Edje_Signal_Data);
1667    if (!esd) return;
1668
1669    esd->obj = obj;
1670    esd->func = func;
1671    esd->emission = eina_stringshare_add(emission);
1672    esd->source = eina_stringshare_add(source);
1673    esd->data = data;
1674    sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1675    sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1676 }
1677
1678 EAPI void *
1679 elm_widget_signal_callback_del(Evas_Object   *obj,
1680                                const char    *emission,
1681                                const char    *source,
1682                                Edje_Signal_Cb func)
1683 {
1684    Edje_Signal_Data *esd;
1685    Eina_List *l;
1686    void *data = NULL;
1687    API_ENTRY return NULL;
1688    if (!sd->callback_del_func) return NULL;
1689
1690    EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1691      {
1692         if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1693             (!strcmp(esd->source, source)))
1694           {
1695              sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1696              eina_stringshare_del(esd->emission);
1697              eina_stringshare_del(esd->source);
1698              data = esd->data;
1699              free(esd);
1700              break;
1701           }
1702      }
1703    sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1704    return data;
1705 }
1706
1707 EAPI void
1708 elm_widget_focus_set(Evas_Object *obj,
1709                      int          first)
1710 {
1711    API_ENTRY return;
1712    if (!sd->focused)
1713      {
1714         focus_order++;
1715         sd->focus_order = focus_order;
1716         sd->focused = EINA_TRUE;
1717         if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1718      }
1719    if (sd->focus_func)
1720      {
1721         sd->focus_func(obj);
1722         return;
1723      }
1724    else
1725      {
1726         if (first)
1727           {
1728              if ((_is_focusable(sd->resize_obj)) &&
1729                  (!elm_widget_disabled_get(sd->resize_obj)))
1730                {
1731                   elm_widget_focus_set(sd->resize_obj, first);
1732                }
1733              else
1734                {
1735                   const Eina_List *l;
1736                   Evas_Object *child;
1737                   EINA_LIST_FOREACH(sd->subobjs, l, child)
1738                     {
1739                        if ((_is_focusable(child)) &&
1740                            (!elm_widget_disabled_get(child)))
1741                          {
1742                             elm_widget_focus_set(child, first);
1743                             break;
1744                          }
1745                     }
1746                }
1747           }
1748         else
1749           {
1750              const Eina_List *l;
1751              Evas_Object *child;
1752              EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1753                {
1754                   if ((_is_focusable(child)) &&
1755                       (!elm_widget_disabled_get(child)))
1756                     {
1757                        elm_widget_focus_set(child, first);
1758                        break;
1759                     }
1760                }
1761              if (!l)
1762                {
1763                   if ((_is_focusable(sd->resize_obj)) &&
1764                       (!elm_widget_disabled_get(sd->resize_obj)))
1765                     {
1766                        elm_widget_focus_set(sd->resize_obj, first);
1767                     }
1768                }
1769           }
1770      }
1771 }
1772
1773 EAPI Evas_Object *
1774 elm_widget_parent_get(const Evas_Object *obj)
1775 {
1776    API_ENTRY return NULL;
1777    return sd->parent_obj;
1778 }
1779
1780 EAPI void
1781 elm_widget_focused_object_clear(Evas_Object *obj)
1782 {
1783    API_ENTRY return;
1784    if (!sd->focused) return;
1785    if (elm_widget_focus_get(sd->resize_obj))
1786      elm_widget_focused_object_clear(sd->resize_obj);
1787    else
1788      {
1789         const Eina_List *l;
1790         Evas_Object *child;
1791         EINA_LIST_FOREACH(sd->subobjs, l, child)
1792           {
1793              if (elm_widget_focus_get(child))
1794                {
1795                   elm_widget_focused_object_clear(child);
1796                   break;
1797                }
1798           }
1799      }
1800    sd->focused = EINA_FALSE;
1801    if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1802    if (sd->focus_func) sd->focus_func(obj);
1803 }
1804
1805 EAPI void
1806 elm_widget_focus_steal(Evas_Object *obj)
1807 {
1808    Evas_Object *parent, *o;
1809    API_ENTRY return;
1810
1811    if (sd->focused) return;
1812    if (sd->disabled) return;
1813    if (!sd->can_focus) return;
1814    if (sd->tree_unfocusable) return;
1815    parent = obj;
1816    for (;;)
1817      {
1818         o = elm_widget_parent_get(parent);
1819         if (!o) break;
1820         sd = evas_object_smart_data_get(o);
1821         if (sd->disabled || sd->tree_unfocusable) return;
1822         if (sd->focused) break;
1823         parent = o;
1824      }
1825    if (!elm_widget_parent_get(parent))
1826      elm_widget_focused_object_clear(parent);
1827    else
1828      {
1829         parent = elm_widget_parent_get(parent);
1830         sd = evas_object_smart_data_get(parent);
1831         if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1832           elm_widget_focused_object_clear(sd->resize_obj);
1833         else
1834           {
1835              const Eina_List *l;
1836              Evas_Object *child;
1837              EINA_LIST_FOREACH(sd->subobjs, l, child)
1838                {
1839                   if (elm_widget_focus_get(child))
1840                     {
1841                        elm_widget_focused_object_clear(child);
1842                        break;
1843                     }
1844                }
1845           }
1846      }
1847    _parent_focus(obj);
1848    return;
1849 }
1850
1851 EAPI void
1852 elm_widget_focus_restore(Evas_Object *obj)
1853 {
1854    Evas_Object *newest = NULL;
1855    unsigned int newest_focus_order = 0;
1856    API_ENTRY return;
1857
1858    newest = _newest_focus_order_get(obj, &newest_focus_order, EINA_TRUE);
1859    if (newest)
1860      {
1861         elm_object_unfocus(newest);
1862         elm_object_focus(newest);
1863      }
1864 }
1865
1866 void
1867 _elm_widget_top_win_focused_set(Evas_Object *obj, Eina_Bool top_win_focused)
1868 {
1869    const Eina_List *l;
1870    Evas_Object *child;
1871    API_ENTRY return;
1872
1873    if (sd->top_win_focused == top_win_focused) return;
1874    if (sd->resize_obj)
1875      _elm_widget_top_win_focused_set(sd->resize_obj, top_win_focused);
1876    EINA_LIST_FOREACH(sd->subobjs, l, child)
1877      {
1878         _elm_widget_top_win_focused_set(child, top_win_focused);
1879      }
1880    sd->top_win_focused = top_win_focused;
1881 }
1882
1883 Eina_Bool
1884 _elm_widget_top_win_focused_get(const Evas_Object *obj)
1885 {
1886    API_ENTRY return EINA_FALSE;
1887    return sd->top_win_focused;
1888 }
1889
1890 EAPI void
1891 elm_widget_activate(Evas_Object *obj)
1892 {
1893    API_ENTRY return;
1894    elm_widget_change(obj);
1895    if (sd->activate_func) sd->activate_func(obj);
1896 }
1897
1898 EAPI void
1899 elm_widget_change(Evas_Object *obj)
1900 {
1901    API_ENTRY return;
1902    elm_widget_change(elm_widget_parent_get(obj));
1903    if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1904 }
1905
1906 EAPI void
1907 elm_widget_disabled_set(Evas_Object *obj,
1908                         Eina_Bool    disabled)
1909 {
1910    API_ENTRY return;
1911
1912    if (sd->disabled == disabled) return;
1913    sd->disabled = !!disabled;
1914    elm_widget_focus_disabled_handle(obj);
1915    if (sd->disable_func) sd->disable_func(obj);
1916 }
1917
1918 EAPI Eina_Bool
1919 elm_widget_disabled_get(const Evas_Object *obj)
1920 {
1921    API_ENTRY return 0;
1922    return sd->disabled;
1923 }
1924
1925 EAPI void
1926 elm_widget_show_region_set(Evas_Object *obj,
1927                            Evas_Coord   x,
1928                            Evas_Coord   y,
1929                            Evas_Coord   w,
1930                            Evas_Coord   h,
1931                            Eina_Bool    forceshow)
1932 {
1933    Evas_Object *parent_obj, *child_obj;
1934    Evas_Coord px, py, cx, cy;
1935
1936    API_ENTRY return;
1937    if (!forceshow && (x == sd->rx) && (y == sd->ry)
1938             && (w == sd->rw) && (h == sd->rh)) return;
1939    sd->rx = x;
1940    sd->ry = y;
1941    sd->rw = w;
1942    sd->rh = h;
1943    if (sd->on_show_region_func)
1944      sd->on_show_region_func(sd->on_show_region_data, obj);
1945
1946    do
1947      {
1948         parent_obj = sd->parent_obj;
1949         child_obj = sd->obj;
1950         if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1951         sd = evas_object_smart_data_get(parent_obj);
1952         if (!sd) break;
1953
1954         evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1955         evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1956
1957         x += (cx - px);
1958         y += (cy - py);
1959         sd->rx = x;
1960         sd->ry = y;
1961         sd->rw = w;
1962         sd->rh = h;
1963
1964         if (sd->on_show_region_func)
1965           {
1966              sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1967           }
1968      }
1969    while (parent_obj);
1970 }
1971
1972 EAPI void
1973 elm_widget_show_region_get(const Evas_Object *obj,
1974                            Evas_Coord        *x,
1975                            Evas_Coord        *y,
1976                            Evas_Coord        *w,
1977                            Evas_Coord        *h)
1978 {
1979    API_ENTRY return;
1980    if (x) *x = sd->rx;
1981    if (y) *y = sd->ry;
1982    if (w) *w = sd->rw;
1983    if (h) *h = sd->rh;
1984 }
1985
1986 /**
1987  * @internal
1988  *
1989  * Get the focus region of the given widget.
1990  *
1991  * The focus region is the area of a widget that should brought into the
1992  * visible area when the widget is focused. Mostly used to show the part of
1993  * an entry where the cursor is, for example. The area returned is relative
1994  * to the object @p obj.
1995  * If the @p obj doesn't have the proper on_focus_region_hook set, this
1996  * function will return the full size of the object.
1997  *
1998  * @param obj The widget object
1999  * @param x Where to store the x coordinate of the area
2000  * @param y Where to store the y coordinate of the area
2001  * @param w Where to store the width of the area
2002  * @param h Where to store the height of the area
2003  *
2004  * @ingroup Widget
2005  */
2006 EAPI void
2007 elm_widget_focus_region_get(const Evas_Object *obj,
2008                             Evas_Coord        *x,
2009                             Evas_Coord        *y,
2010                             Evas_Coord        *w,
2011                             Evas_Coord        *h)
2012 {
2013    Smart_Data *sd;
2014
2015    if (!obj) return;
2016
2017    sd = evas_object_smart_data_get(obj);
2018    if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
2019      {
2020         evas_object_geometry_get(obj, NULL, NULL, w, h);
2021         if (x) *x = 0;
2022         if (y) *y = 0;
2023         return;
2024      }
2025    sd->on_focus_region_func(obj, x, y, w, h);
2026 }
2027
2028 EAPI void
2029 elm_widget_scroll_hold_push(Evas_Object *obj)
2030 {
2031    API_ENTRY return;
2032    sd->scroll_hold++;
2033    if (sd->scroll_hold == 1)
2034      evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
2035    if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
2036    // FIXME: on delete/reparent hold pop
2037 }
2038
2039 EAPI void
2040 elm_widget_scroll_hold_pop(Evas_Object *obj)
2041 {
2042    API_ENTRY return;
2043    sd->scroll_hold--;
2044    if (sd->scroll_hold < 0) sd->scroll_hold = 0;
2045    if (!sd->scroll_hold)
2046      evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
2047    if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
2048 }
2049
2050 EAPI int
2051 elm_widget_scroll_hold_get(const Evas_Object *obj)
2052 {
2053    API_ENTRY return 0;
2054    return sd->scroll_hold;
2055 }
2056
2057 EAPI void
2058 elm_widget_scroll_freeze_push(Evas_Object *obj)
2059 {
2060    API_ENTRY return;
2061    sd->scroll_freeze++;
2062    if (sd->scroll_freeze == 1)
2063      evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
2064    if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
2065    // FIXME: on delete/reparent freeze pop
2066 }
2067
2068 EAPI void
2069 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2070 {
2071    API_ENTRY return;
2072    sd->scroll_freeze--;
2073    if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2074    if (!sd->scroll_freeze)
2075      evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2076    if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2077 }
2078
2079 EAPI int
2080 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2081 {
2082    API_ENTRY return 0;
2083    return sd->scroll_freeze;
2084 }
2085
2086 EAPI void
2087 elm_widget_scale_set(Evas_Object *obj,
2088                      double       scale)
2089 {
2090    API_ENTRY return;
2091    if (scale <= 0.0) scale = 0.0;
2092    if (sd->scale != scale)
2093      {
2094         sd->scale = scale;
2095         elm_widget_theme(obj);
2096      }
2097 }
2098
2099 EAPI double
2100 elm_widget_scale_get(const Evas_Object *obj)
2101 {
2102    API_ENTRY return 1.0;
2103    // FIXME: save walking up the tree by storing/caching parent scale
2104    if (sd->scale == 0.0)
2105      {
2106         if (sd->parent_obj)
2107           return elm_widget_scale_get(sd->parent_obj);
2108         else
2109           return 1.0;
2110      }
2111    return sd->scale;
2112 }
2113
2114 EAPI void
2115 elm_widget_theme_set(Evas_Object *obj,
2116                      Elm_Theme   *th)
2117 {
2118    API_ENTRY return;
2119    if (sd->theme != th)
2120      {
2121         if (sd->theme) elm_theme_free(sd->theme);
2122         sd->theme = th;
2123         if (th) th->ref++;
2124         elm_widget_theme(obj);
2125      }
2126 }
2127
2128 EAPI void
2129 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2130 {
2131    API_ENTRY return;
2132
2133    if (!sd->on_text_set_func)
2134      return;
2135
2136    sd->on_text_set_func(obj, item, label);
2137 }
2138
2139 EAPI const char *
2140 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2141 {
2142    API_ENTRY return NULL;
2143
2144    if (!sd->on_text_get_func)
2145      return NULL;
2146
2147    return sd->on_text_get_func(obj, item);
2148 }
2149
2150 EAPI Elm_Theme *
2151 elm_widget_theme_get(const Evas_Object *obj)
2152 {
2153    API_ENTRY return NULL;
2154    if (!sd->theme)
2155      {
2156         if (sd->parent_obj)
2157           return elm_widget_theme_get(sd->parent_obj);
2158         else
2159           return NULL;
2160      }
2161    return sd->theme;
2162 }
2163
2164 EAPI void
2165 elm_widget_style_set(Evas_Object *obj,
2166                      const char  *style)
2167 {
2168    API_ENTRY return;
2169
2170    if (eina_stringshare_replace(&sd->style, style))
2171      elm_widget_theme(obj);
2172 }
2173
2174 EAPI const char *
2175 elm_widget_style_get(const Evas_Object *obj)
2176 {
2177    API_ENTRY return NULL;
2178    if (sd->style) return sd->style;
2179    return "default";
2180 }
2181
2182 EAPI void
2183 elm_widget_type_set(Evas_Object *obj,
2184                     const char  *type)
2185 {
2186    API_ENTRY return;
2187    eina_stringshare_replace(&sd->type, type);
2188 }
2189
2190 EAPI const char *
2191 elm_widget_type_get(const Evas_Object *obj)
2192 {
2193    API_ENTRY return NULL;
2194    if (sd->type) return sd->type;
2195    return "";
2196 }
2197
2198 EAPI void
2199 elm_widget_tooltip_add(Evas_Object *obj,
2200                        Elm_Tooltip *tt)
2201 {
2202    API_ENTRY return;
2203    sd->tooltips = eina_list_append(sd->tooltips, tt);
2204 }
2205
2206 EAPI void
2207 elm_widget_tooltip_del(Evas_Object *obj,
2208                        Elm_Tooltip *tt)
2209 {
2210    API_ENTRY return;
2211    sd->tooltips = eina_list_remove(sd->tooltips, tt);
2212 }
2213
2214 EAPI void
2215 elm_widget_cursor_add(Evas_Object *obj,
2216                       Elm_Cursor  *cur)
2217 {
2218    API_ENTRY return;
2219    sd->cursors = eina_list_append(sd->cursors, cur);
2220 }
2221
2222 EAPI void
2223 elm_widget_cursor_del(Evas_Object *obj,
2224                       Elm_Cursor  *cur)
2225 {
2226    API_ENTRY return;
2227    sd->cursors = eina_list_remove(sd->cursors, cur);
2228 }
2229
2230 EAPI void
2231 elm_widget_drag_lock_x_set(Evas_Object *obj,
2232                            Eina_Bool    lock)
2233 {
2234    API_ENTRY return;
2235    if (sd->drag_x_locked == lock) return;
2236    sd->drag_x_locked = lock;
2237    if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2238    else _propagate_x_drag_lock(obj, -1);
2239 }
2240
2241 EAPI void
2242 elm_widget_drag_lock_y_set(Evas_Object *obj,
2243                            Eina_Bool    lock)
2244 {
2245    API_ENTRY return;
2246    if (sd->drag_y_locked == lock) return;
2247    sd->drag_y_locked = lock;
2248    if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2249    else _propagate_y_drag_lock(obj, -1);
2250 }
2251
2252 EAPI Eina_Bool
2253 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2254 {
2255    API_ENTRY return EINA_FALSE;
2256    return sd->drag_x_locked;
2257 }
2258
2259 EAPI Eina_Bool
2260 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2261 {
2262    API_ENTRY return EINA_FALSE;
2263    return sd->drag_y_locked;
2264 }
2265
2266 EAPI int
2267 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2268 {
2269    API_ENTRY return 0;
2270    return sd->child_drag_x_locked;
2271 }
2272
2273 EAPI int
2274 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2275 {
2276    API_ENTRY return 0;
2277    return sd->child_drag_y_locked;
2278 }
2279
2280 EAPI Eina_Bool
2281 elm_widget_theme_object_set(Evas_Object *obj,
2282                             Evas_Object *edj,
2283                             const char  *wname,
2284                             const char  *welement,
2285                             const char  *wstyle)
2286 {
2287    API_ENTRY return EINA_FALSE;
2288    return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2289 }
2290
2291 EAPI Eina_Bool
2292 elm_widget_type_check(const Evas_Object *obj,
2293                       const char        *type)
2294 {
2295    const char *provided, *expected = "(unknown)";
2296    static int abort_on_warn = -1;
2297    provided = elm_widget_type_get(obj);
2298    if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2299    if (type) expected = type;
2300    if ((!provided) || (!provided[0]))
2301      {
2302         provided = evas_object_type_get(obj);
2303         if ((!provided) || (!provided[0]))
2304           provided = "(unknown)";
2305      }
2306    ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2307    if (abort_on_warn == -1)
2308      {
2309         if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2310         else abort_on_warn = 0;
2311      }
2312    if (abort_on_warn == 1) abort();
2313    return EINA_FALSE;
2314 }
2315
2316 /**
2317  * @internal
2318  *
2319  * Split string in words
2320  *
2321  * @param str Source string
2322  * @return List of const words
2323  *
2324  * @see elm_widget_stringlist_free()
2325  * @ingroup Widget
2326  */
2327 EAPI Eina_List *
2328 elm_widget_stringlist_get(const char *str)
2329 {
2330    Eina_List *list = NULL;
2331    const char *s, *b;
2332    if (!str) return NULL;
2333    for (b = s = str; 1; s++)
2334      {
2335         if ((*s == ' ') || (!*s))
2336           {
2337              char *t = malloc(s - b + 1);
2338              if (t)
2339                {
2340                   strncpy(t, b, s - b);
2341                   t[s - b] = 0;
2342                   list = eina_list_append(list, eina_stringshare_add(t));
2343                   free(t);
2344                }
2345              b = s + 1;
2346           }
2347         if (!*s) break;
2348      }
2349    return list;
2350 }
2351
2352 EAPI void
2353 elm_widget_stringlist_free(Eina_List *list)
2354 {
2355    const char *s;
2356    EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2357 }
2358
2359 EAPI void
2360 elm_widget_focus_hide_handle(Evas_Object *obj)
2361 {
2362    _if_focused_revert(obj, EINA_TRUE);
2363 }
2364
2365 EAPI void
2366 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2367 {
2368    Evas_Object *o = obj;
2369    do
2370      {
2371         if (_elm_widget_is(o)) break;
2372         o = evas_object_smart_parent_get(o);
2373      }
2374    while (o);
2375    if (!o) return;
2376    if (!_is_focusable(o)) return;
2377    elm_widget_focus_steal(o);
2378 }
2379
2380 EAPI void
2381 elm_widget_focus_tree_unfocusable_handle(Evas_Object *obj)
2382 {
2383    API_ENTRY return;
2384
2385    if (!elm_widget_parent_get(obj))
2386      elm_widget_focused_object_clear(obj);
2387    else
2388      _if_focused_revert(obj, EINA_TRUE);
2389 }
2390
2391 EAPI void
2392 elm_widget_focus_disabled_handle(Evas_Object *obj)
2393 {
2394    API_ENTRY return;
2395
2396    elm_widget_focus_tree_unfocusable_handle(obj);
2397 }
2398
2399 /**
2400  * @internal
2401  *
2402  * Allocate a new Elm_Widget_Item-derived structure.
2403  *
2404  * The goal of this structure is to provide common ground for actions
2405  * that a widget item have, such as the owner widget, callback to
2406  * notify deletion, data pointer and maybe more.
2407  *
2408  * @param widget the owner widget that holds this item, must be an elm_widget!
2409  * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2410  *        be used to allocate memory.
2411  *
2412  * @return allocated memory that is already zeroed out, or NULL on errors.
2413  *
2414  * @see elm_widget_item_new() convenience macro.
2415  * @see elm_widget_item_del() to release memory.
2416  * @ingroup Widget
2417  */
2418 EAPI Elm_Widget_Item *
2419 _elm_widget_item_new(Evas_Object *widget,
2420                      size_t       alloc_size)
2421 {
2422    if (!_elm_widget_is(widget))
2423      return NULL;
2424
2425    Elm_Widget_Item *item;
2426
2427    EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2428    EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2429
2430    item = calloc(1, alloc_size);
2431    EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2432
2433    EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2434    item->widget = widget;
2435    return item;
2436 }
2437
2438 /**
2439  * @internal
2440  *
2441  * Releases widget item memory, calling back del_cb() if it exists.
2442  *
2443  * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2444  * to memory release. Note that elm_widget_item_pre_notify_del() calls
2445  * this function and then unset it, thus being useful for 2 step
2446  * cleanup whenever the del_cb may use any of the data that must be
2447  * deleted from item.
2448  *
2449  * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2450  * is presented!
2451  *
2452  * @param item a valid #Elm_Widget_Item to be deleted.
2453  * @see elm_widget_item_del() convenience macro.
2454  * @ingroup Widget
2455  */
2456 EAPI void
2457 _elm_widget_item_del(Elm_Widget_Item *item)
2458 {
2459    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2460
2461    if (item->del_cb)
2462      item->del_cb((void *)item->data, item->widget, item);
2463
2464    if (item->view)
2465      evas_object_del(item->view);
2466
2467    EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2468    free(item);
2469 }
2470
2471 /**
2472  * @internal
2473  *
2474  * Notify object will be deleted without actually deleting it.
2475  *
2476  * This function will callback Elm_Widget_Item::del_cb if it is set
2477  * and then unset it so it is not called twice (ie: from
2478  * elm_widget_item_del()).
2479  *
2480  * @param item a valid #Elm_Widget_Item to be notified
2481  * @see elm_widget_item_pre_notify_del() convenience macro.
2482  * @ingroup Widget
2483  */
2484 EAPI void
2485 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2486 {
2487    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2488    if (!item->del_cb) return;
2489    item->del_cb((void *)item->data, item->widget, item);
2490    item->del_cb = NULL;
2491 }
2492
2493 /**
2494  * @internal
2495  *
2496  * Set the function to notify when item is being deleted.
2497  *
2498  * This function will complain if there was a callback set already,
2499  * however it will set the new one.
2500  *
2501  * The callback will be called from elm_widget_item_pre_notify_del()
2502  * or elm_widget_item_del() will be called with:
2503  *   - data: the Elm_Widget_Item::data value.
2504  *   - obj: the Elm_Widget_Item::widget evas object.
2505  *   - event_info: the item being deleted.
2506  *
2507  * @param item a valid #Elm_Widget_Item to be notified
2508  * @see elm_widget_item_del_cb_set() convenience macro.
2509  * @ingroup Widget
2510  */
2511 EAPI void
2512 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2513                             Evas_Smart_Cb    del_cb)
2514 {
2515    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2516
2517    if ((item->del_cb) && (item->del_cb != del_cb))
2518      WRN("You're replacing a previously set del_cb %p of item %p with %p",
2519          item->del_cb, item, del_cb);
2520
2521    item->del_cb = del_cb;
2522 }
2523
2524 /**
2525  * @internal
2526  *
2527  * Set user-data in this item.
2528  *
2529  * User data may be used to identify this item or just store any
2530  * application data. It is automatically given as the first parameter
2531  * of the deletion notify callback.
2532  *
2533  * @param item a valid #Elm_Widget_Item to store data in.
2534  * @param data user data to store.
2535  * @see elm_widget_item_del_cb_set() convenience macro.
2536  * @ingroup Widget
2537  */
2538 EAPI void
2539 _elm_widget_item_data_set(Elm_Widget_Item *item,
2540                           const void      *data)
2541 {
2542    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2543    if ((item->data) && (item->data != data))
2544      DBG("Replacing item %p data %p with %p", item, item->data, data);
2545    item->data = data;
2546 }
2547
2548 /**
2549  * @internal
2550  *
2551  * Retrieves user-data of this item.
2552  *
2553  * @param item a valid #Elm_Widget_Item to get data from.
2554  * @see elm_widget_item_data_set()
2555  * @ingroup Widget
2556  */
2557 EAPI void *
2558 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2559 {
2560    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2561    return (void *)item->data;
2562 }
2563
2564 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2565
2566 struct _Elm_Widget_Item_Tooltip
2567 {
2568    Elm_Widget_Item            *item;
2569    Elm_Tooltip_Item_Content_Cb func;
2570    Evas_Smart_Cb               del_cb;
2571    const void                 *data;
2572 };
2573
2574 static Evas_Object *
2575 _elm_widget_item_tooltip_label_create(void        *data,
2576                                       Evas_Object *obj,
2577                                       void        *item __UNUSED__)
2578 {
2579    Evas_Object *label = elm_label_add(obj);
2580    if (!label)
2581      return NULL;
2582    elm_object_style_set(label, "tooltip");
2583    elm_object_text_set(label, data);
2584    return label;
2585 }
2586
2587 static void
2588 _elm_widget_item_tooltip_label_del_cb(void        *data,
2589                                       Evas_Object *obj __UNUSED__,
2590                                       void        *event_info __UNUSED__)
2591 {
2592    eina_stringshare_del(data);
2593 }
2594
2595 /**
2596  * @internal
2597  *
2598  * Set the text to be shown in the widget item.
2599  *
2600  * @param item Target item
2601  * @param text The text to set in the content
2602  *
2603  * Setup the text as tooltip to object. The item can have only one tooltip,
2604  * so any previous tooltip data is removed.
2605  *
2606  * @ingroup Widget
2607  */
2608 EAPI void
2609 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2610                                   const char      *text)
2611 {
2612    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2613    EINA_SAFETY_ON_NULL_RETURN(text);
2614
2615    text = eina_stringshare_add(text);
2616    _elm_widget_item_tooltip_content_cb_set
2617      (item, _elm_widget_item_tooltip_label_create, text,
2618      _elm_widget_item_tooltip_label_del_cb);
2619 }
2620
2621 static Evas_Object *
2622 _elm_widget_item_tooltip_create(void        *data,
2623                                 Evas_Object *obj)
2624 {
2625    Elm_Widget_Item_Tooltip *wit = data;
2626    return wit->func((void *)wit->data, obj, wit->item);
2627 }
2628
2629 static void
2630 _elm_widget_item_tooltip_del_cb(void        *data,
2631                                 Evas_Object *obj,
2632                                 void        *event_info __UNUSED__)
2633 {
2634    Elm_Widget_Item_Tooltip *wit = data;
2635    if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2636    free(wit);
2637 }
2638
2639 /**
2640  * @internal
2641  *
2642  * Set the content to be shown in the tooltip item
2643  *
2644  * Setup the tooltip to item. The item can have only one tooltip,
2645  * so any previous tooltip data is removed. @p func(with @p data) will
2646  * be called every time that need show the tooltip and it should
2647  * return a valid Evas_Object. This object is then managed fully by
2648  * tooltip system and is deleted when the tooltip is gone.
2649  *
2650  * @param item the widget item being attached a tooltip.
2651  * @param func the function used to create the tooltip contents.
2652  * @param data what to provide to @a func as callback data/context.
2653  * @param del_cb called when data is not needed anymore, either when
2654  *        another callback replaces @func, the tooltip is unset with
2655  *        elm_widget_item_tooltip_unset() or the owner @a item
2656  *        dies. This callback receives as the first parameter the
2657  *        given @a data, and @c event_info is the item.
2658  *
2659  * @ingroup Widget
2660  */
2661 EAPI void
2662 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item            *item,
2663                                         Elm_Tooltip_Item_Content_Cb func,
2664                                         const void                 *data,
2665                                         Evas_Smart_Cb               del_cb)
2666 {
2667    Elm_Widget_Item_Tooltip *wit;
2668
2669    ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2670
2671    if (!func)
2672      {
2673         _elm_widget_item_tooltip_unset(item);
2674         return;
2675      }
2676
2677    wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2678    if (!wit) goto error;
2679    wit->item = item;
2680    wit->func = func;
2681    wit->data = data;
2682    wit->del_cb = del_cb;
2683
2684    elm_object_sub_tooltip_content_cb_set
2685      (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2686      _elm_widget_item_tooltip_del_cb);
2687
2688    return;
2689
2690 error_noitem:
2691    if (del_cb) del_cb((void *)data, NULL, item);
2692    return;
2693 error:
2694    if (del_cb) del_cb((void *)data, item->widget, item);
2695 }
2696
2697 /**
2698  * @internal
2699  *
2700  * Unset tooltip from item
2701  *
2702  * @param item widget item to remove previously set tooltip.
2703  *
2704  * Remove tooltip from item. The callback provided as del_cb to
2705  * elm_widget_item_tooltip_content_cb_set() will be called to notify
2706  * it is not used anymore.
2707  *
2708  * @see elm_widget_item_tooltip_content_cb_set()
2709  *
2710  * @ingroup Widget
2711  */
2712 EAPI void
2713 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2714 {
2715    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2716    elm_object_tooltip_unset(item->view);
2717 }
2718
2719 /**
2720  * @internal
2721  *
2722  * Sets a different style for this item tooltip.
2723  *
2724  * @note before you set a style you should define a tooltip with
2725  *       elm_widget_item_tooltip_content_cb_set() or
2726  *       elm_widget_item_tooltip_text_set()
2727  *
2728  * @param item widget item with tooltip already set.
2729  * @param style the theme style to use (default, transparent, ...)
2730  *
2731  * @ingroup Widget
2732  */
2733 EAPI void
2734 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2735                                    const char      *style)
2736 {
2737    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2738    elm_object_tooltip_style_set(item->view, style);
2739 }
2740
2741 /**
2742  * @internal
2743  *
2744  * Get the style for this item tooltip.
2745  *
2746  * @param item widget item with tooltip already set.
2747  * @return style the theme style in use, defaults to "default". If the
2748  *         object does not have a tooltip set, then NULL is returned.
2749  *
2750  * @ingroup Widget
2751  */
2752 EAPI const char *
2753 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2754 {
2755    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2756    return elm_object_tooltip_style_get(item->view);
2757 }
2758
2759 EAPI void
2760 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2761                             const char      *cursor)
2762 {
2763    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2764    elm_object_sub_cursor_set(item->view, item->widget, cursor);
2765 }
2766
2767 EAPI const char *
2768 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2769 {
2770    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2771    return elm_object_cursor_get(item->view);
2772 }
2773
2774 EAPI void
2775 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2776 {
2777    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2778    elm_object_cursor_unset(item->view);
2779 }
2780
2781 /**
2782  * @internal
2783  *
2784  * Sets a different style for this item cursor.
2785  *
2786  * @note before you set a style you should define a cursor with
2787  *       elm_widget_item_cursor_set()
2788  *
2789  * @param item widget item with cursor already set.
2790  * @param style the theme style to use (default, transparent, ...)
2791  *
2792  * @ingroup Widget
2793  */
2794 EAPI void
2795 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2796                                   const char      *style)
2797 {
2798    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2799    elm_object_cursor_style_set(item->view, style);
2800 }
2801
2802 /**
2803  * @internal
2804  *
2805  * Get the style for this item cursor.
2806  *
2807  * @param item widget item with cursor already set.
2808  * @return style the theme style in use, defaults to "default". If the
2809  *         object does not have a cursor set, then NULL is returned.
2810  *
2811  * @ingroup Widget
2812  */
2813 EAPI const char *
2814 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2815 {
2816    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2817    return elm_object_cursor_style_get(item->view);
2818 }
2819
2820 /**
2821  * @internal
2822  *
2823  * Set if the cursor set should be searched on the theme or should use
2824  * the provided by the engine, only.
2825  *
2826  * @note before you set if should look on theme you should define a cursor
2827  * with elm_object_cursor_set(). By default it will only look for cursors
2828  * provided by the engine.
2829  *
2830  * @param item widget item with cursor already set.
2831  * @param engine_only boolean to define it cursors should be looked only
2832  * between the provided by the engine or searched on widget's theme as well.
2833  *
2834  * @ingroup Widget
2835  */
2836 EAPI void
2837 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2838                                         Eina_Bool        engine_only)
2839 {
2840    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2841    elm_object_cursor_engine_only_set(item->view, engine_only);
2842 }
2843
2844 /**
2845  * @internal
2846  *
2847  * Get the cursor engine only usage for this item cursor.
2848  *
2849  * @param item widget item with cursor already set.
2850  * @return engine_only boolean to define it cursors should be looked only
2851  * between the provided by the engine or searched on widget's theme as well. If
2852  *         the object does not have a cursor set, then EINA_FALSE is returned.
2853  *
2854  * @ingroup Widget
2855  */
2856 EAPI Eina_Bool
2857 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2858 {
2859    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2860    return elm_object_cursor_engine_only_get(item->view);
2861 }
2862
2863 // smart object funcs
2864 static void
2865 _smart_reconfigure(Smart_Data *sd)
2866 {
2867    if (sd->resize_obj)
2868      {
2869         evas_object_move(sd->resize_obj, sd->x, sd->y);
2870         evas_object_resize(sd->resize_obj, sd->w, sd->h);
2871      }
2872    if (sd->hover_obj)
2873      {
2874         evas_object_move(sd->hover_obj, sd->x, sd->y);
2875         evas_object_resize(sd->hover_obj, sd->w, sd->h);
2876      }
2877 }
2878
2879 static void
2880 _smart_add(Evas_Object *obj)
2881 {
2882    Smart_Data *sd;
2883
2884    sd = calloc(1, sizeof(Smart_Data));
2885    if (!sd) return;
2886    sd->obj = obj;
2887    sd->x = sd->y = sd->w = sd->h = 0;
2888    sd->can_focus = 1;
2889    sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2890    evas_object_smart_data_set(obj, sd);
2891 }
2892
2893 static Evas_Object *
2894 _newest_focus_order_get(Evas_Object  *obj,
2895                         unsigned int *newest_focus_order,
2896                         Eina_Bool     can_focus_only)
2897 {
2898    const Eina_List *l;
2899    Evas_Object *child, *ret, *best;
2900
2901    API_ENTRY return NULL;
2902
2903    if (!evas_object_visible_get(obj)
2904        || (elm_widget_disabled_get(obj))
2905        || (elm_widget_tree_unfocusable_get(obj)))
2906      return NULL;
2907
2908    best = NULL;
2909    if (*newest_focus_order < sd->focus_order)
2910      {
2911         *newest_focus_order = sd->focus_order;
2912         best = obj;
2913      }
2914    EINA_LIST_FOREACH(sd->subobjs, l, child)
2915      {
2916         ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2917         if (!ret) continue;
2918         best = ret;
2919      }
2920    if (can_focus_only)
2921      {
2922         if ((!best) || (!elm_widget_can_focus_get(best)))
2923           return NULL;
2924      }
2925    return best;
2926 }
2927
2928 static void
2929 _if_focused_revert(Evas_Object *obj,
2930                    Eina_Bool    can_focus_only)
2931 {
2932    Evas_Object *top;
2933    Evas_Object *newest = NULL;
2934    unsigned int newest_focus_order = 0;
2935
2936    INTERNAL_ENTRY
2937
2938    if (!sd->focused) return;
2939    if (!sd->parent_obj) return;
2940
2941    top = elm_widget_top_get(sd->parent_obj);
2942    if (top)
2943      {
2944         newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2945         if (newest)
2946           {
2947              elm_object_unfocus(newest);
2948              elm_object_focus(newest);
2949           }
2950      }
2951 }
2952
2953 static void
2954 _smart_del(Evas_Object *obj)
2955 {
2956    Evas_Object *sobj;
2957    Edje_Signal_Data *esd;
2958
2959    INTERNAL_ENTRY
2960
2961    if (sd->del_pre_func) sd->del_pre_func(obj);
2962    if (sd->resize_obj)
2963      {
2964         sobj = sd->resize_obj;
2965         sd->resize_obj = NULL;
2966         evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2967         evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2968         evas_object_del(sobj);
2969      }
2970    if (sd->hover_obj)
2971      {
2972         sobj = sd->hover_obj;
2973         sd->hover_obj = NULL;
2974         evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2975         evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2976         evas_object_del(sobj);
2977      }
2978    EINA_LIST_FREE(sd->subobjs, sobj)
2979      {
2980         evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2981         evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2982         evas_object_del(sobj);
2983      }
2984    eina_list_free(sd->tooltips); /* should be empty anyway */
2985    eina_list_free(sd->cursors); /* should be empty anyway */
2986    EINA_LIST_FREE(sd->edje_signals, esd)
2987      {
2988         eina_stringshare_del(esd->emission);
2989         eina_stringshare_del(esd->source);
2990         free(esd);
2991      }
2992    eina_list_free(sd->event_cb); /* should be empty anyway */
2993    if (sd->del_func) sd->del_func(obj);
2994    if (sd->style) eina_stringshare_del(sd->style);
2995    if (sd->type) eina_stringshare_del(sd->type);
2996    if (sd->theme) elm_theme_free(sd->theme);
2997    _if_focused_revert(obj, EINA_TRUE);
2998    free(sd);
2999 }
3000
3001 static void
3002 _smart_move(Evas_Object *obj,
3003             Evas_Coord   x,
3004             Evas_Coord   y)
3005 {
3006    INTERNAL_ENTRY
3007    sd->x = x;
3008    sd->y = y;
3009    _smart_reconfigure(sd);
3010 }
3011
3012 static void
3013 _smart_resize(Evas_Object *obj,
3014               Evas_Coord   w,
3015               Evas_Coord   h)
3016 {
3017    INTERNAL_ENTRY
3018    sd->w = w;
3019    sd->h = h;
3020    _smart_reconfigure(sd);
3021 }
3022
3023 static void
3024 _smart_show(Evas_Object *obj)
3025 {
3026    Eina_List *list;
3027    Evas_Object *o;
3028    INTERNAL_ENTRY
3029    if ((list = evas_object_smart_members_get(obj)))
3030      {
3031         EINA_LIST_FREE(list, o)
3032           {
3033              if (evas_object_data_get(o, "_elm_leaveme")) continue;
3034              evas_object_show(o);
3035           }
3036      }
3037 }
3038
3039 static void
3040 _smart_hide(Evas_Object *obj)
3041 {
3042    Eina_List *list;
3043    Evas_Object *o;
3044    INTERNAL_ENTRY
3045
3046    list = evas_object_smart_members_get(obj);
3047    EINA_LIST_FREE(list, o)
3048      {
3049         if (evas_object_data_get(o, "_elm_leaveme")) continue;
3050         evas_object_hide(o);
3051      }
3052 }
3053
3054 static void
3055 _smart_color_set(Evas_Object *obj,
3056                  int          r,
3057                  int          g,
3058                  int          b,
3059                  int          a)
3060 {
3061    Eina_List *list;
3062    Evas_Object *o;
3063    INTERNAL_ENTRY
3064    if ((list = evas_object_smart_members_get(obj)))
3065      {
3066         EINA_LIST_FREE(list, o)
3067           {
3068              if (evas_object_data_get(o, "_elm_leaveme")) continue;
3069              evas_object_color_set(o, r, g, b, a);
3070           }
3071      }
3072 }
3073
3074 static void
3075 _smart_clip_set(Evas_Object *obj,
3076                 Evas_Object *clip)
3077 {
3078    Eina_List *list;
3079    Evas_Object *o;
3080    INTERNAL_ENTRY
3081    if ((list = evas_object_smart_members_get(obj)))
3082      {
3083         EINA_LIST_FREE(list, o)
3084           {
3085              if (evas_object_data_get(o, "_elm_leaveme")) continue;
3086              evas_object_clip_set(o, clip);
3087           }
3088      }
3089 }
3090
3091 static void
3092 _smart_clip_unset(Evas_Object *obj)
3093 {
3094    Eina_List *list;
3095    Evas_Object *o;
3096    INTERNAL_ENTRY
3097    if ((list = evas_object_smart_members_get(obj)))
3098      {
3099         EINA_LIST_FREE(list, o)
3100           {
3101              if (evas_object_data_get(o, "_elm_leaveme")) continue;
3102              evas_object_clip_unset(o);
3103           }
3104      }
3105 }
3106
3107 static void
3108 _smart_calculate(Evas_Object *obj)
3109 {
3110    INTERNAL_ENTRY
3111    if (sd->changed_func) sd->changed_func(obj);
3112 }
3113
3114 /* never need to touch this */
3115 static void
3116 _smart_init(void)
3117 {
3118    if (_e_smart) return;
3119    {
3120       static const Evas_Smart_Class sc =
3121       {
3122          SMART_NAME,
3123          EVAS_SMART_CLASS_VERSION,
3124          _smart_add,
3125          _smart_del,
3126          _smart_move,
3127          _smart_resize,
3128          _smart_show,
3129          _smart_hide,
3130          _smart_color_set,
3131          _smart_clip_set,
3132          _smart_clip_unset,
3133          _smart_calculate,
3134          NULL,
3135          NULL,
3136          NULL,
3137          NULL,
3138          NULL,
3139          NULL
3140       };
3141       _e_smart = evas_smart_class_new(&sc);
3142    }
3143 }
3144
3145 /* happy debug functions */
3146 #ifdef ELM_DEBUG
3147 static void
3148 _sub_obj_tree_dump(const Evas_Object *obj,
3149                    int                lvl)
3150 {
3151    int i;
3152
3153    for (i = 0; i < lvl * 3; i++)
3154      putchar(' ');
3155
3156    if (_elm_widget_is(obj))
3157      {
3158         Eina_List *l;
3159         INTERNAL_ENTRY
3160         printf("+ %s(%p)\n",
3161                sd->type,
3162                obj);
3163         if (sd->resize_obj)
3164           _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3165         EINA_LIST_FOREACH(sd->subobjs, l, obj)
3166           {
3167              if (obj != sd->resize_obj)
3168                _sub_obj_tree_dump(obj, lvl + 1);
3169           }
3170      }
3171    else
3172      printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3173 }
3174
3175 static void
3176 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3177                        FILE              *output)
3178 {
3179    if (!_elm_widget_is(obj))
3180      return;
3181    INTERNAL_ENTRY
3182
3183    Eina_Bool visible = evas_object_visible_get(obj);
3184    Eina_Bool disabled = elm_widget_disabled_get(obj);
3185    Eina_Bool focused = elm_widget_focus_get(obj);
3186    Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3187
3188    if (sd->parent_obj)
3189      {
3190         fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3191
3192         if (focused)
3193           fprintf(output, ", style=bold");
3194
3195         if (!visible)
3196           fprintf(output, ", color=gray28");
3197
3198         fprintf(output, " ];\n");
3199      }
3200
3201    fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3202                    "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3203            evas_object_name_get(obj), visible, disabled, focused, can_focus,
3204            sd->focus_order);
3205
3206    if (focused)
3207      fprintf(output, ", style=bold");
3208
3209    if (!visible)
3210      fprintf(output, ", fontcolor=gray28");
3211
3212    if ((disabled) || (!visible))
3213      fprintf(output, ", color=gray");
3214
3215    fprintf(output, " ];\n");
3216
3217    Eina_List *l;
3218    Evas_Object *o;
3219    EINA_LIST_FOREACH(sd->subobjs, l, o)
3220      _sub_obj_tree_dot_dump(o, output);
3221 }
3222 #endif
3223
3224 EAPI void
3225 elm_widget_tree_dump(const Evas_Object *top)
3226 {
3227 #ifdef ELM_DEBUG
3228    _sub_obj_tree_dump(top, 0);
3229 #else
3230    return;
3231    (void)top;
3232 #endif
3233 }
3234
3235 EAPI void
3236 elm_widget_tree_dot_dump(const Evas_Object *top,
3237                          FILE              *output)
3238 {
3239 #ifdef ELM_DEBUG
3240    if (!_elm_widget_is(top))
3241      return;
3242    fprintf(output, "graph " " { node [shape=record];\n");
3243    _sub_obj_tree_dot_dump(top, output);
3244    fprintf(output, "}\n");
3245 #else
3246    return;
3247    (void)top;
3248    (void)output;
3249 #endif
3250 }