1 #include <Elementary.h>
4 static const char SMART_NAME[] = "elm_widget";
7 Smart_Data * sd = evas_object_smart_data_get(obj); \
8 if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
9 #define INTERNAL_ENTRY \
10 Smart_Data * sd = evas_object_smart_data_get(obj); \
13 typedef struct _Smart_Data Smart_Data;
14 typedef struct _Edje_Signal_Data Edje_Signal_Data;
15 typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data;
21 Evas_Object *parent_obj;
22 Evas_Coord x, y, w, h;
24 Evas_Object *resize_obj;
25 Evas_Object *hover_obj;
26 Eina_List *tooltips, *cursors;
27 void (*del_func)(Evas_Object *obj);
28 void (*del_pre_func)(Evas_Object *obj);
29 void (*focus_func)(Evas_Object *obj);
30 void (*activate_func)(Evas_Object *obj);
31 void (*disable_func)(Evas_Object *obj);
32 void (*theme_func)(Evas_Object *obj);
33 Eina_Bool (*event_func)(Evas_Object *obj,
35 Evas_Callback_Type type,
37 void (*signal_func)(Evas_Object *obj,
40 void (*callback_add_func)(Evas_Object *obj,
45 void (*callback_del_func)(Evas_Object *obj,
50 void (*changed_func)(Evas_Object *obj);
51 Eina_Bool (*focus_next_func)(const Evas_Object *obj,
52 Elm_Focus_Direction dir,
54 void (*on_focus_func)(void *data,
57 void (*on_change_func)(void *data,
60 void (*on_show_region_func)(void *data,
62 void *on_show_region_data;
63 void (*focus_region_func)(Evas_Object *obj,
68 void (*on_focus_region_func)(const Evas_Object *obj,
74 Evas_Coord rx, ry, rw, rh;
80 unsigned int focus_order;
81 Eina_Bool focus_order_on_calc;
83 int child_drag_x_locked;
84 int child_drag_y_locked;
86 Eina_List *edje_signals;
88 Eina_Bool drag_x_locked : 1;
89 Eina_Bool drag_y_locked : 1;
91 Eina_Bool can_focus : 1;
92 Eina_Bool child_can_focus : 1;
93 Eina_Bool focused : 1;
94 Eina_Bool highlight_ignore : 1;
95 Eina_Bool highlight_in_theme : 1;
96 Eina_Bool disabled : 1;
97 Eina_Bool is_mirrored : 1;
98 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
100 Eina_List *focus_chain;
104 struct _Edje_Signal_Data
108 const char *emission;
113 struct _Elm_Event_Cb_Data
119 /* local subsystem functions */
120 static void _smart_reconfigure(Smart_Data *sd);
121 static void _smart_add(Evas_Object *obj);
122 static void _smart_del(Evas_Object *obj);
123 static void _smart_move(Evas_Object *obj,
126 static void _smart_resize(Evas_Object *obj,
129 static void _smart_show(Evas_Object *obj);
130 static void _smart_hide(Evas_Object *obj);
131 static void _smart_color_set(Evas_Object *obj,
136 static void _smart_clip_set(Evas_Object *obj,
138 static void _smart_clip_unset(Evas_Object *obj);
139 static void _smart_calculate(Evas_Object *obj);
140 static void _smart_init(void);
142 static void _if_focused_revert(Evas_Object *obj,
143 Eina_Bool can_focus_only);
144 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
145 unsigned int *newest_focus_order,
146 Eina_Bool can_focus_only);
148 /* local subsystem globals */
149 static Evas_Smart *_e_smart = NULL;
150 static Eina_List *widtypes = NULL;
152 static unsigned int focus_order = 0;
155 static inline Eina_Bool
156 _elm_widget_is(const Evas_Object *obj)
158 const char *type = evas_object_type_get(obj);
159 return type == SMART_NAME;
162 static inline Eina_Bool
163 _is_focusable(Evas_Object *obj)
165 API_ENTRY return EINA_FALSE;
166 return sd->can_focus || (sd->child_can_focus);
170 _unfocus_parents(Evas_Object *obj)
172 for (; obj; obj = elm_widget_parent_get(obj))
175 if (!sd->focused) return;
181 _focus_parents(Evas_Object *obj)
183 for (; obj; obj = elm_widget_parent_get(obj))
186 if (sd->focused) return;
192 _sub_obj_del(void *data,
195 void *event_info __UNUSED__)
197 Smart_Data *sd = data;
199 if (_elm_widget_is(obj))
201 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
203 if (obj == sd->resize_obj)
204 sd->resize_obj = NULL;
205 else if (obj == sd->hover_obj)
206 sd->hover_obj = NULL;
208 sd->subobjs = eina_list_remove(sd->subobjs, obj);
209 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
213 _sub_obj_hide(void *data __UNUSED__,
216 void *event_info __UNUSED__)
218 _if_focused_revert(obj, EINA_TRUE);
222 _sub_obj_mouse_down(void *data __UNUSED__,
225 void *event_info __UNUSED__)
227 Evas_Object *o = obj;
230 if (_elm_widget_is(o)) break;
231 o = evas_object_smart_parent_get(o);
235 if (!_is_focusable(o)) return;
236 elm_widget_focus_steal(o);
240 _propagate_x_drag_lock(Evas_Object *obj,
246 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
249 sd2->child_drag_x_locked += dir;
250 _propagate_x_drag_lock(sd->parent_obj, dir);
256 _propagate_y_drag_lock(Evas_Object *obj,
262 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
265 sd2->child_drag_y_locked += dir;
266 _propagate_y_drag_lock(sd->parent_obj, dir);
272 _propagate_event(void *data,
278 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
279 Evas_Event_Flags *event_flags = NULL;
283 case EVAS_CALLBACK_KEY_DOWN:
284 Evas_Event_Key_Down *ev = event_info;
285 event_flags = &(ev->event_flags);
288 case EVAS_CALLBACK_KEY_UP:
289 Evas_Event_Key_Up *ev = event_info;
290 event_flags = &(ev->event_flags);
293 case EVAS_CALLBACK_MOUSE_WHEEL:
294 Evas_Event_Mouse_Wheel *ev = event_info;
295 event_flags = &(ev->event_flags);
302 elm_widget_event_propagate(obj, type, event_info, event_flags);
306 _parent_focus(Evas_Object *obj)
310 Evas_Object *o = elm_widget_parent_get(obj);
311 sd->focus_order_on_calc = EINA_TRUE;
313 if (sd->focused) return;
319 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
321 /* we don't want to bump a common widget ancestor's
322 focus_order *twice* while parent focusing */
323 if (!ret || (!i) || (i != focus_order))
327 if (!sd->focus_order_on_calc)
328 return; /* we don't want to override it if by means of any of the
329 callbacks below one gets to calculate our order
333 sd->focus_order = focus_order;
334 sd->focused = EINA_TRUE;
335 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
336 if (sd->focus_func) sd->focus_func(obj);
338 _elm_widget_focus_region_show(obj);
340 sd->focus_order_on_calc = EINA_FALSE;
344 _elm_object_focus_chain_del_cb(void *data,
347 void *event_info __UNUSED__)
349 Smart_Data *sd = data;
351 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
354 // exposed util funcs to elm
356 _elm_widget_type_clear(void)
360 EINA_LIST_FREE(widtypes, ptr)
362 eina_stringshare_del(*ptr);
368 _elm_widget_focus_region_show(const Evas_Object *obj)
370 Evas_Coord x, y, w, h, ox, oy;
376 o = elm_widget_parent_get(obj);
379 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
380 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
384 sd2 = evas_object_smart_data_get(o);
385 if (sd2->focus_region_func)
387 sd2->focus_region_func(o, x, y, w, h);
388 elm_widget_focus_region_get(o, &x, &y, &w, &h);
392 evas_object_geometry_get(o, &px, &py, NULL, NULL);
398 o = elm_widget_parent_get(o);
403 * @defgroup Widget Widget
406 * Exposed api for making widgets
409 elm_widget_type_register(const char **ptr)
411 widtypes = eina_list_append(widtypes, (void *)ptr);
415 elm_widget_api_check(int ver)
417 if (ver != ELM_INTERNAL_API_VERSION)
419 CRITICAL("Elementary widget api versions do not match");
426 elm_widget_add(Evas *evas)
430 obj = evas_object_smart_add(evas, _e_smart);
431 elm_widget_mirrored_set(obj, elm_mirrored_get());
436 elm_widget_del_hook_set(Evas_Object *obj,
437 void (*func)(Evas_Object *obj))
444 elm_widget_del_pre_hook_set(Evas_Object *obj,
445 void (*func)(Evas_Object *obj))
448 sd->del_pre_func = func;
452 elm_widget_focus_hook_set(Evas_Object *obj,
453 void (*func)(Evas_Object *obj))
456 sd->focus_func = func;
460 elm_widget_activate_hook_set(Evas_Object *obj,
461 void (*func)(Evas_Object *obj))
464 sd->activate_func = func;
468 elm_widget_disable_hook_set(Evas_Object *obj,
469 void (*func)(Evas_Object *obj))
472 sd->disable_func = func;
476 elm_widget_theme_hook_set(Evas_Object *obj,
477 void (*func)(Evas_Object *obj))
480 sd->theme_func = func;
484 elm_widget_event_hook_set(Evas_Object *obj,
485 Eina_Bool (*func)(Evas_Object *obj,
487 Evas_Callback_Type type,
491 sd->event_func = func;
495 elm_widget_changed_hook_set(Evas_Object *obj,
496 void (*func)(Evas_Object *obj))
499 sd->changed_func = func;
503 elm_widget_signal_emit_hook_set(Evas_Object *obj,
504 void (*func)(Evas_Object *obj,
505 const char *emission,
509 sd->signal_func = func;
513 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
514 void (*func)(Evas_Object *obj,
515 const char *emission,
517 Edje_Signal_Cb func_cb,
521 sd->callback_add_func = func;
525 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
526 void (*func)(Evas_Object *obj,
527 const char *emission,
529 Edje_Signal_Cb func_cb,
533 sd->callback_del_func = func;
537 elm_widget_theme(Evas_Object *obj)
545 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
546 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
547 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
548 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
549 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
550 if (sd->theme_func) sd->theme_func(obj);
554 elm_widget_theme_specific(Evas_Object *obj,
562 Elm_Theme *th2, *thdef;
565 thdef = elm_theme_default_get();
570 if (!th2) th2 = thdef;
578 if (th2 == thdef) break;
579 th2 = th2->ref_theme;
580 if (!th2) th2 = thdef;
584 EINA_LIST_FOREACH(sd->subobjs, l, child)
585 elm_widget_theme_specific(child, th, force);
586 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
587 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
588 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
589 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
590 if (sd->theme_func) sd->theme_func(obj);
596 * Set hook to get next object in object focus chain.
598 * @param obj The widget object.
599 * @param func The hook to be used with this widget.
604 elm_widget_focus_next_hook_set(Evas_Object *obj,
605 Eina_Bool (*func)(const Evas_Object *obj,
606 Elm_Focus_Direction dir,
610 sd->focus_next_func = func;
614 * Returns the widget's mirrored mode.
616 * @param obj The widget.
617 * @return mirrored mode of the object.
621 elm_widget_mirrored_get(const Evas_Object *obj)
623 API_ENTRY return EINA_FALSE;
624 return sd->is_mirrored;
628 * Sets the widget's mirrored mode.
630 * @param obj The widget.
631 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
634 elm_widget_mirrored_set(Evas_Object *obj,
638 if (sd->is_mirrored != mirrored)
640 sd->is_mirrored = mirrored;
641 elm_widget_theme(obj);
647 * Resets the mirrored mode from the system mirror mode for widgets that are in
648 * automatic mirroring mode. This function does not call elm_widget_theme.
650 * @param obj The widget.
651 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
654 _elm_widget_mirrored_reload(Evas_Object *obj)
657 Eina_Bool mirrored = elm_mirrored_get();
658 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
660 sd->is_mirrored = mirrored;
665 * Returns the widget's mirrored mode setting.
667 * @param obj The widget.
668 * @return mirrored mode setting of the object.
672 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
674 API_ENTRY return EINA_FALSE;
675 return sd->mirrored_auto_mode;
679 * Sets the widget's mirrored mode setting.
680 * When widget in automatic mode, it follows the system mirrored mode set by
681 * elm_mirrored_set().
682 * @param obj The widget.
683 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
686 elm_widget_mirrored_automatic_set(Evas_Object *obj,
690 if (sd->mirrored_auto_mode != automatic)
692 sd->mirrored_auto_mode = automatic;
696 elm_widget_mirrored_set(obj, elm_mirrored_get());
702 elm_widget_on_focus_hook_set(Evas_Object *obj,
703 void (*func)(void *data,
708 sd->on_focus_func = func;
709 sd->on_focus_data = data;
713 elm_widget_on_change_hook_set(Evas_Object *obj,
714 void (*func)(void *data,
719 sd->on_change_func = func;
720 sd->on_change_data = data;
724 elm_widget_on_show_region_hook_set(Evas_Object *obj,
725 void (*func)(void *data,
730 sd->on_show_region_func = func;
731 sd->on_show_region_data = data;
737 * Set the hook to use to show the focused region.
739 * Whenever a new widget gets focused or it's needed to show the focused
740 * area of the current one, this hook will be called on objects that may
741 * want to move their children into their visible area.
742 * The area given in the hook function is relative to the @p obj widget.
744 * @param obj The widget object
745 * @param func The function to call to show the specified area.
750 elm_widget_focus_region_hook_set(Evas_Object *obj,
751 void (*func)(Evas_Object *obj,
758 sd->focus_region_func = func;
764 * Set the hook to retrieve the focused region of a widget.
766 * This hook will be called by elm_widget_focus_region_get() whenever
767 * it's needed to get the focused area of a widget. The area must be relative
768 * to the widget itself and if no hook is set, it will default to the entire
771 * @param obj The widget object
772 * @param func The function used to retrieve the focus region.
777 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
778 void (*func)(const Evas_Object *obj,
785 sd->on_focus_region_func = func;
789 elm_widget_data_set(Evas_Object *obj,
797 elm_widget_data_get(const Evas_Object *obj)
799 API_ENTRY return NULL;
804 elm_widget_sub_object_add(Evas_Object *obj,
808 double scale, pscale = elm_widget_scale_get(sobj);
809 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
810 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
812 if (_elm_widget_is(sobj))
814 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
817 if (sd2->parent_obj == obj)
820 elm_widget_sub_object_del(sd2->parent_obj, sobj);
821 sd2->parent_obj = obj;
822 if (!sd->child_can_focus && (_is_focusable(sobj)))
823 sd->child_can_focus = EINA_TRUE;
828 void *data = evas_object_data_get(sobj, "elm-parent");
831 if (data == obj) return;
832 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
837 sd->subobjs = eina_list_append(sd->subobjs, sobj);
838 evas_object_data_set(sobj, "elm-parent", obj);
839 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
840 if (_elm_widget_is(sobj))
841 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
842 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
843 scale = elm_widget_scale_get(sobj);
844 th = elm_widget_theme_get(sobj);
845 mirrored = elm_widget_mirrored_get(sobj);
846 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
847 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
851 elm_widget_sub_object_del(Evas_Object *obj,
854 Evas_Object *sobj_parent;
858 sobj_parent = evas_object_data_del(sobj, "elm-parent");
859 if (sobj_parent != obj)
861 static int abort_on_warn = -1;
862 ERR("removing sub object %p from parent %p, "
863 "but elm-parent is different %p!",
864 sobj, obj, sobj_parent);
865 if (EINA_UNLIKELY(abort_on_warn == -1))
867 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
868 else abort_on_warn = 0;
870 if (abort_on_warn == 1) abort();
872 if (!sd->child_can_focus)
874 if (_is_focusable(sobj)) sd->child_can_focus = 0;
876 if (_elm_widget_is(sobj))
878 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
881 sd2->parent_obj = NULL;
882 if (sd2->resize_obj == sobj)
883 sd2->resize_obj = NULL;
885 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
888 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
889 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
892 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
893 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
895 if (_elm_widget_is(sobj))
896 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
898 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
902 elm_widget_resize_object_set(Evas_Object *obj,
906 // orphan previous resize obj
909 evas_object_clip_unset(sd->resize_obj);
910 evas_object_data_del(sd->resize_obj, "elm-parent");
911 if (_elm_widget_is(sd->resize_obj))
913 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
914 if (sd2) sd2->parent_obj = NULL;
915 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
918 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
920 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
921 _sub_obj_mouse_down, sd);
922 evas_object_smart_member_del(sd->resize_obj);
923 if (_elm_widget_is(sd->resize_obj))
925 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
928 // orphan new resize obj
931 evas_object_data_del(sobj, "elm-parent");
932 if (_elm_widget_is(sobj))
934 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
935 if (sd2) sd2->parent_obj = NULL;
936 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
939 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
941 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
942 _sub_obj_mouse_down, sd);
943 evas_object_smart_member_del(sobj);
944 if (_elm_widget_is(sobj))
946 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
949 // set the resize obj up
950 sd->resize_obj = sobj;
953 if (_elm_widget_is(sd->resize_obj))
955 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
956 if (sd2) sd2->parent_obj = obj;
957 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
960 evas_object_clip_set(sobj, evas_object_clip_get(obj));
961 evas_object_smart_member_add(sobj, obj);
962 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
964 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
965 _sub_obj_mouse_down, sd);
966 _smart_reconfigure(sd);
967 evas_object_data_set(sobj, "elm-parent", obj);
968 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
969 if (_elm_widget_is(sobj))
971 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
977 elm_widget_hover_object_set(Evas_Object *obj,
983 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
986 sd->hover_obj = sobj;
989 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
991 _smart_reconfigure(sd);
996 elm_widget_can_focus_set(Evas_Object *obj,
1000 sd->can_focus = can_focus;
1003 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1005 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1006 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1008 (void *)(long)EVAS_CALLBACK_KEY_UP);
1009 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1011 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1015 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1017 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1019 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1025 elm_widget_can_focus_get(const Evas_Object *obj)
1027 API_ENTRY return EINA_FALSE;
1028 return sd->can_focus;
1032 elm_widget_child_can_focus_get(const Evas_Object *obj)
1034 API_ENTRY return EINA_FALSE;
1035 return sd->child_can_focus;
1039 elm_widget_highlight_ignore_set(Evas_Object *obj,
1043 sd->highlight_ignore = !!ignore;
1047 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1049 API_ENTRY return EINA_FALSE;
1050 return sd->highlight_ignore;
1054 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1055 Eina_Bool highlight)
1058 sd->highlight_in_theme = !!highlight;
1059 /* FIXME: if focused, it should switch from one mode to the other */
1063 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1065 API_ENTRY return EINA_FALSE;
1066 return sd->highlight_in_theme;
1070 elm_widget_focus_get(const Evas_Object *obj)
1072 API_ENTRY return EINA_FALSE;
1077 elm_widget_focused_object_get(const Evas_Object *obj)
1079 const Evas_Object *subobj;
1081 API_ENTRY return NULL;
1083 if (!sd->focused) return NULL;
1084 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1086 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1087 if (fobj) return fobj;
1089 return (Evas_Object *)obj;
1093 elm_widget_top_get(const Evas_Object *obj)
1095 API_ENTRY return NULL;
1096 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1097 return (Evas_Object *)obj;
1101 elm_widget_is(const Evas_Object *obj)
1103 return _elm_widget_is(obj);
1107 elm_widget_parent_widget_get(const Evas_Object *obj)
1109 Evas_Object *parent;
1111 if (_elm_widget_is(obj))
1113 Smart_Data *sd = evas_object_smart_data_get(obj);
1114 if (!sd) return NULL;
1115 parent = sd->parent_obj;
1119 parent = evas_object_data_get(obj, "elm-parent");
1120 if (!parent) parent = evas_object_smart_parent_get(obj);
1125 Evas_Object *elm_parent;
1126 if (_elm_widget_is(parent)) break;
1127 elm_parent = evas_object_data_get(parent, "elm-parent");
1128 if (elm_parent) parent = elm_parent;
1129 else parent = evas_object_smart_parent_get(parent);
1135 elm_widget_event_callback_add(Evas_Object *obj,
1140 EINA_SAFETY_ON_NULL_RETURN(func);
1141 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1144 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1148 elm_widget_event_callback_del(Evas_Object *obj,
1152 API_ENTRY return NULL;
1153 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1155 Elm_Event_Cb_Data *ecd;
1156 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1157 if ((ecd->func == func) && (ecd->data == data))
1160 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1161 return (void *)data;
1167 elm_widget_event_propagate(Evas_Object *obj,
1168 Evas_Callback_Type type,
1170 Evas_Event_Flags *event_flags)
1172 API_ENTRY return EINA_FALSE; //TODO reduce.
1173 if (!_elm_widget_is(obj)) return EINA_FALSE;
1174 Evas_Object *parent = obj;
1175 Elm_Event_Cb_Data *ecd;
1176 Eina_List *l, *l_prev;
1179 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1181 sd = evas_object_smart_data_get(parent);
1182 if ((!sd) || (!_elm_widget_is(obj)))
1183 return EINA_FALSE; //Not Elm Widget
1185 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1188 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1190 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1191 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1194 parent = sd->parent_obj;
1203 * Set custom focus chain.
1205 * This function i set one new and overwrite any previous custom focus chain
1206 * with the list of objects. The previous list will be deleted and this list
1207 * will be managed. After setted, don't modity it.
1209 * @note On focus cycle, only will be evaluated children of this container.
1211 * @param obj The container widget
1212 * @param objs Chain of objects to pass focus
1216 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1220 if (!sd->focus_next_func)
1223 elm_widget_focus_custom_chain_unset(obj);
1228 EINA_LIST_FOREACH(objs, l, o)
1230 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1231 _elm_object_focus_chain_del_cb, sd);
1234 sd->focus_chain = objs;
1240 * Get custom focus chain
1242 * @param obj The container widget
1245 EAPI const Eina_List *
1246 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1248 API_ENTRY return NULL;
1249 return (const Eina_List *)sd->focus_chain;
1255 * Unset custom focus chain
1257 * @param obj The container widget
1261 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1264 Eina_List *l, *l_next;
1267 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1269 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1270 _elm_object_focus_chain_del_cb, sd);
1271 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1278 * Append object to custom focus chain.
1280 * @note If relative_child equal to NULL or not in custom chain, the object
1281 * will be added in end.
1283 * @note On focus cycle, only will be evaluated children of this container.
1285 * @param obj The container widget
1286 * @param child The child to be added in custom chain
1287 * @param relative_child The relative object to position the child
1291 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1293 Evas_Object *relative_child)
1296 EINA_SAFETY_ON_NULL_RETURN(child);
1297 if (!sd->focus_next_func)
1300 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1301 _elm_object_focus_chain_del_cb, sd);
1303 if (!relative_child)
1305 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1309 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1316 * Prepend object to custom focus chain.
1318 * @note If relative_child equal to NULL or not in custom chain, the object
1319 * will be added in begin.
1321 * @note On focus cycle, only will be evaluated children of this container.
1323 * @param obj The container widget
1324 * @param child The child to be added in custom chain
1325 * @param relative_child The relative object to position the child
1329 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1331 Evas_Object *relative_child)
1334 EINA_SAFETY_ON_NULL_RETURN(child);
1335 if (!sd->focus_next_func)
1338 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1339 _elm_object_focus_chain_del_cb, sd);
1341 if (!relative_child)
1343 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1347 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1354 * Give focus to next object in object tree.
1356 * Give focus to next object in focus chain of one object sub-tree.
1357 * If the last object of chain already have focus, the focus will go to the
1358 * first object of chain.
1360 * @param obj The widget root of sub-tree
1361 * @param dir Direction to cycle the focus
1366 elm_widget_focus_cycle(Evas_Object *obj,
1367 Elm_Focus_Direction dir)
1369 Evas_Object *target = NULL;
1370 if (!_elm_widget_is(obj))
1372 elm_widget_focus_next_get(obj, dir, &target);
1374 elm_widget_focus_steal(target);
1380 * Give focus to near object in one direction.
1382 * Give focus to near object in direction of one object.
1383 * If none focusable object in given direction, the focus will not change.
1385 * @param obj The reference widget
1386 * @param x Horizontal component of direction to focus
1387 * @param y Vertical component of direction to focus
1392 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1402 * Get next object in focus chain of object tree.
1404 * Get next object in focus chain of one object sub-tree.
1405 * Return the next object by reference. If don't have any candidate to receive
1406 * focus before chain end, the first candidate will be returned.
1408 * @param obj The widget root of sub-tree
1409 * @param dir Direction os focus chain
1410 * @param next The next object in focus chain
1411 * @return EINA_TRUE if don't need focus chain restart/loop back
1412 * to use 'next' obj.
1417 elm_widget_focus_next_get(const Evas_Object *obj,
1418 Elm_Focus_Direction dir,
1425 API_ENTRY return EINA_FALSE;
1427 /* Ignore if disabled */
1428 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1432 if (sd->focus_next_func)
1433 return sd->focus_next_func(obj, dir, next);
1435 if (!elm_widget_can_focus_get(obj))
1439 *next = (Evas_Object *)obj;
1440 return !elm_widget_focus_get(obj);
1446 * Get next object in focus chain of object tree in list.
1448 * Get next object in focus chain of one object sub-tree ordered by one list.
1449 * Return the next object by reference. If don't have any candidate to receive
1450 * focus before list end, the first candidate will be returned.
1452 * @param obj The widget root of sub-tree
1453 * @param dir Direction os focus chain
1454 * @param items list with ordered objects
1455 * @param list_data_get function to get the object from one item of list
1456 * @param next The next object in focus chain
1457 * @return EINA_TRUE if don't need focus chain restart/loop back
1458 * to use 'next' obj.
1463 elm_widget_focus_list_next_get(const Evas_Object *obj,
1464 const Eina_List *items,
1465 void *(*list_data_get)(const Eina_List * list),
1466 Elm_Focus_Direction dir,
1469 Eina_List *(*list_next)(const Eina_List * list);
1475 if (!_elm_widget_is(obj))
1482 if (dir == ELM_FOCUS_PREVIOUS)
1484 items = eina_list_last(items);
1485 list_next = eina_list_prev;
1487 else if (dir == ELM_FOCUS_NEXT)
1488 list_next = eina_list_next;
1492 const Eina_List *l = items;
1494 /* Recovery last focused sub item */
1495 if (elm_widget_focus_get(obj))
1496 for (; l; l = list_next(l))
1498 Evas_Object *cur = list_data_get(l);
1499 if (elm_widget_focus_get(cur)) break;
1502 const Eina_List *start = l;
1503 Evas_Object *to_focus = NULL;
1505 /* Interate sub items */
1506 /* Go to end of list */
1507 for (; l; l = list_next(l))
1509 Evas_Object *tmp = NULL;
1510 Evas_Object *cur = list_data_get(l);
1512 if (elm_widget_parent_get(cur) != obj)
1515 /* Try Focus cycle in subitem */
1516 if (elm_widget_focus_next_get(cur, dir, &tmp))
1521 else if ((tmp) && (!to_focus))
1527 /* Get First possible */
1528 for (; l != start; l = list_next(l))
1530 Evas_Object *tmp = NULL;
1531 Evas_Object *cur = list_data_get(l);
1533 if (elm_widget_parent_get(cur) != obj)
1536 /* Try Focus cycle in subitem */
1537 elm_widget_focus_next_get(cur, dir, &tmp);
1550 elm_widget_signal_emit(Evas_Object *obj,
1551 const char *emission,
1555 if (!sd->signal_func) return;
1556 sd->signal_func(obj, emission, source);
1560 _edje_signal_callback(void *data,
1561 Evas_Object *obj __UNUSED__,
1562 const char *emission,
1565 Edje_Signal_Data *esd = data;
1566 esd->func(esd->data, esd->obj, emission, source);
1570 elm_widget_signal_callback_add(Evas_Object *obj,
1571 const char *emission,
1573 Edje_Signal_Cb func,
1576 Edje_Signal_Data *esd;
1578 if (!sd->callback_add_func) return;
1579 EINA_SAFETY_ON_NULL_RETURN(func);
1581 esd = ELM_NEW(Edje_Signal_Data);
1586 esd->emission = eina_stringshare_add(emission);
1587 esd->source = eina_stringshare_add(source);
1589 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1590 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1594 elm_widget_signal_callback_del(Evas_Object *obj,
1595 const char *emission,
1597 Edje_Signal_Cb func)
1599 Edje_Signal_Data *esd;
1602 API_ENTRY return NULL;
1603 if (!sd->callback_del_func) return NULL;
1605 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1607 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1608 (!strcmp(esd->source, source)))
1610 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1611 eina_stringshare_del(esd->emission);
1612 eina_stringshare_del(esd->source);
1618 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1623 elm_widget_focus_set(Evas_Object *obj,
1630 sd->focus_order = focus_order;
1631 sd->focused = EINA_TRUE;
1632 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1636 sd->focus_func(obj);
1643 if ((_is_focusable(sd->resize_obj)) &&
1644 (!elm_widget_disabled_get(sd->resize_obj)))
1646 elm_widget_focus_set(sd->resize_obj, first);
1652 EINA_LIST_FOREACH(sd->subobjs, l, child)
1654 if ((_is_focusable(child)) &&
1655 (!elm_widget_disabled_get(child)))
1657 elm_widget_focus_set(child, first);
1667 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1669 if ((_is_focusable(child)) &&
1670 (!elm_widget_disabled_get(child)))
1672 elm_widget_focus_set(child, first);
1678 if ((_is_focusable(sd->resize_obj)) &&
1679 (!elm_widget_disabled_get(sd->resize_obj)))
1681 elm_widget_focus_set(sd->resize_obj, first);
1689 elm_widget_parent_get(const Evas_Object *obj)
1691 API_ENTRY return NULL;
1692 return sd->parent_obj;
1696 elm_widget_focused_object_clear(Evas_Object *obj)
1699 if (!sd->focused) return;
1700 if (elm_widget_focus_get(sd->resize_obj))
1701 elm_widget_focused_object_clear(sd->resize_obj);
1706 EINA_LIST_FOREACH(sd->subobjs, l, child)
1708 if (elm_widget_focus_get(child))
1710 elm_widget_focused_object_clear(child);
1715 sd->focused = EINA_FALSE;
1716 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1717 if (sd->focus_func) sd->focus_func(obj);
1721 elm_widget_focus_steal(Evas_Object *obj)
1723 Evas_Object *parent, *o;
1726 if (sd->focused) return;
1727 if (sd->disabled) return;
1731 o = elm_widget_parent_get(parent);
1733 sd = evas_object_smart_data_get(o);
1734 if (sd->focused) break;
1737 if (!elm_widget_parent_get(parent))
1738 elm_widget_focused_object_clear(parent);
1741 parent = elm_widget_parent_get(parent);
1742 sd = evas_object_smart_data_get(parent);
1743 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1744 elm_widget_focused_object_clear(sd->resize_obj);
1749 EINA_LIST_FOREACH(sd->subobjs, l, child)
1751 if (elm_widget_focus_get(child))
1753 elm_widget_focused_object_clear(child);
1764 elm_widget_activate(Evas_Object *obj)
1767 elm_widget_change(obj);
1768 if (sd->activate_func) sd->activate_func(obj);
1772 elm_widget_change(Evas_Object *obj)
1775 elm_widget_change(elm_widget_parent_get(obj));
1776 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1780 elm_widget_disabled_set(Evas_Object *obj,
1785 if (sd->disabled == disabled) return;
1786 sd->disabled = disabled;
1789 Evas_Object *o, *parent;
1794 o = elm_widget_parent_get(parent);
1798 if (elm_widget_focus_get(obj))
1799 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1801 if (sd->disable_func) sd->disable_func(obj);
1805 elm_widget_disabled_get(const Evas_Object *obj)
1808 return sd->disabled;
1812 elm_widget_show_region_set(Evas_Object *obj,
1818 Evas_Object *parent_obj, *child_obj;
1819 Evas_Coord px, py, cx, cy;
1822 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1827 if (sd->on_show_region_func)
1828 sd->on_show_region_func(sd->on_show_region_data, obj);
1832 parent_obj = sd->parent_obj;
1833 child_obj = sd->obj;
1834 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1835 sd = evas_object_smart_data_get(parent_obj);
1838 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1839 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1848 if (sd->on_show_region_func)
1850 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1857 elm_widget_show_region_get(const Evas_Object *obj,
1873 * Get the focus region of the given widget.
1875 * The focus region is the area of a widget that should brought into the
1876 * visible area when the widget is focused. Mostly used to show the part of
1877 * an entry where the cursor is, for example. The area returned is relative
1878 * to the object @p obj.
1879 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1880 * function will return the full size of the object.
1882 * @param obj The widget object
1883 * @param x Where to store the x coordinate of the area
1884 * @param y Where to store the y coordinate of the area
1885 * @param w Where to store the width of the area
1886 * @param h Where to store the height of the area
1891 elm_widget_focus_region_get(const Evas_Object *obj,
1901 sd = evas_object_smart_data_get(obj);
1902 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1904 evas_object_geometry_get(obj, NULL, NULL, w, h);
1909 sd->on_focus_region_func(obj, x, y, w, h);
1913 elm_widget_scroll_hold_push(Evas_Object *obj)
1917 if (sd->scroll_hold == 1)
1918 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1919 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1920 // FIXME: on delete/reparent hold pop
1924 elm_widget_scroll_hold_pop(Evas_Object *obj)
1928 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1929 if (!sd->scroll_hold)
1930 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1931 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1935 elm_widget_scroll_hold_get(const Evas_Object *obj)
1938 return sd->scroll_hold;
1942 elm_widget_scroll_freeze_push(Evas_Object *obj)
1945 sd->scroll_freeze++;
1946 if (sd->scroll_freeze == 1)
1947 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1948 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1949 // FIXME: on delete/reparent freeze pop
1953 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1956 sd->scroll_freeze--;
1957 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1958 if (!sd->scroll_freeze)
1959 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1960 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1964 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1967 return sd->scroll_freeze;
1971 elm_widget_scale_set(Evas_Object *obj,
1975 if (scale <= 0.0) scale = 0.0;
1976 if (sd->scale != scale)
1979 elm_widget_theme(obj);
1984 elm_widget_scale_get(const Evas_Object *obj)
1986 API_ENTRY return 1.0;
1987 // FIXME: save walking up the tree by storing/caching parent scale
1988 if (sd->scale == 0.0)
1991 return elm_widget_scale_get(sd->parent_obj);
1999 elm_widget_theme_set(Evas_Object *obj,
2003 if (sd->theme != th)
2005 if (sd->theme) elm_theme_free(sd->theme);
2008 elm_widget_theme(obj);
2013 elm_widget_theme_get(const Evas_Object *obj)
2015 API_ENTRY return NULL;
2019 return elm_widget_theme_get(sd->parent_obj);
2027 elm_widget_style_set(Evas_Object *obj,
2032 if (eina_stringshare_replace(&sd->style, style))
2033 elm_widget_theme(obj);
2037 elm_widget_style_get(const Evas_Object *obj)
2039 API_ENTRY return NULL;
2040 if (sd->style) return sd->style;
2045 elm_widget_type_set(Evas_Object *obj,
2049 eina_stringshare_replace(&sd->type, type);
2053 elm_widget_type_get(const Evas_Object *obj)
2055 API_ENTRY return NULL;
2056 if (sd->type) return sd->type;
2061 elm_widget_tooltip_add(Evas_Object *obj,
2065 sd->tooltips = eina_list_append(sd->tooltips, tt);
2069 elm_widget_tooltip_del(Evas_Object *obj,
2073 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2077 elm_widget_cursor_add(Evas_Object *obj,
2081 sd->cursors = eina_list_append(sd->cursors, cur);
2085 elm_widget_cursor_del(Evas_Object *obj,
2089 sd->cursors = eina_list_remove(sd->cursors, cur);
2093 elm_widget_drag_lock_x_set(Evas_Object *obj,
2097 if (sd->drag_x_locked == lock) return;
2098 sd->drag_x_locked = lock;
2099 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2100 else _propagate_x_drag_lock(obj, -1);
2104 elm_widget_drag_lock_y_set(Evas_Object *obj,
2108 if (sd->drag_y_locked == lock) return;
2109 sd->drag_y_locked = lock;
2110 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2111 else _propagate_y_drag_lock(obj, -1);
2115 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2117 API_ENTRY return EINA_FALSE;
2118 return sd->drag_x_locked;
2122 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2124 API_ENTRY return EINA_FALSE;
2125 return sd->drag_y_locked;
2129 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2132 return sd->child_drag_x_locked;
2136 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2139 return sd->child_drag_y_locked;
2143 elm_widget_theme_object_set(Evas_Object *obj,
2146 const char *welement,
2149 API_ENTRY return EINA_FALSE;
2150 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2154 elm_widget_type_check(const Evas_Object *obj,
2157 const char *provided, *expected = "(unknown)";
2158 static int abort_on_warn = -1;
2159 provided = elm_widget_type_get(obj);
2160 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2161 if (type) expected = type;
2162 if ((!provided) || (!provided[0]))
2164 provided = evas_object_type_get(obj);
2165 if ((!provided) || (!provided[0]))
2166 provided = "(unknown)";
2168 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2169 if (abort_on_warn == -1)
2171 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2172 else abort_on_warn = 0;
2174 if (abort_on_warn == 1) abort();
2181 * Split string in words
2183 * @param str Source string
2184 * @return List of const words
2186 * @see elm_widget_stringlist_free()
2190 elm_widget_stringlist_get(const char *str)
2192 Eina_List *list = NULL;
2194 if (!str) return NULL;
2195 for (b = s = str; 1; s++)
2197 if ((*s == ' ') || (!*s))
2199 char *t = malloc(s - b + 1);
2202 strncpy(t, b, s - b);
2204 list = eina_list_append(list, eina_stringshare_add(t));
2215 elm_widget_stringlist_free(Eina_List *list)
2218 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2224 * Allocate a new Elm_Widget_Item-derived structure.
2226 * The goal of this structure is to provide common ground for actions
2227 * that a widget item have, such as the owner widget, callback to
2228 * notify deletion, data pointer and maybe more.
2230 * @param widget the owner widget that holds this item, must be an elm_widget!
2231 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2232 * be used to allocate memory.
2234 * @return allocated memory that is already zeroed out, or NULL on errors.
2236 * @see elm_widget_item_new() convenience macro.
2237 * @see elm_widget_item_del() to release memory.
2240 EAPI Elm_Widget_Item *
2241 _elm_widget_item_new(Evas_Object *widget,
2244 if (!_elm_widget_is(widget))
2247 Elm_Widget_Item *item;
2249 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2250 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2252 item = calloc(1, alloc_size);
2253 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2255 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2256 item->widget = widget;
2263 * Releases widget item memory, calling back del_cb() if it exists.
2265 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2266 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2267 * this function and then unset it, thus being useful for 2 step
2268 * cleanup whenever the del_cb may use any of the data that must be
2269 * deleted from item.
2271 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2274 * @param item a valid #Elm_Widget_Item to be deleted.
2275 * @see elm_widget_item_del() convenience macro.
2279 _elm_widget_item_del(Elm_Widget_Item *item)
2281 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2284 item->del_cb((void *)item->data, item->widget, item);
2287 evas_object_del(item->view);
2289 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2296 * Notify object will be deleted without actually deleting it.
2298 * This function will callback Elm_Widget_Item::del_cb if it is set
2299 * and then unset it so it is not called twice (ie: from
2300 * elm_widget_item_del()).
2302 * @param item a valid #Elm_Widget_Item to be notified
2303 * @see elm_widget_item_pre_notify_del() convenience macro.
2307 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2309 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2310 if (!item->del_cb) return;
2311 item->del_cb((void *)item->data, item->widget, item);
2312 item->del_cb = NULL;
2318 * Set the function to notify when item is being deleted.
2320 * This function will complain if there was a callback set already,
2321 * however it will set the new one.
2323 * The callback will be called from elm_widget_item_pre_notify_del()
2324 * or elm_widget_item_del() will be called with:
2325 * - data: the Elm_Widget_Item::data value.
2326 * - obj: the Elm_Widget_Item::widget evas object.
2327 * - event_info: the item being deleted.
2329 * @param item a valid #Elm_Widget_Item to be notified
2330 * @see elm_widget_item_del_cb_set() convenience macro.
2334 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2335 Evas_Smart_Cb del_cb)
2337 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2339 if ((item->del_cb) && (item->del_cb != del_cb))
2340 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2341 item->del_cb, item, del_cb);
2343 item->del_cb = del_cb;
2349 * Set user-data in this item.
2351 * User data may be used to identify this item or just store any
2352 * application data. It is automatically given as the first parameter
2353 * of the deletion notify callback.
2355 * @param item a valid #Elm_Widget_Item to store data in.
2356 * @param data user data to store.
2357 * @see elm_widget_item_del_cb_set() convenience macro.
2361 _elm_widget_item_data_set(Elm_Widget_Item *item,
2364 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2365 if ((item->data) && (item->data != data))
2366 DBG("Replacing item %p data %p with %p", item, item->data, data);
2373 * Retrieves user-data of this item.
2375 * @param item a valid #Elm_Widget_Item to get data from.
2376 * @see elm_widget_item_data_set()
2380 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2382 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2383 return (void *)item->data;
2386 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2388 struct _Elm_Widget_Item_Tooltip
2390 Elm_Widget_Item *item;
2391 Elm_Tooltip_Item_Content_Cb func;
2392 Evas_Smart_Cb del_cb;
2396 static Evas_Object *
2397 _elm_widget_item_tooltip_label_create(void *data,
2399 void *item __UNUSED__)
2401 Evas_Object *label = elm_label_add(obj);
2404 elm_object_style_set(label, "tooltip");
2405 elm_label_label_set(label, data);
2410 _elm_widget_item_tooltip_label_del_cb(void *data,
2411 Evas_Object *obj __UNUSED__,
2412 void *event_info __UNUSED__)
2414 eina_stringshare_del(data);
2420 * Set the text to be shown in the widget item.
2422 * @param item Target item
2423 * @param text The text to set in the content
2425 * Setup the text as tooltip to object. The item can have only one tooltip,
2426 * so any previous tooltip data is removed.
2431 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2434 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2435 EINA_SAFETY_ON_NULL_RETURN(text);
2437 text = eina_stringshare_add(text);
2438 _elm_widget_item_tooltip_content_cb_set
2439 (item, _elm_widget_item_tooltip_label_create, text,
2440 _elm_widget_item_tooltip_label_del_cb);
2443 static Evas_Object *
2444 _elm_widget_item_tooltip_create(void *data,
2447 Elm_Widget_Item_Tooltip *wit = data;
2448 return wit->func((void *)wit->data, obj, wit->item);
2452 _elm_widget_item_tooltip_del_cb(void *data,
2454 void *event_info __UNUSED__)
2456 Elm_Widget_Item_Tooltip *wit = data;
2457 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2464 * Set the content to be shown in the tooltip item
2466 * Setup the tooltip to item. The item can have only one tooltip,
2467 * so any previous tooltip data is removed. @p func(with @p data) will
2468 * be called every time that need show the tooltip and it should
2469 * return a valid Evas_Object. This object is then managed fully by
2470 * tooltip system and is deleted when the tooltip is gone.
2472 * @param item the widget item being attached a tooltip.
2473 * @param func the function used to create the tooltip contents.
2474 * @param data what to provide to @a func as callback data/context.
2475 * @param del_cb called when data is not needed anymore, either when
2476 * another callback replaces @func, the tooltip is unset with
2477 * elm_widget_item_tooltip_unset() or the owner @a item
2478 * dies. This callback receives as the first parameter the
2479 * given @a data, and @c event_info is the item.
2484 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2485 Elm_Tooltip_Item_Content_Cb func,
2487 Evas_Smart_Cb del_cb)
2489 Elm_Widget_Item_Tooltip *wit;
2491 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2495 _elm_widget_item_tooltip_unset(item);
2499 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2500 if (!wit) goto error;
2504 wit->del_cb = del_cb;
2506 elm_object_sub_tooltip_content_cb_set
2507 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2508 _elm_widget_item_tooltip_del_cb);
2513 if (del_cb) del_cb((void *)data, NULL, item);
2516 if (del_cb) del_cb((void *)data, item->widget, item);
2522 * Unset tooltip from item
2524 * @param item widget item to remove previously set tooltip.
2526 * Remove tooltip from item. The callback provided as del_cb to
2527 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2528 * it is not used anymore.
2530 * @see elm_widget_item_tooltip_content_cb_set()
2535 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2537 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2538 elm_object_tooltip_unset(item->view);
2544 * Sets a different style for this item tooltip.
2546 * @note before you set a style you should define a tooltip with
2547 * elm_widget_item_tooltip_content_cb_set() or
2548 * elm_widget_item_tooltip_text_set()
2550 * @param item widget item with tooltip already set.
2551 * @param style the theme style to use (default, transparent, ...)
2556 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2559 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2560 elm_object_tooltip_style_set(item->view, style);
2566 * Get the style for this item tooltip.
2568 * @param item widget item with tooltip already set.
2569 * @return style the theme style in use, defaults to "default". If the
2570 * object does not have a tooltip set, then NULL is returned.
2575 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2577 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2578 return elm_object_tooltip_style_get(item->view);
2582 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2585 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2586 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2590 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2592 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2593 return elm_object_cursor_get(item->view);
2597 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2599 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2600 elm_object_cursor_unset(item->view);
2606 * Sets a different style for this item cursor.
2608 * @note before you set a style you should define a cursor with
2609 * elm_widget_item_cursor_set()
2611 * @param item widget item with cursor already set.
2612 * @param style the theme style to use (default, transparent, ...)
2617 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2620 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2621 elm_object_cursor_style_set(item->view, style);
2627 * Get the style for this item cursor.
2629 * @param item widget item with cursor already set.
2630 * @return style the theme style in use, defaults to "default". If the
2631 * object does not have a cursor set, then NULL is returned.
2636 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2638 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2639 return elm_object_cursor_style_get(item->view);
2645 * Set if the cursor set should be searched on the theme or should use
2646 * the provided by the engine, only.
2648 * @note before you set if should look on theme you should define a cursor
2649 * with elm_object_cursor_set(). By default it will only look for cursors
2650 * provided by the engine.
2652 * @param item widget item with cursor already set.
2653 * @param engine_only boolean to define it cursors should be looked only
2654 * between the provided by the engine or searched on widget's theme as well.
2659 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2660 Eina_Bool engine_only)
2662 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2663 elm_object_cursor_engine_only_set(item->view, engine_only);
2669 * Get the cursor engine only usage for this item cursor.
2671 * @param item widget item with cursor already set.
2672 * @return engine_only boolean to define it cursors should be looked only
2673 * between the provided by the engine or searched on widget's theme as well. If
2674 * the object does not have a cursor set, then EINA_FALSE is returned.
2679 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2681 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2682 return elm_object_cursor_engine_only_get(item->view);
2685 // smart object funcs
2687 _smart_reconfigure(Smart_Data *sd)
2691 evas_object_move(sd->resize_obj, sd->x, sd->y);
2692 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2696 evas_object_move(sd->hover_obj, sd->x, sd->y);
2697 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2702 _smart_add(Evas_Object *obj)
2706 sd = calloc(1, sizeof(Smart_Data));
2709 sd->x = sd->y = sd->w = sd->h = 0;
2711 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2712 evas_object_smart_data_set(obj, sd);
2715 static Evas_Object *
2716 _newest_focus_order_get(Evas_Object *obj,
2717 unsigned int *newest_focus_order,
2718 Eina_Bool can_focus_only)
2721 Evas_Object *child, *ret, *best;
2723 API_ENTRY return NULL;
2724 if (!evas_object_visible_get(obj)) return NULL;
2726 if (*newest_focus_order < sd->focus_order)
2728 *newest_focus_order = sd->focus_order;
2731 EINA_LIST_FOREACH(sd->subobjs, l, child)
2733 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2739 if ((!best) || (!elm_widget_can_focus_get(best)))
2746 _if_focused_revert(Evas_Object *obj,
2747 Eina_Bool can_focus_only)
2750 Evas_Object *newest = NULL;
2751 unsigned int newest_focus_order = 0;
2755 if (!sd->focused) return;
2756 if (!sd->parent_obj) return;
2758 top = elm_widget_top_get(sd->parent_obj);
2761 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2764 elm_object_unfocus(newest);
2765 elm_object_focus(newest);
2771 _smart_del(Evas_Object *obj)
2774 Edje_Signal_Data *esd;
2778 if (sd->del_pre_func) sd->del_pre_func(obj);
2781 sobj = sd->resize_obj;
2782 sd->resize_obj = NULL;
2783 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2784 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2785 evas_object_del(sobj);
2789 sobj = sd->hover_obj;
2790 sd->hover_obj = NULL;
2791 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2792 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2793 evas_object_del(sobj);
2795 EINA_LIST_FREE(sd->subobjs, sobj)
2797 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2798 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2799 evas_object_del(sobj);
2801 eina_list_free(sd->tooltips); /* should be empty anyway */
2802 eina_list_free(sd->cursors); /* should be empty anyway */
2803 EINA_LIST_FREE(sd->edje_signals, esd)
2805 eina_stringshare_del(esd->emission);
2806 eina_stringshare_del(esd->source);
2809 eina_list_free(sd->event_cb); /* should be empty anyway */
2810 if (sd->del_func) sd->del_func(obj);
2811 if (sd->style) eina_stringshare_del(sd->style);
2812 if (sd->type) eina_stringshare_del(sd->type);
2813 if (sd->theme) elm_theme_free(sd->theme);
2814 _if_focused_revert(obj, EINA_TRUE);
2819 _smart_move(Evas_Object *obj,
2826 _smart_reconfigure(sd);
2830 _smart_resize(Evas_Object *obj,
2837 _smart_reconfigure(sd);
2841 _smart_show(Evas_Object *obj)
2846 if ((list = evas_object_smart_members_get(obj)))
2848 EINA_LIST_FREE(list, o)
2850 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2851 evas_object_show(o);
2857 _smart_hide(Evas_Object *obj)
2862 list = evas_object_smart_members_get(obj);
2863 EINA_LIST_FREE(list, o)
2865 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2866 evas_object_hide(o);
2871 _smart_color_set(Evas_Object *obj,
2880 if ((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_color_set(o, r, g, b, a);
2891 _smart_clip_set(Evas_Object *obj,
2897 if ((list = evas_object_smart_members_get(obj)))
2899 EINA_LIST_FREE(list, o)
2901 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2902 evas_object_clip_set(o, clip);
2908 _smart_clip_unset(Evas_Object *obj)
2913 if ((list = evas_object_smart_members_get(obj)))
2915 EINA_LIST_FREE(list, o)
2917 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2918 evas_object_clip_unset(o);
2924 _smart_calculate(Evas_Object *obj)
2927 if (sd->changed_func) sd->changed_func(obj);
2930 /* never need to touch this */
2934 if (_e_smart) return;
2936 static const Evas_Smart_Class sc =
2939 EVAS_SMART_CLASS_VERSION,
2957 _e_smart = evas_smart_class_new(&sc);
2961 /* happy debug functions */
2964 _sub_obj_tree_dump(const Evas_Object *obj,
2969 for (i = 0; i < lvl * 3; i++)
2972 if (_elm_widget_is(obj))
2976 printf("+ %s(%p)\n",
2980 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2981 EINA_LIST_FOREACH(sd->subobjs, l, obj)
2983 if (obj != sd->resize_obj)
2984 _sub_obj_tree_dump(obj, lvl + 1);
2988 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
2992 _sub_obj_tree_dot_dump(const Evas_Object *obj,
2995 if (!_elm_widget_is(obj))
2999 Eina_Bool visible = evas_object_visible_get(obj);
3000 Eina_Bool disabled = elm_widget_disabled_get(obj);
3001 Eina_Bool focused = elm_widget_focus_get(obj);
3002 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3006 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3009 fprintf(output, ", style=bold");
3012 fprintf(output, ", color=gray28");
3014 fprintf(output, " ];\n");
3017 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3018 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3019 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3023 fprintf(output, ", style=bold");
3026 fprintf(output, ", fontcolor=gray28");
3028 if ((disabled) || (!visible))
3029 fprintf(output, ", color=gray");
3031 fprintf(output, " ];\n");
3035 EINA_LIST_FOREACH(sd->subobjs, l, o)
3036 _sub_obj_tree_dot_dump(o, output);
3041 elm_widget_tree_dump(const Evas_Object *top)
3044 _sub_obj_tree_dump(top, 0);
3052 elm_widget_tree_dot_dump(const Evas_Object *top,
3056 if (!_elm_widget_is(top))
3058 fprintf(output, "graph " " { node [shape=record];\n");
3059 _sub_obj_tree_dot_dump(top, output);
3060 fprintf(output, "}\n");