1 #include <Elementary.h>
4 static const char SMART_NAME[] = "elm_widget";
7 Smart_Data * sd = evas_object_smart_data_get(obj); \
8 if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
9 #define INTERNAL_ENTRY \
10 Smart_Data * sd = evas_object_smart_data_get(obj); \
13 typedef struct _Smart_Data Smart_Data;
14 typedef struct _Edje_Signal_Data Edje_Signal_Data;
15 typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data;
21 Evas_Object *parent_obj;
22 Evas_Coord x, y, w, h;
24 Evas_Object *resize_obj;
25 Evas_Object *hover_obj;
26 Eina_List *tooltips, *cursors;
27 void (*del_func)(Evas_Object *obj);
28 void (*del_pre_func)(Evas_Object *obj);
29 void (*focus_func)(Evas_Object *obj);
30 void (*activate_func)(Evas_Object *obj);
31 void (*disable_func)(Evas_Object *obj);
32 void (*theme_func)(Evas_Object *obj);
33 Eina_Bool (*event_func)(Evas_Object *obj,
35 Evas_Callback_Type type,
37 void (*signal_func)(Evas_Object *obj,
40 void (*callback_add_func)(Evas_Object *obj,
45 void (*callback_del_func)(Evas_Object *obj,
50 void (*changed_func)(Evas_Object *obj);
51 Eina_Bool (*focus_next_func)(const Evas_Object *obj,
52 Elm_Focus_Direction dir,
54 void (*on_focus_func)(void *data,
57 void (*on_change_func)(void *data,
60 void (*on_show_region_func)(void *data,
62 void *on_show_region_data;
63 void (*focus_region_func)(Evas_Object *obj,
68 void (*on_focus_region_func)(const Evas_Object *obj,
73 void (*on_text_set_func)(Evas_Object *obj,
76 const char *(*on_text_get_func)(const Evas_Object *obj,
79 Evas_Coord rx, ry, rw, rh;
85 unsigned int focus_order;
86 Eina_Bool focus_order_on_calc;
88 int child_drag_x_locked;
89 int child_drag_y_locked;
91 Eina_List *edje_signals;
93 Eina_Bool drag_x_locked : 1;
94 Eina_Bool drag_y_locked : 1;
96 Eina_Bool can_focus : 1;
97 Eina_Bool child_can_focus : 1;
98 Eina_Bool focused : 1;
99 Eina_Bool tree_unfocusable : 1;
100 Eina_Bool highlight_ignore : 1;
101 Eina_Bool highlight_in_theme : 1;
102 Eina_Bool disabled : 1;
103 Eina_Bool is_mirrored : 1;
104 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
106 Eina_List *focus_chain;
110 struct _Edje_Signal_Data
114 const char *emission;
119 struct _Elm_Event_Cb_Data
125 /* local subsystem functions */
126 static void _smart_reconfigure(Smart_Data *sd);
127 static void _smart_add(Evas_Object *obj);
128 static void _smart_del(Evas_Object *obj);
129 static void _smart_move(Evas_Object *obj,
132 static void _smart_resize(Evas_Object *obj,
135 static void _smart_show(Evas_Object *obj);
136 static void _smart_hide(Evas_Object *obj);
137 static void _smart_color_set(Evas_Object *obj,
142 static void _smart_clip_set(Evas_Object *obj,
144 static void _smart_clip_unset(Evas_Object *obj);
145 static void _smart_calculate(Evas_Object *obj);
146 static void _smart_init(void);
148 static void _if_focused_revert(Evas_Object *obj,
149 Eina_Bool can_focus_only);
150 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
151 unsigned int *newest_focus_order,
152 Eina_Bool can_focus_only);
154 /* local subsystem globals */
155 static Evas_Smart *_e_smart = NULL;
156 static Eina_List *widtypes = NULL;
158 static unsigned int focus_order = 0;
161 static inline Eina_Bool
162 _elm_widget_is(const Evas_Object *obj)
164 const char *type = evas_object_type_get(obj);
165 return type == SMART_NAME;
168 static inline Eina_Bool
169 _is_focusable(Evas_Object *obj)
171 API_ENTRY return EINA_FALSE;
172 return sd->can_focus || (sd->child_can_focus);
176 _unfocus_parents(Evas_Object *obj)
178 for (; obj; obj = elm_widget_parent_get(obj))
181 if (!sd->focused) return;
187 _focus_parents(Evas_Object *obj)
189 for (; obj; obj = elm_widget_parent_get(obj))
192 if (sd->focused) return;
198 _sub_obj_del(void *data,
201 void *event_info __UNUSED__)
203 Smart_Data *sd = data;
205 if (_elm_widget_is(obj))
207 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
209 if (obj == sd->resize_obj)
210 sd->resize_obj = NULL;
211 else if (obj == sd->hover_obj)
212 sd->hover_obj = NULL;
214 sd->subobjs = eina_list_remove(sd->subobjs, obj);
215 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
219 _sub_obj_hide(void *data __UNUSED__,
222 void *event_info __UNUSED__)
224 elm_widget_focus_hide_handle(obj);
228 _sub_obj_mouse_down(void *data __UNUSED__,
231 void *event_info __UNUSED__)
233 elm_widget_focus_mouse_down_handle(obj);
237 _propagate_x_drag_lock(Evas_Object *obj,
243 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
246 sd2->child_drag_x_locked += dir;
247 _propagate_x_drag_lock(sd->parent_obj, dir);
253 _propagate_y_drag_lock(Evas_Object *obj,
259 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
262 sd2->child_drag_y_locked += dir;
263 _propagate_y_drag_lock(sd->parent_obj, dir);
269 _propagate_event(void *data,
275 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
276 Evas_Event_Flags *event_flags = NULL;
280 case EVAS_CALLBACK_KEY_DOWN:
282 Evas_Event_Key_Down *ev = event_info;
283 event_flags = &(ev->event_flags);
287 case EVAS_CALLBACK_KEY_UP:
289 Evas_Event_Key_Up *ev = event_info;
290 event_flags = &(ev->event_flags);
294 case EVAS_CALLBACK_MOUSE_WHEEL:
296 Evas_Event_Mouse_Wheel *ev = event_info;
297 event_flags = &(ev->event_flags);
305 elm_widget_event_propagate(obj, type, event_info, event_flags);
309 _parent_focus(Evas_Object *obj)
312 if (sd->focused) return;
314 Evas_Object *o = elm_widget_parent_get(obj);
315 sd->focus_order_on_calc = EINA_TRUE;
317 if (o) _parent_focus(o);
319 if (!sd->focus_order_on_calc)
320 return; /* we don't want to override it if by means of any of the
321 callbacks below one gets to calculate our order
325 sd->focus_order = focus_order;
326 sd->focused = EINA_TRUE;
327 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
328 if (sd->focus_func) sd->focus_func(obj);
330 _elm_widget_focus_region_show(obj);
332 sd->focus_order_on_calc = EINA_FALSE;
336 _elm_object_focus_chain_del_cb(void *data,
339 void *event_info __UNUSED__)
341 Smart_Data *sd = data;
343 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
346 // exposed util funcs to elm
348 _elm_widget_type_clear(void)
352 EINA_LIST_FREE(widtypes, ptr)
354 eina_stringshare_del(*ptr);
360 _elm_widget_focus_region_show(const Evas_Object *obj)
362 Evas_Coord x, y, w, h, ox, oy;
368 o = elm_widget_parent_get(obj);
371 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
372 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
376 sd2 = evas_object_smart_data_get(o);
377 if (sd2->focus_region_func)
379 sd2->focus_region_func(o, x, y, w, h);
380 elm_widget_focus_region_get(o, &x, &y, &w, &h);
384 evas_object_geometry_get(o, &px, &py, NULL, NULL);
390 o = elm_widget_parent_get(o);
395 * @defgroup Widget Widget
398 * Exposed api for making widgets
401 elm_widget_type_register(const char **ptr)
403 widtypes = eina_list_append(widtypes, (void *)ptr);
407 elm_widget_api_check(int ver)
409 if (ver != ELM_INTERNAL_API_VERSION)
411 CRITICAL("Elementary widget api versions do not match");
418 elm_widget_add(Evas *evas)
422 obj = evas_object_smart_add(evas, _e_smart);
423 elm_widget_mirrored_set(obj, elm_mirrored_get());
428 elm_widget_del_hook_set(Evas_Object *obj,
429 void (*func)(Evas_Object *obj))
436 elm_widget_del_pre_hook_set(Evas_Object *obj,
437 void (*func)(Evas_Object *obj))
440 sd->del_pre_func = func;
444 elm_widget_focus_hook_set(Evas_Object *obj,
445 void (*func)(Evas_Object *obj))
448 sd->focus_func = func;
452 elm_widget_activate_hook_set(Evas_Object *obj,
453 void (*func)(Evas_Object *obj))
456 sd->activate_func = func;
460 elm_widget_disable_hook_set(Evas_Object *obj,
461 void (*func)(Evas_Object *obj))
464 sd->disable_func = func;
468 elm_widget_theme_hook_set(Evas_Object *obj,
469 void (*func)(Evas_Object *obj))
472 sd->theme_func = func;
476 elm_widget_event_hook_set(Evas_Object *obj,
477 Eina_Bool (*func)(Evas_Object *obj,
479 Evas_Callback_Type type,
483 sd->event_func = func;
487 elm_widget_text_set_hook_set(Evas_Object *obj,
488 void (*func)(Evas_Object *obj,
493 sd->on_text_set_func = func;
497 elm_widget_text_get_hook_set(Evas_Object *obj,
498 const char *(*func)(const Evas_Object *obj,
502 sd->on_text_get_func = func;
506 elm_widget_changed_hook_set(Evas_Object *obj,
507 void (*func)(Evas_Object *obj))
510 sd->changed_func = func;
514 elm_widget_signal_emit_hook_set(Evas_Object *obj,
515 void (*func)(Evas_Object *obj,
516 const char *emission,
520 sd->signal_func = func;
524 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
525 void (*func)(Evas_Object *obj,
526 const char *emission,
528 Edje_Signal_Cb func_cb,
532 sd->callback_add_func = func;
536 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
537 void (*func)(Evas_Object *obj,
538 const char *emission,
540 Edje_Signal_Cb func_cb,
544 sd->callback_del_func = func;
548 elm_widget_theme(Evas_Object *obj)
556 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
557 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
558 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
559 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
560 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
561 if (sd->theme_func) sd->theme_func(obj);
565 elm_widget_theme_specific(Evas_Object *obj,
573 Elm_Theme *th2, *thdef;
576 thdef = elm_theme_default_get();
581 if (!th2) th2 = thdef;
589 if (th2 == thdef) break;
590 th2 = th2->ref_theme;
591 if (!th2) th2 = thdef;
595 EINA_LIST_FOREACH(sd->subobjs, l, child)
596 elm_widget_theme_specific(child, th, force);
597 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
598 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
599 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
600 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
601 if (sd->theme_func) sd->theme_func(obj);
607 * Set hook to get next object in object focus chain.
609 * @param obj The widget object.
610 * @param func The hook to be used with this widget.
615 elm_widget_focus_next_hook_set(Evas_Object *obj,
616 Eina_Bool (*func)(const Evas_Object *obj,
617 Elm_Focus_Direction dir,
621 sd->focus_next_func = func;
625 * Returns the widget's mirrored mode.
627 * @param obj The widget.
628 * @return mirrored mode of the object.
632 elm_widget_mirrored_get(const Evas_Object *obj)
634 API_ENTRY return EINA_FALSE;
635 return sd->is_mirrored;
639 * Sets the widget's mirrored mode.
641 * @param obj The widget.
642 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
645 elm_widget_mirrored_set(Evas_Object *obj,
649 if (sd->is_mirrored != mirrored)
651 sd->is_mirrored = mirrored;
652 elm_widget_theme(obj);
658 * Resets the mirrored mode from the system mirror mode for widgets that are in
659 * automatic mirroring mode. This function does not call elm_widget_theme.
661 * @param obj The widget.
662 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
665 _elm_widget_mirrored_reload(Evas_Object *obj)
668 Eina_Bool mirrored = elm_mirrored_get();
669 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
671 sd->is_mirrored = mirrored;
676 * Returns the widget's mirrored mode setting.
678 * @param obj The widget.
679 * @return mirrored mode setting of the object.
683 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
685 API_ENTRY return EINA_FALSE;
686 return sd->mirrored_auto_mode;
690 * Sets the widget's mirrored mode setting.
691 * When widget in automatic mode, it follows the system mirrored mode set by
692 * elm_mirrored_set().
693 * @param obj The widget.
694 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
697 elm_widget_mirrored_automatic_set(Evas_Object *obj,
701 if (sd->mirrored_auto_mode != automatic)
703 sd->mirrored_auto_mode = automatic;
707 elm_widget_mirrored_set(obj, elm_mirrored_get());
713 elm_widget_on_focus_hook_set(Evas_Object *obj,
714 void (*func)(void *data,
719 sd->on_focus_func = func;
720 sd->on_focus_data = data;
724 elm_widget_on_change_hook_set(Evas_Object *obj,
725 void (*func)(void *data,
730 sd->on_change_func = func;
731 sd->on_change_data = data;
735 elm_widget_on_show_region_hook_set(Evas_Object *obj,
736 void (*func)(void *data,
741 sd->on_show_region_func = func;
742 sd->on_show_region_data = data;
748 * Set the hook to use to show the focused region.
750 * Whenever a new widget gets focused or it's needed to show the focused
751 * area of the current one, this hook will be called on objects that may
752 * want to move their children into their visible area.
753 * The area given in the hook function is relative to the @p obj widget.
755 * @param obj The widget object
756 * @param func The function to call to show the specified area.
761 elm_widget_focus_region_hook_set(Evas_Object *obj,
762 void (*func)(Evas_Object *obj,
769 sd->focus_region_func = func;
775 * Set the hook to retrieve the focused region of a widget.
777 * This hook will be called by elm_widget_focus_region_get() whenever
778 * it's needed to get the focused area of a widget. The area must be relative
779 * to the widget itself and if no hook is set, it will default to the entire
782 * @param obj The widget object
783 * @param func The function used to retrieve the focus region.
788 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
789 void (*func)(const Evas_Object *obj,
796 sd->on_focus_region_func = func;
800 elm_widget_data_set(Evas_Object *obj,
808 elm_widget_data_get(const Evas_Object *obj)
810 API_ENTRY return NULL;
815 elm_widget_sub_object_add(Evas_Object *obj,
819 double scale, pscale = elm_widget_scale_get(sobj);
820 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
821 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
823 if (_elm_widget_is(sobj))
825 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
828 if (sd2->parent_obj == obj)
831 elm_widget_sub_object_del(sd2->parent_obj, sobj);
832 sd2->parent_obj = obj;
833 if (!sd->child_can_focus && (_is_focusable(sobj)))
834 sd->child_can_focus = EINA_TRUE;
839 void *data = evas_object_data_get(sobj, "elm-parent");
842 if (data == obj) return;
843 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
848 sd->subobjs = eina_list_append(sd->subobjs, sobj);
849 evas_object_data_set(sobj, "elm-parent", obj);
850 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
851 if (_elm_widget_is(sobj))
852 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
853 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
854 scale = elm_widget_scale_get(sobj);
855 th = elm_widget_theme_get(sobj);
856 mirrored = elm_widget_mirrored_get(sobj);
857 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
858 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
862 elm_widget_sub_object_del(Evas_Object *obj,
865 Evas_Object *sobj_parent;
869 sobj_parent = evas_object_data_del(sobj, "elm-parent");
870 if (sobj_parent != obj)
872 static int abort_on_warn = -1;
873 ERR("removing sub object %p from parent %p, "
874 "but elm-parent is different %p!",
875 sobj, obj, sobj_parent);
876 if (EINA_UNLIKELY(abort_on_warn == -1))
878 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
879 else abort_on_warn = 0;
881 if (abort_on_warn == 1) abort();
883 if (_elm_widget_is(sobj))
885 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
888 sd2->parent_obj = NULL;
889 if (sd2->resize_obj == sobj)
890 sd2->resize_obj = NULL;
892 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
895 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
896 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
897 if ((sd->child_can_focus) && (_is_focusable(sobj)))
901 sd->child_can_focus = EINA_FALSE;
902 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
904 if (_is_focusable(subobj))
906 sd->child_can_focus = EINA_TRUE;
913 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
914 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
916 if (_elm_widget_is(sobj))
917 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
919 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
923 elm_widget_resize_object_set(Evas_Object *obj,
927 // orphan previous resize obj
930 evas_object_clip_unset(sd->resize_obj);
931 evas_object_data_del(sd->resize_obj, "elm-parent");
932 if (_elm_widget_is(sd->resize_obj))
934 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
935 if (sd2) sd2->parent_obj = NULL;
936 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
939 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
941 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
942 _sub_obj_mouse_down, sd);
943 evas_object_smart_member_del(sd->resize_obj);
944 if (_elm_widget_is(sd->resize_obj))
946 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
949 // orphan new resize obj
952 evas_object_data_del(sobj, "elm-parent");
953 if (_elm_widget_is(sobj))
955 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
956 if (sd2) sd2->parent_obj = NULL;
957 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
960 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
962 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
963 _sub_obj_mouse_down, sd);
964 evas_object_smart_member_del(sobj);
965 if (_elm_widget_is(sobj))
967 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
970 // set the resize obj up
971 sd->resize_obj = sobj;
974 if (_elm_widget_is(sd->resize_obj))
976 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
977 if (sd2) sd2->parent_obj = obj;
978 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
981 evas_object_clip_set(sobj, evas_object_clip_get(obj));
982 evas_object_smart_member_add(sobj, obj);
983 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
985 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
986 _sub_obj_mouse_down, sd);
987 _smart_reconfigure(sd);
988 evas_object_data_set(sobj, "elm-parent", obj);
989 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
990 if (_elm_widget_is(sobj))
992 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
998 elm_widget_hover_object_set(Evas_Object *obj,
1004 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1007 sd->hover_obj = sobj;
1010 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1012 _smart_reconfigure(sd);
1017 elm_widget_can_focus_set(Evas_Object *obj,
1018 Eina_Bool can_focus)
1021 sd->can_focus = can_focus;
1024 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1026 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1027 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1029 (void *)(long)EVAS_CALLBACK_KEY_UP);
1030 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1032 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1036 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1038 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1040 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1046 elm_widget_can_focus_get(const Evas_Object *obj)
1048 API_ENTRY return EINA_FALSE;
1049 return sd->can_focus;
1053 elm_widget_child_can_focus_get(const Evas_Object *obj)
1055 API_ENTRY return EINA_FALSE;
1056 return sd->child_can_focus;
1062 * This API makes the widget object and its children to be unfocusable.
1064 * This API can be helpful for an object to be deleted.
1065 * When an object will be deleted soon, it and its children may not
1066 * want to get focus (by focus reverting or by other focus controls).
1067 * Then, just use this API before deleting.
1069 * @param obj The widget root of sub-tree
1070 * @param tree_unfocusable If true, set the object sub-tree as unfocusable
1075 elm_widget_tree_unfocusable_set(Evas_Object *obj,
1076 Eina_Bool tree_unfocusable)
1080 if (sd->tree_unfocusable == tree_unfocusable) return;
1081 sd->tree_unfocusable = !!tree_unfocusable;
1082 elm_widget_focus_tree_unfocusable_handle(obj);
1088 * This returns true, if the object sub-tree is unfocusable.
1090 * @param obj The widget root of sub-tree
1091 * @return EINA_TRUE if the object sub-tree is unfocusable
1096 elm_widget_tree_unfocusable_get(const Evas_Object *obj)
1098 API_ENTRY return EINA_FALSE;
1099 return sd->tree_unfocusable;
1103 elm_widget_highlight_ignore_set(Evas_Object *obj,
1107 sd->highlight_ignore = !!ignore;
1111 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1113 API_ENTRY return EINA_FALSE;
1114 return sd->highlight_ignore;
1118 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1119 Eina_Bool highlight)
1122 sd->highlight_in_theme = !!highlight;
1123 /* FIXME: if focused, it should switch from one mode to the other */
1127 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1129 API_ENTRY return EINA_FALSE;
1130 return sd->highlight_in_theme;
1134 elm_widget_focus_get(const Evas_Object *obj)
1136 API_ENTRY return EINA_FALSE;
1141 elm_widget_focused_object_get(const Evas_Object *obj)
1143 const Evas_Object *subobj;
1145 API_ENTRY return NULL;
1147 if (!sd->focused) return NULL;
1148 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1150 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1151 if (fobj) return fobj;
1153 return (Evas_Object *)obj;
1157 elm_widget_top_get(const Evas_Object *obj)
1159 API_ENTRY return NULL;
1160 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1161 return (Evas_Object *)obj;
1165 elm_widget_is(const Evas_Object *obj)
1167 return _elm_widget_is(obj);
1171 elm_widget_parent_widget_get(const Evas_Object *obj)
1173 Evas_Object *parent;
1175 if (_elm_widget_is(obj))
1177 Smart_Data *sd = evas_object_smart_data_get(obj);
1178 if (!sd) return NULL;
1179 parent = sd->parent_obj;
1183 parent = evas_object_data_get(obj, "elm-parent");
1184 if (!parent) parent = evas_object_smart_parent_get(obj);
1189 Evas_Object *elm_parent;
1190 if (_elm_widget_is(parent)) break;
1191 elm_parent = evas_object_data_get(parent, "elm-parent");
1192 if (elm_parent) parent = elm_parent;
1193 else parent = evas_object_smart_parent_get(parent);
1199 elm_widget_event_callback_add(Evas_Object *obj,
1204 EINA_SAFETY_ON_NULL_RETURN(func);
1205 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1208 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1212 elm_widget_event_callback_del(Evas_Object *obj,
1216 API_ENTRY return NULL;
1217 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1219 Elm_Event_Cb_Data *ecd;
1220 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1221 if ((ecd->func == func) && (ecd->data == data))
1224 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1225 return (void *)data;
1231 elm_widget_event_propagate(Evas_Object *obj,
1232 Evas_Callback_Type type,
1234 Evas_Event_Flags *event_flags)
1236 API_ENTRY return EINA_FALSE; //TODO reduce.
1237 if (!_elm_widget_is(obj)) return EINA_FALSE;
1238 Evas_Object *parent = obj;
1239 Elm_Event_Cb_Data *ecd;
1240 Eina_List *l, *l_prev;
1243 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1245 sd = evas_object_smart_data_get(parent);
1246 if ((!sd) || (!_elm_widget_is(obj)))
1247 return EINA_FALSE; //Not Elm Widget
1249 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1252 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1254 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1255 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1258 parent = sd->parent_obj;
1267 * Set custom focus chain.
1269 * This function i set one new and overwrite any previous custom focus chain
1270 * with the list of objects. The previous list will be deleted and this list
1271 * will be managed. After setted, don't modity it.
1273 * @note On focus cycle, only will be evaluated children of this container.
1275 * @param obj The container widget
1276 * @param objs Chain of objects to pass focus
1280 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1284 if (!sd->focus_next_func)
1287 elm_widget_focus_custom_chain_unset(obj);
1292 EINA_LIST_FOREACH(objs, l, o)
1294 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1295 _elm_object_focus_chain_del_cb, sd);
1298 sd->focus_chain = objs;
1304 * Get custom focus chain
1306 * @param obj The container widget
1309 EAPI const Eina_List *
1310 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1312 API_ENTRY return NULL;
1313 return (const Eina_List *)sd->focus_chain;
1319 * Unset custom focus chain
1321 * @param obj The container widget
1325 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1328 Eina_List *l, *l_next;
1331 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1333 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1334 _elm_object_focus_chain_del_cb, sd);
1335 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1342 * Append object to custom focus chain.
1344 * @note If relative_child equal to NULL or not in custom chain, the object
1345 * will be added in end.
1347 * @note On focus cycle, only will be evaluated children of this container.
1349 * @param obj The container widget
1350 * @param child The child to be added in custom chain
1351 * @param relative_child The relative object to position the child
1355 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1357 Evas_Object *relative_child)
1360 EINA_SAFETY_ON_NULL_RETURN(child);
1361 if (!sd->focus_next_func)
1364 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1365 _elm_object_focus_chain_del_cb, sd);
1367 if (!relative_child)
1369 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1373 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1380 * Prepend object to custom focus chain.
1382 * @note If relative_child equal to NULL or not in custom chain, the object
1383 * will be added in begin.
1385 * @note On focus cycle, only will be evaluated children of this container.
1387 * @param obj The container widget
1388 * @param child The child to be added in custom chain
1389 * @param relative_child The relative object to position the child
1393 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1395 Evas_Object *relative_child)
1398 EINA_SAFETY_ON_NULL_RETURN(child);
1399 if (!sd->focus_next_func)
1402 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1403 _elm_object_focus_chain_del_cb, sd);
1405 if (!relative_child)
1407 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1411 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1418 * Give focus to next object in object tree.
1420 * Give focus to next object in focus chain of one object sub-tree.
1421 * If the last object of chain already have focus, the focus will go to the
1422 * first object of chain.
1424 * @param obj The widget root of sub-tree
1425 * @param dir Direction to cycle the focus
1430 elm_widget_focus_cycle(Evas_Object *obj,
1431 Elm_Focus_Direction dir)
1433 Evas_Object *target = NULL;
1434 if (!_elm_widget_is(obj))
1436 elm_widget_focus_next_get(obj, dir, &target);
1438 elm_widget_focus_steal(target);
1444 * Give focus to near object in one direction.
1446 * Give focus to near object in direction of one object.
1447 * If none focusable object in given direction, the focus will not change.
1449 * @param obj The reference widget
1450 * @param x Horizontal component of direction to focus
1451 * @param y Vertical component of direction to focus
1456 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1466 * Get next object in focus chain of object tree.
1468 * Get next object in focus chain of one object sub-tree.
1469 * Return the next object by reference. If don't have any candidate to receive
1470 * focus before chain end, the first candidate will be returned.
1472 * @param obj The widget root of sub-tree
1473 * @param dir Direction os focus chain
1474 * @param next The next object in focus chain
1475 * @return EINA_TRUE if don't need focus chain restart/loop back
1476 * to use 'next' obj.
1481 elm_widget_focus_next_get(const Evas_Object *obj,
1482 Elm_Focus_Direction dir,
1489 API_ENTRY return EINA_FALSE;
1491 /* Ignore if disabled */
1492 if ((!evas_object_visible_get(obj))
1493 || (elm_widget_disabled_get(obj))
1494 || (elm_widget_tree_unfocusable_get(obj)))
1498 if (sd->focus_next_func)
1499 return sd->focus_next_func(obj, dir, next);
1501 if (!elm_widget_can_focus_get(obj))
1505 *next = (Evas_Object *)obj;
1506 return !elm_widget_focus_get(obj);
1512 * Get next object in focus chain of object tree in list.
1514 * Get next object in focus chain of one object sub-tree ordered by one list.
1515 * Return the next object by reference. If don't have any candidate to receive
1516 * focus before list end, the first candidate will be returned.
1518 * @param obj The widget root of sub-tree
1519 * @param dir Direction os focus chain
1520 * @param items list with ordered objects
1521 * @param list_data_get function to get the object from one item of list
1522 * @param next The next object in focus chain
1523 * @return EINA_TRUE if don't need focus chain restart/loop back
1524 * to use 'next' obj.
1529 elm_widget_focus_list_next_get(const Evas_Object *obj,
1530 const Eina_List *items,
1531 void *(*list_data_get)(const Eina_List * list),
1532 Elm_Focus_Direction dir,
1535 Eina_List *(*list_next)(const Eina_List * list);
1541 if (!_elm_widget_is(obj))
1548 if (dir == ELM_FOCUS_PREVIOUS)
1550 items = eina_list_last(items);
1551 list_next = eina_list_prev;
1553 else if (dir == ELM_FOCUS_NEXT)
1554 list_next = eina_list_next;
1558 const Eina_List *l = items;
1560 /* Recovery last focused sub item */
1561 if (elm_widget_focus_get(obj))
1562 for (; l; l = list_next(l))
1564 Evas_Object *cur = list_data_get(l);
1565 if (elm_widget_focus_get(cur)) break;
1568 const Eina_List *start = l;
1569 Evas_Object *to_focus = NULL;
1571 /* Interate sub items */
1572 /* Go to end of list */
1573 for (; l; l = list_next(l))
1575 Evas_Object *tmp = NULL;
1576 Evas_Object *cur = list_data_get(l);
1578 if (elm_widget_parent_get(cur) != obj)
1581 /* Try Focus cycle in subitem */
1582 if (elm_widget_focus_next_get(cur, dir, &tmp))
1587 else if ((tmp) && (!to_focus))
1593 /* Get First possible */
1594 for (; l != start; l = list_next(l))
1596 Evas_Object *tmp = NULL;
1597 Evas_Object *cur = list_data_get(l);
1599 if (elm_widget_parent_get(cur) != obj)
1602 /* Try Focus cycle in subitem */
1603 elm_widget_focus_next_get(cur, dir, &tmp);
1616 elm_widget_signal_emit(Evas_Object *obj,
1617 const char *emission,
1621 if (!sd->signal_func) return;
1622 sd->signal_func(obj, emission, source);
1626 _edje_signal_callback(void *data,
1627 Evas_Object *obj __UNUSED__,
1628 const char *emission,
1631 Edje_Signal_Data *esd = data;
1632 esd->func(esd->data, esd->obj, emission, source);
1636 elm_widget_signal_callback_add(Evas_Object *obj,
1637 const char *emission,
1639 Edje_Signal_Cb func,
1642 Edje_Signal_Data *esd;
1644 if (!sd->callback_add_func) return;
1645 EINA_SAFETY_ON_NULL_RETURN(func);
1647 esd = ELM_NEW(Edje_Signal_Data);
1652 esd->emission = eina_stringshare_add(emission);
1653 esd->source = eina_stringshare_add(source);
1655 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1656 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1660 elm_widget_signal_callback_del(Evas_Object *obj,
1661 const char *emission,
1663 Edje_Signal_Cb func)
1665 Edje_Signal_Data *esd;
1668 API_ENTRY return NULL;
1669 if (!sd->callback_del_func) return NULL;
1671 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1673 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1674 (!strcmp(esd->source, source)))
1676 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1677 eina_stringshare_del(esd->emission);
1678 eina_stringshare_del(esd->source);
1684 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1689 elm_widget_focus_set(Evas_Object *obj,
1696 sd->focus_order = focus_order;
1697 sd->focused = EINA_TRUE;
1698 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1702 sd->focus_func(obj);
1709 if ((_is_focusable(sd->resize_obj)) &&
1710 (!elm_widget_disabled_get(sd->resize_obj)))
1712 elm_widget_focus_set(sd->resize_obj, first);
1718 EINA_LIST_FOREACH(sd->subobjs, l, child)
1720 if ((_is_focusable(child)) &&
1721 (!elm_widget_disabled_get(child)))
1723 elm_widget_focus_set(child, first);
1733 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1735 if ((_is_focusable(child)) &&
1736 (!elm_widget_disabled_get(child)))
1738 elm_widget_focus_set(child, first);
1744 if ((_is_focusable(sd->resize_obj)) &&
1745 (!elm_widget_disabled_get(sd->resize_obj)))
1747 elm_widget_focus_set(sd->resize_obj, first);
1755 elm_widget_parent_get(const Evas_Object *obj)
1757 API_ENTRY return NULL;
1758 return sd->parent_obj;
1762 elm_widget_focused_object_clear(Evas_Object *obj)
1765 if (!sd->focused) return;
1766 if (elm_widget_focus_get(sd->resize_obj))
1767 elm_widget_focused_object_clear(sd->resize_obj);
1772 EINA_LIST_FOREACH(sd->subobjs, l, child)
1774 if (elm_widget_focus_get(child))
1776 elm_widget_focused_object_clear(child);
1781 sd->focused = EINA_FALSE;
1782 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1783 if (sd->focus_func) sd->focus_func(obj);
1787 elm_widget_focus_steal(Evas_Object *obj)
1789 Evas_Object *parent, *o;
1792 if (sd->focused) return;
1793 if (sd->disabled) return;
1794 if (!sd->can_focus) return;
1795 if (sd->tree_unfocusable) return;
1799 o = elm_widget_parent_get(parent);
1801 sd = evas_object_smart_data_get(o);
1802 if (sd->disabled || sd->tree_unfocusable) return;
1803 if (sd->focused) break;
1806 if (!elm_widget_parent_get(parent))
1807 elm_widget_focused_object_clear(parent);
1810 parent = elm_widget_parent_get(parent);
1811 sd = evas_object_smart_data_get(parent);
1812 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1813 elm_widget_focused_object_clear(sd->resize_obj);
1818 EINA_LIST_FOREACH(sd->subobjs, l, child)
1820 if (elm_widget_focus_get(child))
1822 elm_widget_focused_object_clear(child);
1833 elm_widget_activate(Evas_Object *obj)
1836 elm_widget_change(obj);
1837 if (sd->activate_func) sd->activate_func(obj);
1841 elm_widget_change(Evas_Object *obj)
1844 elm_widget_change(elm_widget_parent_get(obj));
1845 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1849 elm_widget_disabled_set(Evas_Object *obj,
1854 if (sd->disabled == disabled) return;
1855 sd->disabled = !!disabled;
1856 elm_widget_focus_disabled_handle(obj);
1857 if (sd->disable_func) sd->disable_func(obj);
1861 elm_widget_disabled_get(const Evas_Object *obj)
1864 return sd->disabled;
1868 elm_widget_show_region_set(Evas_Object *obj,
1873 Eina_Bool forceshow)
1875 Evas_Object *parent_obj, *child_obj;
1876 Evas_Coord px, py, cx, cy;
1879 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1880 && (w == sd->rw) && (h == sd->rh)) return;
1885 if (sd->on_show_region_func)
1886 sd->on_show_region_func(sd->on_show_region_data, obj);
1890 parent_obj = sd->parent_obj;
1891 child_obj = sd->obj;
1892 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1893 sd = evas_object_smart_data_get(parent_obj);
1896 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1897 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1906 if (sd->on_show_region_func)
1908 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1915 elm_widget_show_region_get(const Evas_Object *obj,
1931 * Get the focus region of the given widget.
1933 * The focus region is the area of a widget that should brought into the
1934 * visible area when the widget is focused. Mostly used to show the part of
1935 * an entry where the cursor is, for example. The area returned is relative
1936 * to the object @p obj.
1937 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1938 * function will return the full size of the object.
1940 * @param obj The widget object
1941 * @param x Where to store the x coordinate of the area
1942 * @param y Where to store the y coordinate of the area
1943 * @param w Where to store the width of the area
1944 * @param h Where to store the height of the area
1949 elm_widget_focus_region_get(const Evas_Object *obj,
1959 sd = evas_object_smart_data_get(obj);
1960 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1962 evas_object_geometry_get(obj, NULL, NULL, w, h);
1967 sd->on_focus_region_func(obj, x, y, w, h);
1971 elm_widget_scroll_hold_push(Evas_Object *obj)
1975 if (sd->scroll_hold == 1)
1976 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1977 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1978 // FIXME: on delete/reparent hold pop
1982 elm_widget_scroll_hold_pop(Evas_Object *obj)
1986 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1987 if (!sd->scroll_hold)
1988 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1989 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1993 elm_widget_scroll_hold_get(const Evas_Object *obj)
1996 return sd->scroll_hold;
2000 elm_widget_scroll_freeze_push(Evas_Object *obj)
2003 sd->scroll_freeze++;
2004 if (sd->scroll_freeze == 1)
2005 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
2006 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
2007 // FIXME: on delete/reparent freeze pop
2011 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2014 sd->scroll_freeze--;
2015 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2016 if (!sd->scroll_freeze)
2017 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2018 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2022 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2025 return sd->scroll_freeze;
2029 elm_widget_scale_set(Evas_Object *obj,
2033 if (scale <= 0.0) scale = 0.0;
2034 if (sd->scale != scale)
2037 elm_widget_theme(obj);
2042 elm_widget_scale_get(const Evas_Object *obj)
2044 API_ENTRY return 1.0;
2045 // FIXME: save walking up the tree by storing/caching parent scale
2046 if (sd->scale == 0.0)
2049 return elm_widget_scale_get(sd->parent_obj);
2057 elm_widget_theme_set(Evas_Object *obj,
2061 if (sd->theme != th)
2063 if (sd->theme) elm_theme_free(sd->theme);
2066 elm_widget_theme(obj);
2071 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2075 if (!sd->on_text_set_func)
2078 sd->on_text_set_func(obj, item, label);
2082 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2084 API_ENTRY return NULL;
2086 if (!sd->on_text_get_func)
2089 return sd->on_text_get_func(obj, item);
2093 elm_widget_theme_get(const Evas_Object *obj)
2095 API_ENTRY return NULL;
2099 return elm_widget_theme_get(sd->parent_obj);
2107 elm_widget_style_set(Evas_Object *obj,
2112 if (eina_stringshare_replace(&sd->style, style))
2113 elm_widget_theme(obj);
2117 elm_widget_style_get(const Evas_Object *obj)
2119 API_ENTRY return NULL;
2120 if (sd->style) return sd->style;
2125 elm_widget_type_set(Evas_Object *obj,
2129 eina_stringshare_replace(&sd->type, type);
2133 elm_widget_type_get(const Evas_Object *obj)
2135 API_ENTRY return NULL;
2136 if (sd->type) return sd->type;
2141 elm_widget_tooltip_add(Evas_Object *obj,
2145 sd->tooltips = eina_list_append(sd->tooltips, tt);
2149 elm_widget_tooltip_del(Evas_Object *obj,
2153 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2157 elm_widget_cursor_add(Evas_Object *obj,
2161 sd->cursors = eina_list_append(sd->cursors, cur);
2165 elm_widget_cursor_del(Evas_Object *obj,
2169 sd->cursors = eina_list_remove(sd->cursors, cur);
2173 elm_widget_drag_lock_x_set(Evas_Object *obj,
2177 if (sd->drag_x_locked == lock) return;
2178 sd->drag_x_locked = lock;
2179 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2180 else _propagate_x_drag_lock(obj, -1);
2184 elm_widget_drag_lock_y_set(Evas_Object *obj,
2188 if (sd->drag_y_locked == lock) return;
2189 sd->drag_y_locked = lock;
2190 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2191 else _propagate_y_drag_lock(obj, -1);
2195 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2197 API_ENTRY return EINA_FALSE;
2198 return sd->drag_x_locked;
2202 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2204 API_ENTRY return EINA_FALSE;
2205 return sd->drag_y_locked;
2209 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2212 return sd->child_drag_x_locked;
2216 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2219 return sd->child_drag_y_locked;
2223 elm_widget_theme_object_set(Evas_Object *obj,
2226 const char *welement,
2229 API_ENTRY return EINA_FALSE;
2230 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2234 elm_widget_type_check(const Evas_Object *obj,
2237 const char *provided, *expected = "(unknown)";
2238 static int abort_on_warn = -1;
2239 provided = elm_widget_type_get(obj);
2240 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2241 if (type) expected = type;
2242 if ((!provided) || (!provided[0]))
2244 provided = evas_object_type_get(obj);
2245 if ((!provided) || (!provided[0]))
2246 provided = "(unknown)";
2248 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2249 if (abort_on_warn == -1)
2251 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2252 else abort_on_warn = 0;
2254 if (abort_on_warn == 1) abort();
2261 * Split string in words
2263 * @param str Source string
2264 * @return List of const words
2266 * @see elm_widget_stringlist_free()
2270 elm_widget_stringlist_get(const char *str)
2272 Eina_List *list = NULL;
2274 if (!str) return NULL;
2275 for (b = s = str; 1; s++)
2277 if ((*s == ' ') || (!*s))
2279 char *t = malloc(s - b + 1);
2282 strncpy(t, b, s - b);
2284 list = eina_list_append(list, eina_stringshare_add(t));
2295 elm_widget_stringlist_free(Eina_List *list)
2298 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2302 elm_widget_focus_hide_handle(Evas_Object *obj)
2304 _if_focused_revert(obj, EINA_TRUE);
2308 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2310 Evas_Object *o = obj;
2313 if (_elm_widget_is(o)) break;
2314 o = evas_object_smart_parent_get(o);
2318 if (!_is_focusable(o)) return;
2319 elm_widget_focus_steal(o);
2323 elm_widget_focus_tree_unfocusable_handle(Evas_Object *obj)
2327 if (!elm_widget_parent_get(obj))
2328 elm_widget_focused_object_clear(obj);
2330 _if_focused_revert(obj, EINA_TRUE);
2334 elm_widget_focus_disabled_handle(Evas_Object *obj)
2338 elm_widget_focus_tree_unfocusable_handle(obj);
2344 * Allocate a new Elm_Widget_Item-derived structure.
2346 * The goal of this structure is to provide common ground for actions
2347 * that a widget item have, such as the owner widget, callback to
2348 * notify deletion, data pointer and maybe more.
2350 * @param widget the owner widget that holds this item, must be an elm_widget!
2351 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2352 * be used to allocate memory.
2354 * @return allocated memory that is already zeroed out, or NULL on errors.
2356 * @see elm_widget_item_new() convenience macro.
2357 * @see elm_widget_item_del() to release memory.
2360 EAPI Elm_Widget_Item *
2361 _elm_widget_item_new(Evas_Object *widget,
2364 if (!_elm_widget_is(widget))
2367 Elm_Widget_Item *item;
2369 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2370 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2372 item = calloc(1, alloc_size);
2373 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2375 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2376 item->widget = widget;
2383 * Releases widget item memory, calling back del_cb() if it exists.
2385 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2386 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2387 * this function and then unset it, thus being useful for 2 step
2388 * cleanup whenever the del_cb may use any of the data that must be
2389 * deleted from item.
2391 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2394 * @param item a valid #Elm_Widget_Item to be deleted.
2395 * @see elm_widget_item_del() convenience macro.
2399 _elm_widget_item_del(Elm_Widget_Item *item)
2401 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2404 item->del_cb((void *)item->data, item->widget, item);
2407 evas_object_del(item->view);
2409 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2416 * Notify object will be deleted without actually deleting it.
2418 * This function will callback Elm_Widget_Item::del_cb if it is set
2419 * and then unset it so it is not called twice (ie: from
2420 * elm_widget_item_del()).
2422 * @param item a valid #Elm_Widget_Item to be notified
2423 * @see elm_widget_item_pre_notify_del() convenience macro.
2427 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2429 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2430 if (!item->del_cb) return;
2431 item->del_cb((void *)item->data, item->widget, item);
2432 item->del_cb = NULL;
2438 * Set the function to notify when item is being deleted.
2440 * This function will complain if there was a callback set already,
2441 * however it will set the new one.
2443 * The callback will be called from elm_widget_item_pre_notify_del()
2444 * or elm_widget_item_del() will be called with:
2445 * - data: the Elm_Widget_Item::data value.
2446 * - obj: the Elm_Widget_Item::widget evas object.
2447 * - event_info: the item being deleted.
2449 * @param item a valid #Elm_Widget_Item to be notified
2450 * @see elm_widget_item_del_cb_set() convenience macro.
2454 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2455 Evas_Smart_Cb del_cb)
2457 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2459 if ((item->del_cb) && (item->del_cb != del_cb))
2460 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2461 item->del_cb, item, del_cb);
2463 item->del_cb = del_cb;
2469 * Set user-data in this item.
2471 * User data may be used to identify this item or just store any
2472 * application data. It is automatically given as the first parameter
2473 * of the deletion notify callback.
2475 * @param item a valid #Elm_Widget_Item to store data in.
2476 * @param data user data to store.
2477 * @see elm_widget_item_del_cb_set() convenience macro.
2481 _elm_widget_item_data_set(Elm_Widget_Item *item,
2484 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2485 if ((item->data) && (item->data != data))
2486 DBG("Replacing item %p data %p with %p", item, item->data, data);
2493 * Retrieves user-data of this item.
2495 * @param item a valid #Elm_Widget_Item to get data from.
2496 * @see elm_widget_item_data_set()
2500 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2502 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2503 return (void *)item->data;
2506 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2508 struct _Elm_Widget_Item_Tooltip
2510 Elm_Widget_Item *item;
2511 Elm_Tooltip_Item_Content_Cb func;
2512 Evas_Smart_Cb del_cb;
2516 static Evas_Object *
2517 _elm_widget_item_tooltip_label_create(void *data,
2519 void *item __UNUSED__)
2521 Evas_Object *label = elm_label_add(obj);
2524 elm_object_style_set(label, "tooltip");
2525 elm_object_text_set(label, data);
2530 _elm_widget_item_tooltip_label_del_cb(void *data,
2531 Evas_Object *obj __UNUSED__,
2532 void *event_info __UNUSED__)
2534 eina_stringshare_del(data);
2540 * Set the text to be shown in the widget item.
2542 * @param item Target item
2543 * @param text The text to set in the content
2545 * Setup the text as tooltip to object. The item can have only one tooltip,
2546 * so any previous tooltip data is removed.
2551 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2554 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2555 EINA_SAFETY_ON_NULL_RETURN(text);
2557 text = eina_stringshare_add(text);
2558 _elm_widget_item_tooltip_content_cb_set
2559 (item, _elm_widget_item_tooltip_label_create, text,
2560 _elm_widget_item_tooltip_label_del_cb);
2563 static Evas_Object *
2564 _elm_widget_item_tooltip_create(void *data,
2567 Elm_Widget_Item_Tooltip *wit = data;
2568 return wit->func((void *)wit->data, obj, wit->item);
2572 _elm_widget_item_tooltip_del_cb(void *data,
2574 void *event_info __UNUSED__)
2576 Elm_Widget_Item_Tooltip *wit = data;
2577 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2584 * Set the content to be shown in the tooltip item
2586 * Setup the tooltip to item. The item can have only one tooltip,
2587 * so any previous tooltip data is removed. @p func(with @p data) will
2588 * be called every time that need show the tooltip and it should
2589 * return a valid Evas_Object. This object is then managed fully by
2590 * tooltip system and is deleted when the tooltip is gone.
2592 * @param item the widget item being attached a tooltip.
2593 * @param func the function used to create the tooltip contents.
2594 * @param data what to provide to @a func as callback data/context.
2595 * @param del_cb called when data is not needed anymore, either when
2596 * another callback replaces @func, the tooltip is unset with
2597 * elm_widget_item_tooltip_unset() or the owner @a item
2598 * dies. This callback receives as the first parameter the
2599 * given @a data, and @c event_info is the item.
2604 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2605 Elm_Tooltip_Item_Content_Cb func,
2607 Evas_Smart_Cb del_cb)
2609 Elm_Widget_Item_Tooltip *wit;
2611 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2615 _elm_widget_item_tooltip_unset(item);
2619 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2620 if (!wit) goto error;
2624 wit->del_cb = del_cb;
2626 elm_object_sub_tooltip_content_cb_set
2627 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2628 _elm_widget_item_tooltip_del_cb);
2633 if (del_cb) del_cb((void *)data, NULL, item);
2636 if (del_cb) del_cb((void *)data, item->widget, item);
2642 * Unset tooltip from item
2644 * @param item widget item to remove previously set tooltip.
2646 * Remove tooltip from item. The callback provided as del_cb to
2647 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2648 * it is not used anymore.
2650 * @see elm_widget_item_tooltip_content_cb_set()
2655 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2657 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2658 elm_object_tooltip_unset(item->view);
2664 * Sets a different style for this item tooltip.
2666 * @note before you set a style you should define a tooltip with
2667 * elm_widget_item_tooltip_content_cb_set() or
2668 * elm_widget_item_tooltip_text_set()
2670 * @param item widget item with tooltip already set.
2671 * @param style the theme style to use (default, transparent, ...)
2676 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2679 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2680 elm_object_tooltip_style_set(item->view, style);
2686 * Get the style for this item tooltip.
2688 * @param item widget item with tooltip already set.
2689 * @return style the theme style in use, defaults to "default". If the
2690 * object does not have a tooltip set, then NULL is returned.
2695 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2697 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2698 return elm_object_tooltip_style_get(item->view);
2702 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2705 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2706 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2710 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2712 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2713 return elm_object_cursor_get(item->view);
2717 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2719 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2720 elm_object_cursor_unset(item->view);
2726 * Sets a different style for this item cursor.
2728 * @note before you set a style you should define a cursor with
2729 * elm_widget_item_cursor_set()
2731 * @param item widget item with cursor already set.
2732 * @param style the theme style to use (default, transparent, ...)
2737 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2740 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2741 elm_object_cursor_style_set(item->view, style);
2747 * Get the style for this item cursor.
2749 * @param item widget item with cursor already set.
2750 * @return style the theme style in use, defaults to "default". If the
2751 * object does not have a cursor set, then NULL is returned.
2756 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2758 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2759 return elm_object_cursor_style_get(item->view);
2765 * Set if the cursor set should be searched on the theme or should use
2766 * the provided by the engine, only.
2768 * @note before you set if should look on theme you should define a cursor
2769 * with elm_object_cursor_set(). By default it will only look for cursors
2770 * provided by the engine.
2772 * @param item widget item with cursor already set.
2773 * @param engine_only boolean to define it cursors should be looked only
2774 * between the provided by the engine or searched on widget's theme as well.
2779 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2780 Eina_Bool engine_only)
2782 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2783 elm_object_cursor_engine_only_set(item->view, engine_only);
2789 * Get the cursor engine only usage for this item cursor.
2791 * @param item widget item with cursor already set.
2792 * @return engine_only boolean to define it cursors should be looked only
2793 * between the provided by the engine or searched on widget's theme as well. If
2794 * the object does not have a cursor set, then EINA_FALSE is returned.
2799 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2801 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2802 return elm_object_cursor_engine_only_get(item->view);
2805 // smart object funcs
2807 _smart_reconfigure(Smart_Data *sd)
2811 evas_object_move(sd->resize_obj, sd->x, sd->y);
2812 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2816 evas_object_move(sd->hover_obj, sd->x, sd->y);
2817 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2822 _smart_add(Evas_Object *obj)
2826 sd = calloc(1, sizeof(Smart_Data));
2829 sd->x = sd->y = sd->w = sd->h = 0;
2831 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2832 evas_object_smart_data_set(obj, sd);
2835 static Evas_Object *
2836 _newest_focus_order_get(Evas_Object *obj,
2837 unsigned int *newest_focus_order,
2838 Eina_Bool can_focus_only)
2841 Evas_Object *child, *ret, *best;
2843 API_ENTRY return NULL;
2845 if (!evas_object_visible_get(obj)
2846 || (elm_widget_disabled_get(obj))
2847 || (elm_widget_tree_unfocusable_get(obj)))
2851 if (*newest_focus_order < sd->focus_order)
2853 *newest_focus_order = sd->focus_order;
2856 EINA_LIST_FOREACH(sd->subobjs, l, child)
2858 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2864 if ((!best) || (!elm_widget_can_focus_get(best)))
2871 _if_focused_revert(Evas_Object *obj,
2872 Eina_Bool can_focus_only)
2875 Evas_Object *newest = NULL;
2876 unsigned int newest_focus_order = 0;
2880 if (!sd->focused) return;
2881 if (!sd->parent_obj) return;
2883 top = elm_widget_top_get(sd->parent_obj);
2886 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2889 elm_object_unfocus(newest);
2890 elm_object_focus(newest);
2896 _smart_del(Evas_Object *obj)
2899 Edje_Signal_Data *esd;
2903 if (sd->del_pre_func) sd->del_pre_func(obj);
2906 sobj = sd->resize_obj;
2907 sd->resize_obj = NULL;
2908 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2909 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2910 evas_object_del(sobj);
2914 sobj = sd->hover_obj;
2915 sd->hover_obj = NULL;
2916 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2917 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2918 evas_object_del(sobj);
2920 EINA_LIST_FREE(sd->subobjs, sobj)
2922 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2923 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2924 evas_object_del(sobj);
2926 eina_list_free(sd->tooltips); /* should be empty anyway */
2927 eina_list_free(sd->cursors); /* should be empty anyway */
2928 EINA_LIST_FREE(sd->edje_signals, esd)
2930 eina_stringshare_del(esd->emission);
2931 eina_stringshare_del(esd->source);
2934 eina_list_free(sd->event_cb); /* should be empty anyway */
2935 if (sd->del_func) sd->del_func(obj);
2936 if (sd->style) eina_stringshare_del(sd->style);
2937 if (sd->type) eina_stringshare_del(sd->type);
2938 if (sd->theme) elm_theme_free(sd->theme);
2939 _if_focused_revert(obj, EINA_TRUE);
2944 _smart_move(Evas_Object *obj,
2951 _smart_reconfigure(sd);
2955 _smart_resize(Evas_Object *obj,
2962 _smart_reconfigure(sd);
2966 _smart_show(Evas_Object *obj)
2971 if ((list = evas_object_smart_members_get(obj)))
2973 EINA_LIST_FREE(list, o)
2975 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2976 evas_object_show(o);
2982 _smart_hide(Evas_Object *obj)
2988 list = evas_object_smart_members_get(obj);
2989 EINA_LIST_FREE(list, o)
2991 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2992 evas_object_hide(o);
2997 _smart_color_set(Evas_Object *obj,
3006 if ((list = evas_object_smart_members_get(obj)))
3008 EINA_LIST_FREE(list, o)
3010 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3011 evas_object_color_set(o, r, g, b, a);
3017 _smart_clip_set(Evas_Object *obj,
3023 if ((list = evas_object_smart_members_get(obj)))
3025 EINA_LIST_FREE(list, o)
3027 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3028 evas_object_clip_set(o, clip);
3034 _smart_clip_unset(Evas_Object *obj)
3039 if ((list = evas_object_smart_members_get(obj)))
3041 EINA_LIST_FREE(list, o)
3043 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3044 evas_object_clip_unset(o);
3050 _smart_calculate(Evas_Object *obj)
3053 if (sd->changed_func) sd->changed_func(obj);
3056 /* never need to touch this */
3060 if (_e_smart) return;
3062 static const Evas_Smart_Class sc =
3065 EVAS_SMART_CLASS_VERSION,
3083 _e_smart = evas_smart_class_new(&sc);
3087 /* happy debug functions */
3090 _sub_obj_tree_dump(const Evas_Object *obj,
3095 for (i = 0; i < lvl * 3; i++)
3098 if (_elm_widget_is(obj))
3102 printf("+ %s(%p)\n",
3106 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3107 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3109 if (obj != sd->resize_obj)
3110 _sub_obj_tree_dump(obj, lvl + 1);
3114 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3118 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3121 if (!_elm_widget_is(obj))
3125 Eina_Bool visible = evas_object_visible_get(obj);
3126 Eina_Bool disabled = elm_widget_disabled_get(obj);
3127 Eina_Bool focused = elm_widget_focus_get(obj);
3128 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3132 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3135 fprintf(output, ", style=bold");
3138 fprintf(output, ", color=gray28");
3140 fprintf(output, " ];\n");
3143 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3144 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3145 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3149 fprintf(output, ", style=bold");
3152 fprintf(output, ", fontcolor=gray28");
3154 if ((disabled) || (!visible))
3155 fprintf(output, ", color=gray");
3157 fprintf(output, " ];\n");
3161 EINA_LIST_FOREACH(sd->subobjs, l, o)
3162 _sub_obj_tree_dot_dump(o, output);
3167 elm_widget_tree_dump(const Evas_Object *top)
3170 _sub_obj_tree_dump(top, 0);
3178 elm_widget_tree_dot_dump(const Evas_Object *top,
3182 if (!_elm_widget_is(top))
3184 fprintf(output, "graph " " { node [shape=record];\n");
3185 _sub_obj_tree_dot_dump(top, output);
3186 fprintf(output, "}\n");