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;
81 Eina_List *focus_chain;
85 struct _Edje_Signal_Data
94 struct _Elm_Event_Cb_Data {
99 /* local subsystem functions */
100 static void _smart_reconfigure(Smart_Data *sd);
101 static void _smart_add(Evas_Object *obj);
102 static void _smart_del(Evas_Object *obj);
103 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
104 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
105 static void _smart_show(Evas_Object *obj);
106 static void _smart_hide(Evas_Object *obj);
107 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
108 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
109 static void _smart_clip_unset(Evas_Object *obj);
110 static void _smart_calculate(Evas_Object *obj);
111 static void _smart_init(void);
113 static void _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only);
114 static Evas_Object *_newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only);
116 /* local subsystem globals */
117 static Evas_Smart *_e_smart = NULL;
118 static Eina_List *widtypes = NULL;
120 static unsigned int focus_order = 0;
123 static inline Eina_Bool
124 _elm_widget_is(const Evas_Object *obj)
126 const char *type = evas_object_type_get(obj);
127 return type == SMART_NAME;
130 static inline Eina_Bool
131 _is_focusable(Evas_Object *obj)
133 API_ENTRY return EINA_FALSE;
134 return sd->can_focus || (sd->child_can_focus);
138 _unfocus_parents(Evas_Object *obj)
140 for (; obj; obj = elm_widget_parent_get(obj))
142 Smart_Data *sd = evas_object_smart_data_get(obj);
144 if (!sd->focused) return;
150 _focus_parents(Evas_Object *obj)
152 for (; obj; obj = elm_widget_parent_get(obj))
154 Smart_Data *sd = evas_object_smart_data_get(obj);
156 if (sd->focused) return;
162 _sub_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
164 Smart_Data *sd = data;
166 if (_elm_widget_is(obj))
168 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
170 if (obj == sd->resize_obj)
171 sd->resize_obj = NULL;
172 else if (obj == sd->hover_obj)
173 sd->hover_obj = NULL;
175 sd->subobjs = eina_list_remove(sd->subobjs, obj);
176 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
180 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
182 Evas_Object *o = obj;
185 if (_elm_widget_is(o)) break;
186 o = evas_object_smart_parent_get(o);
190 if (!_is_focusable(o)) return;
191 elm_widget_focus_steal(o);
195 _propagate_x_drag_lock(Evas_Object *obj, int dir)
197 Smart_Data *sd = evas_object_smart_data_get(obj);
200 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
203 sd2->child_drag_x_locked += dir;
204 _propagate_x_drag_lock(sd->parent_obj, dir);
210 _propagate_y_drag_lock(Evas_Object *obj, int dir)
212 Smart_Data *sd = evas_object_smart_data_get(obj);
215 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
218 sd2->child_drag_y_locked += dir;
219 _propagate_y_drag_lock(sd->parent_obj, dir);
225 _propagate_event(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
228 Evas_Callback_Type type = (Evas_Callback_Type)(long) data;
229 Evas_Event_Flags *event_flags = NULL;
233 case EVAS_CALLBACK_KEY_DOWN:
235 Evas_Event_Key_Down *ev = event_info;
236 event_flags = &(ev->event_flags);
239 case EVAS_CALLBACK_KEY_UP:
241 Evas_Event_Key_Up *ev = event_info;
242 event_flags = &(ev->event_flags);
245 case EVAS_CALLBACK_MOUSE_WHEEL:
247 Evas_Event_Mouse_Wheel *ev = event_info;
248 event_flags = &(ev->event_flags);
255 elm_widget_event_propagate(obj, type, event_info, event_flags);
259 _parent_focus(Evas_Object *obj)
263 Evas_Object *o = elm_widget_parent_get(obj);
264 sd->focus_order_on_calc = EINA_TRUE;
266 if (sd->focused) return;
272 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
274 /* we don't want to bump a common widget ancestor's
275 focus_order *twice* while parent focusing */
276 if (!ret || (!i) || (i != focus_order))
280 if (!sd->focus_order_on_calc)
281 return; /* we don't want to override it if by means of any of the
282 callbacks below one gets to calculate our order
286 sd->focus_order = focus_order;
287 sd->focused = EINA_TRUE;
288 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
289 if (sd->focus_func) sd->focus_func(obj);
291 _elm_widget_focus_region_show(obj);
293 sd->focus_order_on_calc = EINA_FALSE;
297 _elm_object_focus_chain_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
299 Smart_Data *sd = data;
301 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
304 // exposed util funcs to elm
306 _elm_widget_type_clear(void)
310 EINA_LIST_FREE(widtypes, ptr)
312 eina_stringshare_del(*ptr);
318 _elm_widget_focus_region_show(const Evas_Object *obj)
320 Evas_Coord x, y, w, h, ox, oy;
326 o = elm_widget_parent_get(obj);
329 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
330 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
334 sd2 = evas_object_smart_data_get(o);
335 if (sd2->focus_region_func)
337 sd2->focus_region_func(o, x, y, w, h);
338 elm_widget_focus_region_get(o, &x, &y, &w, &h);
342 evas_object_geometry_get(o, &px, &py, NULL, NULL);
348 o = elm_widget_parent_get(o);
353 * @defgroup Widget Widget
356 * Exposed api for making widgets
359 elm_widget_type_register(const char **ptr)
361 widtypes = eina_list_append(widtypes, (void *)ptr);
365 elm_widget_api_check(int ver)
367 if (ver != ELM_INTERNAL_API_VERSION)
369 CRITICAL("Elementary widget api versions do not match");
376 elm_widget_add(Evas *evas)
380 obj = evas_object_smart_add(evas, _e_smart);
381 elm_widget_mirrored_set(obj, elm_mirrored_get());
386 elm_widget_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
393 elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
396 sd->del_pre_func = func;
400 elm_widget_focus_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
403 sd->focus_func = func;
407 elm_widget_activate_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
410 sd->activate_func = func;
414 elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
417 sd->disable_func = func;
421 elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
424 sd->theme_func = func;
428 elm_widget_event_hook_set(Evas_Object *obj, Eina_Bool (*func) (Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info))
431 sd->event_func = func;
435 elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
438 sd->changed_func = func;
442 elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
445 sd->signal_func = func;
449 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))
452 sd->callback_add_func = func;
456 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))
459 sd->callback_del_func = func;
463 elm_widget_theme(Evas_Object *obj)
471 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
472 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
473 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
474 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
475 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
476 if (sd->theme_func) sd->theme_func(obj);
480 elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force)
486 Elm_Theme *th2, *thdef;
489 thdef = elm_theme_default_get();
494 if (!th2) th2 = thdef;
502 if (th2 == thdef) break;
503 th2 = th2->ref_theme;
504 if (!th2) th2 = thdef;
508 EINA_LIST_FOREACH(sd->subobjs, l, child)
509 elm_widget_theme_specific(child, th, force);
510 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
511 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
512 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
513 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
514 if (sd->theme_func) sd->theme_func(obj);
520 * Set hook to get next object in object focus chain.
522 * @param obj The widget object.
523 * @param func The hook to be used with this widget.
528 elm_widget_focus_next_hook_set(Evas_Object *obj, Eina_Bool (*func) (const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next))
531 sd->focus_next_func = func;
535 * Returns the widget's mirrored mode.
537 * @param obj The widget.
538 * @return mirrored mode of the object.
542 elm_widget_mirrored_get(const Evas_Object *obj)
544 API_ENTRY return EINA_FALSE;
545 return sd->is_mirrored;
549 * Sets the widget's mirrored mode.
551 * @param obj The widget.
552 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
555 elm_widget_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
558 if (sd->is_mirrored != mirrored)
560 sd->is_mirrored = mirrored;
561 elm_widget_theme(obj);
566 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
569 sd->on_focus_func = func;
570 sd->on_focus_data = data;
574 elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
577 sd->on_change_func = func;
578 sd->on_change_data = data;
582 elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
585 sd->on_show_region_func = func;
586 sd->on_show_region_data = data;
592 * Set the hook to use to show the focused region.
594 * Whenever a new widget gets focused or it's needed to show the focused
595 * area of the current one, this hook will be called on objects that may
596 * want to move their children into their visible area.
597 * The area given in the hook function is relative to the @p obj widget.
599 * @param obj The widget object
600 * @param func The function to call to show the specified area.
605 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))
608 sd->focus_region_func = func;
614 * Set the hook to retrieve the focused region of a widget.
616 * This hook will be called by elm_widget_focus_region_get() whenever
617 * it's needed to get the focused area of a widget. The area must be relative
618 * to the widget itself and if no hook is set, it will default to the entire
621 * @param obj The widget object
622 * @param func The function used to retrieve the focus region.
627 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))
630 sd->on_focus_region_func = func;
634 elm_widget_data_set(Evas_Object *obj, void *data)
641 elm_widget_data_get(const Evas_Object *obj)
643 API_ENTRY return NULL;
648 elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
651 double scale, pscale = elm_widget_scale_get(sobj);
652 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
653 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
655 if (_elm_widget_is(sobj))
657 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
660 if (sd2->parent_obj == obj)
662 elm_widget_sub_object_del(sd2->parent_obj, sobj);
663 sd2->parent_obj = obj;
664 if (!sd->child_can_focus && (_is_focusable(sobj)))
665 sd->child_can_focus = EINA_TRUE;
670 void *data = evas_object_data_get(sobj, "elm-parent");
673 if (data == obj) return;
674 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
679 sd->subobjs = eina_list_append(sd->subobjs, sobj);
680 evas_object_data_set(sobj, "elm-parent", obj);
681 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
682 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
683 scale = elm_widget_scale_get(sobj);
684 th = elm_widget_theme_get(sobj);
685 mirrored = elm_widget_mirrored_get(sobj);
686 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
687 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
691 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
693 Evas_Object *sobj_parent;
697 sobj_parent = evas_object_data_del(sobj, "elm-parent");
698 if (sobj_parent != obj)
700 static int abort_on_warn = -1;
701 ERR("removing sub object %p from parent %p, "
702 "but elm-parent is different %p!",
703 sobj, obj, sobj_parent);
704 if (EINA_UNLIKELY(abort_on_warn == -1))
706 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
707 else abort_on_warn = 0;
709 if (abort_on_warn == 1) abort();
711 if (!sd->child_can_focus)
713 if (_is_focusable(sobj)) sd->child_can_focus = 0;
715 if (_elm_widget_is(sobj))
717 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
720 sd2->parent_obj = NULL;
721 if (sd2->resize_obj == sobj)
722 sd2->resize_obj = NULL;
724 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
727 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
728 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
731 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
732 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
734 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
738 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
741 // orphan previous resize obj
744 evas_object_clip_unset(sd->resize_obj);
745 evas_object_data_del(sd->resize_obj, "elm-parent");
746 if (_elm_widget_is(sd->resize_obj))
748 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
749 if (sd2) sd2->parent_obj = NULL;
751 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
753 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
754 _sub_obj_mouse_down, sd);
755 evas_object_smart_member_del(sd->resize_obj);
756 if (_elm_widget_is(sd->resize_obj))
758 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
761 // orphan new resize obj
764 evas_object_data_del(sobj, "elm-parent");
765 if (_elm_widget_is(sobj))
767 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
768 if (sd2) sd2->parent_obj = NULL;
770 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
772 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
773 _sub_obj_mouse_down, sd);
774 evas_object_smart_member_del(sobj);
775 if (_elm_widget_is(sobj))
777 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
780 // set the resize obj up
781 sd->resize_obj = sobj;
784 if (_elm_widget_is(sd->resize_obj))
786 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
787 if (sd2) sd2->parent_obj = obj;
789 evas_object_clip_set(sobj, evas_object_clip_get(obj));
790 evas_object_smart_member_add(sobj, obj);
791 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
793 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
794 _sub_obj_mouse_down, sd);
795 _smart_reconfigure(sd);
796 evas_object_data_set(sobj, "elm-parent", obj);
797 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
798 if (_elm_widget_is(sobj))
800 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
806 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
811 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
814 sd->hover_obj = sobj;
817 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
819 _smart_reconfigure(sd);
824 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
827 sd->can_focus = can_focus;
830 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
832 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
833 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
835 (void *)(long) EVAS_CALLBACK_KEY_UP);
836 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
838 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
842 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
844 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
846 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
852 elm_widget_can_focus_get(const Evas_Object *obj)
854 API_ENTRY return EINA_FALSE;
855 return sd->can_focus;
859 elm_widget_child_can_focus_get(const Evas_Object *obj)
861 API_ENTRY return EINA_FALSE;
862 return sd->child_can_focus;
866 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
869 sd->highlight_ignore = !!ignore;
873 elm_widget_highlight_ignore_get(const Evas_Object *obj)
875 API_ENTRY return EINA_FALSE;
876 return sd->highlight_ignore;
880 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
883 sd->highlight_in_theme = !!highlight;
884 /* FIXME: if focused, it should switch from one mode to the other */
888 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
890 API_ENTRY return EINA_FALSE;
891 return sd->highlight_in_theme;
895 elm_widget_focus_get(const Evas_Object *obj)
897 API_ENTRY return EINA_FALSE;
902 elm_widget_focused_object_get(const Evas_Object *obj)
904 const Evas_Object *subobj;
906 API_ENTRY return NULL;
908 if (!sd->focused) return NULL;
909 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
911 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
912 if (fobj) return fobj;
914 return (Evas_Object *)obj;
918 elm_widget_top_get(const Evas_Object *obj)
920 API_ENTRY return NULL;
921 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
922 return (Evas_Object *)obj;
926 elm_widget_is(const Evas_Object *obj)
928 return _elm_widget_is(obj);
932 elm_widget_parent_widget_get(const Evas_Object *obj)
936 if (_elm_widget_is(obj))
938 Smart_Data *sd = evas_object_smart_data_get(obj);
939 if (!sd) return NULL;
940 parent = sd->parent_obj;
944 parent = evas_object_data_get(obj, "elm-parent");
945 if (!parent) parent = evas_object_smart_parent_get(obj);
950 Evas_Object *elm_parent;
951 if (_elm_widget_is(parent)) break;
952 elm_parent = evas_object_data_get(parent, "elm-parent");
953 if (elm_parent) parent = elm_parent;
954 else parent = evas_object_smart_parent_get(parent);
960 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
963 EINA_SAFETY_ON_NULL_RETURN(func);
964 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
967 sd->event_cb = eina_list_append(sd->event_cb, ecb);
971 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
973 API_ENTRY return NULL;
974 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
976 Elm_Event_Cb_Data *ecd;
977 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
978 if ((ecd->func == func) && (ecd->data == data))
981 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
988 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
990 API_ENTRY return EINA_FALSE; //TODO reduce.
991 if (!_elm_widget_is(obj)) return EINA_FALSE;
992 Evas_Object *parent = obj;
993 Elm_Event_Cb_Data *ecd;
994 Eina_List *l, *l_prev;
997 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
999 sd = evas_object_smart_data_get(parent);
1000 if ((!sd) || (!_elm_widget_is(obj)))
1001 return EINA_FALSE; //Not Elm Widget
1003 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1006 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1008 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1009 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1012 parent = sd->parent_obj;
1021 * Set custom focus chain.
1023 * This function i set one new and overwrite any previous custom focus chain
1024 * with the list of objects. The previous list will be deleted and this list
1025 * will be managed. After setted, don't modity it.
1027 * @note On focus cycle, only will be evaluated children of this container.
1029 * @param obj The container widget
1030 * @param objs Chain of objects to pass focus
1034 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1037 if (!sd->focus_next_func)
1040 elm_widget_focus_custom_chain_unset(obj);
1045 EINA_LIST_FOREACH(objs, l, o)
1047 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1048 _elm_object_focus_chain_del_cb, sd);
1051 sd->focus_chain = objs;
1057 * Get custom focus chain
1059 * @param obj The container widget
1062 EAPI const Eina_List *
1063 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1065 API_ENTRY return NULL;
1066 return (const Eina_List *) sd->focus_chain;
1072 * Unset custom focus chain
1074 * @param obj The container widget
1078 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1081 Eina_List *l, *l_next;
1084 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1086 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1087 _elm_object_focus_chain_del_cb, sd);
1088 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1095 * Append object to custom focus chain.
1097 * @note If relative_child equal to NULL or not in custom chain, the object
1098 * will be added in end.
1100 * @note On focus cycle, only will be evaluated children of this container.
1102 * @param obj The container widget
1103 * @param child The child to be added in custom chain
1104 * @param relative_child The relative object to position the child
1108 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1111 EINA_SAFETY_ON_NULL_RETURN(child);
1112 if (!sd->focus_next_func)
1115 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1116 _elm_object_focus_chain_del_cb, sd);
1118 if (!relative_child)
1120 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1124 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1131 * Prepend object to custom focus chain.
1133 * @note If relative_child equal to NULL or not in custom chain, the object
1134 * will be added in begin.
1136 * @note On focus cycle, only will be evaluated children of this container.
1138 * @param obj The container widget
1139 * @param child The child to be added in custom chain
1140 * @param relative_child The relative object to position the child
1144 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1147 EINA_SAFETY_ON_NULL_RETURN(child);
1148 if (!sd->focus_next_func)
1151 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1152 _elm_object_focus_chain_del_cb, sd);
1154 if (!relative_child)
1156 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1160 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1167 * Give focus to next object in object tree.
1169 * Give focus to next object in focus chain of one object sub-tree.
1170 * If the last object of chain already have focus, the focus will go to the
1171 * first object of chain.
1173 * @param obj The widget root of sub-tree
1174 * @param dir Direction to cycle the focus
1179 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1181 Evas_Object *target = NULL;
1182 if (!_elm_widget_is(obj))
1184 elm_widget_focus_next_get(obj, dir, &target);
1186 elm_widget_focus_steal(target);
1192 * Give focus to near object in one direction.
1194 * Give focus to near object in direction of one object.
1195 * If none focusable object in given direction, the focus will not change.
1197 * @param obj The reference widget
1198 * @param x Horizontal component of direction to focus
1199 * @param y Vertical component of direction to focus
1204 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1212 * Get next object in focus chain of object tree.
1214 * Get next object in focus chain of one object sub-tree.
1215 * Return the next object by reference. If don't have any candidate to receive
1216 * focus before chain end, the first candidate will be returned.
1218 * @param obj The widget root of sub-tree
1219 * @param dir Direction os focus chain
1220 * @param next The next object in focus chain
1221 * @return EINA_TRUE if don't need focus chain restart/loop back
1222 * to use 'next' obj.
1227 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1233 API_ENTRY return EINA_FALSE;
1235 /* Ignore if disabled */
1236 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1240 if (sd->focus_next_func)
1241 return sd->focus_next_func(obj, dir, next);
1243 if (!elm_widget_can_focus_get(obj))
1247 *next = (Evas_Object *)obj;
1248 return !elm_widget_focus_get(obj);
1255 * Get next object in focus chain of object tree in list.
1257 * Get next object in focus chain of one object sub-tree ordered by one list.
1258 * Return the next object by reference. If don't have any candidate to receive
1259 * focus before list end, the first candidate will be returned.
1261 * @param obj The widget root of sub-tree
1262 * @param dir Direction os focus chain
1263 * @param items list with ordered objects
1264 * @param list_data_get function to get the object from one item of list
1265 * @param next The next object in focus chain
1266 * @return EINA_TRUE if don't need focus chain restart/loop back
1267 * to use 'next' obj.
1272 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)
1274 Eina_List *(*list_next) (const Eina_List *list);
1280 if (!_elm_widget_is(obj))
1287 if (dir == ELM_FOCUS_PREVIOUS)
1289 items = eina_list_last(items);
1290 list_next = eina_list_prev;
1292 else if (dir == ELM_FOCUS_NEXT)
1293 list_next = eina_list_next;
1297 const Eina_List *l = items;
1299 /* Recovery last focused sub item */
1300 if (elm_widget_focus_get(obj))
1301 for (; l; l = list_next(l))
1303 Evas_Object *cur = list_data_get(l);
1304 if (elm_widget_focus_get(cur)) break;
1307 const Eina_List *start = l;
1308 Evas_Object *to_focus = NULL;
1310 /* Interate sub items */
1311 /* Go to end of list */
1312 for (; l; l = list_next(l))
1314 Evas_Object *tmp = NULL;
1315 Evas_Object *cur = list_data_get(l);
1317 if (elm_widget_parent_get(cur) != obj)
1320 /* Try Focus cycle in subitem */
1321 if (elm_widget_focus_next_get(cur, dir, &tmp))
1326 else if ((tmp) && (!to_focus))
1332 /* Get First possible */
1333 for (;l != start; l = list_next(l))
1335 Evas_Object *tmp = NULL;
1336 Evas_Object *cur = list_data_get(l);
1338 if (elm_widget_parent_get(cur) != obj)
1341 /* Try Focus cycle in subitem */
1342 elm_widget_focus_next_get(cur, dir, &tmp);
1355 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1358 if (!sd->signal_func) return;
1359 sd->signal_func(obj, emission, source);
1363 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1365 Edje_Signal_Data *esd = data;
1366 esd->func(esd->data, esd->obj, emission, source);
1370 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)
1372 Edje_Signal_Data *esd;
1374 if (!sd->callback_add_func) return;
1375 EINA_SAFETY_ON_NULL_RETURN(func);
1377 esd = ELM_NEW(Edje_Signal_Data);
1382 esd->emission = eina_stringshare_add(emission);
1383 esd->source = eina_stringshare_add(source);
1385 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1386 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1390 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))
1392 Edje_Signal_Data *esd;
1395 API_ENTRY return NULL;
1396 if (!sd->callback_del_func) return NULL;
1398 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1400 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1401 (!strcmp(esd->source, source)))
1403 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1404 eina_stringshare_del(esd->emission);
1405 eina_stringshare_del(esd->source);
1411 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1416 elm_widget_focus_set(Evas_Object *obj, int first)
1422 sd->focus_order = focus_order;
1423 sd->focused = EINA_TRUE;
1424 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1428 sd->focus_func(obj);
1435 if ((_is_focusable(sd->resize_obj)) &&
1436 (!elm_widget_disabled_get(sd->resize_obj)))
1438 elm_widget_focus_set(sd->resize_obj, first);
1444 EINA_LIST_FOREACH(sd->subobjs, l, child)
1446 if ((_is_focusable(child)) &&
1447 (!elm_widget_disabled_get(child)))
1449 elm_widget_focus_set(child, first);
1459 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1461 if ((_is_focusable(child)) &&
1462 (!elm_widget_disabled_get(child)))
1464 elm_widget_focus_set(child, first);
1470 if ((_is_focusable(sd->resize_obj)) &&
1471 (!elm_widget_disabled_get(sd->resize_obj)))
1473 elm_widget_focus_set(sd->resize_obj, first);
1481 elm_widget_parent_get(const Evas_Object *obj)
1483 API_ENTRY return NULL;
1484 return sd->parent_obj;
1488 elm_widget_focused_object_clear(Evas_Object *obj)
1491 if (!sd->focused) return;
1492 if (elm_widget_focus_get(sd->resize_obj))
1493 elm_widget_focused_object_clear(sd->resize_obj);
1498 EINA_LIST_FOREACH(sd->subobjs, l, child)
1500 if (elm_widget_focus_get(child))
1502 elm_widget_focused_object_clear(child);
1507 sd->focused = EINA_FALSE;
1508 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1509 if (sd->focus_func) sd->focus_func(obj);
1513 elm_widget_focus_steal(Evas_Object *obj)
1515 Evas_Object *parent, *o;
1518 if (sd->focused) return;
1519 if (sd->disabled) return;
1523 o = elm_widget_parent_get(parent);
1525 sd = evas_object_smart_data_get(o);
1526 if (sd->focused) break;
1529 if (!elm_widget_parent_get(parent))
1530 elm_widget_focused_object_clear(parent);
1533 parent = elm_widget_parent_get(parent);
1534 sd = evas_object_smart_data_get(parent);
1535 if (elm_widget_focus_get(sd->resize_obj))
1537 elm_widget_focused_object_clear(sd->resize_obj);
1543 EINA_LIST_FOREACH(sd->subobjs, l, child)
1545 if (elm_widget_focus_get(child))
1547 elm_widget_focused_object_clear(child);
1558 elm_widget_activate(Evas_Object *obj)
1561 elm_widget_change(obj);
1562 if (sd->activate_func) sd->activate_func(obj);
1566 elm_widget_change(Evas_Object *obj)
1569 elm_widget_change(elm_widget_parent_get(obj));
1570 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1574 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1578 if (sd->disabled == disabled) return;
1579 sd->disabled = disabled;
1582 Evas_Object *o, *parent;
1587 o = elm_widget_parent_get(parent);
1591 if (elm_widget_focus_get(obj))
1592 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1594 if (sd->disable_func) sd->disable_func(obj);
1598 elm_widget_disabled_get(const Evas_Object *obj)
1601 return sd->disabled;
1605 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1607 Evas_Object *parent_obj, *child_obj;
1608 Evas_Coord px, py, cx, cy;
1611 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1616 if (sd->on_show_region_func)
1617 sd->on_show_region_func(sd->on_show_region_data, obj);
1621 parent_obj = sd->parent_obj;
1622 child_obj = sd->obj;
1623 sd = evas_object_smart_data_get(parent_obj);
1625 if ((!parent_obj) || (!sd) || (!_elm_widget_is(parent_obj))) break;
1627 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1628 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1637 if (sd->on_show_region_func)
1639 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1646 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1658 * Get the focus region of the given widget.
1660 * The focus region is the area of a widget that should brought into the
1661 * visible area when the widget is focused. Mostly used to show the part of
1662 * an entry where the cursor is, for example. The area returned is relative
1663 * to the object @p obj.
1664 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1665 * function will return the full size of the object.
1667 * @param obj The widget object
1668 * @param x Where to store the x coordinate of the area
1669 * @param y Where to store the y coordinate of the area
1670 * @param w Where to store the width of the area
1671 * @param h Where to store the height of the area
1676 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1682 sd = evas_object_smart_data_get(obj);
1683 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1685 evas_object_geometry_get(obj, NULL, NULL, w, h);
1690 sd->on_focus_region_func(obj, x, y, w, h);
1694 elm_widget_scroll_hold_push(Evas_Object *obj)
1698 if (sd->scroll_hold == 1)
1699 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1700 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1701 // FIXME: on delete/reparent hold pop
1705 elm_widget_scroll_hold_pop(Evas_Object *obj)
1709 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1710 if (!sd->scroll_hold)
1711 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1712 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1716 elm_widget_scroll_hold_get(const Evas_Object *obj)
1719 return sd->scroll_hold;
1723 elm_widget_scroll_freeze_push(Evas_Object *obj)
1726 sd->scroll_freeze++;
1727 if (sd->scroll_freeze == 1)
1728 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1729 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1730 // FIXME: on delete/reparent freeze pop
1734 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1737 sd->scroll_freeze--;
1738 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1739 if (!sd->scroll_freeze)
1740 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1741 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1745 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1748 return sd->scroll_freeze;
1752 elm_widget_scale_set(Evas_Object *obj, double scale)
1755 if (scale <= 0.0) scale = 0.0;
1756 if (sd->scale != scale)
1759 elm_widget_theme(obj);
1764 elm_widget_scale_get(const Evas_Object *obj)
1766 API_ENTRY return 1.0;
1767 // FIXME: save walking up the tree by storing/caching parent scale
1768 if (sd->scale == 0.0)
1771 return elm_widget_scale_get(sd->parent_obj);
1779 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1782 if (sd->theme != th)
1784 if (sd->theme) elm_theme_free(sd->theme);
1787 elm_widget_theme(obj);
1792 elm_widget_theme_get(const Evas_Object *obj)
1794 API_ENTRY return NULL;
1798 return elm_widget_theme_get(sd->parent_obj);
1806 elm_widget_style_set(Evas_Object *obj, const char *style)
1810 if (eina_stringshare_replace(&sd->style, style))
1811 elm_widget_theme(obj);
1815 elm_widget_style_get(const Evas_Object *obj)
1817 API_ENTRY return NULL;
1818 if (sd->style) return sd->style;
1823 elm_widget_type_set(Evas_Object *obj, const char *type)
1826 eina_stringshare_replace(&sd->type, type);
1830 elm_widget_type_get(const Evas_Object *obj)
1832 API_ENTRY return NULL;
1833 if (sd->type) return sd->type;
1838 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1841 sd->tooltips = eina_list_append(sd->tooltips, tt);
1845 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1848 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1852 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1855 sd->cursors = eina_list_append(sd->cursors, cur);
1859 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1862 sd->cursors = eina_list_remove(sd->cursors, cur);
1866 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1869 if (sd->drag_x_locked == lock) return;
1870 sd->drag_x_locked = lock;
1871 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1872 else _propagate_x_drag_lock(obj, -1);
1876 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1879 if (sd->drag_y_locked == lock) return;
1880 sd->drag_y_locked = lock;
1881 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1882 else _propagate_y_drag_lock(obj, -1);
1886 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1888 API_ENTRY return EINA_FALSE;
1889 return sd->drag_x_locked;
1893 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1895 API_ENTRY return EINA_FALSE;
1896 return sd->drag_y_locked;
1900 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1903 return sd->child_drag_x_locked;
1907 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1910 return sd->child_drag_y_locked;
1914 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1916 API_ENTRY return EINA_FALSE;
1917 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1921 elm_widget_type_check(const Evas_Object *obj, const char *type)
1923 const char *provided, *expected = "(unknown)";
1924 static int abort_on_warn = -1;
1925 provided = elm_widget_type_get(obj);
1926 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1927 if (type) expected = type;
1928 if ((!provided) || (!provided[0]))
1930 provided = evas_object_type_get(obj);
1931 if ((!provided) || (!provided[0]))
1932 provided = "(unknown)";
1934 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
1935 if (abort_on_warn == -1)
1937 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
1938 else abort_on_warn = 0;
1940 if (abort_on_warn == 1) abort();
1947 * Split string in words
1949 * @param str Source string
1950 * @return List of const words
1952 * @see elm_widget_stringlist_free()
1956 elm_widget_stringlist_get(const char *str)
1958 Eina_List *list = NULL;
1960 if (!str) return NULL;
1961 for (b = s = str; 1; s++)
1963 if ((*s == ' ') || (!*s))
1965 char *t = malloc(s - b + 1);
1968 strncpy(t, b, s - b);
1970 list = eina_list_append(list, eina_stringshare_add(t));
1981 elm_widget_stringlist_free(Eina_List *list)
1984 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
1990 * Allocate a new Elm_Widget_Item-derived structure.
1992 * The goal of this structure is to provide common ground for actions
1993 * that a widget item have, such as the owner widget, callback to
1994 * notify deletion, data pointer and maybe more.
1996 * @param widget the owner widget that holds this item, must be an elm_widget!
1997 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
1998 * be used to allocate memory.
2000 * @return allocated memory that is already zeroed out, or NULL on errors.
2002 * @see elm_widget_item_new() convenience macro.
2003 * @see elm_widget_item_del() to release memory.
2006 EAPI Elm_Widget_Item *
2007 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
2009 if (!_elm_widget_is(widget))
2012 Elm_Widget_Item *item;
2014 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2015 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2017 item = calloc(1, alloc_size);
2018 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2020 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2021 item->widget = widget;
2028 * Releases widget item memory, calling back del_cb() if it exists.
2030 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2031 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2032 * this function and then unset it, thus being useful for 2 step
2033 * cleanup whenever the del_cb may use any of the data that must be
2034 * deleted from item.
2036 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2039 * @param item a valid #Elm_Widget_Item to be deleted.
2040 * @see elm_widget_item_del() convenience macro.
2044 _elm_widget_item_del(Elm_Widget_Item *item)
2046 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2049 item->del_cb((void *)item->data, item->widget, item);
2052 evas_object_del(item->view);
2054 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2061 * Notify object will be deleted without actually deleting it.
2063 * This function will callback Elm_Widget_Item::del_cb if it is set
2064 * and then unset it so it is not called twice (ie: from
2065 * elm_widget_item_del()).
2067 * @param item a valid #Elm_Widget_Item to be notified
2068 * @see elm_widget_item_pre_notify_del() convenience macro.
2072 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2074 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2075 if (!item->del_cb) return;
2076 item->del_cb((void *)item->data, item->widget, item);
2077 item->del_cb = NULL;
2083 * Set the function to notify when item is being deleted.
2085 * This function will complain if there was a callback set already,
2086 * however it will set the new one.
2088 * The callback will be called from elm_widget_item_pre_notify_del()
2089 * or elm_widget_item_del() will be called with:
2090 * - data: the Elm_Widget_Item::data value.
2091 * - obj: the Elm_Widget_Item::widget evas object.
2092 * - event_info: the item being deleted.
2094 * @param item a valid #Elm_Widget_Item to be notified
2095 * @see elm_widget_item_del_cb_set() convenience macro.
2099 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2101 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2103 if ((item->del_cb) && (item->del_cb != del_cb))
2104 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2105 item->del_cb, item, del_cb);
2107 item->del_cb = del_cb;
2113 * Set user-data in this item.
2115 * User data may be used to identify this item or just store any
2116 * application data. It is automatically given as the first parameter
2117 * of the deletion notify callback.
2119 * @param item a valid #Elm_Widget_Item to store data in.
2120 * @param data user data to store.
2121 * @see elm_widget_item_del_cb_set() convenience macro.
2125 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2127 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2128 if ((item->data) && (item->data != data))
2129 DBG("Replacing item %p data %p with %p", item, item->data, data);
2136 * Retrieves user-data of this item.
2138 * @param item a valid #Elm_Widget_Item to get data from.
2139 * @see elm_widget_item_data_set()
2143 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2145 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2146 return (void *)item->data;
2149 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2151 struct _Elm_Widget_Item_Tooltip
2153 Elm_Widget_Item *item;
2154 Elm_Tooltip_Item_Content_Cb func;
2155 Evas_Smart_Cb del_cb;
2159 static Evas_Object *
2160 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2162 Evas_Object *label = elm_label_add(obj);
2165 elm_object_style_set(label, "tooltip");
2166 elm_label_label_set(label, data);
2171 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2173 eina_stringshare_del(data);
2179 * Set the text to be shown in the widget item.
2181 * @param item Target item
2182 * @param text The text to set in the content
2184 * Setup the text as tooltip to object. The item can have only one tooltip,
2185 * so any previous tooltip data is removed.
2190 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2192 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2193 EINA_SAFETY_ON_NULL_RETURN(text);
2195 text = eina_stringshare_add(text);
2196 _elm_widget_item_tooltip_content_cb_set
2197 (item, _elm_widget_item_tooltip_label_create, text,
2198 _elm_widget_item_tooltip_label_del_cb);
2201 static Evas_Object *
2202 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2204 Elm_Widget_Item_Tooltip *wit = data;
2205 return wit->func((void *)wit->data, obj, wit->item);
2209 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2211 Elm_Widget_Item_Tooltip *wit = data;
2212 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2219 * Set the content to be shown in the tooltip item
2221 * Setup the tooltip to item. The item can have only one tooltip,
2222 * so any previous tooltip data is removed. @p func(with @p data) will
2223 * be called every time that need show the tooltip and it should
2224 * return a valid Evas_Object. This object is then managed fully by
2225 * tooltip system and is deleted when the tooltip is gone.
2227 * @param item the widget item being attached a tooltip.
2228 * @param func the function used to create the tooltip contents.
2229 * @param data what to provide to @a func as callback data/context.
2230 * @param del_cb called when data is not needed anymore, either when
2231 * another callback replaces @func, the tooltip is unset with
2232 * elm_widget_item_tooltip_unset() or the owner @a item
2233 * dies. This callback receives as the first parameter the
2234 * given @a data, and @c event_info is the item.
2239 _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)
2241 Elm_Widget_Item_Tooltip *wit;
2243 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2247 _elm_widget_item_tooltip_unset(item);
2251 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2252 if (!wit) goto error;
2256 wit->del_cb = del_cb;
2258 elm_object_sub_tooltip_content_cb_set
2259 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2260 _elm_widget_item_tooltip_del_cb);
2265 if (del_cb) del_cb((void *)data, NULL, item);
2268 if (del_cb) del_cb((void *)data, item->widget, item);
2274 * Unset tooltip from item
2276 * @param item widget item to remove previously set tooltip.
2278 * Remove tooltip from item. The callback provided as del_cb to
2279 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2280 * it is not used anymore.
2282 * @see elm_widget_item_tooltip_content_cb_set()
2287 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2289 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2290 elm_object_tooltip_unset(item->view);
2296 * Sets a different style for this item tooltip.
2298 * @note before you set a style you should define a tooltip with
2299 * elm_widget_item_tooltip_content_cb_set() or
2300 * elm_widget_item_tooltip_text_set()
2302 * @param item widget item with tooltip already set.
2303 * @param style the theme style to use (default, transparent, ...)
2308 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2310 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2311 elm_object_tooltip_style_set(item->view, style);
2317 * Get the style for this item tooltip.
2319 * @param item widget item with tooltip already set.
2320 * @return style the theme style in use, defaults to "default". If the
2321 * object does not have a tooltip set, then NULL is returned.
2326 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2328 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2329 return elm_object_tooltip_style_get(item->view);
2333 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2335 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2336 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2340 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2342 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2343 return elm_object_cursor_get(item->view);
2347 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2349 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2350 elm_object_cursor_unset(item->view);
2356 * Sets a different style for this item cursor.
2358 * @note before you set a style you should define a cursor with
2359 * elm_widget_item_cursor_set()
2361 * @param item widget item with cursor already set.
2362 * @param style the theme style to use (default, transparent, ...)
2367 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2369 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2370 elm_object_cursor_style_set(item->view, style);
2376 * Get the style for this item cursor.
2378 * @param item widget item with cursor already set.
2379 * @return style the theme style in use, defaults to "default". If the
2380 * object does not have a cursor set, then NULL is returned.
2385 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2387 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2388 return elm_object_cursor_style_get(item->view);
2394 * Set if the cursor set should be searched on the theme or should use
2395 * the provided by the engine, only.
2397 * @note before you set if should look on theme you should define a cursor
2398 * with elm_object_cursor_set(). By default it will only look for cursors
2399 * provided by the engine.
2401 * @param item widget item with cursor already set.
2402 * @param engine_only boolean to define it cursors should be looked only
2403 * between the provided by the engine or searched on widget's theme as well.
2408 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2410 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2411 elm_object_cursor_engine_only_set(item->view, engine_only);
2417 * Get the cursor engine only usage for this item cursor.
2419 * @param item widget item with cursor already set.
2420 * @return engine_only boolean to define it cursors should be looked only
2421 * between the provided by the engine or searched on widget's theme as well. If
2422 * the object does not have a cursor set, then EINA_FALSE is returned.
2427 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2429 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2430 return elm_object_cursor_engine_only_get(item->view);
2433 // smart object funcs
2435 _smart_reconfigure(Smart_Data *sd)
2439 evas_object_move(sd->resize_obj, sd->x, sd->y);
2440 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2444 evas_object_move(sd->hover_obj, sd->x, sd->y);
2445 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2450 _smart_add(Evas_Object *obj)
2454 sd = calloc(1, sizeof(Smart_Data));
2457 sd->x = sd->y = sd->w = sd->h = 0;
2459 evas_object_smart_data_set(obj, sd);
2462 static Evas_Object *
2463 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2466 Evas_Object *child, *ret, *best;
2468 API_ENTRY return NULL;
2469 if (!evas_object_visible_get(obj)) return NULL;
2471 if (*newest_focus_order < sd->focus_order)
2473 *newest_focus_order = sd->focus_order;
2476 EINA_LIST_FOREACH(sd->subobjs, l, child)
2478 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2482 if ((can_focus_only) && (!elm_widget_can_focus_get(best))) return NULL;
2487 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2490 Evas_Object *newest = NULL;
2491 unsigned int newest_focus_order = 0;
2495 if (!sd->focused) return;
2496 if (!sd->parent_obj) return;
2498 top = elm_widget_top_get(sd->parent_obj);
2501 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2504 elm_object_unfocus(newest);
2505 elm_object_focus(newest);
2511 _smart_del(Evas_Object *obj)
2514 Edje_Signal_Data *esd;
2518 if (sd->del_pre_func) sd->del_pre_func(obj);
2521 sobj = sd->resize_obj;
2522 sd->resize_obj = NULL;
2523 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2524 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2525 evas_object_del(sobj);
2529 sobj = sd->hover_obj;
2530 sd->hover_obj = NULL;
2531 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2532 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2533 evas_object_del(sobj);
2535 EINA_LIST_FREE(sd->subobjs, sobj)
2537 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2538 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2539 evas_object_del(sobj);
2541 eina_list_free(sd->tooltips); /* should be empty anyway */
2542 eina_list_free(sd->cursors); /* should be empty anyway */
2543 EINA_LIST_FREE(sd->edje_signals, esd)
2545 eina_stringshare_del(esd->emission);
2546 eina_stringshare_del(esd->source);
2549 eina_list_free(sd->event_cb); /* should be empty anyway */
2550 if (sd->del_func) sd->del_func(obj);
2551 if (sd->style) eina_stringshare_del(sd->style);
2552 if (sd->type) eina_stringshare_del(sd->type);
2553 if (sd->theme) elm_theme_free(sd->theme);
2554 _if_focused_revert(obj, EINA_TRUE);
2559 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2564 _smart_reconfigure(sd);
2568 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2573 _smart_reconfigure(sd);
2577 _smart_show(Evas_Object *obj)
2582 if ((list = evas_object_smart_members_get(obj)))
2584 EINA_LIST_FREE(list, o)
2586 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2587 evas_object_show(o);
2593 _smart_hide(Evas_Object *obj)
2598 list = evas_object_smart_members_get(obj);
2599 EINA_LIST_FREE(list, o)
2601 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2602 evas_object_hide(o);
2604 _if_focused_revert(obj, EINA_TRUE);
2608 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2613 if ((list = evas_object_smart_members_get(obj)))
2615 EINA_LIST_FREE(list, o)
2617 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2618 evas_object_color_set(o, r, g, b, a);
2624 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2629 if ((list = evas_object_smart_members_get(obj)))
2631 EINA_LIST_FREE(list, o)
2633 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2634 evas_object_clip_set(o, clip);
2640 _smart_clip_unset(Evas_Object *obj)
2645 if ((list = evas_object_smart_members_get(obj)))
2647 EINA_LIST_FREE(list, o)
2649 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2650 evas_object_clip_unset(o);
2656 _smart_calculate(Evas_Object *obj)
2659 if (sd->changed_func) sd->changed_func(obj);
2662 /* never need to touch this */
2666 if (_e_smart) return;
2668 static const Evas_Smart_Class sc =
2671 EVAS_SMART_CLASS_VERSION,
2689 _e_smart = evas_smart_class_new(&sc);
2693 /* happy debug functions */
2696 _sub_obj_tree_dump(const Evas_Object *o, int lvl)
2700 for (i = 0; i < lvl*3; i++)
2703 if (_elm_widget_is(o))
2706 Smart_Data *sd = evas_object_smart_data_get(o);
2707 printf("+ %s(%p)\n", sd->type, o);
2709 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2710 EINA_LIST_FOREACH(sd->subobjs, l, o)
2712 if (o != sd->resize_obj)
2713 _sub_obj_tree_dump(o, lvl + 1);
2717 printf("+ %s(%p)\n", evas_object_type_get(o), o);
2721 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2723 if (!_elm_widget_is(obj))
2726 Smart_Data *sd = evas_object_smart_data_get(obj);
2728 Eina_Bool visible = evas_object_visible_get(obj);
2729 Eina_Bool disabled = elm_widget_disabled_get(obj);
2730 Eina_Bool focused = elm_widget_focus_get(obj);
2731 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2735 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2738 fprintf(output, ", style=bold");
2741 fprintf(output, ", color=gray28");
2743 fprintf(output, " ];\n");
2746 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2747 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2748 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2752 fprintf(output, ", style=bold");
2755 fprintf(output, ", fontcolor=gray28");
2757 if ((disabled) || (!visible))
2758 fprintf(output, ", color=gray");
2761 fprintf(output, " ];\n");
2765 EINA_LIST_FOREACH(sd->subobjs, l, o)
2766 _sub_obj_tree_dot_dump(o, output);
2771 elm_widget_tree_dump(const Evas_Object *top)
2774 _sub_obj_tree_dump(top, 0);
2782 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2785 if (!_elm_widget_is(top))
2787 fprintf(output, "graph "" { node [shape=record];\n");
2788 _sub_obj_tree_dot_dump(top, output);
2789 fprintf(output, "}\n");