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,
35 Evas_Callback_Type type,
37 void (*signal_func)(Evas_Object *obj,
40 void (*callback_add_func)(Evas_Object *obj,
45 void (*callback_del_func)(Evas_Object *obj,
50 void (*changed_func)(Evas_Object *obj);
51 Eina_Bool (*focus_next_func)(const Evas_Object *obj,
52 Elm_Focus_Direction dir,
54 void (*on_focus_func)(void *data,
57 void (*on_change_func)(void *data,
60 void (*on_show_region_func)(void *data,
62 void *on_show_region_data;
63 void (*focus_region_func)(Evas_Object *obj,
68 void (*on_focus_region_func)(const Evas_Object *obj,
74 Evas_Coord rx, ry, rw, rh;
80 unsigned int focus_order;
81 Eina_Bool focus_order_on_calc;
83 int child_drag_x_locked;
84 int child_drag_y_locked;
86 Eina_List *edje_signals;
88 Eina_Bool drag_x_locked : 1;
89 Eina_Bool drag_y_locked : 1;
91 Eina_Bool can_focus : 1;
92 Eina_Bool child_can_focus : 1;
93 Eina_Bool focused : 1;
94 Eina_Bool highlight_ignore : 1;
95 Eina_Bool highlight_in_theme : 1;
96 Eina_Bool disabled : 1;
97 Eina_Bool is_mirrored : 1;
98 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
100 Eina_List *focus_chain;
104 struct _Edje_Signal_Data
108 const char *emission;
113 struct _Elm_Event_Cb_Data
119 /* local subsystem functions */
120 static void _smart_reconfigure(Smart_Data *sd);
121 static void _smart_add(Evas_Object *obj);
122 static void _smart_del(Evas_Object *obj);
123 static void _smart_move(Evas_Object *obj,
126 static void _smart_resize(Evas_Object *obj,
129 static void _smart_show(Evas_Object *obj);
130 static void _smart_hide(Evas_Object *obj);
131 static void _smart_color_set(Evas_Object *obj,
136 static void _smart_clip_set(Evas_Object *obj,
138 static void _smart_clip_unset(Evas_Object *obj);
139 static void _smart_calculate(Evas_Object *obj);
140 static void _smart_init(void);
142 static void _if_focused_revert(Evas_Object *obj,
143 Eina_Bool can_focus_only);
144 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
145 unsigned int *newest_focus_order,
146 Eina_Bool can_focus_only);
148 /* local subsystem globals */
149 static Evas_Smart *_e_smart = NULL;
150 static Eina_List *widtypes = NULL;
152 static unsigned int focus_order = 0;
155 static inline Eina_Bool
156 _elm_widget_is(const Evas_Object *obj)
158 const char *type = evas_object_type_get(obj);
159 return type == SMART_NAME;
162 static inline Eina_Bool
163 _is_focusable(Evas_Object *obj)
165 API_ENTRY return EINA_FALSE;
166 return sd->can_focus || (sd->child_can_focus);
170 _unfocus_parents(Evas_Object *obj)
172 for (; obj; obj = elm_widget_parent_get(obj))
175 if (!sd->focused) return;
181 _focus_parents(Evas_Object *obj)
183 for (; obj; obj = elm_widget_parent_get(obj))
186 if (sd->focused) return;
192 _sub_obj_del(void *data,
195 void *event_info __UNUSED__)
197 Smart_Data *sd = data;
199 if (_elm_widget_is(obj))
201 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
203 if (obj == sd->resize_obj)
204 sd->resize_obj = NULL;
205 else if (obj == sd->hover_obj)
206 sd->hover_obj = NULL;
208 sd->subobjs = eina_list_remove(sd->subobjs, obj);
209 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
213 _sub_obj_hide(void *data __UNUSED__,
216 void *event_info __UNUSED__)
218 _if_focused_revert(obj, EINA_TRUE);
222 _sub_obj_mouse_down(void *data __UNUSED__,
225 void *event_info __UNUSED__)
227 Evas_Object *o = obj;
230 if (_elm_widget_is(o)) break;
231 o = evas_object_smart_parent_get(o);
235 if (!_is_focusable(o)) return;
236 elm_widget_focus_steal(o);
240 _propagate_x_drag_lock(Evas_Object *obj,
246 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
249 sd2->child_drag_x_locked += dir;
250 _propagate_x_drag_lock(sd->parent_obj, dir);
256 _propagate_y_drag_lock(Evas_Object *obj,
262 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
265 sd2->child_drag_y_locked += dir;
266 _propagate_y_drag_lock(sd->parent_obj, dir);
272 _propagate_event(void *data,
278 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
279 Evas_Event_Flags *event_flags = NULL;
283 case EVAS_CALLBACK_KEY_DOWN:
285 Evas_Event_Key_Down *ev = event_info;
286 event_flags = &(ev->event_flags);
290 case EVAS_CALLBACK_KEY_UP:
292 Evas_Event_Key_Up *ev = event_info;
293 event_flags = &(ev->event_flags);
297 case EVAS_CALLBACK_MOUSE_WHEEL:
299 Evas_Event_Mouse_Wheel *ev = event_info;
300 event_flags = &(ev->event_flags);
308 elm_widget_event_propagate(obj, type, event_info, event_flags);
312 _parent_focus(Evas_Object *obj)
316 Evas_Object *o = elm_widget_parent_get(obj);
317 sd->focus_order_on_calc = EINA_TRUE;
319 if (sd->focused) return;
325 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
327 /* we don't want to bump a common widget ancestor's
328 focus_order *twice* while parent focusing */
329 if (!ret || (!i) || (i != focus_order))
333 if (!sd->focus_order_on_calc)
334 return; /* we don't want to override it if by means of any of the
335 callbacks below one gets to calculate our order
339 sd->focus_order = focus_order;
340 sd->focused = EINA_TRUE;
341 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
342 if (sd->focus_func) sd->focus_func(obj);
344 _elm_widget_focus_region_show(obj);
346 sd->focus_order_on_calc = EINA_FALSE;
350 _elm_object_focus_chain_del_cb(void *data,
353 void *event_info __UNUSED__)
355 Smart_Data *sd = data;
357 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
360 // exposed util funcs to elm
362 _elm_widget_type_clear(void)
366 EINA_LIST_FREE(widtypes, ptr)
368 eina_stringshare_del(*ptr);
374 _elm_widget_focus_region_show(const Evas_Object *obj)
376 Evas_Coord x, y, w, h, ox, oy;
382 o = elm_widget_parent_get(obj);
385 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
386 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
390 sd2 = evas_object_smart_data_get(o);
391 if (sd2->focus_region_func)
393 sd2->focus_region_func(o, x, y, w, h);
394 elm_widget_focus_region_get(o, &x, &y, &w, &h);
398 evas_object_geometry_get(o, &px, &py, NULL, NULL);
404 o = elm_widget_parent_get(o);
409 * @defgroup Widget Widget
412 * Exposed api for making widgets
415 elm_widget_type_register(const char **ptr)
417 widtypes = eina_list_append(widtypes, (void *)ptr);
421 elm_widget_api_check(int ver)
423 if (ver != ELM_INTERNAL_API_VERSION)
425 CRITICAL("Elementary widget api versions do not match");
432 elm_widget_add(Evas *evas)
436 obj = evas_object_smart_add(evas, _e_smart);
437 elm_widget_mirrored_set(obj, elm_mirrored_get());
442 elm_widget_del_hook_set(Evas_Object *obj,
443 void (*func)(Evas_Object *obj))
450 elm_widget_del_pre_hook_set(Evas_Object *obj,
451 void (*func)(Evas_Object *obj))
454 sd->del_pre_func = func;
458 elm_widget_focus_hook_set(Evas_Object *obj,
459 void (*func)(Evas_Object *obj))
462 sd->focus_func = func;
466 elm_widget_activate_hook_set(Evas_Object *obj,
467 void (*func)(Evas_Object *obj))
470 sd->activate_func = func;
474 elm_widget_disable_hook_set(Evas_Object *obj,
475 void (*func)(Evas_Object *obj))
478 sd->disable_func = func;
482 elm_widget_theme_hook_set(Evas_Object *obj,
483 void (*func)(Evas_Object *obj))
486 sd->theme_func = func;
490 elm_widget_event_hook_set(Evas_Object *obj,
491 Eina_Bool (*func)(Evas_Object *obj,
493 Evas_Callback_Type type,
497 sd->event_func = func;
501 elm_widget_changed_hook_set(Evas_Object *obj,
502 void (*func)(Evas_Object *obj))
505 sd->changed_func = func;
509 elm_widget_signal_emit_hook_set(Evas_Object *obj,
510 void (*func)(Evas_Object *obj,
511 const char *emission,
515 sd->signal_func = func;
519 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
520 void (*func)(Evas_Object *obj,
521 const char *emission,
523 Edje_Signal_Cb func_cb,
527 sd->callback_add_func = func;
531 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
532 void (*func)(Evas_Object *obj,
533 const char *emission,
535 Edje_Signal_Cb func_cb,
539 sd->callback_del_func = func;
543 elm_widget_theme(Evas_Object *obj)
551 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
552 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
553 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
554 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
555 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
556 if (sd->theme_func) sd->theme_func(obj);
560 elm_widget_theme_specific(Evas_Object *obj,
568 Elm_Theme *th2, *thdef;
571 thdef = elm_theme_default_get();
576 if (!th2) th2 = thdef;
584 if (th2 == thdef) break;
585 th2 = th2->ref_theme;
586 if (!th2) th2 = thdef;
590 EINA_LIST_FOREACH(sd->subobjs, l, child)
591 elm_widget_theme_specific(child, th, force);
592 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
593 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
594 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
595 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
596 if (sd->theme_func) sd->theme_func(obj);
602 * Set hook to get next object in object focus chain.
604 * @param obj The widget object.
605 * @param func The hook to be used with this widget.
610 elm_widget_focus_next_hook_set(Evas_Object *obj,
611 Eina_Bool (*func)(const Evas_Object *obj,
612 Elm_Focus_Direction dir,
616 sd->focus_next_func = func;
620 * Returns the widget's mirrored mode.
622 * @param obj The widget.
623 * @return mirrored mode of the object.
627 elm_widget_mirrored_get(const Evas_Object *obj)
629 API_ENTRY return EINA_FALSE;
630 return sd->is_mirrored;
634 * Sets the widget's mirrored mode.
636 * @param obj The widget.
637 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
640 elm_widget_mirrored_set(Evas_Object *obj,
644 if (sd->is_mirrored != mirrored)
646 sd->is_mirrored = mirrored;
647 elm_widget_theme(obj);
653 * Resets the mirrored mode from the system mirror mode for widgets that are in
654 * automatic mirroring mode. This function does not call elm_widget_theme.
656 * @param obj The widget.
657 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
660 _elm_widget_mirrored_reload(Evas_Object *obj)
663 Eina_Bool mirrored = elm_mirrored_get();
664 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
666 sd->is_mirrored = mirrored;
671 * Returns the widget's mirrored mode setting.
673 * @param obj The widget.
674 * @return mirrored mode setting of the object.
678 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
680 API_ENTRY return EINA_FALSE;
681 return sd->mirrored_auto_mode;
685 * Sets the widget's mirrored mode setting.
686 * When widget in automatic mode, it follows the system mirrored mode set by
687 * elm_mirrored_set().
688 * @param obj The widget.
689 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
692 elm_widget_mirrored_automatic_set(Evas_Object *obj,
696 if (sd->mirrored_auto_mode != automatic)
698 sd->mirrored_auto_mode = automatic;
702 elm_widget_mirrored_set(obj, elm_mirrored_get());
708 elm_widget_on_focus_hook_set(Evas_Object *obj,
709 void (*func)(void *data,
714 sd->on_focus_func = func;
715 sd->on_focus_data = data;
719 elm_widget_on_change_hook_set(Evas_Object *obj,
720 void (*func)(void *data,
725 sd->on_change_func = func;
726 sd->on_change_data = data;
730 elm_widget_on_show_region_hook_set(Evas_Object *obj,
731 void (*func)(void *data,
736 sd->on_show_region_func = func;
737 sd->on_show_region_data = data;
743 * Set the hook to use to show the focused region.
745 * Whenever a new widget gets focused or it's needed to show the focused
746 * area of the current one, this hook will be called on objects that may
747 * want to move their children into their visible area.
748 * The area given in the hook function is relative to the @p obj widget.
750 * @param obj The widget object
751 * @param func The function to call to show the specified area.
756 elm_widget_focus_region_hook_set(Evas_Object *obj,
757 void (*func)(Evas_Object *obj,
764 sd->focus_region_func = func;
770 * Set the hook to retrieve the focused region of a widget.
772 * This hook will be called by elm_widget_focus_region_get() whenever
773 * it's needed to get the focused area of a widget. The area must be relative
774 * to the widget itself and if no hook is set, it will default to the entire
777 * @param obj The widget object
778 * @param func The function used to retrieve the focus region.
783 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
784 void (*func)(const Evas_Object *obj,
791 sd->on_focus_region_func = func;
795 elm_widget_data_set(Evas_Object *obj,
803 elm_widget_data_get(const Evas_Object *obj)
805 API_ENTRY return NULL;
810 elm_widget_sub_object_add(Evas_Object *obj,
814 double scale, pscale = elm_widget_scale_get(sobj);
815 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
816 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
818 if (_elm_widget_is(sobj))
820 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
823 if (sd2->parent_obj == obj)
826 elm_widget_sub_object_del(sd2->parent_obj, sobj);
827 sd2->parent_obj = obj;
828 if (!sd->child_can_focus && (_is_focusable(sobj)))
829 sd->child_can_focus = EINA_TRUE;
834 void *data = evas_object_data_get(sobj, "elm-parent");
837 if (data == obj) return;
838 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
843 sd->subobjs = eina_list_append(sd->subobjs, sobj);
844 evas_object_data_set(sobj, "elm-parent", obj);
845 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
846 if (_elm_widget_is(sobj))
847 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
848 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
849 scale = elm_widget_scale_get(sobj);
850 th = elm_widget_theme_get(sobj);
851 mirrored = elm_widget_mirrored_get(sobj);
852 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
853 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
857 elm_widget_sub_object_del(Evas_Object *obj,
860 Evas_Object *sobj_parent;
864 sobj_parent = evas_object_data_del(sobj, "elm-parent");
865 if (sobj_parent != obj)
867 static int abort_on_warn = -1;
868 ERR("removing sub object %p from parent %p, "
869 "but elm-parent is different %p!",
870 sobj, obj, sobj_parent);
871 if (EINA_UNLIKELY(abort_on_warn == -1))
873 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
874 else abort_on_warn = 0;
876 if (abort_on_warn == 1) abort();
878 if (!sd->child_can_focus)
880 if (_is_focusable(sobj)) sd->child_can_focus = 0;
882 if (_elm_widget_is(sobj))
884 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
887 sd2->parent_obj = NULL;
888 if (sd2->resize_obj == sobj)
889 sd2->resize_obj = NULL;
891 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
894 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
895 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
898 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
899 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
901 if (_elm_widget_is(sobj))
902 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
904 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
908 elm_widget_resize_object_set(Evas_Object *obj,
912 // orphan previous resize obj
915 evas_object_clip_unset(sd->resize_obj);
916 evas_object_data_del(sd->resize_obj, "elm-parent");
917 if (_elm_widget_is(sd->resize_obj))
919 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
920 if (sd2) sd2->parent_obj = NULL;
921 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
924 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
926 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
927 _sub_obj_mouse_down, sd);
928 evas_object_smart_member_del(sd->resize_obj);
929 if (_elm_widget_is(sd->resize_obj))
931 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
934 // orphan new resize obj
937 evas_object_data_del(sobj, "elm-parent");
938 if (_elm_widget_is(sobj))
940 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
941 if (sd2) sd2->parent_obj = NULL;
942 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
945 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
947 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
948 _sub_obj_mouse_down, sd);
949 evas_object_smart_member_del(sobj);
950 if (_elm_widget_is(sobj))
952 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
955 // set the resize obj up
956 sd->resize_obj = sobj;
959 if (_elm_widget_is(sd->resize_obj))
961 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
962 if (sd2) sd2->parent_obj = obj;
963 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
966 evas_object_clip_set(sobj, evas_object_clip_get(obj));
967 evas_object_smart_member_add(sobj, obj);
968 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
970 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
971 _sub_obj_mouse_down, sd);
972 _smart_reconfigure(sd);
973 evas_object_data_set(sobj, "elm-parent", obj);
974 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
975 if (_elm_widget_is(sobj))
977 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
983 elm_widget_hover_object_set(Evas_Object *obj,
989 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
992 sd->hover_obj = sobj;
995 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
997 _smart_reconfigure(sd);
1002 elm_widget_can_focus_set(Evas_Object *obj,
1003 Eina_Bool can_focus)
1006 sd->can_focus = can_focus;
1009 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1011 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1012 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1014 (void *)(long)EVAS_CALLBACK_KEY_UP);
1015 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1017 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1021 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1023 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1025 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1031 elm_widget_can_focus_get(const Evas_Object *obj)
1033 API_ENTRY return EINA_FALSE;
1034 return sd->can_focus;
1038 elm_widget_child_can_focus_get(const Evas_Object *obj)
1040 API_ENTRY return EINA_FALSE;
1041 return sd->child_can_focus;
1045 elm_widget_highlight_ignore_set(Evas_Object *obj,
1049 sd->highlight_ignore = !!ignore;
1053 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1055 API_ENTRY return EINA_FALSE;
1056 return sd->highlight_ignore;
1060 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1061 Eina_Bool highlight)
1064 sd->highlight_in_theme = !!highlight;
1065 /* FIXME: if focused, it should switch from one mode to the other */
1069 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1071 API_ENTRY return EINA_FALSE;
1072 return sd->highlight_in_theme;
1076 elm_widget_focus_get(const Evas_Object *obj)
1078 API_ENTRY return EINA_FALSE;
1083 elm_widget_focused_object_get(const Evas_Object *obj)
1085 const Evas_Object *subobj;
1087 API_ENTRY return NULL;
1089 if (!sd->focused) return NULL;
1090 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1092 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1093 if (fobj) return fobj;
1095 return (Evas_Object *)obj;
1099 elm_widget_top_get(const Evas_Object *obj)
1101 API_ENTRY return NULL;
1102 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1103 return (Evas_Object *)obj;
1107 elm_widget_is(const Evas_Object *obj)
1109 return _elm_widget_is(obj);
1113 elm_widget_parent_widget_get(const Evas_Object *obj)
1115 Evas_Object *parent;
1117 if (_elm_widget_is(obj))
1119 Smart_Data *sd = evas_object_smart_data_get(obj);
1120 if (!sd) return NULL;
1121 parent = sd->parent_obj;
1125 parent = evas_object_data_get(obj, "elm-parent");
1126 if (!parent) parent = evas_object_smart_parent_get(obj);
1131 Evas_Object *elm_parent;
1132 if (_elm_widget_is(parent)) break;
1133 elm_parent = evas_object_data_get(parent, "elm-parent");
1134 if (elm_parent) parent = elm_parent;
1135 else parent = evas_object_smart_parent_get(parent);
1141 elm_widget_event_callback_add(Evas_Object *obj,
1146 EINA_SAFETY_ON_NULL_RETURN(func);
1147 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1150 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1154 elm_widget_event_callback_del(Evas_Object *obj,
1158 API_ENTRY return NULL;
1159 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1161 Elm_Event_Cb_Data *ecd;
1162 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1163 if ((ecd->func == func) && (ecd->data == data))
1166 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1167 return (void *)data;
1173 elm_widget_event_propagate(Evas_Object *obj,
1174 Evas_Callback_Type type,
1176 Evas_Event_Flags *event_flags)
1178 API_ENTRY return EINA_FALSE; //TODO reduce.
1179 if (!_elm_widget_is(obj)) return EINA_FALSE;
1180 Evas_Object *parent = obj;
1181 Elm_Event_Cb_Data *ecd;
1182 Eina_List *l, *l_prev;
1185 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1187 sd = evas_object_smart_data_get(parent);
1188 if ((!sd) || (!_elm_widget_is(obj)))
1189 return EINA_FALSE; //Not Elm Widget
1191 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1194 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1196 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1197 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1200 parent = sd->parent_obj;
1209 * Set custom focus chain.
1211 * This function i set one new and overwrite any previous custom focus chain
1212 * with the list of objects. The previous list will be deleted and this list
1213 * will be managed. After setted, don't modity it.
1215 * @note On focus cycle, only will be evaluated children of this container.
1217 * @param obj The container widget
1218 * @param objs Chain of objects to pass focus
1222 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1226 if (!sd->focus_next_func)
1229 elm_widget_focus_custom_chain_unset(obj);
1234 EINA_LIST_FOREACH(objs, l, o)
1236 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1237 _elm_object_focus_chain_del_cb, sd);
1240 sd->focus_chain = objs;
1246 * Get custom focus chain
1248 * @param obj The container widget
1251 EAPI const Eina_List *
1252 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1254 API_ENTRY return NULL;
1255 return (const Eina_List *)sd->focus_chain;
1261 * Unset custom focus chain
1263 * @param obj The container widget
1267 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1270 Eina_List *l, *l_next;
1273 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1275 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1276 _elm_object_focus_chain_del_cb, sd);
1277 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1284 * Append object to custom focus chain.
1286 * @note If relative_child equal to NULL or not in custom chain, the object
1287 * will be added in end.
1289 * @note On focus cycle, only will be evaluated children of this container.
1291 * @param obj The container widget
1292 * @param child The child to be added in custom chain
1293 * @param relative_child The relative object to position the child
1297 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1299 Evas_Object *relative_child)
1302 EINA_SAFETY_ON_NULL_RETURN(child);
1303 if (!sd->focus_next_func)
1306 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1307 _elm_object_focus_chain_del_cb, sd);
1309 if (!relative_child)
1311 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1315 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1322 * Prepend object to custom focus chain.
1324 * @note If relative_child equal to NULL or not in custom chain, the object
1325 * will be added in begin.
1327 * @note On focus cycle, only will be evaluated children of this container.
1329 * @param obj The container widget
1330 * @param child The child to be added in custom chain
1331 * @param relative_child The relative object to position the child
1335 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1337 Evas_Object *relative_child)
1340 EINA_SAFETY_ON_NULL_RETURN(child);
1341 if (!sd->focus_next_func)
1344 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1345 _elm_object_focus_chain_del_cb, sd);
1347 if (!relative_child)
1349 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1353 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1360 * Give focus to next object in object tree.
1362 * Give focus to next object in focus chain of one object sub-tree.
1363 * If the last object of chain already have focus, the focus will go to the
1364 * first object of chain.
1366 * @param obj The widget root of sub-tree
1367 * @param dir Direction to cycle the focus
1372 elm_widget_focus_cycle(Evas_Object *obj,
1373 Elm_Focus_Direction dir)
1375 Evas_Object *target = NULL;
1376 if (!_elm_widget_is(obj))
1378 elm_widget_focus_next_get(obj, dir, &target);
1380 elm_widget_focus_steal(target);
1386 * Give focus to near object in one direction.
1388 * Give focus to near object in direction of one object.
1389 * If none focusable object in given direction, the focus will not change.
1391 * @param obj The reference widget
1392 * @param x Horizontal component of direction to focus
1393 * @param y Vertical component of direction to focus
1398 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1408 * Get next object in focus chain of object tree.
1410 * Get next object in focus chain of one object sub-tree.
1411 * Return the next object by reference. If don't have any candidate to receive
1412 * focus before chain end, the first candidate will be returned.
1414 * @param obj The widget root of sub-tree
1415 * @param dir Direction os focus chain
1416 * @param next The next object in focus chain
1417 * @return EINA_TRUE if don't need focus chain restart/loop back
1418 * to use 'next' obj.
1423 elm_widget_focus_next_get(const Evas_Object *obj,
1424 Elm_Focus_Direction dir,
1431 API_ENTRY return EINA_FALSE;
1433 /* Ignore if disabled */
1434 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1438 if (sd->focus_next_func)
1439 return sd->focus_next_func(obj, dir, next);
1441 if (!elm_widget_can_focus_get(obj))
1445 *next = (Evas_Object *)obj;
1446 return !elm_widget_focus_get(obj);
1452 * Get next object in focus chain of object tree in list.
1454 * Get next object in focus chain of one object sub-tree ordered by one list.
1455 * Return the next object by reference. If don't have any candidate to receive
1456 * focus before list end, the first candidate will be returned.
1458 * @param obj The widget root of sub-tree
1459 * @param dir Direction os focus chain
1460 * @param items list with ordered objects
1461 * @param list_data_get function to get the object from one item of list
1462 * @param next The next object in focus chain
1463 * @return EINA_TRUE if don't need focus chain restart/loop back
1464 * to use 'next' obj.
1469 elm_widget_focus_list_next_get(const Evas_Object *obj,
1470 const Eina_List *items,
1471 void *(*list_data_get)(const Eina_List * list),
1472 Elm_Focus_Direction dir,
1475 Eina_List *(*list_next)(const Eina_List * list);
1481 if (!_elm_widget_is(obj))
1488 if (dir == ELM_FOCUS_PREVIOUS)
1490 items = eina_list_last(items);
1491 list_next = eina_list_prev;
1493 else if (dir == ELM_FOCUS_NEXT)
1494 list_next = eina_list_next;
1498 const Eina_List *l = items;
1500 /* Recovery last focused sub item */
1501 if (elm_widget_focus_get(obj))
1502 for (; l; l = list_next(l))
1504 Evas_Object *cur = list_data_get(l);
1505 if (elm_widget_focus_get(cur)) break;
1508 const Eina_List *start = l;
1509 Evas_Object *to_focus = NULL;
1511 /* Interate sub items */
1512 /* Go to end of list */
1513 for (; l; l = list_next(l))
1515 Evas_Object *tmp = NULL;
1516 Evas_Object *cur = list_data_get(l);
1518 if (elm_widget_parent_get(cur) != obj)
1521 /* Try Focus cycle in subitem */
1522 if (elm_widget_focus_next_get(cur, dir, &tmp))
1527 else if ((tmp) && (!to_focus))
1533 /* Get First possible */
1534 for (; l != start; l = list_next(l))
1536 Evas_Object *tmp = NULL;
1537 Evas_Object *cur = list_data_get(l);
1539 if (elm_widget_parent_get(cur) != obj)
1542 /* Try Focus cycle in subitem */
1543 elm_widget_focus_next_get(cur, dir, &tmp);
1556 elm_widget_signal_emit(Evas_Object *obj,
1557 const char *emission,
1561 if (!sd->signal_func) return;
1562 sd->signal_func(obj, emission, source);
1566 _edje_signal_callback(void *data,
1567 Evas_Object *obj __UNUSED__,
1568 const char *emission,
1571 Edje_Signal_Data *esd = data;
1572 esd->func(esd->data, esd->obj, emission, source);
1576 elm_widget_signal_callback_add(Evas_Object *obj,
1577 const char *emission,
1579 Edje_Signal_Cb func,
1582 Edje_Signal_Data *esd;
1584 if (!sd->callback_add_func) return;
1585 EINA_SAFETY_ON_NULL_RETURN(func);
1587 esd = ELM_NEW(Edje_Signal_Data);
1592 esd->emission = eina_stringshare_add(emission);
1593 esd->source = eina_stringshare_add(source);
1595 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1596 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1600 elm_widget_signal_callback_del(Evas_Object *obj,
1601 const char *emission,
1603 Edje_Signal_Cb func)
1605 Edje_Signal_Data *esd;
1608 API_ENTRY return NULL;
1609 if (!sd->callback_del_func) return NULL;
1611 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1613 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1614 (!strcmp(esd->source, source)))
1616 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1617 eina_stringshare_del(esd->emission);
1618 eina_stringshare_del(esd->source);
1624 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1629 elm_widget_focus_set(Evas_Object *obj,
1636 sd->focus_order = focus_order;
1637 sd->focused = EINA_TRUE;
1638 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1642 sd->focus_func(obj);
1649 if ((_is_focusable(sd->resize_obj)) &&
1650 (!elm_widget_disabled_get(sd->resize_obj)))
1652 elm_widget_focus_set(sd->resize_obj, first);
1658 EINA_LIST_FOREACH(sd->subobjs, l, child)
1660 if ((_is_focusable(child)) &&
1661 (!elm_widget_disabled_get(child)))
1663 elm_widget_focus_set(child, first);
1673 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1675 if ((_is_focusable(child)) &&
1676 (!elm_widget_disabled_get(child)))
1678 elm_widget_focus_set(child, first);
1684 if ((_is_focusable(sd->resize_obj)) &&
1685 (!elm_widget_disabled_get(sd->resize_obj)))
1687 elm_widget_focus_set(sd->resize_obj, first);
1695 elm_widget_parent_get(const Evas_Object *obj)
1697 API_ENTRY return NULL;
1698 return sd->parent_obj;
1702 elm_widget_focused_object_clear(Evas_Object *obj)
1705 if (!sd->focused) return;
1706 if (elm_widget_focus_get(sd->resize_obj))
1707 elm_widget_focused_object_clear(sd->resize_obj);
1712 EINA_LIST_FOREACH(sd->subobjs, l, child)
1714 if (elm_widget_focus_get(child))
1716 elm_widget_focused_object_clear(child);
1721 sd->focused = EINA_FALSE;
1722 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1723 if (sd->focus_func) sd->focus_func(obj);
1727 elm_widget_focus_steal(Evas_Object *obj)
1729 Evas_Object *parent, *o;
1732 if (sd->focused) return;
1733 if (sd->disabled) return;
1737 o = elm_widget_parent_get(parent);
1739 sd = evas_object_smart_data_get(o);
1740 if (sd->focused) break;
1743 if (!elm_widget_parent_get(parent))
1744 elm_widget_focused_object_clear(parent);
1747 parent = elm_widget_parent_get(parent);
1748 sd = evas_object_smart_data_get(parent);
1749 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1750 elm_widget_focused_object_clear(sd->resize_obj);
1755 EINA_LIST_FOREACH(sd->subobjs, l, child)
1757 if (elm_widget_focus_get(child))
1759 elm_widget_focused_object_clear(child);
1770 elm_widget_activate(Evas_Object *obj)
1773 elm_widget_change(obj);
1774 if (sd->activate_func) sd->activate_func(obj);
1778 elm_widget_change(Evas_Object *obj)
1781 elm_widget_change(elm_widget_parent_get(obj));
1782 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1786 elm_widget_disabled_set(Evas_Object *obj,
1791 if (sd->disabled == disabled) return;
1792 sd->disabled = disabled;
1795 Evas_Object *o, *parent;
1800 o = elm_widget_parent_get(parent);
1804 if (elm_widget_focus_get(obj))
1805 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1807 if (sd->disable_func) sd->disable_func(obj);
1811 elm_widget_disabled_get(const Evas_Object *obj)
1814 return sd->disabled;
1818 elm_widget_show_region_set(Evas_Object *obj,
1823 Eina_Bool forceshow)
1825 Evas_Object *parent_obj, *child_obj;
1826 Evas_Coord px, py, cx, cy;
1829 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1830 && (w == sd->rw) && (h == sd->rh)) return;
1835 if (sd->on_show_region_func)
1836 sd->on_show_region_func(sd->on_show_region_data, obj);
1840 parent_obj = sd->parent_obj;
1841 child_obj = sd->obj;
1842 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1843 sd = evas_object_smart_data_get(parent_obj);
1846 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1847 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1856 if (sd->on_show_region_func)
1858 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1865 elm_widget_show_region_get(const Evas_Object *obj,
1881 * Get the focus region of the given widget.
1883 * The focus region is the area of a widget that should brought into the
1884 * visible area when the widget is focused. Mostly used to show the part of
1885 * an entry where the cursor is, for example. The area returned is relative
1886 * to the object @p obj.
1887 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1888 * function will return the full size of the object.
1890 * @param obj The widget object
1891 * @param x Where to store the x coordinate of the area
1892 * @param y Where to store the y coordinate of the area
1893 * @param w Where to store the width of the area
1894 * @param h Where to store the height of the area
1899 elm_widget_focus_region_get(const Evas_Object *obj,
1909 sd = evas_object_smart_data_get(obj);
1910 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1912 evas_object_geometry_get(obj, NULL, NULL, w, h);
1917 sd->on_focus_region_func(obj, x, y, w, h);
1921 elm_widget_scroll_hold_push(Evas_Object *obj)
1925 if (sd->scroll_hold == 1)
1926 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1927 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1928 // FIXME: on delete/reparent hold pop
1932 elm_widget_scroll_hold_pop(Evas_Object *obj)
1936 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1937 if (!sd->scroll_hold)
1938 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1939 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1943 elm_widget_scroll_hold_get(const Evas_Object *obj)
1946 return sd->scroll_hold;
1950 elm_widget_scroll_freeze_push(Evas_Object *obj)
1953 sd->scroll_freeze++;
1954 if (sd->scroll_freeze == 1)
1955 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1956 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1957 // FIXME: on delete/reparent freeze pop
1961 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1964 sd->scroll_freeze--;
1965 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1966 if (!sd->scroll_freeze)
1967 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1968 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1972 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1975 return sd->scroll_freeze;
1979 elm_widget_scale_set(Evas_Object *obj,
1983 if (scale <= 0.0) scale = 0.0;
1984 if (sd->scale != scale)
1987 elm_widget_theme(obj);
1992 elm_widget_scale_get(const Evas_Object *obj)
1994 API_ENTRY return 1.0;
1995 // FIXME: save walking up the tree by storing/caching parent scale
1996 if (sd->scale == 0.0)
1999 return elm_widget_scale_get(sd->parent_obj);
2007 elm_widget_theme_set(Evas_Object *obj,
2011 if (sd->theme != th)
2013 if (sd->theme) elm_theme_free(sd->theme);
2016 elm_widget_theme(obj);
2021 elm_widget_theme_get(const Evas_Object *obj)
2023 API_ENTRY return NULL;
2027 return elm_widget_theme_get(sd->parent_obj);
2035 elm_widget_style_set(Evas_Object *obj,
2040 if (eina_stringshare_replace(&sd->style, style))
2041 elm_widget_theme(obj);
2045 elm_widget_style_get(const Evas_Object *obj)
2047 API_ENTRY return NULL;
2048 if (sd->style) return sd->style;
2053 elm_widget_type_set(Evas_Object *obj,
2057 eina_stringshare_replace(&sd->type, type);
2061 elm_widget_type_get(const Evas_Object *obj)
2063 API_ENTRY return NULL;
2064 if (sd->type) return sd->type;
2069 elm_widget_tooltip_add(Evas_Object *obj,
2073 sd->tooltips = eina_list_append(sd->tooltips, tt);
2077 elm_widget_tooltip_del(Evas_Object *obj,
2081 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2085 elm_widget_cursor_add(Evas_Object *obj,
2089 sd->cursors = eina_list_append(sd->cursors, cur);
2093 elm_widget_cursor_del(Evas_Object *obj,
2097 sd->cursors = eina_list_remove(sd->cursors, cur);
2101 elm_widget_drag_lock_x_set(Evas_Object *obj,
2105 if (sd->drag_x_locked == lock) return;
2106 sd->drag_x_locked = lock;
2107 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2108 else _propagate_x_drag_lock(obj, -1);
2112 elm_widget_drag_lock_y_set(Evas_Object *obj,
2116 if (sd->drag_y_locked == lock) return;
2117 sd->drag_y_locked = lock;
2118 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2119 else _propagate_y_drag_lock(obj, -1);
2123 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2125 API_ENTRY return EINA_FALSE;
2126 return sd->drag_x_locked;
2130 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2132 API_ENTRY return EINA_FALSE;
2133 return sd->drag_y_locked;
2137 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2140 return sd->child_drag_x_locked;
2144 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2147 return sd->child_drag_y_locked;
2151 elm_widget_theme_object_set(Evas_Object *obj,
2154 const char *welement,
2157 API_ENTRY return EINA_FALSE;
2158 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2162 elm_widget_type_check(const Evas_Object *obj,
2165 const char *provided, *expected = "(unknown)";
2166 static int abort_on_warn = -1;
2167 provided = elm_widget_type_get(obj);
2168 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2169 if (type) expected = type;
2170 if ((!provided) || (!provided[0]))
2172 provided = evas_object_type_get(obj);
2173 if ((!provided) || (!provided[0]))
2174 provided = "(unknown)";
2176 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2177 if (abort_on_warn == -1)
2179 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2180 else abort_on_warn = 0;
2182 if (abort_on_warn == 1) abort();
2189 * Split string in words
2191 * @param str Source string
2192 * @return List of const words
2194 * @see elm_widget_stringlist_free()
2198 elm_widget_stringlist_get(const char *str)
2200 Eina_List *list = NULL;
2202 if (!str) return NULL;
2203 for (b = s = str; 1; s++)
2205 if ((*s == ' ') || (!*s))
2207 char *t = malloc(s - b + 1);
2210 strncpy(t, b, s - b);
2212 list = eina_list_append(list, eina_stringshare_add(t));
2223 elm_widget_stringlist_free(Eina_List *list)
2226 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2232 * Allocate a new Elm_Widget_Item-derived structure.
2234 * The goal of this structure is to provide common ground for actions
2235 * that a widget item have, such as the owner widget, callback to
2236 * notify deletion, data pointer and maybe more.
2238 * @param widget the owner widget that holds this item, must be an elm_widget!
2239 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2240 * be used to allocate memory.
2242 * @return allocated memory that is already zeroed out, or NULL on errors.
2244 * @see elm_widget_item_new() convenience macro.
2245 * @see elm_widget_item_del() to release memory.
2248 EAPI Elm_Widget_Item *
2249 _elm_widget_item_new(Evas_Object *widget,
2252 if (!_elm_widget_is(widget))
2255 Elm_Widget_Item *item;
2257 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2258 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2260 item = calloc(1, alloc_size);
2261 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2263 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2264 item->widget = widget;
2271 * Releases widget item memory, calling back del_cb() if it exists.
2273 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2274 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2275 * this function and then unset it, thus being useful for 2 step
2276 * cleanup whenever the del_cb may use any of the data that must be
2277 * deleted from item.
2279 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2282 * @param item a valid #Elm_Widget_Item to be deleted.
2283 * @see elm_widget_item_del() convenience macro.
2287 _elm_widget_item_del(Elm_Widget_Item *item)
2289 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2292 item->del_cb((void *)item->data, item->widget, item);
2295 evas_object_del(item->view);
2297 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2304 * Notify object will be deleted without actually deleting it.
2306 * This function will callback Elm_Widget_Item::del_cb if it is set
2307 * and then unset it so it is not called twice (ie: from
2308 * elm_widget_item_del()).
2310 * @param item a valid #Elm_Widget_Item to be notified
2311 * @see elm_widget_item_pre_notify_del() convenience macro.
2315 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2317 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2318 if (!item->del_cb) return;
2319 item->del_cb((void *)item->data, item->widget, item);
2320 item->del_cb = NULL;
2326 * Set the function to notify when item is being deleted.
2328 * This function will complain if there was a callback set already,
2329 * however it will set the new one.
2331 * The callback will be called from elm_widget_item_pre_notify_del()
2332 * or elm_widget_item_del() will be called with:
2333 * - data: the Elm_Widget_Item::data value.
2334 * - obj: the Elm_Widget_Item::widget evas object.
2335 * - event_info: the item being deleted.
2337 * @param item a valid #Elm_Widget_Item to be notified
2338 * @see elm_widget_item_del_cb_set() convenience macro.
2342 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2343 Evas_Smart_Cb del_cb)
2345 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2347 if ((item->del_cb) && (item->del_cb != del_cb))
2348 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2349 item->del_cb, item, del_cb);
2351 item->del_cb = del_cb;
2357 * Set user-data in this item.
2359 * User data may be used to identify this item or just store any
2360 * application data. It is automatically given as the first parameter
2361 * of the deletion notify callback.
2363 * @param item a valid #Elm_Widget_Item to store data in.
2364 * @param data user data to store.
2365 * @see elm_widget_item_del_cb_set() convenience macro.
2369 _elm_widget_item_data_set(Elm_Widget_Item *item,
2372 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2373 if ((item->data) && (item->data != data))
2374 DBG("Replacing item %p data %p with %p", item, item->data, data);
2381 * Retrieves user-data of this item.
2383 * @param item a valid #Elm_Widget_Item to get data from.
2384 * @see elm_widget_item_data_set()
2388 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2390 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2391 return (void *)item->data;
2394 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2396 struct _Elm_Widget_Item_Tooltip
2398 Elm_Widget_Item *item;
2399 Elm_Tooltip_Item_Content_Cb func;
2400 Evas_Smart_Cb del_cb;
2404 static Evas_Object *
2405 _elm_widget_item_tooltip_label_create(void *data,
2407 void *item __UNUSED__)
2409 Evas_Object *label = elm_label_add(obj);
2412 elm_object_style_set(label, "tooltip");
2413 elm_label_label_set(label, data);
2418 _elm_widget_item_tooltip_label_del_cb(void *data,
2419 Evas_Object *obj __UNUSED__,
2420 void *event_info __UNUSED__)
2422 eina_stringshare_del(data);
2428 * Set the text to be shown in the widget item.
2430 * @param item Target item
2431 * @param text The text to set in the content
2433 * Setup the text as tooltip to object. The item can have only one tooltip,
2434 * so any previous tooltip data is removed.
2439 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2442 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2443 EINA_SAFETY_ON_NULL_RETURN(text);
2445 text = eina_stringshare_add(text);
2446 _elm_widget_item_tooltip_content_cb_set
2447 (item, _elm_widget_item_tooltip_label_create, text,
2448 _elm_widget_item_tooltip_label_del_cb);
2451 static Evas_Object *
2452 _elm_widget_item_tooltip_create(void *data,
2455 Elm_Widget_Item_Tooltip *wit = data;
2456 return wit->func((void *)wit->data, obj, wit->item);
2460 _elm_widget_item_tooltip_del_cb(void *data,
2462 void *event_info __UNUSED__)
2464 Elm_Widget_Item_Tooltip *wit = data;
2465 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2472 * Set the content to be shown in the tooltip item
2474 * Setup the tooltip to item. The item can have only one tooltip,
2475 * so any previous tooltip data is removed. @p func(with @p data) will
2476 * be called every time that need show the tooltip and it should
2477 * return a valid Evas_Object. This object is then managed fully by
2478 * tooltip system and is deleted when the tooltip is gone.
2480 * @param item the widget item being attached a tooltip.
2481 * @param func the function used to create the tooltip contents.
2482 * @param data what to provide to @a func as callback data/context.
2483 * @param del_cb called when data is not needed anymore, either when
2484 * another callback replaces @func, the tooltip is unset with
2485 * elm_widget_item_tooltip_unset() or the owner @a item
2486 * dies. This callback receives as the first parameter the
2487 * given @a data, and @c event_info is the item.
2492 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2493 Elm_Tooltip_Item_Content_Cb func,
2495 Evas_Smart_Cb del_cb)
2497 Elm_Widget_Item_Tooltip *wit;
2499 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2503 _elm_widget_item_tooltip_unset(item);
2507 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2508 if (!wit) goto error;
2512 wit->del_cb = del_cb;
2514 elm_object_sub_tooltip_content_cb_set
2515 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2516 _elm_widget_item_tooltip_del_cb);
2521 if (del_cb) del_cb((void *)data, NULL, item);
2524 if (del_cb) del_cb((void *)data, item->widget, item);
2530 * Unset tooltip from item
2532 * @param item widget item to remove previously set tooltip.
2534 * Remove tooltip from item. The callback provided as del_cb to
2535 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2536 * it is not used anymore.
2538 * @see elm_widget_item_tooltip_content_cb_set()
2543 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2545 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2546 elm_object_tooltip_unset(item->view);
2552 * Sets a different style for this item tooltip.
2554 * @note before you set a style you should define a tooltip with
2555 * elm_widget_item_tooltip_content_cb_set() or
2556 * elm_widget_item_tooltip_text_set()
2558 * @param item widget item with tooltip already set.
2559 * @param style the theme style to use (default, transparent, ...)
2564 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2567 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2568 elm_object_tooltip_style_set(item->view, style);
2574 * Get the style for this item tooltip.
2576 * @param item widget item with tooltip already set.
2577 * @return style the theme style in use, defaults to "default". If the
2578 * object does not have a tooltip set, then NULL is returned.
2583 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2585 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2586 return elm_object_tooltip_style_get(item->view);
2590 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2593 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2594 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2598 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2600 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2601 return elm_object_cursor_get(item->view);
2605 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2607 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2608 elm_object_cursor_unset(item->view);
2614 * Sets a different style for this item cursor.
2616 * @note before you set a style you should define a cursor with
2617 * elm_widget_item_cursor_set()
2619 * @param item widget item with cursor already set.
2620 * @param style the theme style to use (default, transparent, ...)
2625 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2628 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2629 elm_object_cursor_style_set(item->view, style);
2635 * Get the style for this item cursor.
2637 * @param item widget item with cursor already set.
2638 * @return style the theme style in use, defaults to "default". If the
2639 * object does not have a cursor set, then NULL is returned.
2644 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2646 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2647 return elm_object_cursor_style_get(item->view);
2653 * Set if the cursor set should be searched on the theme or should use
2654 * the provided by the engine, only.
2656 * @note before you set if should look on theme you should define a cursor
2657 * with elm_object_cursor_set(). By default it will only look for cursors
2658 * provided by the engine.
2660 * @param item widget item with cursor already set.
2661 * @param engine_only boolean to define it cursors should be looked only
2662 * between the provided by the engine or searched on widget's theme as well.
2667 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2668 Eina_Bool engine_only)
2670 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2671 elm_object_cursor_engine_only_set(item->view, engine_only);
2677 * Get the cursor engine only usage for this item cursor.
2679 * @param item widget item with cursor already set.
2680 * @return engine_only boolean to define it cursors should be looked only
2681 * between the provided by the engine or searched on widget's theme as well. If
2682 * the object does not have a cursor set, then EINA_FALSE is returned.
2687 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2689 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2690 return elm_object_cursor_engine_only_get(item->view);
2693 // smart object funcs
2695 _smart_reconfigure(Smart_Data *sd)
2699 evas_object_move(sd->resize_obj, sd->x, sd->y);
2700 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2704 evas_object_move(sd->hover_obj, sd->x, sd->y);
2705 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2710 _smart_add(Evas_Object *obj)
2714 sd = calloc(1, sizeof(Smart_Data));
2717 sd->x = sd->y = sd->w = sd->h = 0;
2719 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2720 evas_object_smart_data_set(obj, sd);
2723 static Evas_Object *
2724 _newest_focus_order_get(Evas_Object *obj,
2725 unsigned int *newest_focus_order,
2726 Eina_Bool can_focus_only)
2729 Evas_Object *child, *ret, *best;
2731 API_ENTRY return NULL;
2732 if (!evas_object_visible_get(obj)) return NULL;
2734 if (*newest_focus_order < sd->focus_order)
2736 *newest_focus_order = sd->focus_order;
2739 EINA_LIST_FOREACH(sd->subobjs, l, child)
2741 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2747 if ((!best) || (!elm_widget_can_focus_get(best)))
2754 _if_focused_revert(Evas_Object *obj,
2755 Eina_Bool can_focus_only)
2758 Evas_Object *newest = NULL;
2759 unsigned int newest_focus_order = 0;
2763 if (!sd->focused) return;
2764 if (!sd->parent_obj) return;
2766 top = elm_widget_top_get(sd->parent_obj);
2769 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2772 elm_object_unfocus(newest);
2773 elm_object_focus(newest);
2779 _smart_del(Evas_Object *obj)
2782 Edje_Signal_Data *esd;
2786 if (sd->del_pre_func) sd->del_pre_func(obj);
2789 sobj = sd->resize_obj;
2790 sd->resize_obj = NULL;
2791 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2792 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2793 evas_object_del(sobj);
2797 sobj = sd->hover_obj;
2798 sd->hover_obj = NULL;
2799 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2800 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2801 evas_object_del(sobj);
2803 EINA_LIST_FREE(sd->subobjs, sobj)
2805 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2806 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2807 evas_object_del(sobj);
2809 eina_list_free(sd->tooltips); /* should be empty anyway */
2810 eina_list_free(sd->cursors); /* should be empty anyway */
2811 EINA_LIST_FREE(sd->edje_signals, esd)
2813 eina_stringshare_del(esd->emission);
2814 eina_stringshare_del(esd->source);
2817 eina_list_free(sd->event_cb); /* should be empty anyway */
2818 if (sd->del_func) sd->del_func(obj);
2819 if (sd->style) eina_stringshare_del(sd->style);
2820 if (sd->type) eina_stringshare_del(sd->type);
2821 if (sd->theme) elm_theme_free(sd->theme);
2822 _if_focused_revert(obj, EINA_TRUE);
2827 _smart_move(Evas_Object *obj,
2834 _smart_reconfigure(sd);
2838 _smart_resize(Evas_Object *obj,
2845 _smart_reconfigure(sd);
2849 _smart_show(Evas_Object *obj)
2854 if ((list = evas_object_smart_members_get(obj)))
2856 EINA_LIST_FREE(list, o)
2858 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2859 evas_object_show(o);
2865 _smart_hide(Evas_Object *obj)
2870 list = evas_object_smart_members_get(obj);
2871 EINA_LIST_FREE(list, o)
2873 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2874 evas_object_hide(o);
2879 _smart_color_set(Evas_Object *obj,
2888 if ((list = evas_object_smart_members_get(obj)))
2890 EINA_LIST_FREE(list, o)
2892 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2893 evas_object_color_set(o, r, g, b, a);
2899 _smart_clip_set(Evas_Object *obj,
2905 if ((list = evas_object_smart_members_get(obj)))
2907 EINA_LIST_FREE(list, o)
2909 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2910 evas_object_clip_set(o, clip);
2916 _smart_clip_unset(Evas_Object *obj)
2921 if ((list = evas_object_smart_members_get(obj)))
2923 EINA_LIST_FREE(list, o)
2925 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2926 evas_object_clip_unset(o);
2932 _smart_calculate(Evas_Object *obj)
2935 if (sd->changed_func) sd->changed_func(obj);
2938 /* never need to touch this */
2942 if (_e_smart) return;
2944 static const Evas_Smart_Class sc =
2947 EVAS_SMART_CLASS_VERSION,
2965 _e_smart = evas_smart_class_new(&sc);
2969 /* happy debug functions */
2972 _sub_obj_tree_dump(const Evas_Object *obj,
2977 for (i = 0; i < lvl * 3; i++)
2980 if (_elm_widget_is(obj))
2984 printf("+ %s(%p)\n",
2988 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2989 EINA_LIST_FOREACH(sd->subobjs, l, obj)
2991 if (obj != sd->resize_obj)
2992 _sub_obj_tree_dump(obj, lvl + 1);
2996 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3000 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3003 if (!_elm_widget_is(obj))
3007 Eina_Bool visible = evas_object_visible_get(obj);
3008 Eina_Bool disabled = elm_widget_disabled_get(obj);
3009 Eina_Bool focused = elm_widget_focus_get(obj);
3010 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3014 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3017 fprintf(output, ", style=bold");
3020 fprintf(output, ", color=gray28");
3022 fprintf(output, " ];\n");
3025 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3026 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3027 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3031 fprintf(output, ", style=bold");
3034 fprintf(output, ", fontcolor=gray28");
3036 if ((disabled) || (!visible))
3037 fprintf(output, ", color=gray");
3039 fprintf(output, " ];\n");
3043 EINA_LIST_FOREACH(sd->subobjs, l, o)
3044 _sub_obj_tree_dot_dump(o, output);
3049 elm_widget_tree_dump(const Evas_Object *top)
3052 _sub_obj_tree_dump(top, 0);
3060 elm_widget_tree_dot_dump(const Evas_Object *top,
3064 if (!_elm_widget_is(top))
3066 fprintf(output, "graph " " { node [shape=record];\n");
3067 _sub_obj_tree_dot_dump(top, output);
3068 fprintf(output, "}\n");