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_activate(Evas_Object *obj)
1848 elm_widget_change(obj);
1849 if (sd->activate_func) sd->activate_func(obj);
1853 elm_widget_change(Evas_Object *obj)
1856 elm_widget_change(elm_widget_parent_get(obj));
1857 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1861 elm_widget_disabled_set(Evas_Object *obj,
1866 if (sd->disabled == disabled) return;
1867 sd->disabled = !!disabled;
1868 elm_widget_focus_disabled_handle(obj);
1869 if (sd->disable_func) sd->disable_func(obj);
1873 elm_widget_disabled_get(const Evas_Object *obj)
1876 return sd->disabled;
1880 elm_widget_show_region_set(Evas_Object *obj,
1885 Eina_Bool forceshow)
1887 Evas_Object *parent_obj, *child_obj;
1888 Evas_Coord px, py, cx, cy;
1891 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1892 && (w == sd->rw) && (h == sd->rh)) return;
1897 if (sd->on_show_region_func)
1898 sd->on_show_region_func(sd->on_show_region_data, obj);
1902 parent_obj = sd->parent_obj;
1903 child_obj = sd->obj;
1904 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1905 sd = evas_object_smart_data_get(parent_obj);
1908 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1909 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1918 if (sd->on_show_region_func)
1920 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1927 elm_widget_show_region_get(const Evas_Object *obj,
1943 * Get the focus region of the given widget.
1945 * The focus region is the area of a widget that should brought into the
1946 * visible area when the widget is focused. Mostly used to show the part of
1947 * an entry where the cursor is, for example. The area returned is relative
1948 * to the object @p obj.
1949 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1950 * function will return the full size of the object.
1952 * @param obj The widget object
1953 * @param x Where to store the x coordinate of the area
1954 * @param y Where to store the y coordinate of the area
1955 * @param w Where to store the width of the area
1956 * @param h Where to store the height of the area
1961 elm_widget_focus_region_get(const Evas_Object *obj,
1971 sd = evas_object_smart_data_get(obj);
1972 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1974 evas_object_geometry_get(obj, NULL, NULL, w, h);
1979 sd->on_focus_region_func(obj, x, y, w, h);
1983 elm_widget_scroll_hold_push(Evas_Object *obj)
1987 if (sd->scroll_hold == 1)
1988 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1989 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1990 // FIXME: on delete/reparent hold pop
1994 elm_widget_scroll_hold_pop(Evas_Object *obj)
1998 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1999 if (!sd->scroll_hold)
2000 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
2001 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
2005 elm_widget_scroll_hold_get(const Evas_Object *obj)
2008 return sd->scroll_hold;
2012 elm_widget_scroll_freeze_push(Evas_Object *obj)
2015 sd->scroll_freeze++;
2016 if (sd->scroll_freeze == 1)
2017 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
2018 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
2019 // FIXME: on delete/reparent freeze pop
2023 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2026 sd->scroll_freeze--;
2027 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2028 if (!sd->scroll_freeze)
2029 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2030 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2034 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2037 return sd->scroll_freeze;
2041 elm_widget_scale_set(Evas_Object *obj,
2045 if (scale <= 0.0) scale = 0.0;
2046 if (sd->scale != scale)
2049 elm_widget_theme(obj);
2054 elm_widget_scale_get(const Evas_Object *obj)
2056 API_ENTRY return 1.0;
2057 // FIXME: save walking up the tree by storing/caching parent scale
2058 if (sd->scale == 0.0)
2061 return elm_widget_scale_get(sd->parent_obj);
2069 elm_widget_theme_set(Evas_Object *obj,
2073 if (sd->theme != th)
2075 if (sd->theme) elm_theme_free(sd->theme);
2078 elm_widget_theme(obj);
2083 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2087 if (!sd->on_text_set_func)
2090 sd->on_text_set_func(obj, item, label);
2094 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2096 API_ENTRY return NULL;
2098 if (!sd->on_text_get_func)
2101 return sd->on_text_get_func(obj, item);
2105 elm_widget_theme_get(const Evas_Object *obj)
2107 API_ENTRY return NULL;
2111 return elm_widget_theme_get(sd->parent_obj);
2119 elm_widget_style_set(Evas_Object *obj,
2124 if (eina_stringshare_replace(&sd->style, style))
2125 elm_widget_theme(obj);
2129 elm_widget_style_get(const Evas_Object *obj)
2131 API_ENTRY return NULL;
2132 if (sd->style) return sd->style;
2137 elm_widget_type_set(Evas_Object *obj,
2141 eina_stringshare_replace(&sd->type, type);
2145 elm_widget_type_get(const Evas_Object *obj)
2147 API_ENTRY return NULL;
2148 if (sd->type) return sd->type;
2153 elm_widget_tooltip_add(Evas_Object *obj,
2157 sd->tooltips = eina_list_append(sd->tooltips, tt);
2161 elm_widget_tooltip_del(Evas_Object *obj,
2165 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2169 elm_widget_cursor_add(Evas_Object *obj,
2173 sd->cursors = eina_list_append(sd->cursors, cur);
2177 elm_widget_cursor_del(Evas_Object *obj,
2181 sd->cursors = eina_list_remove(sd->cursors, cur);
2185 elm_widget_drag_lock_x_set(Evas_Object *obj,
2189 if (sd->drag_x_locked == lock) return;
2190 sd->drag_x_locked = lock;
2191 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2192 else _propagate_x_drag_lock(obj, -1);
2196 elm_widget_drag_lock_y_set(Evas_Object *obj,
2200 if (sd->drag_y_locked == lock) return;
2201 sd->drag_y_locked = lock;
2202 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2203 else _propagate_y_drag_lock(obj, -1);
2207 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2209 API_ENTRY return EINA_FALSE;
2210 return sd->drag_x_locked;
2214 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2216 API_ENTRY return EINA_FALSE;
2217 return sd->drag_y_locked;
2221 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2224 return sd->child_drag_x_locked;
2228 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2231 return sd->child_drag_y_locked;
2235 elm_widget_theme_object_set(Evas_Object *obj,
2238 const char *welement,
2241 API_ENTRY return EINA_FALSE;
2242 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2246 elm_widget_type_check(const Evas_Object *obj,
2249 const char *provided, *expected = "(unknown)";
2250 static int abort_on_warn = -1;
2251 provided = elm_widget_type_get(obj);
2252 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2253 if (type) expected = type;
2254 if ((!provided) || (!provided[0]))
2256 provided = evas_object_type_get(obj);
2257 if ((!provided) || (!provided[0]))
2258 provided = "(unknown)";
2260 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2261 if (abort_on_warn == -1)
2263 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2264 else abort_on_warn = 0;
2266 if (abort_on_warn == 1) abort();
2273 * Split string in words
2275 * @param str Source string
2276 * @return List of const words
2278 * @see elm_widget_stringlist_free()
2282 elm_widget_stringlist_get(const char *str)
2284 Eina_List *list = NULL;
2286 if (!str) return NULL;
2287 for (b = s = str; 1; s++)
2289 if ((*s == ' ') || (!*s))
2291 char *t = malloc(s - b + 1);
2294 strncpy(t, b, s - b);
2296 list = eina_list_append(list, eina_stringshare_add(t));
2307 elm_widget_stringlist_free(Eina_List *list)
2310 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2314 elm_widget_focus_hide_handle(Evas_Object *obj)
2316 _if_focused_revert(obj, EINA_TRUE);
2320 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2322 Evas_Object *o = obj;
2325 if (_elm_widget_is(o)) break;
2326 o = evas_object_smart_parent_get(o);
2330 if (!_is_focusable(o)) return;
2331 elm_widget_focus_steal(o);
2335 elm_widget_focus_tree_unfocusable_handle(Evas_Object *obj)
2339 if (!elm_widget_parent_get(obj))
2340 elm_widget_focused_object_clear(obj);
2342 _if_focused_revert(obj, EINA_TRUE);
2346 elm_widget_focus_disabled_handle(Evas_Object *obj)
2350 elm_widget_focus_tree_unfocusable_handle(obj);
2356 * Allocate a new Elm_Widget_Item-derived structure.
2358 * The goal of this structure is to provide common ground for actions
2359 * that a widget item have, such as the owner widget, callback to
2360 * notify deletion, data pointer and maybe more.
2362 * @param widget the owner widget that holds this item, must be an elm_widget!
2363 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2364 * be used to allocate memory.
2366 * @return allocated memory that is already zeroed out, or NULL on errors.
2368 * @see elm_widget_item_new() convenience macro.
2369 * @see elm_widget_item_del() to release memory.
2372 EAPI Elm_Widget_Item *
2373 _elm_widget_item_new(Evas_Object *widget,
2376 if (!_elm_widget_is(widget))
2379 Elm_Widget_Item *item;
2381 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2382 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2384 item = calloc(1, alloc_size);
2385 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2387 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2388 item->widget = widget;
2395 * Releases widget item memory, calling back del_cb() if it exists.
2397 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2398 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2399 * this function and then unset it, thus being useful for 2 step
2400 * cleanup whenever the del_cb may use any of the data that must be
2401 * deleted from item.
2403 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2406 * @param item a valid #Elm_Widget_Item to be deleted.
2407 * @see elm_widget_item_del() convenience macro.
2411 _elm_widget_item_del(Elm_Widget_Item *item)
2413 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2416 item->del_cb((void *)item->data, item->widget, item);
2419 evas_object_del(item->view);
2421 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2428 * Notify object will be deleted without actually deleting it.
2430 * This function will callback Elm_Widget_Item::del_cb if it is set
2431 * and then unset it so it is not called twice (ie: from
2432 * elm_widget_item_del()).
2434 * @param item a valid #Elm_Widget_Item to be notified
2435 * @see elm_widget_item_pre_notify_del() convenience macro.
2439 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2441 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2442 if (!item->del_cb) return;
2443 item->del_cb((void *)item->data, item->widget, item);
2444 item->del_cb = NULL;
2450 * Set the function to notify when item is being deleted.
2452 * This function will complain if there was a callback set already,
2453 * however it will set the new one.
2455 * The callback will be called from elm_widget_item_pre_notify_del()
2456 * or elm_widget_item_del() will be called with:
2457 * - data: the Elm_Widget_Item::data value.
2458 * - obj: the Elm_Widget_Item::widget evas object.
2459 * - event_info: the item being deleted.
2461 * @param item a valid #Elm_Widget_Item to be notified
2462 * @see elm_widget_item_del_cb_set() convenience macro.
2466 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2467 Evas_Smart_Cb del_cb)
2469 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2471 if ((item->del_cb) && (item->del_cb != del_cb))
2472 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2473 item->del_cb, item, del_cb);
2475 item->del_cb = del_cb;
2481 * Set user-data in this item.
2483 * User data may be used to identify this item or just store any
2484 * application data. It is automatically given as the first parameter
2485 * of the deletion notify callback.
2487 * @param item a valid #Elm_Widget_Item to store data in.
2488 * @param data user data to store.
2489 * @see elm_widget_item_del_cb_set() convenience macro.
2493 _elm_widget_item_data_set(Elm_Widget_Item *item,
2496 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2497 if ((item->data) && (item->data != data))
2498 DBG("Replacing item %p data %p with %p", item, item->data, data);
2505 * Retrieves user-data of this item.
2507 * @param item a valid #Elm_Widget_Item to get data from.
2508 * @see elm_widget_item_data_set()
2512 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2514 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2515 return (void *)item->data;
2518 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2520 struct _Elm_Widget_Item_Tooltip
2522 Elm_Widget_Item *item;
2523 Elm_Tooltip_Item_Content_Cb func;
2524 Evas_Smart_Cb del_cb;
2528 static Evas_Object *
2529 _elm_widget_item_tooltip_label_create(void *data,
2531 void *item __UNUSED__)
2533 Evas_Object *label = elm_label_add(obj);
2536 elm_object_style_set(label, "tooltip");
2537 elm_object_text_set(label, data);
2542 _elm_widget_item_tooltip_label_del_cb(void *data,
2543 Evas_Object *obj __UNUSED__,
2544 void *event_info __UNUSED__)
2546 eina_stringshare_del(data);
2552 * Set the text to be shown in the widget item.
2554 * @param item Target item
2555 * @param text The text to set in the content
2557 * Setup the text as tooltip to object. The item can have only one tooltip,
2558 * so any previous tooltip data is removed.
2563 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2566 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2567 EINA_SAFETY_ON_NULL_RETURN(text);
2569 text = eina_stringshare_add(text);
2570 _elm_widget_item_tooltip_content_cb_set
2571 (item, _elm_widget_item_tooltip_label_create, text,
2572 _elm_widget_item_tooltip_label_del_cb);
2575 static Evas_Object *
2576 _elm_widget_item_tooltip_create(void *data,
2579 Elm_Widget_Item_Tooltip *wit = data;
2580 return wit->func((void *)wit->data, obj, wit->item);
2584 _elm_widget_item_tooltip_del_cb(void *data,
2586 void *event_info __UNUSED__)
2588 Elm_Widget_Item_Tooltip *wit = data;
2589 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2596 * Set the content to be shown in the tooltip item
2598 * Setup the tooltip to item. The item can have only one tooltip,
2599 * so any previous tooltip data is removed. @p func(with @p data) will
2600 * be called every time that need show the tooltip and it should
2601 * return a valid Evas_Object. This object is then managed fully by
2602 * tooltip system and is deleted when the tooltip is gone.
2604 * @param item the widget item being attached a tooltip.
2605 * @param func the function used to create the tooltip contents.
2606 * @param data what to provide to @a func as callback data/context.
2607 * @param del_cb called when data is not needed anymore, either when
2608 * another callback replaces @func, the tooltip is unset with
2609 * elm_widget_item_tooltip_unset() or the owner @a item
2610 * dies. This callback receives as the first parameter the
2611 * given @a data, and @c event_info is the item.
2616 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2617 Elm_Tooltip_Item_Content_Cb func,
2619 Evas_Smart_Cb del_cb)
2621 Elm_Widget_Item_Tooltip *wit;
2623 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2627 _elm_widget_item_tooltip_unset(item);
2631 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2632 if (!wit) goto error;
2636 wit->del_cb = del_cb;
2638 elm_object_sub_tooltip_content_cb_set
2639 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2640 _elm_widget_item_tooltip_del_cb);
2645 if (del_cb) del_cb((void *)data, NULL, item);
2648 if (del_cb) del_cb((void *)data, item->widget, item);
2654 * Unset tooltip from item
2656 * @param item widget item to remove previously set tooltip.
2658 * Remove tooltip from item. The callback provided as del_cb to
2659 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2660 * it is not used anymore.
2662 * @see elm_widget_item_tooltip_content_cb_set()
2667 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2669 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2670 elm_object_tooltip_unset(item->view);
2676 * Sets a different style for this item tooltip.
2678 * @note before you set a style you should define a tooltip with
2679 * elm_widget_item_tooltip_content_cb_set() or
2680 * elm_widget_item_tooltip_text_set()
2682 * @param item widget item with tooltip already set.
2683 * @param style the theme style to use (default, transparent, ...)
2688 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2691 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2692 elm_object_tooltip_style_set(item->view, style);
2698 * Get the style for this item tooltip.
2700 * @param item widget item with tooltip already set.
2701 * @return style the theme style in use, defaults to "default". If the
2702 * object does not have a tooltip set, then NULL is returned.
2707 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2709 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2710 return elm_object_tooltip_style_get(item->view);
2714 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2717 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2718 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2722 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2724 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2725 return elm_object_cursor_get(item->view);
2729 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2731 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2732 elm_object_cursor_unset(item->view);
2738 * Sets a different style for this item cursor.
2740 * @note before you set a style you should define a cursor with
2741 * elm_widget_item_cursor_set()
2743 * @param item widget item with cursor already set.
2744 * @param style the theme style to use (default, transparent, ...)
2749 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2752 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2753 elm_object_cursor_style_set(item->view, style);
2759 * Get the style for this item cursor.
2761 * @param item widget item with cursor already set.
2762 * @return style the theme style in use, defaults to "default". If the
2763 * object does not have a cursor set, then NULL is returned.
2768 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2770 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2771 return elm_object_cursor_style_get(item->view);
2777 * Set if the cursor set should be searched on the theme or should use
2778 * the provided by the engine, only.
2780 * @note before you set if should look on theme you should define a cursor
2781 * with elm_object_cursor_set(). By default it will only look for cursors
2782 * provided by the engine.
2784 * @param item widget item with cursor already set.
2785 * @param engine_only boolean to define it cursors should be looked only
2786 * between the provided by the engine or searched on widget's theme as well.
2791 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2792 Eina_Bool engine_only)
2794 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2795 elm_object_cursor_engine_only_set(item->view, engine_only);
2801 * Get the cursor engine only usage for this item cursor.
2803 * @param item widget item with cursor already set.
2804 * @return engine_only boolean to define it cursors should be looked only
2805 * between the provided by the engine or searched on widget's theme as well. If
2806 * the object does not have a cursor set, then EINA_FALSE is returned.
2811 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2813 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2814 return elm_object_cursor_engine_only_get(item->view);
2817 // smart object funcs
2819 _smart_reconfigure(Smart_Data *sd)
2823 evas_object_move(sd->resize_obj, sd->x, sd->y);
2824 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2828 evas_object_move(sd->hover_obj, sd->x, sd->y);
2829 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2834 _smart_add(Evas_Object *obj)
2838 sd = calloc(1, sizeof(Smart_Data));
2841 sd->x = sd->y = sd->w = sd->h = 0;
2843 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2844 evas_object_smart_data_set(obj, sd);
2847 static Evas_Object *
2848 _newest_focus_order_get(Evas_Object *obj,
2849 unsigned int *newest_focus_order,
2850 Eina_Bool can_focus_only)
2853 Evas_Object *child, *ret, *best;
2855 API_ENTRY return NULL;
2857 if (!evas_object_visible_get(obj)
2858 || (elm_widget_disabled_get(obj))
2859 || (elm_widget_tree_unfocusable_get(obj)))
2863 if (*newest_focus_order < sd->focus_order)
2865 *newest_focus_order = sd->focus_order;
2868 EINA_LIST_FOREACH(sd->subobjs, l, child)
2870 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2876 if ((!best) || (!elm_widget_can_focus_get(best)))
2883 _if_focused_revert(Evas_Object *obj,
2884 Eina_Bool can_focus_only)
2887 Evas_Object *newest = NULL;
2888 unsigned int newest_focus_order = 0;
2892 if (!sd->focused) return;
2893 if (!sd->parent_obj) return;
2895 top = elm_widget_top_get(sd->parent_obj);
2898 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2901 elm_object_unfocus(newest);
2902 elm_object_focus(newest);
2908 _smart_del(Evas_Object *obj)
2911 Edje_Signal_Data *esd;
2915 if (sd->del_pre_func) sd->del_pre_func(obj);
2918 sobj = sd->resize_obj;
2919 sd->resize_obj = NULL;
2920 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2921 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2922 evas_object_del(sobj);
2926 sobj = sd->hover_obj;
2927 sd->hover_obj = NULL;
2928 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2929 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2930 evas_object_del(sobj);
2932 EINA_LIST_FREE(sd->subobjs, sobj)
2934 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2935 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2936 evas_object_del(sobj);
2938 eina_list_free(sd->tooltips); /* should be empty anyway */
2939 eina_list_free(sd->cursors); /* should be empty anyway */
2940 EINA_LIST_FREE(sd->edje_signals, esd)
2942 eina_stringshare_del(esd->emission);
2943 eina_stringshare_del(esd->source);
2946 eina_list_free(sd->event_cb); /* should be empty anyway */
2947 if (sd->del_func) sd->del_func(obj);
2948 if (sd->style) eina_stringshare_del(sd->style);
2949 if (sd->type) eina_stringshare_del(sd->type);
2950 if (sd->theme) elm_theme_free(sd->theme);
2951 _if_focused_revert(obj, EINA_TRUE);
2956 _smart_move(Evas_Object *obj,
2963 _smart_reconfigure(sd);
2967 _smart_resize(Evas_Object *obj,
2974 _smart_reconfigure(sd);
2978 _smart_show(Evas_Object *obj)
2983 if ((list = evas_object_smart_members_get(obj)))
2985 EINA_LIST_FREE(list, o)
2987 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2988 evas_object_show(o);
2994 _smart_hide(Evas_Object *obj)
3000 list = evas_object_smart_members_get(obj);
3001 EINA_LIST_FREE(list, o)
3003 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3004 evas_object_hide(o);
3009 _smart_color_set(Evas_Object *obj,
3018 if ((list = evas_object_smart_members_get(obj)))
3020 EINA_LIST_FREE(list, o)
3022 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3023 evas_object_color_set(o, r, g, b, a);
3029 _smart_clip_set(Evas_Object *obj,
3035 if ((list = evas_object_smart_members_get(obj)))
3037 EINA_LIST_FREE(list, o)
3039 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3040 evas_object_clip_set(o, clip);
3046 _smart_clip_unset(Evas_Object *obj)
3051 if ((list = evas_object_smart_members_get(obj)))
3053 EINA_LIST_FREE(list, o)
3055 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3056 evas_object_clip_unset(o);
3062 _smart_calculate(Evas_Object *obj)
3065 if (sd->changed_func) sd->changed_func(obj);
3068 /* never need to touch this */
3072 if (_e_smart) return;
3074 static const Evas_Smart_Class sc =
3077 EVAS_SMART_CLASS_VERSION,
3095 _e_smart = evas_smart_class_new(&sc);
3099 /* happy debug functions */
3102 _sub_obj_tree_dump(const Evas_Object *obj,
3107 for (i = 0; i < lvl * 3; i++)
3110 if (_elm_widget_is(obj))
3114 printf("+ %s(%p)\n",
3118 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3119 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3121 if (obj != sd->resize_obj)
3122 _sub_obj_tree_dump(obj, lvl + 1);
3126 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3130 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3133 if (!_elm_widget_is(obj))
3137 Eina_Bool visible = evas_object_visible_get(obj);
3138 Eina_Bool disabled = elm_widget_disabled_get(obj);
3139 Eina_Bool focused = elm_widget_focus_get(obj);
3140 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3144 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3147 fprintf(output, ", style=bold");
3150 fprintf(output, ", color=gray28");
3152 fprintf(output, " ];\n");
3155 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3156 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3157 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3161 fprintf(output, ", style=bold");
3164 fprintf(output, ", fontcolor=gray28");
3166 if ((disabled) || (!visible))
3167 fprintf(output, ", color=gray");
3169 fprintf(output, " ];\n");
3173 EINA_LIST_FOREACH(sd->subobjs, l, o)
3174 _sub_obj_tree_dot_dump(o, output);
3179 elm_widget_tree_dump(const Evas_Object *top)
3182 _sub_obj_tree_dump(top, 0);
3190 elm_widget_tree_dot_dump(const Evas_Object *top,
3194 if (!_elm_widget_is(top))
3196 fprintf(output, "graph " " { node [shape=record];\n");
3197 _sub_obj_tree_dot_dump(top, output);
3198 fprintf(output, "}\n");