fef3f8d3071c08e4442b6e67636fd2cd510cf9b6
[framework/uifw/elementary.git] / src / lib / els_tooltip.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 static const char _tooltip_key[] = "_elm_tooltip";
5
6 #define ELM_TOOLTIP_GET_OR_RETURN(tt, obj, ...)         \
7   Elm_Tooltip *tt;                                      \
8   do                                                    \
9     {                                                   \
10        if (!(obj))                                      \
11          {                                              \
12             CRITICAL("Null pointer: " #obj);            \
13             return __VA_ARGS__;                         \
14          }                                              \
15        tt = evas_object_data_get((obj), _tooltip_key);  \
16        if (!tt)                                         \
17          {                                              \
18             ERR("Object does not have tooltip: " #obj); \
19             return __VA_ARGS__;                         \
20          }                                              \
21     }                                                   \
22   while (0)
23
24 struct _Elm_Tooltip
25 {
26    Elm_Tooltip_Content_Cb   func;
27    Evas_Smart_Cb            del_cb;
28    const void              *data;
29    const char              *style;
30    Evas                    *evas, *tt_evas;
31    Evas_Object             *eventarea, *owner;
32    Evas_Object             *tooltip, *content;
33    Evas_Object             *tt_win;
34    Ecore_Timer             *show_timer;
35    Ecore_Timer             *hide_timer;
36    Ecore_Job               *reconfigure_job;
37    struct {
38       Evas_Coord            x, y, bx, by;
39    } pad;
40    struct {
41       double                x, y;
42    } rel_pos;
43    double                   hide_timeout; /* from theme */
44    Eina_Bool                visible_lock:1;
45    Eina_Bool                changed_style:1;
46    Eina_Bool                free_size : 1;
47 };
48
49 static void _elm_tooltip_reconfigure(Elm_Tooltip *tt);
50 static void _elm_tooltip_reconfigure_job_start(Elm_Tooltip *tt);
51 static void _elm_tooltip_reconfigure_job_stop(Elm_Tooltip *tt);
52 static void _elm_tooltip_hide_anim_start(Elm_Tooltip *tt);
53 static void _elm_tooltip_hide_anim_stop(Elm_Tooltip *tt);
54 static void _elm_tooltip_show_timer_stop(Elm_Tooltip *tt);
55 static void _elm_tooltip_hide(Elm_Tooltip *tt);
56 static void _elm_tooltip_data_clean(Elm_Tooltip *tt);
57
58 static void
59 _elm_tooltip_content_changed_hints_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
60 {
61    _elm_tooltip_reconfigure_job_start(data);
62 }
63
64 static void
65 _elm_tooltip_content_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
66 {
67    Elm_Tooltip *tt = data;
68    tt->content = NULL;
69    tt->visible_lock = EINA_FALSE;
70    if (tt->tooltip) _elm_tooltip_hide(tt);
71 }
72
73 static void
74 _elm_tooltip_obj_move_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
75 {
76    Elm_Tooltip *tt = data;
77    _elm_tooltip_reconfigure_job_start(tt);
78 }
79
80 static void
81 _elm_tooltip_obj_resize_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
82 {
83    Elm_Tooltip *tt = data;
84    _elm_tooltip_reconfigure_job_start(tt);
85 }
86
87 static void
88 _elm_tooltip_obj_mouse_move_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
89 {
90    Elm_Tooltip *tt = data;
91    _elm_tooltip_reconfigure_job_start(tt);
92 }
93
94 static void
95 _elm_tooltip_show(Elm_Tooltip *tt)
96 {
97    _elm_tooltip_show_timer_stop(tt);
98    _elm_tooltip_hide_anim_stop(tt);
99
100    if (tt->tooltip)
101      {
102         _elm_tooltip_reconfigure_job_start(tt);
103         return;
104      }
105    if (tt->free_size)
106      {
107         tt->tt_win = elm_win_add(NULL, "tooltip", ELM_WIN_BASIC);
108         elm_win_borderless_set(tt->tt_win, EINA_TRUE);
109         elm_win_override_set(tt->tt_win, EINA_TRUE);
110         tt->tt_evas = evas_object_evas_get(tt->tt_win);
111         tt->tooltip = edje_object_add(tt->tt_evas);
112         evas_object_move(tt->tooltip, 0, 0);
113         elm_win_resize_object_add(tt->tt_win, tt->tooltip);
114 #ifdef HAVE_ELEMENTARY_X
115         ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(tt->tt_win), 0, 0, 0, 0);
116 #endif
117         evas_object_show(tt->tt_win);
118      }
119    else
120       tt->tooltip = edje_object_add(tt->evas);
121    if (!tt->tooltip) return;
122
123    evas_object_layer_set(tt->tt_win ?: tt->tooltip, ELM_OBJECT_LAYER_TOOLTIP);
124
125    evas_object_event_callback_add
126      (tt->eventarea, EVAS_CALLBACK_MOVE, _elm_tooltip_obj_move_cb, tt);
127    evas_object_event_callback_add
128      (tt->eventarea, EVAS_CALLBACK_RESIZE, _elm_tooltip_obj_resize_cb, tt);
129    evas_object_event_callback_add
130      (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, _elm_tooltip_obj_mouse_move_cb, tt);
131
132    tt->changed_style = EINA_TRUE;
133    _elm_tooltip_reconfigure_job_start(tt);
134 }
135
136 static void
137 _elm_tooltip_content_del(Elm_Tooltip *tt)
138 {
139    if (!tt->content) return;
140
141    evas_object_event_callback_del_full
142      (tt->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
143       _elm_tooltip_content_changed_hints_cb, tt);
144    evas_object_event_callback_del_full
145      (tt->content, EVAS_CALLBACK_DEL,
146       _elm_tooltip_content_del_cb, tt);
147    evas_object_hide(tt->content);
148    evas_object_del(tt->content);
149    tt->content = NULL;
150 }
151
152
153 static void
154 _elm_tooltip_hide(Elm_Tooltip *tt)
155 {
156    Evas_Object *del;
157    _elm_tooltip_show_timer_stop(tt);
158    _elm_tooltip_hide_anim_stop(tt);
159    _elm_tooltip_reconfigure_job_stop(tt);
160
161    if (!tt->tooltip) return;
162    if (tt->visible_lock) return;
163
164    _elm_tooltip_content_del(tt);
165
166    evas_object_event_callback_del_full
167      (tt->eventarea, EVAS_CALLBACK_MOVE, _elm_tooltip_obj_move_cb, tt);
168    evas_object_event_callback_del_full
169      (tt->eventarea, EVAS_CALLBACK_RESIZE, _elm_tooltip_obj_resize_cb, tt);
170    evas_object_event_callback_del_full
171      (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, _elm_tooltip_obj_mouse_move_cb, tt);
172
173    del = tt->tt_win ?: tt->tooltip;
174
175    tt->tt_win = NULL;
176    tt->tt_evas = NULL;
177    tt->tooltip = NULL;
178    evas_object_del(del);
179 }
180
181 static void
182 _elm_tooltip_reconfigure_job(void *data)
183 {
184    Elm_Tooltip *tt = data;
185    tt->reconfigure_job = NULL;
186    _elm_tooltip_reconfigure(data);
187 }
188
189 static void
190 _elm_tooltip_reconfigure_job_stop(Elm_Tooltip *tt)
191 {
192    if (!tt->reconfigure_job) return;
193    ecore_job_del(tt->reconfigure_job);
194    tt->reconfigure_job = NULL;
195 }
196
197 static void
198 _elm_tooltip_reconfigure_job_start(Elm_Tooltip *tt)
199 {
200    if (!tt->reconfigure_job)
201      tt->reconfigure_job = ecore_job_add(_elm_tooltip_reconfigure_job, tt);
202 }
203
204 static Eina_Bool
205 _elm_tooltip_hide_anim_cb(void *data)
206 {
207    Elm_Tooltip *tt = data;
208    tt->hide_timer = NULL;
209    _elm_tooltip_hide(tt);
210    return EINA_FALSE;
211 }
212
213 static void
214 _elm_tooltip_hide_anim_start(Elm_Tooltip *tt)
215 {
216    double extra = 0;
217    if (tt->hide_timer) return;
218    /* hide slightly faster when in window mode to look less stupid */
219    if ((tt->hide_timeout > 0) && tt->tt_win) extra = 0.1;
220    edje_object_signal_emit(tt->tooltip, "elm,action,hide", "elm");
221    tt->hide_timer = ecore_timer_add
222      (tt->hide_timeout - extra, _elm_tooltip_hide_anim_cb, tt);
223 }
224
225 static void
226 _elm_tooltip_hide_anim_stop(Elm_Tooltip *tt)
227 {
228    if (!tt->hide_timer) return;
229    if (tt->tooltip)
230      edje_object_signal_emit(tt->tooltip, "elm,action,show", "elm");
231    ecore_timer_del(tt->hide_timer);
232    tt->hide_timer = NULL;
233 }
234
235 static void
236 _elm_tooltip_reconfigure(Elm_Tooltip *tt)
237 {
238    Evas_Coord ox, oy, ow, oh, px, py, tx, ty, tw, th, cw = 0, ch = 0;
239    Evas_Coord eminw, eminh, ominw, ominh;
240    double rel_x, rel_y;
241    Eina_Bool inside_eventarea;
242 #ifdef HAVE_ELEMENTARY_X
243    Ecore_X_Window xwin = 0;
244 #endif
245
246    _elm_tooltip_reconfigure_job_stop(tt);
247
248    if (tt->hide_timer) return;
249    if (!tt->tooltip) return;
250    if (tt->changed_style)
251      {
252         const char *style = tt->style ? tt->style : "default";
253         const char *str;
254         if (!_elm_theme_object_set(tt->tt_win ? NULL : tt->owner, tt->tooltip, "tooltip", "base", style))
255           {
256              ERR("Could not apply the theme to the tooltip! style=%s", style);
257              if (tt->tt_win) evas_object_del(tt->tt_win);
258              else evas_object_del(tt->tooltip);
259              tt->tt_win = NULL;
260              tt->tt_evas = NULL;
261              tt->tooltip = NULL;
262              return;
263           }
264
265         tt->rel_pos.x = 0;
266         tt->rel_pos.y = 0;
267
268         tt->pad.x = 0;
269         tt->pad.y = 0;
270         tt->pad.bx = 0;
271         tt->pad.by = 0;
272         tt->hide_timeout = 0.0;
273
274         str = edje_object_data_get(tt->tooltip, "transparent");
275         if (tt->tt_win)
276           {  /* FIXME: hardcoded here is bad */
277              if (str && (!strcmp(str, "enabled")))
278                {
279                   elm_win_alpha_set(tt->tt_win, EINA_TRUE);
280                   elm_win_transparent_set(tt->tt_win, EINA_TRUE);
281                }
282              else
283                {
284                   elm_win_alpha_set(tt->tt_win, EINA_FALSE);
285                   elm_win_transparent_set(tt->tt_win, EINA_FALSE);
286                }
287           }
288
289         str = edje_object_data_get(tt->tooltip, "pad_x");
290         if (str) tt->pad.x = atoi(str);
291         str = edje_object_data_get(tt->tooltip, "pad_y");
292         if (str) tt->pad.y = atoi(str);
293
294         str = edje_object_data_get(tt->tooltip, "pad_border_x");
295         if (str) tt->pad.bx = atoi(str);
296         str = edje_object_data_get(tt->tooltip, "pad_border_y");
297         if (str) tt->pad.by = atoi(str);
298
299         str = edje_object_data_get(tt->tooltip, "hide_timeout");
300         if (str)
301           {
302              tt->hide_timeout = atof(str);
303              if (tt->hide_timeout < 0.0) tt->hide_timeout = 0.0;
304           }
305
306         evas_object_pass_events_set(tt->tooltip, EINA_TRUE);
307         tt->changed_style = EINA_FALSE;
308         if (tt->tooltip)
309           edje_object_part_swallow(tt->tooltip, "elm.swallow.content",
310                                    tt->content);
311
312         edje_object_signal_emit(tt->tooltip, "elm,action,show", "elm");
313      }
314
315    if (!tt->content)
316      {
317         tt->content = tt->func((void *)tt->data, tt->owner, tt->tt_win ? : tt->owner);
318         if (!tt->content)
319           {
320              WRN("could not create tooltip content!");
321              if (tt->tt_win) evas_object_del(tt->tt_win);
322              else evas_object_del(tt->tooltip);
323
324              tt->tt_win = NULL;
325              tt->tt_evas = NULL;
326              tt->tooltip = NULL;
327              return;
328           }
329         evas_object_show(tt->content);
330         evas_object_layer_set(tt->content, ELM_OBJECT_LAYER_TOOLTIP);
331         evas_object_pass_events_set(tt->content, EINA_TRUE);
332         edje_object_part_swallow
333           (tt->tooltip, "elm.swallow.content", tt->content);
334         evas_object_event_callback_add(tt->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
335            _elm_tooltip_content_changed_hints_cb, tt);
336         evas_object_event_callback_add(tt->content, EVAS_CALLBACK_DEL,
337            _elm_tooltip_content_del_cb, tt);
338
339      }
340
341    evas_object_size_hint_min_get(tt->content, &ominw, &ominh);
342    edje_object_size_min_get(tt->tooltip, &eminw, &eminh);
343
344    if (eminw && (ominw < eminw)) ominw = eminw;
345    if (eminw && (ominh < eminh)) ominh = eminh;
346
347    if (ominw < 1) ominw = 10; /* at least it is noticeable */
348    if (ominh < 1) ominh = 10; /* at least it is noticeable */
349
350    edje_object_size_min_restricted_calc(tt->tooltip, &tw, &th, ominw, ominh);
351
352 #ifdef HAVE_ELEMENTARY_X
353    if (tt->tt_win)
354      {
355         xwin = elm_win_xwindow_get(elm_object_top_widget_get(tt->owner));
356         if (xwin)
357           {
358              xwin = ecore_x_window_root_get(xwin);
359              ecore_x_randr_screen_current_size_get(xwin, &cw, &ch, NULL, NULL);
360           }
361      }
362    if (!cw)
363 #endif
364      evas_output_size_get(tt->tt_evas ?: tt->evas, &cw, &ch);
365
366    evas_object_geometry_get(tt->eventarea, &ox, &oy, &ow, &oh);
367
368    if (tt->tt_win)
369      {
370         int x, y;
371 #ifdef HAVE_ELEMENTARY_X
372         ecore_x_pointer_xy_get(xwin, &px, &py);
373 #endif
374         elm_win_screen_position_get(elm_object_top_widget_get(tt->owner), &x, &y);
375         ox += x;
376         oy += y;
377      }
378    else
379      evas_pointer_canvas_xy_get(tt->evas, &px, &py);
380
381    inside_eventarea = ((px >= ox) && (py >= oy) &&
382                        (px <= ox + ow) && (py <= oy + oh));
383    if (inside_eventarea)
384      {
385         tx = px - tw;
386         ty = py - th;
387      }
388    else
389      {
390         tx = ox + (ow / 2) - (tw / 2);
391         if (0 > (th - oy - oh)) ty = oy + th;
392         else ty = oy - oh;
393      }
394
395    if (tx < 0)
396      {
397         if (abs((tx + 2 * tw) - cw) < abs(tx))
398           tx += tw;
399      }
400    else if ((tx > px) && (px > tx))
401      {
402         if (tx + tw < cw)
403           tx += tw;
404      }
405    if (ty < 0)
406      {
407         if (abs((ty + 2 * th) - ch) < abs(ty))
408           ty += th;
409      }
410    else if ((ty > py) && (py > ty))
411      {
412         if (ty + th < ch)
413           ty += th;
414      }
415    if (inside_eventarea)
416      {
417         if ((tx == px) && ((tx + tw + tt->pad.x < cw) || (tx + tw > cw))) tx += tt->pad.x;
418         else if ((tx - tt->pad.x > 0) || (tx < 0)) tx -= tt->pad.x;
419         if ((ty == py) && ((ty + th + tt->pad.y < ch) || (ty + th > ch))) ty += tt->pad.y;
420         else if ((ty - tt->pad.y > 0) || (ty < 0)) ty -= tt->pad.y;
421      }
422    if (tt->pad.bx * 2 + tw < cw)
423      {
424         if (tx < tt->pad.bx) tx = tt->pad.bx;
425         else if ((tx >= tw) && (tx + tt->pad.bx <= cw)) tx += tt->pad.bx;
426         else if (tx - tt->pad.bx >= 0) tx -= tt->pad.bx;
427      }
428    else if (tx < 0) tx -= tt->pad.bx;
429    else if (tx > cw) tx += tt->pad.bx;
430
431    if (tt->pad.by * 2 + th < ch)
432      {
433         if (ty < tt->pad.by) ty = tt->pad.by;
434         else if ((ty >= th) && (ty + tt->pad.by <= ch)) ty += tt->pad.by;
435         else if (ty - tt->pad.by >= 0) ty -= tt->pad.by;
436      }
437    else if (ty < 0) ty -= tt->pad.by;
438    else if (ty > ch) ty += tt->pad.by;
439
440    evas_object_move(tt->tt_win ? : tt->tooltip, tx, ty);
441    evas_object_resize(tt->tt_win ? : tt->tooltip, tw, th);
442    evas_object_show(tt->tooltip);
443
444    if (inside_eventarea)
445      {
446         rel_x = (px - tx) / (double)tw;
447         rel_y = (py - ty) / (double)th;
448      }
449    else
450      {
451         rel_x = (ox + (ow / 2) - tx) / (double)tw;
452         rel_y = (oy + (oh / 2) - ty) / (double)th;
453      }
454
455 #define FDIF(a, b) (fabs((a) - (b)) > 0.0001)
456    if ((FDIF(rel_x, tt->rel_pos.x)) || (FDIF(rel_y, tt->rel_pos.y)))
457      {
458         Edje_Message_Float_Set *msg;
459
460         msg = alloca(sizeof(Edje_Message_Float_Set) + sizeof(double));
461         msg->count = 2;
462         msg->val[0] = rel_x;
463         msg->val[1] = rel_y;
464         tt->rel_pos.x = rel_x;
465         tt->rel_pos.y = rel_y;
466
467         edje_object_message_send(tt->tooltip, EDJE_MESSAGE_FLOAT_SET, 1, msg);
468      }
469 #undef FDIF
470 }
471
472 static void
473 _elm_tooltip_show_timer_stop(Elm_Tooltip *tt)
474 {
475    if (!tt->show_timer) return;
476    ecore_timer_del(tt->show_timer);
477    tt->show_timer = NULL;
478 }
479
480 static Eina_Bool
481 _elm_tooltip_timer_show_cb(void *data)
482 {
483    Elm_Tooltip *tt = data;
484    tt->show_timer = NULL;
485    _elm_tooltip_show(tt);
486    return ECORE_CALLBACK_CANCEL;
487 }
488
489 static void
490 _elm_tooltip_obj_mouse_in_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
491 {
492    Elm_Tooltip *tt = data;
493
494    _elm_tooltip_hide_anim_stop(tt);
495
496    if ((tt->show_timer) || (tt->tooltip)) return;
497
498    tt->show_timer = ecore_timer_add
499      (_elm_config->tooltip_delay, _elm_tooltip_timer_show_cb, tt);
500 }
501
502 static void
503 _elm_tooltip_obj_mouse_out_cb(Elm_Tooltip *tt, Evas *e  __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Out *event __UNUSED__)
504 {
505    if (tt->visible_lock) return;
506
507    if (!tt->tooltip)
508      {
509         _elm_tooltip_show_timer_stop(tt);
510         return;
511      }
512    _elm_tooltip_hide_anim_start(tt);
513 }
514
515 static void _elm_tooltip_obj_free_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj, void *event_info  __UNUSED__);
516
517 static void
518 _elm_tooltip_unset(Elm_Tooltip *tt)
519 {
520    tt->visible_lock = EINA_FALSE;
521    _elm_tooltip_hide(tt);
522    _elm_tooltip_data_clean(tt);
523
524    if (tt->eventarea)
525      {
526         evas_object_event_callback_del_full
527           (tt->eventarea, EVAS_CALLBACK_MOUSE_IN,
528            _elm_tooltip_obj_mouse_in_cb, tt);
529         evas_object_event_callback_del_full
530           (tt->eventarea, EVAS_CALLBACK_MOUSE_OUT,
531            (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
532         evas_object_event_callback_del_full
533           (tt->eventarea, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
534
535         evas_object_data_del(tt->eventarea, _tooltip_key);
536      }
537    if (tt->owner)
538      {
539         evas_object_event_callback_del_full
540           (tt->owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
541         elm_widget_tooltip_del(tt->owner, tt);
542      }
543
544    eina_stringshare_del(tt->style);
545    free(tt);
546 }
547
548 static void
549 _elm_tooltip_obj_free_cb(void *data, Evas *e  __UNUSED__, Evas_Object *obj, void *event_info  __UNUSED__)
550 {
551    Elm_Tooltip *tt = data;
552    if (tt->eventarea == obj) tt->eventarea = NULL;
553    if (tt->owner == obj) tt->owner = NULL;
554    _elm_tooltip_unset(tt);
555 }
556
557 static Evas_Object *
558 _elm_tooltip_label_create(void *data, Evas_Object *obj __UNUSED__, Evas_Object *tooltip)
559 {
560    Evas_Object *label = elm_label_add(tooltip);
561    if (!label)
562      return NULL;
563    elm_object_style_set(label, "tooltip");
564    elm_object_text_set(label, data);
565    return label;
566 }
567
568 static void
569 _elm_tooltip_label_del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
570 {
571    eina_stringshare_del(data);
572 }
573
574 static void
575 _elm_tooltip_data_clean(Elm_Tooltip *tt)
576 {
577    if (tt->del_cb) tt->del_cb((void *)tt->data, tt->owner, NULL);
578
579    _elm_tooltip_content_del(tt);
580
581    tt->data = NULL;
582    tt->del_cb = NULL;
583 }
584
585 /**
586  * Notify tooltip should recalculate its theme.
587  * @internal
588  */
589 void
590 elm_tooltip_theme(Elm_Tooltip *tt)
591 {
592    if (!tt->tooltip) return;
593    tt->changed_style = EINA_TRUE;
594    _elm_tooltip_reconfigure_job_start(tt);
595 }
596
597
598 /**
599  * Set the content to be shown in the tooltip object for specific event area.
600  *
601  * Setup the tooltip to object. The object @a eventarea can have only
602  * one tooltip, so any previous tooltip data is removed. @p func(with
603  * @p data) will be called every time that need show the tooltip and
604  * it should return a valid Evas_Object. This object is then managed
605  * fully by tooltip system and is deleted when the tooltip is gone.
606  *
607  * This is an internal function that is used by objects with sub-items
608  * that want to provide different tooltips for each of them. The @a
609  * owner object should be an elm_widget and will be used to track
610  * theme changes and to feed @a func and @a del_cb. The @a eventarea
611  * may be any object and is the one that should be used later on with
612  * elm_object_tooltip apis, such as elm_object_tooltip_hide(),
613  * elm_object_tooltip_show() or elm_object_tooltip_unset().
614  *
615  * @param eventarea the object being attached a tooltip.
616  * @param owner the elm_widget that owns this object, will be used to
617  *        track theme changes and to be used in @a func or @a del_cb.
618  * @param func the function used to create the tooltip contents. The
619  *        @a Evas_Object parameters will receive @a owner as value.
620  * @param data what to provide to @a func as callback data/context.
621  * @param del_cb called when data is not needed anymore, either when
622  *        another callback replaces @p func, the tooltip is unset with
623  *        elm_object_tooltip_unset() or the owner object @a obj
624  *        dies. This callback receives as the first parameter the
625  *        given @a data, and @c event_info is NULL.
626  *
627  * @internal
628  * @ingroup Tooltips
629  */
630 void
631 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)
632 {
633    Elm_Tooltip *tt = NULL;
634    Eina_Bool just_created;
635
636    EINA_SAFETY_ON_NULL_GOTO(owner, error);
637    EINA_SAFETY_ON_NULL_GOTO(eventarea, error);
638
639    if (!func)
640      {
641         elm_object_tooltip_unset(eventarea);
642         return;
643      }
644
645    tt = evas_object_data_get(eventarea, _tooltip_key);
646    if (tt)
647      {
648         if (tt->owner != owner)
649           {
650              if (tt->owner != eventarea)
651                evas_object_event_callback_del_full
652                  (tt->owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
653
654              elm_widget_tooltip_del(tt->owner, tt);
655
656              if (owner != eventarea)
657                evas_object_event_callback_add
658                  (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
659
660              elm_widget_tooltip_add(tt->owner, tt);
661           }
662
663         if ((tt->func == func) && (tt->data == data) &&
664             (tt->del_cb == del_cb))
665           return;
666         _elm_tooltip_data_clean(tt);
667         just_created = EINA_FALSE;
668      }
669    else
670      {
671         tt = ELM_NEW(Elm_Tooltip);
672         if (!tt) goto error;
673
674         tt->owner = owner;
675         tt->eventarea = eventarea;
676         tt->evas = evas_object_evas_get(eventarea);
677         evas_object_data_set(eventarea, _tooltip_key, tt);
678
679         just_created = EINA_TRUE;
680
681         evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_IN,
682            _elm_tooltip_obj_mouse_in_cb, tt);
683         evas_object_event_callback_add(eventarea, EVAS_CALLBACK_MOUSE_OUT,
684            (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_out_cb, tt);
685         evas_object_event_callback_add(eventarea, EVAS_CALLBACK_FREE,
686            _elm_tooltip_obj_free_cb, tt);
687
688         if (owner != eventarea)
689           evas_object_event_callback_add
690             (owner, EVAS_CALLBACK_FREE, _elm_tooltip_obj_free_cb, tt);
691
692         elm_widget_tooltip_add(tt->owner, tt);
693      }
694
695    tt->func = func;
696    tt->data = data;
697    tt->del_cb = del_cb;
698
699    if (!just_created) _elm_tooltip_reconfigure_job_start(tt);
700    return;
701
702  error:
703    if (del_cb) del_cb((void *)data, owner, NULL);
704 }
705
706 /**
707  * Force show tooltip of object
708  *
709  * @param obj Target object
710  *
711  * Force show the tooltip and disable hide on mouse_out.
712  * If another content is set as tooltip, the visible tooltip will hididen and
713  * showed again with new content.
714  * This can force show more than one tooltip at a time.
715  *
716  * @ingroup Tooltips
717  */
718 EAPI void
719 elm_object_tooltip_show(Evas_Object *obj)
720 {
721    ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
722    tt->visible_lock = EINA_TRUE;
723    _elm_tooltip_show(tt);
724 }
725
726 /**
727  * Force hide tooltip of object
728  *
729  * @param obj Target object
730  *
731  * Force hide the tooltip and (re)enable future mouse interations.
732  *
733  * @ingroup Tooltips
734  */
735 EAPI void
736 elm_object_tooltip_hide(Evas_Object *obj)
737 {
738    ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
739    tt->visible_lock = EINA_FALSE;
740    _elm_tooltip_hide_anim_start(tt);
741 }
742
743 /**
744  * Set the text to be shown in the tooltip object
745  *
746  * @param obj Target object
747  * @param text The text to set in the content
748  *
749  * Setup the text as tooltip to object. The object can have only one tooltip,
750  * so any previous tooltip data is removed.
751  * This method call internaly the elm_tooltip_content_cb_set().
752  *
753  * @ingroup Tooltips
754  */
755 EAPI void
756 elm_object_tooltip_text_set(Evas_Object *obj, const char *text)
757 {
758    EINA_SAFETY_ON_NULL_RETURN(obj);
759    EINA_SAFETY_ON_NULL_RETURN(text);
760
761    text = eina_stringshare_add(text);
762    elm_object_tooltip_content_cb_set
763      (obj, _elm_tooltip_label_create, text, _elm_tooltip_label_del_cb);
764 }
765
766 /**
767  * Set the content to be shown in the tooltip object
768  *
769  * Setup the tooltip to object. The object can have only one tooltip,
770  * so any previous tooltip data is removed. @p func(with @p data) will
771  * be called every time that need show the tooltip and it should
772  * return a valid Evas_Object. This object is then managed fully by
773  * tooltip system and is deleted when the tooltip is gone.
774  *
775  * @param obj the object being attached a tooltip.
776  * @param func the function used to create the tooltip contents.
777  * @param data what to provide to @a func as callback data/context.
778  * @param del_cb called when data is not needed anymore, either when
779  *        another callback replaces @p func, the tooltip is unset with
780  *        elm_object_tooltip_unset() or the owner object @a obj
781  *        dies. This callback receives as the first parameter the
782  *        given @a data, and @c event_info is NULL.
783  *
784  * @ingroup Tooltips
785  */
786 EAPI void
787 elm_object_tooltip_content_cb_set(Evas_Object *obj, Elm_Tooltip_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
788 {
789    elm_object_sub_tooltip_content_cb_set(obj, obj, func, data, del_cb);
790 }
791
792 /**
793  * Unset tooltip from object
794  *
795  * @param obj Target object
796  *
797  * Remove tooltip from object. The callback provided as del_cb to
798  * elm_object_tooltip_content_cb_set() will be called to notify it is
799  * not used anymore.
800  *
801  * @see elm_object_tooltip_content_cb_set()
802  *
803  * @ingroup Tooltips
804  */
805 EAPI void
806 elm_object_tooltip_unset(Evas_Object *obj)
807 {
808    ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
809    _elm_tooltip_unset(tt);
810 }
811
812 /**
813  * Sets a different style for this object tooltip.
814  *
815  * @note before you set a style you should define a tooltip with
816  *       elm_object_tooltip_content_cb_set() or
817  *       elm_object_tooltip_text_set().
818  *
819  * @param obj an object with tooltip already set.
820  * @param style the theme style to use (default, transparent, ...)
821  */
822 EAPI void
823 elm_object_tooltip_style_set(Evas_Object *obj, const char *style)
824 {
825    ELM_TOOLTIP_GET_OR_RETURN(tt, obj);
826    if (!eina_stringshare_replace(&tt->style, style)) return;
827    elm_tooltip_theme(tt);
828 }
829
830 /**
831  * Get the style for this object tooltip.
832  *
833  * @param obj an object with tooltip already set.
834  * @return style the theme style in use, defaults to "default". If the
835  *         object does not have a tooltip set, then NULL is returned.
836  */
837 EAPI const char *
838 elm_object_tooltip_style_get(const Evas_Object *obj)
839 {
840    ELM_TOOLTIP_GET_OR_RETURN(tt, obj, NULL);
841    return tt->style ? tt->style : "default";
842 }
843
844 /**
845  * Get the configured tooltip delay
846  *
847  * This gets the globally configured tooltip delay in seconds
848  *
849  * @return The tooltip delay
850  * @ingroup Tooltips
851  */
852 EAPI double
853 elm_tooltip_delay_get(void)
854 {
855    return _elm_config->tooltip_delay;
856 }
857
858 /**
859  * Set the configured tooltip delay
860  *
861  * This sets the globally configured delay to tooltip
862  *
863  * @param delay The delay to show the tooltip
864  * @return EINA_TRUE if value is valid and setted
865  * @ingroup Tooltips
866  */
867 EAPI Eina_Bool
868 elm_tooltip_delay_set(double delay)
869 {
870    if (delay < 0.0) return EINA_FALSE;
871    _elm_config->tooltip_delay = delay;
872    return EINA_TRUE;
873 }
874
875 /**
876  * @brief Disable size restrictions on an object's tooltip
877  * @param obj The tooltip's anchor object
878  * @param disable If EINA_TRUE, size restrictions are disabled
879  * @return EINA_FALSE on failure, EINA_TRUE on success
880  *
881  * This function allows a tooltip to expand beyond its parant window's canvas.
882  * It will instead be limited only by the size of the display.
883  */
884 EAPI Eina_Bool
885 elm_tooltip_size_restrict_disable(Evas_Object *obj, Eina_Bool disable)
886 {
887    ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE);
888    return tt->free_size = disable;
889 }
890
891 /**
892  * @brief Retrieve size restriction state of an object's tooltip
893  * @param obj The tooltip's anchor object
894  * @return If EINA_TRUE, size restrictions are disabled
895  *
896  * This function returns whether a tooltip is allowed to expand beyond
897  * its parant window's canvas.
898  * It will instead be limited only by the size of the display.
899  */
900 EAPI Eina_Bool
901 elm_tooltip_size_restrict_disabled_get(const Evas_Object *obj)
902 {
903    ELM_TOOLTIP_GET_OR_RETURN(tt, obj, EINA_FALSE);
904    return tt->free_size;
905 }