From: Jeonghyun Yun Date: Wed, 20 Sep 2017 01:02:56 +0000 (+0900) Subject: els_tooltip: Fix to use some functions before tooltip_test_set or tooltip_content_cb_set X-Git-Tag: accepted/tizen/4.0/unified/20170929.075917~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F151102%2F2;p=platform%2Fupstream%2Felementary.git els_tooltip: Fix to use some functions before tooltip_test_set or tooltip_content_cb_set Summary: If user call tooltip_orient_set or tooltip_style_set or tooltip_window_mode_set before tooltip_test_set or tooltip_content_cb_set, those functions doesn't work. Because elm_tooltip will be created when tooltip_content_cb_set is called. I fixed logic to use some functions before tooltip_test_set or tooltip_content_cb_set. Test Plan: elementary_test -> Popups -> Tooltip Reviewers: jpeg, Jaehyun Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D5183 Change-Id: Ia058679cd1645a12e048d8c5b0db0566f2742fca Signed-off-by: Jeonghyun Yun --- diff --git a/src/bin/test_tooltip.c b/src/bin/test_tooltip.c index e105b1e..4d0d375 100644 --- a/src/bin/test_tooltip.c +++ b/src/bin/test_tooltip.c @@ -231,8 +231,8 @@ _tt_orient_text_replace(void *data EINA_UNUSED, { case ELM_TOOLTIP_ORIENT_TOP_LEFT: { - elm_object_tooltip_text_set(obj, "Top Left"); elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP_LEFT); + elm_object_tooltip_text_set(obj, "Top Left"); printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP_LEFT\n"); break; } @@ -514,8 +514,8 @@ test_tooltip(void *data EINA_UNUSED, bt = elm_button_add(win); elm_object_text_set(bt, "Orient Tooltip, click to change"); - elm_object_tooltip_text_set(bt, "Top Left"); elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP_LEFT); + elm_object_tooltip_text_set(bt, "Top Left"); evas_object_smart_callback_add(bt, "clicked", _tt_orient_text_replace, NULL); elm_box_pack_end(bx, bt); evas_object_show(bt); @@ -557,8 +557,8 @@ test_tooltip(void *data EINA_UNUSED, bt = elm_button_add(win); elm_object_text_set(bt, "Transparent Icon tooltip"); - elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL); elm_object_tooltip_style_set(bt, "transparent"); + elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL); elm_box_pack_end(bx, bt); evas_object_show(bt); @@ -596,8 +596,8 @@ test_tooltip(void *data EINA_UNUSED, lst = elm_list_add(win); lit = elm_list_item_append(lst, "Hello", NULL, NULL, NULL, NULL); - elm_object_item_tooltip_content_cb_set(lit, _tt_item_label, NULL, NULL); elm_object_item_tooltip_window_mode_set(lit, EINA_TRUE); + elm_object_item_tooltip_content_cb_set(lit, _tt_item_label, NULL, NULL); lit = elm_list_item_append(lst, "Icon Tooltip", NULL, NULL, NULL, NULL); elm_object_item_tooltip_content_cb_set(lit, _tt_item_icon, NULL, NULL); lit = elm_list_item_append(lst, "Big Icon Tooltip", NULL, NULL, NULL, NULL); diff --git a/src/lib/els_tooltip.c b/src/lib/els_tooltip.c index ea88cb3..67cf5a7 100644 --- a/src/lib/els_tooltip.c +++ b/src/lib/els_tooltip.c @@ -34,6 +34,23 @@ static const char _tooltip_key[] = "_elm_tooltip"; } \ while (0) +#define ELM_TOOLTIP_GET_OR_CREATE(tt, obj, ...) \ + Elm_Tooltip *tt; \ + do \ + { \ + if (!(obj)) \ + { \ + CRI("Null pointer: " #obj); \ + return __VA_ARGS__; \ + } \ + tt = evas_object_data_get((obj), _tooltip_key); \ + if (!tt) \ + { \ + tt = _elm_tooltip_create((obj)); \ + } \ + } \ + while (0) + struct _Elm_Tooltip { Elm_Tooltip_Content_Cb func; @@ -795,6 +812,28 @@ _elm_tooltip_obj_free_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, voi _elm_tooltip_unset(tt); } +static Elm_Tooltip * +_elm_tooltip_create(Evas_Object *eventarea) +{ + Elm_Tooltip *tt = NULL; + + tt = ELM_NEW(Elm_Tooltip); + if (!tt) return NULL; + + tt->eventarea = eventarea; + tt->evas = evas_object_evas_get(eventarea); + evas_object_data_set(eventarea, _tooltip_key, tt); + + evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN, + _elm_tooltip_obj_mouse_in_cb, tt); + evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT, + (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt); + evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE, + _elm_tooltip_obj_free_cb, tt); + + return tt; +} + static void _tooltip_label_style_set(Evas_Object *obj, Evas_Object *label) { @@ -887,7 +926,7 @@ elm_object_tooltip_move_freeze_get(const Evas_Object *obj) EAPI void elm_object_tooltip_orient_set(Evas_Object *obj, Elm_Tooltip_Orient orient) { - ELM_TOOLTIP_GET_OR_RETURN(tt, obj); + ELM_TOOLTIP_GET_OR_CREATE(tt, obj); if ((orient > ELM_TOOLTIP_ORIENT_NONE) && (orient < ELM_TOOLTIP_ORIENT_LAST)) tt->orient = orient; @@ -954,7 +993,7 @@ void elm_object_sub_tooltip_content_cb_set(Evas_Object *eventarea, Evas_Object *owner, Elm_Tooltip_Content_Cb func, const void *data, Evas_Smart_Cb del_cb) { Elm_Tooltip *tt = NULL; - Eina_Bool just_created; + Eina_Bool just_created = EINA_TRUE; EINA_SAFETY_ON_NULL_GOTO(owner, error); EINA_SAFETY_ON_NULL_GOTO(eventarea, error); @@ -966,7 +1005,7 @@ elm_object_sub_tooltip_content_cb_set(Evas_Object *eventarea, Evas_Object *owner } tt = evas_object_data_get(eventarea, _tooltip_key); - if (tt) + if (tt && tt->owner) { if (tt->owner != owner) { @@ -991,23 +1030,13 @@ elm_object_sub_tooltip_content_cb_set(Evas_Object *eventarea, Evas_Object *owner } else { - tt = ELM_NEW(Elm_Tooltip); - if (!tt) goto error; + if (!tt) + { + tt = _elm_tooltip_create(eventarea); + if (!tt) goto error; + } tt->owner = owner; - tt->eventarea = eventarea; - tt->evas = evas_object_evas_get(eventarea); - evas_object_data_set(eventarea, _tooltip_key, tt); - - just_created = EINA_TRUE; - - evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN, - _elm_tooltip_obj_mouse_in_cb, tt); - evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT, - (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt); - evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE, - _elm_tooltip_obj_free_cb, tt); - if (owner != eventarea) evas_object_event_callback_add (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt); @@ -1085,7 +1114,7 @@ elm_object_tooltip_unset(Evas_Object *obj) EAPI void elm_object_tooltip_style_set(Evas_Object *obj, const char *style) { - ELM_TOOLTIP_GET_OR_RETURN(tt, obj); + ELM_TOOLTIP_GET_OR_CREATE(tt, obj); if (!eina_stringshare_replace(&tt->style, style)) return; elm_tooltip_theme(tt); } @@ -1100,7 +1129,7 @@ elm_object_tooltip_style_get(const Evas_Object *obj) EAPI Eina_Bool elm_object_tooltip_window_mode_set(Evas_Object *obj, Eina_Bool disable) { - ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE); + ELM_TOOLTIP_GET_OR_CREATE(tt, obj, EINA_FALSE); return tt->free_size = disable; }