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