1 #include <Elementary.h>
5 * @defgroup TickerNoti TickerNoti
8 * This is a notification widget which can be used to display some short information.
11 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *edje_obj;
25 Elm_Tickernoti_Mode mode;
26 Elm_Tickernoti_Orient orient;
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
37 evas_object_del(data);
41 _del_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
48 p = elm_widget_parent_get(obj);
49 if (wd->win) ecore_job_add (_del_job, p);
51 evas_object_del (wd->edje_obj);
58 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
60 Widget_Data *wd = elm_widget_data_get(obj);
63 edje_object_mirrored_set(wd->edje_obj, rtl);
67 _theme_hook(Evas_Object *obj)
69 char *data_win_height = NULL;
71 Widget_Data *wd = elm_widget_data_get(obj);
74 _elm_widget_mirrored_reload(obj);
75 _mirrored_set(obj, elm_widget_mirrored_get(obj));
77 _elm_theme_object_set (wd->win, wd->edje_obj, "tickernoti",
78 "base", elm_widget_style_get(obj));
80 edje_object_scale_set (wd->edje_obj, elm_widget_scale_get(obj) * _elm_config->scale);
82 /* tickernoti detail height set */
83 data_win_height = (char *)edje_object_data_get (wd->edje_obj, "height");
84 if (data_win_height != NULL && elm_scale_get() > 0.0)
85 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
87 evas_object_geometry_get(wd->win, NULL, NULL, &w, NULL);
88 evas_object_resize (wd->win, w, wd->noti_height);
91 edje_object_part_text_set(wd->edje_obj, "elm.text", wd->label);
93 edje_object_part_swallow (wd->edje_obj, "icon", wd->icon);
95 edje_object_part_swallow (wd->edje_obj, "button", wd->button);
96 edje_object_signal_emit (wd->edje_obj, "effect,show", "elm");
97 edje_object_message_signal_process(wd->edje_obj);
103 _sizing_eval(Evas_Object *obj)
105 Widget_Data *wd = elm_widget_data_get(obj);
106 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
109 edje_object_size_min_calc(wd->win, &minw, &minh);
113 #ifdef HAVE_ELEMENTARY_X
115 _update_window_hints (Evas_Object *obj)
118 Ecore_X_Atom _notification_level_atom;
120 /* elm_win_xwindow_get() must call after elm_win_alpha_set() */
121 xwin = elm_win_xwindow_get (obj);
123 ecore_x_icccm_hints_set(xwin, 0, ECORE_X_WINDOW_STATE_HINT_NONE, 0, 0, 0, 0, 0);
124 ecore_x_netwm_window_type_set (xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
125 ecore_x_netwm_opacity_set(xwin, 0);
126 /* Create atom for notification level */
127 _notification_level_atom = ecore_x_atom_get ("_E_ILLUME_NOTIFICATION_LEVEL");
129 /* HIGH:150, NORMAL:100, LOW:50 */
132 /* Set notification level of the window */
133 ecore_x_window_prop_property_set (xwin, _notification_level_atom, ECORE_X_ATOM_CARDINAL, 32, &level, 1);
137 static void _hide_cb (void *data, Evas_Object *obj __UNUSED__,
138 const char *emission __UNUSED__,
139 const char *source __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(data);
144 evas_object_hide (wd->win);
145 evas_object_smart_callback_call (data, "hide", NULL);
149 *_create_window (Evas_Object *parent, const char *name)
153 win = elm_win_add (parent, name, ELM_WIN_BASIC);
154 elm_win_title_set (win, name);
155 elm_win_borderless_set (win, EINA_TRUE);
156 elm_win_autodel_set (win, EINA_TRUE);
157 elm_win_alpha_set(win, EINA_TRUE);
159 #ifdef HAVE_ELEMENTARY_X
161 _update_window_hints (win);
167 _create_tickernoti (Evas_Object *obj)
169 #ifdef HAVE_ELEMENTARY_X
172 Widget_Data *wd = elm_widget_data_get(obj);
173 char *data_win_height = NULL;
178 evas_object_move (wd->win, 0, 0);
179 e = evas_object_evas_get (wd->win);
181 wd->edje_obj = edje_object_add (e);
182 _elm_theme_object_set (wd->win, wd->edje_obj, "tickernoti", "base", "default");
183 elm_win_resize_object_add (wd->win, wd->edje_obj);
185 /* tickernoti detail height set */
186 data_win_height = (char *)edje_object_data_get (wd->edje_obj, "height");
187 if (data_win_height != NULL && elm_scale_get() > 0.0)
188 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
190 #ifdef HAVE_ELEMENTARY_X
191 ecore_x_window_size_get (ecore_x_window_root_first_get(), &w, NULL);
192 evas_object_resize (wd->win, w, wd->noti_height);
195 edje_object_signal_callback_add(wd->edje_obj, "request,hide", "", _hide_cb, obj);
196 evas_object_show (wd->edje_obj);
200 _disable_hook(Evas_Object *obj)
202 Widget_Data *wd = elm_widget_data_get(obj);
209 _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
210 void *event_info __UNUSED__)
212 Widget_Data *wd = elm_widget_data_get(obj);
215 #ifdef HAVE_ELEMENTARY_X
216 _update_window_hints (wd->win);
218 evas_object_show (wd->win);
219 edje_object_signal_emit (wd->edje_obj, "effect,show", "elm");
220 edje_object_message_signal_process(wd->edje_obj);
224 _hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
225 void *event_info __UNUSED__)
227 Widget_Data *wd = elm_widget_data_get(obj);
230 evas_object_hide (obj);
231 evas_object_hide (wd->win);
234 static void _tickernoti_hide_cb (void *data, Evas_Object *obj __UNUSED__,
235 void *event_info __UNUSED__)
237 Widget_Data *wd = data;
241 edje_object_signal_emit (wd->edje_obj, "effect,hide", "elm");
242 edje_object_message_signal_process(wd->edje_obj);
246 * Add a tickernoti object to @p parent
248 * @param parent The parent object
250 * @return The tickernoti object, or NULL upon failure
252 * @ingroup TickerNoti
255 elm_tickernoti_add(Evas_Object *parent)
261 wd = ELM_NEW(Widget_Data);
262 wd->win = _create_window (parent, "noti-window");
264 e = evas_object_evas_get(wd->win);
265 obj = elm_widget_add(e);
266 ELM_SET_WIDTYPE(widtype, "tickernoti");
267 elm_widget_type_set(obj, "tickernoti");
268 elm_widget_sub_object_add(wd->win, obj);
269 elm_widget_data_set(obj, wd);
270 elm_widget_del_hook_set(obj, _del_hook);
271 elm_widget_theme_hook_set(obj, _theme_hook);
272 elm_widget_can_focus_set(obj, 0);
273 elm_widget_disable_hook_set(obj, _disable_hook);
275 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
277 _create_tickernoti (obj);
279 evas_object_event_callback_add (obj, EVAS_CALLBACK_SHOW, _show, NULL);
280 evas_object_event_callback_add (obj, EVAS_CALLBACK_HIDE, _hide, NULL);
286 * Set the label on the tickernoti object
288 * @param obj The tickernoti object
289 * @param label The label will be used on the tickernoti object
291 * @ingroup TickerNoti
294 elm_tickernoti_label_set (Evas_Object *obj, const char *label)
296 ELM_CHECK_WIDTYPE(obj, widtype);
297 Widget_Data *wd = elm_widget_data_get(obj);
300 eina_stringshare_replace(&wd->label, label);
301 edje_object_part_text_set(wd->edje_obj, "elm.text", wd->label);
306 * Get the label used on the tickernoti object
308 * @param obj The tickernotil object
309 * @return The string inside the label
310 * @ingroup TickerNoti
313 elm_tickernoti_label_get (const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return NULL;
323 * Set the action button object used on the tickernoti object
325 * @param obj The tickernotil object
326 * @param button The button object will be used on the tickernoti object
327 * @ingroup TickerNoti
330 elm_tickernoti_button_set (Evas_Object *obj, Evas_Object *button)
332 ELM_CHECK_WIDTYPE(obj, widtype);
333 Widget_Data *wd = elm_widget_data_get(obj);
336 edje_object_part_swallow (wd->edje_obj, "button", button);
338 evas_object_smart_callback_add (wd->button, "clicked", _tickernoti_hide_cb, wd);
342 * Get the action button object used on the tickernoti object
344 * @param obj The tickernotil object
345 * @return The button object inside the tickernoti
346 * @ingroup TickerNoti
349 elm_tickernoti_button_get (const Evas_Object *obj)
351 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
352 Widget_Data *wd = elm_widget_data_get(obj);
353 if (!wd) return NULL;
358 * Set the icon object of the tickernoti object
360 * @param obj The tickernotil object
361 * @param icon The icon object will be used on the tickernoti object
362 * @ingroup TickerNoti
365 elm_tickernoti_icon_set (Evas_Object *obj, Evas_Object *icon)
367 ELM_CHECK_WIDTYPE(obj, widtype);
368 Widget_Data *wd = elm_widget_data_get(obj);
372 edje_object_part_swallow (wd->edje_obj, "icon", icon);
377 * Get the icon object of the tickernoti object
379 * @param obj The tickernotil object
380 * @return The icon object inside the tickernoti
381 * @ingroup TickerNoti
384 elm_tickernoti_icon_get (const Evas_Object *obj)
386 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
387 Widget_Data *wd = elm_widget_data_get(obj);
388 if (!wd) return NULL;
393 * Get the rotation of tickernoti object
395 * @param obj The tickernotil object
396 * @return The rotation angle
397 * @ingroup TickerNoti
400 elm_tickernoti_rotation_get (const Evas_Object *obj)
402 ELM_CHECK_WIDTYPE(obj, widtype) -1;
403 Widget_Data *wd = elm_widget_data_get(obj);
409 * Set the rotation angle for the tickernoti object
411 * @param obj The tickernoti object
412 * @param angle The rotation angle(in degree) will be used on the tickernoti object
413 * @ingroup TickerNoti
416 elm_tickernoti_rotation_set (Evas_Object *obj, int angle)
418 ELM_CHECK_WIDTYPE(obj, widtype);
419 Widget_Data *wd = elm_widget_data_get(obj);
420 Evas_Coord w, x = 0, y = 0;
423 if (angle%90 != 0) return;
425 wd->angle = angle%360;
427 wd->angle = 360 + wd->angle;
429 #ifdef HAVE_ELEMENTARY_X
430 Evas_Coord root_w, root_h;
433 * manual calculate win_tickernoti_indi window position & size
434 * - win_indi is not full size window (480 x 27)
436 ecore_x_window_size_get (ecore_x_window_root_first_get(), &root_w, &root_h);
443 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
444 x = root_w-wd->noti_height;
448 if (!(wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM))
449 x = root_w-wd->noti_height;
453 if (!wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
454 y = root_h - wd->noti_height;
459 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
460 y = root_h - wd->noti_height;
465 elm_win_rotation_with_resize_set (wd->win, wd->angle);
466 evas_object_move (wd->win, x, y);
468 evas_object_resize (wd->win, w, wd->noti_height);
469 #ifdef HAVE_ELEMENTARY_X
470 _update_window_hints (wd->win);
475 * Set the orientation of the tickernoti object
477 * @param obj The tickernoti object
478 * @param orient The orientation of tickernoti object
479 * @ingroup TickerNoti
482 elm_tickernoti_orientation_set (Evas_Object *obj, Elm_Tickernoti_Orient orient)
484 ELM_CHECK_WIDTYPE(obj, widtype);
486 #ifdef HAVE_ELEMENTARY_X
487 Evas_Coord root_w, root_h;
489 Widget_Data *wd = elm_widget_data_get(obj);
493 #ifdef HAVE_ELEMENTARY_X
494 ecore_x_window_size_get (ecore_x_window_root_first_get(), &root_w, &root_h);
498 case ELM_TICKERNOTI_ORIENT_BOTTOM:
499 #ifdef HAVE_ELEMENTARY_X
500 evas_object_move (wd->win, 0, root_h - wd->noti_height);
502 wd->orient = ELM_TICKERNOTI_ORIENT_BOTTOM;
504 case ELM_TICKERNOTI_ORIENT_TOP:
506 #ifdef HAVE_ELEMENTARY_X
507 evas_object_move (wd->win, 0, 0);
509 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
515 * Get the orientation of the tickernoti object
517 * @param obj The tickernotil object
518 * @return The orientation of tickernotil object
519 * @ingroup TickerNoti
521 EAPI Elm_Tickernoti_Orient
522 elm_tickernoti_orientation_get (const Evas_Object *obj)
524 ELM_CHECK_WIDTYPE(obj, widtype) -1;
525 Widget_Data *wd = elm_widget_data_get(obj);
531 // ################### Below APIs are going to be removed. ###########################
533 * Set the detail label on the tickernoti object
535 * @param obj The tickernoti object
536 * @param label The label will be used on the tickernoti object
538 * @ingroup TickerNoti
541 elm_tickernoti_detailview_label_set (Evas_Object *obj, const char *label)
543 elm_tickernoti_label_set (obj, label);
547 * Get the detail label used on the tickernoti object
549 * @param obj The tickernotil object
550 * @return The string inside the label
551 * @ingroup TickerNoti
554 elm_tickernoti_detailview_label_get (const Evas_Object *obj)
556 return elm_tickernoti_label_get (obj);
560 * Set the button object used on the tickernoti object
562 * @param obj The tickernotil object
563 * @param button The button object will be used on the tickernoti object
564 * @ingroup TickerNoti
567 elm_tickernoti_detailview_button_set (Evas_Object *obj, Evas_Object *button)
569 elm_tickernoti_button_set (obj, button);
574 * Get the button object used on the tickernoti object
576 * @param obj The tickernotil object
577 * @return The button object inside the tickernoti
578 * @ingroup TickerNoti
581 elm_tickernoti_detailview_button_get (const Evas_Object *obj)
583 return elm_tickernoti_button_get (obj);
589 * Set the detail icon object used on the tickernoti object
591 * @param obj The tickernotil object
592 * @param icon The icon object will be used on the tickernoti object
593 * @ingroup TickerNoti
596 elm_tickernoti_detailview_icon_set (Evas_Object *obj, Evas_Object *icon)
598 elm_tickernoti_icon_set (obj, icon);
602 * Get the detail icon object used on the tickernoti object
604 * @param obj The tickernotil object
605 * @return The icon object inside the tickernoti
606 * @ingroup TickerNoti
609 elm_tickernoti_detailview_icon_get (const Evas_Object *obj)
611 return elm_tickernoti_icon_get (obj);
615 * Get the view mode on the tickernoti object
617 * @param obj The tickernotil object
618 * @return The view mode
619 * @ingroup TickerNoti
621 EAPI Elm_Tickernoti_Mode
622 elm_tickernoti_mode_get (const Evas_Object *obj)
624 ELM_CHECK_WIDTYPE(obj, widtype) -1;
625 Widget_Data *wd = elm_widget_data_get(obj);
631 * Set the view mode used on the tickernoti object
633 * @param obj The tickernotil object
634 * @param mode The view mode will be used on the tickernoti object
635 * @ingroup TickerNoti
638 elm_tickernoti_mode_set (Evas_Object *obj, Elm_Tickernoti_Mode mode)
640 ELM_CHECK_WIDTYPE(obj, widtype);
641 Widget_Data *wd = elm_widget_data_get(obj);
645 case ELM_TICKERNOTI_DEFAULT:
646 case ELM_TICKERNOTI_DETAILVIEW:
655 * Get the detail view window(elm_win) on the tickernoti object
657 * @param obj The tickernotil object
658 * @return detail view window(elm_win) object
659 * @ingroup TickerNoti
662 elm_tickernoti_win_get (const Evas_Object *obj)
664 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
665 Widget_Data *wd = elm_widget_data_get(obj);
666 if (!wd) return NULL;
671 * Get the detail view window(elm_win) on the tickernoti object
673 * @param obj The tickernotil object
674 * @return detail view window(elm_win) object
675 * @ingroup TickerNoti
678 elm_tickernoti_detailview_get (const Evas_Object *obj)
680 return elm_tickernoti_win_get (obj);