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 highlight_ignore : 1;
100 Eina_Bool highlight_in_theme : 1;
101 Eina_Bool disabled : 1;
102 Eina_Bool is_mirrored : 1;
103 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
105 Eina_List *focus_chain;
109 struct _Edje_Signal_Data
113 const char *emission;
118 struct _Elm_Event_Cb_Data
124 /* local subsystem functions */
125 static void _smart_reconfigure(Smart_Data *sd);
126 static void _smart_add(Evas_Object *obj);
127 static void _smart_del(Evas_Object *obj);
128 static void _smart_move(Evas_Object *obj,
131 static void _smart_resize(Evas_Object *obj,
134 static void _smart_show(Evas_Object *obj);
135 static void _smart_hide(Evas_Object *obj);
136 static void _smart_color_set(Evas_Object *obj,
141 static void _smart_clip_set(Evas_Object *obj,
143 static void _smart_clip_unset(Evas_Object *obj);
144 static void _smart_calculate(Evas_Object *obj);
145 static void _smart_init(void);
147 static void _if_focused_revert(Evas_Object *obj,
148 Eina_Bool can_focus_only);
149 static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
150 unsigned int *newest_focus_order,
151 Eina_Bool can_focus_only);
153 /* local subsystem globals */
154 static Evas_Smart *_e_smart = NULL;
155 static Eina_List *widtypes = NULL;
157 static unsigned int focus_order = 0;
160 static inline Eina_Bool
161 _elm_widget_is(const Evas_Object *obj)
163 const char *type = evas_object_type_get(obj);
164 return type == SMART_NAME;
167 static inline Eina_Bool
168 _is_focusable(Evas_Object *obj)
170 API_ENTRY return EINA_FALSE;
171 return sd->can_focus || (sd->child_can_focus);
175 _unfocus_parents(Evas_Object *obj)
177 for (; obj; obj = elm_widget_parent_get(obj))
180 if (!sd->focused) return;
186 _focus_parents(Evas_Object *obj)
188 for (; obj; obj = elm_widget_parent_get(obj))
191 if (sd->focused) return;
197 _sub_obj_del(void *data,
200 void *event_info __UNUSED__)
202 Smart_Data *sd = data;
204 if (_elm_widget_is(obj))
206 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
208 if (obj == sd->resize_obj)
209 sd->resize_obj = NULL;
210 else if (obj == sd->hover_obj)
211 sd->hover_obj = NULL;
213 sd->subobjs = eina_list_remove(sd->subobjs, obj);
214 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
218 _sub_obj_hide(void *data __UNUSED__,
221 void *event_info __UNUSED__)
223 elm_widget_focus_hide_handle(obj);
227 _sub_obj_mouse_down(void *data __UNUSED__,
230 void *event_info __UNUSED__)
232 elm_widget_focus_mouse_down_handle(obj);
236 _propagate_x_drag_lock(Evas_Object *obj,
242 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
245 sd2->child_drag_x_locked += dir;
246 _propagate_x_drag_lock(sd->parent_obj, dir);
252 _propagate_y_drag_lock(Evas_Object *obj,
258 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
261 sd2->child_drag_y_locked += dir;
262 _propagate_y_drag_lock(sd->parent_obj, dir);
268 _propagate_event(void *data,
274 Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
275 Evas_Event_Flags *event_flags = NULL;
279 case EVAS_CALLBACK_KEY_DOWN:
281 Evas_Event_Key_Down *ev = event_info;
282 event_flags = &(ev->event_flags);
286 case EVAS_CALLBACK_KEY_UP:
288 Evas_Event_Key_Up *ev = event_info;
289 event_flags = &(ev->event_flags);
293 case EVAS_CALLBACK_MOUSE_WHEEL:
295 Evas_Event_Mouse_Wheel *ev = event_info;
296 event_flags = &(ev->event_flags);
304 elm_widget_event_propagate(obj, type, event_info, event_flags);
308 _parent_focus(Evas_Object *obj)
311 if (sd->focused) return;
313 Evas_Object *o = elm_widget_parent_get(obj);
314 sd->focus_order_on_calc = EINA_TRUE;
316 if (o) _parent_focus(o);
318 if (!sd->focus_order_on_calc)
319 return; /* we don't want to override it if by means of any of the
320 callbacks below one gets to calculate our order
324 sd->focus_order = focus_order;
325 sd->focused = EINA_TRUE;
326 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
327 if (sd->focus_func) sd->focus_func(obj);
329 _elm_widget_focus_region_show(obj);
331 sd->focus_order_on_calc = EINA_FALSE;
335 _elm_object_focus_chain_del_cb(void *data,
338 void *event_info __UNUSED__)
340 Smart_Data *sd = data;
342 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
345 // exposed util funcs to elm
347 _elm_widget_type_clear(void)
351 EINA_LIST_FREE(widtypes, ptr)
353 eina_stringshare_del(*ptr);
359 _elm_widget_focus_region_show(const Evas_Object *obj)
361 Evas_Coord x, y, w, h, ox, oy;
367 o = elm_widget_parent_get(obj);
370 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
371 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
375 sd2 = evas_object_smart_data_get(o);
376 if (sd2->focus_region_func)
378 sd2->focus_region_func(o, x, y, w, h);
379 elm_widget_focus_region_get(o, &x, &y, &w, &h);
383 evas_object_geometry_get(o, &px, &py, NULL, NULL);
389 o = elm_widget_parent_get(o);
394 * @defgroup Widget Widget
397 * Exposed api for making widgets
400 elm_widget_type_register(const char **ptr)
402 widtypes = eina_list_append(widtypes, (void *)ptr);
406 elm_widget_api_check(int ver)
408 if (ver != ELM_INTERNAL_API_VERSION)
410 CRITICAL("Elementary widget api versions do not match");
417 elm_widget_add(Evas *evas)
421 obj = evas_object_smart_add(evas, _e_smart);
422 elm_widget_mirrored_set(obj, elm_mirrored_get());
427 elm_widget_del_hook_set(Evas_Object *obj,
428 void (*func)(Evas_Object *obj))
435 elm_widget_del_pre_hook_set(Evas_Object *obj,
436 void (*func)(Evas_Object *obj))
439 sd->del_pre_func = func;
443 elm_widget_focus_hook_set(Evas_Object *obj,
444 void (*func)(Evas_Object *obj))
447 sd->focus_func = func;
451 elm_widget_activate_hook_set(Evas_Object *obj,
452 void (*func)(Evas_Object *obj))
455 sd->activate_func = func;
459 elm_widget_disable_hook_set(Evas_Object *obj,
460 void (*func)(Evas_Object *obj))
463 sd->disable_func = func;
467 elm_widget_theme_hook_set(Evas_Object *obj,
468 void (*func)(Evas_Object *obj))
471 sd->theme_func = func;
475 elm_widget_event_hook_set(Evas_Object *obj,
476 Eina_Bool (*func)(Evas_Object *obj,
478 Evas_Callback_Type type,
482 sd->event_func = func;
486 elm_widget_text_set_hook_set(Evas_Object *obj,
487 void (*func)(Evas_Object *obj,
492 sd->on_text_set_func = func;
496 elm_widget_text_get_hook_set(Evas_Object *obj,
497 const char *(*func)(const Evas_Object *obj,
501 sd->on_text_get_func = func;
505 elm_widget_changed_hook_set(Evas_Object *obj,
506 void (*func)(Evas_Object *obj))
509 sd->changed_func = func;
513 elm_widget_signal_emit_hook_set(Evas_Object *obj,
514 void (*func)(Evas_Object *obj,
515 const char *emission,
519 sd->signal_func = func;
523 elm_widget_signal_callback_add_hook_set(Evas_Object *obj,
524 void (*func)(Evas_Object *obj,
525 const char *emission,
527 Edje_Signal_Cb func_cb,
531 sd->callback_add_func = func;
535 elm_widget_signal_callback_del_hook_set(Evas_Object *obj,
536 void (*func)(Evas_Object *obj,
537 const char *emission,
539 Edje_Signal_Cb func_cb,
543 sd->callback_del_func = func;
547 elm_widget_theme(Evas_Object *obj)
555 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
556 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
557 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
558 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
559 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
560 if (sd->theme_func) sd->theme_func(obj);
564 elm_widget_theme_specific(Evas_Object *obj,
572 Elm_Theme *th2, *thdef;
575 thdef = elm_theme_default_get();
580 if (!th2) th2 = thdef;
588 if (th2 == thdef) break;
589 th2 = th2->ref_theme;
590 if (!th2) th2 = thdef;
594 EINA_LIST_FOREACH(sd->subobjs, l, child)
595 elm_widget_theme_specific(child, th, force);
596 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
597 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
598 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
599 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
600 if (sd->theme_func) sd->theme_func(obj);
606 * Set hook to get next object in object focus chain.
608 * @param obj The widget object.
609 * @param func The hook to be used with this widget.
614 elm_widget_focus_next_hook_set(Evas_Object *obj,
615 Eina_Bool (*func)(const Evas_Object *obj,
616 Elm_Focus_Direction dir,
620 sd->focus_next_func = func;
624 * Returns the widget's mirrored mode.
626 * @param obj The widget.
627 * @return mirrored mode of the object.
631 elm_widget_mirrored_get(const Evas_Object *obj)
633 API_ENTRY return EINA_FALSE;
634 return sd->is_mirrored;
638 * Sets the widget's mirrored mode.
640 * @param obj The widget.
641 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
644 elm_widget_mirrored_set(Evas_Object *obj,
648 if (sd->is_mirrored != mirrored)
650 sd->is_mirrored = mirrored;
651 elm_widget_theme(obj);
657 * Resets the mirrored mode from the system mirror mode for widgets that are in
658 * automatic mirroring mode. This function does not call elm_widget_theme.
660 * @param obj The widget.
661 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
664 _elm_widget_mirrored_reload(Evas_Object *obj)
667 Eina_Bool mirrored = elm_mirrored_get();
668 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
670 sd->is_mirrored = mirrored;
675 * Returns the widget's mirrored mode setting.
677 * @param obj The widget.
678 * @return mirrored mode setting of the object.
682 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
684 API_ENTRY return EINA_FALSE;
685 return sd->mirrored_auto_mode;
689 * Sets the widget's mirrored mode setting.
690 * When widget in automatic mode, it follows the system mirrored mode set by
691 * elm_mirrored_set().
692 * @param obj The widget.
693 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
696 elm_widget_mirrored_automatic_set(Evas_Object *obj,
700 if (sd->mirrored_auto_mode != automatic)
702 sd->mirrored_auto_mode = automatic;
706 elm_widget_mirrored_set(obj, elm_mirrored_get());
712 elm_widget_on_focus_hook_set(Evas_Object *obj,
713 void (*func)(void *data,
718 sd->on_focus_func = func;
719 sd->on_focus_data = data;
723 elm_widget_on_change_hook_set(Evas_Object *obj,
724 void (*func)(void *data,
729 sd->on_change_func = func;
730 sd->on_change_data = data;
734 elm_widget_on_show_region_hook_set(Evas_Object *obj,
735 void (*func)(void *data,
740 sd->on_show_region_func = func;
741 sd->on_show_region_data = data;
747 * Set the hook to use to show the focused region.
749 * Whenever a new widget gets focused or it's needed to show the focused
750 * area of the current one, this hook will be called on objects that may
751 * want to move their children into their visible area.
752 * The area given in the hook function is relative to the @p obj widget.
754 * @param obj The widget object
755 * @param func The function to call to show the specified area.
760 elm_widget_focus_region_hook_set(Evas_Object *obj,
761 void (*func)(Evas_Object *obj,
768 sd->focus_region_func = func;
774 * Set the hook to retrieve the focused region of a widget.
776 * This hook will be called by elm_widget_focus_region_get() whenever
777 * it's needed to get the focused area of a widget. The area must be relative
778 * to the widget itself and if no hook is set, it will default to the entire
781 * @param obj The widget object
782 * @param func The function used to retrieve the focus region.
787 elm_widget_on_focus_region_hook_set(Evas_Object *obj,
788 void (*func)(const Evas_Object *obj,
795 sd->on_focus_region_func = func;
799 elm_widget_data_set(Evas_Object *obj,
807 elm_widget_data_get(const Evas_Object *obj)
809 API_ENTRY return NULL;
814 elm_widget_sub_object_add(Evas_Object *obj,
818 double scale, pscale = elm_widget_scale_get(sobj);
819 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
820 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
822 if (_elm_widget_is(sobj))
824 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
827 if (sd2->parent_obj == obj)
830 elm_widget_sub_object_del(sd2->parent_obj, sobj);
831 sd2->parent_obj = obj;
832 if (!sd->child_can_focus && (_is_focusable(sobj)))
833 sd->child_can_focus = EINA_TRUE;
838 void *data = evas_object_data_get(sobj, "elm-parent");
841 if (data == obj) return;
842 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
847 sd->subobjs = eina_list_append(sd->subobjs, sobj);
848 evas_object_data_set(sobj, "elm-parent", obj);
849 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
850 if (_elm_widget_is(sobj))
851 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
852 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
853 scale = elm_widget_scale_get(sobj);
854 th = elm_widget_theme_get(sobj);
855 mirrored = elm_widget_mirrored_get(sobj);
856 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
857 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
861 elm_widget_sub_object_del(Evas_Object *obj,
864 Evas_Object *sobj_parent;
868 sobj_parent = evas_object_data_del(sobj, "elm-parent");
869 if (sobj_parent != obj)
871 static int abort_on_warn = -1;
872 ERR("removing sub object %p from parent %p, "
873 "but elm-parent is different %p!",
874 sobj, obj, sobj_parent);
875 if (EINA_UNLIKELY(abort_on_warn == -1))
877 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
878 else abort_on_warn = 0;
880 if (abort_on_warn == 1) abort();
882 if (_elm_widget_is(sobj))
884 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
887 sd2->parent_obj = NULL;
888 if (sd2->resize_obj == sobj)
889 sd2->resize_obj = NULL;
891 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
894 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
895 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
896 if ((sd->child_can_focus) && (_is_focusable(sobj)))
900 sd->child_can_focus = EINA_FALSE;
901 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
903 if (_is_focusable(subobj))
905 sd->child_can_focus = EINA_TRUE;
912 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
913 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
915 if (_elm_widget_is(sobj))
916 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
918 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
922 elm_widget_resize_object_set(Evas_Object *obj,
926 // orphan previous resize obj
929 evas_object_clip_unset(sd->resize_obj);
930 evas_object_data_del(sd->resize_obj, "elm-parent");
931 if (_elm_widget_is(sd->resize_obj))
933 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
934 if (sd2) sd2->parent_obj = NULL;
935 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
938 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
940 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
941 _sub_obj_mouse_down, sd);
942 evas_object_smart_member_del(sd->resize_obj);
943 if (_elm_widget_is(sd->resize_obj))
945 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
948 // orphan new resize obj
951 evas_object_data_del(sobj, "elm-parent");
952 if (_elm_widget_is(sobj))
954 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
955 if (sd2) sd2->parent_obj = NULL;
956 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
959 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
961 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
962 _sub_obj_mouse_down, sd);
963 evas_object_smart_member_del(sobj);
964 if (_elm_widget_is(sobj))
966 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
969 // set the resize obj up
970 sd->resize_obj = sobj;
973 if (_elm_widget_is(sd->resize_obj))
975 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
976 if (sd2) sd2->parent_obj = obj;
977 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
980 evas_object_clip_set(sobj, evas_object_clip_get(obj));
981 evas_object_smart_member_add(sobj, obj);
982 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
984 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
985 _sub_obj_mouse_down, sd);
986 _smart_reconfigure(sd);
987 evas_object_data_set(sobj, "elm-parent", obj);
988 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
989 if (_elm_widget_is(sobj))
991 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
997 elm_widget_hover_object_set(Evas_Object *obj,
1003 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
1006 sd->hover_obj = sobj;
1009 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
1011 _smart_reconfigure(sd);
1016 elm_widget_can_focus_set(Evas_Object *obj,
1017 Eina_Bool can_focus)
1020 sd->can_focus = can_focus;
1023 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
1025 (void *)(long)EVAS_CALLBACK_KEY_DOWN);
1026 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
1028 (void *)(long)EVAS_CALLBACK_KEY_UP);
1029 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1031 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
1035 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
1037 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
1039 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
1045 elm_widget_can_focus_get(const Evas_Object *obj)
1047 API_ENTRY return EINA_FALSE;
1048 return sd->can_focus;
1052 elm_widget_child_can_focus_get(const Evas_Object *obj)
1054 API_ENTRY return EINA_FALSE;
1055 return sd->child_can_focus;
1059 elm_widget_highlight_ignore_set(Evas_Object *obj,
1063 sd->highlight_ignore = !!ignore;
1067 elm_widget_highlight_ignore_get(const Evas_Object *obj)
1069 API_ENTRY return EINA_FALSE;
1070 return sd->highlight_ignore;
1074 elm_widget_highlight_in_theme_set(Evas_Object *obj,
1075 Eina_Bool highlight)
1078 sd->highlight_in_theme = !!highlight;
1079 /* FIXME: if focused, it should switch from one mode to the other */
1083 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
1085 API_ENTRY return EINA_FALSE;
1086 return sd->highlight_in_theme;
1090 elm_widget_focus_get(const Evas_Object *obj)
1092 API_ENTRY return EINA_FALSE;
1097 elm_widget_focused_object_get(const Evas_Object *obj)
1099 const Evas_Object *subobj;
1101 API_ENTRY return NULL;
1103 if (!sd->focused) return NULL;
1104 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
1106 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
1107 if (fobj) return fobj;
1109 return (Evas_Object *)obj;
1113 elm_widget_top_get(const Evas_Object *obj)
1115 API_ENTRY return NULL;
1116 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
1117 return (Evas_Object *)obj;
1121 elm_widget_is(const Evas_Object *obj)
1123 return _elm_widget_is(obj);
1127 elm_widget_parent_widget_get(const Evas_Object *obj)
1129 Evas_Object *parent;
1131 if (_elm_widget_is(obj))
1133 Smart_Data *sd = evas_object_smart_data_get(obj);
1134 if (!sd) return NULL;
1135 parent = sd->parent_obj;
1139 parent = evas_object_data_get(obj, "elm-parent");
1140 if (!parent) parent = evas_object_smart_parent_get(obj);
1145 Evas_Object *elm_parent;
1146 if (_elm_widget_is(parent)) break;
1147 elm_parent = evas_object_data_get(parent, "elm-parent");
1148 if (elm_parent) parent = elm_parent;
1149 else parent = evas_object_smart_parent_get(parent);
1155 elm_widget_event_callback_add(Evas_Object *obj,
1160 EINA_SAFETY_ON_NULL_RETURN(func);
1161 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1164 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1168 elm_widget_event_callback_del(Evas_Object *obj,
1172 API_ENTRY return NULL;
1173 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1175 Elm_Event_Cb_Data *ecd;
1176 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1177 if ((ecd->func == func) && (ecd->data == data))
1180 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1181 return (void *)data;
1187 elm_widget_event_propagate(Evas_Object *obj,
1188 Evas_Callback_Type type,
1190 Evas_Event_Flags *event_flags)
1192 API_ENTRY return EINA_FALSE; //TODO reduce.
1193 if (!_elm_widget_is(obj)) return EINA_FALSE;
1194 Evas_Object *parent = obj;
1195 Elm_Event_Cb_Data *ecd;
1196 Eina_List *l, *l_prev;
1199 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1201 sd = evas_object_smart_data_get(parent);
1202 if ((!sd) || (!_elm_widget_is(obj)))
1203 return EINA_FALSE; //Not Elm Widget
1205 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1208 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1210 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1211 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1214 parent = sd->parent_obj;
1223 * Set custom focus chain.
1225 * This function i set one new and overwrite any previous custom focus chain
1226 * with the list of objects. The previous list will be deleted and this list
1227 * will be managed. After setted, don't modity it.
1229 * @note On focus cycle, only will be evaluated children of this container.
1231 * @param obj The container widget
1232 * @param objs Chain of objects to pass focus
1236 elm_widget_focus_custom_chain_set(Evas_Object *obj,
1240 if (!sd->focus_next_func)
1243 elm_widget_focus_custom_chain_unset(obj);
1248 EINA_LIST_FOREACH(objs, l, o)
1250 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1251 _elm_object_focus_chain_del_cb, sd);
1254 sd->focus_chain = objs;
1260 * Get custom focus chain
1262 * @param obj The container widget
1265 EAPI const Eina_List *
1266 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1268 API_ENTRY return NULL;
1269 return (const Eina_List *)sd->focus_chain;
1275 * Unset custom focus chain
1277 * @param obj The container widget
1281 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1284 Eina_List *l, *l_next;
1287 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1289 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1290 _elm_object_focus_chain_del_cb, sd);
1291 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1298 * Append object to custom focus chain.
1300 * @note If relative_child equal to NULL or not in custom chain, the object
1301 * will be added in end.
1303 * @note On focus cycle, only will be evaluated children of this container.
1305 * @param obj The container widget
1306 * @param child The child to be added in custom chain
1307 * @param relative_child The relative object to position the child
1311 elm_widget_focus_custom_chain_append(Evas_Object *obj,
1313 Evas_Object *relative_child)
1316 EINA_SAFETY_ON_NULL_RETURN(child);
1317 if (!sd->focus_next_func)
1320 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1321 _elm_object_focus_chain_del_cb, sd);
1323 if (!relative_child)
1325 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1329 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1336 * Prepend object to custom focus chain.
1338 * @note If relative_child equal to NULL or not in custom chain, the object
1339 * will be added in begin.
1341 * @note On focus cycle, only will be evaluated children of this container.
1343 * @param obj The container widget
1344 * @param child The child to be added in custom chain
1345 * @param relative_child The relative object to position the child
1349 elm_widget_focus_custom_chain_prepend(Evas_Object *obj,
1351 Evas_Object *relative_child)
1354 EINA_SAFETY_ON_NULL_RETURN(child);
1355 if (!sd->focus_next_func)
1358 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1359 _elm_object_focus_chain_del_cb, sd);
1361 if (!relative_child)
1363 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1367 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1374 * Give focus to next object in object tree.
1376 * Give focus to next object in focus chain of one object sub-tree.
1377 * If the last object of chain already have focus, the focus will go to the
1378 * first object of chain.
1380 * @param obj The widget root of sub-tree
1381 * @param dir Direction to cycle the focus
1386 elm_widget_focus_cycle(Evas_Object *obj,
1387 Elm_Focus_Direction dir)
1389 Evas_Object *target = NULL;
1390 if (!_elm_widget_is(obj))
1392 elm_widget_focus_next_get(obj, dir, &target);
1394 elm_widget_focus_steal(target);
1400 * Give focus to near object in one direction.
1402 * Give focus to near object in direction of one object.
1403 * If none focusable object in given direction, the focus will not change.
1405 * @param obj The reference widget
1406 * @param x Horizontal component of direction to focus
1407 * @param y Vertical component of direction to focus
1412 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__,
1422 * Get next object in focus chain of object tree.
1424 * Get next object in focus chain of one object sub-tree.
1425 * Return the next object by reference. If don't have any candidate to receive
1426 * focus before chain end, the first candidate will be returned.
1428 * @param obj The widget root of sub-tree
1429 * @param dir Direction os focus chain
1430 * @param next The next object in focus chain
1431 * @return EINA_TRUE if don't need focus chain restart/loop back
1432 * to use 'next' obj.
1437 elm_widget_focus_next_get(const Evas_Object *obj,
1438 Elm_Focus_Direction dir,
1445 API_ENTRY return EINA_FALSE;
1447 /* Ignore if disabled */
1448 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1452 if (sd->focus_next_func)
1453 return sd->focus_next_func(obj, dir, next);
1455 if (!elm_widget_can_focus_get(obj))
1459 *next = (Evas_Object *)obj;
1460 return !elm_widget_focus_get(obj);
1466 * Get next object in focus chain of object tree in list.
1468 * Get next object in focus chain of one object sub-tree ordered by one list.
1469 * Return the next object by reference. If don't have any candidate to receive
1470 * focus before list end, the first candidate will be returned.
1472 * @param obj The widget root of sub-tree
1473 * @param dir Direction os focus chain
1474 * @param items list with ordered objects
1475 * @param list_data_get function to get the object from one item of list
1476 * @param next The next object in focus chain
1477 * @return EINA_TRUE if don't need focus chain restart/loop back
1478 * to use 'next' obj.
1483 elm_widget_focus_list_next_get(const Evas_Object *obj,
1484 const Eina_List *items,
1485 void *(*list_data_get)(const Eina_List * list),
1486 Elm_Focus_Direction dir,
1489 Eina_List *(*list_next)(const Eina_List * list);
1495 if (!_elm_widget_is(obj))
1502 if (dir == ELM_FOCUS_PREVIOUS)
1504 items = eina_list_last(items);
1505 list_next = eina_list_prev;
1507 else if (dir == ELM_FOCUS_NEXT)
1508 list_next = eina_list_next;
1512 const Eina_List *l = items;
1514 /* Recovery last focused sub item */
1515 if (elm_widget_focus_get(obj))
1516 for (; l; l = list_next(l))
1518 Evas_Object *cur = list_data_get(l);
1519 if (elm_widget_focus_get(cur)) break;
1522 const Eina_List *start = l;
1523 Evas_Object *to_focus = NULL;
1525 /* Interate sub items */
1526 /* Go to end of list */
1527 for (; l; l = list_next(l))
1529 Evas_Object *tmp = NULL;
1530 Evas_Object *cur = list_data_get(l);
1532 if (elm_widget_parent_get(cur) != obj)
1535 /* Try Focus cycle in subitem */
1536 if (elm_widget_focus_next_get(cur, dir, &tmp))
1541 else if ((tmp) && (!to_focus))
1547 /* Get First possible */
1548 for (; l != start; l = list_next(l))
1550 Evas_Object *tmp = NULL;
1551 Evas_Object *cur = list_data_get(l);
1553 if (elm_widget_parent_get(cur) != obj)
1556 /* Try Focus cycle in subitem */
1557 elm_widget_focus_next_get(cur, dir, &tmp);
1570 elm_widget_signal_emit(Evas_Object *obj,
1571 const char *emission,
1575 if (!sd->signal_func) return;
1576 sd->signal_func(obj, emission, source);
1580 _edje_signal_callback(void *data,
1581 Evas_Object *obj __UNUSED__,
1582 const char *emission,
1585 Edje_Signal_Data *esd = data;
1586 esd->func(esd->data, esd->obj, emission, source);
1590 elm_widget_signal_callback_add(Evas_Object *obj,
1591 const char *emission,
1593 Edje_Signal_Cb func,
1596 Edje_Signal_Data *esd;
1598 if (!sd->callback_add_func) return;
1599 EINA_SAFETY_ON_NULL_RETURN(func);
1601 esd = ELM_NEW(Edje_Signal_Data);
1606 esd->emission = eina_stringshare_add(emission);
1607 esd->source = eina_stringshare_add(source);
1609 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1610 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1614 elm_widget_signal_callback_del(Evas_Object *obj,
1615 const char *emission,
1617 Edje_Signal_Cb func)
1619 Edje_Signal_Data *esd;
1622 API_ENTRY return NULL;
1623 if (!sd->callback_del_func) return NULL;
1625 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1627 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1628 (!strcmp(esd->source, source)))
1630 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1631 eina_stringshare_del(esd->emission);
1632 eina_stringshare_del(esd->source);
1638 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1643 elm_widget_focus_set(Evas_Object *obj,
1650 sd->focus_order = focus_order;
1651 sd->focused = EINA_TRUE;
1652 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1656 sd->focus_func(obj);
1663 if ((_is_focusable(sd->resize_obj)) &&
1664 (!elm_widget_disabled_get(sd->resize_obj)))
1666 elm_widget_focus_set(sd->resize_obj, first);
1672 EINA_LIST_FOREACH(sd->subobjs, l, child)
1674 if ((_is_focusable(child)) &&
1675 (!elm_widget_disabled_get(child)))
1677 elm_widget_focus_set(child, first);
1687 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1689 if ((_is_focusable(child)) &&
1690 (!elm_widget_disabled_get(child)))
1692 elm_widget_focus_set(child, first);
1698 if ((_is_focusable(sd->resize_obj)) &&
1699 (!elm_widget_disabled_get(sd->resize_obj)))
1701 elm_widget_focus_set(sd->resize_obj, first);
1709 elm_widget_parent_get(const Evas_Object *obj)
1711 API_ENTRY return NULL;
1712 return sd->parent_obj;
1716 elm_widget_focused_object_clear(Evas_Object *obj)
1719 if (!sd->focused) return;
1720 if (elm_widget_focus_get(sd->resize_obj))
1721 elm_widget_focused_object_clear(sd->resize_obj);
1726 EINA_LIST_FOREACH(sd->subobjs, l, child)
1728 if (elm_widget_focus_get(child))
1730 elm_widget_focused_object_clear(child);
1735 sd->focused = EINA_FALSE;
1736 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1737 if (sd->focus_func) sd->focus_func(obj);
1741 elm_widget_focus_steal(Evas_Object *obj)
1743 Evas_Object *parent, *o;
1746 if (sd->focused) return;
1747 if (sd->disabled) return;
1748 if (!sd->can_focus) return;
1752 o = elm_widget_parent_get(parent);
1754 sd = evas_object_smart_data_get(o);
1755 if (sd->disabled) return;
1756 if (sd->focused) break;
1759 if (!elm_widget_parent_get(parent))
1760 elm_widget_focused_object_clear(parent);
1763 parent = elm_widget_parent_get(parent);
1764 sd = evas_object_smart_data_get(parent);
1765 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1766 elm_widget_focused_object_clear(sd->resize_obj);
1771 EINA_LIST_FOREACH(sd->subobjs, l, child)
1773 if (elm_widget_focus_get(child))
1775 elm_widget_focused_object_clear(child);
1786 elm_widget_activate(Evas_Object *obj)
1789 elm_widget_change(obj);
1790 if (sd->activate_func) sd->activate_func(obj);
1794 elm_widget_change(Evas_Object *obj)
1797 elm_widget_change(elm_widget_parent_get(obj));
1798 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1802 elm_widget_disabled_set(Evas_Object *obj,
1807 if (sd->disabled == disabled) return;
1808 sd->disabled = !!disabled;
1809 elm_widget_focus_disabled_handle(obj);
1810 if (sd->disable_func) sd->disable_func(obj);
1814 elm_widget_disabled_get(const Evas_Object *obj)
1817 return sd->disabled;
1821 elm_widget_show_region_set(Evas_Object *obj,
1826 Eina_Bool forceshow)
1828 Evas_Object *parent_obj, *child_obj;
1829 Evas_Coord px, py, cx, cy;
1832 if (!forceshow && (x == sd->rx) && (y == sd->ry)
1833 && (w == sd->rw) && (h == sd->rh)) return;
1838 if (sd->on_show_region_func)
1839 sd->on_show_region_func(sd->on_show_region_data, obj);
1843 parent_obj = sd->parent_obj;
1844 child_obj = sd->obj;
1845 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1846 sd = evas_object_smart_data_get(parent_obj);
1849 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1850 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1859 if (sd->on_show_region_func)
1861 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1868 elm_widget_show_region_get(const Evas_Object *obj,
1884 * Get the focus region of the given widget.
1886 * The focus region is the area of a widget that should brought into the
1887 * visible area when the widget is focused. Mostly used to show the part of
1888 * an entry where the cursor is, for example. The area returned is relative
1889 * to the object @p obj.
1890 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1891 * function will return the full size of the object.
1893 * @param obj The widget object
1894 * @param x Where to store the x coordinate of the area
1895 * @param y Where to store the y coordinate of the area
1896 * @param w Where to store the width of the area
1897 * @param h Where to store the height of the area
1902 elm_widget_focus_region_get(const Evas_Object *obj,
1912 sd = evas_object_smart_data_get(obj);
1913 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1915 evas_object_geometry_get(obj, NULL, NULL, w, h);
1920 sd->on_focus_region_func(obj, x, y, w, h);
1924 elm_widget_scroll_hold_push(Evas_Object *obj)
1928 if (sd->scroll_hold == 1)
1929 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1930 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1931 // FIXME: on delete/reparent hold pop
1935 elm_widget_scroll_hold_pop(Evas_Object *obj)
1939 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1940 if (!sd->scroll_hold)
1941 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1942 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1946 elm_widget_scroll_hold_get(const Evas_Object *obj)
1949 return sd->scroll_hold;
1953 elm_widget_scroll_freeze_push(Evas_Object *obj)
1956 sd->scroll_freeze++;
1957 if (sd->scroll_freeze == 1)
1958 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1959 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1960 // FIXME: on delete/reparent freeze pop
1964 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1967 sd->scroll_freeze--;
1968 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1969 if (!sd->scroll_freeze)
1970 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1971 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1975 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1978 return sd->scroll_freeze;
1982 elm_widget_scale_set(Evas_Object *obj,
1986 if (scale <= 0.0) scale = 0.0;
1987 if (sd->scale != scale)
1990 elm_widget_theme(obj);
1995 elm_widget_scale_get(const Evas_Object *obj)
1997 API_ENTRY return 1.0;
1998 // FIXME: save walking up the tree by storing/caching parent scale
1999 if (sd->scale == 0.0)
2002 return elm_widget_scale_get(sd->parent_obj);
2010 elm_widget_theme_set(Evas_Object *obj,
2014 if (sd->theme != th)
2016 if (sd->theme) elm_theme_free(sd->theme);
2019 elm_widget_theme(obj);
2024 elm_widget_text_part_set(Evas_Object *obj, const char *item, const char *label)
2028 if (!sd->on_text_set_func)
2031 sd->on_text_set_func(obj, item, label);
2035 elm_widget_text_part_get(const Evas_Object *obj, const char *item)
2037 API_ENTRY return NULL;
2039 if (!sd->on_text_get_func)
2042 return sd->on_text_get_func(obj, item);
2046 elm_widget_theme_get(const Evas_Object *obj)
2048 API_ENTRY return NULL;
2052 return elm_widget_theme_get(sd->parent_obj);
2060 elm_widget_style_set(Evas_Object *obj,
2065 if (eina_stringshare_replace(&sd->style, style))
2066 elm_widget_theme(obj);
2070 elm_widget_style_get(const Evas_Object *obj)
2072 API_ENTRY return NULL;
2073 if (sd->style) return sd->style;
2078 elm_widget_type_set(Evas_Object *obj,
2082 eina_stringshare_replace(&sd->type, type);
2086 elm_widget_type_get(const Evas_Object *obj)
2088 API_ENTRY return NULL;
2089 if (sd->type) return sd->type;
2094 elm_widget_tooltip_add(Evas_Object *obj,
2098 sd->tooltips = eina_list_append(sd->tooltips, tt);
2102 elm_widget_tooltip_del(Evas_Object *obj,
2106 sd->tooltips = eina_list_remove(sd->tooltips, tt);
2110 elm_widget_cursor_add(Evas_Object *obj,
2114 sd->cursors = eina_list_append(sd->cursors, cur);
2118 elm_widget_cursor_del(Evas_Object *obj,
2122 sd->cursors = eina_list_remove(sd->cursors, cur);
2126 elm_widget_drag_lock_x_set(Evas_Object *obj,
2130 if (sd->drag_x_locked == lock) return;
2131 sd->drag_x_locked = lock;
2132 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
2133 else _propagate_x_drag_lock(obj, -1);
2137 elm_widget_drag_lock_y_set(Evas_Object *obj,
2141 if (sd->drag_y_locked == lock) return;
2142 sd->drag_y_locked = lock;
2143 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
2144 else _propagate_y_drag_lock(obj, -1);
2148 elm_widget_drag_lock_x_get(const Evas_Object *obj)
2150 API_ENTRY return EINA_FALSE;
2151 return sd->drag_x_locked;
2155 elm_widget_drag_lock_y_get(const Evas_Object *obj)
2157 API_ENTRY return EINA_FALSE;
2158 return sd->drag_y_locked;
2162 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
2165 return sd->child_drag_x_locked;
2169 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
2172 return sd->child_drag_y_locked;
2176 elm_widget_theme_object_set(Evas_Object *obj,
2179 const char *welement,
2182 API_ENTRY return EINA_FALSE;
2183 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
2187 elm_widget_type_check(const Evas_Object *obj,
2190 const char *provided, *expected = "(unknown)";
2191 static int abort_on_warn = -1;
2192 provided = elm_widget_type_get(obj);
2193 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
2194 if (type) expected = type;
2195 if ((!provided) || (!provided[0]))
2197 provided = evas_object_type_get(obj);
2198 if ((!provided) || (!provided[0]))
2199 provided = "(unknown)";
2201 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2202 if (abort_on_warn == -1)
2204 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2205 else abort_on_warn = 0;
2207 if (abort_on_warn == 1) abort();
2214 * Split string in words
2216 * @param str Source string
2217 * @return List of const words
2219 * @see elm_widget_stringlist_free()
2223 elm_widget_stringlist_get(const char *str)
2225 Eina_List *list = NULL;
2227 if (!str) return NULL;
2228 for (b = s = str; 1; s++)
2230 if ((*s == ' ') || (!*s))
2232 char *t = malloc(s - b + 1);
2235 strncpy(t, b, s - b);
2237 list = eina_list_append(list, eina_stringshare_add(t));
2248 elm_widget_stringlist_free(Eina_List *list)
2251 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2255 elm_widget_focus_hide_handle(Evas_Object *obj)
2257 _if_focused_revert(obj, EINA_TRUE);
2261 elm_widget_focus_mouse_down_handle(Evas_Object *obj)
2263 Evas_Object *o = obj;
2266 if (_elm_widget_is(o)) break;
2267 o = evas_object_smart_parent_get(o);
2271 if (!_is_focusable(o)) return;
2272 elm_widget_focus_steal(o);
2276 elm_widget_focus_disabled_handle(Evas_Object *obj)
2280 if (!elm_widget_parent_get(obj))
2281 elm_widget_focused_object_clear(obj);
2283 _if_focused_revert(obj, EINA_TRUE);
2289 * Allocate a new Elm_Widget_Item-derived structure.
2291 * The goal of this structure is to provide common ground for actions
2292 * that a widget item have, such as the owner widget, callback to
2293 * notify deletion, data pointer and maybe more.
2295 * @param widget the owner widget that holds this item, must be an elm_widget!
2296 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2297 * be used to allocate memory.
2299 * @return allocated memory that is already zeroed out, or NULL on errors.
2301 * @see elm_widget_item_new() convenience macro.
2302 * @see elm_widget_item_del() to release memory.
2305 EAPI Elm_Widget_Item *
2306 _elm_widget_item_new(Evas_Object *widget,
2309 if (!_elm_widget_is(widget))
2312 Elm_Widget_Item *item;
2314 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2315 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2317 item = calloc(1, alloc_size);
2318 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2320 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2321 item->widget = widget;
2328 * Releases widget item memory, calling back del_cb() if it exists.
2330 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2331 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2332 * this function and then unset it, thus being useful for 2 step
2333 * cleanup whenever the del_cb may use any of the data that must be
2334 * deleted from item.
2336 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2339 * @param item a valid #Elm_Widget_Item to be deleted.
2340 * @see elm_widget_item_del() convenience macro.
2344 _elm_widget_item_del(Elm_Widget_Item *item)
2346 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2349 item->del_cb((void *)item->data, item->widget, item);
2352 evas_object_del(item->view);
2354 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2361 * Notify object will be deleted without actually deleting it.
2363 * This function will callback Elm_Widget_Item::del_cb if it is set
2364 * and then unset it so it is not called twice (ie: from
2365 * elm_widget_item_del()).
2367 * @param item a valid #Elm_Widget_Item to be notified
2368 * @see elm_widget_item_pre_notify_del() convenience macro.
2372 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2374 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2375 if (!item->del_cb) return;
2376 item->del_cb((void *)item->data, item->widget, item);
2377 item->del_cb = NULL;
2383 * Set the function to notify when item is being deleted.
2385 * This function will complain if there was a callback set already,
2386 * however it will set the new one.
2388 * The callback will be called from elm_widget_item_pre_notify_del()
2389 * or elm_widget_item_del() will be called with:
2390 * - data: the Elm_Widget_Item::data value.
2391 * - obj: the Elm_Widget_Item::widget evas object.
2392 * - event_info: the item being deleted.
2394 * @param item a valid #Elm_Widget_Item to be notified
2395 * @see elm_widget_item_del_cb_set() convenience macro.
2399 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
2400 Evas_Smart_Cb del_cb)
2402 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2404 if ((item->del_cb) && (item->del_cb != del_cb))
2405 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2406 item->del_cb, item, del_cb);
2408 item->del_cb = del_cb;
2414 * Set user-data in this item.
2416 * User data may be used to identify this item or just store any
2417 * application data. It is automatically given as the first parameter
2418 * of the deletion notify callback.
2420 * @param item a valid #Elm_Widget_Item to store data in.
2421 * @param data user data to store.
2422 * @see elm_widget_item_del_cb_set() convenience macro.
2426 _elm_widget_item_data_set(Elm_Widget_Item *item,
2429 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2430 if ((item->data) && (item->data != data))
2431 DBG("Replacing item %p data %p with %p", item, item->data, data);
2438 * Retrieves user-data of this item.
2440 * @param item a valid #Elm_Widget_Item to get data from.
2441 * @see elm_widget_item_data_set()
2445 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2447 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2448 return (void *)item->data;
2451 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2453 struct _Elm_Widget_Item_Tooltip
2455 Elm_Widget_Item *item;
2456 Elm_Tooltip_Item_Content_Cb func;
2457 Evas_Smart_Cb del_cb;
2461 static Evas_Object *
2462 _elm_widget_item_tooltip_label_create(void *data,
2464 void *item __UNUSED__)
2466 Evas_Object *label = elm_label_add(obj);
2469 elm_object_style_set(label, "tooltip");
2470 elm_object_text_set(label, data);
2475 _elm_widget_item_tooltip_label_del_cb(void *data,
2476 Evas_Object *obj __UNUSED__,
2477 void *event_info __UNUSED__)
2479 eina_stringshare_del(data);
2485 * Set the text to be shown in the widget item.
2487 * @param item Target item
2488 * @param text The text to set in the content
2490 * Setup the text as tooltip to object. The item can have only one tooltip,
2491 * so any previous tooltip data is removed.
2496 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item,
2499 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2500 EINA_SAFETY_ON_NULL_RETURN(text);
2502 text = eina_stringshare_add(text);
2503 _elm_widget_item_tooltip_content_cb_set
2504 (item, _elm_widget_item_tooltip_label_create, text,
2505 _elm_widget_item_tooltip_label_del_cb);
2508 static Evas_Object *
2509 _elm_widget_item_tooltip_create(void *data,
2512 Elm_Widget_Item_Tooltip *wit = data;
2513 return wit->func((void *)wit->data, obj, wit->item);
2517 _elm_widget_item_tooltip_del_cb(void *data,
2519 void *event_info __UNUSED__)
2521 Elm_Widget_Item_Tooltip *wit = data;
2522 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2529 * Set the content to be shown in the tooltip item
2531 * Setup the tooltip to item. The item can have only one tooltip,
2532 * so any previous tooltip data is removed. @p func(with @p data) will
2533 * be called every time that need show the tooltip and it should
2534 * return a valid Evas_Object. This object is then managed fully by
2535 * tooltip system and is deleted when the tooltip is gone.
2537 * @param item the widget item being attached a tooltip.
2538 * @param func the function used to create the tooltip contents.
2539 * @param data what to provide to @a func as callback data/context.
2540 * @param del_cb called when data is not needed anymore, either when
2541 * another callback replaces @func, the tooltip is unset with
2542 * elm_widget_item_tooltip_unset() or the owner @a item
2543 * dies. This callback receives as the first parameter the
2544 * given @a data, and @c event_info is the item.
2549 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item,
2550 Elm_Tooltip_Item_Content_Cb func,
2552 Evas_Smart_Cb del_cb)
2554 Elm_Widget_Item_Tooltip *wit;
2556 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2560 _elm_widget_item_tooltip_unset(item);
2564 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2565 if (!wit) goto error;
2569 wit->del_cb = del_cb;
2571 elm_object_sub_tooltip_content_cb_set
2572 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2573 _elm_widget_item_tooltip_del_cb);
2578 if (del_cb) del_cb((void *)data, NULL, item);
2581 if (del_cb) del_cb((void *)data, item->widget, item);
2587 * Unset tooltip from item
2589 * @param item widget item to remove previously set tooltip.
2591 * Remove tooltip from item. The callback provided as del_cb to
2592 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2593 * it is not used anymore.
2595 * @see elm_widget_item_tooltip_content_cb_set()
2600 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2602 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2603 elm_object_tooltip_unset(item->view);
2609 * Sets a different style for this item tooltip.
2611 * @note before you set a style you should define a tooltip with
2612 * elm_widget_item_tooltip_content_cb_set() or
2613 * elm_widget_item_tooltip_text_set()
2615 * @param item widget item with tooltip already set.
2616 * @param style the theme style to use (default, transparent, ...)
2621 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item,
2624 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2625 elm_object_tooltip_style_set(item->view, style);
2631 * Get the style for this item tooltip.
2633 * @param item widget item with tooltip already set.
2634 * @return style the theme style in use, defaults to "default". If the
2635 * object does not have a tooltip set, then NULL is returned.
2640 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2642 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2643 return elm_object_tooltip_style_get(item->view);
2647 _elm_widget_item_cursor_set(Elm_Widget_Item *item,
2650 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2651 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2655 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2657 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2658 return elm_object_cursor_get(item->view);
2662 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2664 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2665 elm_object_cursor_unset(item->view);
2671 * Sets a different style for this item cursor.
2673 * @note before you set a style you should define a cursor with
2674 * elm_widget_item_cursor_set()
2676 * @param item widget item with cursor already set.
2677 * @param style the theme style to use (default, transparent, ...)
2682 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item,
2685 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2686 elm_object_cursor_style_set(item->view, style);
2692 * Get the style for this item cursor.
2694 * @param item widget item with cursor already set.
2695 * @return style the theme style in use, defaults to "default". If the
2696 * object does not have a cursor set, then NULL is returned.
2701 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2703 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2704 return elm_object_cursor_style_get(item->view);
2710 * Set if the cursor set should be searched on the theme or should use
2711 * the provided by the engine, only.
2713 * @note before you set if should look on theme you should define a cursor
2714 * with elm_object_cursor_set(). By default it will only look for cursors
2715 * provided by the engine.
2717 * @param item widget item with cursor already set.
2718 * @param engine_only boolean to define it cursors should be looked only
2719 * between the provided by the engine or searched on widget's theme as well.
2724 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item,
2725 Eina_Bool engine_only)
2727 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2728 elm_object_cursor_engine_only_set(item->view, engine_only);
2734 * Get the cursor engine only usage for this item cursor.
2736 * @param item widget item with cursor already set.
2737 * @return engine_only boolean to define it cursors should be looked only
2738 * between the provided by the engine or searched on widget's theme as well. If
2739 * the object does not have a cursor set, then EINA_FALSE is returned.
2744 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2746 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2747 return elm_object_cursor_engine_only_get(item->view);
2750 // smart object funcs
2752 _smart_reconfigure(Smart_Data *sd)
2756 evas_object_move(sd->resize_obj, sd->x, sd->y);
2757 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2761 evas_object_move(sd->hover_obj, sd->x, sd->y);
2762 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2767 _smart_add(Evas_Object *obj)
2771 sd = calloc(1, sizeof(Smart_Data));
2774 sd->x = sd->y = sd->w = sd->h = 0;
2776 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2777 evas_object_smart_data_set(obj, sd);
2780 static Evas_Object *
2781 _newest_focus_order_get(Evas_Object *obj,
2782 unsigned int *newest_focus_order,
2783 Eina_Bool can_focus_only)
2786 Evas_Object *child, *ret, *best;
2788 API_ENTRY return NULL;
2790 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
2794 if (*newest_focus_order < sd->focus_order)
2796 *newest_focus_order = sd->focus_order;
2799 EINA_LIST_FOREACH(sd->subobjs, l, child)
2801 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2807 if ((!best) || (!elm_widget_can_focus_get(best)))
2814 _if_focused_revert(Evas_Object *obj,
2815 Eina_Bool can_focus_only)
2818 Evas_Object *newest = NULL;
2819 unsigned int newest_focus_order = 0;
2823 if (!sd->focused) return;
2824 if (!sd->parent_obj) return;
2826 top = elm_widget_top_get(sd->parent_obj);
2829 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2832 elm_object_unfocus(newest);
2833 elm_object_focus(newest);
2839 _smart_del(Evas_Object *obj)
2842 Edje_Signal_Data *esd;
2846 if (sd->del_pre_func) sd->del_pre_func(obj);
2849 sobj = sd->resize_obj;
2850 sd->resize_obj = NULL;
2851 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2852 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2853 evas_object_del(sobj);
2857 sobj = sd->hover_obj;
2858 sd->hover_obj = NULL;
2859 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2860 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2861 evas_object_del(sobj);
2863 EINA_LIST_FREE(sd->subobjs, sobj)
2865 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2866 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2867 evas_object_del(sobj);
2869 eina_list_free(sd->tooltips); /* should be empty anyway */
2870 eina_list_free(sd->cursors); /* should be empty anyway */
2871 EINA_LIST_FREE(sd->edje_signals, esd)
2873 eina_stringshare_del(esd->emission);
2874 eina_stringshare_del(esd->source);
2877 eina_list_free(sd->event_cb); /* should be empty anyway */
2878 if (sd->del_func) sd->del_func(obj);
2879 if (sd->style) eina_stringshare_del(sd->style);
2880 if (sd->type) eina_stringshare_del(sd->type);
2881 if (sd->theme) elm_theme_free(sd->theme);
2882 _if_focused_revert(obj, EINA_TRUE);
2887 _smart_move(Evas_Object *obj,
2894 _smart_reconfigure(sd);
2898 _smart_resize(Evas_Object *obj,
2905 _smart_reconfigure(sd);
2909 _smart_show(Evas_Object *obj)
2914 if ((list = evas_object_smart_members_get(obj)))
2916 EINA_LIST_FREE(list, o)
2918 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2919 evas_object_show(o);
2925 _smart_hide(Evas_Object *obj)
2931 list = evas_object_smart_members_get(obj);
2932 EINA_LIST_FREE(list, o)
2934 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2935 evas_object_hide(o);
2940 _smart_color_set(Evas_Object *obj,
2949 if ((list = evas_object_smart_members_get(obj)))
2951 EINA_LIST_FREE(list, o)
2953 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2954 evas_object_color_set(o, r, g, b, a);
2960 _smart_clip_set(Evas_Object *obj,
2966 if ((list = evas_object_smart_members_get(obj)))
2968 EINA_LIST_FREE(list, o)
2970 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2971 evas_object_clip_set(o, clip);
2977 _smart_clip_unset(Evas_Object *obj)
2982 if ((list = evas_object_smart_members_get(obj)))
2984 EINA_LIST_FREE(list, o)
2986 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2987 evas_object_clip_unset(o);
2993 _smart_calculate(Evas_Object *obj)
2996 if (sd->changed_func) sd->changed_func(obj);
2999 /* never need to touch this */
3003 if (_e_smart) return;
3005 static const Evas_Smart_Class sc =
3008 EVAS_SMART_CLASS_VERSION,
3026 _e_smart = evas_smart_class_new(&sc);
3030 /* happy debug functions */
3033 _sub_obj_tree_dump(const Evas_Object *obj,
3038 for (i = 0; i < lvl * 3; i++)
3041 if (_elm_widget_is(obj))
3045 printf("+ %s(%p)\n",
3049 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
3050 EINA_LIST_FOREACH(sd->subobjs, l, obj)
3052 if (obj != sd->resize_obj)
3053 _sub_obj_tree_dump(obj, lvl + 1);
3057 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
3061 _sub_obj_tree_dot_dump(const Evas_Object *obj,
3064 if (!_elm_widget_is(obj))
3068 Eina_Bool visible = evas_object_visible_get(obj);
3069 Eina_Bool disabled = elm_widget_disabled_get(obj);
3070 Eina_Bool focused = elm_widget_focus_get(obj);
3071 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
3075 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
3078 fprintf(output, ", style=bold");
3081 fprintf(output, ", color=gray28");
3083 fprintf(output, " ];\n");
3086 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
3087 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
3088 evas_object_name_get(obj), visible, disabled, focused, can_focus,
3092 fprintf(output, ", style=bold");
3095 fprintf(output, ", fontcolor=gray28");
3097 if ((disabled) || (!visible))
3098 fprintf(output, ", color=gray");
3100 fprintf(output, " ];\n");
3104 EINA_LIST_FOREACH(sd->subobjs, l, o)
3105 _sub_obj_tree_dot_dump(o, output);
3110 elm_widget_tree_dump(const Evas_Object *top)
3113 _sub_obj_tree_dump(top, 0);
3121 elm_widget_tree_dot_dump(const Evas_Object *top,
3125 if (!_elm_widget_is(top))
3127 fprintf(output, "graph " " { node [shape=record];\n");
3128 _sub_obj_tree_dot_dump(top, output);
3129 fprintf(output, "}\n");