1 #include <Elementary.h>
4 static const char SMART_NAME[] = "elm_widget";
7 Smart_Data *sd = evas_object_smart_data_get(obj); \
8 if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
9 #define INTERNAL_ENTRY \
10 Smart_Data *sd = evas_object_smart_data_get(obj); \
13 typedef struct _Smart_Data Smart_Data;
14 typedef struct _Edje_Signal_Data Edje_Signal_Data;
15 typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data;
21 Evas_Object *parent_obj;
22 Evas_Coord x, y, w, h;
24 Evas_Object *resize_obj;
25 Evas_Object *hover_obj;
26 Eina_List *tooltips, *cursors;
27 void (*del_func) (Evas_Object *obj);
28 void (*del_pre_func) (Evas_Object *obj);
29 void (*focus_func) (Evas_Object *obj);
30 void (*activate_func) (Evas_Object *obj);
31 void (*disable_func) (Evas_Object *obj);
32 void (*theme_func) (Evas_Object *obj);
33 Eina_Bool (*event_func) (Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info);
34 void (*signal_func) (Evas_Object *obj, const char *emission,
36 void (*callback_add_func) (Evas_Object *obj, const char *emission,
37 const char *source, void (*func) (void *data,
38 Evas_Object *o, const char *emission,
39 const char *source), void *data);
40 void (*callback_del_func) (Evas_Object *obj, const char *emission,
41 const char *source, void (*func) (void *data,
42 Evas_Object *o, const char *emission,
43 const char *source), void *data);
44 void (*changed_func) (Evas_Object *obj);
45 Eina_Bool (*focus_next_func) (const Evas_Object *obj, Elm_Focus_Direction dir,
47 void (*on_focus_func) (void *data, Evas_Object *obj);
49 void (*on_change_func) (void *data, Evas_Object *obj);
51 void (*on_show_region_func) (void *data, Evas_Object *obj);
52 void *on_show_region_data;
53 void (*focus_region_func) (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
54 void (*on_focus_region_func) (const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
56 Evas_Coord rx, ry, rw, rh;
62 unsigned int focus_order;
63 Eina_Bool focus_order_on_calc;
65 int child_drag_x_locked;
66 int child_drag_y_locked;
68 Eina_List *edje_signals;
70 Eina_Bool drag_x_locked : 1;
71 Eina_Bool drag_y_locked : 1;
73 Eina_Bool can_focus : 1;
74 Eina_Bool child_can_focus : 1;
75 Eina_Bool focused : 1;
76 Eina_Bool highlight_ignore : 1;
77 Eina_Bool highlight_in_theme : 1;
78 Eina_Bool disabled : 1;
79 Eina_Bool is_mirrored : 1;
80 Eina_Bool mirrored_auto_mode : 1; /* This is TRUE by default */
82 Eina_List *focus_chain;
86 struct _Edje_Signal_Data
95 struct _Elm_Event_Cb_Data {
100 /* local subsystem functions */
101 static void _smart_reconfigure(Smart_Data *sd);
102 static void _smart_add(Evas_Object *obj);
103 static void _smart_del(Evas_Object *obj);
104 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
105 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
106 static void _smart_show(Evas_Object *obj);
107 static void _smart_hide(Evas_Object *obj);
108 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
109 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
110 static void _smart_clip_unset(Evas_Object *obj);
111 static void _smart_calculate(Evas_Object *obj);
112 static void _smart_init(void);
114 static void _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only);
115 static Evas_Object *_newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only);
117 /* local subsystem globals */
118 static Evas_Smart *_e_smart = NULL;
119 static Eina_List *widtypes = NULL;
121 static unsigned int focus_order = 0;
124 static inline Eina_Bool
125 _elm_widget_is(const Evas_Object *obj)
127 const char *type = evas_object_type_get(obj);
128 return type == SMART_NAME;
131 static inline Eina_Bool
132 _is_focusable(Evas_Object *obj)
134 API_ENTRY return EINA_FALSE;
135 return sd->can_focus || (sd->child_can_focus);
139 _unfocus_parents(Evas_Object *obj)
141 for (; obj; obj = elm_widget_parent_get(obj))
144 if (!sd->focused) return;
150 _focus_parents(Evas_Object *obj)
152 for (; obj; obj = elm_widget_parent_get(obj))
155 if (sd->focused) return;
161 _sub_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
163 Smart_Data *sd = data;
165 if (_elm_widget_is(obj))
167 if (elm_widget_focus_get(obj)) _unfocus_parents(sd->obj);
169 if (obj == sd->resize_obj)
170 sd->resize_obj = NULL;
171 else if (obj == sd->hover_obj)
172 sd->hover_obj = NULL;
174 sd->subobjs = eina_list_remove(sd->subobjs, obj);
175 evas_object_smart_callback_call(sd->obj, "sub-object-del", obj);
179 _sub_obj_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
181 _if_focused_revert(obj, EINA_TRUE);
185 _sub_obj_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
187 Evas_Object *o = obj;
190 if (_elm_widget_is(o)) break;
191 o = evas_object_smart_parent_get(o);
195 if (!_is_focusable(o)) return;
196 elm_widget_focus_steal(o);
200 _propagate_x_drag_lock(Evas_Object *obj, int dir)
205 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
208 sd2->child_drag_x_locked += dir;
209 _propagate_x_drag_lock(sd->parent_obj, dir);
215 _propagate_y_drag_lock(Evas_Object *obj, int dir)
220 Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
223 sd2->child_drag_y_locked += dir;
224 _propagate_y_drag_lock(sd->parent_obj, dir);
230 _propagate_event(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
233 Evas_Callback_Type type = (Evas_Callback_Type)(long) data;
234 Evas_Event_Flags *event_flags = NULL;
238 case EVAS_CALLBACK_KEY_DOWN:
240 Evas_Event_Key_Down *ev = event_info;
241 event_flags = &(ev->event_flags);
244 case EVAS_CALLBACK_KEY_UP:
246 Evas_Event_Key_Up *ev = event_info;
247 event_flags = &(ev->event_flags);
250 case EVAS_CALLBACK_MOUSE_WHEEL:
252 Evas_Event_Mouse_Wheel *ev = event_info;
253 event_flags = &(ev->event_flags);
260 elm_widget_event_propagate(obj, type, event_info, event_flags);
264 _parent_focus(Evas_Object *obj)
268 Evas_Object *o = elm_widget_parent_get(obj);
269 sd->focus_order_on_calc = EINA_TRUE;
271 if (sd->focused) return;
277 ret = _newest_focus_order_get(o, &i, EINA_TRUE);
279 /* we don't want to bump a common widget ancestor's
280 focus_order *twice* while parent focusing */
281 if (!ret || (!i) || (i != focus_order))
285 if (!sd->focus_order_on_calc)
286 return; /* we don't want to override it if by means of any of the
287 callbacks below one gets to calculate our order
291 sd->focus_order = focus_order;
292 sd->focused = EINA_TRUE;
293 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
294 if (sd->focus_func) sd->focus_func(obj);
296 _elm_widget_focus_region_show(obj);
298 sd->focus_order_on_calc = EINA_FALSE;
302 _elm_object_focus_chain_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
304 Smart_Data *sd = data;
306 sd->focus_chain = eina_list_remove(sd->focus_chain, obj);
309 // exposed util funcs to elm
311 _elm_widget_type_clear(void)
315 EINA_LIST_FREE(widtypes, ptr)
317 eina_stringshare_del(*ptr);
323 _elm_widget_focus_region_show(const Evas_Object *obj)
325 Evas_Coord x, y, w, h, ox, oy;
331 o = elm_widget_parent_get(obj);
334 elm_widget_focus_region_get(obj, &x, &y, &w, &h);
335 evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
339 sd2 = evas_object_smart_data_get(o);
340 if (sd2->focus_region_func)
342 sd2->focus_region_func(o, x, y, w, h);
343 elm_widget_focus_region_get(o, &x, &y, &w, &h);
347 evas_object_geometry_get(o, &px, &py, NULL, NULL);
353 o = elm_widget_parent_get(o);
358 * @defgroup Widget Widget
361 * Exposed api for making widgets
364 elm_widget_type_register(const char **ptr)
366 widtypes = eina_list_append(widtypes, (void *)ptr);
370 elm_widget_api_check(int ver)
372 if (ver != ELM_INTERNAL_API_VERSION)
374 CRITICAL("Elementary widget api versions do not match");
381 elm_widget_add(Evas *evas)
385 obj = evas_object_smart_add(evas, _e_smart);
386 elm_widget_mirrored_set(obj, elm_mirrored_get());
391 elm_widget_del_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
398 elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
401 sd->del_pre_func = func;
405 elm_widget_focus_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
408 sd->focus_func = func;
412 elm_widget_activate_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
415 sd->activate_func = func;
419 elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
422 sd->disable_func = func;
426 elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
429 sd->theme_func = func;
433 elm_widget_event_hook_set(Evas_Object *obj, Eina_Bool (*func) (Evas_Object *obj, Evas_Object *source, Evas_Callback_Type type, void *event_info))
436 sd->event_func = func;
440 elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj))
443 sd->changed_func = func;
447 elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
450 sd->signal_func = func;
454 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))
457 sd->callback_add_func = func;
461 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))
464 sd->callback_del_func = func;
468 elm_widget_theme(Evas_Object *obj)
476 EINA_LIST_FOREACH(sd->subobjs, l, child) elm_widget_theme(child);
477 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
478 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
479 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
480 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
481 if (sd->theme_func) sd->theme_func(obj);
485 elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force)
491 Elm_Theme *th2, *thdef;
494 thdef = elm_theme_default_get();
499 if (!th2) th2 = thdef;
507 if (th2 == thdef) break;
508 th2 = th2->ref_theme;
509 if (!th2) th2 = thdef;
513 EINA_LIST_FOREACH(sd->subobjs, l, child)
514 elm_widget_theme_specific(child, th, force);
515 if (sd->resize_obj) elm_widget_theme(sd->resize_obj);
516 if (sd->hover_obj) elm_widget_theme(sd->hover_obj);
517 EINA_LIST_FOREACH(sd->tooltips, l, tt) elm_tooltip_theme(tt);
518 EINA_LIST_FOREACH(sd->cursors, l, cur) elm_cursor_theme(cur);
519 if (sd->theme_func) sd->theme_func(obj);
525 * Set hook to get next object in object focus chain.
527 * @param obj The widget object.
528 * @param func The hook to be used with this widget.
533 elm_widget_focus_next_hook_set(Evas_Object *obj, Eina_Bool (*func) (const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next))
536 sd->focus_next_func = func;
540 * Returns the widget's mirrored mode.
542 * @param obj The widget.
543 * @return mirrored mode of the object.
547 elm_widget_mirrored_get(const Evas_Object *obj)
549 API_ENTRY return EINA_FALSE;
550 return sd->is_mirrored;
554 * Sets the widget's mirrored mode.
556 * @param obj The widget.
557 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
560 elm_widget_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
563 if (sd->is_mirrored != mirrored)
565 sd->is_mirrored = mirrored;
566 elm_widget_theme(obj);
572 * Resets the mirrored mode from the system mirror mode for widgets that are in
573 * automatic mirroring mode. This function does not call elm_widget_theme.
575 * @param obj The widget.
576 * @param mirrored EINA_TRUE to set mirrored mode. EINA_FALSE to unset.
579 _elm_widget_mirrored_reload(Evas_Object *obj)
582 Eina_Bool mirrored = elm_mirrored_get();
583 if (elm_widget_mirrored_automatic_get(obj) && (sd->is_mirrored != mirrored))
585 sd->is_mirrored = mirrored;
590 * Returns the widget's mirrored mode setting.
592 * @param obj The widget.
593 * @return mirrored mode setting of the object.
597 elm_widget_mirrored_automatic_get(const Evas_Object *obj)
599 API_ENTRY return EINA_FALSE;
600 return sd->mirrored_auto_mode;
604 * Sets the widget's mirrored mode setting.
605 * When widget in automatic mode, it follows the system mirrored mode set by
606 * elm_mirrored_set().
607 * @param obj The widget.
608 * @param automatic EINA_TRUE for auto mirrored mode. EINA_FALSE for manual.
611 elm_widget_mirrored_automatic_set(Evas_Object *obj, Eina_Bool automatic)
614 if (sd->mirrored_auto_mode != automatic)
616 sd->mirrored_auto_mode = automatic;
620 elm_widget_mirrored_set(obj, elm_mirrored_get());
626 elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
629 sd->on_focus_func = func;
630 sd->on_focus_data = data;
634 elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
637 sd->on_change_func = func;
638 sd->on_change_data = data;
642 elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data)
645 sd->on_show_region_func = func;
646 sd->on_show_region_data = data;
652 * Set the hook to use to show the focused region.
654 * Whenever a new widget gets focused or it's needed to show the focused
655 * area of the current one, this hook will be called on objects that may
656 * want to move their children into their visible area.
657 * The area given in the hook function is relative to the @p obj widget.
659 * @param obj The widget object
660 * @param func The function to call to show the specified area.
665 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))
668 sd->focus_region_func = func;
674 * Set the hook to retrieve the focused region of a widget.
676 * This hook will be called by elm_widget_focus_region_get() whenever
677 * it's needed to get the focused area of a widget. The area must be relative
678 * to the widget itself and if no hook is set, it will default to the entire
681 * @param obj The widget object
682 * @param func The function used to retrieve the focus region.
687 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))
690 sd->on_focus_region_func = func;
694 elm_widget_data_set(Evas_Object *obj, void *data)
701 elm_widget_data_get(const Evas_Object *obj)
703 API_ENTRY return NULL;
708 elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
711 double scale, pscale = elm_widget_scale_get(sobj);
712 Elm_Theme *th, *pth = elm_widget_theme_get(sobj);
713 Eina_Bool mirrored, pmirrored = elm_widget_mirrored_get(obj);
715 if (_elm_widget_is(sobj))
717 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
720 if (sd2->parent_obj == obj)
723 elm_widget_sub_object_del(sd2->parent_obj, sobj);
724 sd2->parent_obj = obj;
725 if (!sd->child_can_focus && (_is_focusable(sobj)))
726 sd->child_can_focus = EINA_TRUE;
731 void *data = evas_object_data_get(sobj, "elm-parent");
734 if (data == obj) return;
735 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL,
740 sd->subobjs = eina_list_append(sd->subobjs, sobj);
741 evas_object_data_set(sobj, "elm-parent", obj);
742 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
743 if (_elm_widget_is(sobj))
744 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE, _sub_obj_hide, sd);
745 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
746 scale = elm_widget_scale_get(sobj);
747 th = elm_widget_theme_get(sobj);
748 mirrored = elm_widget_mirrored_get(sobj);
749 if ((scale != pscale) || (th != pth) || (pmirrored != mirrored)) elm_widget_theme(sobj);
750 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
754 elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
756 Evas_Object *sobj_parent;
760 sobj_parent = evas_object_data_del(sobj, "elm-parent");
761 if (sobj_parent != obj)
763 static int abort_on_warn = -1;
764 ERR("removing sub object %p from parent %p, "
765 "but elm-parent is different %p!",
766 sobj, obj, sobj_parent);
767 if (EINA_UNLIKELY(abort_on_warn == -1))
769 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
770 else abort_on_warn = 0;
772 if (abort_on_warn == 1) abort();
774 if (!sd->child_can_focus)
776 if (_is_focusable(sobj)) sd->child_can_focus = 0;
778 if (_elm_widget_is(sobj))
780 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
783 sd2->parent_obj = NULL;
784 if (sd2->resize_obj == sobj)
785 sd2->resize_obj = NULL;
787 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
790 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
791 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
794 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
795 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
797 if (_elm_widget_is(sobj))
798 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
800 evas_object_smart_callback_call(obj, "sub-object-del", sobj);
804 elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
807 // orphan previous resize obj
810 evas_object_clip_unset(sd->resize_obj);
811 evas_object_data_del(sd->resize_obj, "elm-parent");
812 if (_elm_widget_is(sd->resize_obj))
814 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
815 if (sd2) sd2->parent_obj = NULL;
816 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_HIDE,
819 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_DEL,
821 evas_object_event_callback_del_full(sd->resize_obj, EVAS_CALLBACK_MOUSE_DOWN,
822 _sub_obj_mouse_down, sd);
823 evas_object_smart_member_del(sd->resize_obj);
824 if (_elm_widget_is(sd->resize_obj))
826 if (elm_widget_focus_get(sd->resize_obj)) _unfocus_parents(obj);
829 // orphan new resize obj
832 evas_object_data_del(sobj, "elm-parent");
833 if (_elm_widget_is(sobj))
835 Smart_Data *sd2 = evas_object_smart_data_get(sobj);
836 if (sd2) sd2->parent_obj = NULL;
837 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_HIDE,
840 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL,
842 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_MOUSE_DOWN,
843 _sub_obj_mouse_down, sd);
844 evas_object_smart_member_del(sobj);
845 if (_elm_widget_is(sobj))
847 if (elm_widget_focus_get(sobj)) _unfocus_parents(obj);
850 // set the resize obj up
851 sd->resize_obj = sobj;
854 if (_elm_widget_is(sd->resize_obj))
856 Smart_Data *sd2 = evas_object_smart_data_get(sd->resize_obj);
857 if (sd2) sd2->parent_obj = obj;
858 evas_object_event_callback_add(sobj, EVAS_CALLBACK_HIDE,
861 evas_object_clip_set(sobj, evas_object_clip_get(obj));
862 evas_object_smart_member_add(sobj, obj);
863 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
865 evas_object_event_callback_add(sobj, EVAS_CALLBACK_MOUSE_DOWN,
866 _sub_obj_mouse_down, sd);
867 _smart_reconfigure(sd);
868 evas_object_data_set(sobj, "elm-parent", obj);
869 evas_object_smart_callback_call(obj, "sub-object-add", sobj);
870 if (_elm_widget_is(sobj))
872 if (elm_widget_focus_get(sobj)) _focus_parents(obj);
878 elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj)
883 evas_object_event_callback_del_full(sd->hover_obj, EVAS_CALLBACK_DEL,
886 sd->hover_obj = sobj;
889 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL,
891 _smart_reconfigure(sd);
896 elm_widget_can_focus_set(Evas_Object *obj, Eina_Bool can_focus)
899 sd->can_focus = can_focus;
902 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
904 (void *)(long) EVAS_CALLBACK_KEY_DOWN);
905 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP,
907 (void *)(long) EVAS_CALLBACK_KEY_UP);
908 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
910 (void *)(long)EVAS_CALLBACK_MOUSE_WHEEL);
914 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_DOWN,
916 evas_object_event_callback_del(obj, EVAS_CALLBACK_KEY_UP,
918 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_WHEEL,
924 elm_widget_can_focus_get(const Evas_Object *obj)
926 API_ENTRY return EINA_FALSE;
927 return sd->can_focus;
931 elm_widget_child_can_focus_get(const Evas_Object *obj)
933 API_ENTRY return EINA_FALSE;
934 return sd->child_can_focus;
938 elm_widget_highlight_ignore_set(Evas_Object *obj, Eina_Bool ignore)
941 sd->highlight_ignore = !!ignore;
945 elm_widget_highlight_ignore_get(const Evas_Object *obj)
947 API_ENTRY return EINA_FALSE;
948 return sd->highlight_ignore;
952 elm_widget_highlight_in_theme_set(Evas_Object *obj, Eina_Bool highlight)
955 sd->highlight_in_theme = !!highlight;
956 /* FIXME: if focused, it should switch from one mode to the other */
960 elm_widget_highlight_in_theme_get(const Evas_Object *obj)
962 API_ENTRY return EINA_FALSE;
963 return sd->highlight_in_theme;
967 elm_widget_focus_get(const Evas_Object *obj)
969 API_ENTRY return EINA_FALSE;
974 elm_widget_focused_object_get(const Evas_Object *obj)
976 const Evas_Object *subobj;
978 API_ENTRY return NULL;
980 if (!sd->focused) return NULL;
981 EINA_LIST_FOREACH(sd->subobjs, l, subobj)
983 Evas_Object *fobj = elm_widget_focused_object_get(subobj);
984 if (fobj) return fobj;
986 return (Evas_Object *)obj;
990 elm_widget_top_get(const Evas_Object *obj)
992 API_ENTRY return NULL;
993 if (sd->parent_obj) return elm_widget_top_get(sd->parent_obj);
994 return (Evas_Object *)obj;
998 elm_widget_is(const Evas_Object *obj)
1000 return _elm_widget_is(obj);
1004 elm_widget_parent_widget_get(const Evas_Object *obj)
1006 Evas_Object *parent;
1008 if (_elm_widget_is(obj))
1010 Smart_Data *sd = evas_object_smart_data_get(obj);
1011 if (!sd) return NULL;
1012 parent = sd->parent_obj;
1016 parent = evas_object_data_get(obj, "elm-parent");
1017 if (!parent) parent = evas_object_smart_parent_get(obj);
1022 Evas_Object *elm_parent;
1023 if (_elm_widget_is(parent)) break;
1024 elm_parent = evas_object_data_get(parent, "elm-parent");
1025 if (elm_parent) parent = elm_parent;
1026 else parent = evas_object_smart_parent_get(parent);
1032 elm_widget_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1035 EINA_SAFETY_ON_NULL_RETURN(func);
1036 Elm_Event_Cb_Data *ecb = ELM_NEW(Elm_Event_Cb_Data);
1039 sd->event_cb = eina_list_append(sd->event_cb, ecb);
1043 elm_widget_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1045 API_ENTRY return NULL;
1046 EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1048 Elm_Event_Cb_Data *ecd;
1049 EINA_LIST_FOREACH(sd->event_cb, l, ecd)
1050 if ((ecd->func == func) && (ecd->data == data))
1053 sd->event_cb = eina_list_remove_list(sd->event_cb, l);
1054 return (void *)data;
1060 elm_widget_event_propagate(Evas_Object *obj, Evas_Callback_Type type, void *event_info, Evas_Event_Flags *event_flags)
1062 API_ENTRY return EINA_FALSE; //TODO reduce.
1063 if (!_elm_widget_is(obj)) return EINA_FALSE;
1064 Evas_Object *parent = obj;
1065 Elm_Event_Cb_Data *ecd;
1066 Eina_List *l, *l_prev;
1069 (!(event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD))))
1071 sd = evas_object_smart_data_get(parent);
1072 if ((!sd) || (!_elm_widget_is(obj)))
1073 return EINA_FALSE; //Not Elm Widget
1075 if (sd->event_func && (sd->event_func(parent, obj, type, event_info)))
1078 EINA_LIST_FOREACH_SAFE(sd->event_cb, l, l_prev, ecd)
1080 if (ecd->func((void *)ecd->data, parent, obj, type, event_info) ||
1081 (event_flags && ((*event_flags) & EVAS_EVENT_FLAG_ON_HOLD)))
1084 parent = sd->parent_obj;
1093 * Set custom focus chain.
1095 * This function i set one new and overwrite any previous custom focus chain
1096 * with the list of objects. The previous list will be deleted and this list
1097 * will be managed. After setted, don't modity it.
1099 * @note On focus cycle, only will be evaluated children of this container.
1101 * @param obj The container widget
1102 * @param objs Chain of objects to pass focus
1106 elm_widget_focus_custom_chain_set(Evas_Object *obj, Eina_List *objs)
1109 if (!sd->focus_next_func)
1112 elm_widget_focus_custom_chain_unset(obj);
1117 EINA_LIST_FOREACH(objs, l, o)
1119 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1120 _elm_object_focus_chain_del_cb, sd);
1123 sd->focus_chain = objs;
1129 * Get custom focus chain
1131 * @param obj The container widget
1134 EAPI const Eina_List *
1135 elm_widget_focus_custom_chain_get(const Evas_Object *obj)
1137 API_ENTRY return NULL;
1138 return (const Eina_List *) sd->focus_chain;
1144 * Unset custom focus chain
1146 * @param obj The container widget
1150 elm_widget_focus_custom_chain_unset(Evas_Object *obj)
1153 Eina_List *l, *l_next;
1156 EINA_LIST_FOREACH_SAFE(sd->focus_chain, l, l_next, o)
1158 evas_object_event_callback_del_full(o, EVAS_CALLBACK_DEL,
1159 _elm_object_focus_chain_del_cb, sd);
1160 sd->focus_chain = eina_list_remove_list(sd->focus_chain, l);
1167 * Append object to custom focus chain.
1169 * @note If relative_child equal to NULL or not in custom chain, the object
1170 * will be added in end.
1172 * @note On focus cycle, only will be evaluated children of this container.
1174 * @param obj The container widget
1175 * @param child The child to be added in custom chain
1176 * @param relative_child The relative object to position the child
1180 elm_widget_focus_custom_chain_append(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1183 EINA_SAFETY_ON_NULL_RETURN(child);
1184 if (!sd->focus_next_func)
1187 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1188 _elm_object_focus_chain_del_cb, sd);
1190 if (!relative_child)
1192 sd->focus_chain = eina_list_append(sd->focus_chain, child);
1196 sd->focus_chain = eina_list_append_relative(sd->focus_chain, child, relative_child);
1203 * Prepend object to custom focus chain.
1205 * @note If relative_child equal to NULL or not in custom chain, the object
1206 * will be added in begin.
1208 * @note On focus cycle, only will be evaluated children of this container.
1210 * @param obj The container widget
1211 * @param child The child to be added in custom chain
1212 * @param relative_child The relative object to position the child
1216 elm_widget_focus_custom_chain_prepend(Evas_Object *obj, Evas_Object *child, Evas_Object *relative_child)
1219 EINA_SAFETY_ON_NULL_RETURN(child);
1220 if (!sd->focus_next_func)
1223 evas_object_event_callback_del_full(child, EVAS_CALLBACK_DEL,
1224 _elm_object_focus_chain_del_cb, sd);
1226 if (!relative_child)
1228 sd->focus_chain = eina_list_prepend(sd->focus_chain, child);
1232 sd->focus_chain = eina_list_prepend_relative(sd->focus_chain, child, relative_child);
1239 * Give focus to next object in object tree.
1241 * Give focus to next object in focus chain of one object sub-tree.
1242 * If the last object of chain already have focus, the focus will go to the
1243 * first object of chain.
1245 * @param obj The widget root of sub-tree
1246 * @param dir Direction to cycle the focus
1251 elm_widget_focus_cycle(Evas_Object *obj, Elm_Focus_Direction dir)
1253 Evas_Object *target = NULL;
1254 if (!_elm_widget_is(obj))
1256 elm_widget_focus_next_get(obj, dir, &target);
1258 elm_widget_focus_steal(target);
1264 * Give focus to near object in one direction.
1266 * Give focus to near object in direction of one object.
1267 * If none focusable object in given direction, the focus will not change.
1269 * @param obj The reference widget
1270 * @param x Horizontal component of direction to focus
1271 * @param y Vertical component of direction to focus
1276 elm_widget_focus_direction_go(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1284 * Get next object in focus chain of object tree.
1286 * Get next object in focus chain of one object sub-tree.
1287 * Return the next object by reference. If don't have any candidate to receive
1288 * focus before chain end, the first candidate will be returned.
1290 * @param obj The widget root of sub-tree
1291 * @param dir Direction os focus chain
1292 * @param next The next object in focus chain
1293 * @return EINA_TRUE if don't need focus chain restart/loop back
1294 * to use 'next' obj.
1299 elm_widget_focus_next_get(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
1305 API_ENTRY return EINA_FALSE;
1307 /* Ignore if disabled */
1308 if ((!evas_object_visible_get(obj)) || (elm_widget_disabled_get(obj)))
1312 if (sd->focus_next_func)
1313 return sd->focus_next_func(obj, dir, next);
1315 if (!elm_widget_can_focus_get(obj))
1319 *next = (Evas_Object *)obj;
1320 return !elm_widget_focus_get(obj);
1327 * Get next object in focus chain of object tree in list.
1329 * Get next object in focus chain of one object sub-tree ordered by one list.
1330 * Return the next object by reference. If don't have any candidate to receive
1331 * focus before list end, the first candidate will be returned.
1333 * @param obj The widget root of sub-tree
1334 * @param dir Direction os focus chain
1335 * @param items list with ordered objects
1336 * @param list_data_get function to get the object from one item of list
1337 * @param next The next object in focus chain
1338 * @return EINA_TRUE if don't need focus chain restart/loop back
1339 * to use 'next' obj.
1344 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)
1346 Eina_List *(*list_next) (const Eina_List *list);
1352 if (!_elm_widget_is(obj))
1359 if (dir == ELM_FOCUS_PREVIOUS)
1361 items = eina_list_last(items);
1362 list_next = eina_list_prev;
1364 else if (dir == ELM_FOCUS_NEXT)
1365 list_next = eina_list_next;
1369 const Eina_List *l = items;
1371 /* Recovery last focused sub item */
1372 if (elm_widget_focus_get(obj))
1373 for (; l; l = list_next(l))
1375 Evas_Object *cur = list_data_get(l);
1376 if (elm_widget_focus_get(cur)) break;
1379 const Eina_List *start = l;
1380 Evas_Object *to_focus = NULL;
1382 /* Interate sub items */
1383 /* Go to end of list */
1384 for (; l; l = list_next(l))
1386 Evas_Object *tmp = NULL;
1387 Evas_Object *cur = list_data_get(l);
1389 if (elm_widget_parent_get(cur) != obj)
1392 /* Try Focus cycle in subitem */
1393 if (elm_widget_focus_next_get(cur, dir, &tmp))
1398 else if ((tmp) && (!to_focus))
1404 /* Get First possible */
1405 for (;l != start; l = list_next(l))
1407 Evas_Object *tmp = NULL;
1408 Evas_Object *cur = list_data_get(l);
1410 if (elm_widget_parent_get(cur) != obj)
1413 /* Try Focus cycle in subitem */
1414 elm_widget_focus_next_get(cur, dir, &tmp);
1427 elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
1430 if (!sd->signal_func) return;
1431 sd->signal_func(obj, emission, source);
1435 _edje_signal_callback(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
1437 Edje_Signal_Data *esd = data;
1438 esd->func(esd->data, esd->obj, emission, source);
1442 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)
1444 Edje_Signal_Data *esd;
1446 if (!sd->callback_add_func) return;
1447 EINA_SAFETY_ON_NULL_RETURN(func);
1449 esd = ELM_NEW(Edje_Signal_Data);
1454 esd->emission = eina_stringshare_add(emission);
1455 esd->source = eina_stringshare_add(source);
1457 sd->edje_signals = eina_list_append(sd->edje_signals, esd);
1458 sd->callback_add_func(obj, emission, source, _edje_signal_callback, esd);
1462 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))
1464 Edje_Signal_Data *esd;
1467 API_ENTRY return NULL;
1468 if (!sd->callback_del_func) return NULL;
1470 EINA_LIST_FOREACH(sd->edje_signals, l, esd)
1472 if ((esd->func == func) && (!strcmp(esd->emission, emission)) &&
1473 (!strcmp(esd->source, source)))
1475 sd->edje_signals = eina_list_remove_list(sd->edje_signals, l);
1476 eina_stringshare_del(esd->emission);
1477 eina_stringshare_del(esd->source);
1483 sd->callback_del_func(obj, emission, source, _edje_signal_callback, esd);
1488 elm_widget_focus_set(Evas_Object *obj, int first)
1494 sd->focus_order = focus_order;
1495 sd->focused = EINA_TRUE;
1496 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1500 sd->focus_func(obj);
1507 if ((_is_focusable(sd->resize_obj)) &&
1508 (!elm_widget_disabled_get(sd->resize_obj)))
1510 elm_widget_focus_set(sd->resize_obj, first);
1516 EINA_LIST_FOREACH(sd->subobjs, l, child)
1518 if ((_is_focusable(child)) &&
1519 (!elm_widget_disabled_get(child)))
1521 elm_widget_focus_set(child, first);
1531 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, child)
1533 if ((_is_focusable(child)) &&
1534 (!elm_widget_disabled_get(child)))
1536 elm_widget_focus_set(child, first);
1542 if ((_is_focusable(sd->resize_obj)) &&
1543 (!elm_widget_disabled_get(sd->resize_obj)))
1545 elm_widget_focus_set(sd->resize_obj, first);
1553 elm_widget_parent_get(const Evas_Object *obj)
1555 API_ENTRY return NULL;
1556 return sd->parent_obj;
1560 elm_widget_focused_object_clear(Evas_Object *obj)
1563 if (!sd->focused) return;
1564 if (elm_widget_focus_get(sd->resize_obj))
1565 elm_widget_focused_object_clear(sd->resize_obj);
1570 EINA_LIST_FOREACH(sd->subobjs, l, child)
1572 if (elm_widget_focus_get(child))
1574 elm_widget_focused_object_clear(child);
1579 sd->focused = EINA_FALSE;
1580 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
1581 if (sd->focus_func) sd->focus_func(obj);
1585 elm_widget_focus_steal(Evas_Object *obj)
1587 Evas_Object *parent, *o;
1590 if (sd->focused) return;
1591 if (sd->disabled) return;
1595 o = elm_widget_parent_get(parent);
1597 sd = evas_object_smart_data_get(o);
1598 if (sd->focused) break;
1601 if (!elm_widget_parent_get(parent))
1602 elm_widget_focused_object_clear(parent);
1605 parent = elm_widget_parent_get(parent);
1606 sd = evas_object_smart_data_get(parent);
1607 if ((sd->resize_obj) && (elm_widget_focus_get(sd->resize_obj)))
1608 elm_widget_focused_object_clear(sd->resize_obj);
1613 EINA_LIST_FOREACH(sd->subobjs, l, child)
1615 if (elm_widget_focus_get(child))
1617 elm_widget_focused_object_clear(child);
1628 elm_widget_activate(Evas_Object *obj)
1631 elm_widget_change(obj);
1632 if (sd->activate_func) sd->activate_func(obj);
1636 elm_widget_change(Evas_Object *obj)
1639 elm_widget_change(elm_widget_parent_get(obj));
1640 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
1644 elm_widget_disabled_set(Evas_Object *obj, int disabled)
1648 if (sd->disabled == disabled) return;
1649 sd->disabled = disabled;
1652 Evas_Object *o, *parent;
1657 o = elm_widget_parent_get(parent);
1661 if (elm_widget_focus_get(obj))
1662 elm_widget_focus_cycle(parent, ELM_FOCUS_NEXT);
1664 if (sd->disable_func) sd->disable_func(obj);
1668 elm_widget_disabled_get(const Evas_Object *obj)
1671 return sd->disabled;
1675 elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1677 Evas_Object *parent_obj, *child_obj;
1678 Evas_Coord px, py, cx, cy;
1681 if ((x == sd->rx) && (y == sd->ry) && (w == sd->rw) && (h == sd->rh)) return;
1686 if (sd->on_show_region_func)
1687 sd->on_show_region_func(sd->on_show_region_data, obj);
1691 parent_obj = sd->parent_obj;
1692 child_obj = sd->obj;
1693 if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
1694 sd = evas_object_smart_data_get(parent_obj);
1697 evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
1698 evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
1707 if (sd->on_show_region_func)
1709 sd->on_show_region_func(sd->on_show_region_data, parent_obj);
1716 elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1728 * Get the focus region of the given widget.
1730 * The focus region is the area of a widget that should brought into the
1731 * visible area when the widget is focused. Mostly used to show the part of
1732 * an entry where the cursor is, for example. The area returned is relative
1733 * to the object @p obj.
1734 * If the @p obj doesn't have the proper on_focus_region_hook set, this
1735 * function will return the full size of the object.
1737 * @param obj The widget object
1738 * @param x Where to store the x coordinate of the area
1739 * @param y Where to store the y coordinate of the area
1740 * @param w Where to store the width of the area
1741 * @param h Where to store the height of the area
1746 elm_widget_focus_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1752 sd = evas_object_smart_data_get(obj);
1753 if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region_func)
1755 evas_object_geometry_get(obj, NULL, NULL, w, h);
1760 sd->on_focus_region_func(obj, x, y, w, h);
1764 elm_widget_scroll_hold_push(Evas_Object *obj)
1768 if (sd->scroll_hold == 1)
1769 evas_object_smart_callback_call(obj, "scroll-hold-on", obj);
1770 if (sd->parent_obj) elm_widget_scroll_hold_push(sd->parent_obj);
1771 // FIXME: on delete/reparent hold pop
1775 elm_widget_scroll_hold_pop(Evas_Object *obj)
1779 if (sd->scroll_hold < 0) sd->scroll_hold = 0;
1780 if (!sd->scroll_hold)
1781 evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
1782 if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
1786 elm_widget_scroll_hold_get(const Evas_Object *obj)
1789 return sd->scroll_hold;
1793 elm_widget_scroll_freeze_push(Evas_Object *obj)
1796 sd->scroll_freeze++;
1797 if (sd->scroll_freeze == 1)
1798 evas_object_smart_callback_call(obj, "scroll-freeze-on", obj);
1799 if (sd->parent_obj) elm_widget_scroll_freeze_push(sd->parent_obj);
1800 // FIXME: on delete/reparent freeze pop
1804 elm_widget_scroll_freeze_pop(Evas_Object *obj)
1807 sd->scroll_freeze--;
1808 if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
1809 if (!sd->scroll_freeze)
1810 evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
1811 if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
1815 elm_widget_scroll_freeze_get(const Evas_Object *obj)
1818 return sd->scroll_freeze;
1822 elm_widget_scale_set(Evas_Object *obj, double scale)
1825 if (scale <= 0.0) scale = 0.0;
1826 if (sd->scale != scale)
1829 elm_widget_theme(obj);
1834 elm_widget_scale_get(const Evas_Object *obj)
1836 API_ENTRY return 1.0;
1837 // FIXME: save walking up the tree by storing/caching parent scale
1838 if (sd->scale == 0.0)
1841 return elm_widget_scale_get(sd->parent_obj);
1849 elm_widget_theme_set(Evas_Object *obj, Elm_Theme *th)
1852 if (sd->theme != th)
1854 if (sd->theme) elm_theme_free(sd->theme);
1857 elm_widget_theme(obj);
1862 elm_widget_theme_get(const Evas_Object *obj)
1864 API_ENTRY return NULL;
1868 return elm_widget_theme_get(sd->parent_obj);
1876 elm_widget_style_set(Evas_Object *obj, const char *style)
1880 if (eina_stringshare_replace(&sd->style, style))
1881 elm_widget_theme(obj);
1885 elm_widget_style_get(const Evas_Object *obj)
1887 API_ENTRY return NULL;
1888 if (sd->style) return sd->style;
1893 elm_widget_type_set(Evas_Object *obj, const char *type)
1896 eina_stringshare_replace(&sd->type, type);
1900 elm_widget_type_get(const Evas_Object *obj)
1902 API_ENTRY return NULL;
1903 if (sd->type) return sd->type;
1908 elm_widget_tooltip_add(Evas_Object *obj, Elm_Tooltip *tt)
1911 sd->tooltips = eina_list_append(sd->tooltips, tt);
1915 elm_widget_tooltip_del(Evas_Object *obj, Elm_Tooltip *tt)
1918 sd->tooltips = eina_list_remove(sd->tooltips, tt);
1922 elm_widget_cursor_add(Evas_Object *obj, Elm_Cursor *cur)
1925 sd->cursors = eina_list_append(sd->cursors, cur);
1929 elm_widget_cursor_del(Evas_Object *obj, Elm_Cursor *cur)
1932 sd->cursors = eina_list_remove(sd->cursors, cur);
1936 elm_widget_drag_lock_x_set(Evas_Object *obj, Eina_Bool lock)
1939 if (sd->drag_x_locked == lock) return;
1940 sd->drag_x_locked = lock;
1941 if (sd->drag_x_locked) _propagate_x_drag_lock(obj, 1);
1942 else _propagate_x_drag_lock(obj, -1);
1946 elm_widget_drag_lock_y_set(Evas_Object *obj, Eina_Bool lock)
1949 if (sd->drag_y_locked == lock) return;
1950 sd->drag_y_locked = lock;
1951 if (sd->drag_y_locked) _propagate_y_drag_lock(obj, 1);
1952 else _propagate_y_drag_lock(obj, -1);
1956 elm_widget_drag_lock_x_get(const Evas_Object *obj)
1958 API_ENTRY return EINA_FALSE;
1959 return sd->drag_x_locked;
1963 elm_widget_drag_lock_y_get(const Evas_Object *obj)
1965 API_ENTRY return EINA_FALSE;
1966 return sd->drag_y_locked;
1970 elm_widget_drag_child_locked_x_get(const Evas_Object *obj)
1973 return sd->child_drag_x_locked;
1977 elm_widget_drag_child_locked_y_get(const Evas_Object *obj)
1980 return sd->child_drag_y_locked;
1984 elm_widget_theme_object_set(Evas_Object *obj, Evas_Object *edj, const char *wname, const char *welement, const char *wstyle)
1986 API_ENTRY return EINA_FALSE;
1987 return _elm_theme_object_set(obj, edj, wname, welement, wstyle);
1991 elm_widget_type_check(const Evas_Object *obj, const char *type)
1993 const char *provided, *expected = "(unknown)";
1994 static int abort_on_warn = -1;
1995 provided = elm_widget_type_get(obj);
1996 if (EINA_LIKELY(provided == type)) return EINA_TRUE;
1997 if (type) expected = type;
1998 if ((!provided) || (!provided[0]))
2000 provided = evas_object_type_get(obj);
2001 if ((!provided) || (!provided[0]))
2002 provided = "(unknown)";
2004 ERR("Passing Object: %p, of type: '%s' when expecting type: '%s'", obj, provided, expected);
2005 if (abort_on_warn == -1)
2007 if (getenv("ELM_ERROR_ABORT")) abort_on_warn = 1;
2008 else abort_on_warn = 0;
2010 if (abort_on_warn == 1) abort();
2017 * Split string in words
2019 * @param str Source string
2020 * @return List of const words
2022 * @see elm_widget_stringlist_free()
2026 elm_widget_stringlist_get(const char *str)
2028 Eina_List *list = NULL;
2030 if (!str) return NULL;
2031 for (b = s = str; 1; s++)
2033 if ((*s == ' ') || (!*s))
2035 char *t = malloc(s - b + 1);
2038 strncpy(t, b, s - b);
2040 list = eina_list_append(list, eina_stringshare_add(t));
2051 elm_widget_stringlist_free(Eina_List *list)
2054 EINA_LIST_FREE(list, s) eina_stringshare_del(s);
2060 * Allocate a new Elm_Widget_Item-derived structure.
2062 * The goal of this structure is to provide common ground for actions
2063 * that a widget item have, such as the owner widget, callback to
2064 * notify deletion, data pointer and maybe more.
2066 * @param widget the owner widget that holds this item, must be an elm_widget!
2067 * @param alloc_size any number greater than sizeof(Elm_Widget_Item) that will
2068 * be used to allocate memory.
2070 * @return allocated memory that is already zeroed out, or NULL on errors.
2072 * @see elm_widget_item_new() convenience macro.
2073 * @see elm_widget_item_del() to release memory.
2076 EAPI Elm_Widget_Item *
2077 _elm_widget_item_new(Evas_Object *widget, size_t alloc_size)
2079 if (!_elm_widget_is(widget))
2082 Elm_Widget_Item *item;
2084 EINA_SAFETY_ON_TRUE_RETURN_VAL(alloc_size < sizeof(Elm_Widget_Item), NULL);
2085 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_elm_widget_is(widget), NULL);
2087 item = calloc(1, alloc_size);
2088 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
2090 EINA_MAGIC_SET(item, ELM_WIDGET_ITEM_MAGIC);
2091 item->widget = widget;
2098 * Releases widget item memory, calling back del_cb() if it exists.
2100 * If there is a Elm_Widget_Item::del_cb, then it will be called prior
2101 * to memory release. Note that elm_widget_item_pre_notify_del() calls
2102 * this function and then unset it, thus being useful for 2 step
2103 * cleanup whenever the del_cb may use any of the data that must be
2104 * deleted from item.
2106 * The Elm_Widget_Item::view will be deleted (evas_object_del()) if it
2109 * @param item a valid #Elm_Widget_Item to be deleted.
2110 * @see elm_widget_item_del() convenience macro.
2114 _elm_widget_item_del(Elm_Widget_Item *item)
2116 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2119 item->del_cb((void *)item->data, item->widget, item);
2122 evas_object_del(item->view);
2124 EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
2131 * Notify object will be deleted without actually deleting it.
2133 * This function will callback Elm_Widget_Item::del_cb if it is set
2134 * and then unset it so it is not called twice (ie: from
2135 * elm_widget_item_del()).
2137 * @param item a valid #Elm_Widget_Item to be notified
2138 * @see elm_widget_item_pre_notify_del() convenience macro.
2142 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
2144 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2145 if (!item->del_cb) return;
2146 item->del_cb((void *)item->data, item->widget, item);
2147 item->del_cb = NULL;
2153 * Set the function to notify when item is being deleted.
2155 * This function will complain if there was a callback set already,
2156 * however it will set the new one.
2158 * The callback will be called from elm_widget_item_pre_notify_del()
2159 * or elm_widget_item_del() will be called with:
2160 * - data: the Elm_Widget_Item::data value.
2161 * - obj: the Elm_Widget_Item::widget evas object.
2162 * - event_info: the item being deleted.
2164 * @param item a valid #Elm_Widget_Item to be notified
2165 * @see elm_widget_item_del_cb_set() convenience macro.
2169 _elm_widget_item_del_cb_set(Elm_Widget_Item *item, Evas_Smart_Cb del_cb)
2171 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2173 if ((item->del_cb) && (item->del_cb != del_cb))
2174 WRN("You're replacing a previously set del_cb %p of item %p with %p",
2175 item->del_cb, item, del_cb);
2177 item->del_cb = del_cb;
2183 * Set user-data in this item.
2185 * User data may be used to identify this item or just store any
2186 * application data. It is automatically given as the first parameter
2187 * of the deletion notify callback.
2189 * @param item a valid #Elm_Widget_Item to store data in.
2190 * @param data user data to store.
2191 * @see elm_widget_item_del_cb_set() convenience macro.
2195 _elm_widget_item_data_set(Elm_Widget_Item *item, const void *data)
2197 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2198 if ((item->data) && (item->data != data))
2199 DBG("Replacing item %p data %p with %p", item, item->data, data);
2206 * Retrieves user-data of this item.
2208 * @param item a valid #Elm_Widget_Item to get data from.
2209 * @see elm_widget_item_data_set()
2213 _elm_widget_item_data_get(const Elm_Widget_Item *item)
2215 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2216 return (void *)item->data;
2219 typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip;
2221 struct _Elm_Widget_Item_Tooltip
2223 Elm_Widget_Item *item;
2224 Elm_Tooltip_Item_Content_Cb func;
2225 Evas_Smart_Cb del_cb;
2229 static Evas_Object *
2230 _elm_widget_item_tooltip_label_create(void *data, Evas_Object *obj, void *item __UNUSED__)
2232 Evas_Object *label = elm_label_add(obj);
2235 elm_object_style_set(label, "tooltip");
2236 elm_label_label_set(label, data);
2241 _elm_widget_item_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2243 eina_stringshare_del(data);
2249 * Set the text to be shown in the widget item.
2251 * @param item Target item
2252 * @param text The text to set in the content
2254 * Setup the text as tooltip to object. The item can have only one tooltip,
2255 * so any previous tooltip data is removed.
2260 _elm_widget_item_tooltip_text_set(Elm_Widget_Item *item, const char *text)
2262 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2263 EINA_SAFETY_ON_NULL_RETURN(text);
2265 text = eina_stringshare_add(text);
2266 _elm_widget_item_tooltip_content_cb_set
2267 (item, _elm_widget_item_tooltip_label_create, text,
2268 _elm_widget_item_tooltip_label_del_cb);
2271 static Evas_Object *
2272 _elm_widget_item_tooltip_create(void *data, Evas_Object *obj)
2274 Elm_Widget_Item_Tooltip *wit = data;
2275 return wit->func((void *)wit->data, obj, wit->item);
2279 _elm_widget_item_tooltip_del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
2281 Elm_Widget_Item_Tooltip *wit = data;
2282 if (wit->del_cb) wit->del_cb((void *)wit->data, obj, wit->item);
2289 * Set the content to be shown in the tooltip item
2291 * Setup the tooltip to item. The item can have only one tooltip,
2292 * so any previous tooltip data is removed. @p func(with @p data) will
2293 * be called every time that need show the tooltip and it should
2294 * return a valid Evas_Object. This object is then managed fully by
2295 * tooltip system and is deleted when the tooltip is gone.
2297 * @param item the widget item being attached a tooltip.
2298 * @param func the function used to create the tooltip contents.
2299 * @param data what to provide to @a func as callback data/context.
2300 * @param del_cb called when data is not needed anymore, either when
2301 * another callback replaces @func, the tooltip is unset with
2302 * elm_widget_item_tooltip_unset() or the owner @a item
2303 * dies. This callback receives as the first parameter the
2304 * given @a data, and @c event_info is the item.
2309 _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)
2311 Elm_Widget_Item_Tooltip *wit;
2313 ELM_WIDGET_ITEM_CHECK_OR_GOTO(item, error_noitem);
2317 _elm_widget_item_tooltip_unset(item);
2321 wit = ELM_NEW(Elm_Widget_Item_Tooltip);
2322 if (!wit) goto error;
2326 wit->del_cb = del_cb;
2328 elm_object_sub_tooltip_content_cb_set
2329 (item->view, item->widget, _elm_widget_item_tooltip_create, wit,
2330 _elm_widget_item_tooltip_del_cb);
2335 if (del_cb) del_cb((void *)data, NULL, item);
2338 if (del_cb) del_cb((void *)data, item->widget, item);
2344 * Unset tooltip from item
2346 * @param item widget item to remove previously set tooltip.
2348 * Remove tooltip from item. The callback provided as del_cb to
2349 * elm_widget_item_tooltip_content_cb_set() will be called to notify
2350 * it is not used anymore.
2352 * @see elm_widget_item_tooltip_content_cb_set()
2357 _elm_widget_item_tooltip_unset(Elm_Widget_Item *item)
2359 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2360 elm_object_tooltip_unset(item->view);
2366 * Sets a different style for this item tooltip.
2368 * @note before you set a style you should define a tooltip with
2369 * elm_widget_item_tooltip_content_cb_set() or
2370 * elm_widget_item_tooltip_text_set()
2372 * @param item widget item with tooltip already set.
2373 * @param style the theme style to use (default, transparent, ...)
2378 _elm_widget_item_tooltip_style_set(Elm_Widget_Item *item, const char *style)
2380 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2381 elm_object_tooltip_style_set(item->view, style);
2387 * Get the style for this item tooltip.
2389 * @param item widget item with tooltip already set.
2390 * @return style the theme style in use, defaults to "default". If the
2391 * object does not have a tooltip set, then NULL is returned.
2396 _elm_widget_item_tooltip_style_get(const Elm_Widget_Item *item)
2398 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2399 return elm_object_tooltip_style_get(item->view);
2403 _elm_widget_item_cursor_set(Elm_Widget_Item *item, const char *cursor)
2405 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2406 elm_object_sub_cursor_set(item->view, item->widget, cursor);
2410 _elm_widget_item_cursor_get(const Elm_Widget_Item *item)
2412 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2413 return elm_object_cursor_get(item->view);
2417 _elm_widget_item_cursor_unset(Elm_Widget_Item *item)
2419 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2420 elm_object_cursor_unset(item->view);
2426 * Sets a different style for this item cursor.
2428 * @note before you set a style you should define a cursor with
2429 * elm_widget_item_cursor_set()
2431 * @param item widget item with cursor already set.
2432 * @param style the theme style to use (default, transparent, ...)
2437 _elm_widget_item_cursor_style_set(Elm_Widget_Item *item, const char *style)
2439 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2440 elm_object_cursor_style_set(item->view, style);
2446 * Get the style for this item cursor.
2448 * @param item widget item with cursor already set.
2449 * @return style the theme style in use, defaults to "default". If the
2450 * object does not have a cursor set, then NULL is returned.
2455 _elm_widget_item_cursor_style_get(const Elm_Widget_Item *item)
2457 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
2458 return elm_object_cursor_style_get(item->view);
2464 * Set if the cursor set should be searched on the theme or should use
2465 * the provided by the engine, only.
2467 * @note before you set if should look on theme you should define a cursor
2468 * with elm_object_cursor_set(). By default it will only look for cursors
2469 * provided by the engine.
2471 * @param item widget item with cursor already set.
2472 * @param engine_only boolean to define it cursors should be looked only
2473 * between the provided by the engine or searched on widget's theme as well.
2478 _elm_widget_item_cursor_engine_only_set(Elm_Widget_Item *item, Eina_Bool engine_only)
2480 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
2481 elm_object_cursor_engine_only_set(item->view, engine_only);
2487 * Get the cursor engine only usage for this item cursor.
2489 * @param item widget item with cursor already set.
2490 * @return engine_only boolean to define it cursors should be looked only
2491 * between the provided by the engine or searched on widget's theme as well. If
2492 * the object does not have a cursor set, then EINA_FALSE is returned.
2497 _elm_widget_item_cursor_engine_only_get(const Elm_Widget_Item *item)
2499 ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
2500 return elm_object_cursor_engine_only_get(item->view);
2503 // smart object funcs
2505 _smart_reconfigure(Smart_Data *sd)
2509 evas_object_move(sd->resize_obj, sd->x, sd->y);
2510 evas_object_resize(sd->resize_obj, sd->w, sd->h);
2514 evas_object_move(sd->hover_obj, sd->x, sd->y);
2515 evas_object_resize(sd->hover_obj, sd->w, sd->h);
2520 _smart_add(Evas_Object *obj)
2524 sd = calloc(1, sizeof(Smart_Data));
2527 sd->x = sd->y = sd->w = sd->h = 0;
2529 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale settings */
2530 evas_object_smart_data_set(obj, sd);
2533 static Evas_Object *
2534 _newest_focus_order_get(Evas_Object *obj, unsigned int *newest_focus_order, Eina_Bool can_focus_only)
2537 Evas_Object *child, *ret, *best;
2539 API_ENTRY return NULL;
2540 if (!evas_object_visible_get(obj)) return NULL;
2542 if (*newest_focus_order < sd->focus_order)
2544 *newest_focus_order = sd->focus_order;
2547 EINA_LIST_FOREACH(sd->subobjs, l, child)
2549 ret = _newest_focus_order_get(child, newest_focus_order, can_focus_only);
2555 if ((!best) || (!elm_widget_can_focus_get(best)))
2562 _if_focused_revert(Evas_Object *obj, Eina_Bool can_focus_only)
2565 Evas_Object *newest = NULL;
2566 unsigned int newest_focus_order = 0;
2570 if (!sd->focused) return;
2571 if (!sd->parent_obj) return;
2573 top = elm_widget_top_get(sd->parent_obj);
2576 newest = _newest_focus_order_get(top, &newest_focus_order, can_focus_only);
2579 elm_object_unfocus(newest);
2580 elm_object_focus(newest);
2586 _smart_del(Evas_Object *obj)
2589 Edje_Signal_Data *esd;
2593 if (sd->del_pre_func) sd->del_pre_func(obj);
2596 sobj = sd->resize_obj;
2597 sd->resize_obj = NULL;
2598 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2599 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2600 evas_object_del(sobj);
2604 sobj = sd->hover_obj;
2605 sd->hover_obj = NULL;
2606 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2607 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2608 evas_object_del(sobj);
2610 EINA_LIST_FREE(sd->subobjs, sobj)
2612 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
2613 evas_object_smart_callback_call(sd->obj, "sub-object-del", sobj);
2614 evas_object_del(sobj);
2616 eina_list_free(sd->tooltips); /* should be empty anyway */
2617 eina_list_free(sd->cursors); /* should be empty anyway */
2618 EINA_LIST_FREE(sd->edje_signals, esd)
2620 eina_stringshare_del(esd->emission);
2621 eina_stringshare_del(esd->source);
2624 eina_list_free(sd->event_cb); /* should be empty anyway */
2625 if (sd->del_func) sd->del_func(obj);
2626 if (sd->style) eina_stringshare_del(sd->style);
2627 if (sd->type) eina_stringshare_del(sd->type);
2628 if (sd->theme) elm_theme_free(sd->theme);
2629 _if_focused_revert(obj, EINA_TRUE);
2634 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2639 _smart_reconfigure(sd);
2643 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2648 _smart_reconfigure(sd);
2652 _smart_show(Evas_Object *obj)
2657 if ((list = evas_object_smart_members_get(obj)))
2659 EINA_LIST_FREE(list, o)
2661 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2662 evas_object_show(o);
2668 _smart_hide(Evas_Object *obj)
2673 list = evas_object_smart_members_get(obj);
2674 EINA_LIST_FREE(list, o)
2676 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2677 evas_object_hide(o);
2682 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
2687 if ((list = evas_object_smart_members_get(obj)))
2689 EINA_LIST_FREE(list, o)
2691 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2692 evas_object_color_set(o, r, g, b, a);
2698 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
2703 if ((list = evas_object_smart_members_get(obj)))
2705 EINA_LIST_FREE(list, o)
2707 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2708 evas_object_clip_set(o, clip);
2714 _smart_clip_unset(Evas_Object *obj)
2719 if ((list = evas_object_smart_members_get(obj)))
2721 EINA_LIST_FREE(list, o)
2723 if (evas_object_data_get(o, "_elm_leaveme")) continue;
2724 evas_object_clip_unset(o);
2730 _smart_calculate(Evas_Object *obj)
2733 if (sd->changed_func) sd->changed_func(obj);
2736 /* never need to touch this */
2740 if (_e_smart) return;
2742 static const Evas_Smart_Class sc =
2745 EVAS_SMART_CLASS_VERSION,
2763 _e_smart = evas_smart_class_new(&sc);
2767 /* happy debug functions */
2770 _sub_obj_tree_dump(const Evas_Object *obj, int lvl)
2774 for (i = 0; i < lvl*3; i++)
2777 if (_elm_widget_is(obj))
2781 printf("+ %s(%p)\n", sd->type, obj);
2783 _sub_obj_tree_dump(sd->resize_obj, lvl + 1);
2784 EINA_LIST_FOREACH(sd->subobjs, l, obj)
2786 if (obj != sd->resize_obj)
2787 _sub_obj_tree_dump(obj, lvl + 1);
2791 printf("+ %s(%p)\n", evas_object_type_get(obj), obj);
2795 _sub_obj_tree_dot_dump(const Evas_Object *obj, FILE *output)
2797 if (!_elm_widget_is(obj))
2801 Eina_Bool visible = evas_object_visible_get(obj);
2802 Eina_Bool disabled = elm_widget_disabled_get(obj);
2803 Eina_Bool focused = elm_widget_focus_get(obj);
2804 Eina_Bool can_focus = elm_widget_can_focus_get(obj);
2808 fprintf(output, "\"%p\" -- \"%p\" [ color=black", sd->parent_obj, obj);
2811 fprintf(output, ", style=bold");
2814 fprintf(output, ", color=gray28");
2816 fprintf(output, " ];\n");
2819 fprintf(output, "\"%p\" [ label = \"{%p|%s|%s|visible: %d|"
2820 "disabled: %d|focused: %d/%d|focus order:%d}\"", obj, obj, sd->type,
2821 evas_object_name_get(obj), visible, disabled, focused, can_focus,
2825 fprintf(output, ", style=bold");
2828 fprintf(output, ", fontcolor=gray28");
2830 if ((disabled) || (!visible))
2831 fprintf(output, ", color=gray");
2834 fprintf(output, " ];\n");
2838 EINA_LIST_FOREACH(sd->subobjs, l, o)
2839 _sub_obj_tree_dot_dump(o, output);
2844 elm_widget_tree_dump(const Evas_Object *top)
2847 _sub_obj_tree_dump(top, 0);
2855 elm_widget_tree_dot_dump(const Evas_Object *top, FILE *output)
2858 if (!_elm_widget_is(top))
2860 fprintf(output, "graph "" { node [shape=record];\n");
2861 _sub_obj_tree_dot_dump(top, output);
2862 fprintf(output, "}\n");