1 #include <Elementary.h>
6 # define STUPID(X) STR(X)
7 # define TTDBG(x...) fprintf(stderr, STUPID(__LINE__)": " x)
12 static const char _tooltip_key[] = "_elm_tooltip";
14 #define ELM_TOOLTIP_GET_OR_RETURN(tt, obj, ...) \
20 CRITICAL("Null pointer: " #obj); \
23 tt = evas_object_data_get((obj), _tooltip_key); \
26 ERR("Object does not have tooltip: " #obj); \
34 Elm_Tooltip_Content_Cb func;
39 Evas_Object *eventarea, *owner;
40 Evas_Object *tooltip, *content;
42 Ecore_Timer *show_timer;
43 Ecore_Timer *hide_timer;
44 Ecore_Job *reconfigure_job;
45 Evas_Coord mouse_x, mouse_y;
48 Evas_Coord x, y, bx, by;
54 double hide_timeout; /* from theme */
55 Eina_Bool visible_lock:1;
56 Eina_Bool changed_style:1;
57 Eina_Bool free_size : 1;
60 static void _elm_tooltip_reconfigure(Elm_Tooltip *tt);
61 static void _elm_tooltip_reconfigure_job_start(Elm_Tooltip *tt);
62 static void _elm_tooltip_reconfigure_job_stop(Elm_Tooltip *tt);
63 static void _elm_tooltip_hide_anim_start(Elm_Tooltip *tt);
64 static void _elm_tooltip_hide_anim_stop(Elm_Tooltip *tt);
65 static void _elm_tooltip_show_timer_stop(Elm_Tooltip *tt);
66 static void _elm_tooltip_hide(Elm_Tooltip *tt);
67 static void _elm_tooltip_data_clean(Elm_Tooltip *tt);
70 _elm_tooltip_content_changed_hints_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
72 _elm_tooltip_reconfigure_job_start(data);
73 TTDBG("HINTS CHANGED\n");
77 _elm_tooltip_content_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
79 Elm_Tooltip *tt = data;
81 tt->visible_lock = EINA_FALSE;
82 if (tt->tooltip) _elm_tooltip_hide(tt);
86 _elm_tooltip_obj_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
88 Elm_Tooltip *tt = data;
89 _elm_tooltip_reconfigure_job_start(tt);
94 _elm_tooltip_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
96 Elm_Tooltip *tt = data;
97 _elm_tooltip_reconfigure_job_start(tt);
102 _elm_tooltip_obj_mouse_move_cb(Elm_Tooltip *tt, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Move *ev)
104 if (tt->mouse_x || tt->mouse_y)
106 if ((abs(ev->cur.output.x - tt->mouse_x) < 3) &&
107 (abs(ev->cur.output.y - tt->mouse_y) < 3))
109 TTDBG("MOUSE MOVE REJECTED!\n");
113 tt->mouse_x = ev->cur.output.x;
114 tt->mouse_y = ev->cur.output.y;
115 TTDBG("MOUSE MOVED\n");
116 _elm_tooltip_reconfigure_job_start(tt);
120 _elm_tooltip_show(Elm_Tooltip *tt)
122 _elm_tooltip_show_timer_stop(tt);
123 _elm_tooltip_hide_anim_stop(tt);
128 _elm_tooltip_reconfigure_job_start(tt);
129 TTDBG("RECURSIVE JOB\n");
134 tt->tt_win = elm_win_add(NULL, "tooltip", ELM_WIN_BASIC);
135 elm_win_override_set(tt->tt_win, EINA_TRUE);
136 tt->tt_evas = evas_object_evas_get(tt->tt_win);
137 tt->tooltip = edje_object_add(tt->tt_evas);
138 evas_object_size_hint_weight_set(tt->tooltip, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
139 evas_object_size_hint_align_set(tt->tooltip, EVAS_HINT_FILL, EVAS_HINT_FILL);
140 elm_win_resize_object_add(tt->tt_win, tt->tooltip);
143 tt->tooltip = edje_object_add(tt->evas);
144 if (!tt->tooltip) return;
147 evas_object_layer_set(tt->tooltip, ELM_OBJECT_LAYER_TOOLTIP);
149 evas_object_event_callback_add
150 (tt->eventarea, EVAS_CALLBACK_MOVE, _elm_tooltip_obj_move_cb, tt);
151 evas_object_event_callback_add
152 (tt->eventarea, EVAS_CALLBACK_RESIZE, _elm_tooltip_obj_resize_cb, tt);
153 evas_object_event_callback_add
154 (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_move_cb, tt);
156 tt->changed_style = EINA_TRUE;
157 _elm_tooltip_reconfigure_job_start(tt);
161 _elm_tooltip_content_del(Elm_Tooltip *tt)
163 if (!tt->content) return;
165 TTDBG("CONTENT DEL\n");
166 evas_object_event_callback_del_full
167 (tt->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
168 _elm_tooltip_content_changed_hints_cb, tt);
169 evas_object_event_callback_del_full
170 (tt->content, EVAS_CALLBACK_DEL,
171 _elm_tooltip_content_del_cb, tt);
172 evas_object_hide(tt->content);
173 evas_object_del(tt->content);
179 _elm_tooltip_hide(Elm_Tooltip *tt)
183 _elm_tooltip_show_timer_stop(tt);
184 _elm_tooltip_hide_anim_stop(tt);
185 _elm_tooltip_reconfigure_job_stop(tt);
187 if (!tt->tooltip) return;
188 if (tt->visible_lock) return;
190 _elm_tooltip_content_del(tt);
192 evas_object_event_callback_del_full
193 (tt->eventarea, EVAS_CALLBACK_MOVE, _elm_tooltip_obj_move_cb, tt);
194 evas_object_event_callback_del_full
195 (tt->eventarea, EVAS_CALLBACK_RESIZE, _elm_tooltip_obj_resize_cb, tt);
196 evas_object_event_callback_del_full
197 (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_move_cb, tt);
199 del = tt->tt_win ?: tt->tooltip;
204 evas_object_del(del);
208 _elm_tooltip_reconfigure_job(void *data)
210 Elm_Tooltip *tt = data;
211 tt->reconfigure_job = NULL;
212 _elm_tooltip_reconfigure(data);
216 _elm_tooltip_reconfigure_job_stop(Elm_Tooltip *tt)
218 if (!tt->reconfigure_job) return;
219 ecore_job_del(tt->reconfigure_job);
220 tt->reconfigure_job = NULL;
224 _elm_tooltip_reconfigure_job_start(Elm_Tooltip *tt)
226 if (tt->reconfigure_job) ecore_job_del(tt->reconfigure_job);
227 tt->reconfigure_job = ecore_job_add(_elm_tooltip_reconfigure_job, tt);
231 _elm_tooltip_hide_anim_cb(void *data)
233 Elm_Tooltip *tt = data;
234 tt->hide_timer = NULL;
235 _elm_tooltip_hide(tt);
240 _elm_tooltip_hide_anim_start(Elm_Tooltip *tt)
243 if (tt->hide_timer) return;
244 TTDBG("HIDE START\n");
245 /* hide slightly faster when in window mode to look less stupid */
246 if ((tt->hide_timeout > 0) && tt->tt_win) extra = 0.1;
247 edje_object_signal_emit(tt->tooltip, "elm,action,hide", "elm");
248 tt->hide_timer = ecore_timer_add
249 (tt->hide_timeout - extra, _elm_tooltip_hide_anim_cb, tt);
253 _elm_tooltip_hide_anim_stop(Elm_Tooltip *tt)
255 if (!tt->hide_timer) return;
257 edje_object_signal_emit(tt->tooltip, "elm,action,show", "elm");
258 ecore_timer_del(tt->hide_timer);
259 tt->hide_timer = NULL;
263 _elm_tooltip_reconfigure(Elm_Tooltip *tt)
265 Evas_Coord ox, oy, ow, oh, px, py, tx, ty, tw, th, cw = 0, ch = 0;
266 Evas_Coord eminw, eminh, ominw, ominh;
268 Eina_Bool inside_eventarea;
270 _elm_tooltip_reconfigure_job_stop(tt);
272 if (tt->hide_timer) return;
273 if (!tt->tooltip) return;
274 if (tt->changed_style)
276 const char *style = tt->style ? tt->style : "default";
278 if (!_elm_theme_object_set(tt->tt_win ? NULL : tt->owner, tt->tooltip, "tooltip", "base", style))
280 ERR("Could not apply the theme to the tooltip! style=%s", style);
281 if (tt->tt_win) evas_object_del(tt->tt_win);
282 else evas_object_del(tt->tooltip);
296 tt->hide_timeout = 0.0;
298 str = edje_object_data_get(tt->tooltip, "transparent");
300 { /* FIXME: hardcoded here is bad */
301 if (str && (!strcmp(str, "enabled")))
303 evas_object_hide(tt->tt_win);
304 elm_win_alpha_set(tt->tt_win, EINA_TRUE);
305 #ifdef HAVE_ELEMENTARY_X
306 ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(tt->tt_win), 0, 0, 0, 0);
308 evas_object_show(tt->tt_win);
312 evas_object_hide(tt->tt_win);
313 elm_win_alpha_set(tt->tt_win, EINA_FALSE);
314 #ifdef HAVE_ELEMENTARY_X
315 ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(tt->tt_win), 0, 0, 0, 0);
317 evas_object_show(tt->tt_win);
321 str = edje_object_data_get(tt->tooltip, "pad_x");
322 if (str) tt->pad.x = atoi(str);
323 str = edje_object_data_get(tt->tooltip, "pad_y");
324 if (str) tt->pad.y = atoi(str);
326 str = edje_object_data_get(tt->tooltip, "pad_border_x");
327 if (str) tt->pad.bx = atoi(str);
328 str = edje_object_data_get(tt->tooltip, "pad_border_y");
329 if (str) tt->pad.by = atoi(str);
331 str = edje_object_data_get(tt->tooltip, "hide_timeout");
334 tt->hide_timeout = _elm_atof(str);
335 if (tt->hide_timeout < 0.0) tt->hide_timeout = 0.0;
338 evas_object_pass_events_set(tt->tooltip, EINA_TRUE);
339 tt->changed_style = EINA_FALSE;
341 edje_object_part_swallow(tt->tooltip, "elm.swallow.content",
344 edje_object_signal_emit(tt->tooltip, "elm,action,show", "elm");
349 tt->content = tt->func((void *)tt->data, tt->owner, tt->tt_win ? : tt->owner);
352 WRN("could not create tooltip content!");
353 if (tt->tt_win) evas_object_del(tt->tt_win);
354 else evas_object_del(tt->tooltip);
361 evas_object_show(tt->content);
362 evas_object_layer_set(tt->content, ELM_OBJECT_LAYER_TOOLTIP);
363 evas_object_pass_events_set(tt->content, EINA_TRUE);
364 edje_object_part_swallow
365 (tt->tooltip, "elm.swallow.content", tt->content);
366 evas_object_event_callback_add(tt->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
367 _elm_tooltip_content_changed_hints_cb, tt);
368 evas_object_event_callback_add(tt->content, EVAS_CALLBACK_DEL,
369 _elm_tooltip_content_del_cb, tt);
372 TTDBG("*******RECALC\n");
373 evas_object_size_hint_min_get(tt->content, &ominw, &ominh);
374 edje_object_size_min_get(tt->tooltip, &eminw, &eminh);
376 if (eminw && (ominw < eminw)) ominw = eminw;
377 if (eminh && (ominh < eminh)) ominh = eminh;
379 if (ominw < 1) ominw = 10; /* at least it is noticeable */
380 if (ominh < 1) ominh = 10; /* at least it is noticeable */
382 edje_object_size_min_restricted_calc(tt->tooltip, &tw, &th, ominw, ominh);
383 TTDBG("TTSIZE: tw=%d,th=%d,ominw=%d,ominh=%d\n", tw, th, ominw, ominh);
386 elm_win_screen_size_get(elm_object_top_widget_get(tt->owner), NULL, NULL, &cw, &ch);
388 evas_output_size_get(tt->tt_evas ?: tt->evas, &cw, &ch);
389 TTDBG("SCREEN: cw=%d,ch=%d\n", cw, ch);
391 evas_object_geometry_get(tt->eventarea, &ox, &oy, &ow, &oh);
392 TTDBG("EVENTAREA: ox=%d,oy=%d,ow=%d,oh=%d\n", ox, oy, ow, oh);
397 Evas_Object *win = elm_object_top_widget_get(tt->owner);
398 #ifdef HAVE_ELEMENTARY_X
399 Ecore_X_Window xwin = elm_win_xwindow_get(win);
400 ecore_x_pointer_xy_get(xwin, &px, &py);
402 elm_win_screen_position_get(win, &x, &y);
409 evas_pointer_canvas_xy_get(tt->evas, &px, &py);
410 TTDBG("POINTER: px=%d,py=%d\n", px, py);
411 inside_eventarea = ((px >= ox) && (py >= oy) &&
412 (px <= ox + ow) && (py <= oy + oh));
413 if (inside_eventarea)
415 /* try to position bottom right corner at pointer */
418 TTDBG("INIT (EVENTAREA)\n");
422 /* try centered on middle of eventarea */
423 tx = ox + (ow / 2) - (tw / 2);
424 if (0 > (th - oy - oh)) ty = oy + th;
426 TTDBG("INIT (INTERPRETED)\n");
428 TTDBG("ADJUST (POINTER): tx=%d,ty=%d\n", tx, ty);
431 /* if we're offscreen, try to flip over the Y axis */
432 if (abs((tx + 2 * tw) - cw) < abs(tx))
435 else if ((tx > px) && (px > tw))
442 /* if we're offscreen, try to flip over the X axis */
443 if (abs((ty + 2 * th) - ch) < abs(ty))
446 else if ((ty > py) && (py > th))
451 TTDBG("ADJUST (FLIP): tx=%d,ty=%d\n", tx, ty);
452 if (inside_eventarea)
454 if ((tx == px) && ((tx + tw + tt->pad.x < cw) || (tx + tw > cw))) tx += tt->pad.x;
455 else if ((tx - tt->pad.x > 0) || (tx < 0)) tx -= tt->pad.x;
456 if ((ty == py) && ((ty + th + tt->pad.y < ch) || (ty + th > ch))) ty += tt->pad.y;
457 else if ((ty - tt->pad.y > 0) || (ty < 0)) ty -= tt->pad.y;
459 TTDBG("PAD: tx=%d,ty=%d\n", tx, ty);
460 if (tt->pad.bx * 2 + tw < cw)
462 if (tx < tt->pad.bx) tx = tt->pad.bx;
463 else if ((tx >= tw) && (tx + tt->pad.bx <= cw)) tx += tt->pad.bx;
464 else if (tx - tt->pad.bx >= 0) tx -= tt->pad.bx;
466 else if (tx < 0) tx -= tt->pad.bx;
467 else if (tx > cw) tx += tt->pad.bx;
468 if (tt->pad.by * 2 + th < ch)
470 if (ty < tt->pad.by) ty = tt->pad.by;
471 else if ((ty >= th) && (ty + tt->pad.by <= ch)) ty += tt->pad.by;
472 else if (ty - tt->pad.by >= 0) ty -= tt->pad.by;
474 else if (ty < 0) ty -= tt->pad.by;
475 else if (ty > ch) ty += tt->pad.by;
476 TTDBG("PAD (BORDER): tx=%d,ty=%d\n", tx, ty);
477 if (((tx < 0) && (tw < cw)) || ((ty < 0) && (th < ch)))
479 TTDBG("POSITIONING FAILED! THIS IS A BUG SOMEWHERE!\n");
483 evas_object_move(tt->tt_win ? : tt->tooltip, tx, ty);
484 evas_object_resize(tt->tt_win ? : tt->tooltip, tw, th);
485 TTDBG("FINAL: tx=%d,ty=%d,tw=%d,th=%d\n", tx, ty, tw, th);
486 evas_object_show(tt->tooltip);
488 if (inside_eventarea)
490 rel_x = (px - tx) / (double)tw;
491 rel_y = (py - ty) / (double)th;
495 rel_x = (ox + (ow / 2) - tx) / (double)tw;
496 rel_y = (oy + (oh / 2) - ty) / (double)th;
499 #define FDIF(a, b) (fabs((a) - (b)) > 0.0001)
500 if ((FDIF(rel_x, tt->rel_pos.x)) || (FDIF(rel_y, tt->rel_pos.y)))
502 Edje_Message_Float_Set *msg;
504 msg = alloca(sizeof(Edje_Message_Float_Set) + sizeof(double));
508 tt->rel_pos.x = rel_x;
509 tt->rel_pos.y = rel_y;
511 edje_object_message_send(tt->tooltip, EDJE_MESSAGE_FLOAT_SET, 1, msg);
517 _elm_tooltip_show_timer_stop(Elm_Tooltip *tt)
519 if (!tt->show_timer) return;
520 ecore_timer_del(tt->show_timer);
521 tt->show_timer = NULL;
525 _elm_tooltip_timer_show_cb(void *data)
527 Elm_Tooltip *tt = data;
528 tt->show_timer = NULL;
529 _elm_tooltip_show(tt);
530 return ECORE_CALLBACK_CANCEL;
534 _elm_tooltip_obj_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
536 Elm_Tooltip *tt = data;
538 _elm_tooltip_hide_anim_stop(tt);
540 if ((tt->show_timer) || (tt->tooltip)) return;
542 tt->show_timer = ecore_timer_add(_elm_config->tooltip_delay, _elm_tooltip_timer_show_cb, tt);
547 _elm_tooltip_obj_mouse_out_cb(Elm_Tooltip *tt, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Out *event __UNUSED__)
549 if (tt->visible_lock) return;
553 _elm_tooltip_show_timer_stop(tt);
556 _elm_tooltip_hide_anim_start(tt);
557 TTDBG("MOUSE OUT\n");
560 static void _elm_tooltip_obj_free_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
563 _elm_tooltip_unset(Elm_Tooltip *tt)
565 tt->visible_lock = EINA_FALSE;
566 _elm_tooltip_hide(tt);
567 _elm_tooltip_data_clean(tt);
571 evas_object_event_callback_del_full
572 (tt->eventarea, EVAS_CALLBACK_MOUSE_IN,
573 _elm_tooltip_obj_mouse_in_cb, tt);
574 evas_object_event_callback_del_full
575 (tt->eventarea, EVAS_CALLBACK_MOUSE_OUT,
576 (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
577 evas_object_event_callback_del_full
578 (tt->eventarea, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
580 evas_object_data_del(tt->eventarea, _tooltip_key);
584 evas_object_event_callback_del_full
585 (tt->owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
586 elm_widget_tooltip_del(tt->owner, tt);
589 eina_stringshare_del(tt->style);
594 _elm_tooltip_obj_free_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
596 Elm_Tooltip *tt = data;
597 if (tt->eventarea == obj) tt->eventarea = NULL;
598 if (tt->owner == obj) tt->owner = NULL;
599 _elm_tooltip_unset(tt);
603 _elm_tooltip_label_create(void *data, Evas_Object *obj __UNUSED__, Evas_Object *tooltip)
605 Evas_Object *label = elm_label_add(tooltip);
608 elm_object_style_set(label, "tooltip");
609 elm_object_text_set(label, data);
614 _elm_tooltip_trans_label_create(void *data, Evas_Object *obj __UNUSED__, Evas_Object *tooltip)
616 Evas_Object *label = elm_label_add(tooltip);
617 const char **text = data;
620 elm_object_style_set(label, "tooltip");
621 elm_object_domain_translatable_text_set(label, text[0], text[1]);
626 _elm_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
628 eina_stringshare_del(data);
632 _elm_tooltip_trans_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
634 const char **text = data;
635 eina_stringshare_del(text[0]);
636 eina_stringshare_del(text[1]);
641 _elm_tooltip_data_clean(Elm_Tooltip *tt)
643 if (tt->del_cb) tt->del_cb((void *)tt->data, tt->owner, NULL);
645 _elm_tooltip_content_del(tt);
652 * Notify tooltip should recalculate its theme.
656 elm_tooltip_theme(Elm_Tooltip *tt)
658 if (!tt->tooltip) return;
659 tt->changed_style = EINA_TRUE;
660 _elm_tooltip_reconfigure_job_start(tt);
665 * Set the content to be shown in the tooltip object for specific event area.
667 * Setup the tooltip to object. The object @a eventarea can have only
668 * one tooltip, so any previous tooltip data is removed. @p func(with
669 * @p data) will be called every time that need show the tooltip and
670 * it should return a valid Evas_Object. This object is then managed
671 * fully by tooltip system and is deleted when the tooltip is gone.
673 * This is an internal function that is used by objects with sub-items
674 * that want to provide different tooltips for each of them. The @a
675 * owner object should be an elm_widget and will be used to track
676 * theme changes and to feed @a func and @a del_cb. The @a eventarea
677 * may be any object and is the one that should be used later on with
678 * elm_object_tooltip apis, such as elm_object_tooltip_hide(),
679 * elm_object_tooltip_show() or elm_object_tooltip_unset().
681 * @param eventarea the object being attached a tooltip.
682 * @param owner the elm_widget that owns this object, will be used to
683 * track theme changes and to be used in @a func or @a del_cb.
684 * @param func the function used to create the tooltip contents. The
685 * @a Evas_Object parameters will receive @a owner as value.
686 * @param data what to provide to @a func as callback data/context.
687 * @param del_cb called when data is not needed anymore, either when
688 * another callback replaces @p func, the tooltip is unset with
689 * elm_object_tooltip_unset() or the owner object @a obj
690 * dies. This callback receives as the first parameter the
691 * given @a data, and @c event_info is NULL.
697 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)
699 Elm_Tooltip *tt = NULL;
700 Eina_Bool just_created;
702 EINA_SAFETY_ON_NULL_GOTO(owner, error);
703 EINA_SAFETY_ON_NULL_GOTO(eventarea, error);
707 elm_object_tooltip_unset(eventarea);
711 tt = evas_object_data_get(eventarea, _tooltip_key);
714 if (tt->owner != owner)
716 if (tt->owner != eventarea)
717 evas_object_event_callback_del_full
718 (tt->owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
720 elm_widget_tooltip_del(tt->owner, tt);
722 if (owner != eventarea)
723 evas_object_event_callback_add
724 (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
726 elm_widget_tooltip_add(tt->owner, tt);
729 if ((tt->func == func) && (tt->data == data) &&
730 (tt->del_cb == del_cb))
732 _elm_tooltip_data_clean(tt);
733 just_created = EINA_FALSE;
737 tt = ELM_NEW(Elm_Tooltip);
741 tt->eventarea = eventarea;
742 tt->evas = evas_object_evas_get(eventarea);
743 evas_object_data_set(eventarea, _tooltip_key, tt);
745 just_created = EINA_TRUE;
747 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN,
748 _elm_tooltip_obj_mouse_in_cb, tt);
749 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT,
750 (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
751 evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE,
752 _elm_tooltip_obj_free_cb, tt);
754 if (owner != eventarea)
755 evas_object_event_callback_add
756 (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
758 elm_widget_tooltip_add(tt->owner, tt);
765 if (!just_created) _elm_tooltip_reconfigure_job_start(tt);
769 if (del_cb) del_cb((void *)data, owner, NULL);
773 * Force show tooltip of object
775 * @param obj Target object
777 * Force show the tooltip and disable hide on mouse_out.
778 * If another content is set as tooltip, the visible tooltip will hididen and
779 * showed again with new content.
780 * This can force show more than one tooltip at a time.
785 elm_object_tooltip_show(Evas_Object *obj)
787 ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
788 tt->visible_lock = EINA_TRUE;
789 _elm_tooltip_show(tt);
793 * Force hide tooltip of object
795 * @param obj Target object
797 * Force hide the tooltip and (re)enable future mouse interations.
802 elm_object_tooltip_hide(Evas_Object *obj)
804 ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
805 tt->visible_lock = EINA_FALSE;
806 _elm_tooltip_hide_anim_start(tt);
810 * Set the text to be shown in the tooltip object
812 * @param obj Target object
813 * @param text The text to set in the content
815 * Setup the text as tooltip to object. The object can have only one tooltip,
816 * so any previous tooltip data is removed.
817 * This method call internaly the elm_tooltip_content_cb_set().
822 elm_object_tooltip_text_set(Evas_Object *obj, const char *text)
824 EINA_SAFETY_ON_NULL_RETURN(obj);
825 EINA_SAFETY_ON_NULL_RETURN(text);
827 text = eina_stringshare_add(text);
828 elm_object_tooltip_content_cb_set
829 (obj, _elm_tooltip_label_create, text, _elm_tooltip_label_del_cb);
835 elm_object_tooltip_domain_translatable_text_set(Evas_Object *obj, const char *domain, const char *text)
838 EINA_SAFETY_ON_NULL_RETURN(obj);
839 EINA_SAFETY_ON_NULL_RETURN(text);
841 data = malloc(2 * sizeof(char *));
843 data[0] = eina_stringshare_add(domain);
844 data[1] = eina_stringshare_add(text);
845 elm_object_tooltip_content_cb_set
846 (obj, _elm_tooltip_trans_label_create, data,
847 _elm_tooltip_trans_label_del_cb);
851 * Set the content to be shown in the tooltip object
853 * Setup the tooltip to object. The object can have only one tooltip,
854 * so any previous tooltip data is removed. @p func(with @p data) will
855 * be called every time that need show the tooltip and it should
856 * return a valid Evas_Object. This object is then managed fully by
857 * tooltip system and is deleted when the tooltip is gone.
859 * @param obj the object being attached a tooltip.
860 * @param func the function used to create the tooltip contents.
861 * @param data what to provide to @a func as callback data/context.
862 * @param del_cb called when data is not needed anymore, either when
863 * another callback replaces @p func, the tooltip is unset with
864 * elm_object_tooltip_unset() or the owner object @a obj
865 * dies. This callback receives as the first parameter the
866 * given @a data, and @c event_info is NULL.
871 elm_object_tooltip_content_cb_set(Evas_Object *obj, Elm_Tooltip_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
873 elm_object_sub_tooltip_content_cb_set(obj, obj, func, data, del_cb);
877 * Unset tooltip from object
879 * @param obj Target object
881 * Remove tooltip from object. The callback provided as del_cb to
882 * elm_object_tooltip_content_cb_set() will be called to notify it is
885 * @see elm_object_tooltip_content_cb_set()
890 elm_object_tooltip_unset(Evas_Object *obj)
892 ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
893 _elm_tooltip_unset(tt);
897 * Sets a different style for this object tooltip.
899 * @note before you set a style you should define a tooltip with
900 * elm_object_tooltip_content_cb_set() or
901 * elm_object_tooltip_text_set().
903 * @param obj an object with tooltip already set.
904 * @param style the theme style to use (default, transparent, ...)
907 elm_object_tooltip_style_set(Evas_Object *obj, const char *style)
909 ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
910 if (!eina_stringshare_replace(&tt->style, style)) return;
911 elm_tooltip_theme(tt);
915 * Get the style for this object tooltip.
917 * @param obj an object with tooltip already set.
918 * @return style the theme style in use, defaults to "default". If the
919 * object does not have a tooltip set, then NULL is returned.
922 elm_object_tooltip_style_get(const Evas_Object *obj)
924 ELM_TOOLTIP_GET_OR_RETURN(tt, obj, NULL);
925 return tt->style ? tt->style : "default";
929 * @brief Disable size restrictions on an object's tooltip
930 * @param obj The tooltip's anchor object
931 * @param disable If EINA_TRUE, size restrictions are disabled
932 * @return EINA_FALSE on failure, EINA_TRUE on success
934 * This function allows a tooltip to expand beyond its parent window's canvas.
935 * It will instead be limited only by the size of the display.
938 elm_object_tooltip_window_mode_set(Evas_Object *obj, Eina_Bool disable)
940 ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE);
941 return tt->free_size = disable;
945 * @brief Retrieve size restriction state of an object's tooltip
946 * @param obj The tooltip's anchor object
947 * @return If EINA_TRUE, size restrictions are disabled
949 * This function returns whether a tooltip is allowed to expand beyond
950 * its parent window's canvas.
951 * It will instead be limited only by the size of the display.
954 elm_object_tooltip_window_mode_get(const Evas_Object *obj)
956 ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE);
957 return tt->free_size;