X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Felm_hover.c;h=ec92a9c4c878c731629b38f0f18c56225599e31a;hb=8d5275d5db79b4bd83ab88e3d48feec63ddbd5bc;hp=9e0d43c2a5c5809c9b02abf5a8d8c94a8fe481e2;hpb=d8bc35a117109ba043f9f899467d1d36a303b2eb;p=framework%2Fuifw%2Felementary.git diff --git a/src/lib/elm_hover.c b/src/lib/elm_hover.c index 9e0d43c..ec92a9c 100644 --- a/src/lib/elm_hover.c +++ b/src/lib/elm_hover.c @@ -1,36 +1,57 @@ #include #include "elm_priv.h" -/** - * @defgroup Hover Hover - * - * A Hover object will over over the @p Parent object at the @p Target - * location. Anything in the background will be given a darker coloring - * to indicate that the hover object is on top. - * - * NOTE: The hover object will take up the entire space of @p Target object. - */ - typedef struct _Widget_Data Widget_Data; -typedef struct _Subinfo Subinfo; +typedef struct _Content_Info Content_Info; + +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#define ELM_HOVER_PARTS_FOREACH unsigned int i = 0; \ + for (i = 0; i < sizeof(wd->subs) / sizeof(wd->subs[0]); i++) + +static const char *_directions[] = { + "left", + "top-left", + "top", + "top-right", + "right", + "bottom-right", + "bottom", + "bottom-left", + "middle" +}; + +#define _HOV_LEFT (_directions[0]) +#define _HOV_TOP_LEFT (_directions[1]) +#define _HOV_TOP (_directions[2]) +#define _HOV_TOP_RIGHT (_directions[2]) +#define _HOV_RIGHT (_directions[4]) +#define _HOV_BOTTOM_RIGHT (_directions[5]) +#define _HOV_BOTTOM (_directions[6]) +#define _HOV_BOTTOM_LEFT (_directions[7]) +#define _HOV_MIDDLE (_directions[8]) + +struct _Content_Info +{ + const char *swallow; + Evas_Object *obj; +}; struct _Widget_Data { Evas_Object *hov, *cov; Evas_Object *offset, *size; Evas_Object *parent, *target; - Eina_List *subs; -}; - -struct _Subinfo -{ - const char *swallow; - Evas_Object *obj; + Evas_Object *smt_sub; + Content_Info subs[sizeof(_directions)/sizeof(_directions[0])]; }; static const char *widtype = NULL; static void _del_pre_hook(Evas_Object *obj); static void _del_hook(Evas_Object *obj); +static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl); static void _theme_hook(Evas_Object *obj); static void _sizing_eval(Evas_Object *obj); static void _reval_content(Evas_Object *obj); @@ -40,35 +61,69 @@ static void _hov_move(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _hov_resize(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _hov_show(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _hov_hide(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _on_focus_hook(void *data, Evas_Object *obj); +static void _elm_hover_sub_obj_placement_eval_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _elm_hover_sub_obj_placement_eval(Evas_Object *obj); +static void _content_set_hook(Evas_Object *obj, const char *swallow, Evas_Object *content); +static Evas_Object * _content_get_hook(const Evas_Object *obj, const char *swallow); +static Evas_Object * _content_unset_hook(Evas_Object *obj, const char *swallow); + +static const char SIG_CLICKED[] = "clicked"; +static const char SIG_SMART_LOCATION_CHANGED[] = "smart,changed"; +static const Evas_Smart_Cb_Description _signals[] = { + {SIG_CLICKED, ""}, + {SIG_SMART_LOCATION_CHANGED, ""}, + {NULL, NULL} +}; static void _del_pre_hook(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - Subinfo *si; - if (!wd) return; + if (!wd) + return; + if (evas_object_visible_get(obj)) - evas_object_smart_callback_call(obj, "clicked", NULL); + evas_object_smart_callback_call(obj, SIG_CLICKED, NULL); elm_hover_target_set(obj, NULL); elm_hover_parent_set(obj, NULL); evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_MOVE, _hov_move, obj); evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_RESIZE, _hov_resize, obj); evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_SHOW, _hov_show, obj); evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_HIDE, _hov_hide, obj); +} - EINA_LIST_FREE(wd->subs, si) +static void +_del_hook(Evas_Object *obj) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + free(wd); +} + +static void +_on_focus_hook(void *data __UNUSED__, Evas_Object *obj) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + if (elm_widget_focus_get(obj)) + { + edje_object_signal_emit(wd->cov, "elm,action,focus", "elm"); + evas_object_focus_set(wd->cov, EINA_TRUE); + } + else { - eina_stringshare_del(si->swallow); - free(si); + edje_object_signal_emit(wd->cov, "elm,action,unfocus", "elm"); + evas_object_focus_set(wd->cov, EINA_FALSE); } } static void -_del_hook(Evas_Object *obj) +_mirrored_set(Evas_Object *obj, Eina_Bool rtl) { Widget_Data *wd = elm_widget_data_get(obj); if (!wd) return; - free(wd); + edje_object_mirrored_set(wd->cov, rtl); } static void @@ -76,27 +131,98 @@ _theme_hook(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); if (!wd) return; - // FIXME: hover contents doesnt seem to propagate resizes properly + _elm_widget_mirrored_reload(obj); + _mirrored_set(obj, elm_widget_mirrored_get(obj)); + // FIXME: hover contents doesn't seem to propagate resizes properly _elm_theme_object_set(obj, wd->cov, "hover", "base", elm_widget_style_get(obj)); edje_object_scale_set(wd->cov, elm_widget_scale_get(obj) * _elm_config->scale); - _reval_content(obj); + + if (wd->smt_sub) + _elm_hover_sub_obj_placement_eval(obj); + else + _reval_content(obj); _sizing_eval(obj); if (evas_object_visible_get(wd->cov)) _hov_show_do(obj); } +static void +_signal_emit_hook(Evas_Object *obj, const char *emission, const char *source) +{ + Widget_Data *wd; + + wd = elm_widget_data_get(obj); + if (!wd) + return; + + edje_object_signal_emit(wd->cov, emission, source); +} + +static void +_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data) +{ + Widget_Data *wd; + + wd = elm_widget_data_get(obj); + if (!wd) + return; + + edje_object_signal_callback_add(wd->hov, emission, source, func_cb, data); +} + +static void +_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data) +{ + Widget_Data *wd; + + wd = elm_widget_data_get(obj); + + edje_object_signal_callback_del_full(wd->hov, emission, source, func_cb, + data); +} + +static void +_elm_hover_left_space_calc(Widget_Data *wd, Evas_Coord *spc_l, Evas_Coord *spc_t, Evas_Coord *spc_r, Evas_Coord *spc_b) +{ + Evas_Coord x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0; + + if (wd->parent) + evas_object_geometry_get(wd->parent, &x, &y, &w, &h); + if (wd->target) + evas_object_geometry_get(wd->target, &x2, &y2, &w2, &h2); + + *spc_l = x2 - x; + *spc_r = (x + w) - (x2 + w2); + if (*spc_l < 0) + *spc_l = 0; + if (*spc_r < 0) + *spc_r = 0; + + *spc_t = y2 - y; + *spc_b = (y + h) - (y2 + h2); + if (*spc_t < 0) + *spc_t = 0; + if (*spc_b < 0) + *spc_b = 0; +} static void _sizing_eval(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - Evas_Coord x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0; + Evas_Coord ofs_x, x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0; if (!wd) return; if (wd->parent) evas_object_geometry_get(wd->parent, &x, &y, &w, &h); if (wd->hov) evas_object_geometry_get(wd->hov, &x2, &y2, &w2, &h2); + + if (elm_widget_mirrored_get(obj)) + ofs_x = w - (x2 - x) - w2; + else + ofs_x = x2 - x; + evas_object_move(wd->cov, x, y); evas_object_resize(wd->cov, w, h); - evas_object_size_hint_min_set(wd->offset, x2 - x, y2 - y); + evas_object_size_hint_min_set(wd->offset, ofs_x, y2 - y); evas_object_size_hint_min_set(wd->size, w2, h2); edje_object_part_swallow(wd->cov, "elm.swallow.offset", wd->offset); edje_object_part_swallow(wd->cov, "elm.swallow.size", wd->size); @@ -106,30 +232,110 @@ static void _reval_content(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - const Eina_List *l; - const Subinfo *si; - if (!wd) return; - EINA_LIST_FOREACH(wd->subs, l, si) - edje_object_part_swallow(wd->cov, si->swallow, si->obj); + if (!wd) + return; + + ELM_HOVER_PARTS_FOREACH + { + char buf[1024]; + snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", wd->subs[i].swallow); + edje_object_part_swallow(wd->cov, buf, wd->subs[i].obj); + } +} + +static const char * +_elm_hover_smart_content_location_get(Widget_Data *wd, Evas_Coord spc_l, Evas_Coord spc_t, Evas_Coord spc_r, Evas_Coord spc_b) +{ + Evas_Coord c_w = 0, c_h = 0, mid_w, mid_h; + int max; + + evas_object_size_hint_min_get(wd->smt_sub, &c_w, &c_h); + mid_w = c_w / 2; + mid_h = c_h / 2; + + if (spc_l > spc_r) + goto left; + + max = MAX(spc_t, spc_r); + max = MAX(max, spc_b); + + if (max == spc_t) + { + if (mid_w > spc_l) + return _HOV_TOP_RIGHT; + + return _HOV_TOP; + } + + if (max == spc_r) + { + if (mid_h > spc_t) + return _HOV_BOTTOM_RIGHT; + else if (mid_h > spc_b) + return _HOV_TOP_RIGHT; + + return _HOV_RIGHT; + } + + if (mid_h > spc_l) + return _HOV_BOTTOM_RIGHT; + + return _HOV_BOTTOM; + +left: + max = MAX(spc_t, spc_l); + max = MAX(max, spc_b); + + if (max == spc_t) + { + if (mid_w > spc_r) + return _HOV_TOP_LEFT; + + return _HOV_TOP; + } + + if (max == spc_l) + { + if (mid_h > spc_t) + return _HOV_BOTTOM_LEFT; + else if (mid_h > spc_b) + return _HOV_TOP_LEFT; + + return _HOV_LEFT; + } + + if (mid_h > spc_r) + return _HOV_BOTTOM_LEFT; + + return _HOV_BOTTOM; } static void _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info) { - Widget_Data *wd = elm_widget_data_get(obj); - Evas_Object *sub = event_info; - Eina_List *l; - Subinfo *si; - if (!wd) return; - EINA_LIST_FOREACH(wd->subs, l, si) + Widget_Data *wd; + Evas_Object *sub; + + sub = event_info; + wd = elm_widget_data_get(obj); + if (!wd) + return; + + if (wd->smt_sub) { - if (si->obj == sub) - { - wd->subs = eina_list_remove_list(wd->subs, l); - eina_stringshare_del(si->swallow); - free(si); - break; - } + if (wd->smt_sub == sub) + wd->smt_sub = NULL; + } + else + { + ELM_HOVER_PARTS_FOREACH + { + if (wd->subs[i].obj == sub) + { + wd->subs[i].obj = NULL; + break; + } + } } } @@ -137,24 +343,25 @@ static void _hov_show_do(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - const Eina_List *l; - const Subinfo *si; - if (!wd) return; + if (!wd) + return; + if (wd->cov) { - evas_object_show(wd->cov); - edje_object_signal_emit(wd->cov, "elm,action,show", "elm"); + evas_object_show(wd->cov); + edje_object_signal_emit(wd->cov, "elm,action,show", "elm"); } - EINA_LIST_FOREACH(wd->subs, l, si) + + ELM_HOVER_PARTS_FOREACH { - char buf[1024]; - - if (!strncmp(si->swallow, "elm.swallow.slot.", 17)) - { - snprintf(buf, sizeof(buf), "elm,action,slot,%s,show", - si->swallow + 17); - edje_object_signal_emit(wd->cov, buf, "elm"); - } + char buf[1024]; + + if (wd->subs[i].obj) + { + snprintf(buf, sizeof(buf), "elm,action,slot,%s,show", + wd->subs[i].swallow); + edje_object_signal_emit(wd->cov, buf, "elm"); + } } } @@ -180,24 +387,23 @@ static void _hov_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); - const Eina_List *l; - const Subinfo *si; if (!wd) return; if (wd->cov) { - edje_object_signal_emit(wd->cov, "elm,action,hide", "elm"); - evas_object_hide(wd->cov); + edje_object_signal_emit(wd->cov, "elm,action,hide", "elm"); + evas_object_hide(wd->cov); } - EINA_LIST_FOREACH(wd->subs, l, si) + + ELM_HOVER_PARTS_FOREACH { - char buf[1024]; - - if (!strncmp(si->swallow, "elm.swallow.slot.", 17)) - { - snprintf(buf, sizeof(buf), "elm,action,slot,%s,hide", - si->swallow + 17); - edje_object_signal_emit(wd->cov, buf, "elm"); - } + char buf[1024]; + + if (wd->subs[i].obj) + { + snprintf(buf, sizeof(buf), "elm,action,slot,%s,hide", + wd->subs[i].swallow); + edje_object_signal_emit(wd->cov, buf, "elm"); + } } } @@ -210,12 +416,23 @@ _target_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *e } static void +_target_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Widget_Data *wd = elm_widget_data_get(data); + if (!wd) + return; + + _sizing_eval(data); + _elm_hover_sub_obj_placement_eval(data); +} + +static void _signal_dismiss(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); if (!wd) return; evas_object_hide(data); - evas_object_smart_callback_call(data, "clicked", NULL); + evas_object_smart_callback_call(data, SIG_CLICKED, NULL); } static void @@ -240,7 +457,7 @@ _parent_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void * { Widget_Data *wd = elm_widget_data_get(data); if (!wd) return; - if (wd) evas_object_hide(wd->cov); + evas_object_hide(wd->cov); } static void @@ -252,14 +469,6 @@ _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *e _sizing_eval(data); } -/** - * Adds a hover object to @p parent - * - * @param parent The parent object - * @return The hover object or NULL if one could not be created - * - * @ingroup Hover - */ EAPI Evas_Object * elm_hover_add(Evas_Object *parent) { @@ -267,19 +476,29 @@ elm_hover_add(Evas_Object *parent) Evas *e; Widget_Data *wd; - wd = ELM_NEW(Widget_Data); - e = evas_object_evas_get(parent); - obj = elm_widget_add(e); + ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL); + ELM_SET_WIDTYPE(widtype, "hover"); elm_widget_type_set(obj, "hover"); elm_widget_sub_object_add(parent, obj); + elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL); elm_widget_data_set(obj, wd); elm_widget_del_pre_hook_set(obj, _del_pre_hook); elm_widget_theme_hook_set(obj, _theme_hook); elm_widget_del_hook_set(obj, _del_hook); + elm_widget_can_focus_set(obj, EINA_TRUE); + elm_widget_signal_emit_hook_set(obj, _signal_emit_hook); + elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook); + elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook); + elm_widget_content_set_hook_set(obj, _content_set_hook); + elm_widget_content_get_hook_set(obj, _content_get_hook); + elm_widget_content_unset_hook_set(obj, _content_unset_hook); + + ELM_HOVER_PARTS_FOREACH + wd->subs[i].swallow = _directions[i]; wd->hov = evas_object_rectangle_add(e); - evas_object_pass_events_set(wd->hov, 1); + evas_object_pass_events_set(wd->hov, EINA_TRUE); evas_object_color_set(wd->hov, 0, 0, 0, 0); elm_widget_resize_object_set(obj, wd->hov); evas_object_event_callback_add(wd->hov, EVAS_CALLBACK_MOVE, _hov_move, obj); @@ -294,12 +513,12 @@ elm_hover_add(Evas_Object *parent) _signal_dismiss, obj); wd->offset = evas_object_rectangle_add(e); - evas_object_pass_events_set(wd->offset, 1); + evas_object_pass_events_set(wd->offset, EINA_TRUE); evas_object_color_set(wd->offset, 0, 0, 0, 0); elm_widget_sub_object_add(obj, wd->offset); wd->size = evas_object_rectangle_add(e); - evas_object_pass_events_set(wd->size, 1); + evas_object_pass_events_set(wd->size, EINA_TRUE); evas_object_color_set(wd->size, 0, 0, 0, 0); elm_widget_sub_object_add(obj, wd->size); @@ -308,19 +527,14 @@ elm_hover_add(Evas_Object *parent) evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj); + elm_hover_parent_set(obj, parent); + evas_object_smart_callbacks_descriptions_set(obj, _signals); + + _mirrored_set(obj, elm_widget_mirrored_get(obj)); _sizing_eval(obj); return obj; } -/** - * Sets the target object for the hover. - * - * @param obj The hover object - * @param target The object to center the hover onto. The hover - * will take up the entire space that the target object fills. - * - * @ingroup Hover - */ EAPI void elm_hover_target_set(Evas_Object *obj, Evas_Object *target) { @@ -328,27 +542,25 @@ elm_hover_target_set(Evas_Object *obj, Evas_Object *target) Widget_Data *wd = elm_widget_data_get(obj); if (wd->target) - evas_object_event_callback_del_full(wd->target, EVAS_CALLBACK_DEL, - _target_del, obj); + { + evas_object_event_callback_del_full(wd->target, EVAS_CALLBACK_DEL, + _target_del, obj); + evas_object_event_callback_del_full(wd->target, EVAS_CALLBACK_MOVE, + _target_move, obj); + } wd->target = target; if (wd->target) { - evas_object_event_callback_add(wd->target, EVAS_CALLBACK_DEL, + evas_object_event_callback_add(wd->target, EVAS_CALLBACK_DEL, _target_del, obj); - elm_widget_hover_object_set(target, obj); - _sizing_eval(obj); + evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOVE, + _target_move, obj); + elm_widget_hover_object_set(target, obj); + _sizing_eval(obj); } } -/** - * Sets the parent object for the hover. - * - * @param obj The hover object - * @param parent The object to locate the hover over. - * - * @ingroup Hover - */ EAPI void elm_hover_parent_set(Evas_Object *obj, Evas_Object *parent) { @@ -357,45 +569,37 @@ elm_hover_parent_set(Evas_Object *obj, Evas_Object *parent) if (!wd) return; if (wd->parent) { - evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_MOVE, - _parent_move, obj); - evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, - _parent_resize, obj); - evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_SHOW, - _parent_show, obj); - evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_HIDE, - _parent_hide, obj); - evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, - _parent_del, obj); + evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_MOVE, + _parent_move, obj); + evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, + _parent_resize, obj); + evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_SHOW, + _parent_show, obj); + evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_HIDE, + _parent_hide, obj); + evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, + _parent_del, obj); } wd->parent = parent; if (wd->parent) { - evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_MOVE, + evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_MOVE, _parent_move, obj); - evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, + evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, obj); - evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_SHOW, + evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_SHOW, _parent_show, obj); - evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_HIDE, + evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_HIDE, _parent_hide, obj); - evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, + evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, obj); -// elm_widget_sub_object_add(parent, obj); + // elm_widget_sub_object_add(parent, obj); } _sizing_eval(obj); } -/** - * Gets the target object for the hover. - * - * @param obj The hover object - * @return The target object of the hover. - * - * @ingroup Hover - */ EAPI Evas_Object * -elm_hover_target_get(Evas_Object *obj) +elm_hover_target_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; Widget_Data *wd = elm_widget_data_get(obj); @@ -404,16 +608,8 @@ elm_hover_target_get(Evas_Object *obj) return wd->target; } -/** - * Gets the parent object for the hover. - * - * @param obj The hover object - * @return The parent object to locate the hover over. - * - * @ingroup Hover - */ EAPI Evas_Object * -elm_hover_parent_get(Evas_Object *obj) +elm_hover_parent_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; Widget_Data *wd = elm_widget_data_get(obj); @@ -422,95 +618,235 @@ elm_hover_parent_get(Evas_Object *obj) return wd->parent; } -/** - * Sets the content of the hover object and the direction in which - * it will pop out. - * - * @param obj The hover object - * @param swallow The direction that the object will display in. Multiple - * objects can have the same swallow location. Objects placed in the same - * swallow will be placed starting at the middle of the hover and ending - * farther from the middle. - * Accepted values are "left" "right" "top" "bottom" "middle" - * @param content The content to place at @p swallow - * - * @ingroup Hover - */ -EAPI void -elm_hover_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content) +static void +_elm_hover_subs_del(Widget_Data *wd) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - Subinfo *si; - const Eina_List *l; - char buf[1024]; - if (!wd) return; - snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", swallow); - EINA_LIST_FOREACH(wd->subs, l, si) + ELM_HOVER_PARTS_FOREACH { - if (!strcmp(buf, si->swallow)) - { - if (content == si->obj) return; - elm_widget_sub_object_del(obj, si->obj); - break; - } + if (wd->subs[i].obj) + { + evas_object_del(wd->subs[i].obj); + wd->subs[i].obj = NULL; + } } - if (content) +} + +static void +_elm_hover_sub_obj_placement_eval(Evas_Object *obj) +{ + Evas_Coord spc_l, spc_r, spc_t, spc_b; + const char *smart_dir; + Widget_Data *wd; + char buf[1024]; + + wd = elm_widget_data_get(obj); + if (!wd->smt_sub) + return; + + _elm_hover_left_space_calc(wd, &spc_l, &spc_t, &spc_r, &spc_b); + + edje_object_part_unswallow(wd->cov, wd->smt_sub); + + smart_dir = _elm_hover_smart_content_location_get(wd, spc_l, spc_t, spc_r, + spc_b); + evas_object_smart_callback_call(obj, SIG_SMART_LOCATION_CHANGED, + (void *)smart_dir); + + if (elm_widget_mirrored_get(obj)) { - elm_widget_sub_object_add(obj, content); - edje_object_part_swallow(wd->cov, buf, content); - si = ELM_NEW(Subinfo); - si->swallow = eina_stringshare_add(buf); - si->obj = content; - wd->subs = eina_list_append(wd->subs, si); - _sizing_eval(obj); + if (smart_dir == _HOV_BOTTOM_LEFT) + smart_dir = _HOV_BOTTOM_RIGHT; + else if (smart_dir == _HOV_BOTTOM_RIGHT) + smart_dir = _HOV_BOTTOM_LEFT; + else if (smart_dir == _HOV_RIGHT) + smart_dir = _HOV_LEFT; + else if (smart_dir == _HOV_LEFT) + smart_dir = _HOV_RIGHT; + else if (smart_dir == _HOV_TOP_RIGHT) + smart_dir = _HOV_TOP_LEFT; + else if (smart_dir == _HOV_TOP_LEFT) + smart_dir = _HOV_TOP_RIGHT; } + snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", smart_dir); + edje_object_part_swallow(wd->cov, buf, wd->smt_sub); +} + +static void +_elm_hover_sub_obj_placement_eval_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + _elm_hover_sub_obj_placement_eval(data); +} + +static void +_elm_hover_sub_obj_unparent(Evas_Object *obj) +{ + Widget_Data *wd; + Evas_Object *smt_sub; + + wd = elm_widget_data_get(obj); + if (!wd) return; + + smt_sub = wd->smt_sub; + elm_widget_sub_object_del(obj, wd->smt_sub); + evas_object_event_callback_del_full(smt_sub, + EVAS_CALLBACK_CHANGED_SIZE_HINTS, + _elm_hover_sub_obj_placement_eval_cb, + obj); + edje_object_part_unswallow(wd->cov, smt_sub); } -/** - * Returns the best swallow location for content in the hover. - * - * @param obj The hover object - * @return The edje location to place content into the hover. - * See also elm_hover_content_set() - * - * @ingroup Hover - */ EAPI const char * elm_hover_best_content_location_get(const Evas_Object *obj, Elm_Hover_Axis pref_axis) { - ELM_CHECK_WIDTYPE(obj, widtype) "left"; - Widget_Data *wd = elm_widget_data_get(obj); - Evas_Coord x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0; + ELM_CHECK_WIDTYPE(obj, widtype) NULL; + Evas_Coord spc_l, spc_r, spc_t, spc_b; - if (!wd) return "left"; - if (wd->parent) evas_object_geometry_get(wd->parent, &x, &y, &w, &h); - if (wd->target) evas_object_geometry_get(wd->target, &x2, &y2, &w2, &h2); - spc_l = x2 - x; - spc_r = (x + w) - (x2 + w2); - if (spc_l < 0) spc_l = 0; - if (spc_r < 0) spc_r = 0; - spc_t = y2 - y; - spc_b = (y + h) - (y2 + h2); - if (spc_t < 0) spc_t = 0; - if (spc_b < 0) spc_b = 0; + Widget_Data *wd; + + wd = elm_widget_data_get(obj); + if (!wd) + return NULL; + + _elm_hover_left_space_calc(wd, &spc_l, &spc_t, &spc_r, &spc_b); + if (pref_axis == ELM_HOVER_AXIS_HORIZONTAL) { - if (spc_l < spc_r) return "right"; - else return "left"; + if (spc_l < spc_r) return _HOV_RIGHT; + else return _HOV_LEFT; } else if (pref_axis == ELM_HOVER_AXIS_VERTICAL) { - if (spc_t < spc_b) return "bottom"; - else return "top"; + if (spc_t < spc_b) return _HOV_BOTTOM; + else return _HOV_TOP; } + if (spc_l < spc_r) { - if (spc_t > spc_r) return "top"; - else if (spc_b > spc_r) return "bottom"; - return "right"; + if (spc_t > spc_r) return _HOV_TOP; + else if (spc_b > spc_r) return _HOV_BOTTOM; + return _HOV_RIGHT; } - if (spc_t > spc_r) return "top"; - else if (spc_b > spc_r) return "bottom"; - return "left"; + if (spc_t > spc_r) return _HOV_TOP; + else if (spc_b > spc_r) return _HOV_BOTTOM; + return _HOV_LEFT; +} + +EAPI void +elm_hover_dismiss(Evas_Object *obj) +{ + Widget_Data *wd; + ELM_CHECK_WIDTYPE(obj, widtype); + wd = elm_widget_data_get(obj); + if (!wd) return; + + edje_object_signal_emit(wd->cov, "elm,action,dismiss", ""); +} + +static void +_content_set_hook(Evas_Object *obj, const char *swallow, Evas_Object *content) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + + if (!strcmp(swallow, "smart")) + { + if (wd->smt_sub != content) + { + _elm_hover_subs_del(wd); + wd->smt_sub = content; + } + + if (content) + { + elm_widget_sub_object_add(obj, content); + evas_object_event_callback_add(wd->smt_sub, + EVAS_CALLBACK_CHANGED_SIZE_HINTS, + _elm_hover_sub_obj_placement_eval_cb, + obj); + + _elm_hover_sub_obj_placement_eval(obj); + } + + goto end; + } + + if (wd->smt_sub) + { + evas_object_del(wd->smt_sub); + wd->smt_sub = NULL; + } + + ELM_HOVER_PARTS_FOREACH + { + if (!strcmp(swallow, wd->subs[i].swallow)) + { + if (content == wd->subs[i].obj) + return; + evas_object_del(wd->subs[i].obj); + wd->subs[i].obj = NULL; + + if (content) + { + char buf[1024]; + + snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", swallow); + elm_widget_sub_object_add(obj, content); + edje_object_part_swallow(wd->cov, buf, content); + wd->subs[i].obj = content; + } + break; + } + } +end: + _sizing_eval(obj); +} + +static Evas_Object * +_content_get_hook(const Evas_Object *obj, const char *swallow) +{ + ELM_CHECK_WIDTYPE(obj, widtype) NULL; + + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return NULL; + + if (!strcmp(swallow, "smart")) + return wd->smt_sub; + + ELM_HOVER_PARTS_FOREACH + if (!strcmp(swallow, wd->subs[i].swallow)) + return wd->subs[i].obj; + + return NULL; +} + +static Evas_Object * +_content_unset_hook(Evas_Object *obj, const char *swallow) +{ + ELM_CHECK_WIDTYPE(obj, widtype) NULL; + + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return NULL; + + if (!strcmp(swallow, "smart")) + { + if (!wd->smt_sub) return NULL; + Evas_Object *content = wd->smt_sub; + _elm_hover_sub_obj_unparent(obj); + return content; + } + + ELM_HOVER_PARTS_FOREACH + { + if (!strcmp(swallow, wd->subs[i].swallow)) + { + if (!wd->subs[i].obj) return NULL; + Evas_Object *content = wd->subs[i].obj; + elm_widget_sub_object_del(obj, wd->subs[i].obj); + edje_object_part_unswallow(wd->cov, content); + return content; + } + } + + return NULL; }