1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
12 Ecore_Event_Handler *rotation_event_handler;
16 Elm_Tickernoti_Mode mode;
17 Elm_Tickernoti_Orient orient;
20 static const char *widtype = NULL;
21 static void _del_hook(Evas_Object *obj);
22 static void _theme_hook(Evas_Object *obj);
23 static void _sizing_eval(Evas_Object *obj);
24 static void _update_geometry_on_rotation(Evas_Object *obj, int angle, int *x, int *y, int *w);
26 static const char SIG_CLICKED[] = "clicked";
27 static const char SIG_HIDDEN[] = "hide";
28 static const Evas_Smart_Cb_Description _signals[] = {
37 evas_object_del(data);
41 _del_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
47 parent = elm_widget_parent_get(obj);
48 if (wd->rotation_event_handler)
49 ecore_event_handler_del(wd->rotation_event_handler);
50 if (wd->win) ecore_job_add(_del_job, parent);
51 evas_object_del(wd->edje_obj);
57 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
59 Widget_Data *wd = elm_widget_data_get(obj);
62 edje_object_mirrored_set(wd->edje_obj, rtl);
66 _theme_hook(Evas_Object *obj)
68 char *data_win_height = NULL;
70 Widget_Data *wd = elm_widget_data_get(obj);
73 _elm_widget_mirrored_reload(obj);
74 _mirrored_set(obj, elm_widget_mirrored_get(obj));
76 _elm_theme_object_set(wd->win, wd->edje_obj, "tickernoti",
77 "base", elm_widget_style_get(obj));
79 /* tickernoti detail height set */
80 data_win_height = (char *)edje_object_data_get(wd->edje_obj, "height");
81 if (data_win_height != NULL && elm_scale_get() > 0.0)
82 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
84 evas_object_geometry_get(wd->win, NULL, NULL, &w, NULL);
85 evas_object_resize(wd->win, w, wd->noti_height);
87 edje_object_signal_emit(wd->edje_obj, "effect,show", "elm");/*goes too late*/
88 edje_object_message_signal_process(wd->edje_obj);
89 edje_object_scale_set(wd->edje_obj, elm_widget_scale_get(obj) * _elm_config->scale);
95 _sizing_eval(Evas_Object *obj)
97 Widget_Data *wd = elm_widget_data_get(obj);
98 Evas_Coord minw = -1, minh = -1;
101 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
102 edje_object_size_min_restricted_calc(wd->edje_obj, &minw, &minh, minw, minh);
103 evas_object_size_hint_min_set(obj, minw, minh);
106 #ifdef HAVE_ELEMENTARY_X
108 _update_window_hints(Evas_Object *obj)
111 Ecore_X_Atom _notification_level_atom;
113 // elm_win_xwindow_get() must call after elm_win_alpha_set()
114 xwin = elm_win_xwindow_get(obj);
116 ecore_x_icccm_hints_set(xwin, 0, ECORE_X_WINDOW_STATE_HINT_NONE, 0, 0, 0, 0, 0);
117 ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
118 ecore_x_netwm_opacity_set(xwin, 0);
119 // Create atom for notification level
120 _notification_level_atom = ecore_x_atom_get("_E_ILLUME_NOTIFICATION_LEVEL");
122 // HIGH:150, NORMAL:100, LOW:50
125 // Set notification level of the window
126 ecore_x_window_prop_property_set(xwin, _notification_level_atom, ECORE_X_ATOM_CARDINAL, 32, &level, 1);
130 static void _hide_cb(void *data, Evas_Object *obj __UNUSED__,
131 const char *emission __UNUSED__,
132 const char *source __UNUSED__)
134 Widget_Data *wd = elm_widget_data_get(data);
137 evas_object_hide(wd->win);
138 evas_object_smart_callback_call(data, SIG_HIDDEN, NULL);
141 static void _clicked_cb(void *data, Evas_Object *obj __UNUSED__,
142 const char *emission __UNUSED__,
143 const char *source __UNUSED__)
145 Widget_Data *wd = elm_widget_data_get(data);
148 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
152 *_create_window(Evas_Object *parent, const char *name)
156 win = elm_win_add(parent, name, ELM_WIN_BASIC);
157 elm_win_title_set(win, name);
158 elm_win_borderless_set(win, EINA_TRUE);
159 elm_win_autodel_set(win, EINA_TRUE);
160 elm_win_alpha_set(win, EINA_TRUE);
161 evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
162 evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL);
164 #ifdef HAVE_ELEMENTARY_X
166 _update_window_hints(win);
172 _win_rotated(Evas_Object *obj)
174 Widget_Data *wd = elm_widget_data_get(obj);
175 int x = 0, y = 0, w = 0, angle = 0;
178 angle = elm_win_rotation_get(wd->win);
179 if (angle % 90) return;
181 if (angle < 0) angle += 360;
183 _update_geometry_on_rotation(obj, wd->angle, &x, &y, &w);
184 evas_object_move(wd->win, x, y);
185 evas_object_resize(wd->win, w, wd->noti_height);
186 #ifdef HAVE_ELEMENTARY_X
187 _update_window_hints(wd->win);
192 _prop_change(void *data, int type __UNUSED__, void *event)
194 #ifdef HAVE_ELEMENTARY_X
195 Ecore_X_Event_Window_Property *ev;
196 Widget_Data *wd = elm_widget_data_get(data);
198 if (!wd) return ECORE_CALLBACK_PASS_ON;
200 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE)
202 if (ev->win == elm_win_xwindow_get(wd->win))
207 return ECORE_CALLBACK_PASS_ON;
212 _create_tickernoti(Evas_Object *obj)
214 #ifdef HAVE_ELEMENTARY_X
217 Widget_Data *wd = elm_widget_data_get(obj);
218 char *data_win_height = NULL;
223 evas_object_move(wd->win, 0, 0);
224 e = evas_object_evas_get(wd->win);
226 wd->edje_obj = edje_object_add(e);
227 _elm_theme_object_set(wd->win, wd->edje_obj, "tickernoti", "base", "default");
228 elm_win_resize_object_add(wd->win, wd->edje_obj);
230 // tickernoti height setting
231 data_win_height = (char *)edje_object_data_get(wd->edje_obj, "height");
232 if (data_win_height != NULL && elm_scale_get() > 0.0)
233 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
235 #ifdef HAVE_ELEMENTARY_X
236 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, NULL);
237 evas_object_size_hint_min_set(wd->edje_obj, w, wd->noti_height);
238 evas_object_resize(wd->win, w, wd->noti_height);
239 wd->rotation_event_handler = ecore_event_handler_add(
240 ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, obj);
243 edje_object_signal_callback_add(wd->edje_obj, "request,hide", "", _hide_cb, obj);
244 edje_object_signal_callback_add(wd->edje_obj, "clicked", "", _clicked_cb, obj);
245 evas_object_show(wd->edje_obj);
249 _disable_hook(Evas_Object *obj)
251 Widget_Data *wd = elm_widget_data_get(obj);
254 //TODO: To stop the event in case of being disabled
258 _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
259 void *event_info __UNUSED__)
261 Widget_Data *wd = elm_widget_data_get(obj);
264 #ifdef HAVE_ELEMENTARY_X
265 _update_window_hints(wd->win);
267 evas_object_show(wd->win);
268 edje_object_signal_emit(wd->edje_obj, "effect,show", "elm");
269 edje_object_message_signal_process(wd->edje_obj);
273 _hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
274 void *event_info __UNUSED__)
276 Widget_Data *wd = elm_widget_data_get(obj);
279 evas_object_hide(wd->win);
282 static void _tickernoti_hide_cb(void *data, Evas_Object *obj __UNUSED__,
283 void *event_info __UNUSED__)
285 Widget_Data *wd = data;
289 edje_object_signal_emit(wd->edje_obj, "effect,hide", "elm");
290 edje_object_message_signal_process(wd->edje_obj);
294 _update_geometry_on_rotation(Evas_Object *obj, int angle, int *x, int *y, int *w)
296 ELM_CHECK_WIDTYPE(obj, widtype);
297 Widget_Data *wd = elm_widget_data_get(obj);
301 #ifdef HAVE_ELEMENTARY_X
302 Evas_Coord root_w, root_h;
305 * manually calculate win_tickernoti_indi window position & size
306 * - win_indi is not full size window
308 ecore_x_window_size_get(ecore_x_window_root_first_get(), &root_w, &root_h);
314 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
315 *x = root_w - wd->noti_height;
319 if (!(wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM))
320 *x = root_w - wd->noti_height;
324 if (!wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
325 *y = root_h - wd->noti_height;
330 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
331 *y = root_h - wd->noti_height;
338 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
340 Widget_Data *wd = elm_widget_data_get(obj);
341 Evas_Object *sub = event_info;
345 if (sub == wd->button)
350 _elm_tickernoti_label_set(Evas_Object *obj, const char *part, const char *label)
352 ELM_CHECK_WIDTYPE(obj, widtype);
353 Widget_Data *wd = elm_widget_data_get(obj);
356 if (part && strcmp(part, "default")) return;
357 eina_stringshare_replace(&wd->label, label);
358 edje_object_part_text_set(wd->edje_obj, "elm.text", wd->label);
363 _elm_tickernoti_label_get(const Evas_Object *obj, const char *part)
365 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
366 Widget_Data *wd = elm_widget_data_get(obj);
368 if (part && strcmp(part, "default")) return NULL;
369 if (!wd) return NULL;
374 _elm_tickernoti_icon_set(Evas_Object *obj, Evas_Object *icon)
376 ELM_CHECK_WIDTYPE(obj, widtype);
377 Widget_Data *wd = elm_widget_data_get(obj);
380 if (wd->icon == icon) return;
381 if (wd->icon) evas_object_del(wd->icon);
385 elm_widget_sub_object_add(obj, icon);
386 edje_object_part_swallow(wd->edje_obj, "icon", icon);
391 _elm_tickernoti_button_set(Evas_Object *obj, Evas_Object *button)
393 ELM_CHECK_WIDTYPE(obj, widtype);
394 Widget_Data *wd = elm_widget_data_get(obj);
397 if (wd->button == button) return;
398 if (wd->button) evas_object_del(wd->button);
402 elm_widget_sub_object_add(obj, button);
403 edje_object_part_swallow(wd->edje_obj, "button", button);
404 evas_object_smart_callback_add(wd->button, "clicked", _tickernoti_hide_cb, wd);
409 _elm_tickernoti_content_part_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
411 ELM_CHECK_WIDTYPE(obj, widtype);
412 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd || !part) return;
415 if (!part || !strcmp(part, "icon"))
417 _elm_tickernoti_icon_set(obj, content);
420 else if (!strcmp(part, "button"))
422 _elm_tickernoti_button_set(obj, content);
428 _elm_tickernoti_icon_get(const Evas_Object *obj)
430 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
431 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd) return NULL;
437 _elm_tickernoti_button_get(const Evas_Object *obj)
439 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
440 Widget_Data *wd = elm_widget_data_get(obj);
441 if (!wd) return NULL;
446 _elm_tickernoti_content_part_get_hook(Evas_Object *obj, const char *part)
448 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
449 Widget_Data *wd = elm_widget_data_get(obj);
451 if (!wd || !part) return NULL;
452 if (!part || !strcmp(part, "icon"))
453 return _elm_tickernoti_icon_get(obj);
454 else if (!strcmp(part, "button"))
455 return _elm_tickernoti_button_get(obj);
460 _elm_tickernoti_icon_unset(Evas_Object *obj)
462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
464 Widget_Data *wd = elm_widget_data_get(obj);
466 if (!wd || !wd->icon) return NULL;
468 elm_widget_sub_object_del(obj, wd->icon);
469 edje_object_part_unswallow(wd->edje_obj, icon);
475 _elm_tickernoti_button_unset(Evas_Object *obj)
477 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
479 Widget_Data *wd = elm_widget_data_get(obj);
481 if (!wd || !wd->button) return NULL;
483 elm_widget_sub_object_del(obj, wd->button);
484 edje_object_part_unswallow(wd->edje_obj, button);
490 _elm_tickernoti_content_part_unset_hook(Evas_Object *obj, const char *part)
492 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
493 Widget_Data *wd = elm_widget_data_get(obj);
495 if (!wd || !part) return NULL;
496 if (!strcmp(part, "icon"))
497 return _elm_tickernoti_icon_unset(obj);
498 else if (!strcmp(part, "button"))
499 return _elm_tickernoti_button_unset(obj);
504 elm_tickernoti_add(Evas_Object *parent)
510 wd = ELM_NEW(Widget_Data);
511 wd->win = _create_window(parent, "noti-window");
513 e = evas_object_evas_get(wd->win);
514 obj = elm_widget_add(e);
515 ELM_SET_WIDTYPE(widtype, "tickernoti");
516 elm_widget_type_set(obj, widtype);
517 elm_widget_sub_object_add(wd->win, obj);
518 elm_widget_data_set(obj, wd);
519 elm_widget_del_hook_set(obj, _del_hook);
520 elm_widget_theme_hook_set(obj, _theme_hook);
521 elm_widget_can_focus_set(obj, 0);
522 elm_widget_disable_hook_set(obj, _disable_hook);
524 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
526 _create_tickernoti(obj);
527 elm_widget_text_set_hook_set(obj, _elm_tickernoti_label_set);
528 elm_widget_text_get_hook_set(obj, _elm_tickernoti_label_get);
529 elm_widget_content_set_hook_set(obj, _elm_tickernoti_content_part_set_hook);
530 elm_widget_content_get_hook_set(obj, _elm_tickernoti_content_part_get_hook);
531 elm_widget_content_unset_hook_set(obj, _elm_tickernoti_content_part_unset_hook);
532 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, NULL);
534 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, NULL);
535 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide, NULL);
536 evas_object_smart_callbacks_descriptions_set(obj, _signals);
541 elm_tickernoti_rotation_get(const Evas_Object *obj)
543 ELM_CHECK_WIDTYPE(obj, widtype) -1;
544 Widget_Data *wd = elm_widget_data_get(obj);
550 elm_tickernoti_rotation_set(Evas_Object *obj, int angle)
552 ELM_CHECK_WIDTYPE(obj, widtype);
553 Widget_Data *wd = elm_widget_data_get(obj);
556 if (angle % 90) return;
558 if (angle < 0) angle += 360;
560 elm_win_rotation_set(wd->win, angle);
565 elm_tickernoti_orient_set(Evas_Object *obj, Elm_Tickernoti_Orient orient)
567 ELM_CHECK_WIDTYPE(obj, widtype);
569 #ifdef HAVE_ELEMENTARY_X
570 Evas_Coord root_w, root_h;
572 Widget_Data *wd = elm_widget_data_get(obj);
575 if (orient >= ELM_TICKERNOTI_ORIENT_LAST) return;
577 #ifdef HAVE_ELEMENTARY_X
578 ecore_x_window_size_get(ecore_x_window_root_first_get(), &root_w, &root_h);
582 case ELM_TICKERNOTI_ORIENT_BOTTOM:
583 #ifdef HAVE_ELEMENTARY_X
584 evas_object_move(wd->win, 0, root_h - wd->noti_height);
586 wd->orient = ELM_TICKERNOTI_ORIENT_BOTTOM;
588 case ELM_TICKERNOTI_ORIENT_TOP:
590 #ifdef HAVE_ELEMENTARY_X
591 evas_object_move(wd->win, 0, 0);
593 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
596 #ifdef HAVE_ELEMENTARY_X
597 _update_window_hints(wd->win);
601 EAPI Elm_Tickernoti_Orient
602 elm_tickernoti_orient_get(const Evas_Object *obj)
604 ELM_CHECK_WIDTYPE(obj, widtype) -1;
605 Widget_Data *wd = elm_widget_data_get(obj);
607 if (!wd) return ELM_TICKERNOTI_ORIENT_LAST;
612 elm_tickernoti_win_get(const Evas_Object *obj)
614 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
615 Widget_Data *wd = elm_widget_data_get(obj);
616 if (!wd) return NULL;
621 elm_tickernoti_detailview_label_set(Evas_Object *obj, const char *label)
623 _elm_tickernoti_label_set(obj, NULL, label);
627 elm_tickernoti_detailview_label_get(const Evas_Object *obj)
629 return _elm_tickernoti_label_get(obj, NULL);
633 elm_tickernoti_detailview_button_set(Evas_Object *obj, Evas_Object *button)
635 _elm_tickernoti_button_set(obj, button);
639 elm_tickernoti_detailview_button_get(const Evas_Object *obj)
641 return _elm_tickernoti_button_get(obj);
645 elm_tickernoti_detailview_icon_set(Evas_Object *obj, Evas_Object *icon)
647 _elm_tickernoti_icon_set(obj, icon);
651 elm_tickernoti_detailview_icon_get(const Evas_Object *obj)
653 return _elm_tickernoti_icon_get(obj);
656 EAPI Elm_Tickernoti_Mode
657 elm_tickernoti_mode_get(const Evas_Object *obj)
659 ELM_CHECK_WIDTYPE(obj, widtype) -1;
660 Widget_Data *wd = elm_widget_data_get(obj);
666 elm_tickernoti_mode_set(Evas_Object *obj, Elm_Tickernoti_Mode mode)
668 ELM_CHECK_WIDTYPE(obj, widtype);
669 Widget_Data *wd = elm_widget_data_get(obj);
673 case ELM_TICKERNOTI_DEFAULT:
674 case ELM_TICKERNOTI_DETAILVIEW:
683 elm_tickernoti_detailview_get(const Evas_Object *obj)
685 return elm_tickernoti_win_get(obj);
689 elm_tickernoti_orientation_set(Evas_Object *obj, Elm_Tickernoti_Orient orient)
691 elm_tickernoti_orient_set(obj, orient);
694 EAPI Elm_Tickernoti_Orient
695 elm_tickernoti_orientation_get(const Evas_Object *obj)
697 return elm_tickernoti_orient_get(obj);
701 elm_tickernoti_label_set(Evas_Object *obj, const char *label)
703 _elm_tickernoti_label_set(obj, NULL, label);
707 elm_tickernoti_label_get(const Evas_Object *obj)
709 return _elm_tickernoti_label_get(obj, NULL);
713 elm_tickernoti_button_set(Evas_Object *obj, Evas_Object *button)
715 _elm_tickernoti_button_set(obj, button);
719 elm_tickernoti_button_get(const Evas_Object *obj)
721 return _elm_tickernoti_button_get(obj);
725 elm_tickernoti_icon_set(Evas_Object *obj, Evas_Object *icon)
727 _elm_tickernoti_icon_set(obj, icon);
731 elm_tickernoti_icon_get(const Evas_Object *obj)
733 return _elm_tickernoti_icon_get(obj);