summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeonghyun Yun <jh0506.yun@samsung.com>2017-09-19 17:05:15 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-09-19 17:05:15 +0900
commitcc691776f31f09e3012272c5bb02579efaaf1dc7 (patch)
treeaac2d3701ab6ed39f241b2275ee816ffb232e10d
parentd3cf6093aaba677992efa83509ecb3c99df35e85 (diff)
downloadefl-cc691776f31f09e3012272c5bb02579efaaf1dc7.tar.gz
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
-rw-r--r--src/bin/elementary/test_tooltip.c8
-rw-r--r--src/lib/elementary/els_tooltip.c69
2 files changed, 53 insertions, 24 deletions
diff --git a/src/bin/elementary/test_tooltip.c b/src/bin/elementary/test_tooltip.c
index b93ffcc2a6..eb4ce890c1 100644
--- a/src/bin/elementary/test_tooltip.c
+++ b/src/bin/elementary/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;
}
@@ -526,8 +526,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);
@@ -572,8 +572,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);
@@ -611,8 +611,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/elementary/els_tooltip.c b/src/lib/elementary/els_tooltip.c
index 16c1fe9ace..4865d7c9db 100644
--- a/src/lib/elementary/els_tooltip.c
+++ b/src/lib/elementary/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;
@@ -734,6 +751,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)
{
@@ -826,7 +865,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;
@@ -893,7 +932,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);
@@ -905,7 +944,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)
{
@@ -930,23 +969,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);
@@ -1032,7 +1061,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);
}
@@ -1047,7 +1076,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;
}