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 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1603 sd = evas_object_smart_data_get(parent_obj);
1606 if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
1608 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1609 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1618 if (sd->on_show_region_func)
1620 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1627 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1639 * Get the focus region of the given widget.
1641 * The focus region is the area of a widget that should brought into the
1642 * visible area when the widget is focused. Mostly used to show the part of
1643 * an entry where the cursor is, for example. The area returned is relative
1644 * to the object @p obj.
1645 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1646 * function will return the full size of the object.
1648 * @param obj The widget object
1649 * @param x Where to store the x coordinate of the area
1650 * @param y Where to store the y coordinate of the area
1651 * @param w Where to store the width of the area
1652 * @param h Where to store the height of the area
1657 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1663 sd = evas_object_smart_data_get(obj);
1664 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1666 evas_object_geometry_get(obj, NULL, NULL, w, h);
1671 sd->on_focus_region_func(obj, x, y, w, h);
1675 elm_widget_scroll_hold_push(Evas_Object *obj)
1679 if (sd->scroll_hold == 1)
1680 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1681 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1682 // FIXME: on delete/reparent hold pop
1686 elm_widget_scroll_hold_pop(Evas_Object *obj)
1690 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1691 if (!sd->scroll_hold)
1692 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1693 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1697 elm_widget_scroll_hold_get(const Evas_Object *obj)
1700 return sd->scroll_hold;
1704 elm_widget_scroll_freeze_push(Evas_Object *obj)
1707 sd->scroll_freeze++;
1708 if (sd->scroll_freeze == 1)
1709 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1710 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1711 // FIXME: on delete/reparent freeze pop
1715 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1718 sd->scroll_freeze--;
1719 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1720 if (!sd->scroll_freeze)
1721 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1722 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1726 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1729 return sd->scroll_freeze;
1733 elm_widget_scale_set(Evas_Object *obj, double scale)
1736 if (scale <= 0.0) scale = 0.0;
1737 if (sd->scale != scale)
1740 elm_widget_theme(obj);
1745 elm_widget_scale_get(const Evas_Object *obj)
1747 API_ENTRY return 1.0;
1748 // FIXME: save walking up the tree by storing/caching parent scale
1749 if (sd->scale == 0.0)
1752 return elm_widget_scale_get(sd->parent_obj);
1760 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1763 if (sd->theme != th)
1765 if (sd->theme) elm_theme_free(sd->theme);
1768 elm_widget_theme(obj);
1773 elm_widget_theme_get(const Evas_Object *obj)
1775 API_ENTRY return NULL;
1779 return elm_widget_theme_get(sd->parent_obj);
1787 elm_widget_style_set(Evas_Object *obj, const char *style)
1791 if (eina_stringshare_replace(&sd->style, style))
1792 elm_widget_theme(obj);
1796 elm_widget_style_get(const Evas_Object *obj)
1798 API_ENTRY return NULL;
1799 if (sd->style) return sd->style;
1804 elm_widget_type_set(Evas_Object *obj, const char *type)
1807 eina_stringshare_replace(&sd->type, type);
1811 elm_widget_type_get(const Evas_Object *obj)
1813 API_ENTRY return NULL;
1814 if (sd->type) return sd->type;
1819 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1822 sd->tooltips = eina_list_append(sd->tooltips, tt);
1826 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1829 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1833 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1836 sd->cursors = eina_list_append(sd->cursors, cur);
1840 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1843 sd->cursors = eina_list_remove(sd->cursors, cur);
1847 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1850 if (sd->drag_x_locked == lock) return;
1851 sd->drag_x_locked = lock;
1852 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1853 else _propagate_x_drag_lock(obj, -1);
1857 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1860 if (sd->drag_y_locked == lock) return;
1861 sd->drag_y_locked = lock;
1862 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1863 else _propagate_y_drag_lock(obj, -1);
1867 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1869 API_ENTRY return EINA_FALSE;
1870 return sd->drag_x_locked;
1874 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1876 API_ENTRY return EINA_FALSE;
1877 return sd->drag_y_locked;
1881 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1884 return sd->child_drag_x_locked;
1888 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1891 return sd->child_drag_y_locked;
1895 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1897 API_ENTRY return EINA_FALSE;
1898 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1902 elm_widget_type_check(const Evas_Object *obj, const char *type)
1904 const char *provided, *expected = "(unknown)";
1905 static int abort_on_warn = -1;
1906 provided = elm_widget_type_get(obj);
1907 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1908 if (type) expected = type;
1909 if ((!provided) || (!provided[0]))
1911 provided = evas_object_type_get(obj);
1912 if ((!provided) || (!provided[0]))
1913 provided = "(unknown)";
1915 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
1916 if (abort_on_warn == -1)
1918 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1919 else abort_on_warn = 0;
1921 if (abort_on_warn == 1) abort();
1928 * Split string in words
1930 * @param str Source string
1931 * @return List of const words
1933 * @see elm_widget_stringlist_free()
1937 elm_widget_stringlist_get(const char *str)
1939 Eina_List *list = NULL;
1941 if (!str) return NULL;
1942 for (b = s = str; 1; s++)
1944 if ((*s == ' ') || (!*s))
1946 char *t = malloc(s - b + 1);
1949 strncpy(t, b, s - b);
1951 list = eina_list_append(list, eina_stringshare_add(t));
1962 elm_widget_stringlist_free(Eina_List *list)
1965 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
1971 * Allocate a new Elm_Widget_Item-derived structure.
1973 * The goal of this structure is to provide common ground for actions
1974 * that a widget item have, such as the owner widget, callback to
1975 * notify deletion, data pointer and maybe more.
1977 * @param widget the owner widget that holds this item, must be an elm_widget!
1978 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
1979 * be used to allocate memory.
1981 * @return allocated memory that is already zeroed out, or NULL on errors.
1983 * @see elm_widget_item_new() convenience macro.
1984 * @see elm_widget_item_del() to release memory.
1987 EAPI Elm_Widget_Item *
1988 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
1990 if (!_elm_widget_is(widget))
1993 Elm_Widget_Item *item;
1995 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
1996 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
1998 item = calloc(1, alloc_size);
1999 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2001 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2002 item->widget = widget;
2009 * Releases widget item memory, calling back del_cb() if it exists.
2011 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2012 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2013 * this function and then unset it, thus being useful for 2 step
2014 * cleanup whenever the del_cb may use any of the data that must be
2015 * deleted from item.
2017 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2020 * @param item a valid #Elm_Widget_Item to be deleted.
2021 * @see elm_widget_item_del() convenience macro.
2025 _elm_widget_item_del(Elm_Widget_Item *item)
2027 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2030 item->del_cb((void *)item->data, item->widget, item);
2033 evas_object_del(item->view);
2035 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2042 * Notify object will be deleted without actually deleting it.
2044 * This function will callback Elm_Widget_Item::del_cb if it is set
2045 * and then unset it so it is not called twice (ie: from
2046 * elm_widget_item_del()).
2048 * @param item a valid #Elm_Widget_Item to be notified
2049 * @see elm_widget_item_pre_notify_del() convenience macro.
2053 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2055 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2056 if (!item->del_cb) return;
2057 item->del_cb((void *)item->data, item->widget, item);
2058 item->del_cb = NULL;
2064 * Set the function to notify when item is being deleted.
2066 * This function will complain if there was a callback set already,
2067 * however it will set the new one.
2069 * The callback will be called from elm_widget_item_pre_notify_del()
2070 * or elm_widget_item_del() will be called with:
2071 * - data: the Elm_Widget_Item::data value.
2072 * - obj: the Elm_Widget_Item::widget evas object.
2073 * - event_info: the item being deleted.
2075 * @param item a valid #Elm_Widget_Item to be notified
2076 * @see elm_widget_item_del_cb_set() convenience macro.
2080 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2082 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2084 if ((item->del_cb) && (item->del_cb != del_cb))
2085 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2086 item->del_cb, item, del_cb);
2088 item->del_cb = del_cb;
2094 * Set user-data in this item.
2096 * User data may be used to identify this item or just store any
2097 * application data. It is automatically given as the first parameter
2098 * of the deletion notify callback.
2100 * @param item a valid #Elm_Widget_Item to store data in.
2101 * @param data user data to store.
2102 * @see elm_widget_item_del_cb_set() convenience macro.
2106 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2108 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2109 if ((item->data) && (item->data != data))
2110 DBG("Replacing item %p data %p with %p", item, item->data, data);
2117 * Retrieves user-data of this item.
2119 * @param item a valid #Elm_Widget_Item to get data from.
2120 * @see elm_widget_item_data_set()
2124 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2126 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2127 return (void *)item->data;
2130 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2132 struct _Elm_Widget_Item_Tooltip
2134 Elm_Widget_Item *item;
2135 Elm_Tooltip_Item_Content_Cb func;
2136 Evas_Smart_Cb del_cb;
2140 static Evas_Object *
2141 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2143 Evas_Object *label = elm_label_add(obj);
2146 elm_object_style_set(label, "tooltip");
2147 elm_label_label_set(label, data);
2152 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2154 eina_stringshare_del(data);
2160 * Set the text to be shown in the widget item.
2162 * @param item Target item
2163 * @param text The text to set in the content
2165 * Setup the text as tooltip to object. The item can have only one tooltip,
2166 * so any previous tooltip data is removed.
2171 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2173 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2174 EINA_SAFETY_ON_NULL_RETURN(text);
2176 text = eina_stringshare_add(text);
2177 _elm_widget_item_tooltip_content_cb_set
2178 (item, _elm_widget_item_tooltip_label_create, text,
2179 _elm_widget_item_tooltip_label_del_cb);
2182 static Evas_Object *
2183 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2185 Elm_Widget_Item_Tooltip *wit = data;
2186 return wit->func((void *)wit->data, obj, wit->item);
2190 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2192 Elm_Widget_Item_Tooltip *wit = data;
2193 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2200 * Set the content to be shown in the tooltip item
2202 * Setup the tooltip to item. The item can have only one tooltip,
2203 * so any previous tooltip data is removed. @p func(with @p data) will
2204 * be called every time that need show the tooltip and it should
2205 * return a valid Evas_Object. This object is then managed fully by
2206 * tooltip system and is deleted when the tooltip is gone.
2208 * @param item the widget item being attached a tooltip.
2209 * @param func the function used to create the tooltip contents.
2210 * @param data what to provide to @a func as callback data/context.
2211 * @param del_cb called when data is not needed anymore, either when
2212 * another callback replaces @func, the tooltip is unset with
2213 * elm_widget_item_tooltip_unset() or the owner @a item
2214 * dies. This callback receives as the first parameter the
2215 * given @a data, and @c event_info is the item.
2220 _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)
2222 Elm_Widget_Item_Tooltip *wit;
2224 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2228 _elm_widget_item_tooltip_unset(item);
2232 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2233 if (!wit) goto error;
2237 wit->del_cb = del_cb;
2239 elm_object_sub_tooltip_content_cb_set
2240 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2241 _elm_widget_item_tooltip_del_cb);
2246 if (del_cb) del_cb((void *)data, NULL, item);
2249 if (del_cb) del_cb((void *)data, item->widget, item);
2255 * Unset tooltip from item
2257 * @param item widget item to remove previously set tooltip.
2259 * Remove tooltip from item. The callback provided as del_cb to
2260 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2261 * it is not used anymore.
2263 * @see elm_widget_item_tooltip_content_cb_set()
2268 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2270 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2271 elm_object_tooltip_unset(item->view);
2277 * Sets a different style for this item tooltip.
2279 * @note before you set a style you should define a tooltip with
2280 * elm_widget_item_tooltip_content_cb_set() or
2281 * elm_widget_item_tooltip_text_set()
2283 * @param item widget item with tooltip already set.
2284 * @param style the theme style to use (default, transparent, ...)
2289 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2291 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2292 elm_object_tooltip_style_set(item->view, style);
2298 * Get the style for this item tooltip.
2300 * @param item widget item with tooltip already set.
2301 * @return style the theme style in use, defaults to "default". If the
2302 * object does not have a tooltip set, then NULL is returned.
2307 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2309 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2310 return elm_object_tooltip_style_get(item->view);
2314 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2316 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2317 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2321 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2323 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2324 return elm_object_cursor_get(item->view);
2328 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2330 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2331 elm_object_cursor_unset(item->view);
2337 * Sets a different style for this item cursor.
2339 * @note before you set a style you should define a cursor with
2340 * elm_widget_item_cursor_set()
2342 * @param item widget item with cursor already set.
2343 * @param style the theme style to use (default, transparent, ...)
2348 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2350 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2351 elm_object_cursor_style_set(item->view, style);
2357 * Get the style for this item cursor.
2359 * @param item widget item with cursor already set.
2360 * @return style the theme style in use, defaults to "default". If the
2361 * object does not have a cursor set, then NULL is returned.
2366 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2368 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2369 return elm_object_cursor_style_get(item->view);
2375 * Set if the cursor set should be searched on the theme or should use
2376 * the provided by the engine, only.
2378 * @note before you set if should look on theme you should define a cursor
2379 * with elm_object_cursor_set(). By default it will only look for cursors
2380 * provided by the engine.
2382 * @param item widget item with cursor already set.
2383 * @param 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.
2389 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2391 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2392 elm_object_cursor_engine_only_set(item->view, engine_only);
2398 * Get the cursor engine only usage for this item cursor.
2400 * @param item widget item with cursor already set.
2401 * @return engine_only boolean to define it cursors should be looked only
2402 * between the provided by the engine or searched on widget's theme as well. If
2403 * the object does not have a cursor set, then EINA_FALSE is returned.
2408 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2410 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2411 return elm_object_cursor_engine_only_get(item->view);
2414 // smart object funcs
2416 _smart_reconfigure(Smart_Data *sd)
2420 evas_object_move(sd->resize_obj, sd->x, sd->y);
2421 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2425 evas_object_move(sd->hover_obj, sd->x, sd->y);
2426 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2431 _smart_add(Evas_Object *obj)
2435 sd = calloc(1, sizeof(Smart_Data));
2438 sd->x = sd->y = sd->w = sd->h = 0;
2440 evas_object_smart_data_set(obj, sd);
2443 static Evas_Object *
2444 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2447 Evas_Object *child, *ret, *best;
2449 API_ENTRY return NULL;
2450 if (!evas_object_visible_get(obj)) return NULL;
2452 if (*newest_focus_order < sd->focus_order)
2454 *newest_focus_order = sd->focus_order;
2457 EINA_LIST_FOREACH(sd->subobjs, l, child)
2459 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2465 if ((!best) || (!elm_widget_can_focus_get(best)))
2472 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2475 Evas_Object *newest = NULL;
2476 unsigned int newest_focus_order = 0;
2480 if (!sd->focused) return;
2481 if (!sd->parent_obj) return;
2483 top = elm_widget_top_get(sd->parent_obj);
2486 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2489 elm_object_unfocus(newest);
2490 elm_object_focus(newest);
2496 _smart_del(Evas_Object *obj)
2499 Edje_Signal_Data *esd;
2503 if (sd->del_pre_func) sd->del_pre_func(obj);
2506 sobj = sd->resize_obj;
2507 sd->resize_obj = NULL;
2508 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2509 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2510 evas_object_del(sobj);
2514 sobj = sd->hover_obj;
2515 sd->hover_obj = NULL;
2516 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2517 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2518 evas_object_del(sobj);
2520 EINA_LIST_FREE(sd->subobjs, sobj)
2522 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2523 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2524 evas_object_del(sobj);
2526 eina_list_free(sd->tooltips); /* should be empty anyway */
2527 eina_list_free(sd->cursors); /* should be empty anyway */
2528 EINA_LIST_FREE(sd->edje_signals, esd)
2530 eina_stringshare_del(esd->emission);
2531 eina_stringshare_del(esd->source);
2534 eina_list_free(sd->event_cb); /* should be empty anyway */
2535 if (sd->del_func) sd->del_func(obj);
2536 if (sd->style) eina_stringshare_del(sd->style);
2537 if (sd->type) eina_stringshare_del(sd->type);
2538 if (sd->theme) elm_theme_free(sd->theme);
2539 _if_focused_revert(obj, EINA_TRUE);
2544 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2549 _smart_reconfigure(sd);
2553 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2558 _smart_reconfigure(sd);
2562 _smart_show(Evas_Object *obj)
2567 if ((list = evas_object_smart_members_get(obj)))
2569 EINA_LIST_FREE(list, o)
2571 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2572 evas_object_show(o);
2578 _smart_hide(Evas_Object *obj)
2583 list = evas_object_smart_members_get(obj);
2584 EINA_LIST_FREE(list, o)
2586 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2587 evas_object_hide(o);
2592 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2597 if ((list = evas_object_smart_members_get(obj)))
2599 EINA_LIST_FREE(list, o)
2601 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2602 evas_object_color_set(o, r, g, b, a);
2608 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2613 if ((list = evas_object_smart_members_get(obj)))
2615 EINA_LIST_FREE(list, o)
2617 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2618 evas_object_clip_set(o, clip);
2624 _smart_clip_unset(Evas_Object *obj)
2629 if ((list = evas_object_smart_members_get(obj)))
2631 EINA_LIST_FREE(list, o)
2633 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2634 evas_object_clip_unset(o);
2640 _smart_calculate(Evas_Object *obj)
2643 if (sd->changed_func) sd->changed_func(obj);
2646 /* never need to touch this */
2650 if (_e_smart) return;
2652 static const Evas_Smart_Class sc =
2655 EVAS_SMART_CLASS_VERSION,
2673 _e_smart = evas_smart_class_new(&sc);
2677 /* happy debug functions */
2680 _sub_obj_tree_dump(const Evas_Object *o, int lvl)
2684 for (i = 0; i < lvl*3; i++)
2687 if (_elm_widget_is(o))
2690 Smart_Data *sd = evas_object_smart_data_get(o);
2691 printf("+ %s(%p)\n", sd->type, o);
2693 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2694 EINA_LIST_FOREACH(sd->subobjs, l, o)
2696 if (o != sd->resize_obj)
2697 _sub_obj_tree_dump(o, lvl + 1);
2701 printf("+ %s(%p)\n", evas_object_type_get(o), o);
2705 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2707 if (!_elm_widget_is(obj))
2710 Smart_Data *sd = evas_object_smart_data_get(obj);
2712 Eina_Bool visible = evas_object_visible_get(obj);
2713 Eina_Bool disabled = elm_widget_disabled_get(obj);
2714 Eina_Bool focused = elm_widget_focus_get(obj);
2715 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2719 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2722 fprintf(output, ", style=bold");
2725 fprintf(output, ", color=gray28");
2727 fprintf(output, " ];\n");
2730 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2731 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2732 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2736 fprintf(output, ", style=bold");
2739 fprintf(output, ", fontcolor=gray28");
2741 if ((disabled) || (!visible))
2742 fprintf(output, ", color=gray");
2745 fprintf(output, " ];\n");
2749 EINA_LIST_FOREACH(sd->subobjs, l, o)
2750 _sub_obj_tree_dot_dump(o, output);
2755 elm_widget_tree_dump(const Evas_Object *top)
2758 _sub_obj_tree_dump(top, 0);
2766 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2769 if (!_elm_widget_is(top))
2771 fprintf(output, "graph "" { node [shape=record];\n");
2772 _sub_obj_tree_dot_dump(top, output);
2773 fprintf(output, "}\n");