1 #include <Elementary.h>
3 #include "elm_widget_notify.h"
5 EAPI const char ELM_NOTIFY_SMART_NAME[] = "elm_notify";
7 static const char SIG_BLOCK_CLICKED[] = "block,clicked";
8 static const char SIG_TIMEOUT[] = "timeout";
9 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
10 {SIG_BLOCK_CLICKED, ""},
15 EVAS_SMART_SUBCLASS_NEW
16 (ELM_NOTIFY_SMART_NAME, _elm_notify, Elm_Notify_Smart_Class,
17 Elm_Container_Smart_Class, elm_container_smart_class_get, NULL);
20 _notify_theme_apply(Evas_Object *obj)
22 const char *style = elm_widget_style_get(obj);
25 ELM_NOTIFY_DATA_GET(obj, sd);
27 ax = sd->horizontal_align;
28 ay = sd->vertical_align;
29 if ((elm_widget_mirrored_get(obj)) && (ax != ELM_NOTIFY_ALIGN_FILL)) ax = 1.0 - ax;
32 elm_widget_theme_object_set(obj, sd->notify, "notify", "top", style);
34 elm_widget_theme_object_set(obj, sd->notify, "notify", "bottom", style);
36 elm_widget_theme_object_set(obj, sd->notify, "notify", "left", style);
38 elm_widget_theme_object_set(obj, sd->notify, "notify", "right", style);
40 elm_widget_theme_object_set(obj, sd->notify, "notify", "center", style);
44 * Moves notification to orientation.
46 * This function moves notification to orientation
47 * according to object RTL orientation.
49 * @param obj notification object.
51 * @param orient notification orientation.
56 _notify_move_to_orientation(Evas_Object *obj)
58 Evas_Coord minw = -1, minh = -1;
59 Evas_Coord x, y, w, h;
62 ELM_NOTIFY_DATA_GET(obj, sd);
64 evas_object_geometry_get(obj, &x, &y, &w, &h);
65 edje_object_size_min_get(sd->notify, &minw, &minh);
66 edje_object_size_min_restricted_calc(sd->notify, &minw, &minh, minw, minh);
68 ax = sd->horizontal_align;
69 ay = sd->vertical_align;
70 if ((elm_widget_mirrored_get(obj)) && (ax != ELM_NOTIFY_ALIGN_FILL)) ax = 1.0 - ax;
72 if (ax == ELM_NOTIFY_ALIGN_FILL) minw = w;
73 if (ay == ELM_NOTIFY_ALIGN_FILL) minh = h;
75 x = x + ((w - minw) * ax);
76 y = y + ((h - minh) * ay);
78 evas_object_move(sd->notify, x, y);
82 _block_events_theme_apply(Evas_Object *obj)
84 ELM_NOTIFY_DATA_GET(obj, sd);
86 const char *style = elm_widget_style_get(obj);
88 elm_layout_theme_set(sd->block_events, "notify", "block_events", style);
92 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
94 ELM_NOTIFY_DATA_GET(obj, sd);
95 edje_object_mirrored_set(sd->notify, rtl);
96 _notify_move_to_orientation(obj);
100 _sizing_eval(Evas_Object *obj)
102 Evas_Coord x, y, w, h;
104 ELM_NOTIFY_DATA_GET(obj, sd);
106 if (!sd->parent) return;
107 evas_object_geometry_get(sd->parent, &x, &y, &w, &h);
108 evas_object_move(obj, x, y);
109 evas_object_resize(obj, w, h);
113 _elm_notify_smart_theme(Evas_Object *obj)
115 ELM_NOTIFY_DATA_GET(obj, sd);
117 if (!ELM_WIDGET_CLASS(_elm_notify_parent_sc)->theme(obj)) return EINA_FALSE;
119 _mirrored_set(obj, elm_widget_mirrored_get(obj));
121 _notify_theme_apply(obj);
122 if (sd->block_events) _block_events_theme_apply(obj);
124 edje_object_scale_set
125 (sd->notify, elm_widget_scale_get(obj) * elm_config_scale_get());
133 _calc(Evas_Object *obj)
135 Evas_Coord minw = -1, minh = -1;
136 Evas_Coord x, y, w, h;
138 ELM_NOTIFY_DATA_GET(obj, sd);
142 evas_object_geometry_get(obj, &x, &y, &w, &h);
144 edje_object_size_min_get(sd->notify, &minw, &minh);
145 edje_object_size_min_restricted_calc(sd->notify, &minw, &minh, minw, minh);
147 if (sd->horizontal_align == ELM_NOTIFY_ALIGN_FILL) minw = w;
148 if (sd->vertical_align == ELM_NOTIFY_ALIGN_FILL) minh = h;
152 _notify_move_to_orientation(obj);
153 evas_object_resize(sd->notify, minw, minh);
158 _changed_size_hints_cb(void *data,
160 Evas_Object *obj __UNUSED__,
161 void *event_info __UNUSED__)
167 _elm_notify_smart_sub_object_del(Evas_Object *obj,
170 ELM_NOTIFY_DATA_GET(obj, sd);
172 if (!ELM_WIDGET_CLASS(_elm_notify_parent_sc)->sub_object_del(obj, sobj))
175 if (sobj == sd->content)
177 evas_object_event_callback_del_full
178 (sobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
179 _changed_size_hints_cb, obj);
187 _block_area_clicked_cb(void *data,
188 Evas_Object *obj __UNUSED__,
189 const char *emission __UNUSED__,
190 const char *source __UNUSED__)
192 evas_object_smart_callback_call(data, SIG_BLOCK_CLICKED, NULL);
196 _restack_cb(void *data __UNUSED__,
199 void *event_info __UNUSED__)
201 ELM_NOTIFY_DATA_GET(obj, sd);
203 evas_object_layer_set(sd->notify, evas_object_layer_get(obj));
207 _elm_notify_smart_resize(Evas_Object *obj,
211 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.resize(obj, w, h);
217 _elm_notify_smart_move(Evas_Object *obj,
221 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.move(obj, x, y);
227 _timer_cb(void *data)
229 Evas_Object *obj = data;
231 ELM_NOTIFY_DATA_GET(obj, sd);
234 if (!evas_object_visible_get(obj)) goto end;
236 evas_object_hide(obj);
237 evas_object_smart_callback_call(obj, SIG_TIMEOUT, NULL);
240 return ECORE_CALLBACK_CANCEL;
244 _timer_init(Evas_Object *obj,
245 Elm_Notify_Smart_Data *sd)
249 ecore_timer_del(sd->timer);
252 if (sd->timeout > 0.0)
253 sd->timer = ecore_timer_add(sd->timeout, _timer_cb, obj);
257 _elm_notify_smart_show(Evas_Object *obj)
259 ELM_NOTIFY_DATA_GET(obj, sd);
261 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.show(obj);
263 evas_object_show(sd->notify);
264 if (!sd->allow_events) evas_object_show(sd->block_events);
265 _timer_init(obj, sd);
266 elm_object_focus_set(obj, EINA_TRUE);
270 _elm_notify_smart_hide(Evas_Object *obj)
272 ELM_NOTIFY_DATA_GET(obj, sd);
274 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.hide(obj);
276 evas_object_hide(sd->notify);
277 if (!sd->allow_events) evas_object_hide(sd->block_events);
280 ecore_timer_del(sd->timer);
286 _parent_del_cb(void *data,
288 Evas_Object *obj __UNUSED__,
289 void *event_info __UNUSED__)
291 elm_notify_parent_set(data, NULL);
292 evas_object_hide(data);
296 _parent_hide_cb(void *data,
298 Evas_Object *obj __UNUSED__,
299 void *event_info __UNUSED__)
301 evas_object_hide(data);
305 _elm_notify_smart_focus_next(const Evas_Object *obj,
306 Elm_Focus_Direction dir,
311 ELM_NOTIFY_DATA_GET(obj, sd);
318 /* Try to cycle focus on content */
319 return elm_widget_focus_next_get(cur, dir, next);
323 _elm_notify_smart_focus_direction(const Evas_Object *obj,
324 const Evas_Object *base,
326 Evas_Object **direction,
331 ELM_NOTIFY_DATA_GET(obj, sd);
338 return elm_widget_focus_direction_get(cur, base, degree, direction, weight);
342 _elm_notify_smart_content_set(Evas_Object *obj,
344 Evas_Object *content)
346 ELM_NOTIFY_DATA_GET(obj, sd);
348 if (part && strcmp(part, "default")) return EINA_FALSE;
349 if (sd->content == content) return EINA_TRUE;
350 if (sd->content) evas_object_del(sd->content);
351 sd->content = content;
355 elm_widget_sub_object_add(obj, content);
356 evas_object_event_callback_add
357 (content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
358 _changed_size_hints_cb, obj);
359 edje_object_part_swallow(sd->notify, "elm.swallow.content", content);
369 _elm_notify_smart_content_get(const Evas_Object *obj,
372 ELM_NOTIFY_DATA_GET(obj, sd);
374 if (part && strcmp(part, "default")) return NULL;
380 _elm_notify_smart_content_unset(Evas_Object *obj,
383 Evas_Object *content;
385 ELM_NOTIFY_DATA_GET(obj, sd);
387 if (part && strcmp(part, "default")) return NULL;
388 if (!sd->content) return NULL;
390 content = sd->content;
391 elm_widget_sub_object_del(obj, sd->content);
392 edje_object_part_unswallow(sd->notify, content);
398 _elm_notify_smart_add(Evas_Object *obj)
400 EVAS_SMART_DATA_ALLOC(obj, Elm_Notify_Smart_Data);
402 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.add(obj);
404 priv->allow_events = EINA_TRUE;
406 priv->notify = edje_object_add(evas_object_evas_get(obj));
407 priv->horizontal_align = 0.5;
408 priv->vertical_align = 0.0;
410 evas_object_event_callback_add
411 (obj, EVAS_CALLBACK_RESTACK, _restack_cb, obj);
413 elm_widget_can_focus_set(obj, EINA_FALSE);
414 elm_notify_align_set(obj, 0.5, 0.0);
418 _elm_notify_smart_del(Evas_Object *obj)
420 ELM_NOTIFY_DATA_GET(obj, sd);
422 elm_notify_parent_set(obj, NULL);
423 elm_notify_allow_events_set(obj, EINA_FALSE);
426 ecore_timer_del(sd->timer);
430 ELM_WIDGET_CLASS(_elm_notify_parent_sc)->base.del(obj);
434 _elm_notify_smart_parent_set(Evas_Object *obj,
437 elm_notify_parent_set(obj, parent);
443 _elm_notify_smart_set_user(Elm_Notify_Smart_Class *sc)
445 ELM_WIDGET_CLASS(sc)->base.add = _elm_notify_smart_add;
446 ELM_WIDGET_CLASS(sc)->base.del = _elm_notify_smart_del;
448 ELM_WIDGET_CLASS(sc)->base.resize = _elm_notify_smart_resize;
449 ELM_WIDGET_CLASS(sc)->base.move = _elm_notify_smart_move;
450 ELM_WIDGET_CLASS(sc)->base.show = _elm_notify_smart_show;
451 ELM_WIDGET_CLASS(sc)->base.hide = _elm_notify_smart_hide;
453 ELM_WIDGET_CLASS(sc)->parent_set = _elm_notify_smart_parent_set;
454 ELM_WIDGET_CLASS(sc)->theme = _elm_notify_smart_theme;
455 ELM_WIDGET_CLASS(sc)->focus_next = _elm_notify_smart_focus_next;
456 ELM_WIDGET_CLASS(sc)->focus_direction = _elm_notify_smart_focus_direction;
458 ELM_WIDGET_CLASS(sc)->sub_object_del = _elm_notify_smart_sub_object_del;
460 ELM_CONTAINER_CLASS(sc)->content_set = _elm_notify_smart_content_set;
461 ELM_CONTAINER_CLASS(sc)->content_get = _elm_notify_smart_content_get;
462 ELM_CONTAINER_CLASS(sc)->content_unset = _elm_notify_smart_content_unset;
465 EAPI const Elm_Notify_Smart_Class *
466 elm_notify_smart_class_get(void)
468 static Elm_Notify_Smart_Class _sc =
469 ELM_NOTIFY_SMART_CLASS_INIT_NAME_VERSION(ELM_NOTIFY_SMART_NAME);
470 static const Elm_Notify_Smart_Class *class = NULL;
471 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
473 if (class) return class;
475 _elm_notify_smart_set(&_sc);
476 esc->callbacks = _smart_callbacks;
483 elm_notify_add(Evas_Object *parent)
487 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
489 obj = elm_widget_add(_elm_notify_smart_class_new(), parent);
490 if (!obj) return NULL;
492 if (!elm_widget_sub_object_add(parent, obj))
493 ERR("could not add %p as sub object of %p", obj, parent);
499 elm_notify_parent_set(Evas_Object *obj,
502 ELM_NOTIFY_CHECK(obj);
503 ELM_NOTIFY_DATA_GET(obj, sd);
507 evas_object_event_callback_del_full
508 (sd->parent, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
509 _changed_size_hints_cb, obj);
510 evas_object_event_callback_del_full
511 (sd->parent, EVAS_CALLBACK_RESIZE, _changed_size_hints_cb, obj);
512 evas_object_event_callback_del_full
513 (sd->parent, EVAS_CALLBACK_MOVE, _changed_size_hints_cb, obj);
514 evas_object_event_callback_del_full
515 (sd->parent, EVAS_CALLBACK_DEL, _parent_del_cb, obj);
516 evas_object_event_callback_del_full
517 (sd->parent, EVAS_CALLBACK_HIDE, _parent_hide_cb, obj);
524 evas_object_event_callback_add
525 (parent, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
526 _changed_size_hints_cb, obj);
527 evas_object_event_callback_add
528 (parent, EVAS_CALLBACK_RESIZE, _changed_size_hints_cb, obj);
529 evas_object_event_callback_add
530 (parent, EVAS_CALLBACK_MOVE, _changed_size_hints_cb, obj);
531 evas_object_event_callback_add
532 (parent, EVAS_CALLBACK_DEL, _parent_del_cb, obj);
533 evas_object_event_callback_add
534 (parent, EVAS_CALLBACK_HIDE, _parent_hide_cb, obj);
542 elm_notify_parent_get(const Evas_Object *obj)
544 ELM_NOTIFY_CHECK(obj) NULL;
545 ELM_NOTIFY_DATA_GET(obj, sd);
550 EINA_DEPRECATED EAPI void
551 elm_notify_orient_set(Evas_Object *obj,
552 Elm_Notify_Orient orient)
554 double horizontal = 0, vertical = 0;
558 case ELM_NOTIFY_ORIENT_TOP:
559 horizontal = 0.5; vertical = 0.0;
562 case ELM_NOTIFY_ORIENT_CENTER:
563 horizontal = 0.5; vertical = 0.5;
566 case ELM_NOTIFY_ORIENT_BOTTOM:
567 horizontal = 0.5; vertical = 1.0;
570 case ELM_NOTIFY_ORIENT_LEFT:
571 horizontal = 0.0; vertical = 0.5;
574 case ELM_NOTIFY_ORIENT_RIGHT:
575 horizontal = 1.0; vertical = 0.5;
578 case ELM_NOTIFY_ORIENT_TOP_LEFT:
579 horizontal = 0.0; vertical = 0.0;
582 case ELM_NOTIFY_ORIENT_TOP_RIGHT:
583 horizontal = 1.0; vertical = 0.0;
586 case ELM_NOTIFY_ORIENT_BOTTOM_LEFT:
587 horizontal = 0.0; vertical = 1.0;
590 case ELM_NOTIFY_ORIENT_BOTTOM_RIGHT:
591 horizontal = 1.0; vertical = 1.0;
594 case ELM_NOTIFY_ORIENT_LAST:
597 elm_notify_align_set(obj, horizontal, vertical);
600 EINA_DEPRECATED EAPI Elm_Notify_Orient
601 elm_notify_orient_get(const Evas_Object *obj)
603 Elm_Notify_Orient orient;
604 double horizontal, vertical;
606 elm_notify_align_get(obj, &horizontal, &vertical);
608 if ((horizontal == 0.5) && (vertical == 0.0))
609 orient = ELM_NOTIFY_ORIENT_TOP;
610 else if ((horizontal == 0.5) && (vertical == 0.5))
611 orient = ELM_NOTIFY_ORIENT_CENTER;
612 else if ((horizontal == 0.5) && (vertical == 1.0))
613 orient = ELM_NOTIFY_ORIENT_BOTTOM;
614 else if ((horizontal == 0.0) && (vertical == 0.5))
615 orient = ELM_NOTIFY_ORIENT_LEFT;
616 else if ((horizontal == 1.0) && (vertical == 0.5))
617 orient = ELM_NOTIFY_ORIENT_RIGHT;
618 else if ((horizontal == 0.0) && (vertical == 0.0))
619 orient = ELM_NOTIFY_ORIENT_TOP_LEFT;
620 else if ((horizontal == 1.0) && (vertical == 0.0))
621 orient = ELM_NOTIFY_ORIENT_TOP_RIGHT;
622 else if ((horizontal == 0.0) && (vertical == 1.0))
623 orient = ELM_NOTIFY_ORIENT_BOTTOM_LEFT;
624 else if ((horizontal == 1.0) && (vertical == 1.0))
625 orient = ELM_NOTIFY_ORIENT_BOTTOM_RIGHT;
627 orient = ELM_NOTIFY_ORIENT_TOP;
632 elm_notify_timeout_set(Evas_Object *obj,
635 ELM_NOTIFY_CHECK(obj);
636 ELM_NOTIFY_DATA_GET(obj, sd);
638 sd->timeout = timeout;
639 _timer_init(obj, sd);
643 elm_notify_timeout_get(const Evas_Object *obj)
645 ELM_NOTIFY_CHECK(obj) 0.0;
646 ELM_NOTIFY_DATA_GET(obj, sd);
652 elm_notify_allow_events_set(Evas_Object *obj,
655 ELM_NOTIFY_CHECK(obj);
656 ELM_NOTIFY_DATA_GET(obj, sd);
658 if (allow == sd->allow_events) return;
659 sd->allow_events = allow;
662 sd->block_events = elm_layout_add(obj);
663 _block_events_theme_apply(obj);
664 elm_widget_resize_object_set(obj, sd->block_events);
665 elm_layout_signal_callback_add
666 (sd->block_events, "elm,action,click", "elm",
667 _block_area_clicked_cb, obj);
670 evas_object_del(sd->block_events);
674 elm_notify_allow_events_get(const Evas_Object *obj)
676 ELM_NOTIFY_CHECK(obj) EINA_FALSE;
677 ELM_NOTIFY_DATA_GET(obj, sd);
679 return sd->allow_events;
683 elm_notify_align_set(Evas_Object *obj, double horizontal, double vertical)
685 ELM_NOTIFY_CHECK(obj);
686 ELM_NOTIFY_DATA_GET(obj, sd);
688 sd->horizontal_align = horizontal;
689 sd->vertical_align = vertical;
691 _notify_theme_apply(obj);
696 elm_notify_align_get(const Evas_Object *obj, double *horizontal, double *vertical)
698 ELM_NOTIFY_CHECK(obj);
699 ELM_NOTIFY_DATA_GET(obj, sd);
701 *horizontal = sd->horizontal_align;
702 *vertical = sd->vertical_align;