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