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)
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,
231 { 231 {
232 case ELM_TOOLTIP_ORIENT_TOP_LEFT: 232 case ELM_TOOLTIP_ORIENT_TOP_LEFT:
233 { 233 {
234 elm_object_tooltip_text_set(obj, "Top Left");
235 elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP_LEFT); 234 elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP_LEFT);
235 elm_object_tooltip_text_set(obj, "Top Left");
236 printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP_LEFT\n"); 236 printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP_LEFT\n");
237 break; 237 break;
238 } 238 }
@@ -526,8 +526,8 @@ test_tooltip(void *data EINA_UNUSED,
526 526
527 bt = elm_button_add(win); 527 bt = elm_button_add(win);
528 elm_object_text_set(bt, "Orient Tooltip, click to change"); 528 elm_object_text_set(bt, "Orient Tooltip, click to change");
529 elm_object_tooltip_text_set(bt, "Top Left");
530 elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP_LEFT); 529 elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP_LEFT);
530 elm_object_tooltip_text_set(bt, "Top Left");
531 evas_object_smart_callback_add(bt, "clicked", _tt_orient_text_replace, NULL); 531 evas_object_smart_callback_add(bt, "clicked", _tt_orient_text_replace, NULL);
532 elm_box_pack_end(bx, bt); 532 elm_box_pack_end(bx, bt);
533 evas_object_show(bt); 533 evas_object_show(bt);
@@ -572,8 +572,8 @@ test_tooltip(void *data EINA_UNUSED,
572 572
573 bt = elm_button_add(win); 573 bt = elm_button_add(win);
574 elm_object_text_set(bt, "Transparent Icon tooltip"); 574 elm_object_text_set(bt, "Transparent Icon tooltip");
575 elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
576 elm_object_tooltip_style_set(bt, "transparent"); 575 elm_object_tooltip_style_set(bt, "transparent");
576 elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
577 elm_box_pack_end(bx, bt); 577 elm_box_pack_end(bx, bt);
578 evas_object_show(bt); 578 evas_object_show(bt);
579 579
@@ -611,8 +611,8 @@ test_tooltip(void *data EINA_UNUSED,
611 611
612 lst = elm_list_add(win); 612 lst = elm_list_add(win);
613 lit = elm_list_item_append(lst, "Hello", NULL, NULL, NULL, NULL); 613 lit = elm_list_item_append(lst, "Hello", NULL, NULL, NULL, NULL);
614 elm_object_item_tooltip_content_cb_set(lit, _tt_item_label, NULL, NULL);
615 elm_object_item_tooltip_window_mode_set(lit, EINA_TRUE); 614 elm_object_item_tooltip_window_mode_set(lit, EINA_TRUE);
615 elm_object_item_tooltip_content_cb_set(lit, _tt_item_label, NULL, NULL);
616 lit = elm_list_item_append(lst, "Icon Tooltip", NULL, NULL, NULL, NULL); 616 lit = elm_list_item_append(lst, "Icon Tooltip", NULL, NULL, NULL, NULL);
617 elm_object_item_tooltip_content_cb_set(lit, _tt_item_icon, NULL, NULL); 617 elm_object_item_tooltip_content_cb_set(lit, _tt_item_icon, NULL, NULL);
618 lit = elm_list_item_append(lst, "Big Icon Tooltip", NULL, NULL, NULL, NULL); 618 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";
34 } \ 34 } \
35 while (0) 35 while (0)
36 36
37#define ELM_TOOLTIP_GET_OR_CREATE(tt, obj, ...) \
38 Elm_Tooltip *tt; \
39 do \
40 { \
41 if (!(obj)) \
42 { \
43 CRI("Null pointer: " #obj); \
44 return __VA_ARGS__; \
45 } \
46 tt = evas_object_data_get((obj), _tooltip_key); \
47 if (!tt) \
48 { \
49 tt = _elm_tooltip_create((obj)); \
50 } \
51 } \
52 while (0)
53
37struct _Elm_Tooltip 54struct _Elm_Tooltip
38{ 55{
39 Elm_Tooltip_Content_Cb func; 56 Elm_Tooltip_Content_Cb func;
@@ -734,6 +751,28 @@ _elm_tooltip_obj_free_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, voi
734 _elm_tooltip_unset(tt); 751 _elm_tooltip_unset(tt);
735} 752}
736 753
754static Elm_Tooltip *
755_elm_tooltip_create(Evas_Object *eventarea)
756{
757 Elm_Tooltip *tt = NULL;
758
759 tt = ELM_NEW(Elm_Tooltip);
760 if (!tt) return NULL;
761
762 tt->eventarea = eventarea;
763 tt->evas = evas_object_evas_get(eventarea);
764 evas_object_data_set(eventarea, _tooltip_key, tt);
765
766 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN,
767 _elm_tooltip_obj_mouse_in_cb, tt);
768 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT,
769 (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
770 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE,
771 _elm_tooltip_obj_free_cb, tt);
772
773 return tt;
774}
775
737static void 776static void
738_tooltip_label_style_set(Evas_Object *obj, Evas_Object *label) 777_tooltip_label_style_set(Evas_Object *obj, Evas_Object *label)
739{ 778{
@@ -826,7 +865,7 @@ elm_object_tooltip_move_freeze_get(const Evas_Object *obj)
826EAPI void 865EAPI void
827elm_object_tooltip_orient_set(Evas_Object *obj, Elm_Tooltip_Orient orient) 866elm_object_tooltip_orient_set(Evas_Object *obj, Elm_Tooltip_Orient orient)
828{ 867{
829 ELM_TOOLTIP_GET_OR_RETURN(tt, obj); 868 ELM_TOOLTIP_GET_OR_CREATE(tt, obj);
830 869
831 if ((orient > ELM_TOOLTIP_ORIENT_NONE) && (orient < ELM_TOOLTIP_ORIENT_LAST)) 870 if ((orient > ELM_TOOLTIP_ORIENT_NONE) && (orient < ELM_TOOLTIP_ORIENT_LAST))
832 tt->orient = orient; 871 tt->orient = orient;
@@ -893,7 +932,7 @@ void
893elm_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) 932elm_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)
894{ 933{
895 Elm_Tooltip *tt = NULL; 934 Elm_Tooltip *tt = NULL;
896 Eina_Bool just_created; 935 Eina_Bool just_created = EINA_TRUE;
897 936
898 EINA_SAFETY_ON_NULL_GOTO(owner, error); 937 EINA_SAFETY_ON_NULL_GOTO(owner, error);
899 EINA_SAFETY_ON_NULL_GOTO(eventarea, error); 938 EINA_SAFETY_ON_NULL_GOTO(eventarea, error);
@@ -905,7 +944,7 @@ elm_object_sub_tooltip_content_cb_set(Evas_Object *eventarea, Evas_Object *owner
905 } 944 }
906 945
907 tt = evas_object_data_get(eventarea, _tooltip_key); 946 tt = evas_object_data_get(eventarea, _tooltip_key);
908 if (tt) 947 if (tt && tt->owner)
909 { 948 {
910 if (tt->owner != owner) 949 if (tt->owner != owner)
911 { 950 {
@@ -930,23 +969,13 @@ elm_object_sub_tooltip_content_cb_set(Evas_Object *eventarea, Evas_Object *owner
930 } 969 }
931 else 970 else
932 { 971 {
933 tt = ELM_NEW(Elm_Tooltip); 972 if (!tt)
934 if (!tt) goto error; 973 {
974 tt = _elm_tooltip_create(eventarea);
975 if (!tt) goto error;
976 }
935 977
936 tt->owner = owner; 978 tt->owner = owner;
937 tt->eventarea = eventarea;
938 tt->evas = evas_object_evas_get(eventarea);
939 evas_object_data_set(eventarea, _tooltip_key, tt);
940
941 just_created = EINA_TRUE;
942
943 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN,
944 _elm_tooltip_obj_mouse_in_cb, tt);
945 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT,
946 (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
947 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE,
948 _elm_tooltip_obj_free_cb, tt);
949
950 if (owner != eventarea) 979 if (owner != eventarea)
951 evas_object_event_callback_add 980 evas_object_event_callback_add
952 (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt); 981 (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
@@ -1032,7 +1061,7 @@ elm_object_tooltip_unset(Evas_Object *obj)
1032EAPI void 1061EAPI void
1033elm_object_tooltip_style_set(Evas_Object *obj, const char *style) 1062elm_object_tooltip_style_set(Evas_Object *obj, const char *style)
1034{ 1063{
1035 ELM_TOOLTIP_GET_OR_RETURN(tt, obj); 1064 ELM_TOOLTIP_GET_OR_CREATE(tt, obj);
1036 if (!eina_stringshare_replace(&tt->style, style)) return; 1065 if (!eina_stringshare_replace(&tt->style, style)) return;
1037 elm_tooltip_theme(tt); 1066 elm_tooltip_theme(tt);
1038} 1067}
@@ -1047,7 +1076,7 @@ elm_object_tooltip_style_get(const Evas_Object *obj)
1047EAPI Eina_Bool 1076EAPI Eina_Bool
1048elm_object_tooltip_window_mode_set(Evas_Object *obj, Eina_Bool disable) 1077elm_object_tooltip_window_mode_set(Evas_Object *obj, Eina_Bool disable)
1049{ 1078{
1050 ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE); 1079 ELM_TOOLTIP_GET_OR_CREATE(tt, obj, EINA_FALSE);
1051 return tt->free_size = disable; 1080 return tt->free_size = disable;
1052} 1081}
1053 1082