1 #include <Elementary.h>
6 * @defgroup Notify Notify
8 * Display a window in a particular region of the application (top,
9 * bottom, etc. A timeout can be set to automatically close the
10 * window. This is so that, after an evas_object_show() on a notify
11 * object, if a timeout was set on it, it will <b>automatically</b>
12 * get hidden after that time.
14 * Signals that you can add callbacks for are:
16 * "timeout" - when timeout happens on notify and it's hidden
17 * "block,clicked" - when it's hidden by a click outside of the notify's view
20 typedef struct _Widget_Data Widget_Data;
24 Evas_Object *notify, *content, *parent;
26 Elm_Notify_Orient orient;
27 Eina_Bool repeat_events;
28 Evas_Object *block_events;
34 static const char *widtype = NULL;
35 static void _del_hook(Evas_Object *obj);
36 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
37 static void _theme_hook(Evas_Object *obj);
38 static void _sizing_eval(Evas_Object *obj);
39 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
40 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
41 static void _signal_block_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
42 static void _calc(Evas_Object *obj);
43 static void _content_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
44 static void _show(void *data, Evas *e, Evas_Object *obj, void *event_info);
45 static void _hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
46 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _parent_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
49 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
50 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
52 static const char SIG_BLOCK_CLICKED[] = "block,clicked";
53 static const char SIG_TIMEOUT[] = "timeout";
54 static const Evas_Smart_Cb_Description _signals[] = {
55 {SIG_BLOCK_CLICKED, ""},
61 _del_pre_hook(Evas_Object *obj)
63 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
64 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE, _resize, obj);
65 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_SHOW, _show, obj);
66 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_HIDE, _hide, obj);
67 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
71 _del_hook(Evas_Object *obj)
73 Widget_Data *wd = elm_widget_data_get(obj);
75 elm_notify_parent_set(obj, NULL);
76 elm_notify_repeat_events_set(obj, EINA_TRUE);
79 ecore_timer_del(wd->timer);
86 * Return Notification orientation with RTL
88 * This function switches-sides of notification area when in RTL mode.
90 * @param obj notification object.
92 * @param orient Original notification orientation.
94 * @return notification orientation with respect to the object RTL mode.
98 static Elm_Notify_Orient
99 _notify_orientation_with_rtl(Evas_Object *obj, Elm_Notify_Orient orient)
101 if (elm_widget_mirrored_get(obj))
105 case ELM_NOTIFY_ORIENT_LEFT:
106 orient = ELM_NOTIFY_ORIENT_RIGHT;
108 case ELM_NOTIFY_ORIENT_RIGHT:
109 orient = ELM_NOTIFY_ORIENT_LEFT;
111 case ELM_NOTIFY_ORIENT_TOP_LEFT:
112 orient = ELM_NOTIFY_ORIENT_TOP_RIGHT;
114 case ELM_NOTIFY_ORIENT_TOP_RIGHT:
115 orient = ELM_NOTIFY_ORIENT_TOP_LEFT;
117 case ELM_NOTIFY_ORIENT_BOTTOM_LEFT:
118 orient = ELM_NOTIFY_ORIENT_BOTTOM_RIGHT;
120 case ELM_NOTIFY_ORIENT_BOTTOM_RIGHT:
121 orient = ELM_NOTIFY_ORIENT_BOTTOM_LEFT;
132 _notify_theme_apply(Evas_Object *obj)
134 Widget_Data *wd = elm_widget_data_get(obj);
135 const char *style = elm_widget_style_get(obj);
139 case ELM_NOTIFY_ORIENT_TOP:
140 _elm_theme_object_set(obj, wd->notify, "notify", "top", style);
142 case ELM_NOTIFY_ORIENT_CENTER:
143 _elm_theme_object_set(obj, wd->notify, "notify", "center", style);
145 case ELM_NOTIFY_ORIENT_BOTTOM:
146 _elm_theme_object_set(obj, wd->notify, "notify", "bottom", style);
148 case ELM_NOTIFY_ORIENT_LEFT:
149 _elm_theme_object_set(obj, wd->notify, "notify", "left", style);
151 case ELM_NOTIFY_ORIENT_RIGHT:
152 _elm_theme_object_set(obj, wd->notify, "notify", "right", style);
154 case ELM_NOTIFY_ORIENT_TOP_LEFT:
155 _elm_theme_object_set(obj, wd->notify, "notify", "top_left", style);
157 case ELM_NOTIFY_ORIENT_TOP_RIGHT:
158 _elm_theme_object_set(obj, wd->notify, "notify", "top_right", style);
160 case ELM_NOTIFY_ORIENT_BOTTOM_LEFT:
161 _elm_theme_object_set(obj, wd->notify, "notify", "bottom_left", style);
163 case ELM_NOTIFY_ORIENT_BOTTOM_RIGHT:
164 _elm_theme_object_set(obj, wd->notify, "notify", "bottom_right", style);
166 case ELM_NOTIFY_ORIENT_LAST:
172 * Moves notification to orientation.
174 * This fucntion moves notification to orientation
175 * according to object RTL orientation.
177 * @param obj notification object.
179 * @param orient notification orientation.
184 _notify_move_to_orientation(Evas_Object *obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
189 Evas_Coord minw = -1, minh = -1;
190 Evas_Coord x, y, w, h;
193 evas_object_geometry_get(obj, &x, &y, &w, &h);
194 edje_object_size_min_get(wd->notify, &minw, &minh);
195 edje_object_size_min_restricted_calc(wd->notify, &minw, &minh, minw, minh);
196 offx = (w - minw) / 2;
197 offy = (h - minh) / 2;
199 switch (_notify_orientation_with_rtl(obj, wd->orient))
201 case ELM_NOTIFY_ORIENT_TOP:
202 evas_object_move(wd->notify, x + offx, y);
204 case ELM_NOTIFY_ORIENT_CENTER:
205 evas_object_move(wd->notify, x + offx, y + offy);
207 case ELM_NOTIFY_ORIENT_BOTTOM:
208 evas_object_move(wd->notify, x + offx, y + h - minh);
210 case ELM_NOTIFY_ORIENT_LEFT:
211 evas_object_move(wd->notify, x, y + offy);
213 case ELM_NOTIFY_ORIENT_RIGHT:
214 evas_object_move(wd->notify, x + w - minw, y + offy);
216 case ELM_NOTIFY_ORIENT_TOP_LEFT:
217 evas_object_move(wd->notify, x, y);
219 case ELM_NOTIFY_ORIENT_TOP_RIGHT:
220 evas_object_move(wd->notify, x + w - minw, y);
222 case ELM_NOTIFY_ORIENT_BOTTOM_LEFT:
223 evas_object_move(wd->notify, x, y + h - minh);
225 case ELM_NOTIFY_ORIENT_BOTTOM_RIGHT:
226 evas_object_move(wd->notify, x + w - minw, y + h - minh);
228 case ELM_NOTIFY_ORIENT_LAST:
234 _block_events_theme_apply(Evas_Object *obj)
236 Widget_Data *wd = elm_widget_data_get(obj);
237 const char *style = elm_widget_style_get(obj);
238 _elm_theme_object_set(obj, wd->block_events, "notify", "block_events", style);
242 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
244 Widget_Data *wd = elm_widget_data_get(obj);
246 edje_object_mirrored_set(wd->notify, rtl);
247 _notify_move_to_orientation(obj);
251 _theme_hook(Evas_Object *obj)
253 Widget_Data *wd = elm_widget_data_get(obj);
255 _elm_widget_mirrored_reload(obj);
256 _mirrored_set(obj, elm_widget_mirrored_get(obj));
257 _notify_theme_apply(obj);
258 if (wd->block_events) _block_events_theme_apply(obj);
259 edje_object_scale_set(wd->notify, elm_widget_scale_get(obj) *
265 _sizing_eval(Evas_Object *obj)
267 Widget_Data *wd = elm_widget_data_get(obj);
270 if (!wd->parent) return;
271 evas_object_geometry_get(wd->parent, &x, &y, &w, &h);
272 evas_object_move(obj, x, y);
273 evas_object_resize(obj, w, h);
277 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
283 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
285 Widget_Data *wd = elm_widget_data_get(obj);
286 Evas_Object *sub = event_info;
289 if (sub == wd->content)
291 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
292 _changed_size_hints, obj);
293 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_RESIZE,
294 _content_resize, obj);
300 _signal_block_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
302 Widget_Data *wd = elm_widget_data_get(data);
304 evas_object_smart_callback_call(data, SIG_BLOCK_CLICKED, NULL);
308 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
310 Widget_Data *wd = elm_widget_data_get(obj);
312 evas_object_layer_set(wd->notify,
313 evas_object_layer_get(obj));
317 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
323 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
329 _calc(Evas_Object *obj)
331 Widget_Data *wd = elm_widget_data_get(obj);
332 Evas_Coord minw = -1, minh = -1;
333 Evas_Coord x, y, w, h;
336 evas_object_geometry_get(obj, &x, &y, &w, &h);
337 edje_object_size_min_get(wd->notify, &minw, &minh);
338 edje_object_size_min_restricted_calc(wd->notify, &minw, &minh, minw, minh);
342 _notify_move_to_orientation(obj);
343 evas_object_resize(wd->notify, minw, minh);
349 _timer_cb(void *data)
351 Evas_Object *obj = data;
352 Widget_Data *wd = elm_widget_data_get(obj);
353 if (!wd) return ECORE_CALLBACK_CANCEL;
355 evas_object_hide(obj);
356 evas_object_smart_callback_call(obj, SIG_TIMEOUT, NULL);
357 return ECORE_CALLBACK_CANCEL;
361 _timer_init(Evas_Object *obj, Widget_Data *wd)
365 ecore_timer_del(wd->timer);
368 if ((evas_object_visible_get(obj)) && (wd->timeout > 0.0))
369 wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
373 _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
375 Widget_Data *wd = elm_widget_data_get(obj);
377 evas_object_show(wd->notify);
378 if (!wd->repeat_events)
379 evas_object_show(wd->block_events);
380 _timer_init(obj, wd);
381 elm_object_focus(obj);
385 _hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
387 Widget_Data *wd = elm_widget_data_get(obj);
389 evas_object_hide(wd->notify);
390 if (!wd->repeat_events)
391 evas_object_hide(wd->block_events);
394 ecore_timer_del(wd->timer);
400 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
402 Widget_Data *wd = elm_widget_data_get(data);
405 evas_object_hide(data);
409 _parent_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
411 Widget_Data *wd = elm_widget_data_get(data);
413 evas_object_hide(data);
417 _elm_notify_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
419 Widget_Data *wd = elm_widget_data_get(obj);
422 if ((!wd) || (!wd->content))
427 /* Try Focus cycle in subitem */
428 return elm_widget_focus_next_get(cur, dir, next);
432 * Add a new notify to the parent
434 * @param parent The parent object
435 * @return The new object or NULL if it cannot be created
440 elm_notify_add(Evas_Object *parent)
446 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
448 ELM_SET_WIDTYPE(widtype, "notify");
449 elm_widget_type_set(obj, "notify");
450 elm_widget_sub_object_add(parent, obj);
451 elm_widget_data_set(obj, wd);
452 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
453 elm_widget_del_hook_set(obj, _del_hook);
454 elm_widget_theme_hook_set(obj, _theme_hook);
455 elm_widget_can_focus_set(obj, EINA_FALSE);
456 elm_widget_focus_next_hook_set(obj, _elm_notify_focus_next_hook);
458 wd->repeat_events = EINA_TRUE;
460 wd->notify = edje_object_add(e);
462 elm_notify_orient_set(obj, ELM_NOTIFY_ORIENT_TOP);
464 elm_notify_parent_set(obj, parent);
466 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
467 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
468 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _resize, obj);
469 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
470 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide, obj);
471 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
472 _mirrored_set(obj, elm_widget_mirrored_get(obj));
475 evas_object_smart_callbacks_descriptions_set(obj, _signals);
480 * Set the content of the notify widget
482 * Once the content object is set, a previously set one will be deleted.
483 * If you want to keep that old content object, use the
484 * elm_notify_content_unset() function.
486 * @param obj The notify object
487 * @param content The content will be filled in this notify object
492 elm_notify_content_set(Evas_Object *obj, Evas_Object *content)
494 ELM_CHECK_WIDTYPE(obj, widtype);
495 Widget_Data *wd = elm_widget_data_get(obj);
497 if (wd->content == content) return;
498 if (wd->content) evas_object_del(wd->content);
499 wd->content = content;
503 elm_widget_sub_object_add(obj, content);
504 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
505 _changed_size_hints, obj);
506 evas_object_event_callback_add(content, EVAS_CALLBACK_RESIZE,
507 _content_resize, obj);
508 edje_object_part_swallow(wd->notify, "elm.swallow.content", content);
515 * Unset the content of the notify widget
517 * Unparent and return the content object which was set for this widget
519 * @param obj The notify object
520 * @return The content that was being used
525 elm_notify_content_unset(Evas_Object *obj)
527 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
528 Widget_Data *wd = elm_widget_data_get(obj);
529 Evas_Object *content;
530 if (!wd) return NULL;
531 if (!wd->content) return NULL;
532 content = wd->content;
533 elm_widget_sub_object_del(obj, wd->content);
534 edje_object_part_unswallow(wd->notify, wd->content);
540 * Return the content of the notify widget
542 * @param obj The notify object
543 * @return The content that is being used
548 elm_notify_content_get(const Evas_Object *obj)
550 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
551 Widget_Data *wd = elm_widget_data_get(obj);
553 if (!wd) return NULL;
558 * Set the notify parent
560 * Once the parent object is set, a previously set one will be disconnected
563 * @param obj The notify object
564 * @param content The new parent
569 elm_notify_parent_set(Evas_Object *obj, Evas_Object *parent)
571 ELM_CHECK_WIDTYPE(obj, widtype);
572 Widget_Data *wd = elm_widget_data_get(obj);
576 evas_object_event_callback_del_full(wd->parent,
577 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
578 _changed_size_hints, obj);
579 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
580 _changed_size_hints, obj);
581 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_MOVE,
582 _changed_size_hints, obj);
583 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL,
585 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_HIDE,
593 evas_object_event_callback_add(parent,
594 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
595 _changed_size_hints, obj);
596 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE,
597 _changed_size_hints, obj);
598 evas_object_event_callback_add(parent, EVAS_CALLBACK_MOVE,
599 _changed_size_hints, obj);
600 evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL,
602 evas_object_event_callback_add(parent, EVAS_CALLBACK_HIDE,
604 edje_object_part_swallow(wd->notify, "elm.swallow.parent", parent);
611 * Get the notify parent
613 * @param obj The notify object
619 elm_notify_parent_get(const Evas_Object *obj)
621 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
622 Widget_Data *wd = elm_widget_data_get(obj);
623 if (!wd) return NULL;
628 * Set the orientation
630 * @param obj The notify object
631 * @param orient The new orientation
636 elm_notify_orient_set(Evas_Object *obj, Elm_Notify_Orient orient)
638 ELM_CHECK_WIDTYPE(obj, widtype);
639 Widget_Data *wd = elm_widget_data_get(obj);
641 if (wd->orient == orient) return;
643 _notify_theme_apply(obj);
644 _resize(obj, NULL, obj, NULL);
648 * Return the orientation
649 * @param obj the notify objects
651 EAPI Elm_Notify_Orient
652 elm_notify_orient_get(const Evas_Object *obj)
654 ELM_CHECK_WIDTYPE(obj, widtype) -1;
655 Widget_Data *wd = elm_widget_data_get(obj);
661 * Set the time interval after which the notify window is going to be
664 * @param obj The notify object
665 * @param time The new timeout
667 * As said previously, an evas_object_show() on a notify object which
668 * had a timeout set by this function will trigger a timer to
669 * automatically hide it again. So, any order one calls
670 * elm_notify_timeout_set() and evas_object_show() on the same object
671 * (at hidden state) will behave the same.
673 * @note Set a value <= 0.0 to disable a running timer.
675 * @note If the value > 0.0 and the notify is previously visible, the
676 * timer will be started with this value, canceling any running timer.
680 elm_notify_timeout_set(Evas_Object *obj, double timeout)
682 ELM_CHECK_WIDTYPE(obj, widtype);
683 Widget_Data *wd = elm_widget_data_get(obj);
685 wd->timeout = timeout;
686 _timer_init(obj, wd);
690 * Return the timeout value (in seconds)
691 * @param obj the notify object
694 elm_notify_timeout_get(const Evas_Object *obj)
696 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
697 Widget_Data *wd = elm_widget_data_get(obj);
703 * When true if the user clicks outside the window the events will be
704 * catch by the others widgets, else the events are block and the signal
705 * dismiss will be sent when the user click outside the window.
707 * @note The default value is EINA_TRUE.
709 * @param obj The notify object
710 * @param repeats EINA_TRUE Events are repeats, else no
713 elm_notify_repeat_events_set(Evas_Object *obj, Eina_Bool repeat)
715 ELM_CHECK_WIDTYPE(obj, widtype);
716 Widget_Data *wd = elm_widget_data_get(obj);
718 if (repeat == wd->repeat_events) return;
719 wd->repeat_events = repeat;
722 wd->block_events = edje_object_add(evas_object_evas_get(obj));
723 _block_events_theme_apply(obj);
724 elm_widget_resize_object_set(obj, wd->block_events);
725 edje_object_signal_callback_add(wd->block_events, "elm,action,clicked",
726 "elm", _signal_block_clicked, obj);
729 evas_object_del(wd->block_events);
733 * Return true if events are repeat below the notify object
734 * @param obj the notify object
737 elm_notify_repeat_events_get(const Evas_Object *obj)
739 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
740 Widget_Data *wd = elm_widget_data_get(obj);
741 if (!wd) return EINA_FALSE;
742 return wd->repeat_events;