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, Evas_Object *source, Evas_Callback_Type type, void *event_info);
34 void (*signal_func) (Evas_Object *obj, const char *emission,
36 void (*callback_add_func) (Evas_Object *obj, const char *emission,
37 const char *source, void (*func) (void *data,
38 Evas_Object *o, const char *emission,
39 const char *source), void *data);
40 void (*callback_del_func) (Evas_Object *obj, const char *emission,
41 const char *source, void (*func) (void *data,
42 Evas_Object *o, const char *emission,
43 const char *source), void *data);
44 void (*changed_func) (Evas_Object *obj);
45 Eina_Bool (*focus_next_func) (const Evas_Object *obj, Elm_Focus_Direction dir,
47 void (*on_focus_func) (void *data, Evas_Object *obj);
49 void (*on_change_func) (void *data, Evas_Object *obj);
51 void (*on_show_region_func) (void *data, Evas_Object *obj);
52 void *on_show_region_data;
53 void (*focus_region_func) (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
54 void (*on_focus_region_func) (const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
56 Evas_Coord rx, ry, rw, rh;
62 unsigned int focus_order;
63 Eina_Bool focus_order_on_calc;
65 int child_drag_x_locked;
66 int child_drag_y_locked;
68 Eina_List *edje_signals;
70 Eina_Bool drag_x_locked : 1;
71 Eina_Bool drag_y_locked : 1;
73 Eina_Bool can_focus : 1;
74 Eina_Bool child_can_focus : 1;
75 Eina_Bool focused : 1;
76 Eina_Bool highlight_ignore : 1;
77 Eina_Bool highlight_in_theme : 1;
78 Eina_Bool disabled : 1;
79 Eina_Bool is_mirrored : 1;
80 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
82 Eina_List *focus_chain;
86 struct _Edje_Signal_Data
95 struct _Elm_Event_Cb_Data {
100 /* local subsystem functions */
101 static void _smart_reconfigure(Smart_Data *sd);
102 static void _smart_add(Evas_Object *obj);
103 static void _smart_del(Evas_Object *obj);
104 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
105 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
106 static void _smart_show(Evas_Object *obj);
107 static void _smart_hide(Evas_Object *obj);
108 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
109 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
110 static void _smart_clip_unset(Evas_Object *obj);
111 static void _smart_calculate(Evas_Object *obj);
112 static void _smart_init(void);
114 static void _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only);
115 static Evas_Object *_newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only);
117 /* local subsystem globals */
118 static Evas_Smart *_e_smart = NULL;
119 static Eina_List *widtypes = NULL;
121 static unsigned int focus_order = 0;
124 static inline Eina_Bool
125 _elm_widget_is(const Evas_Object *obj)
127 const char *type = evas_object_type_get(obj);
128 return type == SMART_NAME;
131 static inline Eina_Bool
132 _is_focusable(Evas_Object *obj)
134 API_ENTRY return EINA_FALSE;
135 return sd->can_focus || (sd->child_can_focus);
139 _unfocus_parents(Evas_Object *obj)
141 for (; obj; obj = elm_widget_parent_get(obj))
143 Smart_Data *sd = evas_object_smart_data_get(obj);
145 if (!sd->focused) return;
151 _focus_parents(Evas_Object *obj)
153 for (; obj; obj = elm_widget_parent_get(obj))
155 Smart_Data *sd = evas_object_smart_data_get(obj);
157 if (sd->focused) return;
163 _sub_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
165 Smart_Data *sd = data;
167 if (_elm_widget_is(obj))
169 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
171 if (obj == sd->resize_obj)
172 sd->resize_obj = NULL;
173 else if (obj == sd->hover_obj)
174 sd->hover_obj = NULL;
176 sd->subobjs = eina_list_remove(sd->subobjs, obj);
177 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
181 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
183 Evas_Object *o = obj;
186 if (_elm_widget_is(o)) break;
187 o = evas_object_smart_parent_get(o);
191 if (!_is_focusable(o)) return;
192 elm_widget_focus_steal(o);
196 _propagate_x_drag_lock(Evas_Object *obj, int dir)
198 Smart_Data *sd = evas_object_smart_data_get(obj);
201 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
204 sd2->child_drag_x_locked += dir;
205 _propagate_x_drag_lock(sd->parent_obj, dir);
211 _propagate_y_drag_lock(Evas_Object *obj, int dir)
213 Smart_Data *sd = evas_object_smart_data_get(obj);
216 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
219 sd2->child_drag_y_locked += dir;
220 _propagate_y_drag_lock(sd->parent_obj, dir);
226 _propagate_event(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
229 Evas_Callback_Type type = (Evas_Callback_Type)(long) data;
230 Evas_Event_Flags *event_flags = NULL;
234 case EVAS_CALLBACK_KEY_DOWN:
236 Evas_Event_Key_Down *ev = event_info;
237 event_flags = &(ev->event_flags);
240 case EVAS_CALLBACK_KEY_UP:
242 Evas_Event_Key_Up *ev = event_info;
243 event_flags = &(ev->event_flags);
246 case EVAS_CALLBACK_MOUSE_WHEEL:
248 Evas_Event_Mouse_Wheel *ev = event_info;
249 event_flags = &(ev->event_flags);
256 elm_widget_event_propagate(obj, type, event_info, event_flags);
260 _parent_focus(Evas_Object *obj)
264 Evas_Object *o = elm_widget_parent_get(obj);
265 sd->focus_order_on_calc = EINA_TRUE;
267 if (sd->focused) return;
273 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
275 /* we don't want to bump a common widget ancestor's
276 focus_order *twice* while parent focusing */
277 if (!ret || (!i) || (i != focus_order))
281 if (!sd->focus_order_on_calc)
282 return; /* we don't want to override it if by means of any of the
283 callbacks below one gets to calculate our order
287 sd->focus_order = focus_order;
288 sd->focused = EINA_TRUE;
289 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
290 if (sd->focus_func) sd->focus_func(obj);
292 _elm_widget_focus_region_show(obj);
294 sd->focus_order_on_calc = EINA_FALSE;
298 _elm_object_focus_chain_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
300 Smart_Data *sd = data;
302 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
305 // exposed util funcs to elm
307 _elm_widget_type_clear(void)
311 EINA_LIST_FREE(widtypes, ptr)
313 eina_stringshare_del(*ptr);
319 _elm_widget_focus_region_show(const Evas_Object *obj)
321 Evas_Coord x, y, w, h, ox, oy;
327 o = elm_widget_parent_get(obj);
330 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
331 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
335 sd2 = evas_object_smart_data_get(o);
336 if (sd2->focus_region_func)
338 sd2->focus_region_func(o, x, y, w, h);
339 elm_widget_focus_region_get(o, &x, &y, &w, &h);
343 evas_object_geometry_get(o, &px, &py, NULL, NULL);
349 o = elm_widget_parent_get(o);
354 * @defgroup Widget Widget
357 * Exposed api for making widgets
360 elm_widget_type_register(const char **ptr)
362 widtypes = eina_list_append(widtypes, (void *)ptr);
366 elm_widget_api_check(int ver)
368 if (ver != ELM_INTERNAL_API_VERSION)
370 CRITICAL("Elementary widget api versions do not match");
377 elm_widget_add(Evas *evas)
381 obj = evas_object_smart_add(evas, _e_smart);
382 elm_widget_mirrored_set(obj, elm_mirrored_get());
387 elm_widget_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
394 elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
397 sd->del_pre_func = func;
401 elm_widget_focus_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
404 sd->focus_func = func;
408 elm_widget_activate_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
411 sd->activate_func = func;
415 elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
418 sd->disable_func = func;
422 elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
425 sd->theme_func = func;
429 elm_widget_event_hook_set(Evas_Object *obj, Eina_Bool (*func) (Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info))
432 sd->event_func = func;
436 elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
439 sd->changed_func = func;
443 elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
446 sd->signal_func = func;
450 elm_widget_signal_callback_add_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data))
453 sd->callback_add_func = func;
457 elm_widget_signal_callback_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data))
460 sd->callback_del_func = func;
464 elm_widget_theme(Evas_Object *obj)
472 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
473 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
474 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
475 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
476 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
477 if (sd->theme_func) sd->theme_func(obj);
481 elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force)
487 Elm_Theme *th2, *thdef;
490 thdef = elm_theme_default_get();
495 if (!th2) th2 = thdef;
503 if (th2 == thdef) break;
504 th2 = th2->ref_theme;
505 if (!th2) th2 = thdef;
509 EINA_LIST_FOREACH(sd->subobjs, l, child)
510 elm_widget_theme_specific(child, th, force);
511 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
512 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
513 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
514 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
515 if (sd->theme_func) sd->theme_func(obj);
521 * Set hook to get next object in object focus chain.
523 * @param obj The widget object.
524 * @param func The hook to be used with this widget.
529 elm_widget_focus_next_hook_set(Evas_Object *obj, Eina_Bool (*func) (const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next))
532 sd->focus_next_func = func;
536 * Returns the widget's mirrored mode.
538 * @param obj The widget.
539 * @return mirrored mode of the object.
543 elm_widget_mirrored_get(const Evas_Object *obj)
545 API_ENTRY return EINA_FALSE;
546 return sd->is_mirrored;
550 * Sets the widget's mirrored mode.
552 * @param obj The widget.
553 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
556 elm_widget_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
559 if (sd->is_mirrored != mirrored)
561 sd->is_mirrored = mirrored;
562 elm_widget_theme(obj);
568 * Resets the mirrored mode from the system mirror mode for widgets that are in
569 * automatic mirroring mode. This function does not call elm_widget_theme.
571 * @param obj The widget.
572 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
575 _elm_widget_mirrored_reload(Evas_Object *obj)
578 Eina_Bool mirrored = elm_mirrored_get();
579 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
581 sd->is_mirrored = mirrored;
586 * Returns the widget's mirrored mode setting.
588 * @param obj The widget.
589 * @return mirrored mode setting of the object.
593 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
595 API_ENTRY return EINA_FALSE;
596 return sd->mirrored_auto_mode;
600 * Sets the widget's mirrored mode setting.
601 * When widget in automatic mode, it follows the system mirrored mode set by
602 * elm_mirrored_set().
603 * @param obj The widget.
604 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
607 elm_widget_mirrored_automatic_set(Evas_Object *obj, Eina_Bool automatic)
610 if (sd->mirrored_auto_mode != automatic)
612 sd->mirrored_auto_mode = automatic;
616 elm_widget_mirrored_set(obj, elm_mirrored_get());
622 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
625 sd->on_focus_func = func;
626 sd->on_focus_data = data;
630 elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
633 sd->on_change_func = func;
634 sd->on_change_data = data;
638 elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
641 sd->on_show_region_func = func;
642 sd->on_show_region_data = data;
648 * Set the hook to use to show the focused region.
650 * Whenever a new widget gets focused or it's needed to show the focused
651 * area of the current one, this hook will be called on objects that may
652 * want to move their children into their visible area.
653 * The area given in the hook function is relative to the @p obj widget.
655 * @param obj The widget object
656 * @param func The function to call to show the specified area.
661 elm_widget_focus_region_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h))
664 sd->focus_region_func = func;
670 * Set the hook to retrieve the focused region of a widget.
672 * This hook will be called by elm_widget_focus_region_get() whenever
673 * it's needed to get the focused area of a widget. The area must be relative
674 * to the widget itself and if no hook is set, it will default to the entire
677 * @param obj The widget object
678 * @param func The function used to retrieve the focus region.
683 elm_widget_on_focus_region_hook_set(Evas_Object *obj, void (*func) (const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h))
686 sd->on_focus_region_func = func;
690 elm_widget_data_set(Evas_Object *obj, void *data)
697 elm_widget_data_get(const Evas_Object *obj)
699 API_ENTRY return NULL;
704 elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
707 double scale, pscale = elm_widget_scale_get(sobj);
708 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
709 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
711 if (_elm_widget_is(sobj))
713 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
716 if (sd2->parent_obj == obj)
719 elm_widget_sub_object_del(sd2->parent_obj, sobj);
720 sd2->parent_obj = obj;
721 if (!sd->child_can_focus && (_is_focusable(sobj)))
722 sd->child_can_focus = EINA_TRUE;
727 void *data = evas_object_data_get(sobj, "elm-parent");
730 if (data == obj) return;
731 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
736 sd->subobjs = eina_list_append(sd->subobjs, sobj);
737 evas_object_data_set(sobj, "elm-parent", obj);
738 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
739 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
740 scale = elm_widget_scale_get(sobj);
741 th = elm_widget_theme_get(sobj);
742 mirrored = elm_widget_mirrored_get(sobj);
743 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
744 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
748 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
750 Evas_Object *sobj_parent;
754 sobj_parent = evas_object_data_del(sobj, "elm-parent");
755 if (sobj_parent != obj)
757 static int abort_on_warn = -1;
758 ERR("removing sub object %p from parent %p, "
759 "but elm-parent is different %p!",
760 sobj, obj, sobj_parent);
761 if (EINA_UNLIKELY(abort_on_warn == -1))
763 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
764 else abort_on_warn = 0;
766 if (abort_on_warn == 1) abort();
768 if (!sd->child_can_focus)
770 if (_is_focusable(sobj)) sd->child_can_focus = 0;
772 if (_elm_widget_is(sobj))
774 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
777 sd2->parent_obj = NULL;
778 if (sd2->resize_obj == sobj)
779 sd2->resize_obj = NULL;
781 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
784 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
785 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
788 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
789 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
791 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
795 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
798 // orphan previous resize obj
801 evas_object_clip_unset(sd->resize_obj);
802 evas_object_data_del(sd->resize_obj, "elm-parent");
803 if (_elm_widget_is(sd->resize_obj))
805 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
806 if (sd2) sd2->parent_obj = NULL;
808 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
810 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
811 _sub_obj_mouse_down, sd);
812 evas_object_smart_member_del(sd->resize_obj);
813 if (_elm_widget_is(sd->resize_obj))
815 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
818 // orphan new resize obj
821 evas_object_data_del(sobj, "elm-parent");
822 if (_elm_widget_is(sobj))
824 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
825 if (sd2) sd2->parent_obj = NULL;
827 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
829 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
830 _sub_obj_mouse_down, sd);
831 evas_object_smart_member_del(sobj);
832 if (_elm_widget_is(sobj))
834 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
837 // set the resize obj up
838 sd->resize_obj = sobj;
841 if (_elm_widget_is(sd->resize_obj))
843 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
844 if (sd2) sd2->parent_obj = obj;
846 evas_object_clip_set(sobj, evas_object_clip_get(obj));
847 evas_object_smart_member_add(sobj, obj);
848 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
850 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
851 _sub_obj_mouse_down, sd);
852 _smart_reconfigure(sd);
853 evas_object_data_set(sobj, "elm-parent", obj);
854 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
855 if (_elm_widget_is(sobj))
857 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
863 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
868 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
871 sd->hover_obj = sobj;
874 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
876 _smart_reconfigure(sd);
881 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
884 sd->can_focus = can_focus;
887 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
889 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
890 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
892 (void *)(long) EVAS_CALLBACK_KEY_UP);
893 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
895 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
899 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
901 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
903 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
909 elm_widget_can_focus_get(const Evas_Object *obj)
911 API_ENTRY return EINA_FALSE;
912 return sd->can_focus;
916 elm_widget_child_can_focus_get(const Evas_Object *obj)
918 API_ENTRY return EINA_FALSE;
919 return sd->child_can_focus;
923 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
926 sd->highlight_ignore = !!ignore;
930 elm_widget_highlight_ignore_get(const Evas_Object *obj)
932 API_ENTRY return EINA_FALSE;
933 return sd->highlight_ignore;
937 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
940 sd->highlight_in_theme = !!highlight;
941 /* FIXME: if focused, it should switch from one mode to the other */
945 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
947 API_ENTRY return EINA_FALSE;
948 return sd->highlight_in_theme;
952 elm_widget_focus_get(const Evas_Object *obj)
954 API_ENTRY return EINA_FALSE;
959 elm_widget_focused_object_get(const Evas_Object *obj)
961 const Evas_Object *subobj;
963 API_ENTRY return NULL;
965 if (!sd->focused) return NULL;
966 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
968 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
969 if (fobj) return fobj;
971 return (Evas_Object *)obj;
975 elm_widget_top_get(const Evas_Object *obj)
977 API_ENTRY return NULL;
978 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
979 return (Evas_Object *)obj;
983 elm_widget_is(const Evas_Object *obj)
985 return _elm_widget_is(obj);
989 elm_widget_parent_widget_get(const Evas_Object *obj)
993 if (_elm_widget_is(obj))
995 Smart_Data *sd = evas_object_smart_data_get(obj);
996 if (!sd) return NULL;
997 parent = sd->parent_obj;
1001 parent = evas_object_data_get(obj, "elm-parent");
1002 if (!parent) parent = evas_object_smart_parent_get(obj);
1007 Evas_Object *elm_parent;
1008 if (_elm_widget_is(parent)) break;
1009 elm_parent = evas_object_data_get(parent, "elm-parent");
1010 if (elm_parent) parent = elm_parent;
1011 else parent = evas_object_smart_parent_get(parent);
1017 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1020 EINA_SAFETY_ON_NULL_RETURN(func);
1021 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1024 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1028 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1030 API_ENTRY return NULL;
1031 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1033 Elm_Event_Cb_Data *ecd;
1034 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1035 if ((ecd->func == func) && (ecd->data == data))
1038 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1039 return (void *)data;
1045 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
1047 API_ENTRY return EINA_FALSE; //TODO reduce.
1048 if (!_elm_widget_is(obj)) return EINA_FALSE;
1049 Evas_Object *parent = obj;
1050 Elm_Event_Cb_Data *ecd;
1051 Eina_List *l, *l_prev;
1054 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1056 sd = evas_object_smart_data_get(parent);
1057 if ((!sd) || (!_elm_widget_is(obj)))
1058 return EINA_FALSE; //Not Elm Widget
1060 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1063 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1065 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1066 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1069 parent = sd->parent_obj;
1078 * Set custom focus chain.
1080 * This function i set one new and overwrite any previous custom focus chain
1081 * with the list of objects. The previous list will be deleted and this list
1082 * will be managed. After setted, don't modity it.
1084 * @note On focus cycle, only will be evaluated children of this container.
1086 * @param obj The container widget
1087 * @param objs Chain of objects to pass focus
1091 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1094 if (!sd->focus_next_func)
1097 elm_widget_focus_custom_chain_unset(obj);
1102 EINA_LIST_FOREACH(objs, l, o)
1104 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1105 _elm_object_focus_chain_del_cb, sd);
1108 sd->focus_chain = objs;
1114 * Get custom focus chain
1116 * @param obj The container widget
1119 EAPI const Eina_List *
1120 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1122 API_ENTRY return NULL;
1123 return (const Eina_List *) sd->focus_chain;
1129 * Unset custom focus chain
1131 * @param obj The container widget
1135 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1138 Eina_List *l, *l_next;
1141 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1143 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1144 _elm_object_focus_chain_del_cb, sd);
1145 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1152 * Append object to custom focus chain.
1154 * @note If relative_child equal to NULL or not in custom chain, the object
1155 * will be added in end.
1157 * @note On focus cycle, only will be evaluated children of this container.
1159 * @param obj The container widget
1160 * @param child The child to be added in custom chain
1161 * @param relative_child The relative object to position the child
1165 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1168 EINA_SAFETY_ON_NULL_RETURN(child);
1169 if (!sd->focus_next_func)
1172 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1173 _elm_object_focus_chain_del_cb, sd);
1175 if (!relative_child)
1177 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1181 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1188 * Prepend object to custom focus chain.
1190 * @note If relative_child equal to NULL or not in custom chain, the object
1191 * will be added in begin.
1193 * @note On focus cycle, only will be evaluated children of this container.
1195 * @param obj The container widget
1196 * @param child The child to be added in custom chain
1197 * @param relative_child The relative object to position the child
1201 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1204 EINA_SAFETY_ON_NULL_RETURN(child);
1205 if (!sd->focus_next_func)
1208 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1209 _elm_object_focus_chain_del_cb, sd);
1211 if (!relative_child)
1213 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1217 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1224 * Give focus to next object in object tree.
1226 * Give focus to next object in focus chain of one object sub-tree.
1227 * If the last object of chain already have focus, the focus will go to the
1228 * first object of chain.
1230 * @param obj The widget root of sub-tree
1231 * @param dir Direction to cycle the focus
1236 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1238 Evas_Object *target = NULL;
1239 if (!_elm_widget_is(obj))
1241 elm_widget_focus_next_get(obj, dir, &target);
1243 elm_widget_focus_steal(target);
1249 * Give focus to near object in one direction.
1251 * Give focus to near object in direction of one object.
1252 * If none focusable object in given direction, the focus will not change.
1254 * @param obj The reference widget
1255 * @param x Horizontal component of direction to focus
1256 * @param y Vertical component of direction to focus
1261 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1269 * Get next object in focus chain of object tree.
1271 * Get next object in focus chain of one object sub-tree.
1272 * Return the next object by reference. If don't have any candidate to receive
1273 * focus before chain end, the first candidate will be returned.
1275 * @param obj The widget root of sub-tree
1276 * @param dir Direction os focus chain
1277 * @param next The next object in focus chain
1278 * @return EINA_TRUE if don't need focus chain restart/loop back
1279 * to use 'next' obj.
1284 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1290 API_ENTRY return EINA_FALSE;
1292 /* Ignore if disabled */
1293 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1297 if (sd->focus_next_func)
1298 return sd->focus_next_func(obj, dir, next);
1300 if (!elm_widget_can_focus_get(obj))
1304 *next = (Evas_Object *)obj;
1305 return !elm_widget_focus_get(obj);
1312 * Get next object in focus chain of object tree in list.
1314 * Get next object in focus chain of one object sub-tree ordered by one list.
1315 * Return the next object by reference. If don't have any candidate to receive
1316 * focus before list end, the first candidate will be returned.
1318 * @param obj The widget root of sub-tree
1319 * @param dir Direction os focus chain
1320 * @param items list with ordered objects
1321 * @param list_data_get function to get the object from one item of list
1322 * @param next The next object in focus chain
1323 * @return EINA_TRUE if don't need focus chain restart/loop back
1324 * to use 'next' obj.
1329 elm_widget_focus_list_next_get(const Evas_Object *obj, const Eina_List *items, void *(*list_data_get) (const Eina_List *list), Elm_Focus_Direction dir, Evas_Object **next)
1331 Eina_List *(*list_next) (const Eina_List *list);
1337 if (!_elm_widget_is(obj))
1344 if (dir == ELM_FOCUS_PREVIOUS)
1346 items = eina_list_last(items);
1347 list_next = eina_list_prev;
1349 else if (dir == ELM_FOCUS_NEXT)
1350 list_next = eina_list_next;
1354 const Eina_List *l = items;
1356 /* Recovery last focused sub item */
1357 if (elm_widget_focus_get(obj))
1358 for (; l; l = list_next(l))
1360 Evas_Object *cur = list_data_get(l);
1361 if (elm_widget_focus_get(cur)) break;
1364 const Eina_List *start = l;
1365 Evas_Object *to_focus = NULL;
1367 /* Interate sub items */
1368 /* Go to end of list */
1369 for (; l; l = list_next(l))
1371 Evas_Object *tmp = NULL;
1372 Evas_Object *cur = list_data_get(l);
1374 if (elm_widget_parent_get(cur) != obj)
1377 /* Try Focus cycle in subitem */
1378 if (elm_widget_focus_next_get(cur, dir, &tmp))
1383 else if ((tmp) && (!to_focus))
1389 /* Get First possible */
1390 for (;l != start; l = list_next(l))
1392 Evas_Object *tmp = NULL;
1393 Evas_Object *cur = list_data_get(l);
1395 if (elm_widget_parent_get(cur) != obj)
1398 /* Try Focus cycle in subitem */
1399 elm_widget_focus_next_get(cur, dir, &tmp);
1412 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1415 if (!sd->signal_func) return;
1416 sd->signal_func(obj, emission, source);
1420 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1422 Edje_Signal_Data *esd = data;
1423 esd->func(esd->data, esd->obj, emission, source);
1427 elm_widget_signal_callback_add(Evas_Object *obj, const char *emission, const char *source, void (*func) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
1429 Edje_Signal_Data *esd;
1431 if (!sd->callback_add_func) return;
1432 EINA_SAFETY_ON_NULL_RETURN(func);
1434 esd = ELM_NEW(Edje_Signal_Data);
1439 esd->emission = eina_stringshare_add(emission);
1440 esd->source = eina_stringshare_add(source);
1442 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1443 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1447 elm_widget_signal_callback_del(Evas_Object *obj, const char *emission, const char *source, void (*func) (void *data, Evas_Object *o, const char *emission, const char *source))
1449 Edje_Signal_Data *esd;
1452 API_ENTRY return NULL;
1453 if (!sd->callback_del_func) return NULL;
1455 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1457 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1458 (!strcmp(esd->source, source)))
1460 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1461 eina_stringshare_del(esd->emission);
1462 eina_stringshare_del(esd->source);
1468 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1473 elm_widget_focus_set(Evas_Object *obj, int first)
1479 sd->focus_order = focus_order;
1480 sd->focused = EINA_TRUE;
1481 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1485 sd->focus_func(obj);
1492 if ((_is_focusable(sd->resize_obj)) &&
1493 (!elm_widget_disabled_get(sd->resize_obj)))
1495 elm_widget_focus_set(sd->resize_obj, first);
1501 EINA_LIST_FOREACH(sd->subobjs, l, child)
1503 if ((_is_focusable(child)) &&
1504 (!elm_widget_disabled_get(child)))
1506 elm_widget_focus_set(child, first);
1516 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1518 if ((_is_focusable(child)) &&
1519 (!elm_widget_disabled_get(child)))
1521 elm_widget_focus_set(child, first);
1527 if ((_is_focusable(sd->resize_obj)) &&
1528 (!elm_widget_disabled_get(sd->resize_obj)))
1530 elm_widget_focus_set(sd->resize_obj, first);
1538 elm_widget_parent_get(const Evas_Object *obj)
1540 API_ENTRY return NULL;
1541 return sd->parent_obj;
1545 elm_widget_focused_object_clear(Evas_Object *obj)
1548 if (!sd->focused) return;
1549 if (elm_widget_focus_get(sd->resize_obj))
1550 elm_widget_focused_object_clear(sd->resize_obj);
1555 EINA_LIST_FOREACH(sd->subobjs, l, child)
1557 if (elm_widget_focus_get(child))
1559 elm_widget_focused_object_clear(child);
1564 sd->focused = EINA_FALSE;
1565 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1566 if (sd->focus_func) sd->focus_func(obj);
1570 elm_widget_focus_steal(Evas_Object *obj)
1572 Evas_Object *parent, *o;
1575 if (sd->focused) return;
1576 if (sd->disabled) return;
1580 o = elm_widget_parent_get(parent);
1582 sd = evas_object_smart_data_get(o);
1583 if (sd->focused) break;
1586 if (!elm_widget_parent_get(parent))
1587 elm_widget_focused_object_clear(parent);
1590 parent = elm_widget_parent_get(parent);
1591 sd = evas_object_smart_data_get(parent);
1592 if (elm_widget_focus_get(sd->resize_obj))
1594 elm_widget_focused_object_clear(sd->resize_obj);
1600 EINA_LIST_FOREACH(sd->subobjs, l, child)
1602 if (elm_widget_focus_get(child))
1604 elm_widget_focused_object_clear(child);
1615 elm_widget_activate(Evas_Object *obj)
1618 elm_widget_change(obj);
1619 if (sd->activate_func) sd->activate_func(obj);
1623 elm_widget_change(Evas_Object *obj)
1626 elm_widget_change(elm_widget_parent_get(obj));
1627 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1631 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1635 if (sd->disabled == disabled) return;
1636 sd->disabled = disabled;
1639 Evas_Object *o, *parent;
1644 o = elm_widget_parent_get(parent);
1648 if (elm_widget_focus_get(obj))
1649 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1651 if (sd->disable_func) sd->disable_func(obj);
1655 elm_widget_disabled_get(const Evas_Object *obj)
1658 return sd->disabled;
1662 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1664 Evas_Object *parent_obj, *child_obj;
1665 Evas_Coord px, py, cx, cy;
1668 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1673 if (sd->on_show_region_func)
1674 sd->on_show_region_func(sd->on_show_region_data, obj);
1678 parent_obj = sd->parent_obj;
1679 child_obj = sd->obj;
1680 sd = evas_object_smart_data_get(parent_obj);
1682 if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
1684 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1685 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1694 if (sd->on_show_region_func)
1696 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1703 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1715 * Get the focus region of the given widget.
1717 * The focus region is the area of a widget that should brought into the
1718 * visible area when the widget is focused. Mostly used to show the part of
1719 * an entry where the cursor is, for example. The area returned is relative
1720 * to the object @p obj.
1721 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1722 * function will return the full size of the object.
1724 * @param obj The widget object
1725 * @param x Where to store the x coordinate of the area
1726 * @param y Where to store the y coordinate of the area
1727 * @param w Where to store the width of the area
1728 * @param h Where to store the height of the area
1733 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1739 sd = evas_object_smart_data_get(obj);
1740 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1742 evas_object_geometry_get(obj, NULL, NULL, w, h);
1747 sd->on_focus_region_func(obj, x, y, w, h);
1751 elm_widget_scroll_hold_push(Evas_Object *obj)
1755 if (sd->scroll_hold == 1)
1756 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1757 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1758 // FIXME: on delete/reparent hold pop
1762 elm_widget_scroll_hold_pop(Evas_Object *obj)
1766 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1767 if (!sd->scroll_hold)
1768 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1769 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1773 elm_widget_scroll_hold_get(const Evas_Object *obj)
1776 return sd->scroll_hold;
1780 elm_widget_scroll_freeze_push(Evas_Object *obj)
1783 sd->scroll_freeze++;
1784 if (sd->scroll_freeze == 1)
1785 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1786 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1787 // FIXME: on delete/reparent freeze pop
1791 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1794 sd->scroll_freeze--;
1795 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1796 if (!sd->scroll_freeze)
1797 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1798 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1802 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1805 return sd->scroll_freeze;
1809 elm_widget_scale_set(Evas_Object *obj, double scale)
1812 if (scale <= 0.0) scale = 0.0;
1813 if (sd->scale != scale)
1816 elm_widget_theme(obj);
1821 elm_widget_scale_get(const Evas_Object *obj)
1823 API_ENTRY return 1.0;
1824 // FIXME: save walking up the tree by storing/caching parent scale
1825 if (sd->scale == 0.0)
1828 return elm_widget_scale_get(sd->parent_obj);
1836 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1839 if (sd->theme != th)
1841 if (sd->theme) elm_theme_free(sd->theme);
1844 elm_widget_theme(obj);
1849 elm_widget_theme_get(const Evas_Object *obj)
1851 API_ENTRY return NULL;
1855 return elm_widget_theme_get(sd->parent_obj);
1863 elm_widget_style_set(Evas_Object *obj, const char *style)
1867 if (eina_stringshare_replace(&sd->style, style))
1868 elm_widget_theme(obj);
1872 elm_widget_style_get(const Evas_Object *obj)
1874 API_ENTRY return NULL;
1875 if (sd->style) return sd->style;
1880 elm_widget_type_set(Evas_Object *obj, const char *type)
1883 eina_stringshare_replace(&sd->type, type);
1887 elm_widget_type_get(const Evas_Object *obj)
1889 API_ENTRY return NULL;
1890 if (sd->type) return sd->type;
1895 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1898 sd->tooltips = eina_list_append(sd->tooltips, tt);
1902 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1905 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1909 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1912 sd->cursors = eina_list_append(sd->cursors, cur);
1916 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1919 sd->cursors = eina_list_remove(sd->cursors, cur);
1923 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1926 if (sd->drag_x_locked == lock) return;
1927 sd->drag_x_locked = lock;
1928 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1929 else _propagate_x_drag_lock(obj, -1);
1933 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1936 if (sd->drag_y_locked == lock) return;
1937 sd->drag_y_locked = lock;
1938 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1939 else _propagate_y_drag_lock(obj, -1);
1943 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1945 API_ENTRY return EINA_FALSE;
1946 return sd->drag_x_locked;
1950 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1952 API_ENTRY return EINA_FALSE;
1953 return sd->drag_y_locked;
1957 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1960 return sd->child_drag_x_locked;
1964 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1967 return sd->child_drag_y_locked;
1971 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1973 API_ENTRY return EINA_FALSE;
1974 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1978 elm_widget_type_check(const Evas_Object *obj, const char *type)
1980 const char *provided, *expected = "(unknown)";
1981 static int abort_on_warn = -1;
1982 provided = elm_widget_type_get(obj);
1983 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1984 if (type) expected = type;
1985 if ((!provided) || (!provided[0]))
1987 provided = evas_object_type_get(obj);
1988 if ((!provided) || (!provided[0]))
1989 provided = "(unknown)";
1991 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
1992 if (abort_on_warn == -1)
1994 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1995 else abort_on_warn = 0;
1997 if (abort_on_warn == 1) abort();
2004 * Split string in words
2006 * @param str Source string
2007 * @return List of const words
2009 * @see elm_widget_stringlist_free()
2013 elm_widget_stringlist_get(const char *str)
2015 Eina_List *list = NULL;
2017 if (!str) return NULL;
2018 for (b = s = str; 1; s++)
2020 if ((*s == ' ') || (!*s))
2022 char *t = malloc(s - b + 1);
2025 strncpy(t, b, s - b);
2027 list = eina_list_append(list, eina_stringshare_add(t));
2038 elm_widget_stringlist_free(Eina_List *list)
2041 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2047 * Allocate a new Elm_Widget_Item-derived structure.
2049 * The goal of this structure is to provide common ground for actions
2050 * that a widget item have, such as the owner widget, callback to
2051 * notify deletion, data pointer and maybe more.
2053 * @param widget the owner widget that holds this item, must be an elm_widget!
2054 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2055 * be used to allocate memory.
2057 * @return allocated memory that is already zeroed out, or NULL on errors.
2059 * @see elm_widget_item_new() convenience macro.
2060 * @see elm_widget_item_del() to release memory.
2063 EAPI Elm_Widget_Item *
2064 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
2066 if (!_elm_widget_is(widget))
2069 Elm_Widget_Item *item;
2071 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2072 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2074 item = calloc(1, alloc_size);
2075 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2077 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2078 item->widget = widget;
2085 * Releases widget item memory, calling back del_cb() if it exists.
2087 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2088 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2089 * this function and then unset it, thus being useful for 2 step
2090 * cleanup whenever the del_cb may use any of the data that must be
2091 * deleted from item.
2093 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2096 * @param item a valid #Elm_Widget_Item to be deleted.
2097 * @see elm_widget_item_del() convenience macro.
2101 _elm_widget_item_del(Elm_Widget_Item *item)
2103 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2106 item->del_cb((void *)item->data, item->widget, item);
2109 evas_object_del(item->view);
2111 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2118 * Notify object will be deleted without actually deleting it.
2120 * This function will callback Elm_Widget_Item::del_cb if it is set
2121 * and then unset it so it is not called twice (ie: from
2122 * elm_widget_item_del()).
2124 * @param item a valid #Elm_Widget_Item to be notified
2125 * @see elm_widget_item_pre_notify_del() convenience macro.
2129 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2131 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2132 if (!item->del_cb) return;
2133 item->del_cb((void *)item->data, item->widget, item);
2134 item->del_cb = NULL;
2140 * Set the function to notify when item is being deleted.
2142 * This function will complain if there was a callback set already,
2143 * however it will set the new one.
2145 * The callback will be called from elm_widget_item_pre_notify_del()
2146 * or elm_widget_item_del() will be called with:
2147 * - data: the Elm_Widget_Item::data value.
2148 * - obj: the Elm_Widget_Item::widget evas object.
2149 * - event_info: the item being deleted.
2151 * @param item a valid #Elm_Widget_Item to be notified
2152 * @see elm_widget_item_del_cb_set() convenience macro.
2156 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2158 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2160 if ((item->del_cb) && (item->del_cb != del_cb))
2161 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2162 item->del_cb, item, del_cb);
2164 item->del_cb = del_cb;
2170 * Set user-data in this item.
2172 * User data may be used to identify this item or just store any
2173 * application data. It is automatically given as the first parameter
2174 * of the deletion notify callback.
2176 * @param item a valid #Elm_Widget_Item to store data in.
2177 * @param data user data to store.
2178 * @see elm_widget_item_del_cb_set() convenience macro.
2182 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2184 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2185 if ((item->data) && (item->data != data))
2186 DBG("Replacing item %p data %p with %p", item, item->data, data);
2193 * Retrieves user-data of this item.
2195 * @param item a valid #Elm_Widget_Item to get data from.
2196 * @see elm_widget_item_data_set()
2200 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2202 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2203 return (void *)item->data;
2206 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2208 struct _Elm_Widget_Item_Tooltip
2210 Elm_Widget_Item *item;
2211 Elm_Tooltip_Item_Content_Cb func;
2212 Evas_Smart_Cb del_cb;
2216 static Evas_Object *
2217 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2219 Evas_Object *label = elm_label_add(obj);
2222 elm_object_style_set(label, "tooltip");
2223 elm_label_label_set(label, data);
2228 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2230 eina_stringshare_del(data);
2236 * Set the text to be shown in the widget item.
2238 * @param item Target item
2239 * @param text The text to set in the content
2241 * Setup the text as tooltip to object. The item can have only one tooltip,
2242 * so any previous tooltip data is removed.
2247 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2249 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2250 EINA_SAFETY_ON_NULL_RETURN(text);
2252 text = eina_stringshare_add(text);
2253 _elm_widget_item_tooltip_content_cb_set
2254 (item, _elm_widget_item_tooltip_label_create, text,
2255 _elm_widget_item_tooltip_label_del_cb);
2258 static Evas_Object *
2259 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2261 Elm_Widget_Item_Tooltip *wit = data;
2262 return wit->func((void *)wit->data, obj, wit->item);
2266 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2268 Elm_Widget_Item_Tooltip *wit = data;
2269 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2276 * Set the content to be shown in the tooltip item
2278 * Setup the tooltip to item. The item can have only one tooltip,
2279 * so any previous tooltip data is removed. @p func(with @p data) will
2280 * be called every time that need show the tooltip and it should
2281 * return a valid Evas_Object. This object is then managed fully by
2282 * tooltip system and is deleted when the tooltip is gone.
2284 * @param item the widget item being attached a tooltip.
2285 * @param func the function used to create the tooltip contents.
2286 * @param data what to provide to @a func as callback data/context.
2287 * @param del_cb called when data is not needed anymore, either when
2288 * another callback replaces @func, the tooltip is unset with
2289 * elm_widget_item_tooltip_unset() or the owner @a item
2290 * dies. This callback receives as the first parameter the
2291 * given @a data, and @c event_info is the item.
2296 _elm_widget_item_tooltip_content_cb_set(Elm_Widget_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
2298 Elm_Widget_Item_Tooltip *wit;
2300 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2304 _elm_widget_item_tooltip_unset(item);
2308 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2309 if (!wit) goto error;
2313 wit->del_cb = del_cb;
2315 elm_object_sub_tooltip_content_cb_set
2316 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2317 _elm_widget_item_tooltip_del_cb);
2322 if (del_cb) del_cb((void *)data, NULL, item);
2325 if (del_cb) del_cb((void *)data, item->widget, item);
2331 * Unset tooltip from item
2333 * @param item widget item to remove previously set tooltip.
2335 * Remove tooltip from item. The callback provided as del_cb to
2336 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2337 * it is not used anymore.
2339 * @see elm_widget_item_tooltip_content_cb_set()
2344 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2346 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2347 elm_object_tooltip_unset(item->view);
2353 * Sets a different style for this item tooltip.
2355 * @note before you set a style you should define a tooltip with
2356 * elm_widget_item_tooltip_content_cb_set() or
2357 * elm_widget_item_tooltip_text_set()
2359 * @param item widget item with tooltip already set.
2360 * @param style the theme style to use (default, transparent, ...)
2365 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2367 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2368 elm_object_tooltip_style_set(item->view, style);
2374 * Get the style for this item tooltip.
2376 * @param item widget item with tooltip already set.
2377 * @return style the theme style in use, defaults to "default". If the
2378 * object does not have a tooltip set, then NULL is returned.
2383 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2385 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2386 return elm_object_tooltip_style_get(item->view);
2390 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2392 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2393 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2397 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2399 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2400 return elm_object_cursor_get(item->view);
2404 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2406 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2407 elm_object_cursor_unset(item->view);
2413 * Sets a different style for this item cursor.
2415 * @note before you set a style you should define a cursor with
2416 * elm_widget_item_cursor_set()
2418 * @param item widget item with cursor already set.
2419 * @param style the theme style to use (default, transparent, ...)
2424 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2426 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2427 elm_object_cursor_style_set(item->view, style);
2433 * Get the style for this item cursor.
2435 * @param item widget item with cursor already set.
2436 * @return style the theme style in use, defaults to "default". If the
2437 * object does not have a cursor set, then NULL is returned.
2442 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2444 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2445 return elm_object_cursor_style_get(item->view);
2451 * Set if the cursor set should be searched on the theme or should use
2452 * the provided by the engine, only.
2454 * @note before you set if should look on theme you should define a cursor
2455 * with elm_object_cursor_set(). By default it will only look for cursors
2456 * provided by the engine.
2458 * @param item widget item with cursor already set.
2459 * @param engine_only boolean to define it cursors should be looked only
2460 * between the provided by the engine or searched on widget's theme as well.
2465 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2467 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2468 elm_object_cursor_engine_only_set(item->view, engine_only);
2474 * Get the cursor engine only usage for this item cursor.
2476 * @param item widget item with cursor already set.
2477 * @return engine_only boolean to define it cursors should be looked only
2478 * between the provided by the engine or searched on widget's theme as well. If
2479 * the object does not have a cursor set, then EINA_FALSE is returned.
2484 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2486 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2487 return elm_object_cursor_engine_only_get(item->view);
2490 // smart object funcs
2492 _smart_reconfigure(Smart_Data *sd)
2496 evas_object_move(sd->resize_obj, sd->x, sd->y);
2497 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2501 evas_object_move(sd->hover_obj, sd->x, sd->y);
2502 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2507 _smart_add(Evas_Object *obj)
2511 sd = calloc(1, sizeof(Smart_Data));
2514 sd->x = sd->y = sd->w = sd->h = 0;
2516 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2517 evas_object_smart_data_set(obj, sd);
2520 static Evas_Object *
2521 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2524 Evas_Object *child, *ret, *best;
2526 API_ENTRY return NULL;
2527 if (!evas_object_visible_get(obj)) return NULL;
2529 if (*newest_focus_order < sd->focus_order)
2531 *newest_focus_order = sd->focus_order;
2534 EINA_LIST_FOREACH(sd->subobjs, l, child)
2536 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2540 if ((can_focus_only) && (!elm_widget_can_focus_get(best))) return NULL;
2545 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2548 Evas_Object *newest = NULL;
2549 unsigned int newest_focus_order = 0;
2553 if (!sd->focused) return;
2554 if (!sd->parent_obj) return;
2556 top = elm_widget_top_get(sd->parent_obj);
2559 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2562 elm_object_unfocus(newest);
2563 elm_object_focus(newest);
2569 _smart_del(Evas_Object *obj)
2572 Edje_Signal_Data *esd;
2576 if (sd->del_pre_func) sd->del_pre_func(obj);
2579 sobj = sd->resize_obj;
2580 sd->resize_obj = NULL;
2581 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2582 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2583 evas_object_del(sobj);
2587 sobj = sd->hover_obj;
2588 sd->hover_obj = NULL;
2589 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2590 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2591 evas_object_del(sobj);
2593 EINA_LIST_FREE(sd->subobjs, sobj)
2595 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2596 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2597 evas_object_del(sobj);
2599 eina_list_free(sd->tooltips); /* should be empty anyway */
2600 eina_list_free(sd->cursors); /* should be empty anyway */
2601 EINA_LIST_FREE(sd->edje_signals, esd)
2603 eina_stringshare_del(esd->emission);
2604 eina_stringshare_del(esd->source);
2607 eina_list_free(sd->event_cb); /* should be empty anyway */
2608 if (sd->del_func) sd->del_func(obj);
2609 if (sd->style) eina_stringshare_del(sd->style);
2610 if (sd->type) eina_stringshare_del(sd->type);
2611 if (sd->theme) elm_theme_free(sd->theme);
2612 _if_focused_revert(obj, EINA_TRUE);
2617 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2622 _smart_reconfigure(sd);
2626 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2631 _smart_reconfigure(sd);
2635 _smart_show(Evas_Object *obj)
2640 if ((list = evas_object_smart_members_get(obj)))
2642 EINA_LIST_FREE(list, o)
2644 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2645 evas_object_show(o);
2651 _smart_hide(Evas_Object *obj)
2656 list = evas_object_smart_members_get(obj);
2657 EINA_LIST_FREE(list, o)
2659 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2660 evas_object_hide(o);
2662 _if_focused_revert(obj, EINA_TRUE);
2666 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2671 if ((list = evas_object_smart_members_get(obj)))
2673 EINA_LIST_FREE(list, o)
2675 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2676 evas_object_color_set(o, r, g, b, a);
2682 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2687 if ((list = evas_object_smart_members_get(obj)))
2689 EINA_LIST_FREE(list, o)
2691 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2692 evas_object_clip_set(o, clip);
2698 _smart_clip_unset(Evas_Object *obj)
2703 if ((list = evas_object_smart_members_get(obj)))
2705 EINA_LIST_FREE(list, o)
2707 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2708 evas_object_clip_unset(o);
2714 _smart_calculate(Evas_Object *obj)
2717 if (sd->changed_func) sd->changed_func(obj);
2720 /* never need to touch this */
2724 if (_e_smart) return;
2726 static const Evas_Smart_Class sc =
2729 EVAS_SMART_CLASS_VERSION,
2747 _e_smart = evas_smart_class_new(&sc);
2751 /* happy debug functions */
2754 _sub_obj_tree_dump(const Evas_Object *o, int lvl)
2758 for (i = 0; i < lvl*3; i++)
2761 if (_elm_widget_is(o))
2764 Smart_Data *sd = evas_object_smart_data_get(o);
2765 printf("+ %s(%p)\n", sd->type, o);
2767 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2768 EINA_LIST_FOREACH(sd->subobjs, l, o)
2770 if (o != sd->resize_obj)
2771 _sub_obj_tree_dump(o, lvl + 1);
2775 printf("+ %s(%p)\n", evas_object_type_get(o), o);
2779 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2781 if (!_elm_widget_is(obj))
2784 Smart_Data *sd = evas_object_smart_data_get(obj);
2786 Eina_Bool visible = evas_object_visible_get(obj);
2787 Eina_Bool disabled = elm_widget_disabled_get(obj);
2788 Eina_Bool focused = elm_widget_focus_get(obj);
2789 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2793 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2796 fprintf(output, ", style=bold");
2799 fprintf(output, ", color=gray28");
2801 fprintf(output, " ];\n");
2804 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2805 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2806 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2810 fprintf(output, ", style=bold");
2813 fprintf(output, ", fontcolor=gray28");
2815 if ((disabled) || (!visible))
2816 fprintf(output, ", color=gray");
2819 fprintf(output, " ];\n");
2823 EINA_LIST_FOREACH(sd->subobjs, l, o)
2824 _sub_obj_tree_dot_dump(o, output);
2829 elm_widget_tree_dump(const Evas_Object *top)
2832 _sub_obj_tree_dump(top, 0);
2840 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2843 if (!_elm_widget_is(top))
2845 fprintf(output, "graph "" { node [shape=record];\n");
2846 _sub_obj_tree_dot_dump(top, output);
2847 fprintf(output, "}\n");