1 #include <Elementary.h>
4 static const char SMART_NAME[] = "elm_widget";
7 Smart_Data * sd = evas_object_smart_data_get(obj); \
8 if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
9 #define INTERNAL_ENTRY \
10 Smart_Data * sd = evas_object_smart_data_get(obj); \
13 typedef struct _Smart_Data Smart_Data;
14 typedef struct _Edje_Signal_Data Edje_Signal_Data;
15 typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data;
21 Evas_Object *parent_obj;
22 Evas_Coord x, y, w, h;
24 Evas_Object *resize_obj;
25 Evas_Object *hover_obj;
26 Eina_List *tooltips, *cursors;
27 void (*del_func)(Evas_Object *obj);
28 void (*del_pre_func)(Evas_Object *obj);
29 void (*focus_func)(Evas_Object *obj);
30 void (*activate_func)(Evas_Object *obj);
31 void (*disable_func)(Evas_Object *obj);
32 void (*theme_func)(Evas_Object *obj);
33 Eina_Bool (*event_func)(Evas_Object *obj,
35 Evas_Callback_Type type,
37 void (*signal_func)(Evas_Object *obj,
40 void (*callback_add_func)(Evas_Object *obj,
45 void (*callback_del_func)(Evas_Object *obj,
50 void (*changed_func)(Evas_Object *obj);
51 Eina_Bool (*focus_next_func)(const Evas_Object *obj,
52 Elm_Focus_Direction dir,
54 void (*on_focus_func)(void *data,
57 void (*on_change_func)(void *data,
60 void (*on_show_region_func)(void *data,
62 void *on_show_region_data;
63 void (*focus_region_func)(Evas_Object *obj,
68 void (*on_focus_region_func)(const Evas_Object *obj,
74 Evas_Coord rx, ry, rw, rh;
80 unsigned int focus_order;
81 Eina_Bool focus_order_on_calc;
83 int child_drag_x_locked;
84 int child_drag_y_locked;
86 Eina_List *edje_signals;
88 Eina_Bool drag_x_locked : 1;
89 Eina_Bool drag_y_locked : 1;
91 Eina_Bool can_focus : 1;
92 Eina_Bool child_can_focus : 1;
93 Eina_Bool focused : 1;
94 Eina_Bool highlight_ignore : 1;
95 Eina_Bool highlight_in_theme : 1;
96 Eina_Bool disabled : 1;
97 Eina_Bool is_mirrored : 1;
98 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
100 Eina_List *focus_chain;
104 struct _Edje_Signal_Data
108 const char *emission;
113 struct _Elm_Event_Cb_Data
119 /* local subsystem functions */
120 static void _smart_reconfigure(Smart_Data *sd);
121 static void _smart_add(Evas_Object *obj);
122 static void _smart_del(Evas_Object *obj);
123 static void _smart_move(Evas_Object *obj,
126 static void _smart_resize(Evas_Object *obj,
129 static void _smart_show(Evas_Object *obj);
130 static void _smart_hide(Evas_Object *obj);
131 static void _smart_color_set(Evas_Object *obj,
136 static void _smart_clip_set(Evas_Object *obj,
138 static void _smart_clip_unset(Evas_Object *obj);
139 static void _smart_calculate(Evas_Object *obj);
140 static void _smart_init(void);
142 static void _if_focused_revert(Evas_Object *obj,
143 Eina_Bool can_focus_only);
144 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
145 unsigned int *newest_focus_order,
146 Eina_Bool can_focus_only);
148 /* local subsystem globals */
149 static Evas_Smart *_e_smart = NULL;
150 static Eina_List *widtypes = NULL;
152 static unsigned int focus_order = 0;
155 static inline Eina_Bool
156 _elm_widget_is(const Evas_Object *obj)
158 const char *type = evas_object_type_get(obj);
159 return type == SMART_NAME;
162 static inline Eina_Bool
163 _is_focusable(Evas_Object *obj)
165 API_ENTRY return EINA_FALSE;
166 return sd->can_focus || (sd->child_can_focus);
170 _unfocus_parents(Evas_Object *obj)
172 for (; obj; obj = elm_widget_parent_get(obj))
175 if (!sd->focused) return;
181 _focus_parents(Evas_Object *obj)
183 for (; obj; obj = elm_widget_parent_get(obj))
186 if (sd->focused) return;
192 _sub_obj_del(void *data,
195 void *event_info __UNUSED__)
197 Smart_Data *sd = data;
199 if (_elm_widget_is(obj))
201 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
203 if (obj == sd->resize_obj)
204 sd->resize_obj = NULL;
205 else if (obj == sd->hover_obj)
206 sd->hover_obj = NULL;
208 sd->subobjs = eina_list_remove(sd->subobjs, obj);
209 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
213 _sub_obj_hide(void *data __UNUSED__,
216 void *event_info __UNUSED__)
218 elm_widget_focus_hide_handle(obj);
222 _sub_obj_mouse_down(void *data __UNUSED__,
225 void *event_info __UNUSED__)
227 elm_widget_focus_mouse_down_handle(obj);
231 _propagate_x_drag_lock(Evas_Object *obj,
237 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
240 sd2->child_drag_x_locked += dir;
241 _propagate_x_drag_lock(sd->parent_obj, dir);
247 _propagate_y_drag_lock(Evas_Object *obj,
253 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
256 sd2->child_drag_y_locked += dir;
257 _propagate_y_drag_lock(sd->parent_obj, dir);
263 _propagate_event(void *data,
269 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
270 Evas_Event_Flags *event_flags = NULL;
274 case EVAS_CALLBACK_KEY_DOWN:
276 Evas_Event_Key_Down *ev = event_info;
277 event_flags = &(ev->event_flags);
281 case EVAS_CALLBACK_KEY_UP:
283 Evas_Event_Key_Up *ev = event_info;
284 event_flags = &(ev->event_flags);
288 case EVAS_CALLBACK_MOUSE_WHEEL:
290 Evas_Event_Mouse_Wheel *ev = event_info;
291 event_flags = &(ev->event_flags);
299 elm_widget_event_propagate(obj, type, event_info, event_flags);
303 _parent_focus(Evas_Object *obj)
307 Evas_Object *o = elm_widget_parent_get(obj);
308 sd->focus_order_on_calc = EINA_TRUE;
310 if (sd->focused) return;
316 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
318 /* we don't want to bump a common widget ancestor's
319 focus_order *twice* while parent focusing */
320 if (!ret || (!i) || (i != focus_order))
324 if (!sd->focus_order_on_calc)
325 return; /* we don't want to override it if by means of any of the
326 callbacks below one gets to calculate our order
330 sd->focus_order = focus_order;
331 sd->focused = EINA_TRUE;
332 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
333 if (sd->focus_func) sd->focus_func(obj);
335 _elm_widget_focus_region_show(obj);
337 sd->focus_order_on_calc = EINA_FALSE;
341 _elm_object_focus_chain_del_cb(void *data,
344 void *event_info __UNUSED__)
346 Smart_Data *sd = data;
348 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
351 // exposed util funcs to elm
353 _elm_widget_type_clear(void)
357 EINA_LIST_FREE(widtypes, ptr)
359 eina_stringshare_del(*ptr);
365 _elm_widget_focus_region_show(const Evas_Object *obj)
367 Evas_Coord x, y, w, h, ox, oy;
373 o = elm_widget_parent_get(obj);
376 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
377 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
381 sd2 = evas_object_smart_data_get(o);
382 if (sd2->focus_region_func)
384 sd2->focus_region_func(o, x, y, w, h);
385 elm_widget_focus_region_get(o, &x, &y, &w, &h);
389 evas_object_geometry_get(o, &px, &py, NULL, NULL);
395 o = elm_widget_parent_get(o);
400 * @defgroup Widget Widget
403 * Exposed api for making widgets
406 elm_widget_type_register(const char **ptr)
408 widtypes = eina_list_append(widtypes, (void *)ptr);
412 elm_widget_api_check(int ver)
414 if (ver != ELM_INTERNAL_API_VERSION)
416 CRITICAL("Elementary widget api versions do not match");
423 elm_widget_add(Evas *evas)
427 obj = evas_object_smart_add(evas, _e_smart);
428 elm_widget_mirrored_set(obj, elm_mirrored_get());
433 elm_widget_del_hook_set(Evas_Object *obj,
434 void (*func)(Evas_Object *obj))
441 elm_widget_del_pre_hook_set(Evas_Object *obj,
442 void (*func)(Evas_Object *obj))
445 sd->del_pre_func = func;
449 elm_widget_focus_hook_set(Evas_Object *obj,
450 void (*func)(Evas_Object *obj))
453 sd->focus_func = func;
457 elm_widget_activate_hook_set(Evas_Object *obj,
458 void (*func)(Evas_Object *obj))
461 sd->activate_func = func;
465 elm_widget_disable_hook_set(Evas_Object *obj,
466 void (*func)(Evas_Object *obj))
469 sd->disable_func = func;
473 elm_widget_theme_hook_set(Evas_Object *obj,
474 void (*func)(Evas_Object *obj))
477 sd->theme_func = func;
481 elm_widget_event_hook_set(Evas_Object *obj,
482 Eina_Bool (*func)(Evas_Object *obj,
484 Evas_Callback_Type type,
488 sd->event_func = func;
492 elm_widget_changed_hook_set(Evas_Object *obj,
493 void (*func)(Evas_Object *obj))
496 sd->changed_func = func;
500 elm_widget_signal_emit_hook_set(Evas_Object *obj,
501 void (*func)(Evas_Object *obj,
502 const char *emission,
506 sd->signal_func = func;
510 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
511 void (*func)(Evas_Object *obj,
512 const char *emission,
514 Edje_Signal_Cb func_cb,
518 sd->callback_add_func = func;
522 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
523 void (*func)(Evas_Object *obj,
524 const char *emission,
526 Edje_Signal_Cb func_cb,
530 sd->callback_del_func = func;
534 elm_widget_theme(Evas_Object *obj)
542 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
543 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
544 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
545 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
546 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
547 if (sd->theme_func) sd->theme_func(obj);
551 elm_widget_theme_specific(Evas_Object *obj,
559 Elm_Theme *th2, *thdef;
562 thdef = elm_theme_default_get();
567 if (!th2) th2 = thdef;
575 if (th2 == thdef) break;
576 th2 = th2->ref_theme;
577 if (!th2) th2 = thdef;
581 EINA_LIST_FOREACH(sd->subobjs, l, child)
582 elm_widget_theme_specific(child, th, force);
583 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
584 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
585 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
586 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
587 if (sd->theme_func) sd->theme_func(obj);
593 * Set hook to get next object in object focus chain.
595 * @param obj The widget object.
596 * @param func The hook to be used with this widget.
601 elm_widget_focus_next_hook_set(Evas_Object *obj,
602 Eina_Bool (*func)(const Evas_Object *obj,
603 Elm_Focus_Direction dir,
607 sd->focus_next_func = func;
611 * Returns the widget's mirrored mode.
613 * @param obj The widget.
614 * @return mirrored mode of the object.
618 elm_widget_mirrored_get(const Evas_Object *obj)
620 API_ENTRY return EINA_FALSE;
621 return sd->is_mirrored;
625 * Sets the widget's mirrored mode.
627 * @param obj The widget.
628 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
631 elm_widget_mirrored_set(Evas_Object *obj,
635 if (sd->is_mirrored != mirrored)
637 sd->is_mirrored = mirrored;
638 elm_widget_theme(obj);
644 * Resets the mirrored mode from the system mirror mode for widgets that are in
645 * automatic mirroring mode. This function does not call elm_widget_theme.
647 * @param obj The widget.
648 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
651 _elm_widget_mirrored_reload(Evas_Object *obj)
654 Eina_Bool mirrored = elm_mirrored_get();
655 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
657 sd->is_mirrored = mirrored;
662 * Returns the widget's mirrored mode setting.
664 * @param obj The widget.
665 * @return mirrored mode setting of the object.
669 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
671 API_ENTRY return EINA_FALSE;
672 return sd->mirrored_auto_mode;
676 * Sets the widget's mirrored mode setting.
677 * When widget in automatic mode, it follows the system mirrored mode set by
678 * elm_mirrored_set().
679 * @param obj The widget.
680 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
683 elm_widget_mirrored_automatic_set(Evas_Object *obj,
687 if (sd->mirrored_auto_mode != automatic)
689 sd->mirrored_auto_mode = automatic;
693 elm_widget_mirrored_set(obj, elm_mirrored_get());
699 elm_widget_on_focus_hook_set(Evas_Object *obj,
700 void (*func)(void *data,
705 sd->on_focus_func = func;
706 sd->on_focus_data = data;
710 elm_widget_on_change_hook_set(Evas_Object *obj,
711 void (*func)(void *data,
716 sd->on_change_func = func;
717 sd->on_change_data = data;
721 elm_widget_on_show_region_hook_set(Evas_Object *obj,
722 void (*func)(void *data,
727 sd->on_show_region_func = func;
728 sd->on_show_region_data = data;
734 * Set the hook to use to show the focused region.
736 * Whenever a new widget gets focused or it's needed to show the focused
737 * area of the current one, this hook will be called on objects that may
738 * want to move their children into their visible area.
739 * The area given in the hook function is relative to the @p obj widget.
741 * @param obj The widget object
742 * @param func The function to call to show the specified area.
747 elm_widget_focus_region_hook_set(Evas_Object *obj,
748 void (*func)(Evas_Object *obj,
755 sd->focus_region_func = func;
761 * Set the hook to retrieve the focused region of a widget.
763 * This hook will be called by elm_widget_focus_region_get() whenever
764 * it's needed to get the focused area of a widget. The area must be relative
765 * to the widget itself and if no hook is set, it will default to the entire
768 * @param obj The widget object
769 * @param func The function used to retrieve the focus region.
774 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
775 void (*func)(const Evas_Object *obj,
782 sd->on_focus_region_func = func;
786 elm_widget_data_set(Evas_Object *obj,
794 elm_widget_data_get(const Evas_Object *obj)
796 API_ENTRY return NULL;
801 elm_widget_sub_object_add(Evas_Object *obj,
805 double scale, pscale = elm_widget_scale_get(sobj);
806 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
807 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
809 if (_elm_widget_is(sobj))
811 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
814 if (sd2->parent_obj == obj)
817 elm_widget_sub_object_del(sd2->parent_obj, sobj);
818 sd2->parent_obj = obj;
819 if (!sd->child_can_focus && (_is_focusable(sobj)))
820 sd->child_can_focus = EINA_TRUE;
825 void *data = evas_object_data_get(sobj, "elm-parent");
828 if (data == obj) return;
829 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
834 sd->subobjs = eina_list_append(sd->subobjs, sobj);
835 evas_object_data_set(sobj, "elm-parent", obj);
836 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
837 if (_elm_widget_is(sobj))
838 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
839 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
840 scale = elm_widget_scale_get(sobj);
841 th = elm_widget_theme_get(sobj);
842 mirrored = elm_widget_mirrored_get(sobj);
843 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
844 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
848 elm_widget_sub_object_del(Evas_Object *obj,
851 Evas_Object *sobj_parent;
855 sobj_parent = evas_object_data_del(sobj, "elm-parent");
856 if (sobj_parent != obj)
858 static int abort_on_warn = -1;
859 ERR("removing sub object %p from parent %p, "
860 "but elm-parent is different %p!",
861 sobj, obj, sobj_parent);
862 if (EINA_UNLIKELY(abort_on_warn == -1))
864 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
865 else abort_on_warn = 0;
867 if (abort_on_warn == 1) abort();
869 if (!sd->child_can_focus)
871 if (_is_focusable(sobj)) sd->child_can_focus = 0;
873 if (_elm_widget_is(sobj))
875 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
878 sd2->parent_obj = NULL;
879 if (sd2->resize_obj == sobj)
880 sd2->resize_obj = NULL;
882 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
885 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
886 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
889 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
890 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
892 if (_elm_widget_is(sobj))
893 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
895 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
899 elm_widget_resize_object_set(Evas_Object *obj,
903 // orphan previous resize obj
906 evas_object_clip_unset(sd->resize_obj);
907 evas_object_data_del(sd->resize_obj, "elm-parent");
908 if (_elm_widget_is(sd->resize_obj))
910 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
911 if (sd2) sd2->parent_obj = NULL;
912 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
915 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
917 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
918 _sub_obj_mouse_down, sd);
919 evas_object_smart_member_del(sd->resize_obj);
920 if (_elm_widget_is(sd->resize_obj))
922 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
925 // orphan new resize obj
928 evas_object_data_del(sobj, "elm-parent");
929 if (_elm_widget_is(sobj))
931 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
932 if (sd2) sd2->parent_obj = NULL;
933 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
936 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
938 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
939 _sub_obj_mouse_down, sd);
940 evas_object_smart_member_del(sobj);
941 if (_elm_widget_is(sobj))
943 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
946 // set the resize obj up
947 sd->resize_obj = sobj;
950 if (_elm_widget_is(sd->resize_obj))
952 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
953 if (sd2) sd2->parent_obj = obj;
954 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
957 evas_object_clip_set(sobj, evas_object_clip_get(obj));
958 evas_object_smart_member_add(sobj, obj);
959 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
961 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
962 _sub_obj_mouse_down, sd);
963 _smart_reconfigure(sd);
964 evas_object_data_set(sobj, "elm-parent", obj);
965 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
966 if (_elm_widget_is(sobj))
968 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
974 elm_widget_hover_object_set(Evas_Object *obj,
980 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
983 sd->hover_obj = sobj;
986 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
988 _smart_reconfigure(sd);
993 elm_widget_can_focus_set(Evas_Object *obj,
997 sd->can_focus = can_focus;
1000 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1002 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1003 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1005 (void *)(long)EVAS_CALLBACK_KEY_UP);
1006 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1008 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1012 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1014 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1016 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1022 elm_widget_can_focus_get(const Evas_Object *obj)
1024 API_ENTRY return EINA_FALSE;
1025 return sd->can_focus;
1029 elm_widget_child_can_focus_get(const Evas_Object *obj)
1031 API_ENTRY return EINA_FALSE;
1032 return sd->child_can_focus;
1036 elm_widget_highlight_ignore_set(Evas_Object *obj,
1040 sd->highlight_ignore = !!ignore;
1044 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1046 API_ENTRY return EINA_FALSE;
1047 return sd->highlight_ignore;
1051 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1052 Eina_Bool highlight)
1055 sd->highlight_in_theme = !!highlight;
1056 /* FIXME: if focused, it should switch from one mode to the other */
1060 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1062 API_ENTRY return EINA_FALSE;
1063 return sd->highlight_in_theme;
1067 elm_widget_focus_get(const Evas_Object *obj)
1069 API_ENTRY return EINA_FALSE;
1074 elm_widget_focused_object_get(const Evas_Object *obj)
1076 const Evas_Object *subobj;
1078 API_ENTRY return NULL;
1080 if (!sd->focused) return NULL;
1081 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1083 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1084 if (fobj) return fobj;
1086 return (Evas_Object *)obj;
1090 elm_widget_top_get(const Evas_Object *obj)
1092 API_ENTRY return NULL;
1093 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1094 return (Evas_Object *)obj;
1098 elm_widget_is(const Evas_Object *obj)
1100 return _elm_widget_is(obj);
1104 elm_widget_parent_widget_get(const Evas_Object *obj)
1106 Evas_Object *parent;
1108 if (_elm_widget_is(obj))
1110 Smart_Data *sd = evas_object_smart_data_get(obj);
1111 if (!sd) return NULL;
1112 parent = sd->parent_obj;
1116 parent = evas_object_data_get(obj, "elm-parent");
1117 if (!parent) parent = evas_object_smart_parent_get(obj);
1122 Evas_Object *elm_parent;
1123 if (_elm_widget_is(parent)) break;
1124 elm_parent = evas_object_data_get(parent, "elm-parent");
1125 if (elm_parent) parent = elm_parent;
1126 else parent = evas_object_smart_parent_get(parent);
1132 elm_widget_event_callback_add(Evas_Object *obj,
1137 EINA_SAFETY_ON_NULL_RETURN(func);
1138 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1141 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1145 elm_widget_event_callback_del(Evas_Object *obj,
1149 API_ENTRY return NULL;
1150 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1152 Elm_Event_Cb_Data *ecd;
1153 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1154 if ((ecd->func == func) && (ecd->data == data))
1157 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1158 return (void *)data;
1164 elm_widget_event_propagate(Evas_Object *obj,
1165 Evas_Callback_Type type,
1167 Evas_Event_Flags *event_flags)
1169 API_ENTRY return EINA_FALSE; //TODO reduce.
1170 if (!_elm_widget_is(obj)) return EINA_FALSE;
1171 Evas_Object *parent = obj;
1172 Elm_Event_Cb_Data *ecd;
1173 Eina_List *l, *l_prev;
1176 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1178 sd = evas_object_smart_data_get(parent);
1179 if ((!sd) || (!_elm_widget_is(obj)))
1180 return EINA_FALSE; //Not Elm Widget
1182 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1185 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1187 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1188 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1191 parent = sd->parent_obj;
1200 * Set custom focus chain.
1202 * This function i set one new and overwrite any previous custom focus chain
1203 * with the list of objects. The previous list will be deleted and this list
1204 * will be managed. After setted, don't modity it.
1206 * @note On focus cycle, only will be evaluated children of this container.
1208 * @param obj The container widget
1209 * @param objs Chain of objects to pass focus
1213 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1217 if (!sd->focus_next_func)
1220 elm_widget_focus_custom_chain_unset(obj);
1225 EINA_LIST_FOREACH(objs, l, o)
1227 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1228 _elm_object_focus_chain_del_cb, sd);
1231 sd->focus_chain = objs;
1237 * Get custom focus chain
1239 * @param obj The container widget
1242 EAPI const Eina_List *
1243 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1245 API_ENTRY return NULL;
1246 return (const Eina_List *)sd->focus_chain;
1252 * Unset custom focus chain
1254 * @param obj The container widget
1258 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1261 Eina_List *l, *l_next;
1264 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1266 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1267 _elm_object_focus_chain_del_cb, sd);
1268 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1275 * Append object to custom focus chain.
1277 * @note If relative_child equal to NULL or not in custom chain, the object
1278 * will be added in end.
1280 * @note On focus cycle, only will be evaluated children of this container.
1282 * @param obj The container widget
1283 * @param child The child to be added in custom chain
1284 * @param relative_child The relative object to position the child
1288 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1290 Evas_Object *relative_child)
1293 EINA_SAFETY_ON_NULL_RETURN(child);
1294 if (!sd->focus_next_func)
1297 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1298 _elm_object_focus_chain_del_cb, sd);
1300 if (!relative_child)
1302 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1306 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1313 * Prepend object to custom focus chain.
1315 * @note If relative_child equal to NULL or not in custom chain, the object
1316 * will be added in begin.
1318 * @note On focus cycle, only will be evaluated children of this container.
1320 * @param obj The container widget
1321 * @param child The child to be added in custom chain
1322 * @param relative_child The relative object to position the child
1326 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1328 Evas_Object *relative_child)
1331 EINA_SAFETY_ON_NULL_RETURN(child);
1332 if (!sd->focus_next_func)
1335 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1336 _elm_object_focus_chain_del_cb, sd);
1338 if (!relative_child)
1340 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1344 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1351 * Give focus to next object in object tree.
1353 * Give focus to next object in focus chain of one object sub-tree.
1354 * If the last object of chain already have focus, the focus will go to the
1355 * first object of chain.
1357 * @param obj The widget root of sub-tree
1358 * @param dir Direction to cycle the focus
1363 elm_widget_focus_cycle(Evas_Object *obj,
1364 Elm_Focus_Direction dir)
1366 Evas_Object *target = NULL;
1367 if (!_elm_widget_is(obj))
1369 elm_widget_focus_next_get(obj, dir, &target);
1371 elm_widget_focus_steal(target);
1377 * Give focus to near object in one direction.
1379 * Give focus to near object in direction of one object.
1380 * If none focusable object in given direction, the focus will not change.
1382 * @param obj The reference widget
1383 * @param x Horizontal component of direction to focus
1384 * @param y Vertical component of direction to focus
1389 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1399 * Get next object in focus chain of object tree.
1401 * Get next object in focus chain of one object sub-tree.
1402 * Return the next object by reference. If don't have any candidate to receive
1403 * focus before chain end, the first candidate will be returned.
1405 * @param obj The widget root of sub-tree
1406 * @param dir Direction os focus chain
1407 * @param next The next object in focus chain
1408 * @return EINA_TRUE if don't need focus chain restart/loop back
1409 * to use 'next' obj.
1414 elm_widget_focus_next_get(const Evas_Object *obj,
1415 Elm_Focus_Direction dir,
1422 API_ENTRY return EINA_FALSE;
1424 /* Ignore if disabled */
1425 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1429 if (sd->focus_next_func)
1430 return sd->focus_next_func(obj, dir, next);
1432 if (!elm_widget_can_focus_get(obj))
1436 *next = (Evas_Object *)obj;
1437 return !elm_widget_focus_get(obj);
1443 * Get next object in focus chain of object tree in list.
1445 * Get next object in focus chain of one object sub-tree ordered by one list.
1446 * Return the next object by reference. If don't have any candidate to receive
1447 * focus before list end, the first candidate will be returned.
1449 * @param obj The widget root of sub-tree
1450 * @param dir Direction os focus chain
1451 * @param items list with ordered objects
1452 * @param list_data_get function to get the object from one item of list
1453 * @param next The next object in focus chain
1454 * @return EINA_TRUE if don't need focus chain restart/loop back
1455 * to use 'next' obj.
1460 elm_widget_focus_list_next_get(const Evas_Object *obj,
1461 const Eina_List *items,
1462 void *(*list_data_get)(const Eina_List * list),
1463 Elm_Focus_Direction dir,
1466 Eina_List *(*list_next)(const Eina_List * list);
1472 if (!_elm_widget_is(obj))
1479 if (dir == ELM_FOCUS_PREVIOUS)
1481 items = eina_list_last(items);
1482 list_next = eina_list_prev;
1484 else if (dir == ELM_FOCUS_NEXT)
1485 list_next = eina_list_next;
1489 const Eina_List *l = items;
1491 /* Recovery last focused sub item */
1492 if (elm_widget_focus_get(obj))
1493 for (; l; l = list_next(l))
1495 Evas_Object *cur = list_data_get(l);
1496 if (elm_widget_focus_get(cur)) break;
1499 const Eina_List *start = l;
1500 Evas_Object *to_focus = NULL;
1502 /* Interate sub items */
1503 /* Go to end of list */
1504 for (; l; l = list_next(l))
1506 Evas_Object *tmp = NULL;
1507 Evas_Object *cur = list_data_get(l);
1509 if (elm_widget_parent_get(cur) != obj)
1512 /* Try Focus cycle in subitem */
1513 if (elm_widget_focus_next_get(cur, dir, &tmp))
1518 else if ((tmp) && (!to_focus))
1524 /* Get First possible */
1525 for (; l != start; l = list_next(l))
1527 Evas_Object *tmp = NULL;
1528 Evas_Object *cur = list_data_get(l);
1530 if (elm_widget_parent_get(cur) != obj)
1533 /* Try Focus cycle in subitem */
1534 elm_widget_focus_next_get(cur, dir, &tmp);
1547 elm_widget_signal_emit(Evas_Object *obj,
1548 const char *emission,
1552 if (!sd->signal_func) return;
1553 sd->signal_func(obj, emission, source);
1557 _edje_signal_callback(void *data,
1558 Evas_Object *obj __UNUSED__,
1559 const char *emission,
1562 Edje_Signal_Data *esd = data;
1563 esd->func(esd->data, esd->obj, emission, source);
1567 elm_widget_signal_callback_add(Evas_Object *obj,
1568 const char *emission,
1570 Edje_Signal_Cb func,
1573 Edje_Signal_Data *esd;
1575 if (!sd->callback_add_func) return;
1576 EINA_SAFETY_ON_NULL_RETURN(func);
1578 esd = ELM_NEW(Edje_Signal_Data);
1583 esd->emission = eina_stringshare_add(emission);
1584 esd->source = eina_stringshare_add(source);
1586 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1587 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1591 elm_widget_signal_callback_del(Evas_Object *obj,
1592 const char *emission,
1594 Edje_Signal_Cb func)
1596 Edje_Signal_Data *esd;
1599 API_ENTRY return NULL;
1600 if (!sd->callback_del_func) return NULL;
1602 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1604 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1605 (!strcmp(esd->source, source)))
1607 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1608 eina_stringshare_del(esd->emission);
1609 eina_stringshare_del(esd->source);
1615 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1620 elm_widget_focus_set(Evas_Object *obj,
1627 sd->focus_order = focus_order;
1628 sd->focused = EINA_TRUE;
1629 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1633 sd->focus_func(obj);
1640 if ((_is_focusable(sd->resize_obj)) &&
1641 (!elm_widget_disabled_get(sd->resize_obj)))
1643 elm_widget_focus_set(sd->resize_obj, first);
1649 EINA_LIST_FOREACH(sd->subobjs, l, child)
1651 if ((_is_focusable(child)) &&
1652 (!elm_widget_disabled_get(child)))
1654 elm_widget_focus_set(child, first);
1664 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1666 if ((_is_focusable(child)) &&
1667 (!elm_widget_disabled_get(child)))
1669 elm_widget_focus_set(child, first);
1675 if ((_is_focusable(sd->resize_obj)) &&
1676 (!elm_widget_disabled_get(sd->resize_obj)))
1678 elm_widget_focus_set(sd->resize_obj, first);
1686 elm_widget_parent_get(const Evas_Object *obj)
1688 API_ENTRY return NULL;
1689 return sd->parent_obj;
1693 elm_widget_focused_object_clear(Evas_Object *obj)
1696 if (!sd->focused) return;
1697 if (elm_widget_focus_get(sd->resize_obj))
1698 elm_widget_focused_object_clear(sd->resize_obj);
1703 EINA_LIST_FOREACH(sd->subobjs, l, child)
1705 if (elm_widget_focus_get(child))
1707 elm_widget_focused_object_clear(child);
1712 sd->focused = EINA_FALSE;
1713 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1714 if (sd->focus_func) sd->focus_func(obj);
1718 elm_widget_focus_steal(Evas_Object *obj)
1720 Evas_Object *parent, *o;
1723 if (sd->focused) return;
1724 if (sd->disabled) return;
1728 o = elm_widget_parent_get(parent);
1730 sd = evas_object_smart_data_get(o);
1731 if (sd->focused) break;
1734 if (!elm_widget_parent_get(parent))
1735 elm_widget_focused_object_clear(parent);
1738 parent = elm_widget_parent_get(parent);
1739 sd = evas_object_smart_data_get(parent);
1740 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1741 elm_widget_focused_object_clear(sd->resize_obj);
1746 EINA_LIST_FOREACH(sd->subobjs, l, child)
1748 if (elm_widget_focus_get(child))
1750 elm_widget_focused_object_clear(child);
1761 elm_widget_activate(Evas_Object *obj)
1764 elm_widget_change(obj);
1765 if (sd->activate_func) sd->activate_func(obj);
1769 elm_widget_change(Evas_Object *obj)
1772 elm_widget_change(elm_widget_parent_get(obj));
1773 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1777 elm_widget_disabled_set(Evas_Object *obj,
1782 if (sd->disabled == disabled) return;
1783 sd->disabled = !!disabled;
1786 Evas_Object *o, *parent;
1791 o = elm_widget_parent_get(parent);
1795 if (elm_widget_focus_get(obj))
1796 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1798 if (sd->disable_func) sd->disable_func(obj);
1802 elm_widget_disabled_get(const Evas_Object *obj)
1805 return sd->disabled;
1809 elm_widget_show_region_set(Evas_Object *obj,
1815 Evas_Object *parent_obj, *child_obj;
1816 Evas_Coord px, py, cx, cy;
1819 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1824 if (sd->on_show_region_func)
1825 sd->on_show_region_func(sd->on_show_region_data, obj);
1829 parent_obj = sd->parent_obj;
1830 child_obj = sd->obj;
1831 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1832 sd = evas_object_smart_data_get(parent_obj);
1835 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1836 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1845 if (sd->on_show_region_func)
1847 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1854 elm_widget_show_region_get(const Evas_Object *obj,
1870 * Get the focus region of the given widget.
1872 * The focus region is the area of a widget that should brought into the
1873 * visible area when the widget is focused. Mostly used to show the part of
1874 * an entry where the cursor is, for example. The area returned is relative
1875 * to the object @p obj.
1876 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1877 * function will return the full size of the object.
1879 * @param obj The widget object
1880 * @param x Where to store the x coordinate of the area
1881 * @param y Where to store the y coordinate of the area
1882 * @param w Where to store the width of the area
1883 * @param h Where to store the height of the area
1888 elm_widget_focus_region_get(const Evas_Object *obj,
1898 sd = evas_object_smart_data_get(obj);
1899 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1901 evas_object_geometry_get(obj, NULL, NULL, w, h);
1906 sd->on_focus_region_func(obj, x, y, w, h);
1910 elm_widget_scroll_hold_push(Evas_Object *obj)
1914 if (sd->scroll_hold == 1)
1915 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1916 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1917 // FIXME: on delete/reparent hold pop
1921 elm_widget_scroll_hold_pop(Evas_Object *obj)
1925 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1926 if (!sd->scroll_hold)
1927 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1928 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1932 elm_widget_scroll_hold_get(const Evas_Object *obj)
1935 return sd->scroll_hold;
1939 elm_widget_scroll_freeze_push(Evas_Object *obj)
1942 sd->scroll_freeze++;
1943 if (sd->scroll_freeze == 1)
1944 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1945 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1946 // FIXME: on delete/reparent freeze pop
1950 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1953 sd->scroll_freeze--;
1954 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1955 if (!sd->scroll_freeze)
1956 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1957 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1961 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1964 return sd->scroll_freeze;
1968 elm_widget_scale_set(Evas_Object *obj,
1972 if (scale <= 0.0) scale = 0.0;
1973 if (sd->scale != scale)
1976 elm_widget_theme(obj);
1981 elm_widget_scale_get(const Evas_Object *obj)
1983 API_ENTRY return 1.0;
1984 // FIXME: save walking up the tree by storing/caching parent scale
1985 if (sd->scale == 0.0)
1988 return elm_widget_scale_get(sd->parent_obj);
1996 elm_widget_theme_set(Evas_Object *obj,
2000 if (sd->theme != th)
2002 if (sd->theme) elm_theme_free(sd->theme);
2005 elm_widget_theme(obj);
2010 elm_widget_theme_get(const Evas_Object *obj)
2012 API_ENTRY return NULL;
2016 return elm_widget_theme_get(sd->parent_obj);
2024 elm_widget_style_set(Evas_Object *obj,
2029 if (eina_stringshare_replace(&sd->style, style))
2030 elm_widget_theme(obj);
2034 elm_widget_style_get(const Evas_Object *obj)
2036 API_ENTRY return NULL;
2037 if (sd->style) return sd->style;
2042 elm_widget_type_set(Evas_Object *obj,
2046 eina_stringshare_replace(&sd->type, type);
2050 elm_widget_type_get(const Evas_Object *obj)
2052 API_ENTRY return NULL;
2053 if (sd->type) return sd->type;
2058 elm_widget_tooltip_add(Evas_Object *obj,
2062 sd->tooltips = eina_list_append(sd->tooltips, tt);
2066 elm_widget_tooltip_del(Evas_Object *obj,
2070 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2074 elm_widget_cursor_add(Evas_Object *obj,
2078 sd->cursors = eina_list_append(sd->cursors, cur);
2082 elm_widget_cursor_del(Evas_Object *obj,
2086 sd->cursors = eina_list_remove(sd->cursors, cur);
2090 elm_widget_drag_lock_x_set(Evas_Object *obj,
2094 if (sd->drag_x_locked == lock) return;
2095 sd->drag_x_locked = lock;
2096 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2097 else _propagate_x_drag_lock(obj, -1);
2101 elm_widget_drag_lock_y_set(Evas_Object *obj,
2105 if (sd->drag_y_locked == lock) return;
2106 sd->drag_y_locked = lock;
2107 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2108 else _propagate_y_drag_lock(obj, -1);
2112 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2114 API_ENTRY return EINA_FALSE;
2115 return sd->drag_x_locked;
2119 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2121 API_ENTRY return EINA_FALSE;
2122 return sd->drag_y_locked;
2126 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2129 return sd->child_drag_x_locked;
2133 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2136 return sd->child_drag_y_locked;
2140 elm_widget_theme_object_set(Evas_Object *obj,
2143 const char *welement,
2146 API_ENTRY return EINA_FALSE;
2147 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2151 elm_widget_type_check(const Evas_Object *obj,
2154 const char *provided, *expected = "(unknown)";
2155 static int abort_on_warn = -1;
2156 provided = elm_widget_type_get(obj);
2157 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2158 if (type) expected = type;
2159 if ((!provided) || (!provided[0]))
2161 provided = evas_object_type_get(obj);
2162 if ((!provided) || (!provided[0]))
2163 provided = "(unknown)";
2165 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2166 if (abort_on_warn == -1)
2168 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2169 else abort_on_warn = 0;
2171 if (abort_on_warn == 1) abort();
2178 * Split string in words
2180 * @param str Source string
2181 * @return List of const words
2183 * @see elm_widget_stringlist_free()
2187 elm_widget_stringlist_get(const char *str)
2189 Eina_List *list = NULL;
2191 if (!str) return NULL;
2192 for (b = s = str; 1; s++)
2194 if ((*s == ' ') || (!*s))
2196 char *t = malloc(s - b + 1);
2199 strncpy(t, b, s - b);
2201 list = eina_list_append(list, eina_stringshare_add(t));
2212 elm_widget_stringlist_free(Eina_List *list)
2215 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2219 elm_widget_focus_hide_handle(Evas_Object *obj)
2221 _if_focused_revert(obj, EINA_TRUE);
2225 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2227 Evas_Object *o = obj;
2230 if (_elm_widget_is(o)) break;
2231 o = evas_object_smart_parent_get(o);
2235 if (!_is_focusable(o)) return;
2236 elm_widget_focus_steal(o);
2242 * Allocate a new Elm_Widget_Item-derived structure.
2244 * The goal of this structure is to provide common ground for actions
2245 * that a widget item have, such as the owner widget, callback to
2246 * notify deletion, data pointer and maybe more.
2248 * @param widget the owner widget that holds this item, must be an elm_widget!
2249 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2250 * be used to allocate memory.
2252 * @return allocated memory that is already zeroed out, or NULL on errors.
2254 * @see elm_widget_item_new() convenience macro.
2255 * @see elm_widget_item_del() to release memory.
2258 EAPI Elm_Widget_Item *
2259 _elm_widget_item_new(Evas_Object *widget,
2262 if (!_elm_widget_is(widget))
2265 Elm_Widget_Item *item;
2267 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2268 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2270 item = calloc(1, alloc_size);
2271 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2273 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2274 item->widget = widget;
2281 * Releases widget item memory, calling back del_cb() if it exists.
2283 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2284 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2285 * this function and then unset it, thus being useful for 2 step
2286 * cleanup whenever the del_cb may use any of the data that must be
2287 * deleted from item.
2289 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2292 * @param item a valid #Elm_Widget_Item to be deleted.
2293 * @see elm_widget_item_del() convenience macro.
2297 _elm_widget_item_del(Elm_Widget_Item *item)
2299 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2302 item->del_cb((void *)item->data, item->widget, item);
2305 evas_object_del(item->view);
2307 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2314 * Notify object will be deleted without actually deleting it.
2316 * This function will callback Elm_Widget_Item::del_cb if it is set
2317 * and then unset it so it is not called twice (ie: from
2318 * elm_widget_item_del()).
2320 * @param item a valid #Elm_Widget_Item to be notified
2321 * @see elm_widget_item_pre_notify_del() convenience macro.
2325 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2327 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2328 if (!item->del_cb) return;
2329 item->del_cb((void *)item->data, item->widget, item);
2330 item->del_cb = NULL;
2336 * Set the function to notify when item is being deleted.
2338 * This function will complain if there was a callback set already,
2339 * however it will set the new one.
2341 * The callback will be called from elm_widget_item_pre_notify_del()
2342 * or elm_widget_item_del() will be called with:
2343 * - data: the Elm_Widget_Item::data value.
2344 * - obj: the Elm_Widget_Item::widget evas object.
2345 * - event_info: the item being deleted.
2347 * @param item a valid #Elm_Widget_Item to be notified
2348 * @see elm_widget_item_del_cb_set() convenience macro.
2352 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2353 Evas_Smart_Cb del_cb)
2355 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2357 if ((item->del_cb) && (item->del_cb != del_cb))
2358 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2359 item->del_cb, item, del_cb);
2361 item->del_cb = del_cb;
2367 * Set user-data in this item.
2369 * User data may be used to identify this item or just store any
2370 * application data. It is automatically given as the first parameter
2371 * of the deletion notify callback.
2373 * @param item a valid #Elm_Widget_Item to store data in.
2374 * @param data user data to store.
2375 * @see elm_widget_item_del_cb_set() convenience macro.
2379 _elm_widget_item_data_set(Elm_Widget_Item *item,
2382 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2383 if ((item->data) && (item->data != data))
2384 DBG("Replacing item %p data %p with %p", item, item->data, data);
2391 * Retrieves user-data of this item.
2393 * @param item a valid #Elm_Widget_Item to get data from.
2394 * @see elm_widget_item_data_set()
2398 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2400 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2401 return (void *)item->data;
2404 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2406 struct _Elm_Widget_Item_Tooltip
2408 Elm_Widget_Item *item;
2409 Elm_Tooltip_Item_Content_Cb func;
2410 Evas_Smart_Cb del_cb;
2414 static Evas_Object *
2415 _elm_widget_item_tooltip_label_create(void *data,
2417 void *item __UNUSED__)
2419 Evas_Object *label = elm_label_add(obj);
2422 elm_object_style_set(label, "tooltip");
2423 elm_label_label_set(label, data);
2428 _elm_widget_item_tooltip_label_del_cb(void *data,
2429 Evas_Object *obj __UNUSED__,
2430 void *event_info __UNUSED__)
2432 eina_stringshare_del(data);
2438 * Set the text to be shown in the widget item.
2440 * @param item Target item
2441 * @param text The text to set in the content
2443 * Setup the text as tooltip to object. The item can have only one tooltip,
2444 * so any previous tooltip data is removed.
2449 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2452 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2453 EINA_SAFETY_ON_NULL_RETURN(text);
2455 text = eina_stringshare_add(text);
2456 _elm_widget_item_tooltip_content_cb_set
2457 (item, _elm_widget_item_tooltip_label_create, text,
2458 _elm_widget_item_tooltip_label_del_cb);
2461 static Evas_Object *
2462 _elm_widget_item_tooltip_create(void *data,
2465 Elm_Widget_Item_Tooltip *wit = data;
2466 return wit->func((void *)wit->data, obj, wit->item);
2470 _elm_widget_item_tooltip_del_cb(void *data,
2472 void *event_info __UNUSED__)
2474 Elm_Widget_Item_Tooltip *wit = data;
2475 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2482 * Set the content to be shown in the tooltip item
2484 * Setup the tooltip to item. The item can have only one tooltip,
2485 * so any previous tooltip data is removed. @p func(with @p data) will
2486 * be called every time that need show the tooltip and it should
2487 * return a valid Evas_Object. This object is then managed fully by
2488 * tooltip system and is deleted when the tooltip is gone.
2490 * @param item the widget item being attached a tooltip.
2491 * @param func the function used to create the tooltip contents.
2492 * @param data what to provide to @a func as callback data/context.
2493 * @param del_cb called when data is not needed anymore, either when
2494 * another callback replaces @func, the tooltip is unset with
2495 * elm_widget_item_tooltip_unset() or the owner @a item
2496 * dies. This callback receives as the first parameter the
2497 * given @a data, and @c event_info is the item.
2502 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2503 Elm_Tooltip_Item_Content_Cb func,
2505 Evas_Smart_Cb del_cb)
2507 Elm_Widget_Item_Tooltip *wit;
2509 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2513 _elm_widget_item_tooltip_unset(item);
2517 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2518 if (!wit) goto error;
2522 wit->del_cb = del_cb;
2524 elm_object_sub_tooltip_content_cb_set
2525 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2526 _elm_widget_item_tooltip_del_cb);
2531 if (del_cb) del_cb((void *)data, NULL, item);
2534 if (del_cb) del_cb((void *)data, item->widget, item);
2540 * Unset tooltip from item
2542 * @param item widget item to remove previously set tooltip.
2544 * Remove tooltip from item. The callback provided as del_cb to
2545 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2546 * it is not used anymore.
2548 * @see elm_widget_item_tooltip_content_cb_set()
2553 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2555 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2556 elm_object_tooltip_unset(item->view);
2562 * Sets a different style for this item tooltip.
2564 * @note before you set a style you should define a tooltip with
2565 * elm_widget_item_tooltip_content_cb_set() or
2566 * elm_widget_item_tooltip_text_set()
2568 * @param item widget item with tooltip already set.
2569 * @param style the theme style to use (default, transparent, ...)
2574 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2577 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2578 elm_object_tooltip_style_set(item->view, style);
2584 * Get the style for this item tooltip.
2586 * @param item widget item with tooltip already set.
2587 * @return style the theme style in use, defaults to "default". If the
2588 * object does not have a tooltip set, then NULL is returned.
2593 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2595 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2596 return elm_object_tooltip_style_get(item->view);
2600 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2603 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2604 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2608 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2610 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2611 return elm_object_cursor_get(item->view);
2615 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2617 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2618 elm_object_cursor_unset(item->view);
2624 * Sets a different style for this item cursor.
2626 * @note before you set a style you should define a cursor with
2627 * elm_widget_item_cursor_set()
2629 * @param item widget item with cursor already set.
2630 * @param style the theme style to use (default, transparent, ...)
2635 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2638 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2639 elm_object_cursor_style_set(item->view, style);
2645 * Get the style for this item cursor.
2647 * @param item widget item with cursor already set.
2648 * @return style the theme style in use, defaults to "default". If the
2649 * object does not have a cursor set, then NULL is returned.
2654 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2656 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2657 return elm_object_cursor_style_get(item->view);
2663 * Set if the cursor set should be searched on the theme or should use
2664 * the provided by the engine, only.
2666 * @note before you set if should look on theme you should define a cursor
2667 * with elm_object_cursor_set(). By default it will only look for cursors
2668 * provided by the engine.
2670 * @param item widget item with cursor already set.
2671 * @param engine_only boolean to define it cursors should be looked only
2672 * between the provided by the engine or searched on widget's theme as well.
2677 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2678 Eina_Bool engine_only)
2680 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2681 elm_object_cursor_engine_only_set(item->view, engine_only);
2687 * Get the cursor engine only usage for this item cursor.
2689 * @param item widget item with cursor already set.
2690 * @return engine_only boolean to define it cursors should be looked only
2691 * between the provided by the engine or searched on widget's theme as well. If
2692 * the object does not have a cursor set, then EINA_FALSE is returned.
2697 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2699 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2700 return elm_object_cursor_engine_only_get(item->view);
2703 // smart object funcs
2705 _smart_reconfigure(Smart_Data *sd)
2709 evas_object_move(sd->resize_obj, sd->x, sd->y);
2710 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2714 evas_object_move(sd->hover_obj, sd->x, sd->y);
2715 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2720 _smart_add(Evas_Object *obj)
2724 sd = calloc(1, sizeof(Smart_Data));
2727 sd->x = sd->y = sd->w = sd->h = 0;
2729 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2730 evas_object_smart_data_set(obj, sd);
2733 static Evas_Object *
2734 _newest_focus_order_get(Evas_Object *obj,
2735 unsigned int *newest_focus_order,
2736 Eina_Bool can_focus_only)
2739 Evas_Object *child, *ret, *best;
2741 API_ENTRY return NULL;
2742 if (!evas_object_visible_get(obj)) return NULL;
2744 if (*newest_focus_order < sd->focus_order)
2746 *newest_focus_order = sd->focus_order;
2749 EINA_LIST_FOREACH(sd->subobjs, l, child)
2751 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2757 if ((!best) || (!elm_widget_can_focus_get(best)))
2764 _if_focused_revert(Evas_Object *obj,
2765 Eina_Bool can_focus_only)
2768 Evas_Object *newest = NULL;
2769 unsigned int newest_focus_order = 0;
2773 if (!sd->focused) return;
2774 if (!sd->parent_obj) return;
2776 top = elm_widget_top_get(sd->parent_obj);
2779 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2782 elm_object_unfocus(newest);
2783 elm_object_focus(newest);
2789 _smart_del(Evas_Object *obj)
2792 Edje_Signal_Data *esd;
2796 if (sd->del_pre_func) sd->del_pre_func(obj);
2799 sobj = sd->resize_obj;
2800 sd->resize_obj = NULL;
2801 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2802 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2803 evas_object_del(sobj);
2807 sobj = sd->hover_obj;
2808 sd->hover_obj = NULL;
2809 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2810 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2811 evas_object_del(sobj);
2813 EINA_LIST_FREE(sd->subobjs, sobj)
2815 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2816 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2817 evas_object_del(sobj);
2819 eina_list_free(sd->tooltips); /* should be empty anyway */
2820 eina_list_free(sd->cursors); /* should be empty anyway */
2821 EINA_LIST_FREE(sd->edje_signals, esd)
2823 eina_stringshare_del(esd->emission);
2824 eina_stringshare_del(esd->source);
2827 eina_list_free(sd->event_cb); /* should be empty anyway */
2828 if (sd->del_func) sd->del_func(obj);
2829 if (sd->style) eina_stringshare_del(sd->style);
2830 if (sd->type) eina_stringshare_del(sd->type);
2831 if (sd->theme) elm_theme_free(sd->theme);
2832 _if_focused_revert(obj, EINA_TRUE);
2837 _smart_move(Evas_Object *obj,
2844 _smart_reconfigure(sd);
2848 _smart_resize(Evas_Object *obj,
2855 _smart_reconfigure(sd);
2859 _smart_show(Evas_Object *obj)
2864 if ((list = evas_object_smart_members_get(obj)))
2866 EINA_LIST_FREE(list, o)
2868 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2869 evas_object_show(o);
2875 _smart_hide(Evas_Object *obj)
2881 list = evas_object_smart_members_get(obj);
2882 EINA_LIST_FREE(list, o)
2884 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2885 evas_object_hide(o);
2890 _smart_color_set(Evas_Object *obj,
2899 if ((list = evas_object_smart_members_get(obj)))
2901 EINA_LIST_FREE(list, o)
2903 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2904 evas_object_color_set(o, r, g, b, a);
2910 _smart_clip_set(Evas_Object *obj,
2916 if ((list = evas_object_smart_members_get(obj)))
2918 EINA_LIST_FREE(list, o)
2920 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2921 evas_object_clip_set(o, clip);
2927 _smart_clip_unset(Evas_Object *obj)
2932 if ((list = evas_object_smart_members_get(obj)))
2934 EINA_LIST_FREE(list, o)
2936 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2937 evas_object_clip_unset(o);
2943 _smart_calculate(Evas_Object *obj)
2946 if (sd->changed_func) sd->changed_func(obj);
2949 /* never need to touch this */
2953 if (_e_smart) return;
2955 static const Evas_Smart_Class sc =
2958 EVAS_SMART_CLASS_VERSION,
2976 _e_smart = evas_smart_class_new(&sc);
2980 /* happy debug functions */
2983 _sub_obj_tree_dump(const Evas_Object *obj,
2988 for (i = 0; i < lvl * 3; i++)
2991 if (_elm_widget_is(obj))
2995 printf("+ %s(%p)\n",
2999 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3000 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3002 if (obj != sd->resize_obj)
3003 _sub_obj_tree_dump(obj, lvl + 1);
3007 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3011 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3014 if (!_elm_widget_is(obj))
3018 Eina_Bool visible = evas_object_visible_get(obj);
3019 Eina_Bool disabled = elm_widget_disabled_get(obj);
3020 Eina_Bool focused = elm_widget_focus_get(obj);
3021 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3025 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3028 fprintf(output, ", style=bold");
3031 fprintf(output, ", color=gray28");
3033 fprintf(output, " ];\n");
3036 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3037 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3038 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3042 fprintf(output, ", style=bold");
3045 fprintf(output, ", fontcolor=gray28");
3047 if ((disabled) || (!visible))
3048 fprintf(output, ", color=gray");
3050 fprintf(output, " ];\n");
3054 EINA_LIST_FOREACH(sd->subobjs, l, o)
3055 _sub_obj_tree_dot_dump(o, output);
3060 elm_widget_tree_dump(const Evas_Object *top)
3063 _sub_obj_tree_dump(top, 0);
3071 elm_widget_tree_dot_dump(const Evas_Object *top,
3075 if (!_elm_widget_is(top))
3077 fprintf(output, "graph " " { node [shape=record];\n");
3078 _sub_obj_tree_dot_dump(top, output);
3079 fprintf(output, "}\n");