1 #include <Elementary.h>
4 static const char SMART_NAME[] = "elm_widget";
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); \
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;
21 Evas_Object *parent_obj;
22 Evas_Coord x, y, w, h;
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,
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,
47 void (*on_focus_func) (void *data, Evas_Object *obj);
49 void (*on_change_func) (void *data, Evas_Object *obj);
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);
56 Evas_Coord rx, ry, rw, rh;
62 unsigned int focus_order;
63 Eina_Bool focus_order_on_calc;
65 int child_drag_x_locked;
66 int child_drag_y_locked;
68 Eina_List *edje_signals;
70 Eina_Bool drag_x_locked : 1;
71 Eina_Bool drag_y_locked : 1;
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;
80 Eina_List *focus_chain;
84 struct _Edje_Signal_Data
93 struct _Elm_Event_Cb_Data {
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);
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);
115 /* local subsystem globals */
116 static Evas_Smart *_e_smart = NULL;
117 static Eina_List *widtypes = NULL;
119 static unsigned int focus_order = 0;
122 static inline Eina_Bool
123 _elm_widget_is(const Evas_Object *obj)
125 const char *type = evas_object_type_get(obj);
126 return type == SMART_NAME;
129 static inline Eina_Bool
130 _is_focusable(Evas_Object *obj)
132 API_ENTRY return EINA_FALSE;
133 return sd->can_focus || (sd->child_can_focus);
137 _unfocus_parents(Evas_Object *obj)
139 for (; obj; obj = elm_widget_parent_get(obj))
141 Smart_Data *sd = evas_object_smart_data_get(obj);
143 if (!sd->focused) return;
149 _focus_parents(Evas_Object *obj)
151 for (; obj; obj = elm_widget_parent_get(obj))
153 Smart_Data *sd = evas_object_smart_data_get(obj);
155 if (sd->focused) return;
161 _sub_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
163 Smart_Data *sd = data;
165 if (_elm_widget_is(obj))
167 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
169 if (obj == sd->resize_obj)
170 sd->resize_obj = NULL;
171 else if (obj == sd->hover_obj)
172 sd->hover_obj = NULL;
174 sd->subobjs = eina_list_remove(sd->subobjs, obj);
175 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
179 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
181 Evas_Object *o = obj;
184 if (_elm_widget_is(o)) break;
185 o = evas_object_smart_parent_get(o);
189 if (!_is_focusable(o)) return;
190 elm_widget_focus_steal(o);
194 _propagate_x_drag_lock(Evas_Object *obj, int dir)
196 Smart_Data *sd = evas_object_smart_data_get(obj);
199 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
202 sd2->child_drag_x_locked += dir;
203 _propagate_x_drag_lock(sd->parent_obj, dir);
209 _propagate_y_drag_lock(Evas_Object *obj, int dir)
211 Smart_Data *sd = evas_object_smart_data_get(obj);
214 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
217 sd2->child_drag_y_locked += dir;
218 _propagate_y_drag_lock(sd->parent_obj, dir);
224 _propagate_event(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
227 Evas_Callback_Type type = (Evas_Callback_Type)(long) data;
228 Evas_Event_Flags *event_flags = NULL;
232 case EVAS_CALLBACK_KEY_DOWN:
234 Evas_Event_Key_Down *ev = event_info;
235 event_flags = &(ev->event_flags);
238 case EVAS_CALLBACK_KEY_UP:
240 Evas_Event_Key_Up *ev = event_info;
241 event_flags = &(ev->event_flags);
244 case EVAS_CALLBACK_MOUSE_WHEEL:
246 Evas_Event_Mouse_Wheel *ev = event_info;
247 event_flags = &(ev->event_flags);
254 elm_widget_event_propagate(obj, type, event_info, event_flags);
258 _parent_focus(Evas_Object *obj)
262 Evas_Object *o = elm_widget_parent_get(obj);
263 sd->focus_order_on_calc = EINA_TRUE;
265 if (sd->focused) return;
271 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
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))
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
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);
290 if (sd->can_focus) _elm_widget_focus_region_show(obj);
292 sd->focus_order_on_calc = EINA_FALSE;
296 _elm_object_focus_chain_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
298 Smart_Data *sd = data;
300 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
303 // exposed util funcs to elm
305 _elm_widget_type_clear(void)
309 EINA_LIST_FREE(widtypes, ptr)
311 eina_stringshare_del(*ptr);
317 _elm_widget_focus_region_show(const Evas_Object *obj)
319 Evas_Coord x, y, w, h, ox, oy;
325 o = elm_widget_parent_get(obj);
328 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
329 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
333 sd2 = evas_object_smart_data_get(o);
334 if (sd2->focus_region_func)
336 sd2->focus_region_func(o, x, y, w, h);
337 elm_widget_focus_region_get(o, &x, &y, &w, &h);
341 evas_object_geometry_get(o, &px, &py, NULL, NULL);
347 o = elm_widget_parent_get(o);
352 * @defgroup Widget Widget
355 * Exposed api for making widgets
358 elm_widget_type_register(const char **ptr)
360 widtypes = eina_list_append(widtypes, (void *)ptr);
364 elm_widget_api_check(int ver)
366 if (ver != ELM_INTERNAL_API_VERSION)
368 CRITICAL("Elementary widget api versions do not match");
375 elm_widget_add(Evas *evas)
378 return evas_object_smart_add(evas, _e_smart);
382 elm_widget_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
389 elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
392 sd->del_pre_func = func;
396 elm_widget_focus_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
399 sd->focus_func = func;
403 elm_widget_activate_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
406 sd->activate_func = func;
410 elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
413 sd->disable_func = func;
417 elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
420 sd->theme_func = func;
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))
427 sd->event_func = func;
431 elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
434 sd->changed_func = func;
438 elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
441 sd->signal_func = func;
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))
448 sd->callback_add_func = func;
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))
455 sd->callback_del_func = func;
459 elm_widget_theme(Evas_Object *obj)
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);
476 elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force)
482 Elm_Theme *th2, *thdef;
485 thdef = elm_theme_default_get();
490 if (!th2) th2 = thdef;
498 if (th2 == thdef) break;
499 th2 = th2->ref_theme;
500 if (!th2) th2 = thdef;
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);
516 * Set hook to get next object in object focus chain.
518 * @param obj The widget object.
519 * @param func The hook to be used with this widget.
524 elm_widget_focus_next_hook_set(Evas_Object *obj, Eina_Bool (*func) (const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next))
527 sd->focus_next_func = func;
531 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
534 sd->on_focus_func = func;
535 sd->on_focus_data = data;
539 elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
542 sd->on_change_func = func;
543 sd->on_change_data = data;
547 elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
550 sd->on_show_region_func = func;
551 sd->on_show_region_data = data;
557 * Set the hook to use to show the focused region.
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.
564 * @param obj The widget object
565 * @param func The function to call to show the specified area.
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))
573 sd->focus_region_func = func;
579 * Set the hook to retrieve the focused region of a widget.
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
586 * @param obj The widget object
587 * @param func The function used to retrieve the focus region.
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))
595 sd->on_focus_region_func = func;
599 elm_widget_data_set(Evas_Object *obj, void *data)
606 elm_widget_data_get(const Evas_Object *obj)
608 API_ENTRY return NULL;
613 elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
616 double scale, pscale = elm_widget_scale_get(sobj);
617 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
619 if (_elm_widget_is(sobj))
621 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
624 if (sd2->parent_obj == obj)
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;
634 void *data = evas_object_data_get(sobj, "elm-parent");
637 if (data == obj) return;
638 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
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);
654 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
656 Evas_Object *sobj_parent;
660 sobj_parent = evas_object_data_del(sobj, "elm-parent");
661 if (sobj_parent != obj)
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))
669 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
670 else abort_on_warn = 0;
672 if (abort_on_warn == 1) abort();
674 if (!sd->child_can_focus)
676 if (_is_focusable(sobj)) sd->child_can_focus = 0;
678 if (_elm_widget_is(sobj))
680 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
683 sd2->parent_obj = NULL;
684 if (sd2->resize_obj == sobj)
685 sd2->resize_obj = NULL;
687 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
690 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
691 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
694 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
695 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
697 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
701 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
704 // orphan previous resize obj
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))
711 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
712 if (sd2) sd2->parent_obj = NULL;
714 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
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))
721 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
724 // orphan new resize obj
727 evas_object_data_del(sobj, "elm-parent");
728 if (_elm_widget_is(sobj))
730 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
731 if (sd2) sd2->parent_obj = NULL;
733 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
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))
740 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
743 // set the resize obj up
744 sd->resize_obj = sobj;
747 if (_elm_widget_is(sd->resize_obj))
749 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
750 if (sd2) sd2->parent_obj = obj;
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,
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))
763 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
769 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
774 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
777 sd->hover_obj = sobj;
780 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
782 _smart_reconfigure(sd);
787 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
790 sd->can_focus = can_focus;
793 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
795 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
796 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
798 (void *)(long) EVAS_CALLBACK_KEY_UP);
799 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
801 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
805 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
807 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
809 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
815 elm_widget_can_focus_get(const Evas_Object *obj)
817 API_ENTRY return EINA_FALSE;
818 return sd->can_focus;
822 elm_widget_child_can_focus_get(const Evas_Object *obj)
824 API_ENTRY return EINA_FALSE;
825 return sd->child_can_focus;
829 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
832 sd->highlight_ignore = !!ignore;
836 elm_widget_highlight_ignore_get(const Evas_Object *obj)
838 API_ENTRY return EINA_FALSE;
839 return sd->highlight_ignore;
843 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
846 sd->highlight_in_theme = !!highlight;
847 /* FIXME: if focused, it should switch from one mode to the other */
851 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
853 API_ENTRY return EINA_FALSE;
854 return sd->highlight_in_theme;
858 elm_widget_focus_get(const Evas_Object *obj)
860 API_ENTRY return EINA_FALSE;
865 elm_widget_focused_object_get(const Evas_Object *obj)
867 const Evas_Object *subobj;
869 API_ENTRY return NULL;
871 if (!sd->focused) return NULL;
872 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
874 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
875 if (fobj) return fobj;
877 return (Evas_Object *)obj;
881 elm_widget_top_get(const Evas_Object *obj)
883 API_ENTRY return NULL;
884 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
885 return (Evas_Object *)obj;
889 elm_widget_is(const Evas_Object *obj)
891 return _elm_widget_is(obj);
895 elm_widget_parent_widget_get(const Evas_Object *obj)
899 if (_elm_widget_is(obj))
901 Smart_Data *sd = evas_object_smart_data_get(obj);
902 if (!sd) return NULL;
903 parent = sd->parent_obj;
907 parent = evas_object_data_get(obj, "elm-parent");
908 if (!parent) parent = evas_object_smart_parent_get(obj);
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);
923 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
926 EINA_SAFETY_ON_NULL_RETURN(func);
927 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
930 sd->event_cb = eina_list_append(sd->event_cb, ecb);
934 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
936 API_ENTRY return NULL;
937 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
939 Elm_Event_Cb_Data *ecd;
940 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
941 if ((ecd->func == func) && (ecd->data == data))
944 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
951 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
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;
960 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
962 sd = evas_object_smart_data_get(parent);
963 if ((!sd) || (!_elm_widget_is(obj)))
964 return EINA_FALSE; //Not Elm Widget
966 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
969 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
971 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
972 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
975 parent = sd->parent_obj;
984 * Set custom focus chain.
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.
990 * @note On focus cycle, only will be evaluated children of this container.
992 * @param obj The container widget
993 * @param objs Chain of objects to pass focus
997 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1000 if (!sd->focus_next_func)
1003 elm_widget_focus_custom_chain_unset(obj);
1008 EINA_LIST_FOREACH(objs, l, o)
1010 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1011 _elm_object_focus_chain_del_cb, sd);
1014 sd->focus_chain = objs;
1020 * Get custom focus chain
1022 * @param obj The container widget
1025 EAPI const Eina_List *
1026 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1028 API_ENTRY return NULL;
1029 return (const Eina_List *) sd->focus_chain;
1035 * Unset custom focus chain
1037 * @param obj The container widget
1041 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1044 Eina_List *l, *l_next;
1047 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
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);
1058 * Append object to custom focus chain.
1060 * @note If relative_child equal to NULL or not in custom chain, the object
1061 * will be added in end.
1063 * @note On focus cycle, only will be evaluated children of this container.
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
1071 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1074 EINA_SAFETY_ON_NULL_RETURN(child);
1075 if (!sd->focus_next_func)
1078 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1079 _elm_object_focus_chain_del_cb, sd);
1081 if (!relative_child)
1083 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1087 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1094 * Prepend object to custom focus chain.
1096 * @note If relative_child equal to NULL or not in custom chain, the object
1097 * will be added in begin.
1099 * @note On focus cycle, only will be evaluated children of this container.
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
1107 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1110 EINA_SAFETY_ON_NULL_RETURN(child);
1111 if (!sd->focus_next_func)
1114 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1115 _elm_object_focus_chain_del_cb, sd);
1117 if (!relative_child)
1119 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1123 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1130 * Give focus to next object in object tree.
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.
1136 * @param obj The widget root of sub-tree
1137 * @param dir Direction to cycle the focus
1142 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1144 Evas_Object *target = NULL;
1145 if (!_elm_widget_is(obj))
1147 elm_widget_focus_next_get(obj, dir, &target);
1149 elm_widget_focus_steal(target);
1155 * Give focus to near object in one direction.
1157 * Give focus to near object in direction of one object.
1158 * If none focusable object in given direction, the focus will not change.
1160 * @param obj The reference widget
1161 * @param x Horizontal component of direction to focus
1162 * @param y Vertical component of direction to focus
1167 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1175 * Get next object in focus chain of object tree.
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.
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.
1190 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1196 API_ENTRY return EINA_FALSE;
1198 /* Ignore if disabled */
1199 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1203 if (sd->focus_next_func)
1204 return sd->focus_next_func(obj, dir, next);
1206 if (!elm_widget_can_focus_get(obj))
1210 *next = (Evas_Object *)obj;
1211 return !elm_widget_focus_get(obj);
1218 * Get next object in focus chain of object tree in list.
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.
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.
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)
1237 Eina_List *(*list_next) (const Eina_List *list);
1243 if (!_elm_widget_is(obj))
1250 if (dir == ELM_FOCUS_PREVIOUS)
1252 items = eina_list_last(items);
1253 list_next = eina_list_prev;
1255 else if (dir == ELM_FOCUS_NEXT)
1256 list_next = eina_list_next;
1260 const Eina_List *l = items;
1262 /* Recovery last focused sub item */
1263 if (elm_widget_focus_get(obj))
1264 for (; l; l = list_next(l))
1266 Evas_Object *cur = list_data_get(l);
1267 if (elm_widget_focus_get(cur)) break;
1270 const Eina_List *start = l;
1271 Evas_Object *to_focus = NULL;
1273 /* Interate sub items */
1274 /* Go to end of list */
1275 for (; l; l = list_next(l))
1277 Evas_Object *tmp = NULL;
1278 Evas_Object *cur = list_data_get(l);
1280 if (elm_widget_parent_get(cur) != obj)
1283 /* Try Focus cycle in subitem */
1284 if (elm_widget_focus_next_get(cur, dir, &tmp))
1289 else if ((tmp) && (!to_focus))
1295 /* Get First possible */
1296 for (;l != start; l = list_next(l))
1298 Evas_Object *tmp = NULL;
1299 Evas_Object *cur = list_data_get(l);
1301 if (elm_widget_parent_get(cur) != obj)
1304 /* Try Focus cycle in subitem */
1305 elm_widget_focus_next_get(cur, dir, &tmp);
1318 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1321 if (!sd->signal_func) return;
1322 sd->signal_func(obj, emission, source);
1326 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1328 Edje_Signal_Data *esd = data;
1329 esd->func(esd->data, esd->obj, emission, source);
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)
1335 Edje_Signal_Data *esd;
1337 if (!sd->callback_add_func) return;
1338 EINA_SAFETY_ON_NULL_RETURN(func);
1340 esd = ELM_NEW(Edje_Signal_Data);
1345 esd->emission = eina_stringshare_add(emission);
1346 esd->source = eina_stringshare_add(source);
1348 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1349 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
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))
1355 Edje_Signal_Data *esd;
1358 API_ENTRY return NULL;
1359 if (!sd->callback_del_func) return NULL;
1361 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1363 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1364 (!strcmp(esd->source, source)))
1366 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1367 eina_stringshare_del(esd->emission);
1368 eina_stringshare_del(esd->source);
1374 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1379 elm_widget_focus_set(Evas_Object *obj, int first)
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);
1391 sd->focus_func(obj);
1398 if ((_is_focusable(sd->resize_obj)) &&
1399 (!elm_widget_disabled_get(sd->resize_obj)))
1401 elm_widget_focus_set(sd->resize_obj, first);
1407 EINA_LIST_FOREACH(sd->subobjs, l, child)
1409 if ((_is_focusable(child)) &&
1410 (!elm_widget_disabled_get(child)))
1412 elm_widget_focus_set(child, first);
1422 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1424 if ((_is_focusable(child)) &&
1425 (!elm_widget_disabled_get(child)))
1427 elm_widget_focus_set(child, first);
1433 if ((_is_focusable(sd->resize_obj)) &&
1434 (!elm_widget_disabled_get(sd->resize_obj)))
1436 elm_widget_focus_set(sd->resize_obj, first);
1444 elm_widget_parent_get(const Evas_Object *obj)
1446 API_ENTRY return NULL;
1447 return sd->parent_obj;
1451 elm_widget_focused_object_clear(Evas_Object *obj)
1454 if (!sd->focused) return;
1455 if (elm_widget_focus_get(sd->resize_obj))
1456 elm_widget_focused_object_clear(sd->resize_obj);
1461 EINA_LIST_FOREACH(sd->subobjs, l, child)
1463 if (elm_widget_focus_get(child))
1465 elm_widget_focused_object_clear(child);
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);
1476 elm_widget_focus_steal(Evas_Object *obj)
1478 Evas_Object *parent, *o;
1481 if (sd->focused) return;
1482 if (sd->disabled) return;
1486 o = elm_widget_parent_get(parent);
1488 sd = evas_object_smart_data_get(o);
1489 if (sd->focused) break;
1492 if (!elm_widget_parent_get(parent))
1493 elm_widget_focused_object_clear(parent);
1496 parent = elm_widget_parent_get(parent);
1497 sd = evas_object_smart_data_get(parent);
1498 if (elm_widget_focus_get(sd->resize_obj))
1500 elm_widget_focused_object_clear(sd->resize_obj);
1506 EINA_LIST_FOREACH(sd->subobjs, l, child)
1508 if (elm_widget_focus_get(child))
1510 elm_widget_focused_object_clear(child);
1521 elm_widget_activate(Evas_Object *obj)
1524 elm_widget_change(obj);
1525 if (sd->activate_func) sd->activate_func(obj);
1529 elm_widget_change(Evas_Object *obj)
1532 elm_widget_change(elm_widget_parent_get(obj));
1533 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1537 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1541 if (sd->disabled == disabled) return;
1542 sd->disabled = disabled;
1545 Evas_Object *o, *parent;
1550 o = elm_widget_parent_get(parent);
1554 if (elm_widget_focus_get(obj))
1555 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1557 if (sd->disable_func) sd->disable_func(obj);
1561 elm_widget_disabled_get(const Evas_Object *obj)
1564 return sd->disabled;
1568 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1570 Evas_Object *parent_obj, *child_obj;
1571 Evas_Coord px, py, cx, cy;
1574 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1579 if (sd->on_show_region_func)
1580 sd->on_show_region_func(sd->on_show_region_data, obj);
1584 parent_obj = sd->parent_obj;
1585 child_obj = sd->obj;
1586 sd = evas_object_smart_data_get(parent_obj);
1588 if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
1590 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1591 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1600 if (sd->on_show_region_func)
1602 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1609 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1621 * Get the focus region of the given widget.
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.
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
1639 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1645 sd = evas_object_smart_data_get(obj);
1646 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1648 evas_object_geometry_get(obj, NULL, NULL, w, h);
1653 sd->on_focus_region_func(obj, x, y, w, h);
1657 elm_widget_scroll_hold_push(Evas_Object *obj)
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
1668 elm_widget_scroll_hold_pop(Evas_Object *obj)
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);
1679 elm_widget_scroll_hold_get(const Evas_Object *obj)
1682 return sd->scroll_hold;
1686 elm_widget_scroll_freeze_push(Evas_Object *obj)
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
1697 elm_widget_scroll_freeze_pop(Evas_Object *obj)
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);
1708 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1711 return sd->scroll_freeze;
1715 elm_widget_scale_set(Evas_Object *obj, double scale)
1718 if (scale <= 0.0) scale = 0.0;
1719 if (sd->scale != scale)
1722 elm_widget_theme(obj);
1727 elm_widget_scale_get(const Evas_Object *obj)
1729 API_ENTRY return 1.0;
1730 // FIXME: save walking up the tree by storing/caching parent scale
1731 if (sd->scale == 0.0)
1734 return elm_widget_scale_get(sd->parent_obj);
1742 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1745 if (sd->theme != th)
1747 if (sd->theme) elm_theme_free(sd->theme);
1750 elm_widget_theme(obj);
1755 elm_widget_theme_get(const Evas_Object *obj)
1757 API_ENTRY return NULL;
1761 return elm_widget_theme_get(sd->parent_obj);
1769 elm_widget_style_set(Evas_Object *obj, const char *style)
1773 if (eina_stringshare_replace(&sd->style, style))
1774 elm_widget_theme(obj);
1778 elm_widget_style_get(const Evas_Object *obj)
1780 API_ENTRY return NULL;
1781 if (sd->style) return sd->style;
1786 elm_widget_type_set(Evas_Object *obj, const char *type)
1789 eina_stringshare_replace(&sd->type, type);
1793 elm_widget_type_get(const Evas_Object *obj)
1795 API_ENTRY return NULL;
1796 if (sd->type) return sd->type;
1801 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1804 sd->tooltips = eina_list_append(sd->tooltips, tt);
1808 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1811 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1815 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1818 sd->cursors = eina_list_append(sd->cursors, cur);
1822 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1825 sd->cursors = eina_list_remove(sd->cursors, cur);
1829 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
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);
1839 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
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);
1849 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1851 API_ENTRY return EINA_FALSE;
1852 return sd->drag_x_locked;
1856 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1858 API_ENTRY return EINA_FALSE;
1859 return sd->drag_y_locked;
1863 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1866 return sd->child_drag_x_locked;
1870 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1873 return sd->child_drag_y_locked;
1877 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1879 API_ENTRY return EINA_FALSE;
1880 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1884 elm_widget_type_check(const Evas_Object *obj, const char *type)
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]))
1893 provided = evas_object_type_get(obj);
1894 if ((!provided) || (!provided[0]))
1895 provided = "(unknown)";
1897 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
1898 if (abort_on_warn == -1)
1900 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1901 else abort_on_warn = 0;
1903 if (abort_on_warn == 1) abort();
1910 * Split string in words
1912 * @param str Source string
1913 * @return List of const words
1915 * @see elm_widget_stringlist_free()
1919 elm_widget_stringlist_get(const char *str)
1921 Eina_List *list = NULL;
1923 if (!str) return NULL;
1924 for (b = s = str; 1; s++)
1926 if ((*s == ' ') || (!*s))
1928 char *t = malloc(s - b + 1);
1931 strncpy(t, b, s - b);
1933 list = eina_list_append(list, eina_stringshare_add(t));
1944 elm_widget_stringlist_free(Eina_List *list)
1947 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
1953 * Allocate a new Elm_Widget_Item-derived structure.
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.
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.
1963 * @return allocated memory that is already zeroed out, or NULL on errors.
1965 * @see elm_widget_item_new() convenience macro.
1966 * @see elm_widget_item_del() to release memory.
1969 EAPI Elm_Widget_Item *
1970 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
1972 if (!_elm_widget_is(widget))
1975 Elm_Widget_Item *item;
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);
1980 item = calloc(1, alloc_size);
1981 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
1983 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
1984 item->widget = widget;
1991 * Releases widget item memory, calling back del_cb() if it exists.
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.
1999 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2002 * @param item a valid #Elm_Widget_Item to be deleted.
2003 * @see elm_widget_item_del() convenience macro.
2007 _elm_widget_item_del(Elm_Widget_Item *item)
2009 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2012 item->del_cb((void *)item->data, item->widget, item);
2015 evas_object_del(item->view);
2017 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2024 * Notify object will be deleted without actually deleting it.
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()).
2030 * @param item a valid #Elm_Widget_Item to be notified
2031 * @see elm_widget_item_pre_notify_del() convenience macro.
2035 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
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;
2046 * Set the function to notify when item is being deleted.
2048 * This function will complain if there was a callback set already,
2049 * however it will set the new one.
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.
2057 * @param item a valid #Elm_Widget_Item to be notified
2058 * @see elm_widget_item_del_cb_set() convenience macro.
2062 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2064 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
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);
2070 item->del_cb = del_cb;
2076 * Set user-data in this item.
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.
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.
2088 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
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);
2099 * Retrieves user-data of this item.
2101 * @param item a valid #Elm_Widget_Item to get data from.
2102 * @see elm_widget_item_data_set()
2106 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2108 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2109 return (void *)item->data;
2112 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2114 struct _Elm_Widget_Item_Tooltip
2116 Elm_Widget_Item *item;
2117 Elm_Tooltip_Item_Content_Cb func;
2118 Evas_Smart_Cb del_cb;
2122 static Evas_Object *
2123 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2125 Evas_Object *label = elm_label_add(obj);
2128 elm_object_style_set(label, "tooltip");
2129 elm_label_label_set(label, data);
2134 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2136 eina_stringshare_del(data);
2142 * Set the text to be shown in the widget item.
2144 * @param item Target item
2145 * @param text The text to set in the content
2147 * Setup the text as tooltip to object. The item can have only one tooltip,
2148 * so any previous tooltip data is removed.
2153 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2155 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2156 EINA_SAFETY_ON_NULL_RETURN(text);
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);
2164 static Evas_Object *
2165 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2167 Elm_Widget_Item_Tooltip *wit = data;
2168 return wit->func((void *)wit->data, obj, wit->item);
2172 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2174 Elm_Widget_Item_Tooltip *wit = data;
2175 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2182 * Set the content to be shown in the tooltip item
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.
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.
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)
2204 Elm_Widget_Item_Tooltip *wit;
2206 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2210 _elm_widget_item_tooltip_unset(item);
2214 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2215 if (!wit) goto error;
2219 wit->del_cb = del_cb;
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);
2228 if (del_cb) del_cb((void *)data, NULL, item);
2231 if (del_cb) del_cb((void *)data, item->widget, item);
2237 * Unset tooltip from item
2239 * @param item widget item to remove previously set tooltip.
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.
2245 * @see elm_widget_item_tooltip_content_cb_set()
2250 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2252 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2253 elm_object_tooltip_unset(item->view);
2259 * Sets a different style for this item tooltip.
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()
2265 * @param item widget item with tooltip already set.
2266 * @param style the theme style to use (default, transparent, ...)
2271 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2273 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2274 elm_object_tooltip_style_set(item->view, style);
2280 * Get the style for this item tooltip.
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.
2289 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2291 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2292 return elm_object_tooltip_style_get(item->view);
2296 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2298 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2299 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2303 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2305 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2306 return elm_object_cursor_get(item->view);
2310 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2312 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2313 elm_object_cursor_unset(item->view);
2319 * Sets a different style for this item cursor.
2321 * @note before you set a style you should define a cursor with
2322 * elm_widget_item_cursor_set()
2324 * @param item widget item with cursor already set.
2325 * @param style the theme style to use (default, transparent, ...)
2330 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2332 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2333 elm_object_cursor_style_set(item->view, style);
2339 * Get the style for this item cursor.
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.
2348 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2350 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2351 return elm_object_cursor_style_get(item->view);
2357 * Set if the cursor set should be searched on the theme or should use
2358 * the provided by the engine, only.
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.
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.
2371 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2373 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2374 elm_object_cursor_engine_only_set(item->view, engine_only);
2380 * Get the cursor engine only usage for this item cursor.
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.
2390 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2392 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2393 return elm_object_cursor_engine_only_get(item->view);
2396 // smart object funcs
2398 _smart_reconfigure(Smart_Data *sd)
2402 evas_object_move(sd->resize_obj, sd->x, sd->y);
2403 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2407 evas_object_move(sd->hover_obj, sd->x, sd->y);
2408 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2413 _smart_add(Evas_Object *obj)
2417 sd = calloc(1, sizeof(Smart_Data));
2420 sd->x = sd->y = sd->w = sd->h = 0;
2422 evas_object_smart_data_set(obj, sd);
2425 static Evas_Object *
2426 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2429 Evas_Object *child, *ret, *best;
2431 API_ENTRY return NULL;
2432 if (!evas_object_visible_get(obj)) return NULL;
2434 if (*newest_focus_order < sd->focus_order)
2436 *newest_focus_order = sd->focus_order;
2439 EINA_LIST_FOREACH(sd->subobjs, l, child)
2441 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2445 if ((can_focus_only) && (!elm_widget_can_focus_get(best))) return NULL;
2450 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2453 Evas_Object *newest = NULL;
2454 unsigned int newest_focus_order = 0;
2458 if (!sd->focused) return;
2459 if (!sd->parent_obj) return;
2461 top = elm_widget_top_get(sd->parent_obj);
2464 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2467 elm_object_unfocus(newest);
2468 elm_object_focus(newest);
2474 _smart_del(Evas_Object *obj)
2477 Edje_Signal_Data *esd;
2481 if (sd->del_pre_func) sd->del_pre_func(obj);
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);
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);
2498 EINA_LIST_FREE(sd->subobjs, sobj)
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);
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)
2508 eina_stringshare_del(esd->emission);
2509 eina_stringshare_del(esd->source);
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);
2522 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2527 _smart_reconfigure(sd);
2531 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2536 _smart_reconfigure(sd);
2540 _smart_show(Evas_Object *obj)
2545 if ((list = evas_object_smart_members_get(obj)))
2547 EINA_LIST_FREE(list, o)
2549 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2550 evas_object_show(o);
2556 _smart_hide(Evas_Object *obj)
2561 list = evas_object_smart_members_get(obj);
2562 EINA_LIST_FREE(list, o)
2564 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2565 evas_object_hide(o);
2567 _if_focused_revert(obj, EINA_TRUE);
2571 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2576 if ((list = evas_object_smart_members_get(obj)))
2578 EINA_LIST_FREE(list, o)
2580 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2581 evas_object_color_set(o, r, g, b, a);
2587 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2592 if ((list = evas_object_smart_members_get(obj)))
2594 EINA_LIST_FREE(list, o)
2596 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2597 evas_object_clip_set(o, clip);
2603 _smart_clip_unset(Evas_Object *obj)
2608 if ((list = evas_object_smart_members_get(obj)))
2610 EINA_LIST_FREE(list, o)
2612 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2613 evas_object_clip_unset(o);
2619 _smart_calculate(Evas_Object *obj)
2622 if (sd->changed_func) sd->changed_func(obj);
2625 /* never need to touch this */
2629 if (_e_smart) return;
2631 static const Evas_Smart_Class sc =
2634 EVAS_SMART_CLASS_VERSION,
2652 _e_smart = evas_smart_class_new(&sc);
2656 /* happy debug functions */
2659 _sub_obj_tree_dump(const Evas_Object *o, int lvl)
2663 for (i = 0; i < lvl*3; i++)
2666 if (_elm_widget_is(o))
2669 Smart_Data *sd = evas_object_smart_data_get(o);
2670 printf("+ %s(%p)\n", sd->type, o);
2672 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2673 EINA_LIST_FOREACH(sd->subobjs, l, o)
2675 if (o != sd->resize_obj)
2676 _sub_obj_tree_dump(o, lvl + 1);
2680 printf("+ %s(%p)\n", evas_object_type_get(o), o);
2684 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2686 if (!_elm_widget_is(obj))
2689 Smart_Data *sd = evas_object_smart_data_get(obj);
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);
2698 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2701 fprintf(output, ", style=bold");
2704 fprintf(output, ", color=gray28");
2706 fprintf(output, " ];\n");
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,
2715 fprintf(output, ", style=bold");
2718 fprintf(output, ", fontcolor=gray28");
2720 if ((disabled) || (!visible))
2721 fprintf(output, ", color=gray");
2724 fprintf(output, " ];\n");
2728 EINA_LIST_FOREACH(sd->subobjs, l, o)
2729 _sub_obj_tree_dot_dump(o, output);
2734 elm_widget_tree_dump(const Evas_Object *top)
2737 _sub_obj_tree_dump(top, 0);
2745 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2748 if (!_elm_widget_is(top))
2750 fprintf(output, "graph "" { node [shape=record];\n");
2751 _sub_obj_tree_dot_dump(top, output);
2752 fprintf(output, "}\n");