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,
73 void (*on_text_set_func)(Evas_Object *obj,
76 const char *(*on_text_get_func)(const Evas_Object *obj,
79 Evas_Coord rx, ry, rw, rh;
85 unsigned int focus_order;
86 Eina_Bool focus_order_on_calc;
88 int child_drag_x_locked;
89 int child_drag_y_locked;
91 Eina_List *edje_signals;
93 Eina_Bool drag_x_locked : 1;
94 Eina_Bool drag_y_locked : 1;
96 Eina_Bool can_focus : 1;
97 Eina_Bool child_can_focus : 1;
98 Eina_Bool focused : 1;
99 Eina_Bool tree_unfocusable : 1;
100 Eina_Bool highlight_ignore : 1;
101 Eina_Bool highlight_in_theme : 1;
102 Eina_Bool disabled : 1;
103 Eina_Bool is_mirrored : 1;
104 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
106 Eina_List *focus_chain;
110 struct _Edje_Signal_Data
114 const char *emission;
119 struct _Elm_Event_Cb_Data
125 /* local subsystem functions */
126 static void _smart_reconfigure(Smart_Data *sd);
127 static void _smart_add(Evas_Object *obj);
128 static void _smart_del(Evas_Object *obj);
129 static void _smart_move(Evas_Object *obj,
132 static void _smart_resize(Evas_Object *obj,
135 static void _smart_show(Evas_Object *obj);
136 static void _smart_hide(Evas_Object *obj);
137 static void _smart_color_set(Evas_Object *obj,
142 static void _smart_clip_set(Evas_Object *obj,
144 static void _smart_clip_unset(Evas_Object *obj);
145 static void _smart_calculate(Evas_Object *obj);
146 static void _smart_init(void);
148 static void _if_focused_revert(Evas_Object *obj,
149 Eina_Bool can_focus_only);
150 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
151 unsigned int *newest_focus_order,
152 Eina_Bool can_focus_only);
154 /* local subsystem globals */
155 static Evas_Smart *_e_smart = NULL;
156 static Eina_List *widtypes = NULL;
158 static unsigned int focus_order = 0;
161 static inline Eina_Bool
162 _elm_widget_is(const Evas_Object *obj)
164 const char *type = evas_object_type_get(obj);
165 return type == SMART_NAME;
168 static inline Eina_Bool
169 _is_focusable(Evas_Object *obj)
171 API_ENTRY return EINA_FALSE;
172 return sd->can_focus || (sd->child_can_focus);
176 _unfocus_parents(Evas_Object *obj)
178 for (; obj; obj = elm_widget_parent_get(obj))
181 if (!sd->focused) return;
187 _focus_parents(Evas_Object *obj)
189 for (; obj; obj = elm_widget_parent_get(obj))
192 if (sd->focused) return;
198 _sub_obj_del(void *data,
201 void *event_info __UNUSED__)
203 Smart_Data *sd = data;
205 if (_elm_widget_is(obj))
207 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
209 if (obj == sd->resize_obj)
210 sd->resize_obj = NULL;
211 else if (obj == sd->hover_obj)
212 sd->hover_obj = NULL;
214 sd->subobjs = eina_list_remove(sd->subobjs, obj);
215 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
219 _sub_obj_hide(void *data __UNUSED__,
222 void *event_info __UNUSED__)
224 elm_widget_focus_hide_handle(obj);
228 _sub_obj_mouse_down(void *data __UNUSED__,
231 void *event_info __UNUSED__)
233 elm_widget_focus_mouse_down_handle(obj);
237 _propagate_x_drag_lock(Evas_Object *obj,
243 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
246 sd2->child_drag_x_locked += dir;
247 _propagate_x_drag_lock(sd->parent_obj, dir);
253 _propagate_y_drag_lock(Evas_Object *obj,
259 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
262 sd2->child_drag_y_locked += dir;
263 _propagate_y_drag_lock(sd->parent_obj, dir);
269 _propagate_event(void *data,
275 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
276 Evas_Event_Flags *event_flags = NULL;
280 case EVAS_CALLBACK_KEY_DOWN:
282 Evas_Event_Key_Down *ev = event_info;
283 event_flags = &(ev->event_flags);
287 case EVAS_CALLBACK_KEY_UP:
289 Evas_Event_Key_Up *ev = event_info;
290 event_flags = &(ev->event_flags);
294 case EVAS_CALLBACK_MOUSE_WHEEL:
296 Evas_Event_Mouse_Wheel *ev = event_info;
297 event_flags = &(ev->event_flags);
305 elm_widget_event_propagate(obj, type, event_info, event_flags);
309 _parent_focus(Evas_Object *obj)
312 if (sd->focused) return;
314 Evas_Object *o = elm_widget_parent_get(obj);
315 sd->focus_order_on_calc = EINA_TRUE;
317 if (o) _parent_focus(o);
319 if (!sd->focus_order_on_calc)
320 return; /* we don't want to override it if by means of any of the
321 callbacks below one gets to calculate our order
325 sd->focus_order = focus_order;
326 sd->focused = EINA_TRUE;
327 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
328 if (sd->focus_func) sd->focus_func(obj);
330 _elm_widget_focus_region_show(obj);
332 sd->focus_order_on_calc = EINA_FALSE;
336 _elm_object_focus_chain_del_cb(void *data,
339 void *event_info __UNUSED__)
341 Smart_Data *sd = data;
343 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
346 // exposed util funcs to elm
348 _elm_widget_type_clear(void)
352 EINA_LIST_FREE(widtypes, ptr)
354 eina_stringshare_del(*ptr);
360 _elm_widget_focus_region_show(const Evas_Object *obj)
362 Evas_Coord x, y, w, h, ox, oy;
368 o = elm_widget_parent_get(obj);
371 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
372 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
376 sd2 = evas_object_smart_data_get(o);
377 if (sd2->focus_region_func)
379 sd2->focus_region_func(o, x, y, w, h);
380 elm_widget_focus_region_get(o, &x, &y, &w, &h);
384 evas_object_geometry_get(o, &px, &py, NULL, NULL);
390 o = elm_widget_parent_get(o);
395 * @defgroup Widget Widget
398 * Exposed api for making widgets
401 elm_widget_type_register(const char **ptr)
403 widtypes = eina_list_append(widtypes, (void *)ptr);
407 * @defgroup Widget Widget
410 * Disposed api for making widgets
413 elm_widget_type_unregister(const char **ptr)
415 widtypes = eina_list_remove(widtypes, (void *)ptr);
419 elm_widget_api_check(int ver)
421 if (ver != ELM_INTERNAL_API_VERSION)
423 CRITICAL("Elementary widget api versions do not match");
430 elm_widget_add(Evas *evas)
434 obj = evas_object_smart_add(evas, _e_smart);
435 elm_widget_mirrored_set(obj, elm_mirrored_get());
440 elm_widget_del_hook_set(Evas_Object *obj,
441 void (*func)(Evas_Object *obj))
448 elm_widget_del_pre_hook_set(Evas_Object *obj,
449 void (*func)(Evas_Object *obj))
452 sd->del_pre_func = func;
456 elm_widget_focus_hook_set(Evas_Object *obj,
457 void (*func)(Evas_Object *obj))
460 sd->focus_func = func;
464 elm_widget_activate_hook_set(Evas_Object *obj,
465 void (*func)(Evas_Object *obj))
468 sd->activate_func = func;
472 elm_widget_disable_hook_set(Evas_Object *obj,
473 void (*func)(Evas_Object *obj))
476 sd->disable_func = func;
480 elm_widget_theme_hook_set(Evas_Object *obj,
481 void (*func)(Evas_Object *obj))
484 sd->theme_func = func;
488 elm_widget_event_hook_set(Evas_Object *obj,
489 Eina_Bool (*func)(Evas_Object *obj,
491 Evas_Callback_Type type,
495 sd->event_func = func;
499 elm_widget_text_set_hook_set(Evas_Object *obj,
500 void (*func)(Evas_Object *obj,
505 sd->on_text_set_func = func;
509 elm_widget_text_get_hook_set(Evas_Object *obj,
510 const char *(*func)(const Evas_Object *obj,
514 sd->on_text_get_func = func;
518 elm_widget_changed_hook_set(Evas_Object *obj,
519 void (*func)(Evas_Object *obj))
522 sd->changed_func = func;
526 elm_widget_signal_emit_hook_set(Evas_Object *obj,
527 void (*func)(Evas_Object *obj,
528 const char *emission,
532 sd->signal_func = func;
536 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
537 void (*func)(Evas_Object *obj,
538 const char *emission,
540 Edje_Signal_Cb func_cb,
544 sd->callback_add_func = func;
548 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
549 void (*func)(Evas_Object *obj,
550 const char *emission,
552 Edje_Signal_Cb func_cb,
556 sd->callback_del_func = func;
560 elm_widget_theme(Evas_Object *obj)
568 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
569 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
570 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
571 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
572 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
573 if (sd->theme_func) sd->theme_func(obj);
577 elm_widget_theme_specific(Evas_Object *obj,
585 Elm_Theme *th2, *thdef;
588 thdef = elm_theme_default_get();
593 if (!th2) th2 = thdef;
601 if (th2 == thdef) break;
602 th2 = th2->ref_theme;
603 if (!th2) th2 = thdef;
607 EINA_LIST_FOREACH(sd->subobjs, l, child)
608 elm_widget_theme_specific(child, th, force);
609 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
610 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
611 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
612 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
613 if (sd->theme_func) sd->theme_func(obj);
619 * Set hook to get next object in object focus chain.
621 * @param obj The widget object.
622 * @param func The hook to be used with this widget.
627 elm_widget_focus_next_hook_set(Evas_Object *obj,
628 Eina_Bool (*func)(const Evas_Object *obj,
629 Elm_Focus_Direction dir,
633 sd->focus_next_func = func;
637 * Returns the widget's mirrored mode.
639 * @param obj The widget.
640 * @return mirrored mode of the object.
644 elm_widget_mirrored_get(const Evas_Object *obj)
646 API_ENTRY return EINA_FALSE;
647 return sd->is_mirrored;
651 * Sets the widget's mirrored mode.
653 * @param obj The widget.
654 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
657 elm_widget_mirrored_set(Evas_Object *obj,
661 if (sd->is_mirrored != mirrored)
663 sd->is_mirrored = mirrored;
664 elm_widget_theme(obj);
670 * Resets the mirrored mode from the system mirror mode for widgets that are in
671 * automatic mirroring mode. This function does not call elm_widget_theme.
673 * @param obj The widget.
674 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
677 _elm_widget_mirrored_reload(Evas_Object *obj)
680 Eina_Bool mirrored = elm_mirrored_get();
681 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
683 sd->is_mirrored = mirrored;
688 * Returns the widget's mirrored mode setting.
690 * @param obj The widget.
691 * @return mirrored mode setting of the object.
695 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
697 API_ENTRY return EINA_FALSE;
698 return sd->mirrored_auto_mode;
702 * Sets the widget's mirrored mode setting.
703 * When widget in automatic mode, it follows the system mirrored mode set by
704 * elm_mirrored_set().
705 * @param obj The widget.
706 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
709 elm_widget_mirrored_automatic_set(Evas_Object *obj,
713 if (sd->mirrored_auto_mode != automatic)
715 sd->mirrored_auto_mode = automatic;
719 elm_widget_mirrored_set(obj, elm_mirrored_get());
725 elm_widget_on_focus_hook_set(Evas_Object *obj,
726 void (*func)(void *data,
731 sd->on_focus_func = func;
732 sd->on_focus_data = data;
736 elm_widget_on_change_hook_set(Evas_Object *obj,
737 void (*func)(void *data,
742 sd->on_change_func = func;
743 sd->on_change_data = data;
747 elm_widget_on_show_region_hook_set(Evas_Object *obj,
748 void (*func)(void *data,
753 sd->on_show_region_func = func;
754 sd->on_show_region_data = data;
760 * Set the hook to use to show the focused region.
762 * Whenever a new widget gets focused or it's needed to show the focused
763 * area of the current one, this hook will be called on objects that may
764 * want to move their children into their visible area.
765 * The area given in the hook function is relative to the @p obj widget.
767 * @param obj The widget object
768 * @param func The function to call to show the specified area.
773 elm_widget_focus_region_hook_set(Evas_Object *obj,
774 void (*func)(Evas_Object *obj,
781 sd->focus_region_func = func;
787 * Set the hook to retrieve the focused region of a widget.
789 * This hook will be called by elm_widget_focus_region_get() whenever
790 * it's needed to get the focused area of a widget. The area must be relative
791 * to the widget itself and if no hook is set, it will default to the entire
794 * @param obj The widget object
795 * @param func The function used to retrieve the focus region.
800 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
801 void (*func)(const Evas_Object *obj,
808 sd->on_focus_region_func = func;
812 elm_widget_data_set(Evas_Object *obj,
820 elm_widget_data_get(const Evas_Object *obj)
822 API_ENTRY return NULL;
827 elm_widget_sub_object_add(Evas_Object *obj,
831 double scale, pscale = elm_widget_scale_get(sobj);
832 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
833 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
835 if (_elm_widget_is(sobj))
837 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
840 if (sd2->parent_obj == obj)
843 elm_widget_sub_object_del(sd2->parent_obj, sobj);
844 sd2->parent_obj = obj;
845 if (!sd->child_can_focus && (_is_focusable(sobj)))
846 sd->child_can_focus = EINA_TRUE;
851 void *data = evas_object_data_get(sobj, "elm-parent");
854 if (data == obj) return;
855 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
860 sd->subobjs = eina_list_append(sd->subobjs, sobj);
861 evas_object_data_set(sobj, "elm-parent", obj);
862 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
863 if (_elm_widget_is(sobj))
864 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
865 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
866 scale = elm_widget_scale_get(sobj);
867 th = elm_widget_theme_get(sobj);
868 mirrored = elm_widget_mirrored_get(sobj);
869 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
870 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
874 elm_widget_sub_object_del(Evas_Object *obj,
877 Evas_Object *sobj_parent;
881 sobj_parent = evas_object_data_del(sobj, "elm-parent");
882 if (sobj_parent != obj)
884 static int abort_on_warn = -1;
885 ERR("removing sub object %p from parent %p, "
886 "but elm-parent is different %p!",
887 sobj, obj, sobj_parent);
888 if (EINA_UNLIKELY(abort_on_warn == -1))
890 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
891 else abort_on_warn = 0;
893 if (abort_on_warn == 1) abort();
895 if (_elm_widget_is(sobj))
897 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
900 sd2->parent_obj = NULL;
901 if (sd2->resize_obj == sobj)
902 sd2->resize_obj = NULL;
904 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
907 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
908 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
909 if ((sd->child_can_focus) && (_is_focusable(sobj)))
913 sd->child_can_focus = EINA_FALSE;
914 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
916 if (_is_focusable(subobj))
918 sd->child_can_focus = EINA_TRUE;
925 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
926 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
928 if (_elm_widget_is(sobj))
929 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
931 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
935 elm_widget_resize_object_set(Evas_Object *obj,
939 // orphan previous resize obj
942 evas_object_clip_unset(sd->resize_obj);
943 evas_object_data_del(sd->resize_obj, "elm-parent");
944 if (_elm_widget_is(sd->resize_obj))
946 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
947 if (sd2) sd2->parent_obj = NULL;
948 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
951 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
953 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
954 _sub_obj_mouse_down, sd);
955 evas_object_smart_member_del(sd->resize_obj);
956 if (_elm_widget_is(sd->resize_obj))
958 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
961 // orphan new resize obj
964 evas_object_data_del(sobj, "elm-parent");
965 if (_elm_widget_is(sobj))
967 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
968 if (sd2) sd2->parent_obj = NULL;
969 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
972 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
974 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
975 _sub_obj_mouse_down, sd);
976 evas_object_smart_member_del(sobj);
977 if (_elm_widget_is(sobj))
979 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
982 // set the resize obj up
983 sd->resize_obj = sobj;
986 if (_elm_widget_is(sd->resize_obj))
988 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
989 if (sd2) sd2->parent_obj = obj;
990 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
993 evas_object_clip_set(sobj, evas_object_clip_get(obj));
994 evas_object_smart_member_add(sobj, obj);
995 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
997 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
998 _sub_obj_mouse_down, sd);
999 _smart_reconfigure(sd);
1000 evas_object_data_set(sobj, "elm-parent", obj);
1001 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
1002 if (_elm_widget_is(sobj))
1004 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
1010 elm_widget_hover_object_set(Evas_Object *obj,
1016 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1019 sd->hover_obj = sobj;
1022 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1024 _smart_reconfigure(sd);
1029 elm_widget_can_focus_set(Evas_Object *obj,
1030 Eina_Bool can_focus)
1033 sd->can_focus = can_focus;
1036 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1038 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1039 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1041 (void *)(long)EVAS_CALLBACK_KEY_UP);
1042 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1044 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1048 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1050 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1052 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1058 elm_widget_can_focus_get(const Evas_Object *obj)
1060 API_ENTRY return EINA_FALSE;
1061 return sd->can_focus;
1065 elm_widget_child_can_focus_get(const Evas_Object *obj)
1067 API_ENTRY return EINA_FALSE;
1068 return sd->child_can_focus;
1074 * This API makes the widget object and its children to be unfocusable.
1076 * This API can be helpful for an object to be deleted.
1077 * When an object will be deleted soon, it and its children may not
1078 * want to get focus (by focus reverting or by other focus controls).
1079 * Then, just use this API before deleting.
1081 * @param obj The widget root of sub-tree
1082 * @param tree_unfocusable If true, set the object sub-tree as unfocusable
1087 elm_widget_tree_unfocusable_set(Evas_Object *obj,
1088 Eina_Bool tree_unfocusable)
1092 if (sd->tree_unfocusable == tree_unfocusable) return;
1093 sd->tree_unfocusable = !!tree_unfocusable;
1094 elm_widget_focus_tree_unfocusable_handle(obj);
1100 * This returns true, if the object sub-tree is unfocusable.
1102 * @param obj The widget root of sub-tree
1103 * @return EINA_TRUE if the object sub-tree is unfocusable
1108 elm_widget_tree_unfocusable_get(const Evas_Object *obj)
1110 API_ENTRY return EINA_FALSE;
1111 return sd->tree_unfocusable;
1115 elm_widget_highlight_ignore_set(Evas_Object *obj,
1119 sd->highlight_ignore = !!ignore;
1123 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1125 API_ENTRY return EINA_FALSE;
1126 return sd->highlight_ignore;
1130 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1131 Eina_Bool highlight)
1134 sd->highlight_in_theme = !!highlight;
1135 /* FIXME: if focused, it should switch from one mode to the other */
1139 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1141 API_ENTRY return EINA_FALSE;
1142 return sd->highlight_in_theme;
1146 elm_widget_focus_get(const Evas_Object *obj)
1148 API_ENTRY return EINA_FALSE;
1153 elm_widget_focused_object_get(const Evas_Object *obj)
1155 const Evas_Object *subobj;
1157 API_ENTRY return NULL;
1159 if (!sd->focused) return NULL;
1160 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1162 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1163 if (fobj) return fobj;
1165 return (Evas_Object *)obj;
1169 elm_widget_top_get(const Evas_Object *obj)
1171 API_ENTRY return NULL;
1172 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1173 return (Evas_Object *)obj;
1177 elm_widget_is(const Evas_Object *obj)
1179 return _elm_widget_is(obj);
1183 elm_widget_parent_widget_get(const Evas_Object *obj)
1185 Evas_Object *parent;
1187 if (_elm_widget_is(obj))
1189 Smart_Data *sd = evas_object_smart_data_get(obj);
1190 if (!sd) return NULL;
1191 parent = sd->parent_obj;
1195 parent = evas_object_data_get(obj, "elm-parent");
1196 if (!parent) parent = evas_object_smart_parent_get(obj);
1201 Evas_Object *elm_parent;
1202 if (_elm_widget_is(parent)) break;
1203 elm_parent = evas_object_data_get(parent, "elm-parent");
1204 if (elm_parent) parent = elm_parent;
1205 else parent = evas_object_smart_parent_get(parent);
1211 elm_widget_event_callback_add(Evas_Object *obj,
1216 EINA_SAFETY_ON_NULL_RETURN(func);
1217 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1220 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1224 elm_widget_event_callback_del(Evas_Object *obj,
1228 API_ENTRY return NULL;
1229 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1231 Elm_Event_Cb_Data *ecd;
1232 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1233 if ((ecd->func == func) && (ecd->data == data))
1236 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1237 return (void *)data;
1243 elm_widget_event_propagate(Evas_Object *obj,
1244 Evas_Callback_Type type,
1246 Evas_Event_Flags *event_flags)
1248 API_ENTRY return EINA_FALSE; //TODO reduce.
1249 if (!_elm_widget_is(obj)) return EINA_FALSE;
1250 Evas_Object *parent = obj;
1251 Elm_Event_Cb_Data *ecd;
1252 Eina_List *l, *l_prev;
1255 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1257 sd = evas_object_smart_data_get(parent);
1258 if ((!sd) || (!_elm_widget_is(obj)))
1259 return EINA_FALSE; //Not Elm Widget
1261 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1264 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1266 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1267 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1270 parent = sd->parent_obj;
1279 * Set custom focus chain.
1281 * This function i set one new and overwrite any previous custom focus chain
1282 * with the list of objects. The previous list will be deleted and this list
1283 * will be managed. After setted, don't modity it.
1285 * @note On focus cycle, only will be evaluated children of this container.
1287 * @param obj The container widget
1288 * @param objs Chain of objects to pass focus
1292 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1296 if (!sd->focus_next_func)
1299 elm_widget_focus_custom_chain_unset(obj);
1304 EINA_LIST_FOREACH(objs, l, o)
1306 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1307 _elm_object_focus_chain_del_cb, sd);
1310 sd->focus_chain = objs;
1316 * Get custom focus chain
1318 * @param obj The container widget
1321 EAPI const Eina_List *
1322 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1324 API_ENTRY return NULL;
1325 return (const Eina_List *)sd->focus_chain;
1331 * Unset custom focus chain
1333 * @param obj The container widget
1337 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1340 Eina_List *l, *l_next;
1343 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1345 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1346 _elm_object_focus_chain_del_cb, sd);
1347 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1354 * Append object to custom focus chain.
1356 * @note If relative_child equal to NULL or not in custom chain, the object
1357 * will be added in end.
1359 * @note On focus cycle, only will be evaluated children of this container.
1361 * @param obj The container widget
1362 * @param child The child to be added in custom chain
1363 * @param relative_child The relative object to position the child
1367 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1369 Evas_Object *relative_child)
1372 EINA_SAFETY_ON_NULL_RETURN(child);
1373 if (!sd->focus_next_func)
1376 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1377 _elm_object_focus_chain_del_cb, sd);
1379 if (!relative_child)
1381 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1385 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1392 * Prepend object to custom focus chain.
1394 * @note If relative_child equal to NULL or not in custom chain, the object
1395 * will be added in begin.
1397 * @note On focus cycle, only will be evaluated children of this container.
1399 * @param obj The container widget
1400 * @param child The child to be added in custom chain
1401 * @param relative_child The relative object to position the child
1405 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1407 Evas_Object *relative_child)
1410 EINA_SAFETY_ON_NULL_RETURN(child);
1411 if (!sd->focus_next_func)
1414 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1415 _elm_object_focus_chain_del_cb, sd);
1417 if (!relative_child)
1419 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1423 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1430 * Give focus to next object in object tree.
1432 * Give focus to next object in focus chain of one object sub-tree.
1433 * If the last object of chain already have focus, the focus will go to the
1434 * first object of chain.
1436 * @param obj The widget root of sub-tree
1437 * @param dir Direction to cycle the focus
1442 elm_widget_focus_cycle(Evas_Object *obj,
1443 Elm_Focus_Direction dir)
1445 Evas_Object *target = NULL;
1446 if (!_elm_widget_is(obj))
1448 elm_widget_focus_next_get(obj, dir, &target);
1450 elm_widget_focus_steal(target);
1456 * Give focus to near object in one direction.
1458 * Give focus to near object in direction of one object.
1459 * If none focusable object in given direction, the focus will not change.
1461 * @param obj The reference widget
1462 * @param x Horizontal component of direction to focus
1463 * @param y Vertical component of direction to focus
1468 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1478 * Get next object in focus chain of object tree.
1480 * Get next object in focus chain of one object sub-tree.
1481 * Return the next object by reference. If don't have any candidate to receive
1482 * focus before chain end, the first candidate will be returned.
1484 * @param obj The widget root of sub-tree
1485 * @param dir Direction os focus chain
1486 * @param next The next object in focus chain
1487 * @return EINA_TRUE if don't need focus chain restart/loop back
1488 * to use 'next' obj.
1493 elm_widget_focus_next_get(const Evas_Object *obj,
1494 Elm_Focus_Direction dir,
1501 API_ENTRY return EINA_FALSE;
1503 /* Ignore if disabled */
1504 if ((!evas_object_visible_get(obj))
1505 || (elm_widget_disabled_get(obj))
1506 || (elm_widget_tree_unfocusable_get(obj)))
1510 if (sd->focus_next_func)
1511 return sd->focus_next_func(obj, dir, next);
1513 if (!elm_widget_can_focus_get(obj))
1517 *next = (Evas_Object *)obj;
1518 return !elm_widget_focus_get(obj);
1524 * Get next object in focus chain of object tree in list.
1526 * Get next object in focus chain of one object sub-tree ordered by one list.
1527 * Return the next object by reference. If don't have any candidate to receive
1528 * focus before list end, the first candidate will be returned.
1530 * @param obj The widget root of sub-tree
1531 * @param dir Direction os focus chain
1532 * @param items list with ordered objects
1533 * @param list_data_get function to get the object from one item of list
1534 * @param next The next object in focus chain
1535 * @return EINA_TRUE if don't need focus chain restart/loop back
1536 * to use 'next' obj.
1541 elm_widget_focus_list_next_get(const Evas_Object *obj,
1542 const Eina_List *items,
1543 void *(*list_data_get)(const Eina_List * list),
1544 Elm_Focus_Direction dir,
1547 Eina_List *(*list_next)(const Eina_List * list);
1553 if (!_elm_widget_is(obj))
1560 if (dir == ELM_FOCUS_PREVIOUS)
1562 items = eina_list_last(items);
1563 list_next = eina_list_prev;
1565 else if (dir == ELM_FOCUS_NEXT)
1566 list_next = eina_list_next;
1570 const Eina_List *l = items;
1572 /* Recovery last focused sub item */
1573 if (elm_widget_focus_get(obj))
1574 for (; l; l = list_next(l))
1576 Evas_Object *cur = list_data_get(l);
1577 if (elm_widget_focus_get(cur)) break;
1580 const Eina_List *start = l;
1581 Evas_Object *to_focus = NULL;
1583 /* Interate sub items */
1584 /* Go to end of list */
1585 for (; l; l = list_next(l))
1587 Evas_Object *tmp = NULL;
1588 Evas_Object *cur = list_data_get(l);
1590 if (elm_widget_parent_get(cur) != obj)
1593 /* Try Focus cycle in subitem */
1594 if (elm_widget_focus_next_get(cur, dir, &tmp))
1599 else if ((tmp) && (!to_focus))
1605 /* Get First possible */
1606 for (; l != start; l = list_next(l))
1608 Evas_Object *tmp = NULL;
1609 Evas_Object *cur = list_data_get(l);
1611 if (elm_widget_parent_get(cur) != obj)
1614 /* Try Focus cycle in subitem */
1615 elm_widget_focus_next_get(cur, dir, &tmp);
1628 elm_widget_signal_emit(Evas_Object *obj,
1629 const char *emission,
1633 if (!sd->signal_func) return;
1634 sd->signal_func(obj, emission, source);
1638 _edje_signal_callback(void *data,
1639 Evas_Object *obj __UNUSED__,
1640 const char *emission,
1643 Edje_Signal_Data *esd = data;
1644 esd->func(esd->data, esd->obj, emission, source);
1648 elm_widget_signal_callback_add(Evas_Object *obj,
1649 const char *emission,
1651 Edje_Signal_Cb func,
1654 Edje_Signal_Data *esd;
1656 if (!sd->callback_add_func) return;
1657 EINA_SAFETY_ON_NULL_RETURN(func);
1659 esd = ELM_NEW(Edje_Signal_Data);
1664 esd->emission = eina_stringshare_add(emission);
1665 esd->source = eina_stringshare_add(source);
1667 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1668 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1672 elm_widget_signal_callback_del(Evas_Object *obj,
1673 const char *emission,
1675 Edje_Signal_Cb func)
1677 Edje_Signal_Data *esd;
1680 API_ENTRY return NULL;
1681 if (!sd->callback_del_func) return NULL;
1683 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1685 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1686 (!strcmp(esd->source, source)))
1688 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1689 eina_stringshare_del(esd->emission);
1690 eina_stringshare_del(esd->source);
1696 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1701 elm_widget_focus_set(Evas_Object *obj,
1708 sd->focus_order = focus_order;
1709 sd->focused = EINA_TRUE;
1710 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1714 sd->focus_func(obj);
1721 if ((_is_focusable(sd->resize_obj)) &&
1722 (!elm_widget_disabled_get(sd->resize_obj)))
1724 elm_widget_focus_set(sd->resize_obj, first);
1730 EINA_LIST_FOREACH(sd->subobjs, l, child)
1732 if ((_is_focusable(child)) &&
1733 (!elm_widget_disabled_get(child)))
1735 elm_widget_focus_set(child, first);
1745 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1747 if ((_is_focusable(child)) &&
1748 (!elm_widget_disabled_get(child)))
1750 elm_widget_focus_set(child, first);
1756 if ((_is_focusable(sd->resize_obj)) &&
1757 (!elm_widget_disabled_get(sd->resize_obj)))
1759 elm_widget_focus_set(sd->resize_obj, first);
1767 elm_widget_parent_get(const Evas_Object *obj)
1769 API_ENTRY return NULL;
1770 return sd->parent_obj;
1774 elm_widget_focused_object_clear(Evas_Object *obj)
1777 if (!sd->focused) return;
1778 if (elm_widget_focus_get(sd->resize_obj))
1779 elm_widget_focused_object_clear(sd->resize_obj);
1784 EINA_LIST_FOREACH(sd->subobjs, l, child)
1786 if (elm_widget_focus_get(child))
1788 elm_widget_focused_object_clear(child);
1793 sd->focused = EINA_FALSE;
1794 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1795 if (sd->focus_func) sd->focus_func(obj);
1799 elm_widget_focus_steal(Evas_Object *obj)
1801 Evas_Object *parent, *o;
1804 if (sd->focused) return;
1805 if (sd->disabled) return;
1806 if (!sd->can_focus) return;
1807 if (sd->tree_unfocusable) return;
1811 o = elm_widget_parent_get(parent);
1813 sd = evas_object_smart_data_get(o);
1814 if (sd->disabled || sd->tree_unfocusable) return;
1815 if (sd->focused) break;
1818 if (!elm_widget_parent_get(parent))
1819 elm_widget_focused_object_clear(parent);
1822 parent = elm_widget_parent_get(parent);
1823 sd = evas_object_smart_data_get(parent);
1824 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1825 elm_widget_focused_object_clear(sd->resize_obj);
1830 EINA_LIST_FOREACH(sd->subobjs, l, child)
1832 if (elm_widget_focus_get(child))
1834 elm_widget_focused_object_clear(child);
1845 elm_widget_focus_restore(Evas_Object *obj)
1847 Evas_Object *newest = NULL;
1848 unsigned int newest_focus_order = 0;
1851 newest = _newest_focus_order_get(obj, &newest_focus_order, EINA_TRUE);
1854 elm_object_unfocus(newest);
1855 elm_object_focus(newest);
1860 elm_widget_activate(Evas_Object *obj)
1863 elm_widget_change(obj);
1864 if (sd->activate_func) sd->activate_func(obj);
1868 elm_widget_change(Evas_Object *obj)
1871 elm_widget_change(elm_widget_parent_get(obj));
1872 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1876 elm_widget_disabled_set(Evas_Object *obj,
1881 if (sd->disabled == disabled) return;
1882 sd->disabled = !!disabled;
1883 elm_widget_focus_disabled_handle(obj);
1884 if (sd->disable_func) sd->disable_func(obj);
1888 elm_widget_disabled_get(const Evas_Object *obj)
1891 return sd->disabled;
1895 elm_widget_show_region_set(Evas_Object *obj,
1900 Eina_Bool forceshow)
1902 Evas_Object *parent_obj, *child_obj;
1903 Evas_Coord px, py, cx, cy;
1906 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1907 && (w == sd->rw) && (h == sd->rh)) return;
1912 if (sd->on_show_region_func)
1913 sd->on_show_region_func(sd->on_show_region_data, obj);
1917 parent_obj = sd->parent_obj;
1918 child_obj = sd->obj;
1919 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1920 sd = evas_object_smart_data_get(parent_obj);
1923 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1924 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1933 if (sd->on_show_region_func)
1935 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1942 elm_widget_show_region_get(const Evas_Object *obj,
1958 * Get the focus region of the given widget.
1960 * The focus region is the area of a widget that should brought into the
1961 * visible area when the widget is focused. Mostly used to show the part of
1962 * an entry where the cursor is, for example. The area returned is relative
1963 * to the object @p obj.
1964 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1965 * function will return the full size of the object.
1967 * @param obj The widget object
1968 * @param x Where to store the x coordinate of the area
1969 * @param y Where to store the y coordinate of the area
1970 * @param w Where to store the width of the area
1971 * @param h Where to store the height of the area
1976 elm_widget_focus_region_get(const Evas_Object *obj,
1986 sd = evas_object_smart_data_get(obj);
1987 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1989 evas_object_geometry_get(obj, NULL, NULL, w, h);
1994 sd->on_focus_region_func(obj, x, y, w, h);
1998 elm_widget_scroll_hold_push(Evas_Object *obj)
2002 if (sd->scroll_hold == 1)
2003 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
2004 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
2005 // FIXME: on delete/reparent hold pop
2009 elm_widget_scroll_hold_pop(Evas_Object *obj)
2013 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
2014 if (!sd->scroll_hold)
2015 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
2016 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
2020 elm_widget_scroll_hold_get(const Evas_Object *obj)
2023 return sd->scroll_hold;
2027 elm_widget_scroll_freeze_push(Evas_Object *obj)
2030 sd->scroll_freeze++;
2031 if (sd->scroll_freeze == 1)
2032 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
2033 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
2034 // FIXME: on delete/reparent freeze pop
2038 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2041 sd->scroll_freeze--;
2042 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2043 if (!sd->scroll_freeze)
2044 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2045 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2049 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2052 return sd->scroll_freeze;
2056 elm_widget_scale_set(Evas_Object *obj,
2060 if (scale <= 0.0) scale = 0.0;
2061 if (sd->scale != scale)
2064 elm_widget_theme(obj);
2069 elm_widget_scale_get(const Evas_Object *obj)
2071 API_ENTRY return 1.0;
2072 // FIXME: save walking up the tree by storing/caching parent scale
2073 if (sd->scale == 0.0)
2076 return elm_widget_scale_get(sd->parent_obj);
2084 elm_widget_theme_set(Evas_Object *obj,
2088 if (sd->theme != th)
2090 if (sd->theme) elm_theme_free(sd->theme);
2093 elm_widget_theme(obj);
2098 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2102 if (!sd->on_text_set_func)
2105 sd->on_text_set_func(obj, item, label);
2109 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2111 API_ENTRY return NULL;
2113 if (!sd->on_text_get_func)
2116 return sd->on_text_get_func(obj, item);
2120 elm_widget_theme_get(const Evas_Object *obj)
2122 API_ENTRY return NULL;
2126 return elm_widget_theme_get(sd->parent_obj);
2134 elm_widget_style_set(Evas_Object *obj,
2139 if (eina_stringshare_replace(&sd->style, style))
2140 elm_widget_theme(obj);
2144 elm_widget_style_get(const Evas_Object *obj)
2146 API_ENTRY return NULL;
2147 if (sd->style) return sd->style;
2152 elm_widget_type_set(Evas_Object *obj,
2156 eina_stringshare_replace(&sd->type, type);
2160 elm_widget_type_get(const Evas_Object *obj)
2162 API_ENTRY return NULL;
2163 if (sd->type) return sd->type;
2168 elm_widget_tooltip_add(Evas_Object *obj,
2172 sd->tooltips = eina_list_append(sd->tooltips, tt);
2176 elm_widget_tooltip_del(Evas_Object *obj,
2180 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2184 elm_widget_cursor_add(Evas_Object *obj,
2188 sd->cursors = eina_list_append(sd->cursors, cur);
2192 elm_widget_cursor_del(Evas_Object *obj,
2196 sd->cursors = eina_list_remove(sd->cursors, cur);
2200 elm_widget_drag_lock_x_set(Evas_Object *obj,
2204 if (sd->drag_x_locked == lock) return;
2205 sd->drag_x_locked = lock;
2206 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2207 else _propagate_x_drag_lock(obj, -1);
2211 elm_widget_drag_lock_y_set(Evas_Object *obj,
2215 if (sd->drag_y_locked == lock) return;
2216 sd->drag_y_locked = lock;
2217 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2218 else _propagate_y_drag_lock(obj, -1);
2222 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2224 API_ENTRY return EINA_FALSE;
2225 return sd->drag_x_locked;
2229 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2231 API_ENTRY return EINA_FALSE;
2232 return sd->drag_y_locked;
2236 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2239 return sd->child_drag_x_locked;
2243 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2246 return sd->child_drag_y_locked;
2250 elm_widget_theme_object_set(Evas_Object *obj,
2253 const char *welement,
2256 API_ENTRY return EINA_FALSE;
2257 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2261 elm_widget_type_check(const Evas_Object *obj,
2264 const char *provided, *expected = "(unknown)";
2265 static int abort_on_warn = -1;
2266 provided = elm_widget_type_get(obj);
2267 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2268 if (type) expected = type;
2269 if ((!provided) || (!provided[0]))
2271 provided = evas_object_type_get(obj);
2272 if ((!provided) || (!provided[0]))
2273 provided = "(unknown)";
2275 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2276 if (abort_on_warn == -1)
2278 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2279 else abort_on_warn = 0;
2281 if (abort_on_warn == 1) abort();
2288 * Split string in words
2290 * @param str Source string
2291 * @return List of const words
2293 * @see elm_widget_stringlist_free()
2297 elm_widget_stringlist_get(const char *str)
2299 Eina_List *list = NULL;
2301 if (!str) return NULL;
2302 for (b = s = str; 1; s++)
2304 if ((*s == ' ') || (!*s))
2306 char *t = malloc(s - b + 1);
2309 strncpy(t, b, s - b);
2311 list = eina_list_append(list, eina_stringshare_add(t));
2322 elm_widget_stringlist_free(Eina_List *list)
2325 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2329 elm_widget_focus_hide_handle(Evas_Object *obj)
2331 _if_focused_revert(obj, EINA_TRUE);
2335 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2337 Evas_Object *o = obj;
2340 if (_elm_widget_is(o)) break;
2341 o = evas_object_smart_parent_get(o);
2345 if (!_is_focusable(o)) return;
2346 elm_widget_focus_steal(o);
2350 elm_widget_focus_tree_unfocusable_handle(Evas_Object *obj)
2354 if (!elm_widget_parent_get(obj))
2355 elm_widget_focused_object_clear(obj);
2357 _if_focused_revert(obj, EINA_TRUE);
2361 elm_widget_focus_disabled_handle(Evas_Object *obj)
2365 elm_widget_focus_tree_unfocusable_handle(obj);
2371 * Allocate a new Elm_Widget_Item-derived structure.
2373 * The goal of this structure is to provide common ground for actions
2374 * that a widget item have, such as the owner widget, callback to
2375 * notify deletion, data pointer and maybe more.
2377 * @param widget the owner widget that holds this item, must be an elm_widget!
2378 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2379 * be used to allocate memory.
2381 * @return allocated memory that is already zeroed out, or NULL on errors.
2383 * @see elm_widget_item_new() convenience macro.
2384 * @see elm_widget_item_del() to release memory.
2387 EAPI Elm_Widget_Item *
2388 _elm_widget_item_new(Evas_Object *widget,
2391 if (!_elm_widget_is(widget))
2394 Elm_Widget_Item *item;
2396 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2397 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2399 item = calloc(1, alloc_size);
2400 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2402 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2403 item->widget = widget;
2410 * Releases widget item memory, calling back del_cb() if it exists.
2412 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2413 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2414 * this function and then unset it, thus being useful for 2 step
2415 * cleanup whenever the del_cb may use any of the data that must be
2416 * deleted from item.
2418 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2421 * @param item a valid #Elm_Widget_Item to be deleted.
2422 * @see elm_widget_item_del() convenience macro.
2426 _elm_widget_item_del(Elm_Widget_Item *item)
2428 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2431 item->del_cb((void *)item->data, item->widget, item);
2434 evas_object_del(item->view);
2436 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2443 * Notify object will be deleted without actually deleting it.
2445 * This function will callback Elm_Widget_Item::del_cb if it is set
2446 * and then unset it so it is not called twice (ie: from
2447 * elm_widget_item_del()).
2449 * @param item a valid #Elm_Widget_Item to be notified
2450 * @see elm_widget_item_pre_notify_del() convenience macro.
2454 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2456 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2457 if (!item->del_cb) return;
2458 item->del_cb((void *)item->data, item->widget, item);
2459 item->del_cb = NULL;
2465 * Set the function to notify when item is being deleted.
2467 * This function will complain if there was a callback set already,
2468 * however it will set the new one.
2470 * The callback will be called from elm_widget_item_pre_notify_del()
2471 * or elm_widget_item_del() will be called with:
2472 * - data: the Elm_Widget_Item::data value.
2473 * - obj: the Elm_Widget_Item::widget evas object.
2474 * - event_info: the item being deleted.
2476 * @param item a valid #Elm_Widget_Item to be notified
2477 * @see elm_widget_item_del_cb_set() convenience macro.
2481 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2482 Evas_Smart_Cb del_cb)
2484 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2486 if ((item->del_cb) && (item->del_cb != del_cb))
2487 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2488 item->del_cb, item, del_cb);
2490 item->del_cb = del_cb;
2496 * Set user-data in this item.
2498 * User data may be used to identify this item or just store any
2499 * application data. It is automatically given as the first parameter
2500 * of the deletion notify callback.
2502 * @param item a valid #Elm_Widget_Item to store data in.
2503 * @param data user data to store.
2504 * @see elm_widget_item_del_cb_set() convenience macro.
2508 _elm_widget_item_data_set(Elm_Widget_Item *item,
2511 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2512 if ((item->data) && (item->data != data))
2513 DBG("Replacing item %p data %p with %p", item, item->data, data);
2520 * Retrieves user-data of this item.
2522 * @param item a valid #Elm_Widget_Item to get data from.
2523 * @see elm_widget_item_data_set()
2527 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2529 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2530 return (void *)item->data;
2533 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2535 struct _Elm_Widget_Item_Tooltip
2537 Elm_Widget_Item *item;
2538 Elm_Tooltip_Item_Content_Cb func;
2539 Evas_Smart_Cb del_cb;
2543 static Evas_Object *
2544 _elm_widget_item_tooltip_label_create(void *data,
2546 void *item __UNUSED__)
2548 Evas_Object *label = elm_label_add(obj);
2551 elm_object_style_set(label, "tooltip");
2552 elm_object_text_set(label, data);
2557 _elm_widget_item_tooltip_label_del_cb(void *data,
2558 Evas_Object *obj __UNUSED__,
2559 void *event_info __UNUSED__)
2561 eina_stringshare_del(data);
2567 * Set the text to be shown in the widget item.
2569 * @param item Target item
2570 * @param text The text to set in the content
2572 * Setup the text as tooltip to object. The item can have only one tooltip,
2573 * so any previous tooltip data is removed.
2578 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2581 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2582 EINA_SAFETY_ON_NULL_RETURN(text);
2584 text = eina_stringshare_add(text);
2585 _elm_widget_item_tooltip_content_cb_set
2586 (item, _elm_widget_item_tooltip_label_create, text,
2587 _elm_widget_item_tooltip_label_del_cb);
2590 static Evas_Object *
2591 _elm_widget_item_tooltip_create(void *data,
2594 Elm_Widget_Item_Tooltip *wit = data;
2595 return wit->func((void *)wit->data, obj, wit->item);
2599 _elm_widget_item_tooltip_del_cb(void *data,
2601 void *event_info __UNUSED__)
2603 Elm_Widget_Item_Tooltip *wit = data;
2604 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2611 * Set the content to be shown in the tooltip item
2613 * Setup the tooltip to item. The item can have only one tooltip,
2614 * so any previous tooltip data is removed. @p func(with @p data) will
2615 * be called every time that need show the tooltip and it should
2616 * return a valid Evas_Object. This object is then managed fully by
2617 * tooltip system and is deleted when the tooltip is gone.
2619 * @param item the widget item being attached a tooltip.
2620 * @param func the function used to create the tooltip contents.
2621 * @param data what to provide to @a func as callback data/context.
2622 * @param del_cb called when data is not needed anymore, either when
2623 * another callback replaces @func, the tooltip is unset with
2624 * elm_widget_item_tooltip_unset() or the owner @a item
2625 * dies. This callback receives as the first parameter the
2626 * given @a data, and @c event_info is the item.
2631 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2632 Elm_Tooltip_Item_Content_Cb func,
2634 Evas_Smart_Cb del_cb)
2636 Elm_Widget_Item_Tooltip *wit;
2638 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2642 _elm_widget_item_tooltip_unset(item);
2646 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2647 if (!wit) goto error;
2651 wit->del_cb = del_cb;
2653 elm_object_sub_tooltip_content_cb_set
2654 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2655 _elm_widget_item_tooltip_del_cb);
2660 if (del_cb) del_cb((void *)data, NULL, item);
2663 if (del_cb) del_cb((void *)data, item->widget, item);
2669 * Unset tooltip from item
2671 * @param item widget item to remove previously set tooltip.
2673 * Remove tooltip from item. The callback provided as del_cb to
2674 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2675 * it is not used anymore.
2677 * @see elm_widget_item_tooltip_content_cb_set()
2682 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2684 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2685 elm_object_tooltip_unset(item->view);
2691 * Sets a different style for this item tooltip.
2693 * @note before you set a style you should define a tooltip with
2694 * elm_widget_item_tooltip_content_cb_set() or
2695 * elm_widget_item_tooltip_text_set()
2697 * @param item widget item with tooltip already set.
2698 * @param style the theme style to use (default, transparent, ...)
2703 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2706 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2707 elm_object_tooltip_style_set(item->view, style);
2713 * Get the style for this item tooltip.
2715 * @param item widget item with tooltip already set.
2716 * @return style the theme style in use, defaults to "default". If the
2717 * object does not have a tooltip set, then NULL is returned.
2722 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2724 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2725 return elm_object_tooltip_style_get(item->view);
2729 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2732 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2733 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2737 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2739 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2740 return elm_object_cursor_get(item->view);
2744 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2746 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2747 elm_object_cursor_unset(item->view);
2753 * Sets a different style for this item cursor.
2755 * @note before you set a style you should define a cursor with
2756 * elm_widget_item_cursor_set()
2758 * @param item widget item with cursor already set.
2759 * @param style the theme style to use (default, transparent, ...)
2764 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2767 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2768 elm_object_cursor_style_set(item->view, style);
2774 * Get the style for this item cursor.
2776 * @param item widget item with cursor already set.
2777 * @return style the theme style in use, defaults to "default". If the
2778 * object does not have a cursor set, then NULL is returned.
2783 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2785 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2786 return elm_object_cursor_style_get(item->view);
2792 * Set if the cursor set should be searched on the theme or should use
2793 * the provided by the engine, only.
2795 * @note before you set if should look on theme you should define a cursor
2796 * with elm_object_cursor_set(). By default it will only look for cursors
2797 * provided by the engine.
2799 * @param item widget item with cursor already set.
2800 * @param engine_only boolean to define it cursors should be looked only
2801 * between the provided by the engine or searched on widget's theme as well.
2806 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2807 Eina_Bool engine_only)
2809 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2810 elm_object_cursor_engine_only_set(item->view, engine_only);
2816 * Get the cursor engine only usage for this item cursor.
2818 * @param item widget item with cursor already set.
2819 * @return engine_only boolean to define it cursors should be looked only
2820 * between the provided by the engine or searched on widget's theme as well. If
2821 * the object does not have a cursor set, then EINA_FALSE is returned.
2826 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2828 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2829 return elm_object_cursor_engine_only_get(item->view);
2832 // smart object funcs
2834 _smart_reconfigure(Smart_Data *sd)
2838 evas_object_move(sd->resize_obj, sd->x, sd->y);
2839 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2843 evas_object_move(sd->hover_obj, sd->x, sd->y);
2844 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2849 _smart_add(Evas_Object *obj)
2853 sd = calloc(1, sizeof(Smart_Data));
2856 sd->x = sd->y = sd->w = sd->h = 0;
2858 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2859 evas_object_smart_data_set(obj, sd);
2862 static Evas_Object *
2863 _newest_focus_order_get(Evas_Object *obj,
2864 unsigned int *newest_focus_order,
2865 Eina_Bool can_focus_only)
2868 Evas_Object *child, *ret, *best;
2870 API_ENTRY return NULL;
2872 if (!evas_object_visible_get(obj)
2873 || (elm_widget_disabled_get(obj))
2874 || (elm_widget_tree_unfocusable_get(obj)))
2878 if (*newest_focus_order < sd->focus_order)
2880 *newest_focus_order = sd->focus_order;
2883 EINA_LIST_FOREACH(sd->subobjs, l, child)
2885 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2891 if ((!best) || (!elm_widget_can_focus_get(best)))
2898 _if_focused_revert(Evas_Object *obj,
2899 Eina_Bool can_focus_only)
2902 Evas_Object *newest = NULL;
2903 unsigned int newest_focus_order = 0;
2907 if (!sd->focused) return;
2908 if (!sd->parent_obj) return;
2910 top = elm_widget_top_get(sd->parent_obj);
2913 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2916 elm_object_unfocus(newest);
2917 elm_object_focus(newest);
2923 _smart_del(Evas_Object *obj)
2926 Edje_Signal_Data *esd;
2930 if (sd->del_pre_func) sd->del_pre_func(obj);
2933 sobj = sd->resize_obj;
2934 sd->resize_obj = NULL;
2935 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2936 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2937 evas_object_del(sobj);
2941 sobj = sd->hover_obj;
2942 sd->hover_obj = NULL;
2943 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2944 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2945 evas_object_del(sobj);
2947 EINA_LIST_FREE(sd->subobjs, sobj)
2949 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2950 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2951 evas_object_del(sobj);
2953 eina_list_free(sd->tooltips); /* should be empty anyway */
2954 eina_list_free(sd->cursors); /* should be empty anyway */
2955 EINA_LIST_FREE(sd->edje_signals, esd)
2957 eina_stringshare_del(esd->emission);
2958 eina_stringshare_del(esd->source);
2961 eina_list_free(sd->event_cb); /* should be empty anyway */
2962 if (sd->del_func) sd->del_func(obj);
2963 if (sd->style) eina_stringshare_del(sd->style);
2964 if (sd->type) eina_stringshare_del(sd->type);
2965 if (sd->theme) elm_theme_free(sd->theme);
2966 _if_focused_revert(obj, EINA_TRUE);
2971 _smart_move(Evas_Object *obj,
2978 _smart_reconfigure(sd);
2982 _smart_resize(Evas_Object *obj,
2989 _smart_reconfigure(sd);
2993 _smart_show(Evas_Object *obj)
2998 if ((list = evas_object_smart_members_get(obj)))
3000 EINA_LIST_FREE(list, o)
3002 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3003 evas_object_show(o);
3009 _smart_hide(Evas_Object *obj)
3015 list = evas_object_smart_members_get(obj);
3016 EINA_LIST_FREE(list, o)
3018 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3019 evas_object_hide(o);
3024 _smart_color_set(Evas_Object *obj,
3033 if ((list = evas_object_smart_members_get(obj)))
3035 EINA_LIST_FREE(list, o)
3037 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3038 evas_object_color_set(o, r, g, b, a);
3044 _smart_clip_set(Evas_Object *obj,
3050 if ((list = evas_object_smart_members_get(obj)))
3052 EINA_LIST_FREE(list, o)
3054 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3055 evas_object_clip_set(o, clip);
3061 _smart_clip_unset(Evas_Object *obj)
3066 if ((list = evas_object_smart_members_get(obj)))
3068 EINA_LIST_FREE(list, o)
3070 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3071 evas_object_clip_unset(o);
3077 _smart_calculate(Evas_Object *obj)
3080 if (sd->changed_func) sd->changed_func(obj);
3083 /* never need to touch this */
3087 if (_e_smart) return;
3089 static const Evas_Smart_Class sc =
3092 EVAS_SMART_CLASS_VERSION,
3110 _e_smart = evas_smart_class_new(&sc);
3114 /* happy debug functions */
3117 _sub_obj_tree_dump(const Evas_Object *obj,
3122 for (i = 0; i < lvl * 3; i++)
3125 if (_elm_widget_is(obj))
3129 printf("+ %s(%p)\n",
3133 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3134 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3136 if (obj != sd->resize_obj)
3137 _sub_obj_tree_dump(obj, lvl + 1);
3141 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3145 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3148 if (!_elm_widget_is(obj))
3152 Eina_Bool visible = evas_object_visible_get(obj);
3153 Eina_Bool disabled = elm_widget_disabled_get(obj);
3154 Eina_Bool focused = elm_widget_focus_get(obj);
3155 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3159 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3162 fprintf(output, ", style=bold");
3165 fprintf(output, ", color=gray28");
3167 fprintf(output, " ];\n");
3170 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3171 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3172 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3176 fprintf(output, ", style=bold");
3179 fprintf(output, ", fontcolor=gray28");
3181 if ((disabled) || (!visible))
3182 fprintf(output, ", color=gray");
3184 fprintf(output, " ];\n");
3188 EINA_LIST_FOREACH(sd->subobjs, l, o)
3189 _sub_obj_tree_dot_dump(o, output);
3194 elm_widget_tree_dump(const Evas_Object *top)
3197 _sub_obj_tree_dump(top, 0);
3205 elm_widget_tree_dot_dump(const Evas_Object *top,
3209 if (!_elm_widget_is(top))
3211 fprintf(output, "graph " " { node [shape=record];\n");
3212 _sub_obj_tree_dot_dump(top, output);
3213 fprintf(output, "}\n");