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, Edje_Signal_Cb func, void *data);
38 void (*callback_del_func) (Evas_Object *obj, const char *emission,
39 const char *source, Edje_Signal_Cb func, void *data);
40 void (*changed_func) (Evas_Object *obj);
41 Eina_Bool (*focus_next_func) (const Evas_Object *obj, Elm_Focus_Direction dir,
43 void (*on_focus_func) (void *data, Evas_Object *obj);
45 void (*on_change_func) (void *data, Evas_Object *obj);
47 void (*on_show_region_func) (void *data, Evas_Object *obj);
48 void *on_show_region_data;
49 void (*focus_region_func) (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
50 void (*on_focus_region_func) (const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
52 Evas_Coord rx, ry, rw, rh;
58 unsigned int focus_order;
59 Eina_Bool focus_order_on_calc;
61 int child_drag_x_locked;
62 int child_drag_y_locked;
64 Eina_List *edje_signals;
66 Eina_Bool drag_x_locked : 1;
67 Eina_Bool drag_y_locked : 1;
69 Eina_Bool can_focus : 1;
70 Eina_Bool child_can_focus : 1;
71 Eina_Bool focused : 1;
72 Eina_Bool highlight_ignore : 1;
73 Eina_Bool highlight_in_theme : 1;
74 Eina_Bool disabled : 1;
75 Eina_Bool is_mirrored : 1;
76 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
78 Eina_List *focus_chain;
82 struct _Edje_Signal_Data
91 struct _Elm_Event_Cb_Data {
96 /* local subsystem functions */
97 static void _smart_reconfigure(Smart_Data *sd);
98 static void _smart_add(Evas_Object *obj);
99 static void _smart_del(Evas_Object *obj);
100 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
101 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
102 static void _smart_show(Evas_Object *obj);
103 static void _smart_hide(Evas_Object *obj);
104 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
105 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
106 static void _smart_clip_unset(Evas_Object *obj);
107 static void _smart_calculate(Evas_Object *obj);
108 static void _smart_init(void);
110 static void _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only);
111 static Evas_Object *_newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only);
113 /* local subsystem globals */
114 static Evas_Smart *_e_smart = NULL;
115 static Eina_List *widtypes = NULL;
117 static unsigned int focus_order = 0;
120 static inline Eina_Bool
121 _elm_widget_is(const Evas_Object *obj)
123 const char *type = evas_object_type_get(obj);
124 return type == SMART_NAME;
127 static inline Eina_Bool
128 _is_focusable(Evas_Object *obj)
130 API_ENTRY return EINA_FALSE;
131 return sd->can_focus || (sd->child_can_focus);
135 _unfocus_parents(Evas_Object *obj)
137 for (; obj; obj = elm_widget_parent_get(obj))
140 if (!sd->focused) return;
146 _focus_parents(Evas_Object *obj)
148 for (; obj; obj = elm_widget_parent_get(obj))
151 if (sd->focused) return;
157 _sub_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
159 Smart_Data *sd = data;
161 if (_elm_widget_is(obj))
163 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
165 if (obj == sd->resize_obj)
166 sd->resize_obj = NULL;
167 else if (obj == sd->hover_obj)
168 sd->hover_obj = NULL;
170 sd->subobjs = eina_list_remove(sd->subobjs, obj);
171 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
175 _sub_obj_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
177 _if_focused_revert(obj, EINA_TRUE);
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)
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)
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, Edje_Signal_Cb func_cb, 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, Edje_Signal_Cb func_cb, 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 if (_elm_widget_is(sobj))
740 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
741 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
742 scale = elm_widget_scale_get(sobj);
743 th = elm_widget_theme_get(sobj);
744 mirrored = elm_widget_mirrored_get(sobj);
745 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
746 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
750 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
752 Evas_Object *sobj_parent;
756 sobj_parent = evas_object_data_del(sobj, "elm-parent");
757 if (sobj_parent != obj)
759 static int abort_on_warn = -1;
760 ERR("removing sub object %p from parent %p, "
761 "but elm-parent is different %p!",
762 sobj, obj, sobj_parent);
763 if (EINA_UNLIKELY(abort_on_warn == -1))
765 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
766 else abort_on_warn = 0;
768 if (abort_on_warn == 1) abort();
770 if (!sd->child_can_focus)
772 if (_is_focusable(sobj)) sd->child_can_focus = 0;
774 if (_elm_widget_is(sobj))
776 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
779 sd2->parent_obj = NULL;
780 if (sd2->resize_obj == sobj)
781 sd2->resize_obj = NULL;
783 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
786 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
787 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
790 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
791 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
793 if (_elm_widget_is(sobj))
794 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
796 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
800 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
803 // orphan previous resize obj
806 evas_object_clip_unset(sd->resize_obj);
807 evas_object_data_del(sd->resize_obj, "elm-parent");
808 if (_elm_widget_is(sd->resize_obj))
810 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
811 if (sd2) sd2->parent_obj = NULL;
812 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
815 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
817 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
818 _sub_obj_mouse_down, sd);
819 evas_object_smart_member_del(sd->resize_obj);
820 if (_elm_widget_is(sd->resize_obj))
822 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
825 // orphan new resize obj
828 evas_object_data_del(sobj, "elm-parent");
829 if (_elm_widget_is(sobj))
831 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
832 if (sd2) sd2->parent_obj = NULL;
833 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
836 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
838 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
839 _sub_obj_mouse_down, sd);
840 evas_object_smart_member_del(sobj);
841 if (_elm_widget_is(sobj))
843 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
846 // set the resize obj up
847 sd->resize_obj = sobj;
850 if (_elm_widget_is(sd->resize_obj))
852 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
853 if (sd2) sd2->parent_obj = obj;
854 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
857 evas_object_clip_set(sobj, evas_object_clip_get(obj));
858 evas_object_smart_member_add(sobj, obj);
859 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
861 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
862 _sub_obj_mouse_down, sd);
863 _smart_reconfigure(sd);
864 evas_object_data_set(sobj, "elm-parent", obj);
865 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
866 if (_elm_widget_is(sobj))
868 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
874 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
879 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
882 sd->hover_obj = sobj;
885 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
887 _smart_reconfigure(sd);
892 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
895 sd->can_focus = can_focus;
898 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
900 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
901 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
903 (void *)(long) EVAS_CALLBACK_KEY_UP);
904 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
906 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
910 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
912 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
914 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
920 elm_widget_can_focus_get(const Evas_Object *obj)
922 API_ENTRY return EINA_FALSE;
923 return sd->can_focus;
927 elm_widget_child_can_focus_get(const Evas_Object *obj)
929 API_ENTRY return EINA_FALSE;
930 return sd->child_can_focus;
934 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
937 sd->highlight_ignore = !!ignore;
941 elm_widget_highlight_ignore_get(const Evas_Object *obj)
943 API_ENTRY return EINA_FALSE;
944 return sd->highlight_ignore;
948 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
951 sd->highlight_in_theme = !!highlight;
952 /* FIXME: if focused, it should switch from one mode to the other */
956 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
958 API_ENTRY return EINA_FALSE;
959 return sd->highlight_in_theme;
963 elm_widget_focus_get(const Evas_Object *obj)
965 API_ENTRY return EINA_FALSE;
970 elm_widget_focused_object_get(const Evas_Object *obj)
972 const Evas_Object *subobj;
974 API_ENTRY return NULL;
976 if (!sd->focused) return NULL;
977 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
979 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
980 if (fobj) return fobj;
982 return (Evas_Object *)obj;
986 elm_widget_top_get(const Evas_Object *obj)
988 API_ENTRY return NULL;
989 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
990 return (Evas_Object *)obj;
994 elm_widget_is(const Evas_Object *obj)
996 return _elm_widget_is(obj);
1000 elm_widget_parent_widget_get(const Evas_Object *obj)
1002 Evas_Object *parent;
1004 if (_elm_widget_is(obj))
1006 Smart_Data *sd = evas_object_smart_data_get(obj);
1007 if (!sd) return NULL;
1008 parent = sd->parent_obj;
1012 parent = evas_object_data_get(obj, "elm-parent");
1013 if (!parent) parent = evas_object_smart_parent_get(obj);
1018 Evas_Object *elm_parent;
1019 if (_elm_widget_is(parent)) break;
1020 elm_parent = evas_object_data_get(parent, "elm-parent");
1021 if (elm_parent) parent = elm_parent;
1022 else parent = evas_object_smart_parent_get(parent);
1028 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1031 EINA_SAFETY_ON_NULL_RETURN(func);
1032 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1035 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1039 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1041 API_ENTRY return NULL;
1042 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1044 Elm_Event_Cb_Data *ecd;
1045 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1046 if ((ecd->func == func) && (ecd->data == data))
1049 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1050 return (void *)data;
1056 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
1058 API_ENTRY return EINA_FALSE; //TODO reduce.
1059 if (!_elm_widget_is(obj)) return EINA_FALSE;
1060 Evas_Object *parent = obj;
1061 Elm_Event_Cb_Data *ecd;
1062 Eina_List *l, *l_prev;
1065 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1067 sd = evas_object_smart_data_get(parent);
1068 if ((!sd) || (!_elm_widget_is(obj)))
1069 return EINA_FALSE; //Not Elm Widget
1071 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1074 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1076 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1077 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1080 parent = sd->parent_obj;
1089 * Set custom focus chain.
1091 * This function i set one new and overwrite any previous custom focus chain
1092 * with the list of objects. The previous list will be deleted and this list
1093 * will be managed. After setted, don't modity it.
1095 * @note On focus cycle, only will be evaluated children of this container.
1097 * @param obj The container widget
1098 * @param objs Chain of objects to pass focus
1102 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1105 if (!sd->focus_next_func)
1108 elm_widget_focus_custom_chain_unset(obj);
1113 EINA_LIST_FOREACH(objs, l, o)
1115 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1116 _elm_object_focus_chain_del_cb, sd);
1119 sd->focus_chain = objs;
1125 * Get custom focus chain
1127 * @param obj The container widget
1130 EAPI const Eina_List *
1131 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1133 API_ENTRY return NULL;
1134 return (const Eina_List *) sd->focus_chain;
1140 * Unset custom focus chain
1142 * @param obj The container widget
1146 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1149 Eina_List *l, *l_next;
1152 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1154 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1155 _elm_object_focus_chain_del_cb, sd);
1156 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1163 * Append object to custom focus chain.
1165 * @note If relative_child equal to NULL or not in custom chain, the object
1166 * will be added in end.
1168 * @note On focus cycle, only will be evaluated children of this container.
1170 * @param obj The container widget
1171 * @param child The child to be added in custom chain
1172 * @param relative_child The relative object to position the child
1176 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1179 EINA_SAFETY_ON_NULL_RETURN(child);
1180 if (!sd->focus_next_func)
1183 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1184 _elm_object_focus_chain_del_cb, sd);
1186 if (!relative_child)
1188 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1192 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1199 * Prepend object to custom focus chain.
1201 * @note If relative_child equal to NULL or not in custom chain, the object
1202 * will be added in begin.
1204 * @note On focus cycle, only will be evaluated children of this container.
1206 * @param obj The container widget
1207 * @param child The child to be added in custom chain
1208 * @param relative_child The relative object to position the child
1212 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1215 EINA_SAFETY_ON_NULL_RETURN(child);
1216 if (!sd->focus_next_func)
1219 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1220 _elm_object_focus_chain_del_cb, sd);
1222 if (!relative_child)
1224 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1228 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1235 * Give focus to next object in object tree.
1237 * Give focus to next object in focus chain of one object sub-tree.
1238 * If the last object of chain already have focus, the focus will go to the
1239 * first object of chain.
1241 * @param obj The widget root of sub-tree
1242 * @param dir Direction to cycle the focus
1247 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1249 Evas_Object *target = NULL;
1250 if (!_elm_widget_is(obj))
1252 elm_widget_focus_next_get(obj, dir, &target);
1254 elm_widget_focus_steal(target);
1260 * Give focus to near object in one direction.
1262 * Give focus to near object in direction of one object.
1263 * If none focusable object in given direction, the focus will not change.
1265 * @param obj The reference widget
1266 * @param x Horizontal component of direction to focus
1267 * @param y Vertical component of direction to focus
1272 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1280 * Get next object in focus chain of object tree.
1282 * Get next object in focus chain of one object sub-tree.
1283 * Return the next object by reference. If don't have any candidate to receive
1284 * focus before chain end, the first candidate will be returned.
1286 * @param obj The widget root of sub-tree
1287 * @param dir Direction os focus chain
1288 * @param next The next object in focus chain
1289 * @return EINA_TRUE if don't need focus chain restart/loop back
1290 * to use 'next' obj.
1295 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1301 API_ENTRY return EINA_FALSE;
1303 /* Ignore if disabled */
1304 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1308 if (sd->focus_next_func)
1309 return sd->focus_next_func(obj, dir, next);
1311 if (!elm_widget_can_focus_get(obj))
1315 *next = (Evas_Object *)obj;
1316 return !elm_widget_focus_get(obj);
1323 * Get next object in focus chain of object tree in list.
1325 * Get next object in focus chain of one object sub-tree ordered by one list.
1326 * Return the next object by reference. If don't have any candidate to receive
1327 * focus before list end, the first candidate will be returned.
1329 * @param obj The widget root of sub-tree
1330 * @param dir Direction os focus chain
1331 * @param items list with ordered objects
1332 * @param list_data_get function to get the object from one item of list
1333 * @param next The next object in focus chain
1334 * @return EINA_TRUE if don't need focus chain restart/loop back
1335 * to use 'next' obj.
1340 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)
1342 Eina_List *(*list_next) (const Eina_List *list);
1348 if (!_elm_widget_is(obj))
1355 if (dir == ELM_FOCUS_PREVIOUS)
1357 items = eina_list_last(items);
1358 list_next = eina_list_prev;
1360 else if (dir == ELM_FOCUS_NEXT)
1361 list_next = eina_list_next;
1365 const Eina_List *l = items;
1367 /* Recovery last focused sub item */
1368 if (elm_widget_focus_get(obj))
1369 for (; l; l = list_next(l))
1371 Evas_Object *cur = list_data_get(l);
1372 if (elm_widget_focus_get(cur)) break;
1375 const Eina_List *start = l;
1376 Evas_Object *to_focus = NULL;
1378 /* Interate sub items */
1379 /* Go to end of list */
1380 for (; l; l = list_next(l))
1382 Evas_Object *tmp = NULL;
1383 Evas_Object *cur = list_data_get(l);
1385 if (elm_widget_parent_get(cur) != obj)
1388 /* Try Focus cycle in subitem */
1389 if (elm_widget_focus_next_get(cur, dir, &tmp))
1394 else if ((tmp) && (!to_focus))
1400 /* Get First possible */
1401 for (;l != start; l = list_next(l))
1403 Evas_Object *tmp = NULL;
1404 Evas_Object *cur = list_data_get(l);
1406 if (elm_widget_parent_get(cur) != obj)
1409 /* Try Focus cycle in subitem */
1410 elm_widget_focus_next_get(cur, dir, &tmp);
1423 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1426 if (!sd->signal_func) return;
1427 sd->signal_func(obj, emission, source);
1431 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1433 Edje_Signal_Data *esd = data;
1434 esd->func(esd->data, esd->obj, emission, source);
1438 elm_widget_signal_callback_add(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func, void *data)
1440 Edje_Signal_Data *esd;
1442 if (!sd->callback_add_func) return;
1443 EINA_SAFETY_ON_NULL_RETURN(func);
1445 esd = ELM_NEW(Edje_Signal_Data);
1450 esd->emission = eina_stringshare_add(emission);
1451 esd->source = eina_stringshare_add(source);
1453 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1454 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1458 elm_widget_signal_callback_del(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func)
1460 Edje_Signal_Data *esd;
1463 API_ENTRY return NULL;
1464 if (!sd->callback_del_func) return NULL;
1466 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1468 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1469 (!strcmp(esd->source, source)))
1471 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1472 eina_stringshare_del(esd->emission);
1473 eina_stringshare_del(esd->source);
1479 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1484 elm_widget_focus_set(Evas_Object *obj, int first)
1490 sd->focus_order = focus_order;
1491 sd->focused = EINA_TRUE;
1492 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1496 sd->focus_func(obj);
1503 if ((_is_focusable(sd->resize_obj)) &&
1504 (!elm_widget_disabled_get(sd->resize_obj)))
1506 elm_widget_focus_set(sd->resize_obj, first);
1512 EINA_LIST_FOREACH(sd->subobjs, l, child)
1514 if ((_is_focusable(child)) &&
1515 (!elm_widget_disabled_get(child)))
1517 elm_widget_focus_set(child, first);
1527 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1529 if ((_is_focusable(child)) &&
1530 (!elm_widget_disabled_get(child)))
1532 elm_widget_focus_set(child, first);
1538 if ((_is_focusable(sd->resize_obj)) &&
1539 (!elm_widget_disabled_get(sd->resize_obj)))
1541 elm_widget_focus_set(sd->resize_obj, first);
1549 elm_widget_parent_get(const Evas_Object *obj)
1551 API_ENTRY return NULL;
1552 return sd->parent_obj;
1556 elm_widget_focused_object_clear(Evas_Object *obj)
1559 if (!sd->focused) return;
1560 if (elm_widget_focus_get(sd->resize_obj))
1561 elm_widget_focused_object_clear(sd->resize_obj);
1566 EINA_LIST_FOREACH(sd->subobjs, l, child)
1568 if (elm_widget_focus_get(child))
1570 elm_widget_focused_object_clear(child);
1575 sd->focused = EINA_FALSE;
1576 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1577 if (sd->focus_func) sd->focus_func(obj);
1581 elm_widget_focus_steal(Evas_Object *obj)
1583 Evas_Object *parent, *o;
1586 if (sd->focused) return;
1587 if (sd->disabled) return;
1591 o = elm_widget_parent_get(parent);
1593 sd = evas_object_smart_data_get(o);
1594 if (sd->focused) break;
1597 if (!elm_widget_parent_get(parent))
1598 elm_widget_focused_object_clear(parent);
1601 parent = elm_widget_parent_get(parent);
1602 sd = evas_object_smart_data_get(parent);
1603 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1604 elm_widget_focused_object_clear(sd->resize_obj);
1609 EINA_LIST_FOREACH(sd->subobjs, l, child)
1611 if (elm_widget_focus_get(child))
1613 elm_widget_focused_object_clear(child);
1624 elm_widget_activate(Evas_Object *obj)
1627 elm_widget_change(obj);
1628 if (sd->activate_func) sd->activate_func(obj);
1632 elm_widget_change(Evas_Object *obj)
1635 elm_widget_change(elm_widget_parent_get(obj));
1636 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1640 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1644 if (sd->disabled == disabled) return;
1645 sd->disabled = disabled;
1648 Evas_Object *o, *parent;
1653 o = elm_widget_parent_get(parent);
1657 if (elm_widget_focus_get(obj))
1658 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1660 if (sd->disable_func) sd->disable_func(obj);
1664 elm_widget_disabled_get(const Evas_Object *obj)
1667 return sd->disabled;
1671 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1673 Evas_Object *parent_obj, *child_obj;
1674 Evas_Coord px, py, cx, cy;
1677 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1682 if (sd->on_show_region_func)
1683 sd->on_show_region_func(sd->on_show_region_data, obj);
1687 parent_obj = sd->parent_obj;
1688 child_obj = sd->obj;
1689 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1690 sd = evas_object_smart_data_get(parent_obj);
1693 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1694 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1703 if (sd->on_show_region_func)
1705 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1712 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1724 * Get the focus region of the given widget.
1726 * The focus region is the area of a widget that should brought into the
1727 * visible area when the widget is focused. Mostly used to show the part of
1728 * an entry where the cursor is, for example. The area returned is relative
1729 * to the object @p obj.
1730 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1731 * function will return the full size of the object.
1733 * @param obj The widget object
1734 * @param x Where to store the x coordinate of the area
1735 * @param y Where to store the y coordinate of the area
1736 * @param w Where to store the width of the area
1737 * @param h Where to store the height of the area
1742 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1748 sd = evas_object_smart_data_get(obj);
1749 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1751 evas_object_geometry_get(obj, NULL, NULL, w, h);
1756 sd->on_focus_region_func(obj, x, y, w, h);
1760 elm_widget_scroll_hold_push(Evas_Object *obj)
1764 if (sd->scroll_hold == 1)
1765 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1766 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1767 // FIXME: on delete/reparent hold pop
1771 elm_widget_scroll_hold_pop(Evas_Object *obj)
1775 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1776 if (!sd->scroll_hold)
1777 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1778 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1782 elm_widget_scroll_hold_get(const Evas_Object *obj)
1785 return sd->scroll_hold;
1789 elm_widget_scroll_freeze_push(Evas_Object *obj)
1792 sd->scroll_freeze++;
1793 if (sd->scroll_freeze == 1)
1794 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1795 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1796 // FIXME: on delete/reparent freeze pop
1800 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1803 sd->scroll_freeze--;
1804 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1805 if (!sd->scroll_freeze)
1806 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1807 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1811 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1814 return sd->scroll_freeze;
1818 elm_widget_scale_set(Evas_Object *obj, double scale)
1821 if (scale <= 0.0) scale = 0.0;
1822 if (sd->scale != scale)
1825 elm_widget_theme(obj);
1830 elm_widget_scale_get(const Evas_Object *obj)
1832 API_ENTRY return 1.0;
1833 // FIXME: save walking up the tree by storing/caching parent scale
1834 if (sd->scale == 0.0)
1837 return elm_widget_scale_get(sd->parent_obj);
1845 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1848 if (sd->theme != th)
1850 if (sd->theme) elm_theme_free(sd->theme);
1853 elm_widget_theme(obj);
1858 elm_widget_theme_get(const Evas_Object *obj)
1860 API_ENTRY return NULL;
1864 return elm_widget_theme_get(sd->parent_obj);
1872 elm_widget_style_set(Evas_Object *obj, const char *style)
1876 if (eina_stringshare_replace(&sd->style, style))
1877 elm_widget_theme(obj);
1881 elm_widget_style_get(const Evas_Object *obj)
1883 API_ENTRY return NULL;
1884 if (sd->style) return sd->style;
1889 elm_widget_type_set(Evas_Object *obj, const char *type)
1892 eina_stringshare_replace(&sd->type, type);
1896 elm_widget_type_get(const Evas_Object *obj)
1898 API_ENTRY return NULL;
1899 if (sd->type) return sd->type;
1904 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1907 sd->tooltips = eina_list_append(sd->tooltips, tt);
1911 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1914 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1918 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1921 sd->cursors = eina_list_append(sd->cursors, cur);
1925 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1928 sd->cursors = eina_list_remove(sd->cursors, cur);
1932 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1935 if (sd->drag_x_locked == lock) return;
1936 sd->drag_x_locked = lock;
1937 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1938 else _propagate_x_drag_lock(obj, -1);
1942 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1945 if (sd->drag_y_locked == lock) return;
1946 sd->drag_y_locked = lock;
1947 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1948 else _propagate_y_drag_lock(obj, -1);
1952 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1954 API_ENTRY return EINA_FALSE;
1955 return sd->drag_x_locked;
1959 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1961 API_ENTRY return EINA_FALSE;
1962 return sd->drag_y_locked;
1966 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1969 return sd->child_drag_x_locked;
1973 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1976 return sd->child_drag_y_locked;
1980 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1982 API_ENTRY return EINA_FALSE;
1983 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1987 elm_widget_type_check(const Evas_Object *obj, const char *type)
1989 const char *provided, *expected = "(unknown)";
1990 static int abort_on_warn = -1;
1991 provided = elm_widget_type_get(obj);
1992 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1993 if (type) expected = type;
1994 if ((!provided) || (!provided[0]))
1996 provided = evas_object_type_get(obj);
1997 if ((!provided) || (!provided[0]))
1998 provided = "(unknown)";
2000 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2001 if (abort_on_warn == -1)
2003 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2004 else abort_on_warn = 0;
2006 if (abort_on_warn == 1) abort();
2013 * Split string in words
2015 * @param str Source string
2016 * @return List of const words
2018 * @see elm_widget_stringlist_free()
2022 elm_widget_stringlist_get(const char *str)
2024 Eina_List *list = NULL;
2026 if (!str) return NULL;
2027 for (b = s = str; 1; s++)
2029 if ((*s == ' ') || (!*s))
2031 char *t = malloc(s - b + 1);
2034 strncpy(t, b, s - b);
2036 list = eina_list_append(list, eina_stringshare_add(t));
2047 elm_widget_stringlist_free(Eina_List *list)
2050 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2056 * Allocate a new Elm_Widget_Item-derived structure.
2058 * The goal of this structure is to provide common ground for actions
2059 * that a widget item have, such as the owner widget, callback to
2060 * notify deletion, data pointer and maybe more.
2062 * @param widget the owner widget that holds this item, must be an elm_widget!
2063 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2064 * be used to allocate memory.
2066 * @return allocated memory that is already zeroed out, or NULL on errors.
2068 * @see elm_widget_item_new() convenience macro.
2069 * @see elm_widget_item_del() to release memory.
2072 EAPI Elm_Widget_Item *
2073 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
2075 if (!_elm_widget_is(widget))
2078 Elm_Widget_Item *item;
2080 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2081 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2083 item = calloc(1, alloc_size);
2084 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2086 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2087 item->widget = widget;
2094 * Releases widget item memory, calling back del_cb() if it exists.
2096 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2097 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2098 * this function and then unset it, thus being useful for 2 step
2099 * cleanup whenever the del_cb may use any of the data that must be
2100 * deleted from item.
2102 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2105 * @param item a valid #Elm_Widget_Item to be deleted.
2106 * @see elm_widget_item_del() convenience macro.
2110 _elm_widget_item_del(Elm_Widget_Item *item)
2112 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2115 item->del_cb((void *)item->data, item->widget, item);
2118 evas_object_del(item->view);
2120 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2127 * Notify object will be deleted without actually deleting it.
2129 * This function will callback Elm_Widget_Item::del_cb if it is set
2130 * and then unset it so it is not called twice (ie: from
2131 * elm_widget_item_del()).
2133 * @param item a valid #Elm_Widget_Item to be notified
2134 * @see elm_widget_item_pre_notify_del() convenience macro.
2138 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2140 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2141 if (!item->del_cb) return;
2142 item->del_cb((void *)item->data, item->widget, item);
2143 item->del_cb = NULL;
2149 * Set the function to notify when item is being deleted.
2151 * This function will complain if there was a callback set already,
2152 * however it will set the new one.
2154 * The callback will be called from elm_widget_item_pre_notify_del()
2155 * or elm_widget_item_del() will be called with:
2156 * - data: the Elm_Widget_Item::data value.
2157 * - obj: the Elm_Widget_Item::widget evas object.
2158 * - event_info: the item being deleted.
2160 * @param item a valid #Elm_Widget_Item to be notified
2161 * @see elm_widget_item_del_cb_set() convenience macro.
2165 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2167 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2169 if ((item->del_cb) && (item->del_cb != del_cb))
2170 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2171 item->del_cb, item, del_cb);
2173 item->del_cb = del_cb;
2179 * Set user-data in this item.
2181 * User data may be used to identify this item or just store any
2182 * application data. It is automatically given as the first parameter
2183 * of the deletion notify callback.
2185 * @param item a valid #Elm_Widget_Item to store data in.
2186 * @param data user data to store.
2187 * @see elm_widget_item_del_cb_set() convenience macro.
2191 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2193 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2194 if ((item->data) && (item->data != data))
2195 DBG("Replacing item %p data %p with %p", item, item->data, data);
2202 * Retrieves user-data of this item.
2204 * @param item a valid #Elm_Widget_Item to get data from.
2205 * @see elm_widget_item_data_set()
2209 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2211 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2212 return (void *)item->data;
2215 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2217 struct _Elm_Widget_Item_Tooltip
2219 Elm_Widget_Item *item;
2220 Elm_Tooltip_Item_Content_Cb func;
2221 Evas_Smart_Cb del_cb;
2225 static Evas_Object *
2226 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2228 Evas_Object *label = elm_label_add(obj);
2231 elm_object_style_set(label, "tooltip");
2232 elm_label_label_set(label, data);
2237 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2239 eina_stringshare_del(data);
2245 * Set the text to be shown in the widget item.
2247 * @param item Target item
2248 * @param text The text to set in the content
2250 * Setup the text as tooltip to object. The item can have only one tooltip,
2251 * so any previous tooltip data is removed.
2256 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2258 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2259 EINA_SAFETY_ON_NULL_RETURN(text);
2261 text = eina_stringshare_add(text);
2262 _elm_widget_item_tooltip_content_cb_set
2263 (item, _elm_widget_item_tooltip_label_create, text,
2264 _elm_widget_item_tooltip_label_del_cb);
2267 static Evas_Object *
2268 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2270 Elm_Widget_Item_Tooltip *wit = data;
2271 return wit->func((void *)wit->data, obj, wit->item);
2275 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2277 Elm_Widget_Item_Tooltip *wit = data;
2278 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2285 * Set the content to be shown in the tooltip item
2287 * Setup the tooltip to item. The item can have only one tooltip,
2288 * so any previous tooltip data is removed. @p func(with @p data) will
2289 * be called every time that need show the tooltip and it should
2290 * return a valid Evas_Object. This object is then managed fully by
2291 * tooltip system and is deleted when the tooltip is gone.
2293 * @param item the widget item being attached a tooltip.
2294 * @param func the function used to create the tooltip contents.
2295 * @param data what to provide to @a func as callback data/context.
2296 * @param del_cb called when data is not needed anymore, either when
2297 * another callback replaces @func, the tooltip is unset with
2298 * elm_widget_item_tooltip_unset() or the owner @a item
2299 * dies. This callback receives as the first parameter the
2300 * given @a data, and @c event_info is the item.
2305 _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)
2307 Elm_Widget_Item_Tooltip *wit;
2309 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2313 _elm_widget_item_tooltip_unset(item);
2317 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2318 if (!wit) goto error;
2322 wit->del_cb = del_cb;
2324 elm_object_sub_tooltip_content_cb_set
2325 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2326 _elm_widget_item_tooltip_del_cb);
2331 if (del_cb) del_cb((void *)data, NULL, item);
2334 if (del_cb) del_cb((void *)data, item->widget, item);
2340 * Unset tooltip from item
2342 * @param item widget item to remove previously set tooltip.
2344 * Remove tooltip from item. The callback provided as del_cb to
2345 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2346 * it is not used anymore.
2348 * @see elm_widget_item_tooltip_content_cb_set()
2353 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2355 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2356 elm_object_tooltip_unset(item->view);
2362 * Sets a different style for this item tooltip.
2364 * @note before you set a style you should define a tooltip with
2365 * elm_widget_item_tooltip_content_cb_set() or
2366 * elm_widget_item_tooltip_text_set()
2368 * @param item widget item with tooltip already set.
2369 * @param style the theme style to use (default, transparent, ...)
2374 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2376 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2377 elm_object_tooltip_style_set(item->view, style);
2383 * Get the style for this item tooltip.
2385 * @param item widget item with tooltip already set.
2386 * @return style the theme style in use, defaults to "default". If the
2387 * object does not have a tooltip set, then NULL is returned.
2392 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2394 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2395 return elm_object_tooltip_style_get(item->view);
2399 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2401 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2402 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2406 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2408 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2409 return elm_object_cursor_get(item->view);
2413 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2415 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2416 elm_object_cursor_unset(item->view);
2422 * Sets a different style for this item cursor.
2424 * @note before you set a style you should define a cursor with
2425 * elm_widget_item_cursor_set()
2427 * @param item widget item with cursor already set.
2428 * @param style the theme style to use (default, transparent, ...)
2433 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2435 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2436 elm_object_cursor_style_set(item->view, style);
2442 * Get the style for this item cursor.
2444 * @param item widget item with cursor already set.
2445 * @return style the theme style in use, defaults to "default". If the
2446 * object does not have a cursor set, then NULL is returned.
2451 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2453 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2454 return elm_object_cursor_style_get(item->view);
2460 * Set if the cursor set should be searched on the theme or should use
2461 * the provided by the engine, only.
2463 * @note before you set if should look on theme you should define a cursor
2464 * with elm_object_cursor_set(). By default it will only look for cursors
2465 * provided by the engine.
2467 * @param item widget item with cursor already set.
2468 * @param engine_only boolean to define it cursors should be looked only
2469 * between the provided by the engine or searched on widget's theme as well.
2474 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2476 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2477 elm_object_cursor_engine_only_set(item->view, engine_only);
2483 * Get the cursor engine only usage for this item cursor.
2485 * @param item widget item with cursor already set.
2486 * @return engine_only boolean to define it cursors should be looked only
2487 * between the provided by the engine or searched on widget's theme as well. If
2488 * the object does not have a cursor set, then EINA_FALSE is returned.
2493 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2495 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2496 return elm_object_cursor_engine_only_get(item->view);
2499 // smart object funcs
2501 _smart_reconfigure(Smart_Data *sd)
2505 evas_object_move(sd->resize_obj, sd->x, sd->y);
2506 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2510 evas_object_move(sd->hover_obj, sd->x, sd->y);
2511 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2516 _smart_add(Evas_Object *obj)
2520 sd = calloc(1, sizeof(Smart_Data));
2523 sd->x = sd->y = sd->w = sd->h = 0;
2525 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2526 evas_object_smart_data_set(obj, sd);
2529 static Evas_Object *
2530 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2533 Evas_Object *child, *ret, *best;
2535 API_ENTRY return NULL;
2536 if (!evas_object_visible_get(obj)) return NULL;
2538 if (*newest_focus_order < sd->focus_order)
2540 *newest_focus_order = sd->focus_order;
2543 EINA_LIST_FOREACH(sd->subobjs, l, child)
2545 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2551 if ((!best) || (!elm_widget_can_focus_get(best)))
2558 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2561 Evas_Object *newest = NULL;
2562 unsigned int newest_focus_order = 0;
2566 if (!sd->focused) return;
2567 if (!sd->parent_obj) return;
2569 top = elm_widget_top_get(sd->parent_obj);
2572 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2575 elm_object_unfocus(newest);
2576 elm_object_focus(newest);
2582 _smart_del(Evas_Object *obj)
2585 Edje_Signal_Data *esd;
2589 if (sd->del_pre_func) sd->del_pre_func(obj);
2592 sobj = sd->resize_obj;
2593 sd->resize_obj = NULL;
2594 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2595 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2596 evas_object_del(sobj);
2600 sobj = sd->hover_obj;
2601 sd->hover_obj = NULL;
2602 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2603 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2604 evas_object_del(sobj);
2606 EINA_LIST_FREE(sd->subobjs, sobj)
2608 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2609 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2610 evas_object_del(sobj);
2612 eina_list_free(sd->tooltips); /* should be empty anyway */
2613 eina_list_free(sd->cursors); /* should be empty anyway */
2614 EINA_LIST_FREE(sd->edje_signals, esd)
2616 eina_stringshare_del(esd->emission);
2617 eina_stringshare_del(esd->source);
2620 eina_list_free(sd->event_cb); /* should be empty anyway */
2621 if (sd->del_func) sd->del_func(obj);
2622 if (sd->style) eina_stringshare_del(sd->style);
2623 if (sd->type) eina_stringshare_del(sd->type);
2624 if (sd->theme) elm_theme_free(sd->theme);
2625 _if_focused_revert(obj, EINA_TRUE);
2630 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2635 _smart_reconfigure(sd);
2639 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2644 _smart_reconfigure(sd);
2648 _smart_show(Evas_Object *obj)
2653 if ((list = evas_object_smart_members_get(obj)))
2655 EINA_LIST_FREE(list, o)
2657 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2658 evas_object_show(o);
2664 _smart_hide(Evas_Object *obj)
2669 list = evas_object_smart_members_get(obj);
2670 EINA_LIST_FREE(list, o)
2672 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2673 evas_object_hide(o);
2678 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2683 if ((list = evas_object_smart_members_get(obj)))
2685 EINA_LIST_FREE(list, o)
2687 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2688 evas_object_color_set(o, r, g, b, a);
2694 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2699 if ((list = evas_object_smart_members_get(obj)))
2701 EINA_LIST_FREE(list, o)
2703 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2704 evas_object_clip_set(o, clip);
2710 _smart_clip_unset(Evas_Object *obj)
2715 if ((list = evas_object_smart_members_get(obj)))
2717 EINA_LIST_FREE(list, o)
2719 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2720 evas_object_clip_unset(o);
2726 _smart_calculate(Evas_Object *obj)
2729 if (sd->changed_func) sd->changed_func(obj);
2732 /* never need to touch this */
2736 if (_e_smart) return;
2738 static const Evas_Smart_Class sc =
2741 EVAS_SMART_CLASS_VERSION,
2759 _e_smart = evas_smart_class_new(&sc);
2763 /* happy debug functions */
2766 _sub_obj_tree_dump(const Evas_Object *obj, int lvl)
2770 for (i = 0; i < lvl*3; i++)
2773 if (_elm_widget_is(obj))
2777 printf("+ %s(%p)\n", sd->type, obj);
2779 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2780 EINA_LIST_FOREACH(sd->subobjs, l, obj)
2782 if (obj != sd->resize_obj)
2783 _sub_obj_tree_dump(obj, lvl + 1);
2787 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
2791 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2793 if (!_elm_widget_is(obj))
2797 Eina_Bool visible = evas_object_visible_get(obj);
2798 Eina_Bool disabled = elm_widget_disabled_get(obj);
2799 Eina_Bool focused = elm_widget_focus_get(obj);
2800 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2804 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2807 fprintf(output, ", style=bold");
2810 fprintf(output, ", color=gray28");
2812 fprintf(output, " ];\n");
2815 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2816 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2817 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2821 fprintf(output, ", style=bold");
2824 fprintf(output, ", fontcolor=gray28");
2826 if ((disabled) || (!visible))
2827 fprintf(output, ", color=gray");
2830 fprintf(output, " ];\n");
2834 EINA_LIST_FOREACH(sd->subobjs, l, o)
2835 _sub_obj_tree_dot_dump(o, output);
2840 elm_widget_tree_dump(const Evas_Object *top)
2843 _sub_obj_tree_dump(top, 0);
2851 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2854 if (!_elm_widget_is(top))
2856 fprintf(output, "graph "" { node [shape=record];\n");
2857 _sub_obj_tree_dot_dump(top, output);
2858 fprintf(output, "}\n");