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_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
181 _if_focused_revert(obj, EINA_TRUE);
185 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
187 Evas_Object *o = obj;
190 if (_elm_widget_is(o)) break;
191 o = evas_object_smart_parent_get(o);
195 if (!_is_focusable(o)) return;
196 elm_widget_focus_steal(o);
200 _propagate_x_drag_lock(Evas_Object *obj, int dir)
202 Smart_Data *sd = evas_object_smart_data_get(obj);
205 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
208 sd2->child_drag_x_locked += dir;
209 _propagate_x_drag_lock(sd->parent_obj, dir);
215 _propagate_y_drag_lock(Evas_Object *obj, int dir)
217 Smart_Data *sd = evas_object_smart_data_get(obj);
220 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
223 sd2->child_drag_y_locked += dir;
224 _propagate_y_drag_lock(sd->parent_obj, dir);
230 _propagate_event(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
233 Evas_Callback_Type type = (Evas_Callback_Type)(long) data;
234 Evas_Event_Flags *event_flags = NULL;
238 case EVAS_CALLBACK_KEY_DOWN:
240 Evas_Event_Key_Down *ev = event_info;
241 event_flags = &(ev->event_flags);
244 case EVAS_CALLBACK_KEY_UP:
246 Evas_Event_Key_Up *ev = event_info;
247 event_flags = &(ev->event_flags);
250 case EVAS_CALLBACK_MOUSE_WHEEL:
252 Evas_Event_Mouse_Wheel *ev = event_info;
253 event_flags = &(ev->event_flags);
260 elm_widget_event_propagate(obj, type, event_info, event_flags);
264 _parent_focus(Evas_Object *obj)
268 Evas_Object *o = elm_widget_parent_get(obj);
269 sd->focus_order_on_calc = EINA_TRUE;
271 if (sd->focused) return;
277 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
279 /* we don't want to bump a common widget ancestor's
280 focus_order *twice* while parent focusing */
281 if (!ret || (!i) || (i != focus_order))
285 if (!sd->focus_order_on_calc)
286 return; /* we don't want to override it if by means of any of the
287 callbacks below one gets to calculate our order
291 sd->focus_order = focus_order;
292 sd->focused = EINA_TRUE;
293 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
294 if (sd->focus_func) sd->focus_func(obj);
296 if (sd->can_focus) _elm_widget_focus_region_show(obj);
298 sd->focus_order_on_calc = EINA_FALSE;
302 _elm_object_focus_chain_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
304 Smart_Data *sd = data;
306 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
309 // exposed util funcs to elm
311 _elm_widget_type_clear(void)
315 EINA_LIST_FREE(widtypes, ptr)
317 eina_stringshare_del(*ptr);
323 _elm_widget_focus_region_show(const Evas_Object *obj)
325 Evas_Coord x, y, w, h, ox, oy;
331 o = elm_widget_parent_get(obj);
334 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
335 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
339 sd2 = evas_object_smart_data_get(o);
340 if (sd2->focus_region_func)
342 sd2->focus_region_func(o, x, y, w, h);
343 elm_widget_focus_region_get(o, &x, &y, &w, &h);
347 evas_object_geometry_get(o, &px, &py, NULL, NULL);
353 o = elm_widget_parent_get(o);
358 * @defgroup Widget Widget
361 * Exposed api for making widgets
364 elm_widget_type_register(const char **ptr)
366 widtypes = eina_list_append(widtypes, (void *)ptr);
370 elm_widget_api_check(int ver)
372 if (ver != ELM_INTERNAL_API_VERSION)
374 CRITICAL("Elementary widget api versions do not match");
381 elm_widget_add(Evas *evas)
384 return evas_object_smart_add(evas, _e_smart);
388 elm_widget_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
395 elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
398 sd->del_pre_func = func;
402 elm_widget_focus_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
405 sd->focus_func = func;
409 elm_widget_activate_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
412 sd->activate_func = func;
416 elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
419 sd->disable_func = func;
423 elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
426 sd->theme_func = func;
430 elm_widget_event_hook_set(Evas_Object *obj, Eina_Bool (*func) (Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info))
433 sd->event_func = func;
437 elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
440 sd->changed_func = func;
444 elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
447 sd->signal_func = func;
451 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))
454 sd->callback_add_func = func;
458 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))
461 sd->callback_del_func = func;
465 elm_widget_theme(Evas_Object *obj)
473 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
474 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
475 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
476 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
477 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
478 if (sd->theme_func) sd->theme_func(obj);
482 elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force)
488 Elm_Theme *th2, *thdef;
491 thdef = elm_theme_default_get();
496 if (!th2) th2 = thdef;
504 if (th2 == thdef) break;
505 th2 = th2->ref_theme;
506 if (!th2) th2 = thdef;
510 EINA_LIST_FOREACH(sd->subobjs, l, child)
511 elm_widget_theme_specific(child, th, force);
512 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
513 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
514 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
515 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
516 if (sd->theme_func) sd->theme_func(obj);
522 * Set hook to get next object in object focus chain.
524 * @param obj The widget object.
525 * @param func The hook to be used with this widget.
530 elm_widget_focus_next_hook_set(Evas_Object *obj, Eina_Bool (*func) (const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next))
533 sd->focus_next_func = func;
537 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
540 sd->on_focus_func = func;
541 sd->on_focus_data = data;
545 elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
548 sd->on_change_func = func;
549 sd->on_change_data = data;
553 elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
556 sd->on_show_region_func = func;
557 sd->on_show_region_data = data;
563 * Set the hook to use to show the focused region.
565 * Whenever a new widget gets focused or it's needed to show the focused
566 * area of the current one, this hook will be called on objects that may
567 * want to move their children into their visible area.
568 * The area given in the hook function is relative to the @p obj widget.
570 * @param obj The widget object
571 * @param func The function to call to show the specified area.
576 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))
579 sd->focus_region_func = func;
585 * Set the hook to retrieve the focused region of a widget.
587 * This hook will be called by elm_widget_focus_region_get() whenever
588 * it's needed to get the focused area of a widget. The area must be relative
589 * to the widget itself and if no hook is set, it will default to the entire
592 * @param obj The widget object
593 * @param func The function used to retrieve the focus region.
598 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))
601 sd->on_focus_region_func = func;
605 elm_widget_data_set(Evas_Object *obj, void *data)
612 elm_widget_data_get(const Evas_Object *obj)
614 API_ENTRY return NULL;
619 elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
622 double scale, pscale = elm_widget_scale_get(sobj);
623 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
625 if (_elm_widget_is(sobj))
627 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
630 if (sd2->parent_obj == obj)
633 elm_widget_sub_object_del(sd2->parent_obj, sobj);
634 sd2->parent_obj = obj;
635 if (!sd->child_can_focus && (_is_focusable(sobj)))
636 sd->child_can_focus = EINA_TRUE;
641 void *data = evas_object_data_get(sobj, "elm-parent");
644 if (data == obj) return;
645 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
650 sd->subobjs = eina_list_append(sd->subobjs, sobj);
651 evas_object_data_set(sobj, "elm-parent", obj);
652 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
653 if (_elm_widget_is(sobj))
654 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
655 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
656 scale = elm_widget_scale_get(sobj);
657 th = elm_widget_theme_get(sobj);
658 if ((scale != pscale) || (th != pth)) elm_widget_theme(sobj);
659 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
663 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
665 Evas_Object *sobj_parent;
669 sobj_parent = evas_object_data_del(sobj, "elm-parent");
670 if (sobj_parent != obj)
672 static int abort_on_warn = -1;
673 ERR("removing sub object %p from parent %p, "
674 "but elm-parent is different %p!",
675 sobj, obj, sobj_parent);
676 if (EINA_UNLIKELY(abort_on_warn == -1))
678 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
679 else abort_on_warn = 0;
681 if (abort_on_warn == 1) abort();
683 if (!sd->child_can_focus)
685 if (_is_focusable(sobj)) sd->child_can_focus = 0;
687 if (_elm_widget_is(sobj))
689 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
692 sd2->parent_obj = NULL;
693 if (sd2->resize_obj == sobj)
694 sd2->resize_obj = NULL;
696 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
699 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
700 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
703 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
704 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
706 if (_elm_widget_is(sobj))
707 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
709 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
713 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
716 // orphan previous resize obj
719 evas_object_clip_unset(sd->resize_obj);
720 evas_object_data_del(sd->resize_obj, "elm-parent");
721 if (_elm_widget_is(sd->resize_obj))
723 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
724 if (sd2) sd2->parent_obj = NULL;
725 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
728 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
730 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
731 _sub_obj_mouse_down, sd);
732 evas_object_smart_member_del(sd->resize_obj);
733 if (_elm_widget_is(sd->resize_obj))
735 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
738 // orphan new resize obj
741 evas_object_data_del(sobj, "elm-parent");
742 if (_elm_widget_is(sobj))
744 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
745 if (sd2) sd2->parent_obj = NULL;
746 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
749 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
751 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
752 _sub_obj_mouse_down, sd);
753 evas_object_smart_member_del(sobj);
754 if (_elm_widget_is(sobj))
756 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
759 // set the resize obj up
760 sd->resize_obj = sobj;
763 if (_elm_widget_is(sd->resize_obj))
765 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
766 if (sd2) sd2->parent_obj = obj;
767 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
770 evas_object_clip_set(sobj, evas_object_clip_get(obj));
771 evas_object_smart_member_add(sobj, obj);
772 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
774 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
775 _sub_obj_mouse_down, sd);
776 _smart_reconfigure(sd);
777 evas_object_data_set(sobj, "elm-parent", obj);
778 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
779 if (_elm_widget_is(sobj))
781 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
787 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
792 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
795 sd->hover_obj = sobj;
798 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
800 _smart_reconfigure(sd);
805 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
808 sd->can_focus = can_focus;
811 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
813 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
814 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
816 (void *)(long) EVAS_CALLBACK_KEY_UP);
817 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
819 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
823 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
825 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
827 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
833 elm_widget_can_focus_get(const Evas_Object *obj)
835 API_ENTRY return EINA_FALSE;
836 return sd->can_focus;
840 elm_widget_child_can_focus_get(const Evas_Object *obj)
842 API_ENTRY return EINA_FALSE;
843 return sd->child_can_focus;
847 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
850 sd->highlight_ignore = !!ignore;
854 elm_widget_highlight_ignore_get(const Evas_Object *obj)
856 API_ENTRY return EINA_FALSE;
857 return sd->highlight_ignore;
861 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
864 sd->highlight_in_theme = !!highlight;
865 /* FIXME: if focused, it should switch from one mode to the other */
869 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
871 API_ENTRY return EINA_FALSE;
872 return sd->highlight_in_theme;
876 elm_widget_focus_get(const Evas_Object *obj)
878 API_ENTRY return EINA_FALSE;
883 elm_widget_focused_object_get(const Evas_Object *obj)
885 const Evas_Object *subobj;
887 API_ENTRY return NULL;
889 if (!sd->focused) return NULL;
890 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
892 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
893 if (fobj) return fobj;
895 return (Evas_Object *)obj;
899 elm_widget_top_get(const Evas_Object *obj)
901 API_ENTRY return NULL;
902 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
903 return (Evas_Object *)obj;
907 elm_widget_is(const Evas_Object *obj)
909 return _elm_widget_is(obj);
913 elm_widget_parent_widget_get(const Evas_Object *obj)
917 if (_elm_widget_is(obj))
919 Smart_Data *sd = evas_object_smart_data_get(obj);
920 if (!sd) return NULL;
921 parent = sd->parent_obj;
925 parent = evas_object_data_get(obj, "elm-parent");
926 if (!parent) parent = evas_object_smart_parent_get(obj);
931 Evas_Object *elm_parent;
932 if (_elm_widget_is(parent)) break;
933 elm_parent = evas_object_data_get(parent, "elm-parent");
934 if (elm_parent) parent = elm_parent;
935 else parent = evas_object_smart_parent_get(parent);
941 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
944 EINA_SAFETY_ON_NULL_RETURN(func);
945 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
948 sd->event_cb = eina_list_append(sd->event_cb, ecb);
952 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
954 API_ENTRY return NULL;
955 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
957 Elm_Event_Cb_Data *ecd;
958 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
959 if ((ecd->func == func) && (ecd->data == data))
962 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
969 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
971 API_ENTRY return EINA_FALSE; //TODO reduce.
972 if (!_elm_widget_is(obj)) return EINA_FALSE;
973 Evas_Object *parent = obj;
974 Elm_Event_Cb_Data *ecd;
975 Eina_List *l, *l_prev;
978 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
980 sd = evas_object_smart_data_get(parent);
981 if ((!sd) || (!_elm_widget_is(obj)))
982 return EINA_FALSE; //Not Elm Widget
984 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
987 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
989 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
990 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
993 parent = sd->parent_obj;
1002 * Set custom focus chain.
1004 * This function i set one new and overwrite any previous custom focus chain
1005 * with the list of objects. The previous list will be deleted and this list
1006 * will be managed. After setted, don't modity it.
1008 * @note On focus cycle, only will be evaluated children of this container.
1010 * @param obj The container widget
1011 * @param objs Chain of objects to pass focus
1015 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1018 if (!sd->focus_next_func)
1021 elm_widget_focus_custom_chain_unset(obj);
1026 EINA_LIST_FOREACH(objs, l, o)
1028 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1029 _elm_object_focus_chain_del_cb, sd);
1032 sd->focus_chain = objs;
1038 * Get custom focus chain
1040 * @param obj The container widget
1043 EAPI const Eina_List *
1044 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1046 API_ENTRY return NULL;
1047 return (const Eina_List *) sd->focus_chain;
1053 * Unset custom focus chain
1055 * @param obj The container widget
1059 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1062 Eina_List *l, *l_next;
1065 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1067 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1068 _elm_object_focus_chain_del_cb, sd);
1069 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1076 * Append object to custom focus chain.
1078 * @note If relative_child equal to NULL or not in custom chain, the object
1079 * will be added in end.
1081 * @note On focus cycle, only will be evaluated children of this container.
1083 * @param obj The container widget
1084 * @param child The child to be added in custom chain
1085 * @param relative_child The relative object to position the child
1089 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1092 EINA_SAFETY_ON_NULL_RETURN(child);
1093 if (!sd->focus_next_func)
1096 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1097 _elm_object_focus_chain_del_cb, sd);
1099 if (!relative_child)
1101 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1105 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1112 * Prepend object to custom focus chain.
1114 * @note If relative_child equal to NULL or not in custom chain, the object
1115 * will be added in begin.
1117 * @note On focus cycle, only will be evaluated children of this container.
1119 * @param obj The container widget
1120 * @param child The child to be added in custom chain
1121 * @param relative_child The relative object to position the child
1125 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1128 EINA_SAFETY_ON_NULL_RETURN(child);
1129 if (!sd->focus_next_func)
1132 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1133 _elm_object_focus_chain_del_cb, sd);
1135 if (!relative_child)
1137 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1141 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1148 * Give focus to next object in object tree.
1150 * Give focus to next object in focus chain of one object sub-tree.
1151 * If the last object of chain already have focus, the focus will go to the
1152 * first object of chain.
1154 * @param obj The widget root of sub-tree
1155 * @param dir Direction to cycle the focus
1160 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1162 Evas_Object *target = NULL;
1163 if (!_elm_widget_is(obj))
1165 elm_widget_focus_next_get(obj, dir, &target);
1167 elm_widget_focus_steal(target);
1173 * Give focus to near object in one direction.
1175 * Give focus to near object in direction of one object.
1176 * If none focusable object in given direction, the focus will not change.
1178 * @param obj The reference widget
1179 * @param x Horizontal component of direction to focus
1180 * @param y Vertical component of direction to focus
1185 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1193 * Get next object in focus chain of object tree.
1195 * Get next object in focus chain of one object sub-tree.
1196 * Return the next object by reference. If don't have any candidate to receive
1197 * focus before chain end, the first candidate will be returned.
1199 * @param obj The widget root of sub-tree
1200 * @param dir Direction os focus chain
1201 * @param next The next object in focus chain
1202 * @return EINA_TRUE if don't need focus chain restart/loop back
1203 * to use 'next' obj.
1208 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1214 API_ENTRY return EINA_FALSE;
1216 /* Ignore if disabled */
1217 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1221 if (sd->focus_next_func)
1222 return sd->focus_next_func(obj, dir, next);
1224 if (!elm_widget_can_focus_get(obj))
1228 *next = (Evas_Object *)obj;
1229 return !elm_widget_focus_get(obj);
1236 * Get next object in focus chain of object tree in list.
1238 * Get next object in focus chain of one object sub-tree ordered by one list.
1239 * Return the next object by reference. If don't have any candidate to receive
1240 * focus before list end, the first candidate will be returned.
1242 * @param obj The widget root of sub-tree
1243 * @param dir Direction os focus chain
1244 * @param items list with ordered objects
1245 * @param list_data_get function to get the object from one item of list
1246 * @param next The next object in focus chain
1247 * @return EINA_TRUE if don't need focus chain restart/loop back
1248 * to use 'next' obj.
1253 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)
1255 Eina_List *(*list_next) (const Eina_List *list);
1261 if (!_elm_widget_is(obj))
1268 if (dir == ELM_FOCUS_PREVIOUS)
1270 items = eina_list_last(items);
1271 list_next = eina_list_prev;
1273 else if (dir == ELM_FOCUS_NEXT)
1274 list_next = eina_list_next;
1278 const Eina_List *l = items;
1280 /* Recovery last focused sub item */
1281 if (elm_widget_focus_get(obj))
1282 for (; l; l = list_next(l))
1284 Evas_Object *cur = list_data_get(l);
1285 if (elm_widget_focus_get(cur)) break;
1288 const Eina_List *start = l;
1289 Evas_Object *to_focus = NULL;
1291 /* Interate sub items */
1292 /* Go to end of list */
1293 for (; l; l = list_next(l))
1295 Evas_Object *tmp = NULL;
1296 Evas_Object *cur = list_data_get(l);
1298 if (elm_widget_parent_get(cur) != obj)
1301 /* Try Focus cycle in subitem */
1302 if (elm_widget_focus_next_get(cur, dir, &tmp))
1307 else if ((tmp) && (!to_focus))
1313 /* Get First possible */
1314 for (;l != start; l = list_next(l))
1316 Evas_Object *tmp = NULL;
1317 Evas_Object *cur = list_data_get(l);
1319 if (elm_widget_parent_get(cur) != obj)
1322 /* Try Focus cycle in subitem */
1323 elm_widget_focus_next_get(cur, dir, &tmp);
1336 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1339 if (!sd->signal_func) return;
1340 sd->signal_func(obj, emission, source);
1344 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1346 Edje_Signal_Data *esd = data;
1347 esd->func(esd->data, esd->obj, emission, source);
1351 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)
1353 Edje_Signal_Data *esd;
1355 if (!sd->callback_add_func) return;
1356 EINA_SAFETY_ON_NULL_RETURN(func);
1358 esd = ELM_NEW(Edje_Signal_Data);
1363 esd->emission = eina_stringshare_add(emission);
1364 esd->source = eina_stringshare_add(source);
1366 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1367 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1371 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))
1373 Edje_Signal_Data *esd;
1376 API_ENTRY return NULL;
1377 if (!sd->callback_del_func) return NULL;
1379 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1381 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1382 (!strcmp(esd->source, source)))
1384 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1385 eina_stringshare_del(esd->emission);
1386 eina_stringshare_del(esd->source);
1392 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1397 elm_widget_focus_set(Evas_Object *obj, int first)
1403 sd->focus_order = focus_order;
1404 sd->focused = EINA_TRUE;
1405 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1409 sd->focus_func(obj);
1416 if ((_is_focusable(sd->resize_obj)) &&
1417 (!elm_widget_disabled_get(sd->resize_obj)))
1419 elm_widget_focus_set(sd->resize_obj, first);
1425 EINA_LIST_FOREACH(sd->subobjs, l, child)
1427 if ((_is_focusable(child)) &&
1428 (!elm_widget_disabled_get(child)))
1430 elm_widget_focus_set(child, first);
1440 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1442 if ((_is_focusable(child)) &&
1443 (!elm_widget_disabled_get(child)))
1445 elm_widget_focus_set(child, first);
1451 if ((_is_focusable(sd->resize_obj)) &&
1452 (!elm_widget_disabled_get(sd->resize_obj)))
1454 elm_widget_focus_set(sd->resize_obj, first);
1462 elm_widget_parent_get(const Evas_Object *obj)
1464 API_ENTRY return NULL;
1465 return sd->parent_obj;
1469 elm_widget_focused_object_clear(Evas_Object *obj)
1472 if (!sd->focused) return;
1473 if (elm_widget_focus_get(sd->resize_obj))
1474 elm_widget_focused_object_clear(sd->resize_obj);
1479 EINA_LIST_FOREACH(sd->subobjs, l, child)
1481 if (elm_widget_focus_get(child))
1483 elm_widget_focused_object_clear(child);
1488 sd->focused = EINA_FALSE;
1489 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1490 if (sd->focus_func) sd->focus_func(obj);
1494 elm_widget_focus_steal(Evas_Object *obj)
1496 Evas_Object *parent, *o;
1499 if (sd->focused) return;
1500 if (sd->disabled) return;
1504 o = elm_widget_parent_get(parent);
1506 sd = evas_object_smart_data_get(o);
1507 if (sd->focused) break;
1510 if (!elm_widget_parent_get(parent))
1511 elm_widget_focused_object_clear(parent);
1514 parent = elm_widget_parent_get(parent);
1515 sd = evas_object_smart_data_get(parent);
1516 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1517 elm_widget_focused_object_clear(sd->resize_obj);
1522 EINA_LIST_FOREACH(sd->subobjs, l, child)
1524 if (elm_widget_focus_get(child))
1526 elm_widget_focused_object_clear(child);
1537 elm_widget_activate(Evas_Object *obj)
1540 elm_widget_change(obj);
1541 if (sd->activate_func) sd->activate_func(obj);
1545 elm_widget_change(Evas_Object *obj)
1548 elm_widget_change(elm_widget_parent_get(obj));
1549 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1553 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1557 if (sd->disabled == disabled) return;
1558 sd->disabled = disabled;
1561 Evas_Object *o, *parent;
1566 o = elm_widget_parent_get(parent);
1570 if (elm_widget_focus_get(obj))
1571 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1573 if (sd->disable_func) sd->disable_func(obj);
1577 elm_widget_disabled_get(const Evas_Object *obj)
1580 return sd->disabled;
1584 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1586 Evas_Object *parent_obj, *child_obj;
1587 Evas_Coord px, py, cx, cy;
1590 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1595 if (sd->on_show_region_func)
1596 sd->on_show_region_func(sd->on_show_region_data, obj);
1600 parent_obj = sd->parent_obj;
1601 child_obj = sd->obj;
1602 sd = evas_object_smart_data_get(parent_obj);
1604 if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
1606 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1607 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1616 if (sd->on_show_region_func)
1618 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1625 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1637 * Get the focus region of the given widget.
1639 * The focus region is the area of a widget that should brought into the
1640 * visible area when the widget is focused. Mostly used to show the part of
1641 * an entry where the cursor is, for example. The area returned is relative
1642 * to the object @p obj.
1643 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1644 * function will return the full size of the object.
1646 * @param obj The widget object
1647 * @param x Where to store the x coordinate of the area
1648 * @param y Where to store the y coordinate of the area
1649 * @param w Where to store the width of the area
1650 * @param h Where to store the height of the area
1655 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1661 sd = evas_object_smart_data_get(obj);
1662 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1664 evas_object_geometry_get(obj, NULL, NULL, w, h);
1669 sd->on_focus_region_func(obj, x, y, w, h);
1673 elm_widget_scroll_hold_push(Evas_Object *obj)
1677 if (sd->scroll_hold == 1)
1678 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1679 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1680 // FIXME: on delete/reparent hold pop
1684 elm_widget_scroll_hold_pop(Evas_Object *obj)
1688 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1689 if (!sd->scroll_hold)
1690 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1691 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1695 elm_widget_scroll_hold_get(const Evas_Object *obj)
1698 return sd->scroll_hold;
1702 elm_widget_scroll_freeze_push(Evas_Object *obj)
1705 sd->scroll_freeze++;
1706 if (sd->scroll_freeze == 1)
1707 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1708 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1709 // FIXME: on delete/reparent freeze pop
1713 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1716 sd->scroll_freeze--;
1717 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1718 if (!sd->scroll_freeze)
1719 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1720 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1724 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1727 return sd->scroll_freeze;
1731 elm_widget_scale_set(Evas_Object *obj, double scale)
1734 if (scale <= 0.0) scale = 0.0;
1735 if (sd->scale != scale)
1738 elm_widget_theme(obj);
1743 elm_widget_scale_get(const Evas_Object *obj)
1745 API_ENTRY return 1.0;
1746 // FIXME: save walking up the tree by storing/caching parent scale
1747 if (sd->scale == 0.0)
1750 return elm_widget_scale_get(sd->parent_obj);
1758 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1761 if (sd->theme != th)
1763 if (sd->theme) elm_theme_free(sd->theme);
1766 elm_widget_theme(obj);
1771 elm_widget_theme_get(const Evas_Object *obj)
1773 API_ENTRY return NULL;
1777 return elm_widget_theme_get(sd->parent_obj);
1785 elm_widget_style_set(Evas_Object *obj, const char *style)
1789 if (eina_stringshare_replace(&sd->style, style))
1790 elm_widget_theme(obj);
1794 elm_widget_style_get(const Evas_Object *obj)
1796 API_ENTRY return NULL;
1797 if (sd->style) return sd->style;
1802 elm_widget_type_set(Evas_Object *obj, const char *type)
1805 eina_stringshare_replace(&sd->type, type);
1809 elm_widget_type_get(const Evas_Object *obj)
1811 API_ENTRY return NULL;
1812 if (sd->type) return sd->type;
1817 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1820 sd->tooltips = eina_list_append(sd->tooltips, tt);
1824 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1827 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1831 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1834 sd->cursors = eina_list_append(sd->cursors, cur);
1838 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1841 sd->cursors = eina_list_remove(sd->cursors, cur);
1845 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1848 if (sd->drag_x_locked == lock) return;
1849 sd->drag_x_locked = lock;
1850 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1851 else _propagate_x_drag_lock(obj, -1);
1855 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1858 if (sd->drag_y_locked == lock) return;
1859 sd->drag_y_locked = lock;
1860 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1861 else _propagate_y_drag_lock(obj, -1);
1865 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1867 API_ENTRY return EINA_FALSE;
1868 return sd->drag_x_locked;
1872 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1874 API_ENTRY return EINA_FALSE;
1875 return sd->drag_y_locked;
1879 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1882 return sd->child_drag_x_locked;
1886 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1889 return sd->child_drag_y_locked;
1893 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1895 API_ENTRY return EINA_FALSE;
1896 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1900 elm_widget_type_check(const Evas_Object *obj, const char *type)
1902 const char *provided, *expected = "(unknown)";
1903 static int abort_on_warn = -1;
1904 provided = elm_widget_type_get(obj);
1905 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1906 if (type) expected = type;
1907 if ((!provided) || (!provided[0]))
1909 provided = evas_object_type_get(obj);
1910 if ((!provided) || (!provided[0]))
1911 provided = "(unknown)";
1913 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
1914 if (abort_on_warn == -1)
1916 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1917 else abort_on_warn = 0;
1919 if (abort_on_warn == 1) abort();
1926 * Split string in words
1928 * @param str Source string
1929 * @return List of const words
1931 * @see elm_widget_stringlist_free()
1935 elm_widget_stringlist_get(const char *str)
1937 Eina_List *list = NULL;
1939 if (!str) return NULL;
1940 for (b = s = str; 1; s++)
1942 if ((*s == ' ') || (!*s))
1944 char *t = malloc(s - b + 1);
1947 strncpy(t, b, s - b);
1949 list = eina_list_append(list, eina_stringshare_add(t));
1960 elm_widget_stringlist_free(Eina_List *list)
1963 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
1969 * Allocate a new Elm_Widget_Item-derived structure.
1971 * The goal of this structure is to provide common ground for actions
1972 * that a widget item have, such as the owner widget, callback to
1973 * notify deletion, data pointer and maybe more.
1975 * @param widget the owner widget that holds this item, must be an elm_widget!
1976 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
1977 * be used to allocate memory.
1979 * @return allocated memory that is already zeroed out, or NULL on errors.
1981 * @see elm_widget_item_new() convenience macro.
1982 * @see elm_widget_item_del() to release memory.
1985 EAPI Elm_Widget_Item *
1986 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
1988 if (!_elm_widget_is(widget))
1991 Elm_Widget_Item *item;
1993 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
1994 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
1996 item = calloc(1, alloc_size);
1997 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
1999 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2000 item->widget = widget;
2007 * Releases widget item memory, calling back del_cb() if it exists.
2009 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2010 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2011 * this function and then unset it, thus being useful for 2 step
2012 * cleanup whenever the del_cb may use any of the data that must be
2013 * deleted from item.
2015 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2018 * @param item a valid #Elm_Widget_Item to be deleted.
2019 * @see elm_widget_item_del() convenience macro.
2023 _elm_widget_item_del(Elm_Widget_Item *item)
2025 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2028 item->del_cb((void *)item->data, item->widget, item);
2031 evas_object_del(item->view);
2033 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2040 * Notify object will be deleted without actually deleting it.
2042 * This function will callback Elm_Widget_Item::del_cb if it is set
2043 * and then unset it so it is not called twice (ie: from
2044 * elm_widget_item_del()).
2046 * @param item a valid #Elm_Widget_Item to be notified
2047 * @see elm_widget_item_pre_notify_del() convenience macro.
2051 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2053 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2054 if (!item->del_cb) return;
2055 item->del_cb((void *)item->data, item->widget, item);
2056 item->del_cb = NULL;
2062 * Set the function to notify when item is being deleted.
2064 * This function will complain if there was a callback set already,
2065 * however it will set the new one.
2067 * The callback will be called from elm_widget_item_pre_notify_del()
2068 * or elm_widget_item_del() will be called with:
2069 * - data: the Elm_Widget_Item::data value.
2070 * - obj: the Elm_Widget_Item::widget evas object.
2071 * - event_info: the item being deleted.
2073 * @param item a valid #Elm_Widget_Item to be notified
2074 * @see elm_widget_item_del_cb_set() convenience macro.
2078 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2080 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2082 if ((item->del_cb) && (item->del_cb != del_cb))
2083 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2084 item->del_cb, item, del_cb);
2086 item->del_cb = del_cb;
2092 * Set user-data in this item.
2094 * User data may be used to identify this item or just store any
2095 * application data. It is automatically given as the first parameter
2096 * of the deletion notify callback.
2098 * @param item a valid #Elm_Widget_Item to store data in.
2099 * @param data user data to store.
2100 * @see elm_widget_item_del_cb_set() convenience macro.
2104 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2106 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2107 if ((item->data) && (item->data != data))
2108 DBG("Replacing item %p data %p with %p", item, item->data, data);
2115 * Retrieves user-data of this item.
2117 * @param item a valid #Elm_Widget_Item to get data from.
2118 * @see elm_widget_item_data_set()
2122 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2124 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2125 return (void *)item->data;
2128 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2130 struct _Elm_Widget_Item_Tooltip
2132 Elm_Widget_Item *item;
2133 Elm_Tooltip_Item_Content_Cb func;
2134 Evas_Smart_Cb del_cb;
2138 static Evas_Object *
2139 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2141 Evas_Object *label = elm_label_add(obj);
2144 elm_object_style_set(label, "tooltip");
2145 elm_label_label_set(label, data);
2150 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2152 eina_stringshare_del(data);
2158 * Set the text to be shown in the widget item.
2160 * @param item Target item
2161 * @param text The text to set in the content
2163 * Setup the text as tooltip to object. The item can have only one tooltip,
2164 * so any previous tooltip data is removed.
2169 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2171 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2172 EINA_SAFETY_ON_NULL_RETURN(text);
2174 text = eina_stringshare_add(text);
2175 _elm_widget_item_tooltip_content_cb_set
2176 (item, _elm_widget_item_tooltip_label_create, text,
2177 _elm_widget_item_tooltip_label_del_cb);
2180 static Evas_Object *
2181 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2183 Elm_Widget_Item_Tooltip *wit = data;
2184 return wit->func((void *)wit->data, obj, wit->item);
2188 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2190 Elm_Widget_Item_Tooltip *wit = data;
2191 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2198 * Set the content to be shown in the tooltip item
2200 * Setup the tooltip to item. The item can have only one tooltip,
2201 * so any previous tooltip data is removed. @p func(with @p data) will
2202 * be called every time that need show the tooltip and it should
2203 * return a valid Evas_Object. This object is then managed fully by
2204 * tooltip system and is deleted when the tooltip is gone.
2206 * @param item the widget item being attached a tooltip.
2207 * @param func the function used to create the tooltip contents.
2208 * @param data what to provide to @a func as callback data/context.
2209 * @param del_cb called when data is not needed anymore, either when
2210 * another callback replaces @func, the tooltip is unset with
2211 * elm_widget_item_tooltip_unset() or the owner @a item
2212 * dies. This callback receives as the first parameter the
2213 * given @a data, and @c event_info is the item.
2218 _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)
2220 Elm_Widget_Item_Tooltip *wit;
2222 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2226 _elm_widget_item_tooltip_unset(item);
2230 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2231 if (!wit) goto error;
2235 wit->del_cb = del_cb;
2237 elm_object_sub_tooltip_content_cb_set
2238 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2239 _elm_widget_item_tooltip_del_cb);
2244 if (del_cb) del_cb((void *)data, NULL, item);
2247 if (del_cb) del_cb((void *)data, item->widget, item);
2253 * Unset tooltip from item
2255 * @param item widget item to remove previously set tooltip.
2257 * Remove tooltip from item. The callback provided as del_cb to
2258 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2259 * it is not used anymore.
2261 * @see elm_widget_item_tooltip_content_cb_set()
2266 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2268 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2269 elm_object_tooltip_unset(item->view);
2275 * Sets a different style for this item tooltip.
2277 * @note before you set a style you should define a tooltip with
2278 * elm_widget_item_tooltip_content_cb_set() or
2279 * elm_widget_item_tooltip_text_set()
2281 * @param item widget item with tooltip already set.
2282 * @param style the theme style to use (default, transparent, ...)
2287 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2289 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2290 elm_object_tooltip_style_set(item->view, style);
2296 * Get the style for this item tooltip.
2298 * @param item widget item with tooltip already set.
2299 * @return style the theme style in use, defaults to "default". If the
2300 * object does not have a tooltip set, then NULL is returned.
2305 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2307 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2308 return elm_object_tooltip_style_get(item->view);
2312 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2314 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2315 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2319 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2321 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2322 return elm_object_cursor_get(item->view);
2326 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2328 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2329 elm_object_cursor_unset(item->view);
2335 * Sets a different style for this item cursor.
2337 * @note before you set a style you should define a cursor with
2338 * elm_widget_item_cursor_set()
2340 * @param item widget item with cursor already set.
2341 * @param style the theme style to use (default, transparent, ...)
2346 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2348 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2349 elm_object_cursor_style_set(item->view, style);
2355 * Get the style for this item cursor.
2357 * @param item widget item with cursor already set.
2358 * @return style the theme style in use, defaults to "default". If the
2359 * object does not have a cursor set, then NULL is returned.
2364 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2366 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2367 return elm_object_cursor_style_get(item->view);
2373 * Set if the cursor set should be searched on the theme or should use
2374 * the provided by the engine, only.
2376 * @note before you set if should look on theme you should define a cursor
2377 * with elm_object_cursor_set(). By default it will only look for cursors
2378 * provided by the engine.
2380 * @param item widget item with cursor already set.
2381 * @param engine_only boolean to define it cursors should be looked only
2382 * between the provided by the engine or searched on widget's theme as well.
2387 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2389 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2390 elm_object_cursor_engine_only_set(item->view, engine_only);
2396 * Get the cursor engine only usage for this item cursor.
2398 * @param item widget item with cursor already set.
2399 * @return engine_only boolean to define it cursors should be looked only
2400 * between the provided by the engine or searched on widget's theme as well. If
2401 * the object does not have a cursor set, then EINA_FALSE is returned.
2406 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2408 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2409 return elm_object_cursor_engine_only_get(item->view);
2412 // smart object funcs
2414 _smart_reconfigure(Smart_Data *sd)
2418 evas_object_move(sd->resize_obj, sd->x, sd->y);
2419 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2423 evas_object_move(sd->hover_obj, sd->x, sd->y);
2424 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2429 _smart_add(Evas_Object *obj)
2433 sd = calloc(1, sizeof(Smart_Data));
2436 sd->x = sd->y = sd->w = sd->h = 0;
2438 evas_object_smart_data_set(obj, sd);
2441 static Evas_Object *
2442 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2445 Evas_Object *child, *ret, *best;
2447 API_ENTRY return NULL;
2448 if (!evas_object_visible_get(obj)) return NULL;
2450 if (*newest_focus_order < sd->focus_order)
2452 *newest_focus_order = sd->focus_order;
2455 EINA_LIST_FOREACH(sd->subobjs, l, child)
2457 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2463 if ((!best) || (!elm_widget_can_focus_get(best)))
2470 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2473 Evas_Object *newest = NULL;
2474 unsigned int newest_focus_order = 0;
2478 if (!sd->focused) return;
2479 if (!sd->parent_obj) return;
2481 top = elm_widget_top_get(sd->parent_obj);
2484 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2487 elm_object_unfocus(newest);
2488 elm_object_focus(newest);
2494 _smart_del(Evas_Object *obj)
2497 Edje_Signal_Data *esd;
2501 if (sd->del_pre_func) sd->del_pre_func(obj);
2504 sobj = sd->resize_obj;
2505 sd->resize_obj = NULL;
2506 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2507 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2508 evas_object_del(sobj);
2512 sobj = sd->hover_obj;
2513 sd->hover_obj = NULL;
2514 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2515 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2516 evas_object_del(sobj);
2518 EINA_LIST_FREE(sd->subobjs, sobj)
2520 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2521 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2522 evas_object_del(sobj);
2524 eina_list_free(sd->tooltips); /* should be empty anyway */
2525 eina_list_free(sd->cursors); /* should be empty anyway */
2526 EINA_LIST_FREE(sd->edje_signals, esd)
2528 eina_stringshare_del(esd->emission);
2529 eina_stringshare_del(esd->source);
2532 eina_list_free(sd->event_cb); /* should be empty anyway */
2533 if (sd->del_func) sd->del_func(obj);
2534 if (sd->style) eina_stringshare_del(sd->style);
2535 if (sd->type) eina_stringshare_del(sd->type);
2536 if (sd->theme) elm_theme_free(sd->theme);
2537 _if_focused_revert(obj, EINA_TRUE);
2542 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2547 _smart_reconfigure(sd);
2551 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2556 _smart_reconfigure(sd);
2560 _smart_show(Evas_Object *obj)
2565 if ((list = evas_object_smart_members_get(obj)))
2567 EINA_LIST_FREE(list, o)
2569 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2570 evas_object_show(o);
2576 _smart_hide(Evas_Object *obj)
2581 list = evas_object_smart_members_get(obj);
2582 EINA_LIST_FREE(list, o)
2584 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2585 evas_object_hide(o);
2590 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2595 if ((list = evas_object_smart_members_get(obj)))
2597 EINA_LIST_FREE(list, o)
2599 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2600 evas_object_color_set(o, r, g, b, a);
2606 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2611 if ((list = evas_object_smart_members_get(obj)))
2613 EINA_LIST_FREE(list, o)
2615 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2616 evas_object_clip_set(o, clip);
2622 _smart_clip_unset(Evas_Object *obj)
2627 if ((list = evas_object_smart_members_get(obj)))
2629 EINA_LIST_FREE(list, o)
2631 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2632 evas_object_clip_unset(o);
2638 _smart_calculate(Evas_Object *obj)
2641 if (sd->changed_func) sd->changed_func(obj);
2644 /* never need to touch this */
2648 if (_e_smart) return;
2650 static const Evas_Smart_Class sc =
2653 EVAS_SMART_CLASS_VERSION,
2671 _e_smart = evas_smart_class_new(&sc);
2675 /* happy debug functions */
2678 _sub_obj_tree_dump(const Evas_Object *o, int lvl)
2682 for (i = 0; i < lvl*3; i++)
2685 if (_elm_widget_is(o))
2688 Smart_Data *sd = evas_object_smart_data_get(o);
2689 printf("+ %s(%p)\n", sd->type, o);
2691 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2692 EINA_LIST_FOREACH(sd->subobjs, l, o)
2694 if (o != sd->resize_obj)
2695 _sub_obj_tree_dump(o, lvl + 1);
2699 printf("+ %s(%p)\n", evas_object_type_get(o), o);
2703 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2705 if (!_elm_widget_is(obj))
2708 Smart_Data *sd = evas_object_smart_data_get(obj);
2710 Eina_Bool visible = evas_object_visible_get(obj);
2711 Eina_Bool disabled = elm_widget_disabled_get(obj);
2712 Eina_Bool focused = elm_widget_focus_get(obj);
2713 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2717 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2720 fprintf(output, ", style=bold");
2723 fprintf(output, ", color=gray28");
2725 fprintf(output, " ];\n");
2728 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2729 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2730 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2734 fprintf(output, ", style=bold");
2737 fprintf(output, ", fontcolor=gray28");
2739 if ((disabled) || (!visible))
2740 fprintf(output, ", color=gray");
2743 fprintf(output, " ];\n");
2747 EINA_LIST_FOREACH(sd->subobjs, l, o)
2748 _sub_obj_tree_dot_dump(o, output);
2753 elm_widget_tree_dump(const Evas_Object *top)
2756 _sub_obj_tree_dump(top, 0);
2764 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2767 if (!_elm_widget_is(top))
2769 fprintf(output, "graph "" { node [shape=record];\n");
2770 _sub_obj_tree_dot_dump(top, output);
2771 fprintf(output, "}\n");