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 top_win_focused : 1;
100 Eina_Bool tree_unfocusable : 1;
101 Eina_Bool highlight_ignore : 1;
102 Eina_Bool highlight_in_theme : 1;
103 Eina_Bool disabled : 1;
104 Eina_Bool is_mirrored : 1;
105 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
107 Eina_List *focus_chain;
111 struct _Edje_Signal_Data
115 const char *emission;
120 struct _Elm_Event_Cb_Data
126 /* local subsystem functions */
127 static void _smart_reconfigure(Smart_Data *sd);
128 static void _smart_add(Evas_Object *obj);
129 static void _smart_del(Evas_Object *obj);
130 static void _smart_move(Evas_Object *obj,
133 static void _smart_resize(Evas_Object *obj,
136 static void _smart_show(Evas_Object *obj);
137 static void _smart_hide(Evas_Object *obj);
138 static void _smart_color_set(Evas_Object *obj,
143 static void _smart_clip_set(Evas_Object *obj,
145 static void _smart_clip_unset(Evas_Object *obj);
146 static void _smart_calculate(Evas_Object *obj);
147 static void _smart_init(void);
149 static void _if_focused_revert(Evas_Object *obj,
150 Eina_Bool can_focus_only);
151 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
152 unsigned int *newest_focus_order,
153 Eina_Bool can_focus_only);
155 /* local subsystem globals */
156 static Evas_Smart *_e_smart = NULL;
157 static Eina_List *widtypes = NULL;
159 static unsigned int focus_order = 0;
162 static inline Eina_Bool
163 _elm_widget_is(const Evas_Object *obj)
165 const char *type = evas_object_type_get(obj);
166 return type == SMART_NAME;
169 static inline Eina_Bool
170 _is_focusable(Evas_Object *obj)
172 API_ENTRY return EINA_FALSE;
173 return sd->can_focus || (sd->child_can_focus);
177 _unfocus_parents(Evas_Object *obj)
179 for (; obj; obj = elm_widget_parent_get(obj))
182 if (!sd->focused) return;
188 _focus_parents(Evas_Object *obj)
190 for (; obj; obj = elm_widget_parent_get(obj))
193 if (sd->focused) return;
199 _sub_obj_del(void *data,
202 void *event_info __UNUSED__)
204 Smart_Data *sd = data;
206 if (_elm_widget_is(obj))
208 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
210 if (obj == sd->resize_obj)
211 sd->resize_obj = NULL;
212 else if (obj == sd->hover_obj)
213 sd->hover_obj = NULL;
215 sd->subobjs = eina_list_remove(sd->subobjs, obj);
216 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
220 _sub_obj_hide(void *data __UNUSED__,
223 void *event_info __UNUSED__)
225 elm_widget_focus_hide_handle(obj);
229 _sub_obj_mouse_down(void *data __UNUSED__,
232 void *event_info __UNUSED__)
234 elm_widget_focus_mouse_down_handle(obj);
238 _propagate_x_drag_lock(Evas_Object *obj,
244 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
247 sd2->child_drag_x_locked += dir;
248 _propagate_x_drag_lock(sd->parent_obj, dir);
254 _propagate_y_drag_lock(Evas_Object *obj,
260 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
263 sd2->child_drag_y_locked += dir;
264 _propagate_y_drag_lock(sd->parent_obj, dir);
270 _propagate_event(void *data,
276 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
277 Evas_Event_Flags *event_flags = NULL;
281 case EVAS_CALLBACK_KEY_DOWN:
283 Evas_Event_Key_Down *ev = event_info;
284 event_flags = &(ev->event_flags);
288 case EVAS_CALLBACK_KEY_UP:
290 Evas_Event_Key_Up *ev = event_info;
291 event_flags = &(ev->event_flags);
295 case EVAS_CALLBACK_MOUSE_WHEEL:
297 Evas_Event_Mouse_Wheel *ev = event_info;
298 event_flags = &(ev->event_flags);
306 elm_widget_event_propagate(obj, type, event_info, event_flags);
310 _parent_focus(Evas_Object *obj)
313 if (sd->focused) return;
315 Evas_Object *o = elm_widget_parent_get(obj);
316 sd->focus_order_on_calc = EINA_TRUE;
318 if (o) _parent_focus(o);
320 if (!sd->focus_order_on_calc)
321 return; /* we don't want to override it if by means of any of the
322 callbacks below one gets to calculate our order
326 sd->focus_order = focus_order;
327 if (sd->top_win_focused)
329 sd->focused = EINA_TRUE;
330 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
331 if (sd->focus_func) sd->focus_func(obj);
332 _elm_widget_focus_region_show(obj);
334 sd->focus_order_on_calc = EINA_FALSE;
338 _elm_object_focus_chain_del_cb(void *data,
341 void *event_info __UNUSED__)
343 Smart_Data *sd = data;
345 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
348 // exposed util funcs to elm
350 _elm_widget_type_clear(void)
354 EINA_LIST_FREE(widtypes, ptr)
356 eina_stringshare_del(*ptr);
362 _elm_widget_focus_region_show(const Evas_Object *obj)
364 Evas_Coord x, y, w, h, ox, oy;
370 o = elm_widget_parent_get(obj);
373 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
374 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
378 sd2 = evas_object_smart_data_get(o);
379 if (sd2->focus_region_func)
381 sd2->focus_region_func(o, x, y, w, h);
382 elm_widget_focus_region_get(o, &x, &y, &w, &h);
386 evas_object_geometry_get(o, &px, &py, NULL, NULL);
392 o = elm_widget_parent_get(o);
397 * @defgroup Widget Widget
400 * Exposed api for making widgets
403 elm_widget_type_register(const char **ptr)
405 widtypes = eina_list_append(widtypes, (void *)ptr);
409 * @defgroup Widget Widget
412 * Disposed api for making widgets
415 elm_widget_type_unregister(const char **ptr)
417 widtypes = eina_list_remove(widtypes, (void *)ptr);
421 elm_widget_api_check(int ver)
423 if (ver != ELM_INTERNAL_API_VERSION)
425 CRITICAL("Elementary widget api versions do not match");
432 elm_widget_add(Evas *evas)
436 obj = evas_object_smart_add(evas, _e_smart);
437 elm_widget_mirrored_set(obj, elm_mirrored_get());
442 elm_widget_del_hook_set(Evas_Object *obj,
443 void (*func)(Evas_Object *obj))
450 elm_widget_del_pre_hook_set(Evas_Object *obj,
451 void (*func)(Evas_Object *obj))
454 sd->del_pre_func = func;
458 elm_widget_focus_hook_set(Evas_Object *obj,
459 void (*func)(Evas_Object *obj))
462 sd->focus_func = func;
466 elm_widget_activate_hook_set(Evas_Object *obj,
467 void (*func)(Evas_Object *obj))
470 sd->activate_func = func;
474 elm_widget_disable_hook_set(Evas_Object *obj,
475 void (*func)(Evas_Object *obj))
478 sd->disable_func = func;
482 elm_widget_theme_hook_set(Evas_Object *obj,
483 void (*func)(Evas_Object *obj))
486 sd->theme_func = func;
490 elm_widget_event_hook_set(Evas_Object *obj,
491 Eina_Bool (*func)(Evas_Object *obj,
493 Evas_Callback_Type type,
497 sd->event_func = func;
501 elm_widget_text_set_hook_set(Evas_Object *obj,
502 void (*func)(Evas_Object *obj,
507 sd->on_text_set_func = func;
511 elm_widget_text_get_hook_set(Evas_Object *obj,
512 const char *(*func)(const Evas_Object *obj,
516 sd->on_text_get_func = func;
520 elm_widget_changed_hook_set(Evas_Object *obj,
521 void (*func)(Evas_Object *obj))
524 sd->changed_func = func;
528 elm_widget_signal_emit_hook_set(Evas_Object *obj,
529 void (*func)(Evas_Object *obj,
530 const char *emission,
534 sd->signal_func = func;
538 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
539 void (*func)(Evas_Object *obj,
540 const char *emission,
542 Edje_Signal_Cb func_cb,
546 sd->callback_add_func = func;
550 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
551 void (*func)(Evas_Object *obj,
552 const char *emission,
554 Edje_Signal_Cb func_cb,
558 sd->callback_del_func = func;
562 elm_widget_theme(Evas_Object *obj)
570 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
571 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
572 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
573 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
574 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
575 if (sd->theme_func) sd->theme_func(obj);
579 elm_widget_theme_specific(Evas_Object *obj,
587 Elm_Theme *th2, *thdef;
590 thdef = elm_theme_default_get();
595 if (!th2) th2 = thdef;
603 if (th2 == thdef) break;
604 th2 = th2->ref_theme;
605 if (!th2) th2 = thdef;
609 EINA_LIST_FOREACH(sd->subobjs, l, child)
610 elm_widget_theme_specific(child, th, force);
611 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
612 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
613 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
614 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
615 if (sd->theme_func) sd->theme_func(obj);
621 * Set hook to get next object in object focus chain.
623 * @param obj The widget object.
624 * @param func The hook to be used with this widget.
629 elm_widget_focus_next_hook_set(Evas_Object *obj,
630 Eina_Bool (*func)(const Evas_Object *obj,
631 Elm_Focus_Direction dir,
635 sd->focus_next_func = func;
639 * Returns the widget's mirrored mode.
641 * @param obj The widget.
642 * @return mirrored mode of the object.
646 elm_widget_mirrored_get(const Evas_Object *obj)
648 API_ENTRY return EINA_FALSE;
649 return sd->is_mirrored;
653 * Sets the widget's mirrored mode.
655 * @param obj The widget.
656 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
659 elm_widget_mirrored_set(Evas_Object *obj,
663 if (sd->is_mirrored != mirrored)
665 sd->is_mirrored = mirrored;
666 elm_widget_theme(obj);
672 * Resets the mirrored mode from the system mirror mode for widgets that are in
673 * automatic mirroring mode. This function does not call elm_widget_theme.
675 * @param obj The widget.
676 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
679 _elm_widget_mirrored_reload(Evas_Object *obj)
682 Eina_Bool mirrored = elm_mirrored_get();
683 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
685 sd->is_mirrored = mirrored;
690 * Returns the widget's mirrored mode setting.
692 * @param obj The widget.
693 * @return mirrored mode setting of the object.
697 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
699 API_ENTRY return EINA_FALSE;
700 return sd->mirrored_auto_mode;
704 * Sets the widget's mirrored mode setting.
705 * When widget in automatic mode, it follows the system mirrored mode set by
706 * elm_mirrored_set().
707 * @param obj The widget.
708 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
711 elm_widget_mirrored_automatic_set(Evas_Object *obj,
715 if (sd->mirrored_auto_mode != automatic)
717 sd->mirrored_auto_mode = automatic;
721 elm_widget_mirrored_set(obj, elm_mirrored_get());
727 elm_widget_on_focus_hook_set(Evas_Object *obj,
728 void (*func)(void *data,
733 sd->on_focus_func = func;
734 sd->on_focus_data = data;
738 elm_widget_on_change_hook_set(Evas_Object *obj,
739 void (*func)(void *data,
744 sd->on_change_func = func;
745 sd->on_change_data = data;
749 elm_widget_on_show_region_hook_set(Evas_Object *obj,
750 void (*func)(void *data,
755 sd->on_show_region_func = func;
756 sd->on_show_region_data = data;
762 * Set the hook to use to show the focused region.
764 * Whenever a new widget gets focused or it's needed to show the focused
765 * area of the current one, this hook will be called on objects that may
766 * want to move their children into their visible area.
767 * The area given in the hook function is relative to the @p obj widget.
769 * @param obj The widget object
770 * @param func The function to call to show the specified area.
775 elm_widget_focus_region_hook_set(Evas_Object *obj,
776 void (*func)(Evas_Object *obj,
783 sd->focus_region_func = func;
789 * Set the hook to retrieve the focused region of a widget.
791 * This hook will be called by elm_widget_focus_region_get() whenever
792 * it's needed to get the focused area of a widget. The area must be relative
793 * to the widget itself and if no hook is set, it will default to the entire
796 * @param obj The widget object
797 * @param func The function used to retrieve the focus region.
802 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
803 void (*func)(const Evas_Object *obj,
810 sd->on_focus_region_func = func;
814 elm_widget_data_set(Evas_Object *obj,
822 elm_widget_data_get(const Evas_Object *obj)
824 API_ENTRY return NULL;
829 elm_widget_sub_object_add(Evas_Object *obj,
833 double scale, pscale = elm_widget_scale_get(sobj);
834 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
835 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
837 if (_elm_widget_is(sobj))
839 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
842 if (sd2->parent_obj == obj)
845 elm_widget_sub_object_del(sd2->parent_obj, sobj);
846 sd2->parent_obj = obj;
847 sd2->top_win_focused = sd->top_win_focused;
848 if (!sd->child_can_focus && (_is_focusable(sobj)))
849 sd->child_can_focus = EINA_TRUE;
854 void *data = evas_object_data_get(sobj, "elm-parent");
857 if (data == obj) return;
858 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
863 sd->subobjs = eina_list_append(sd->subobjs, sobj);
864 evas_object_data_set(sobj, "elm-parent", obj);
865 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
866 if (_elm_widget_is(sobj))
867 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
868 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
869 scale = elm_widget_scale_get(sobj);
870 th = elm_widget_theme_get(sobj);
871 mirrored = elm_widget_mirrored_get(sobj);
872 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
873 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
877 elm_widget_sub_object_del(Evas_Object *obj,
880 Evas_Object *sobj_parent;
884 sobj_parent = evas_object_data_del(sobj, "elm-parent");
885 if (sobj_parent != obj)
887 static int abort_on_warn = -1;
888 ERR("removing sub object %p from parent %p, "
889 "but elm-parent is different %p!",
890 sobj, obj, sobj_parent);
891 if (EINA_UNLIKELY(abort_on_warn == -1))
893 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
894 else abort_on_warn = 0;
896 if (abort_on_warn == 1) abort();
898 if (_elm_widget_is(sobj))
900 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
903 sd2->parent_obj = NULL;
904 if (sd2->resize_obj == sobj)
905 sd2->resize_obj = NULL;
907 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
910 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
911 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
912 if ((sd->child_can_focus) && (_is_focusable(sobj)))
916 sd->child_can_focus = EINA_FALSE;
917 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
919 if (_is_focusable(subobj))
921 sd->child_can_focus = EINA_TRUE;
928 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
929 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
931 if (_elm_widget_is(sobj))
932 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
934 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
938 elm_widget_resize_object_set(Evas_Object *obj,
942 // orphan previous resize obj
945 evas_object_clip_unset(sd->resize_obj);
946 evas_object_data_del(sd->resize_obj, "elm-parent");
947 if (_elm_widget_is(sd->resize_obj))
949 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
950 if (sd2) sd2->parent_obj = NULL;
951 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
954 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
956 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
957 _sub_obj_mouse_down, sd);
958 evas_object_smart_member_del(sd->resize_obj);
959 if (_elm_widget_is(sd->resize_obj))
961 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
964 // orphan new resize obj
967 evas_object_data_del(sobj, "elm-parent");
968 if (_elm_widget_is(sobj))
970 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
971 if (sd2) sd2->parent_obj = NULL;
972 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
975 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
977 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
978 _sub_obj_mouse_down, sd);
979 evas_object_smart_member_del(sobj);
980 if (_elm_widget_is(sobj))
982 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
985 // set the resize obj up
986 sd->resize_obj = sobj;
989 if (_elm_widget_is(sd->resize_obj))
991 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
994 sd2->parent_obj = obj;
995 sd2->top_win_focused = sd->top_win_focused;
997 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
1000 evas_object_clip_set(sobj, evas_object_clip_get(obj));
1001 evas_object_smart_member_add(sobj, obj);
1002 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1004 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
1005 _sub_obj_mouse_down, sd);
1006 _smart_reconfigure(sd);
1007 evas_object_data_set(sobj, "elm-parent", obj);
1008 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
1009 if (_elm_widget_is(sobj))
1011 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
1017 elm_widget_hover_object_set(Evas_Object *obj,
1023 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1026 sd->hover_obj = sobj;
1029 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1031 _smart_reconfigure(sd);
1036 elm_widget_can_focus_set(Evas_Object *obj,
1037 Eina_Bool can_focus)
1040 sd->can_focus = can_focus;
1043 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1045 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1046 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1048 (void *)(long)EVAS_CALLBACK_KEY_UP);
1049 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1051 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1055 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1057 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1059 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1065 elm_widget_can_focus_get(const Evas_Object *obj)
1067 API_ENTRY return EINA_FALSE;
1068 return sd->can_focus;
1072 elm_widget_child_can_focus_get(const Evas_Object *obj)
1074 API_ENTRY return EINA_FALSE;
1075 return sd->child_can_focus;
1081 * This API makes the widget object and its children to be unfocusable.
1083 * This API can be helpful for an object to be deleted.
1084 * When an object will be deleted soon, it and its children may not
1085 * want to get focus (by focus reverting or by other focus controls).
1086 * Then, just use this API before deleting.
1088 * @param obj The widget root of sub-tree
1089 * @param tree_unfocusable If true, set the object sub-tree as unfocusable
1094 elm_widget_tree_unfocusable_set(Evas_Object *obj,
1095 Eina_Bool tree_unfocusable)
1099 if (sd->tree_unfocusable == tree_unfocusable) return;
1100 sd->tree_unfocusable = !!tree_unfocusable;
1101 elm_widget_focus_tree_unfocusable_handle(obj);
1107 * This returns true, if the object sub-tree is unfocusable.
1109 * @param obj The widget root of sub-tree
1110 * @return EINA_TRUE if the object sub-tree is unfocusable
1115 elm_widget_tree_unfocusable_get(const Evas_Object *obj)
1117 API_ENTRY return EINA_FALSE;
1118 return sd->tree_unfocusable;
1122 elm_widget_highlight_ignore_set(Evas_Object *obj,
1126 sd->highlight_ignore = !!ignore;
1130 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1132 API_ENTRY return EINA_FALSE;
1133 return sd->highlight_ignore;
1137 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1138 Eina_Bool highlight)
1141 sd->highlight_in_theme = !!highlight;
1142 /* FIXME: if focused, it should switch from one mode to the other */
1146 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1148 API_ENTRY return EINA_FALSE;
1149 return sd->highlight_in_theme;
1153 elm_widget_focus_get(const Evas_Object *obj)
1155 API_ENTRY return EINA_FALSE;
1160 elm_widget_focused_object_get(const Evas_Object *obj)
1162 const Evas_Object *subobj;
1164 API_ENTRY return NULL;
1166 if (!sd->focused) return NULL;
1167 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1169 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1170 if (fobj) return fobj;
1172 return (Evas_Object *)obj;
1176 elm_widget_top_get(const Evas_Object *obj)
1178 API_ENTRY return NULL;
1179 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1180 return (Evas_Object *)obj;
1184 elm_widget_is(const Evas_Object *obj)
1186 return _elm_widget_is(obj);
1190 elm_widget_parent_widget_get(const Evas_Object *obj)
1192 Evas_Object *parent;
1194 if (_elm_widget_is(obj))
1196 Smart_Data *sd = evas_object_smart_data_get(obj);
1197 if (!sd) return NULL;
1198 parent = sd->parent_obj;
1202 parent = evas_object_data_get(obj, "elm-parent");
1203 if (!parent) parent = evas_object_smart_parent_get(obj);
1208 Evas_Object *elm_parent;
1209 if (_elm_widget_is(parent)) break;
1210 elm_parent = evas_object_data_get(parent, "elm-parent");
1211 if (elm_parent) parent = elm_parent;
1212 else parent = evas_object_smart_parent_get(parent);
1218 elm_widget_event_callback_add(Evas_Object *obj,
1223 EINA_SAFETY_ON_NULL_RETURN(func);
1224 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1227 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1231 elm_widget_event_callback_del(Evas_Object *obj,
1235 API_ENTRY return NULL;
1236 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1238 Elm_Event_Cb_Data *ecd;
1239 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1240 if ((ecd->func == func) && (ecd->data == data))
1243 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1244 return (void *)data;
1250 elm_widget_event_propagate(Evas_Object *obj,
1251 Evas_Callback_Type type,
1253 Evas_Event_Flags *event_flags)
1255 API_ENTRY return EINA_FALSE; //TODO reduce.
1256 if (!_elm_widget_is(obj)) return EINA_FALSE;
1257 Evas_Object *parent = obj;
1258 Elm_Event_Cb_Data *ecd;
1259 Eina_List *l, *l_prev;
1262 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1264 sd = evas_object_smart_data_get(parent);
1265 if ((!sd) || (!_elm_widget_is(obj)))
1266 return EINA_FALSE; //Not Elm Widget
1268 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1271 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1273 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1274 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1277 parent = sd->parent_obj;
1286 * Set custom focus chain.
1288 * This function i set one new and overwrite any previous custom focus chain
1289 * with the list of objects. The previous list will be deleted and this list
1290 * will be managed. After setted, don't modity it.
1292 * @note On focus cycle, only will be evaluated children of this container.
1294 * @param obj The container widget
1295 * @param objs Chain of objects to pass focus
1299 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1303 if (!sd->focus_next_func)
1306 elm_widget_focus_custom_chain_unset(obj);
1311 EINA_LIST_FOREACH(objs, l, o)
1313 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1314 _elm_object_focus_chain_del_cb, sd);
1317 sd->focus_chain = objs;
1323 * Get custom focus chain
1325 * @param obj The container widget
1328 EAPI const Eina_List *
1329 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1331 API_ENTRY return NULL;
1332 return (const Eina_List *)sd->focus_chain;
1338 * Unset custom focus chain
1340 * @param obj The container widget
1344 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1347 Eina_List *l, *l_next;
1350 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1352 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1353 _elm_object_focus_chain_del_cb, sd);
1354 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1361 * Append object to custom focus chain.
1363 * @note If relative_child equal to NULL or not in custom chain, the object
1364 * will be added in end.
1366 * @note On focus cycle, only will be evaluated children of this container.
1368 * @param obj The container widget
1369 * @param child The child to be added in custom chain
1370 * @param relative_child The relative object to position the child
1374 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1376 Evas_Object *relative_child)
1379 EINA_SAFETY_ON_NULL_RETURN(child);
1380 if (!sd->focus_next_func)
1383 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1384 _elm_object_focus_chain_del_cb, sd);
1386 if (!relative_child)
1388 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1392 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1399 * Prepend object to custom focus chain.
1401 * @note If relative_child equal to NULL or not in custom chain, the object
1402 * will be added in begin.
1404 * @note On focus cycle, only will be evaluated children of this container.
1406 * @param obj The container widget
1407 * @param child The child to be added in custom chain
1408 * @param relative_child The relative object to position the child
1412 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1414 Evas_Object *relative_child)
1417 EINA_SAFETY_ON_NULL_RETURN(child);
1418 if (!sd->focus_next_func)
1421 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1422 _elm_object_focus_chain_del_cb, sd);
1424 if (!relative_child)
1426 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1430 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1437 * Give focus to next object in object tree.
1439 * Give focus to next object in focus chain of one object sub-tree.
1440 * If the last object of chain already have focus, the focus will go to the
1441 * first object of chain.
1443 * @param obj The widget root of sub-tree
1444 * @param dir Direction to cycle the focus
1449 elm_widget_focus_cycle(Evas_Object *obj,
1450 Elm_Focus_Direction dir)
1452 Evas_Object *target = NULL;
1453 if (!_elm_widget_is(obj))
1455 elm_widget_focus_next_get(obj, dir, &target);
1457 elm_widget_focus_steal(target);
1463 * Give focus to near object in one direction.
1465 * Give focus to near object in direction of one object.
1466 * If none focusable object in given direction, the focus will not change.
1468 * @param obj The reference widget
1469 * @param x Horizontal component of direction to focus
1470 * @param y Vertical component of direction to focus
1475 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1485 * Get next object in focus chain of object tree.
1487 * Get next object in focus chain of one object sub-tree.
1488 * Return the next object by reference. If don't have any candidate to receive
1489 * focus before chain end, the first candidate will be returned.
1491 * @param obj The widget root of sub-tree
1492 * @param dir Direction os focus chain
1493 * @param next The next object in focus chain
1494 * @return EINA_TRUE if don't need focus chain restart/loop back
1495 * to use 'next' obj.
1500 elm_widget_focus_next_get(const Evas_Object *obj,
1501 Elm_Focus_Direction dir,
1508 API_ENTRY return EINA_FALSE;
1510 /* Ignore if disabled */
1511 if ((!evas_object_visible_get(obj))
1512 || (elm_widget_disabled_get(obj))
1513 || (elm_widget_tree_unfocusable_get(obj)))
1517 if (sd->focus_next_func)
1518 return sd->focus_next_func(obj, dir, next);
1520 if (!elm_widget_can_focus_get(obj))
1524 *next = (Evas_Object *)obj;
1525 return !elm_widget_focus_get(obj);
1531 * Get next object in focus chain of object tree in list.
1533 * Get next object in focus chain of one object sub-tree ordered by one list.
1534 * Return the next object by reference. If don't have any candidate to receive
1535 * focus before list end, the first candidate will be returned.
1537 * @param obj The widget root of sub-tree
1538 * @param dir Direction os focus chain
1539 * @param items list with ordered objects
1540 * @param list_data_get function to get the object from one item of list
1541 * @param next The next object in focus chain
1542 * @return EINA_TRUE if don't need focus chain restart/loop back
1543 * to use 'next' obj.
1548 elm_widget_focus_list_next_get(const Evas_Object *obj,
1549 const Eina_List *items,
1550 void *(*list_data_get)(const Eina_List * list),
1551 Elm_Focus_Direction dir,
1554 Eina_List *(*list_next)(const Eina_List * list);
1560 if (!_elm_widget_is(obj))
1567 if (dir == ELM_FOCUS_PREVIOUS)
1569 items = eina_list_last(items);
1570 list_next = eina_list_prev;
1572 else if (dir == ELM_FOCUS_NEXT)
1573 list_next = eina_list_next;
1577 const Eina_List *l = items;
1579 /* Recovery last focused sub item */
1580 if (elm_widget_focus_get(obj))
1581 for (; l; l = list_next(l))
1583 Evas_Object *cur = list_data_get(l);
1584 if (elm_widget_focus_get(cur)) break;
1587 const Eina_List *start = l;
1588 Evas_Object *to_focus = NULL;
1590 /* Interate sub items */
1591 /* Go to end of list */
1592 for (; l; l = list_next(l))
1594 Evas_Object *tmp = NULL;
1595 Evas_Object *cur = list_data_get(l);
1597 if (elm_widget_parent_get(cur) != obj)
1600 /* Try Focus cycle in subitem */
1601 if (elm_widget_focus_next_get(cur, dir, &tmp))
1606 else if ((tmp) && (!to_focus))
1612 /* Get First possible */
1613 for (; l != start; l = list_next(l))
1615 Evas_Object *tmp = NULL;
1616 Evas_Object *cur = list_data_get(l);
1618 if (elm_widget_parent_get(cur) != obj)
1621 /* Try Focus cycle in subitem */
1622 elm_widget_focus_next_get(cur, dir, &tmp);
1635 elm_widget_signal_emit(Evas_Object *obj,
1636 const char *emission,
1640 if (!sd->signal_func) return;
1641 sd->signal_func(obj, emission, source);
1645 _edje_signal_callback(void *data,
1646 Evas_Object *obj __UNUSED__,
1647 const char *emission,
1650 Edje_Signal_Data *esd = data;
1651 esd->func(esd->data, esd->obj, emission, source);
1655 elm_widget_signal_callback_add(Evas_Object *obj,
1656 const char *emission,
1658 Edje_Signal_Cb func,
1661 Edje_Signal_Data *esd;
1663 if (!sd->callback_add_func) return;
1664 EINA_SAFETY_ON_NULL_RETURN(func);
1666 esd = ELM_NEW(Edje_Signal_Data);
1671 esd->emission = eina_stringshare_add(emission);
1672 esd->source = eina_stringshare_add(source);
1674 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1675 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1679 elm_widget_signal_callback_del(Evas_Object *obj,
1680 const char *emission,
1682 Edje_Signal_Cb func)
1684 Edje_Signal_Data *esd;
1687 API_ENTRY return NULL;
1688 if (!sd->callback_del_func) return NULL;
1690 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1692 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1693 (!strcmp(esd->source, source)))
1695 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1696 eina_stringshare_del(esd->emission);
1697 eina_stringshare_del(esd->source);
1703 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1708 elm_widget_focus_set(Evas_Object *obj,
1715 sd->focus_order = focus_order;
1716 sd->focused = EINA_TRUE;
1717 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1721 sd->focus_func(obj);
1728 if ((_is_focusable(sd->resize_obj)) &&
1729 (!elm_widget_disabled_get(sd->resize_obj)))
1731 elm_widget_focus_set(sd->resize_obj, first);
1737 EINA_LIST_FOREACH(sd->subobjs, l, child)
1739 if ((_is_focusable(child)) &&
1740 (!elm_widget_disabled_get(child)))
1742 elm_widget_focus_set(child, first);
1752 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1754 if ((_is_focusable(child)) &&
1755 (!elm_widget_disabled_get(child)))
1757 elm_widget_focus_set(child, first);
1763 if ((_is_focusable(sd->resize_obj)) &&
1764 (!elm_widget_disabled_get(sd->resize_obj)))
1766 elm_widget_focus_set(sd->resize_obj, first);
1774 elm_widget_parent_get(const Evas_Object *obj)
1776 API_ENTRY return NULL;
1777 return sd->parent_obj;
1781 elm_widget_focused_object_clear(Evas_Object *obj)
1784 if (!sd->focused) return;
1785 if (elm_widget_focus_get(sd->resize_obj))
1786 elm_widget_focused_object_clear(sd->resize_obj);
1791 EINA_LIST_FOREACH(sd->subobjs, l, child)
1793 if (elm_widget_focus_get(child))
1795 elm_widget_focused_object_clear(child);
1800 sd->focused = EINA_FALSE;
1801 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1802 if (sd->focus_func) sd->focus_func(obj);
1806 elm_widget_focus_steal(Evas_Object *obj)
1808 Evas_Object *parent, *o;
1811 if (sd->focused) return;
1812 if (sd->disabled) return;
1813 if (!sd->can_focus) return;
1814 if (sd->tree_unfocusable) return;
1818 o = elm_widget_parent_get(parent);
1820 sd = evas_object_smart_data_get(o);
1821 if (sd->disabled || sd->tree_unfocusable) return;
1822 if (sd->focused) break;
1825 if (!elm_widget_parent_get(parent))
1826 elm_widget_focused_object_clear(parent);
1829 parent = elm_widget_parent_get(parent);
1830 sd = evas_object_smart_data_get(parent);
1831 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1832 elm_widget_focused_object_clear(sd->resize_obj);
1837 EINA_LIST_FOREACH(sd->subobjs, l, child)
1839 if (elm_widget_focus_get(child))
1841 elm_widget_focused_object_clear(child);
1852 elm_widget_focus_restore(Evas_Object *obj)
1854 Evas_Object *newest = NULL;
1855 unsigned int newest_focus_order = 0;
1858 newest = _newest_focus_order_get(obj, &newest_focus_order, EINA_TRUE);
1861 elm_object_unfocus(newest);
1862 elm_object_focus(newest);
1867 _elm_widget_top_win_focused_set(Evas_Object *obj, Eina_Bool top_win_focused)
1873 if (sd->top_win_focused == top_win_focused) return;
1875 _elm_widget_top_win_focused_set(sd->resize_obj, top_win_focused);
1876 EINA_LIST_FOREACH(sd->subobjs, l, child)
1878 _elm_widget_top_win_focused_set(child, top_win_focused);
1880 sd->top_win_focused = top_win_focused;
1884 _elm_widget_top_win_focused_get(const Evas_Object *obj)
1886 API_ENTRY return EINA_FALSE;
1887 return sd->top_win_focused;
1891 elm_widget_activate(Evas_Object *obj)
1894 elm_widget_change(obj);
1895 if (sd->activate_func) sd->activate_func(obj);
1899 elm_widget_change(Evas_Object *obj)
1902 elm_widget_change(elm_widget_parent_get(obj));
1903 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1907 elm_widget_disabled_set(Evas_Object *obj,
1912 if (sd->disabled == disabled) return;
1913 sd->disabled = !!disabled;
1914 elm_widget_focus_disabled_handle(obj);
1915 if (sd->disable_func) sd->disable_func(obj);
1919 elm_widget_disabled_get(const Evas_Object *obj)
1922 return sd->disabled;
1926 elm_widget_show_region_set(Evas_Object *obj,
1931 Eina_Bool forceshow)
1933 Evas_Object *parent_obj, *child_obj;
1934 Evas_Coord px, py, cx, cy;
1937 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1938 && (w == sd->rw) && (h == sd->rh)) return;
1943 if (sd->on_show_region_func)
1944 sd->on_show_region_func(sd->on_show_region_data, obj);
1948 parent_obj = sd->parent_obj;
1949 child_obj = sd->obj;
1950 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1951 sd = evas_object_smart_data_get(parent_obj);
1954 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1955 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1964 if (sd->on_show_region_func)
1966 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1973 elm_widget_show_region_get(const Evas_Object *obj,
1989 * Get the focus region of the given widget.
1991 * The focus region is the area of a widget that should brought into the
1992 * visible area when the widget is focused. Mostly used to show the part of
1993 * an entry where the cursor is, for example. The area returned is relative
1994 * to the object @p obj.
1995 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1996 * function will return the full size of the object.
1998 * @param obj The widget object
1999 * @param x Where to store the x coordinate of the area
2000 * @param y Where to store the y coordinate of the area
2001 * @param w Where to store the width of the area
2002 * @param h Where to store the height of the area
2007 elm_widget_focus_region_get(const Evas_Object *obj,
2017 sd = evas_object_smart_data_get(obj);
2018 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
2020 evas_object_geometry_get(obj, NULL, NULL, w, h);
2025 sd->on_focus_region_func(obj, x, y, w, h);
2029 elm_widget_scroll_hold_push(Evas_Object *obj)
2033 if (sd->scroll_hold == 1)
2034 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
2035 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
2036 // FIXME: on delete/reparent hold pop
2040 elm_widget_scroll_hold_pop(Evas_Object *obj)
2044 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
2045 if (!sd->scroll_hold)
2046 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
2047 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
2051 elm_widget_scroll_hold_get(const Evas_Object *obj)
2054 return sd->scroll_hold;
2058 elm_widget_scroll_freeze_push(Evas_Object *obj)
2061 sd->scroll_freeze++;
2062 if (sd->scroll_freeze == 1)
2063 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
2064 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
2065 // FIXME: on delete/reparent freeze pop
2069 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2072 sd->scroll_freeze--;
2073 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2074 if (!sd->scroll_freeze)
2075 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2076 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2080 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2083 return sd->scroll_freeze;
2087 elm_widget_scale_set(Evas_Object *obj,
2091 if (scale <= 0.0) scale = 0.0;
2092 if (sd->scale != scale)
2095 elm_widget_theme(obj);
2100 elm_widget_scale_get(const Evas_Object *obj)
2102 API_ENTRY return 1.0;
2103 // FIXME: save walking up the tree by storing/caching parent scale
2104 if (sd->scale == 0.0)
2107 return elm_widget_scale_get(sd->parent_obj);
2115 elm_widget_theme_set(Evas_Object *obj,
2119 if (sd->theme != th)
2121 if (sd->theme) elm_theme_free(sd->theme);
2124 elm_widget_theme(obj);
2129 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2133 if (!sd->on_text_set_func)
2136 sd->on_text_set_func(obj, item, label);
2140 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2142 API_ENTRY return NULL;
2144 if (!sd->on_text_get_func)
2147 return sd->on_text_get_func(obj, item);
2151 elm_widget_theme_get(const Evas_Object *obj)
2153 API_ENTRY return NULL;
2157 return elm_widget_theme_get(sd->parent_obj);
2165 elm_widget_style_set(Evas_Object *obj,
2170 if (eina_stringshare_replace(&sd->style, style))
2171 elm_widget_theme(obj);
2175 elm_widget_style_get(const Evas_Object *obj)
2177 API_ENTRY return NULL;
2178 if (sd->style) return sd->style;
2183 elm_widget_type_set(Evas_Object *obj,
2187 eina_stringshare_replace(&sd->type, type);
2191 elm_widget_type_get(const Evas_Object *obj)
2193 API_ENTRY return NULL;
2194 if (sd->type) return sd->type;
2199 elm_widget_tooltip_add(Evas_Object *obj,
2203 sd->tooltips = eina_list_append(sd->tooltips, tt);
2207 elm_widget_tooltip_del(Evas_Object *obj,
2211 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2215 elm_widget_cursor_add(Evas_Object *obj,
2219 sd->cursors = eina_list_append(sd->cursors, cur);
2223 elm_widget_cursor_del(Evas_Object *obj,
2227 sd->cursors = eina_list_remove(sd->cursors, cur);
2231 elm_widget_drag_lock_x_set(Evas_Object *obj,
2235 if (sd->drag_x_locked == lock) return;
2236 sd->drag_x_locked = lock;
2237 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2238 else _propagate_x_drag_lock(obj, -1);
2242 elm_widget_drag_lock_y_set(Evas_Object *obj,
2246 if (sd->drag_y_locked == lock) return;
2247 sd->drag_y_locked = lock;
2248 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2249 else _propagate_y_drag_lock(obj, -1);
2253 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2255 API_ENTRY return EINA_FALSE;
2256 return sd->drag_x_locked;
2260 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2262 API_ENTRY return EINA_FALSE;
2263 return sd->drag_y_locked;
2267 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2270 return sd->child_drag_x_locked;
2274 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2277 return sd->child_drag_y_locked;
2281 elm_widget_theme_object_set(Evas_Object *obj,
2284 const char *welement,
2287 API_ENTRY return EINA_FALSE;
2288 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2292 elm_widget_type_check(const Evas_Object *obj,
2295 const char *provided, *expected = "(unknown)";
2296 static int abort_on_warn = -1;
2297 provided = elm_widget_type_get(obj);
2298 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2299 if (type) expected = type;
2300 if ((!provided) || (!provided[0]))
2302 provided = evas_object_type_get(obj);
2303 if ((!provided) || (!provided[0]))
2304 provided = "(unknown)";
2306 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2307 if (abort_on_warn == -1)
2309 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2310 else abort_on_warn = 0;
2312 if (abort_on_warn == 1) abort();
2319 * Split string in words
2321 * @param str Source string
2322 * @return List of const words
2324 * @see elm_widget_stringlist_free()
2328 elm_widget_stringlist_get(const char *str)
2330 Eina_List *list = NULL;
2332 if (!str) return NULL;
2333 for (b = s = str; 1; s++)
2335 if ((*s == ' ') || (!*s))
2337 char *t = malloc(s - b + 1);
2340 strncpy(t, b, s - b);
2342 list = eina_list_append(list, eina_stringshare_add(t));
2353 elm_widget_stringlist_free(Eina_List *list)
2356 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2360 elm_widget_focus_hide_handle(Evas_Object *obj)
2362 _if_focused_revert(obj, EINA_TRUE);
2366 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2368 Evas_Object *o = obj;
2371 if (_elm_widget_is(o)) break;
2372 o = evas_object_smart_parent_get(o);
2376 if (!_is_focusable(o)) return;
2377 elm_widget_focus_steal(o);
2381 elm_widget_focus_tree_unfocusable_handle(Evas_Object *obj)
2385 if (!elm_widget_parent_get(obj))
2386 elm_widget_focused_object_clear(obj);
2388 _if_focused_revert(obj, EINA_TRUE);
2392 elm_widget_focus_disabled_handle(Evas_Object *obj)
2396 elm_widget_focus_tree_unfocusable_handle(obj);
2402 * Allocate a new Elm_Widget_Item-derived structure.
2404 * The goal of this structure is to provide common ground for actions
2405 * that a widget item have, such as the owner widget, callback to
2406 * notify deletion, data pointer and maybe more.
2408 * @param widget the owner widget that holds this item, must be an elm_widget!
2409 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2410 * be used to allocate memory.
2412 * @return allocated memory that is already zeroed out, or NULL on errors.
2414 * @see elm_widget_item_new() convenience macro.
2415 * @see elm_widget_item_del() to release memory.
2418 EAPI Elm_Widget_Item *
2419 _elm_widget_item_new(Evas_Object *widget,
2422 if (!_elm_widget_is(widget))
2425 Elm_Widget_Item *item;
2427 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2428 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2430 item = calloc(1, alloc_size);
2431 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2433 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2434 item->widget = widget;
2441 * Releases widget item memory, calling back del_cb() if it exists.
2443 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2444 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2445 * this function and then unset it, thus being useful for 2 step
2446 * cleanup whenever the del_cb may use any of the data that must be
2447 * deleted from item.
2449 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2452 * @param item a valid #Elm_Widget_Item to be deleted.
2453 * @see elm_widget_item_del() convenience macro.
2457 _elm_widget_item_del(Elm_Widget_Item *item)
2459 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2462 item->del_cb((void *)item->data, item->widget, item);
2465 evas_object_del(item->view);
2467 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2474 * Notify object will be deleted without actually deleting it.
2476 * This function will callback Elm_Widget_Item::del_cb if it is set
2477 * and then unset it so it is not called twice (ie: from
2478 * elm_widget_item_del()).
2480 * @param item a valid #Elm_Widget_Item to be notified
2481 * @see elm_widget_item_pre_notify_del() convenience macro.
2485 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2487 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2488 if (!item->del_cb) return;
2489 item->del_cb((void *)item->data, item->widget, item);
2490 item->del_cb = NULL;
2496 * Set the function to notify when item is being deleted.
2498 * This function will complain if there was a callback set already,
2499 * however it will set the new one.
2501 * The callback will be called from elm_widget_item_pre_notify_del()
2502 * or elm_widget_item_del() will be called with:
2503 * - data: the Elm_Widget_Item::data value.
2504 * - obj: the Elm_Widget_Item::widget evas object.
2505 * - event_info: the item being deleted.
2507 * @param item a valid #Elm_Widget_Item to be notified
2508 * @see elm_widget_item_del_cb_set() convenience macro.
2512 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2513 Evas_Smart_Cb del_cb)
2515 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2517 if ((item->del_cb) && (item->del_cb != del_cb))
2518 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2519 item->del_cb, item, del_cb);
2521 item->del_cb = del_cb;
2527 * Set user-data in this item.
2529 * User data may be used to identify this item or just store any
2530 * application data. It is automatically given as the first parameter
2531 * of the deletion notify callback.
2533 * @param item a valid #Elm_Widget_Item to store data in.
2534 * @param data user data to store.
2535 * @see elm_widget_item_del_cb_set() convenience macro.
2539 _elm_widget_item_data_set(Elm_Widget_Item *item,
2542 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2543 if ((item->data) && (item->data != data))
2544 DBG("Replacing item %p data %p with %p", item, item->data, data);
2551 * Retrieves user-data of this item.
2553 * @param item a valid #Elm_Widget_Item to get data from.
2554 * @see elm_widget_item_data_set()
2558 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2560 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2561 return (void *)item->data;
2564 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2566 struct _Elm_Widget_Item_Tooltip
2568 Elm_Widget_Item *item;
2569 Elm_Tooltip_Item_Content_Cb func;
2570 Evas_Smart_Cb del_cb;
2574 static Evas_Object *
2575 _elm_widget_item_tooltip_label_create(void *data,
2577 void *item __UNUSED__)
2579 Evas_Object *label = elm_label_add(obj);
2582 elm_object_style_set(label, "tooltip");
2583 elm_object_text_set(label, data);
2588 _elm_widget_item_tooltip_label_del_cb(void *data,
2589 Evas_Object *obj __UNUSED__,
2590 void *event_info __UNUSED__)
2592 eina_stringshare_del(data);
2598 * Set the text to be shown in the widget item.
2600 * @param item Target item
2601 * @param text The text to set in the content
2603 * Setup the text as tooltip to object. The item can have only one tooltip,
2604 * so any previous tooltip data is removed.
2609 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2612 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2613 EINA_SAFETY_ON_NULL_RETURN(text);
2615 text = eina_stringshare_add(text);
2616 _elm_widget_item_tooltip_content_cb_set
2617 (item, _elm_widget_item_tooltip_label_create, text,
2618 _elm_widget_item_tooltip_label_del_cb);
2621 static Evas_Object *
2622 _elm_widget_item_tooltip_create(void *data,
2625 Elm_Widget_Item_Tooltip *wit = data;
2626 return wit->func((void *)wit->data, obj, wit->item);
2630 _elm_widget_item_tooltip_del_cb(void *data,
2632 void *event_info __UNUSED__)
2634 Elm_Widget_Item_Tooltip *wit = data;
2635 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2642 * Set the content to be shown in the tooltip item
2644 * Setup the tooltip to item. The item can have only one tooltip,
2645 * so any previous tooltip data is removed. @p func(with @p data) will
2646 * be called every time that need show the tooltip and it should
2647 * return a valid Evas_Object. This object is then managed fully by
2648 * tooltip system and is deleted when the tooltip is gone.
2650 * @param item the widget item being attached a tooltip.
2651 * @param func the function used to create the tooltip contents.
2652 * @param data what to provide to @a func as callback data/context.
2653 * @param del_cb called when data is not needed anymore, either when
2654 * another callback replaces @func, the tooltip is unset with
2655 * elm_widget_item_tooltip_unset() or the owner @a item
2656 * dies. This callback receives as the first parameter the
2657 * given @a data, and @c event_info is the item.
2662 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2663 Elm_Tooltip_Item_Content_Cb func,
2665 Evas_Smart_Cb del_cb)
2667 Elm_Widget_Item_Tooltip *wit;
2669 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2673 _elm_widget_item_tooltip_unset(item);
2677 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2678 if (!wit) goto error;
2682 wit->del_cb = del_cb;
2684 elm_object_sub_tooltip_content_cb_set
2685 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2686 _elm_widget_item_tooltip_del_cb);
2691 if (del_cb) del_cb((void *)data, NULL, item);
2694 if (del_cb) del_cb((void *)data, item->widget, item);
2700 * Unset tooltip from item
2702 * @param item widget item to remove previously set tooltip.
2704 * Remove tooltip from item. The callback provided as del_cb to
2705 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2706 * it is not used anymore.
2708 * @see elm_widget_item_tooltip_content_cb_set()
2713 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2715 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2716 elm_object_tooltip_unset(item->view);
2722 * Sets a different style for this item tooltip.
2724 * @note before you set a style you should define a tooltip with
2725 * elm_widget_item_tooltip_content_cb_set() or
2726 * elm_widget_item_tooltip_text_set()
2728 * @param item widget item with tooltip already set.
2729 * @param style the theme style to use (default, transparent, ...)
2734 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2737 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2738 elm_object_tooltip_style_set(item->view, style);
2744 * Get the style for this item tooltip.
2746 * @param item widget item with tooltip already set.
2747 * @return style the theme style in use, defaults to "default". If the
2748 * object does not have a tooltip set, then NULL is returned.
2753 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2755 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2756 return elm_object_tooltip_style_get(item->view);
2760 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2763 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2764 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2768 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2770 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2771 return elm_object_cursor_get(item->view);
2775 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2777 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2778 elm_object_cursor_unset(item->view);
2784 * Sets a different style for this item cursor.
2786 * @note before you set a style you should define a cursor with
2787 * elm_widget_item_cursor_set()
2789 * @param item widget item with cursor already set.
2790 * @param style the theme style to use (default, transparent, ...)
2795 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2798 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2799 elm_object_cursor_style_set(item->view, style);
2805 * Get the style for this item cursor.
2807 * @param item widget item with cursor already set.
2808 * @return style the theme style in use, defaults to "default". If the
2809 * object does not have a cursor set, then NULL is returned.
2814 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2816 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2817 return elm_object_cursor_style_get(item->view);
2823 * Set if the cursor set should be searched on the theme or should use
2824 * the provided by the engine, only.
2826 * @note before you set if should look on theme you should define a cursor
2827 * with elm_object_cursor_set(). By default it will only look for cursors
2828 * provided by the engine.
2830 * @param item widget item with cursor already set.
2831 * @param engine_only boolean to define it cursors should be looked only
2832 * between the provided by the engine or searched on widget's theme as well.
2837 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2838 Eina_Bool engine_only)
2840 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2841 elm_object_cursor_engine_only_set(item->view, engine_only);
2847 * Get the cursor engine only usage for this item cursor.
2849 * @param item widget item with cursor already set.
2850 * @return engine_only boolean to define it cursors should be looked only
2851 * between the provided by the engine or searched on widget's theme as well. If
2852 * the object does not have a cursor set, then EINA_FALSE is returned.
2857 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2859 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2860 return elm_object_cursor_engine_only_get(item->view);
2863 // smart object funcs
2865 _smart_reconfigure(Smart_Data *sd)
2869 evas_object_move(sd->resize_obj, sd->x, sd->y);
2870 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2874 evas_object_move(sd->hover_obj, sd->x, sd->y);
2875 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2880 _smart_add(Evas_Object *obj)
2884 sd = calloc(1, sizeof(Smart_Data));
2887 sd->x = sd->y = sd->w = sd->h = 0;
2889 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2890 evas_object_smart_data_set(obj, sd);
2893 static Evas_Object *
2894 _newest_focus_order_get(Evas_Object *obj,
2895 unsigned int *newest_focus_order,
2896 Eina_Bool can_focus_only)
2899 Evas_Object *child, *ret, *best;
2901 API_ENTRY return NULL;
2903 if (!evas_object_visible_get(obj)
2904 || (elm_widget_disabled_get(obj))
2905 || (elm_widget_tree_unfocusable_get(obj)))
2909 if (*newest_focus_order < sd->focus_order)
2911 *newest_focus_order = sd->focus_order;
2914 EINA_LIST_FOREACH(sd->subobjs, l, child)
2916 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2922 if ((!best) || (!elm_widget_can_focus_get(best)))
2929 _if_focused_revert(Evas_Object *obj,
2930 Eina_Bool can_focus_only)
2933 Evas_Object *newest = NULL;
2934 unsigned int newest_focus_order = 0;
2938 if (!sd->focused) return;
2939 if (!sd->parent_obj) return;
2941 top = elm_widget_top_get(sd->parent_obj);
2944 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2947 elm_object_unfocus(newest);
2948 elm_object_focus(newest);
2954 _smart_del(Evas_Object *obj)
2957 Edje_Signal_Data *esd;
2961 if (sd->del_pre_func) sd->del_pre_func(obj);
2964 sobj = sd->resize_obj;
2965 sd->resize_obj = NULL;
2966 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2967 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2968 evas_object_del(sobj);
2972 sobj = sd->hover_obj;
2973 sd->hover_obj = NULL;
2974 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2975 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2976 evas_object_del(sobj);
2978 EINA_LIST_FREE(sd->subobjs, sobj)
2980 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2981 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2982 evas_object_del(sobj);
2984 eina_list_free(sd->tooltips); /* should be empty anyway */
2985 eina_list_free(sd->cursors); /* should be empty anyway */
2986 EINA_LIST_FREE(sd->edje_signals, esd)
2988 eina_stringshare_del(esd->emission);
2989 eina_stringshare_del(esd->source);
2992 eina_list_free(sd->event_cb); /* should be empty anyway */
2993 if (sd->del_func) sd->del_func(obj);
2994 if (sd->style) eina_stringshare_del(sd->style);
2995 if (sd->type) eina_stringshare_del(sd->type);
2996 if (sd->theme) elm_theme_free(sd->theme);
2997 _if_focused_revert(obj, EINA_TRUE);
3002 _smart_move(Evas_Object *obj,
3009 _smart_reconfigure(sd);
3013 _smart_resize(Evas_Object *obj,
3020 _smart_reconfigure(sd);
3024 _smart_show(Evas_Object *obj)
3029 if ((list = evas_object_smart_members_get(obj)))
3031 EINA_LIST_FREE(list, o)
3033 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3034 evas_object_show(o);
3040 _smart_hide(Evas_Object *obj)
3046 list = evas_object_smart_members_get(obj);
3047 EINA_LIST_FREE(list, o)
3049 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3050 evas_object_hide(o);
3055 _smart_color_set(Evas_Object *obj,
3064 if ((list = evas_object_smart_members_get(obj)))
3066 EINA_LIST_FREE(list, o)
3068 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3069 evas_object_color_set(o, r, g, b, a);
3075 _smart_clip_set(Evas_Object *obj,
3081 if ((list = evas_object_smart_members_get(obj)))
3083 EINA_LIST_FREE(list, o)
3085 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3086 evas_object_clip_set(o, clip);
3092 _smart_clip_unset(Evas_Object *obj)
3097 if ((list = evas_object_smart_members_get(obj)))
3099 EINA_LIST_FREE(list, o)
3101 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3102 evas_object_clip_unset(o);
3108 _smart_calculate(Evas_Object *obj)
3111 if (sd->changed_func) sd->changed_func(obj);
3114 /* never need to touch this */
3118 if (_e_smart) return;
3120 static const Evas_Smart_Class sc =
3123 EVAS_SMART_CLASS_VERSION,
3141 _e_smart = evas_smart_class_new(&sc);
3145 /* happy debug functions */
3148 _sub_obj_tree_dump(const Evas_Object *obj,
3153 for (i = 0; i < lvl * 3; i++)
3156 if (_elm_widget_is(obj))
3160 printf("+ %s(%p)\n",
3164 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3165 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3167 if (obj != sd->resize_obj)
3168 _sub_obj_tree_dump(obj, lvl + 1);
3172 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3176 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3179 if (!_elm_widget_is(obj))
3183 Eina_Bool visible = evas_object_visible_get(obj);
3184 Eina_Bool disabled = elm_widget_disabled_get(obj);
3185 Eina_Bool focused = elm_widget_focus_get(obj);
3186 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3190 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3193 fprintf(output, ", style=bold");
3196 fprintf(output, ", color=gray28");
3198 fprintf(output, " ];\n");
3201 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3202 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3203 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3207 fprintf(output, ", style=bold");
3210 fprintf(output, ", fontcolor=gray28");
3212 if ((disabled) || (!visible))
3213 fprintf(output, ", color=gray");
3215 fprintf(output, " ];\n");
3219 EINA_LIST_FOREACH(sd->subobjs, l, o)
3220 _sub_obj_tree_dot_dump(o, output);
3225 elm_widget_tree_dump(const Evas_Object *top)
3228 _sub_obj_tree_dump(top, 0);
3236 elm_widget_tree_dot_dump(const Evas_Object *top,
3240 if (!_elm_widget_is(top))
3242 fprintf(output, "graph " " { node [shape=record];\n");
3243 _sub_obj_tree_dot_dump(top, output);
3244 fprintf(output, "}\n");