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,
78 void (*on_content_set_func)(Evas_Object *obj,
80 Evas_Object *content);
81 Evas_Object *(*on_content_get_func)(const Evas_Object *obj,
83 Evas_Object *(*on_content_unset_func)(Evas_Object *obj,
86 Evas_Coord rx, ry, rw, rh;
92 unsigned int focus_order;
93 Eina_Bool focus_order_on_calc;
95 int child_drag_x_locked;
96 int child_drag_y_locked;
98 Eina_List *edje_signals;
100 Eina_Bool drag_x_locked : 1;
101 Eina_Bool drag_y_locked : 1;
103 Eina_Bool can_focus : 1;
104 Eina_Bool child_can_focus : 1;
105 Eina_Bool focused : 1;
106 Eina_Bool highlight_ignore : 1;
107 Eina_Bool highlight_in_theme : 1;
108 Eina_Bool disabled : 1;
109 Eina_Bool is_mirrored : 1;
110 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
112 Eina_List *focus_chain;
116 struct _Edje_Signal_Data
120 const char *emission;
125 struct _Elm_Event_Cb_Data
131 /* local subsystem functions */
132 static void _smart_reconfigure(Smart_Data *sd);
133 static void _smart_add(Evas_Object *obj);
134 static void _smart_del(Evas_Object *obj);
135 static void _smart_move(Evas_Object *obj,
138 static void _smart_resize(Evas_Object *obj,
141 static void _smart_show(Evas_Object *obj);
142 static void _smart_hide(Evas_Object *obj);
143 static void _smart_color_set(Evas_Object *obj,
148 static void _smart_clip_set(Evas_Object *obj,
150 static void _smart_clip_unset(Evas_Object *obj);
151 static void _smart_calculate(Evas_Object *obj);
152 static void _smart_init(void);
154 static void _if_focused_revert(Evas_Object *obj,
155 Eina_Bool can_focus_only);
156 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
157 unsigned int *newest_focus_order,
158 Eina_Bool can_focus_only);
160 /* local subsystem globals */
161 static Evas_Smart *_e_smart = NULL;
162 static Eina_List *widtypes = NULL;
164 static unsigned int focus_order = 0;
167 static inline Eina_Bool
168 _elm_widget_is(const Evas_Object *obj)
170 const char *type = evas_object_type_get(obj);
171 return type == SMART_NAME;
174 static inline Eina_Bool
175 _is_focusable(Evas_Object *obj)
177 API_ENTRY return EINA_FALSE;
178 return sd->can_focus || (sd->child_can_focus);
182 _unfocus_parents(Evas_Object *obj)
184 for (; obj; obj = elm_widget_parent_get(obj))
187 if (!sd->focused) return;
193 _focus_parents(Evas_Object *obj)
195 for (; obj; obj = elm_widget_parent_get(obj))
198 if (sd->focused) return;
204 _sub_obj_del(void *data,
207 void *event_info __UNUSED__)
209 Smart_Data *sd = data;
211 if (_elm_widget_is(obj))
213 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
215 if (obj == sd->resize_obj)
216 sd->resize_obj = NULL;
217 else if (obj == sd->hover_obj)
218 sd->hover_obj = NULL;
220 sd->subobjs = eina_list_remove(sd->subobjs, obj);
221 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
225 _sub_obj_hide(void *data __UNUSED__,
228 void *event_info __UNUSED__)
230 elm_widget_focus_hide_handle(obj);
234 _sub_obj_mouse_down(void *data __UNUSED__,
237 void *event_info __UNUSED__)
239 elm_widget_focus_mouse_down_handle(obj);
243 _propagate_x_drag_lock(Evas_Object *obj,
249 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
252 sd2->child_drag_x_locked += dir;
253 _propagate_x_drag_lock(sd->parent_obj, dir);
259 _propagate_y_drag_lock(Evas_Object *obj,
265 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
268 sd2->child_drag_y_locked += dir;
269 _propagate_y_drag_lock(sd->parent_obj, dir);
275 _propagate_event(void *data,
281 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
282 Evas_Event_Flags *event_flags = NULL;
286 case EVAS_CALLBACK_KEY_DOWN:
288 Evas_Event_Key_Down *ev = event_info;
289 event_flags = &(ev->event_flags);
293 case EVAS_CALLBACK_KEY_UP:
295 Evas_Event_Key_Up *ev = event_info;
296 event_flags = &(ev->event_flags);
300 case EVAS_CALLBACK_MOUSE_WHEEL:
302 Evas_Event_Mouse_Wheel *ev = event_info;
303 event_flags = &(ev->event_flags);
311 elm_widget_event_propagate(obj, type, event_info, event_flags);
315 _parent_focus(Evas_Object *obj)
318 if (sd->focused) return;
320 Evas_Object *o = elm_widget_parent_get(obj);
321 sd->focus_order_on_calc = EINA_TRUE;
323 if (o) _parent_focus(o);
325 if (!sd->focus_order_on_calc)
326 return; /* we don't want to override it if by means of any of the
327 callbacks below one gets to calculate our order
331 sd->focus_order = focus_order;
332 sd->focused = EINA_TRUE;
333 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
334 if (sd->focus_func) sd->focus_func(obj);
336 _elm_widget_focus_region_show(obj);
338 sd->focus_order_on_calc = EINA_FALSE;
342 _elm_object_focus_chain_del_cb(void *data,
345 void *event_info __UNUSED__)
347 Smart_Data *sd = data;
349 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
352 // exposed util funcs to elm
354 _elm_widget_type_clear(void)
358 EINA_LIST_FREE(widtypes, ptr)
360 eina_stringshare_del(*ptr);
366 _elm_widget_focus_region_show(const Evas_Object *obj)
368 Evas_Coord x, y, w, h, ox, oy;
374 o = elm_widget_parent_get(obj);
377 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
378 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
382 sd2 = evas_object_smart_data_get(o);
383 if (sd2->focus_region_func)
385 sd2->focus_region_func(o, x, y, w, h);
386 elm_widget_focus_region_get(o, &x, &y, &w, &h);
390 evas_object_geometry_get(o, &px, &py, NULL, NULL);
396 o = elm_widget_parent_get(o);
401 * @defgroup Widget Widget
404 * Exposed api for making widgets
407 elm_widget_type_register(const char **ptr)
409 widtypes = eina_list_append(widtypes, (void *)ptr);
413 elm_widget_api_check(int ver)
415 if (ver != ELM_INTERNAL_API_VERSION)
417 CRITICAL("Elementary widget api versions do not match");
424 elm_widget_add(Evas *evas)
428 obj = evas_object_smart_add(evas, _e_smart);
429 elm_widget_mirrored_set(obj, elm_mirrored_get());
434 elm_widget_del_hook_set(Evas_Object *obj,
435 void (*func)(Evas_Object *obj))
442 elm_widget_del_pre_hook_set(Evas_Object *obj,
443 void (*func)(Evas_Object *obj))
446 sd->del_pre_func = func;
450 elm_widget_focus_hook_set(Evas_Object *obj,
451 void (*func)(Evas_Object *obj))
454 sd->focus_func = func;
458 elm_widget_activate_hook_set(Evas_Object *obj,
459 void (*func)(Evas_Object *obj))
462 sd->activate_func = func;
466 elm_widget_disable_hook_set(Evas_Object *obj,
467 void (*func)(Evas_Object *obj))
470 sd->disable_func = func;
474 elm_widget_theme_hook_set(Evas_Object *obj,
475 void (*func)(Evas_Object *obj))
478 sd->theme_func = func;
482 elm_widget_event_hook_set(Evas_Object *obj,
483 Eina_Bool (*func)(Evas_Object *obj,
485 Evas_Callback_Type type,
489 sd->event_func = func;
493 elm_widget_text_set_hook_set(Evas_Object *obj,
494 void (*func)(Evas_Object *obj,
499 sd->on_text_set_func = func;
503 elm_widget_text_get_hook_set(Evas_Object *obj,
504 const char *(*func)(const Evas_Object *obj,
508 sd->on_text_get_func = func;
512 elm_widget_content_set_hook_set(Evas_Object *obj,
513 void (*func)(Evas_Object *obj,
515 Evas_Object *content))
518 sd->on_content_set_func = func;
522 elm_widget_content_get_hook_set(Evas_Object *obj,
523 Evas_Object *(*func)(const Evas_Object *obj, const char *item))
526 sd->on_content_get_func = func;
530 elm_widget_content_unset_hook_set(Evas_Object *obj,
531 Evas_Object *(*func)(Evas_Object *obj,
535 sd->on_content_unset_func = func;
539 elm_widget_changed_hook_set(Evas_Object *obj,
540 void (*func)(Evas_Object *obj))
543 sd->changed_func = func;
547 elm_widget_signal_emit_hook_set(Evas_Object *obj,
548 void (*func)(Evas_Object *obj,
549 const char *emission,
553 sd->signal_func = func;
557 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
558 void (*func)(Evas_Object *obj,
559 const char *emission,
561 Edje_Signal_Cb func_cb,
565 sd->callback_add_func = func;
569 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
570 void (*func)(Evas_Object *obj,
571 const char *emission,
573 Edje_Signal_Cb func_cb,
577 sd->callback_del_func = func;
581 elm_widget_theme(Evas_Object *obj)
589 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
590 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
591 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
592 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
593 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
594 if (sd->theme_func) sd->theme_func(obj);
598 elm_widget_theme_specific(Evas_Object *obj,
606 Elm_Theme *th2, *thdef;
609 thdef = elm_theme_default_get();
614 if (!th2) th2 = thdef;
622 if (th2 == thdef) break;
623 th2 = th2->ref_theme;
624 if (!th2) th2 = thdef;
628 EINA_LIST_FOREACH(sd->subobjs, l, child)
629 elm_widget_theme_specific(child, th, force);
630 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
631 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
632 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
633 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
634 if (sd->theme_func) sd->theme_func(obj);
640 * Set hook to get next object in object focus chain.
642 * @param obj The widget object.
643 * @param func The hook to be used with this widget.
648 elm_widget_focus_next_hook_set(Evas_Object *obj,
649 Eina_Bool (*func)(const Evas_Object *obj,
650 Elm_Focus_Direction dir,
654 sd->focus_next_func = func;
658 * Returns the widget's mirrored mode.
660 * @param obj The widget.
661 * @return mirrored mode of the object.
665 elm_widget_mirrored_get(const Evas_Object *obj)
667 API_ENTRY return EINA_FALSE;
668 return sd->is_mirrored;
672 * Sets the widget's mirrored mode.
674 * @param obj The widget.
675 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
678 elm_widget_mirrored_set(Evas_Object *obj,
682 if (sd->is_mirrored != mirrored)
684 sd->is_mirrored = mirrored;
685 elm_widget_theme(obj);
691 * Resets the mirrored mode from the system mirror mode for widgets that are in
692 * automatic mirroring mode. This function does not call elm_widget_theme.
694 * @param obj The widget.
695 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
698 _elm_widget_mirrored_reload(Evas_Object *obj)
701 Eina_Bool mirrored = elm_mirrored_get();
702 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
704 sd->is_mirrored = mirrored;
709 * Returns the widget's mirrored mode setting.
711 * @param obj The widget.
712 * @return mirrored mode setting of the object.
716 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
718 API_ENTRY return EINA_FALSE;
719 return sd->mirrored_auto_mode;
723 * Sets the widget's mirrored mode setting.
724 * When widget in automatic mode, it follows the system mirrored mode set by
725 * elm_mirrored_set().
726 * @param obj The widget.
727 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
730 elm_widget_mirrored_automatic_set(Evas_Object *obj,
734 if (sd->mirrored_auto_mode != automatic)
736 sd->mirrored_auto_mode = automatic;
740 elm_widget_mirrored_set(obj, elm_mirrored_get());
746 elm_widget_on_focus_hook_set(Evas_Object *obj,
747 void (*func)(void *data,
752 sd->on_focus_func = func;
753 sd->on_focus_data = data;
757 elm_widget_on_change_hook_set(Evas_Object *obj,
758 void (*func)(void *data,
763 sd->on_change_func = func;
764 sd->on_change_data = data;
768 elm_widget_on_show_region_hook_set(Evas_Object *obj,
769 void (*func)(void *data,
774 sd->on_show_region_func = func;
775 sd->on_show_region_data = data;
781 * Set the hook to use to show the focused region.
783 * Whenever a new widget gets focused or it's needed to show the focused
784 * area of the current one, this hook will be called on objects that may
785 * want to move their children into their visible area.
786 * The area given in the hook function is relative to the @p obj widget.
788 * @param obj The widget object
789 * @param func The function to call to show the specified area.
794 elm_widget_focus_region_hook_set(Evas_Object *obj,
795 void (*func)(Evas_Object *obj,
802 sd->focus_region_func = func;
808 * Set the hook to retrieve the focused region of a widget.
810 * This hook will be called by elm_widget_focus_region_get() whenever
811 * it's needed to get the focused area of a widget. The area must be relative
812 * to the widget itself and if no hook is set, it will default to the entire
815 * @param obj The widget object
816 * @param func The function used to retrieve the focus region.
821 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
822 void (*func)(const Evas_Object *obj,
829 sd->on_focus_region_func = func;
833 elm_widget_data_set(Evas_Object *obj,
841 elm_widget_data_get(const Evas_Object *obj)
843 API_ENTRY return NULL;
848 elm_widget_sub_object_add(Evas_Object *obj,
852 double scale, pscale = elm_widget_scale_get(sobj);
853 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
854 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
856 if (_elm_widget_is(sobj))
858 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
861 if (sd2->parent_obj == obj)
864 elm_widget_sub_object_del(sd2->parent_obj, sobj);
865 sd2->parent_obj = obj;
866 if (!sd->child_can_focus && (_is_focusable(sobj)))
867 sd->child_can_focus = EINA_TRUE;
872 void *data = evas_object_data_get(sobj, "elm-parent");
875 if (data == obj) return;
876 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
881 sd->subobjs = eina_list_append(sd->subobjs, sobj);
882 evas_object_data_set(sobj, "elm-parent", obj);
883 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
884 if (_elm_widget_is(sobj))
885 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
886 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
887 scale = elm_widget_scale_get(sobj);
888 th = elm_widget_theme_get(sobj);
889 mirrored = elm_widget_mirrored_get(sobj);
890 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
891 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
895 elm_widget_sub_object_del(Evas_Object *obj,
898 Evas_Object *sobj_parent;
902 sobj_parent = evas_object_data_del(sobj, "elm-parent");
903 if (sobj_parent != obj)
905 static int abort_on_warn = -1;
906 ERR("removing sub object %p from parent %p, "
907 "but elm-parent is different %p!",
908 sobj, obj, sobj_parent);
909 if (EINA_UNLIKELY(abort_on_warn == -1))
911 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
912 else abort_on_warn = 0;
914 if (abort_on_warn == 1) abort();
916 if (_elm_widget_is(sobj))
918 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
921 sd2->parent_obj = NULL;
922 if (sd2->resize_obj == sobj)
923 sd2->resize_obj = NULL;
925 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
928 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
929 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
930 if ((sd->child_can_focus) && (_is_focusable(sobj)))
934 sd->child_can_focus = EINA_FALSE;
935 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
937 if (_is_focusable(subobj))
939 sd->child_can_focus = EINA_TRUE;
946 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
947 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
949 if (_elm_widget_is(sobj))
950 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
952 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
956 elm_widget_resize_object_set(Evas_Object *obj,
960 // orphan previous resize obj
963 evas_object_clip_unset(sd->resize_obj);
964 evas_object_data_del(sd->resize_obj, "elm-parent");
965 if (_elm_widget_is(sd->resize_obj))
967 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
968 if (sd2) sd2->parent_obj = NULL;
969 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
972 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
974 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
975 _sub_obj_mouse_down, sd);
976 evas_object_smart_member_del(sd->resize_obj);
977 if (_elm_widget_is(sd->resize_obj))
979 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
982 // orphan new resize obj
985 evas_object_data_del(sobj, "elm-parent");
986 if (_elm_widget_is(sobj))
988 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
989 if (sd2) sd2->parent_obj = NULL;
990 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
993 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
995 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
996 _sub_obj_mouse_down, sd);
997 evas_object_smart_member_del(sobj);
998 if (_elm_widget_is(sobj))
1000 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
1003 // set the resize obj up
1004 sd->resize_obj = sobj;
1007 if (_elm_widget_is(sd->resize_obj))
1009 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
1010 if (sd2) sd2->parent_obj = obj;
1011 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
1014 evas_object_clip_set(sobj, evas_object_clip_get(obj));
1015 evas_object_smart_member_add(sobj, obj);
1016 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1018 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
1019 _sub_obj_mouse_down, sd);
1020 _smart_reconfigure(sd);
1021 evas_object_data_set(sobj, "elm-parent", obj);
1022 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
1023 if (_elm_widget_is(sobj))
1025 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
1031 elm_widget_hover_object_set(Evas_Object *obj,
1037 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1040 sd->hover_obj = sobj;
1043 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1045 _smart_reconfigure(sd);
1050 elm_widget_can_focus_set(Evas_Object *obj,
1051 Eina_Bool can_focus)
1054 sd->can_focus = can_focus;
1057 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1059 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1060 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1062 (void *)(long)EVAS_CALLBACK_KEY_UP);
1063 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1065 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1069 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1071 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1073 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1079 elm_widget_can_focus_get(const Evas_Object *obj)
1081 API_ENTRY return EINA_FALSE;
1082 return sd->can_focus;
1086 elm_widget_child_can_focus_get(const Evas_Object *obj)
1088 API_ENTRY return EINA_FALSE;
1089 return sd->child_can_focus;
1093 elm_widget_highlight_ignore_set(Evas_Object *obj,
1097 sd->highlight_ignore = !!ignore;
1101 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1103 API_ENTRY return EINA_FALSE;
1104 return sd->highlight_ignore;
1108 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1109 Eina_Bool highlight)
1112 sd->highlight_in_theme = !!highlight;
1113 /* FIXME: if focused, it should switch from one mode to the other */
1117 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1119 API_ENTRY return EINA_FALSE;
1120 return sd->highlight_in_theme;
1124 elm_widget_focus_get(const Evas_Object *obj)
1126 API_ENTRY return EINA_FALSE;
1131 elm_widget_focused_object_get(const Evas_Object *obj)
1133 const Evas_Object *subobj;
1135 API_ENTRY return NULL;
1137 if (!sd->focused) return NULL;
1138 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1140 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1141 if (fobj) return fobj;
1143 return (Evas_Object *)obj;
1147 elm_widget_top_get(const Evas_Object *obj)
1149 API_ENTRY return NULL;
1150 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1151 return (Evas_Object *)obj;
1155 elm_widget_is(const Evas_Object *obj)
1157 return _elm_widget_is(obj);
1161 elm_widget_parent_widget_get(const Evas_Object *obj)
1163 Evas_Object *parent;
1165 if (_elm_widget_is(obj))
1167 Smart_Data *sd = evas_object_smart_data_get(obj);
1168 if (!sd) return NULL;
1169 parent = sd->parent_obj;
1173 parent = evas_object_data_get(obj, "elm-parent");
1174 if (!parent) parent = evas_object_smart_parent_get(obj);
1179 Evas_Object *elm_parent;
1180 if (_elm_widget_is(parent)) break;
1181 elm_parent = evas_object_data_get(parent, "elm-parent");
1182 if (elm_parent) parent = elm_parent;
1183 else parent = evas_object_smart_parent_get(parent);
1189 elm_widget_event_callback_add(Evas_Object *obj,
1194 EINA_SAFETY_ON_NULL_RETURN(func);
1195 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1198 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1202 elm_widget_event_callback_del(Evas_Object *obj,
1206 API_ENTRY return NULL;
1207 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1209 Elm_Event_Cb_Data *ecd;
1210 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1211 if ((ecd->func == func) && (ecd->data == data))
1214 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1215 return (void *)data;
1221 elm_widget_event_propagate(Evas_Object *obj,
1222 Evas_Callback_Type type,
1224 Evas_Event_Flags *event_flags)
1226 API_ENTRY return EINA_FALSE; //TODO reduce.
1227 if (!_elm_widget_is(obj)) return EINA_FALSE;
1228 Evas_Object *parent = obj;
1229 Elm_Event_Cb_Data *ecd;
1230 Eina_List *l, *l_prev;
1233 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1235 sd = evas_object_smart_data_get(parent);
1236 if ((!sd) || (!_elm_widget_is(obj)))
1237 return EINA_FALSE; //Not Elm Widget
1239 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1242 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1244 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1245 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1248 parent = sd->parent_obj;
1257 * Set custom focus chain.
1259 * This function i set one new and overwrite any previous custom focus chain
1260 * with the list of objects. The previous list will be deleted and this list
1261 * will be managed. After setted, don't modity it.
1263 * @note On focus cycle, only will be evaluated children of this container.
1265 * @param obj The container widget
1266 * @param objs Chain of objects to pass focus
1270 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1274 if (!sd->focus_next_func)
1277 elm_widget_focus_custom_chain_unset(obj);
1282 EINA_LIST_FOREACH(objs, l, o)
1284 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1285 _elm_object_focus_chain_del_cb, sd);
1288 sd->focus_chain = objs;
1294 * Get custom focus chain
1296 * @param obj The container widget
1299 EAPI const Eina_List *
1300 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1302 API_ENTRY return NULL;
1303 return (const Eina_List *)sd->focus_chain;
1309 * Unset custom focus chain
1311 * @param obj The container widget
1315 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1318 Eina_List *l, *l_next;
1321 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1323 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1324 _elm_object_focus_chain_del_cb, sd);
1325 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1332 * Append object to custom focus chain.
1334 * @note If relative_child equal to NULL or not in custom chain, the object
1335 * will be added in end.
1337 * @note On focus cycle, only will be evaluated children of this container.
1339 * @param obj The container widget
1340 * @param child The child to be added in custom chain
1341 * @param relative_child The relative object to position the child
1345 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1347 Evas_Object *relative_child)
1350 EINA_SAFETY_ON_NULL_RETURN(child);
1351 if (!sd->focus_next_func)
1354 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1355 _elm_object_focus_chain_del_cb, sd);
1357 if (!relative_child)
1359 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1363 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1370 * Prepend object to custom focus chain.
1372 * @note If relative_child equal to NULL or not in custom chain, the object
1373 * will be added in begin.
1375 * @note On focus cycle, only will be evaluated children of this container.
1377 * @param obj The container widget
1378 * @param child The child to be added in custom chain
1379 * @param relative_child The relative object to position the child
1383 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1385 Evas_Object *relative_child)
1388 EINA_SAFETY_ON_NULL_RETURN(child);
1389 if (!sd->focus_next_func)
1392 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1393 _elm_object_focus_chain_del_cb, sd);
1395 if (!relative_child)
1397 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1401 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1408 * Give focus to next object in object tree.
1410 * Give focus to next object in focus chain of one object sub-tree.
1411 * If the last object of chain already have focus, the focus will go to the
1412 * first object of chain.
1414 * @param obj The widget root of sub-tree
1415 * @param dir Direction to cycle the focus
1420 elm_widget_focus_cycle(Evas_Object *obj,
1421 Elm_Focus_Direction dir)
1423 Evas_Object *target = NULL;
1424 if (!_elm_widget_is(obj))
1426 elm_widget_focus_next_get(obj, dir, &target);
1428 elm_widget_focus_steal(target);
1434 * Give focus to near object in one direction.
1436 * Give focus to near object in direction of one object.
1437 * If none focusable object in given direction, the focus will not change.
1439 * @param obj The reference widget
1440 * @param x Horizontal component of direction to focus
1441 * @param y Vertical component of direction to focus
1446 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1456 * Get next object in focus chain of object tree.
1458 * Get next object in focus chain of one object sub-tree.
1459 * Return the next object by reference. If don't have any candidate to receive
1460 * focus before chain end, the first candidate will be returned.
1462 * @param obj The widget root of sub-tree
1463 * @param dir Direction os focus chain
1464 * @param next The next object in focus chain
1465 * @return EINA_TRUE if don't need focus chain restart/loop back
1466 * to use 'next' obj.
1471 elm_widget_focus_next_get(const Evas_Object *obj,
1472 Elm_Focus_Direction dir,
1479 API_ENTRY return EINA_FALSE;
1481 /* Ignore if disabled */
1482 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1486 if (sd->focus_next_func)
1487 return sd->focus_next_func(obj, dir, next);
1489 if (!elm_widget_can_focus_get(obj))
1493 *next = (Evas_Object *)obj;
1494 return !elm_widget_focus_get(obj);
1500 * Get next object in focus chain of object tree in list.
1502 * Get next object in focus chain of one object sub-tree ordered by one list.
1503 * Return the next object by reference. If don't have any candidate to receive
1504 * focus before list end, the first candidate will be returned.
1506 * @param obj The widget root of sub-tree
1507 * @param dir Direction os focus chain
1508 * @param items list with ordered objects
1509 * @param list_data_get function to get the object from one item of list
1510 * @param next The next object in focus chain
1511 * @return EINA_TRUE if don't need focus chain restart/loop back
1512 * to use 'next' obj.
1517 elm_widget_focus_list_next_get(const Evas_Object *obj,
1518 const Eina_List *items,
1519 void *(*list_data_get)(const Eina_List * list),
1520 Elm_Focus_Direction dir,
1523 Eina_List *(*list_next)(const Eina_List * list);
1529 if (!_elm_widget_is(obj))
1536 if (dir == ELM_FOCUS_PREVIOUS)
1538 items = eina_list_last(items);
1539 list_next = eina_list_prev;
1541 else if (dir == ELM_FOCUS_NEXT)
1542 list_next = eina_list_next;
1546 const Eina_List *l = items;
1548 /* Recovery last focused sub item */
1549 if (elm_widget_focus_get(obj))
1550 for (; l; l = list_next(l))
1552 Evas_Object *cur = list_data_get(l);
1553 if (elm_widget_focus_get(cur)) break;
1556 const Eina_List *start = l;
1557 Evas_Object *to_focus = NULL;
1559 /* Interate sub items */
1560 /* Go to end of list */
1561 for (; l; l = list_next(l))
1563 Evas_Object *tmp = NULL;
1564 Evas_Object *cur = list_data_get(l);
1566 if (elm_widget_parent_get(cur) != obj)
1569 /* Try Focus cycle in subitem */
1570 if (elm_widget_focus_next_get(cur, dir, &tmp))
1575 else if ((tmp) && (!to_focus))
1581 /* Get First possible */
1582 for (; l != start; l = list_next(l))
1584 Evas_Object *tmp = NULL;
1585 Evas_Object *cur = list_data_get(l);
1587 if (elm_widget_parent_get(cur) != obj)
1590 /* Try Focus cycle in subitem */
1591 elm_widget_focus_next_get(cur, dir, &tmp);
1604 elm_widget_signal_emit(Evas_Object *obj,
1605 const char *emission,
1609 if (!sd->signal_func) return;
1610 sd->signal_func(obj, emission, source);
1614 _edje_signal_callback(void *data,
1615 Evas_Object *obj __UNUSED__,
1616 const char *emission,
1619 Edje_Signal_Data *esd = data;
1620 esd->func(esd->data, esd->obj, emission, source);
1624 elm_widget_signal_callback_add(Evas_Object *obj,
1625 const char *emission,
1627 Edje_Signal_Cb func,
1630 Edje_Signal_Data *esd;
1632 if (!sd->callback_add_func) return;
1633 EINA_SAFETY_ON_NULL_RETURN(func);
1635 esd = ELM_NEW(Edje_Signal_Data);
1640 esd->emission = eina_stringshare_add(emission);
1641 esd->source = eina_stringshare_add(source);
1643 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1644 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1648 elm_widget_signal_callback_del(Evas_Object *obj,
1649 const char *emission,
1651 Edje_Signal_Cb func)
1653 Edje_Signal_Data *esd;
1656 API_ENTRY return NULL;
1657 if (!sd->callback_del_func) return NULL;
1659 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1661 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1662 (!strcmp(esd->source, source)))
1664 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1665 eina_stringshare_del(esd->emission);
1666 eina_stringshare_del(esd->source);
1672 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1677 elm_widget_focus_set(Evas_Object *obj,
1684 sd->focus_order = focus_order;
1685 sd->focused = EINA_TRUE;
1686 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1690 sd->focus_func(obj);
1697 if ((_is_focusable(sd->resize_obj)) &&
1698 (!elm_widget_disabled_get(sd->resize_obj)))
1700 elm_widget_focus_set(sd->resize_obj, first);
1706 EINA_LIST_FOREACH(sd->subobjs, l, child)
1708 if ((_is_focusable(child)) &&
1709 (!elm_widget_disabled_get(child)))
1711 elm_widget_focus_set(child, first);
1721 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1723 if ((_is_focusable(child)) &&
1724 (!elm_widget_disabled_get(child)))
1726 elm_widget_focus_set(child, first);
1732 if ((_is_focusable(sd->resize_obj)) &&
1733 (!elm_widget_disabled_get(sd->resize_obj)))
1735 elm_widget_focus_set(sd->resize_obj, first);
1743 elm_widget_parent_get(const Evas_Object *obj)
1745 API_ENTRY return NULL;
1746 return sd->parent_obj;
1750 elm_widget_focused_object_clear(Evas_Object *obj)
1753 if (!sd->focused) return;
1754 if (elm_widget_focus_get(sd->resize_obj))
1755 elm_widget_focused_object_clear(sd->resize_obj);
1760 EINA_LIST_FOREACH(sd->subobjs, l, child)
1762 if (elm_widget_focus_get(child))
1764 elm_widget_focused_object_clear(child);
1769 sd->focused = EINA_FALSE;
1770 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1771 if (sd->focus_func) sd->focus_func(obj);
1775 elm_widget_focus_steal(Evas_Object *obj)
1777 Evas_Object *parent, *o;
1780 if (sd->focused) return;
1781 if (sd->disabled) return;
1782 if (!sd->can_focus) return;
1786 o = elm_widget_parent_get(parent);
1788 sd = evas_object_smart_data_get(o);
1789 if (sd->disabled) return;
1790 if (sd->focused) break;
1793 if (!elm_widget_parent_get(parent))
1794 elm_widget_focused_object_clear(parent);
1797 parent = elm_widget_parent_get(parent);
1798 sd = evas_object_smart_data_get(parent);
1799 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1800 elm_widget_focused_object_clear(sd->resize_obj);
1805 EINA_LIST_FOREACH(sd->subobjs, l, child)
1807 if (elm_widget_focus_get(child))
1809 elm_widget_focused_object_clear(child);
1820 elm_widget_activate(Evas_Object *obj)
1823 elm_widget_change(obj);
1824 if (sd->activate_func) sd->activate_func(obj);
1828 elm_widget_change(Evas_Object *obj)
1831 elm_widget_change(elm_widget_parent_get(obj));
1832 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1836 elm_widget_disabled_set(Evas_Object *obj,
1841 if (sd->disabled == disabled) return;
1842 sd->disabled = !!disabled;
1843 elm_widget_focus_disabled_handle(obj);
1844 if (sd->disable_func) sd->disable_func(obj);
1848 elm_widget_disabled_get(const Evas_Object *obj)
1851 return sd->disabled;
1855 elm_widget_show_region_set(Evas_Object *obj,
1860 Eina_Bool forceshow)
1862 Evas_Object *parent_obj, *child_obj;
1863 Evas_Coord px, py, cx, cy;
1866 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1867 && (w == sd->rw) && (h == sd->rh)) return;
1872 if (sd->on_show_region_func)
1873 sd->on_show_region_func(sd->on_show_region_data, obj);
1877 parent_obj = sd->parent_obj;
1878 child_obj = sd->obj;
1879 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1880 sd = evas_object_smart_data_get(parent_obj);
1883 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1884 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1893 if (sd->on_show_region_func)
1895 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1902 elm_widget_show_region_get(const Evas_Object *obj,
1918 * Get the focus region of the given widget.
1920 * The focus region is the area of a widget that should brought into the
1921 * visible area when the widget is focused. Mostly used to show the part of
1922 * an entry where the cursor is, for example. The area returned is relative
1923 * to the object @p obj.
1924 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1925 * function will return the full size of the object.
1927 * @param obj The widget object
1928 * @param x Where to store the x coordinate of the area
1929 * @param y Where to store the y coordinate of the area
1930 * @param w Where to store the width of the area
1931 * @param h Where to store the height of the area
1936 elm_widget_focus_region_get(const Evas_Object *obj,
1946 sd = evas_object_smart_data_get(obj);
1947 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1949 evas_object_geometry_get(obj, NULL, NULL, w, h);
1954 sd->on_focus_region_func(obj, x, y, w, h);
1958 elm_widget_scroll_hold_push(Evas_Object *obj)
1962 if (sd->scroll_hold == 1)
1963 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1964 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1965 // FIXME: on delete/reparent hold pop
1969 elm_widget_scroll_hold_pop(Evas_Object *obj)
1973 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1974 if (!sd->scroll_hold)
1975 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1976 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1980 elm_widget_scroll_hold_get(const Evas_Object *obj)
1983 return sd->scroll_hold;
1987 elm_widget_scroll_freeze_push(Evas_Object *obj)
1990 sd->scroll_freeze++;
1991 if (sd->scroll_freeze == 1)
1992 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1993 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1994 // FIXME: on delete/reparent freeze pop
1998 elm_widget_scroll_freeze_pop(Evas_Object *obj)
2001 sd->scroll_freeze--;
2002 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
2003 if (!sd->scroll_freeze)
2004 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
2005 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
2009 elm_widget_scroll_freeze_get(const Evas_Object *obj)
2012 return sd->scroll_freeze;
2016 elm_widget_scale_set(Evas_Object *obj,
2020 if (scale <= 0.0) scale = 0.0;
2021 if (sd->scale != scale)
2024 elm_widget_theme(obj);
2029 elm_widget_scale_get(const Evas_Object *obj)
2031 API_ENTRY return 1.0;
2032 // FIXME: save walking up the tree by storing/caching parent scale
2033 if (sd->scale == 0.0)
2036 return elm_widget_scale_get(sd->parent_obj);
2044 elm_widget_theme_set(Evas_Object *obj,
2048 if (sd->theme != th)
2050 if (sd->theme) elm_theme_free(sd->theme);
2053 elm_widget_theme(obj);
2058 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2062 if (!sd->on_text_set_func)
2065 sd->on_text_set_func(obj, item, label);
2069 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2071 API_ENTRY return NULL;
2073 if (!sd->on_text_get_func)
2076 return sd->on_text_get_func(obj, item);
2080 elm_widget_content_part_set(Evas_Object *obj, const char *item, Evas_Object *content)
2084 if (!sd->on_content_set_func) return;
2085 sd->on_content_set_func(obj, item, content);
2089 elm_widget_content_part_get(const Evas_Object *obj, const char *item)
2091 API_ENTRY return NULL;
2093 if (!sd->on_content_get_func) return NULL;
2094 return sd->on_content_get_func(obj, item);
2098 elm_widget_content_part_unset(Evas_Object *obj, const char *item)
2100 API_ENTRY return NULL;
2102 if (!sd->on_content_unset_func) return NULL;
2103 return sd->on_content_unset_func(obj, item);
2107 elm_widget_theme_get(const Evas_Object *obj)
2109 API_ENTRY return NULL;
2113 return elm_widget_theme_get(sd->parent_obj);
2121 elm_widget_style_set(Evas_Object *obj,
2126 if (eina_stringshare_replace(&sd->style, style))
2127 elm_widget_theme(obj);
2131 elm_widget_style_get(const Evas_Object *obj)
2133 API_ENTRY return NULL;
2134 if (sd->style) return sd->style;
2139 elm_widget_type_set(Evas_Object *obj,
2143 eina_stringshare_replace(&sd->type, type);
2147 elm_widget_type_get(const Evas_Object *obj)
2149 API_ENTRY return NULL;
2150 if (sd->type) return sd->type;
2155 elm_widget_tooltip_add(Evas_Object *obj,
2159 sd->tooltips = eina_list_append(sd->tooltips, tt);
2163 elm_widget_tooltip_del(Evas_Object *obj,
2167 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2171 elm_widget_cursor_add(Evas_Object *obj,
2175 sd->cursors = eina_list_append(sd->cursors, cur);
2179 elm_widget_cursor_del(Evas_Object *obj,
2183 sd->cursors = eina_list_remove(sd->cursors, cur);
2187 elm_widget_drag_lock_x_set(Evas_Object *obj,
2191 if (sd->drag_x_locked == lock) return;
2192 sd->drag_x_locked = lock;
2193 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2194 else _propagate_x_drag_lock(obj, -1);
2198 elm_widget_drag_lock_y_set(Evas_Object *obj,
2202 if (sd->drag_y_locked == lock) return;
2203 sd->drag_y_locked = lock;
2204 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2205 else _propagate_y_drag_lock(obj, -1);
2209 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2211 API_ENTRY return EINA_FALSE;
2212 return sd->drag_x_locked;
2216 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2218 API_ENTRY return EINA_FALSE;
2219 return sd->drag_y_locked;
2223 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2226 return sd->child_drag_x_locked;
2230 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2233 return sd->child_drag_y_locked;
2237 elm_widget_theme_object_set(Evas_Object *obj,
2240 const char *welement,
2243 API_ENTRY return EINA_FALSE;
2244 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2248 elm_widget_type_check(const Evas_Object *obj,
2251 const char *provided, *expected = "(unknown)";
2252 static int abort_on_warn = -1;
2253 provided = elm_widget_type_get(obj);
2254 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2255 if (type) expected = type;
2256 if ((!provided) || (!provided[0]))
2258 provided = evas_object_type_get(obj);
2259 if ((!provided) || (!provided[0]))
2260 provided = "(unknown)";
2262 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2263 if (abort_on_warn == -1)
2265 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2266 else abort_on_warn = 0;
2268 if (abort_on_warn == 1) abort();
2275 * Split string in words
2277 * @param str Source string
2278 * @return List of const words
2280 * @see elm_widget_stringlist_free()
2284 elm_widget_stringlist_get(const char *str)
2286 Eina_List *list = NULL;
2288 if (!str) return NULL;
2289 for (b = s = str; 1; s++)
2291 if ((*s == ' ') || (!*s))
2293 char *t = malloc(s - b + 1);
2296 strncpy(t, b, s - b);
2298 list = eina_list_append(list, eina_stringshare_add(t));
2309 elm_widget_stringlist_free(Eina_List *list)
2312 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2316 elm_widget_focus_hide_handle(Evas_Object *obj)
2318 _if_focused_revert(obj, EINA_TRUE);
2322 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2324 Evas_Object *o = obj;
2327 if (_elm_widget_is(o)) break;
2328 o = evas_object_smart_parent_get(o);
2332 if (!_is_focusable(o)) return;
2333 elm_widget_focus_steal(o);
2337 elm_widget_focus_disabled_handle(Evas_Object *obj)
2341 if (!elm_widget_parent_get(obj))
2342 elm_widget_focused_object_clear(obj);
2344 _if_focused_revert(obj, EINA_TRUE);
2350 * Allocate a new Elm_Widget_Item-derived structure.
2352 * The goal of this structure is to provide common ground for actions
2353 * that a widget item have, such as the owner widget, callback to
2354 * notify deletion, data pointer and maybe more.
2356 * @param widget the owner widget that holds this item, must be an elm_widget!
2357 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2358 * be used to allocate memory.
2360 * @return allocated memory that is already zeroed out, or NULL on errors.
2362 * @see elm_widget_item_new() convenience macro.
2363 * @see elm_widget_item_del() to release memory.
2366 EAPI Elm_Widget_Item *
2367 _elm_widget_item_new(Evas_Object *widget,
2370 if (!_elm_widget_is(widget))
2373 Elm_Widget_Item *item;
2375 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2376 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2378 item = calloc(1, alloc_size);
2379 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2381 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2382 item->widget = widget;
2389 * Releases widget item memory, calling back del_cb() if it exists.
2391 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2392 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2393 * this function and then unset it, thus being useful for 2 step
2394 * cleanup whenever the del_cb may use any of the data that must be
2395 * deleted from item.
2397 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2400 * @param item a valid #Elm_Widget_Item to be deleted.
2401 * @see elm_widget_item_del() convenience macro.
2405 _elm_widget_item_del(Elm_Widget_Item *item)
2407 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2410 item->del_cb((void *)item->data, item->widget, item);
2413 evas_object_del(item->view);
2415 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2422 * Notify object will be deleted without actually deleting it.
2424 * This function will callback Elm_Widget_Item::del_cb if it is set
2425 * and then unset it so it is not called twice (ie: from
2426 * elm_widget_item_del()).
2428 * @param item a valid #Elm_Widget_Item to be notified
2429 * @see elm_widget_item_pre_notify_del() convenience macro.
2433 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2435 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2436 if (!item->del_cb) return;
2437 item->del_cb((void *)item->data, item->widget, item);
2438 item->del_cb = NULL;
2444 * Set the function to notify when item is being deleted.
2446 * This function will complain if there was a callback set already,
2447 * however it will set the new one.
2449 * The callback will be called from elm_widget_item_pre_notify_del()
2450 * or elm_widget_item_del() will be called with:
2451 * - data: the Elm_Widget_Item::data value.
2452 * - obj: the Elm_Widget_Item::widget evas object.
2453 * - event_info: the item being deleted.
2455 * @param item a valid #Elm_Widget_Item to be notified
2456 * @see elm_widget_item_del_cb_set() convenience macro.
2460 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2461 Evas_Smart_Cb del_cb)
2463 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2465 if ((item->del_cb) && (item->del_cb != del_cb))
2466 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2467 item->del_cb, item, del_cb);
2469 item->del_cb = del_cb;
2475 * Set user-data in this item.
2477 * User data may be used to identify this item or just store any
2478 * application data. It is automatically given as the first parameter
2479 * of the deletion notify callback.
2481 * @param item a valid #Elm_Widget_Item to store data in.
2482 * @param data user data to store.
2483 * @see elm_widget_item_del_cb_set() convenience macro.
2487 _elm_widget_item_data_set(Elm_Widget_Item *item,
2490 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2491 if ((item->data) && (item->data != data))
2492 DBG("Replacing item %p data %p with %p", item, item->data, data);
2499 * Retrieves user-data of this item.
2501 * @param item a valid #Elm_Widget_Item to get data from.
2502 * @see elm_widget_item_data_set()
2506 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2508 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2509 return (void *)item->data;
2512 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2514 struct _Elm_Widget_Item_Tooltip
2516 Elm_Widget_Item *item;
2517 Elm_Tooltip_Item_Content_Cb func;
2518 Evas_Smart_Cb del_cb;
2522 static Evas_Object *
2523 _elm_widget_item_tooltip_label_create(void *data,
2524 Evas_Object *obj __UNUSED__,
2525 Evas_Object *tooltip,
2526 void *item __UNUSED__)
2528 Evas_Object *label = elm_label_add(tooltip);
2531 elm_object_style_set(label, "tooltip");
2532 elm_object_text_set(label, data);
2537 _elm_widget_item_tooltip_label_del_cb(void *data,
2538 Evas_Object *obj __UNUSED__,
2539 void *event_info __UNUSED__)
2541 eina_stringshare_del(data);
2547 * Set the text to be shown in the widget item.
2549 * @param item Target item
2550 * @param text The text to set in the content
2552 * Setup the text as tooltip to object. The item can have only one tooltip,
2553 * so any previous tooltip data is removed.
2558 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2561 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2562 EINA_SAFETY_ON_NULL_RETURN(text);
2564 text = eina_stringshare_add(text);
2565 _elm_widget_item_tooltip_content_cb_set
2566 (item, _elm_widget_item_tooltip_label_create, text,
2567 _elm_widget_item_tooltip_label_del_cb);
2570 static Evas_Object *
2571 _elm_widget_item_tooltip_create(void *data,
2573 Evas_Object *tooltip)
2575 Elm_Widget_Item_Tooltip *wit = data;
2576 return wit->func((void *)wit->data, obj, tooltip, wit->item);
2580 _elm_widget_item_tooltip_del_cb(void *data,
2582 void *event_info __UNUSED__)
2584 Elm_Widget_Item_Tooltip *wit = data;
2585 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2592 * Set the content to be shown in the tooltip item
2594 * Setup the tooltip to item. The item can have only one tooltip,
2595 * so any previous tooltip data is removed. @p func(with @p data) will
2596 * be called every time that need show the tooltip and it should
2597 * return a valid Evas_Object. This object is then managed fully by
2598 * tooltip system and is deleted when the tooltip is gone.
2600 * @param item the widget item being attached a tooltip.
2601 * @param func the function used to create the tooltip contents.
2602 * @param data what to provide to @a func as callback data/context.
2603 * @param del_cb called when data is not needed anymore, either when
2604 * another callback replaces @func, the tooltip is unset with
2605 * elm_widget_item_tooltip_unset() or the owner @a item
2606 * dies. This callback receives as the first parameter the
2607 * given @a data, and @c event_info is the item.
2612 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2613 Elm_Tooltip_Item_Content_Cb func,
2615 Evas_Smart_Cb del_cb)
2617 Elm_Widget_Item_Tooltip *wit;
2619 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2623 _elm_widget_item_tooltip_unset(item);
2627 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2628 if (!wit) goto error;
2632 wit->del_cb = del_cb;
2634 elm_object_sub_tooltip_content_cb_set
2635 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2636 _elm_widget_item_tooltip_del_cb);
2641 if (del_cb) del_cb((void *)data, NULL, item);
2644 if (del_cb) del_cb((void *)data, item->widget, item);
2650 * Unset tooltip from item
2652 * @param item widget item to remove previously set tooltip.
2654 * Remove tooltip from item. The callback provided as del_cb to
2655 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2656 * it is not used anymore.
2658 * @see elm_widget_item_tooltip_content_cb_set()
2663 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2665 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2666 elm_object_tooltip_unset(item->view);
2672 * Sets a different style for this item tooltip.
2674 * @note before you set a style you should define a tooltip with
2675 * elm_widget_item_tooltip_content_cb_set() or
2676 * elm_widget_item_tooltip_text_set()
2678 * @param item widget item with tooltip already set.
2679 * @param style the theme style to use (default, transparent, ...)
2684 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2687 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2688 elm_object_tooltip_style_set(item->view, style);
2692 _elm_widget_item_tooltip_size_restrict_disable(Elm_Widget_Item *item, Eina_Bool disable)
2694 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2695 return elm_tooltip_size_restrict_disable(item->view, disable);
2699 _elm_widget_item_tooltip_size_restrict_disabled_get(const Elm_Widget_Item *item)
2701 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2702 return elm_tooltip_size_restrict_disabled_get(item->view);
2708 * Get the style for this item tooltip.
2710 * @param item widget item with tooltip already set.
2711 * @return style the theme style in use, defaults to "default". If the
2712 * object does not have a tooltip set, then NULL is returned.
2717 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2719 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2720 return elm_object_tooltip_style_get(item->view);
2724 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2727 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2728 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2732 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2734 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2735 return elm_object_cursor_get(item->view);
2739 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2741 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2742 elm_object_cursor_unset(item->view);
2748 * Sets a different style for this item cursor.
2750 * @note before you set a style you should define a cursor with
2751 * elm_widget_item_cursor_set()
2753 * @param item widget item with cursor already set.
2754 * @param style the theme style to use (default, transparent, ...)
2759 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2762 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2763 elm_object_cursor_style_set(item->view, style);
2769 * Get the style for this item cursor.
2771 * @param item widget item with cursor already set.
2772 * @return style the theme style in use, defaults to "default". If the
2773 * object does not have a cursor set, then NULL is returned.
2778 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2780 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2781 return elm_object_cursor_style_get(item->view);
2787 * Set if the cursor set should be searched on the theme or should use
2788 * the provided by the engine, only.
2790 * @note before you set if should look on theme you should define a cursor
2791 * with elm_object_cursor_set(). By default it will only look for cursors
2792 * provided by the engine.
2794 * @param item widget item with cursor already set.
2795 * @param engine_only boolean to define it cursors should be looked only
2796 * between the provided by the engine or searched on widget's theme as well.
2801 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2802 Eina_Bool engine_only)
2804 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2805 elm_object_cursor_engine_only_set(item->view, engine_only);
2811 * Get the cursor engine only usage for this item cursor.
2813 * @param item widget item with cursor already set.
2814 * @return engine_only boolean to define it cursors should be looked only
2815 * between the provided by the engine or searched on widget's theme as well. If
2816 * the object does not have a cursor set, then EINA_FALSE is returned.
2821 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2823 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2824 return elm_object_cursor_engine_only_get(item->view);
2827 // smart object funcs
2829 _smart_reconfigure(Smart_Data *sd)
2833 evas_object_move(sd->resize_obj, sd->x, sd->y);
2834 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2838 evas_object_move(sd->hover_obj, sd->x, sd->y);
2839 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2844 _smart_add(Evas_Object *obj)
2848 sd = calloc(1, sizeof(Smart_Data));
2851 sd->x = sd->y = sd->w = sd->h = 0;
2853 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2854 evas_object_smart_data_set(obj, sd);
2857 static Evas_Object *
2858 _newest_focus_order_get(Evas_Object *obj,
2859 unsigned int *newest_focus_order,
2860 Eina_Bool can_focus_only)
2863 Evas_Object *child, *ret, *best;
2865 API_ENTRY return NULL;
2867 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
2871 if (*newest_focus_order < sd->focus_order)
2873 *newest_focus_order = sd->focus_order;
2876 EINA_LIST_FOREACH(sd->subobjs, l, child)
2878 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2884 if ((!best) || (!elm_widget_can_focus_get(best)))
2891 _if_focused_revert(Evas_Object *obj,
2892 Eina_Bool can_focus_only)
2895 Evas_Object *newest = NULL;
2896 unsigned int newest_focus_order = 0;
2900 if (!sd->focused) return;
2901 if (!sd->parent_obj) return;
2903 top = elm_widget_top_get(sd->parent_obj);
2906 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2909 elm_object_unfocus(newest);
2910 elm_object_focus(newest);
2916 _smart_del(Evas_Object *obj)
2919 Edje_Signal_Data *esd;
2923 if (sd->del_pre_func) sd->del_pre_func(obj);
2926 sobj = sd->resize_obj;
2927 sd->resize_obj = NULL;
2928 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2929 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2930 evas_object_del(sobj);
2934 sobj = sd->hover_obj;
2935 sd->hover_obj = NULL;
2936 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2937 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2938 evas_object_del(sobj);
2940 EINA_LIST_FREE(sd->subobjs, sobj)
2942 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2943 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2944 evas_object_del(sobj);
2946 eina_list_free(sd->tooltips); /* should be empty anyway */
2947 eina_list_free(sd->cursors); /* should be empty anyway */
2948 EINA_LIST_FREE(sd->edje_signals, esd)
2950 eina_stringshare_del(esd->emission);
2951 eina_stringshare_del(esd->source);
2954 eina_list_free(sd->event_cb); /* should be empty anyway */
2955 if (sd->del_func) sd->del_func(obj);
2956 if (sd->style) eina_stringshare_del(sd->style);
2957 if (sd->type) eina_stringshare_del(sd->type);
2958 if (sd->theme) elm_theme_free(sd->theme);
2959 _if_focused_revert(obj, EINA_TRUE);
2964 _smart_move(Evas_Object *obj,
2971 _smart_reconfigure(sd);
2975 _smart_resize(Evas_Object *obj,
2982 _smart_reconfigure(sd);
2986 _smart_show(Evas_Object *obj)
2991 if ((list = evas_object_smart_members_get(obj)))
2993 EINA_LIST_FREE(list, o)
2995 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2996 evas_object_show(o);
3002 _smart_hide(Evas_Object *obj)
3008 list = evas_object_smart_members_get(obj);
3009 EINA_LIST_FREE(list, o)
3011 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3012 evas_object_hide(o);
3017 _smart_color_set(Evas_Object *obj,
3026 if ((list = evas_object_smart_members_get(obj)))
3028 EINA_LIST_FREE(list, o)
3030 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3031 evas_object_color_set(o, r, g, b, a);
3037 _smart_clip_set(Evas_Object *obj,
3043 if ((list = evas_object_smart_members_get(obj)))
3045 EINA_LIST_FREE(list, o)
3047 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3048 evas_object_clip_set(o, clip);
3054 _smart_clip_unset(Evas_Object *obj)
3059 if ((list = evas_object_smart_members_get(obj)))
3061 EINA_LIST_FREE(list, o)
3063 if (evas_object_data_get(o, "_elm_leaveme")) continue;
3064 evas_object_clip_unset(o);
3070 _smart_calculate(Evas_Object *obj)
3073 if (sd->changed_func) sd->changed_func(obj);
3076 /* never need to touch this */
3080 if (_e_smart) return;
3082 static const Evas_Smart_Class sc =
3085 EVAS_SMART_CLASS_VERSION,
3103 _e_smart = evas_smart_class_new(&sc);
3107 /* happy debug functions */
3110 _sub_obj_tree_dump(const Evas_Object *obj,
3115 for (i = 0; i < lvl * 3; i++)
3118 if (_elm_widget_is(obj))
3122 printf("+ %s(%p)\n",
3126 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3127 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3129 if (obj != sd->resize_obj)
3130 _sub_obj_tree_dump(obj, lvl + 1);
3134 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3138 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3141 if (!_elm_widget_is(obj))
3145 Eina_Bool visible = evas_object_visible_get(obj);
3146 Eina_Bool disabled = elm_widget_disabled_get(obj);
3147 Eina_Bool focused = elm_widget_focus_get(obj);
3148 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3152 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3155 fprintf(output, ", style=bold");
3158 fprintf(output, ", color=gray28");
3160 fprintf(output, " ];\n");
3163 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3164 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3165 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3169 fprintf(output, ", style=bold");
3172 fprintf(output, ", fontcolor=gray28");
3174 if ((disabled) || (!visible))
3175 fprintf(output, ", color=gray");
3177 fprintf(output, " ];\n");
3181 EINA_LIST_FOREACH(sd->subobjs, l, o)
3182 _sub_obj_tree_dot_dump(o, output);
3187 elm_widget_tree_dump(const Evas_Object *top)
3190 _sub_obj_tree_dump(top, 0);
3198 elm_widget_tree_dot_dump(const Evas_Object *top,
3202 if (!_elm_widget_is(top))
3204 fprintf(output, "graph " " { node [shape=record];\n");
3205 _sub_obj_tree_dot_dump(top, output);
3206 fprintf(output, "}\n");