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);
34 static const char SIG_CLICKED[] = "clicked";
35 static const char SIG_HIDDEN[] = "hide";
36 static const Evas_Smart_Cb_Description _signals[] = {
44 evas_object_del(data);
48 _del_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
55 p = elm_widget_parent_get(obj);
56 if (wd->win) ecore_job_add (_del_job, p);
58 evas_object_del (wd->edje_obj);
65 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
67 Widget_Data *wd = elm_widget_data_get(obj);
70 edje_object_mirrored_set(wd->edje_obj, rtl);
74 _theme_hook(Evas_Object *obj)
76 char *data_win_height = NULL;
78 Widget_Data *wd = elm_widget_data_get(obj);
81 _elm_widget_mirrored_reload(obj);
82 _mirrored_set(obj, elm_widget_mirrored_get(obj));
84 _elm_theme_object_set (wd->win, wd->edje_obj, "tickernoti",
85 "base", elm_widget_style_get(obj));
87 edje_object_scale_set (wd->edje_obj, elm_widget_scale_get(obj) * _elm_config->scale);
89 /* tickernoti detail height set */
90 data_win_height = (char *)edje_object_data_get (wd->edje_obj, "height");
91 if (data_win_height != NULL && elm_scale_get() > 0.0)
92 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
94 evas_object_geometry_get(wd->win, NULL, NULL, &w, NULL);
95 evas_object_resize (wd->win, w, wd->noti_height);
98 edje_object_part_text_set(wd->edje_obj, "elm.text", wd->label);
100 edje_object_part_swallow (wd->edje_obj, "icon", wd->icon);
102 edje_object_part_swallow (wd->edje_obj, "button", wd->button);
103 edje_object_signal_emit (wd->edje_obj, "effect,show", "elm");
104 edje_object_message_signal_process(wd->edje_obj);
110 _sizing_eval(Evas_Object *obj)
112 Widget_Data *wd = elm_widget_data_get(obj);
113 Evas_Coord minw = -1, minh = -1;
116 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
117 edje_object_size_min_restricted_calc(wd->edje_obj, &minw, &minh, minw, minh);
118 evas_object_size_hint_min_set(obj, minw, minh);
121 #ifdef HAVE_ELEMENTARY_X
123 _update_window_hints (Evas_Object *obj)
126 Ecore_X_Atom _notification_level_atom;
128 /* elm_win_xwindow_get() must call after elm_win_alpha_set() */
129 xwin = elm_win_xwindow_get (obj);
131 ecore_x_icccm_hints_set(xwin, 0, ECORE_X_WINDOW_STATE_HINT_NONE, 0, 0, 0, 0, 0);
132 ecore_x_netwm_window_type_set (xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
133 ecore_x_netwm_opacity_set(xwin, 0);
134 /* Create atom for notification level */
135 _notification_level_atom = ecore_x_atom_get ("_E_ILLUME_NOTIFICATION_LEVEL");
137 /* HIGH:150, NORMAL:100, LOW:50 */
140 /* Set notification level of the window */
141 ecore_x_window_prop_property_set (xwin, _notification_level_atom, ECORE_X_ATOM_CARDINAL, 32, &level, 1);
145 static void _hide_cb (void *data, Evas_Object *obj __UNUSED__,
146 const char *emission __UNUSED__,
147 const char *source __UNUSED__)
149 Widget_Data *wd = elm_widget_data_get(data);
152 evas_object_hide (wd->win);
153 evas_object_smart_callback_call (data, SIG_HIDDEN, NULL);
156 static void _clicked_cb (void *data, Evas_Object *obj __UNUSED__,
157 const char *emission __UNUSED__,
158 const char *source __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(data);
163 evas_object_smart_callback_call (data, SIG_CLICKED, NULL);
167 *_create_window (Evas_Object *parent, const char *name)
171 win = elm_win_add (parent, name, ELM_WIN_BASIC);
172 elm_win_title_set (win, name);
173 elm_win_borderless_set (win, EINA_TRUE);
174 elm_win_autodel_set (win, EINA_TRUE);
175 elm_win_alpha_set(win, EINA_TRUE);
177 #ifdef HAVE_ELEMENTARY_X
179 _update_window_hints (win);
185 _create_tickernoti (Evas_Object *obj)
187 #ifdef HAVE_ELEMENTARY_X
190 Widget_Data *wd = elm_widget_data_get(obj);
191 char *data_win_height = NULL;
196 evas_object_move (wd->win, 0, 0);
197 e = evas_object_evas_get (wd->win);
199 wd->edje_obj = edje_object_add (e);
200 _elm_theme_object_set (wd->win, wd->edje_obj, "tickernoti", "base", "default");
201 elm_win_resize_object_add (wd->win, wd->edje_obj);
203 /* tickernoti detail height set */
204 data_win_height = (char *)edje_object_data_get (wd->edje_obj, "height");
205 if (data_win_height != NULL && elm_scale_get() > 0.0)
206 wd->noti_height = (int)(elm_scale_get() * atoi(data_win_height));
208 #ifdef HAVE_ELEMENTARY_X
209 ecore_x_window_size_get (ecore_x_window_root_first_get(), &w, NULL);
210 evas_object_resize (wd->win, w, wd->noti_height);
213 edje_object_signal_callback_add(wd->edje_obj, "request,hide", "", _hide_cb, obj);
214 edje_object_signal_callback_add(wd->edje_obj, "clicked", "", _clicked_cb, obj);
215 evas_object_show (wd->edje_obj);
219 _disable_hook(Evas_Object *obj)
221 Widget_Data *wd = elm_widget_data_get(obj);
228 _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
229 void *event_info __UNUSED__)
231 Widget_Data *wd = elm_widget_data_get(obj);
234 #ifdef HAVE_ELEMENTARY_X
235 _update_window_hints (wd->win);
237 evas_object_show (wd->win);
238 edje_object_signal_emit (wd->edje_obj, "effect,show", "elm");
239 edje_object_message_signal_process(wd->edje_obj);
243 _hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
244 void *event_info __UNUSED__)
246 Widget_Data *wd = elm_widget_data_get(obj);
249 evas_object_hide (obj);
250 evas_object_hide (wd->win);
253 static void _tickernoti_hide_cb (void *data, Evas_Object *obj __UNUSED__,
254 void *event_info __UNUSED__)
256 Widget_Data *wd = data;
260 edje_object_signal_emit (wd->edje_obj, "effect,hide", "elm");
261 edje_object_message_signal_process(wd->edje_obj);
265 * Add a tickernoti object to @p parent
267 * @param parent The parent object
269 * @return The tickernoti object, or NULL upon failure
271 * @ingroup TickerNoti
274 elm_tickernoti_add(Evas_Object *parent)
280 wd = ELM_NEW(Widget_Data);
281 wd->win = _create_window (parent, "noti-window");
283 e = evas_object_evas_get(wd->win);
284 obj = elm_widget_add(e);
285 ELM_SET_WIDTYPE(widtype, "tickernoti");
286 elm_widget_type_set(obj, "tickernoti");
287 elm_widget_sub_object_add(wd->win, obj);
288 elm_widget_data_set(obj, wd);
289 elm_widget_del_hook_set(obj, _del_hook);
290 elm_widget_theme_hook_set(obj, _theme_hook);
291 elm_widget_can_focus_set(obj, 0);
292 elm_widget_disable_hook_set(obj, _disable_hook);
294 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
296 _create_tickernoti (obj);
298 evas_object_event_callback_add (obj, EVAS_CALLBACK_SHOW, _show, NULL);
299 evas_object_event_callback_add (obj, EVAS_CALLBACK_HIDE, _hide, NULL);
300 evas_object_smart_callbacks_descriptions_set(obj, _signals);
305 * Set the label on the tickernoti object
307 * @param obj The tickernoti object
308 * @param label The label will be used on the tickernoti object
310 * @ingroup TickerNoti
313 elm_tickernoti_label_set (Evas_Object *obj, const char *label)
315 ELM_CHECK_WIDTYPE(obj, widtype);
316 Widget_Data *wd = elm_widget_data_get(obj);
319 eina_stringshare_replace(&wd->label, label);
320 edje_object_part_text_set(wd->edje_obj, "elm.text", wd->label);
325 * Get the label used on the tickernoti object
327 * @param obj The tickernotil object
328 * @return The string inside the label
329 * @ingroup TickerNoti
332 elm_tickernoti_label_get (const Evas_Object *obj)
334 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
335 Widget_Data *wd = elm_widget_data_get(obj);
336 if (!wd) return NULL;
342 * Set the action button object used on the tickernoti object
344 * @param obj The tickernotil object
345 * @param button The button object will be used on the tickernoti object
346 * @ingroup TickerNoti
349 elm_tickernoti_button_set (Evas_Object *obj, Evas_Object *button)
351 ELM_CHECK_WIDTYPE(obj, widtype);
352 Widget_Data *wd = elm_widget_data_get(obj);
355 edje_object_part_swallow (wd->edje_obj, "button", button);
357 evas_object_smart_callback_add (wd->button, "clicked", _tickernoti_hide_cb, wd);
361 * Get the action button object used on the tickernoti object
363 * @param obj The tickernotil object
364 * @return The button object inside the tickernoti
365 * @ingroup TickerNoti
368 elm_tickernoti_button_get (const Evas_Object *obj)
370 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
371 Widget_Data *wd = elm_widget_data_get(obj);
372 if (!wd) return NULL;
377 * Set the icon object of the tickernoti object
379 * @param obj The tickernotil object
380 * @param icon The icon object will be used on the tickernoti object
381 * @ingroup TickerNoti
384 elm_tickernoti_icon_set (Evas_Object *obj, Evas_Object *icon)
386 ELM_CHECK_WIDTYPE(obj, widtype);
387 Widget_Data *wd = elm_widget_data_get(obj);
391 edje_object_part_swallow (wd->edje_obj, "icon", icon);
396 * Get the icon object of the tickernoti object
398 * @param obj The tickernotil object
399 * @return The icon object inside the tickernoti
400 * @ingroup TickerNoti
403 elm_tickernoti_icon_get (const Evas_Object *obj)
405 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
406 Widget_Data *wd = elm_widget_data_get(obj);
407 if (!wd) return NULL;
412 * Get the rotation of tickernoti object
414 * @param obj The tickernotil object
415 * @return The rotation angle
416 * @ingroup TickerNoti
419 elm_tickernoti_rotation_get (const Evas_Object *obj)
421 ELM_CHECK_WIDTYPE(obj, widtype) -1;
422 Widget_Data *wd = elm_widget_data_get(obj);
428 * Set the rotation angle for the tickernoti object
430 * @param obj The tickernoti object
431 * @param angle The rotation angle(in degree) will be used on the tickernoti object
432 * @ingroup TickerNoti
435 elm_tickernoti_rotation_set (Evas_Object *obj, int angle)
437 ELM_CHECK_WIDTYPE(obj, widtype);
438 Widget_Data *wd = elm_widget_data_get(obj);
439 Evas_Coord w, x = 0, y = 0;
442 if (angle%90 != 0) return;
444 wd->angle = angle%360;
446 wd->angle = 360 + wd->angle;
448 #ifdef HAVE_ELEMENTARY_X
449 Evas_Coord root_w, root_h;
452 * manual calculate win_tickernoti_indi window position & size
453 * - win_indi is not full size window
455 ecore_x_window_size_get (ecore_x_window_root_first_get(), &root_w, &root_h);
462 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
463 x = root_w-wd->noti_height;
467 if (!(wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM))
468 x = root_w-wd->noti_height;
472 if (!wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
473 y = root_h - wd->noti_height;
478 if (wd->orient == ELM_TICKERNOTI_ORIENT_BOTTOM)
479 y = root_h - wd->noti_height;
484 elm_win_rotation_with_resize_set (wd->win, wd->angle);
485 evas_object_move (wd->win, x, y);
487 evas_object_resize (wd->win, w, wd->noti_height);
488 #ifdef HAVE_ELEMENTARY_X
489 _update_window_hints (wd->win);
494 * Set the orientation of the tickernoti object
496 * @param obj The tickernoti object
497 * @param orient The orientation of tickernoti object
498 * @ingroup TickerNoti
501 elm_tickernoti_orientation_set (Evas_Object *obj, Elm_Tickernoti_Orient orient)
503 ELM_CHECK_WIDTYPE(obj, widtype);
505 #ifdef HAVE_ELEMENTARY_X
506 Evas_Coord root_w, root_h;
508 Widget_Data *wd = elm_widget_data_get(obj);
512 #ifdef HAVE_ELEMENTARY_X
513 ecore_x_window_size_get (ecore_x_window_root_first_get(), &root_w, &root_h);
517 case ELM_TICKERNOTI_ORIENT_BOTTOM:
518 #ifdef HAVE_ELEMENTARY_X
519 evas_object_move (wd->win, 0, root_h - wd->noti_height);
521 wd->orient = ELM_TICKERNOTI_ORIENT_BOTTOM;
523 case ELM_TICKERNOTI_ORIENT_TOP:
525 #ifdef HAVE_ELEMENTARY_X
526 evas_object_move (wd->win, 0, 0);
528 wd->orient = ELM_TICKERNOTI_ORIENT_TOP;
534 * Get the orientation of the tickernoti object
536 * @param obj The tickernotil object
537 * @return The orientation of tickernotil object
538 * @ingroup TickerNoti
540 EAPI Elm_Tickernoti_Orient
541 elm_tickernoti_orientation_get (const Evas_Object *obj)
543 ELM_CHECK_WIDTYPE(obj, widtype) -1;
544 Widget_Data *wd = elm_widget_data_get(obj);
550 // ################### Below APIs are going to be removed. ###########################
552 * Set the detail label on the tickernoti object
554 * @param obj The tickernoti object
555 * @param label The label will be used on the tickernoti object
557 * @ingroup TickerNoti
560 elm_tickernoti_detailview_label_set (Evas_Object *obj, const char *label)
562 elm_tickernoti_label_set (obj, label);
566 * Get the detail label used on the tickernoti object
568 * @param obj The tickernotil object
569 * @return The string inside the label
570 * @ingroup TickerNoti
573 elm_tickernoti_detailview_label_get (const Evas_Object *obj)
575 return elm_tickernoti_label_get (obj);
579 * Set the button object used on the tickernoti object
581 * @param obj The tickernotil object
582 * @param button The button object will be used on the tickernoti object
583 * @ingroup TickerNoti
586 elm_tickernoti_detailview_button_set (Evas_Object *obj, Evas_Object *button)
588 elm_tickernoti_button_set (obj, button);
593 * Get the button object used on the tickernoti object
595 * @param obj The tickernotil object
596 * @return The button object inside the tickernoti
597 * @ingroup TickerNoti
600 elm_tickernoti_detailview_button_get (const Evas_Object *obj)
602 return elm_tickernoti_button_get (obj);
608 * Set the detail icon object used on the tickernoti object
610 * @param obj The tickernotil object
611 * @param icon The icon object will be used on the tickernoti object
612 * @ingroup TickerNoti
615 elm_tickernoti_detailview_icon_set (Evas_Object *obj, Evas_Object *icon)
617 elm_tickernoti_icon_set (obj, icon);
621 * Get the detail icon object used on the tickernoti object
623 * @param obj The tickernotil object
624 * @return The icon object inside the tickernoti
625 * @ingroup TickerNoti
628 elm_tickernoti_detailview_icon_get (const Evas_Object *obj)
630 return elm_tickernoti_icon_get (obj);
634 * Get the view mode on the tickernoti object
636 * @param obj The tickernotil object
637 * @return The view mode
638 * @ingroup TickerNoti
640 EAPI Elm_Tickernoti_Mode
641 elm_tickernoti_mode_get (const Evas_Object *obj)
643 ELM_CHECK_WIDTYPE(obj, widtype) -1;
644 Widget_Data *wd = elm_widget_data_get(obj);
650 * Set the view mode used on the tickernoti object
652 * @param obj The tickernotil object
653 * @param mode The view mode will be used on the tickernoti object
654 * @ingroup TickerNoti
657 elm_tickernoti_mode_set (Evas_Object *obj, Elm_Tickernoti_Mode mode)
659 ELM_CHECK_WIDTYPE(obj, widtype);
660 Widget_Data *wd = elm_widget_data_get(obj);
664 case ELM_TICKERNOTI_DEFAULT:
665 case ELM_TICKERNOTI_DETAILVIEW:
674 * Get the detail view window(elm_win) on the tickernoti object
676 * @param obj The tickernotil object
677 * @return detail view window(elm_win) object
678 * @ingroup TickerNoti
681 elm_tickernoti_win_get (const Evas_Object *obj)
683 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
684 Widget_Data *wd = elm_widget_data_get(obj);
685 if (!wd) return NULL;
690 * Get the detail view window(elm_win) on the tickernoti object
692 * @param obj The tickernotil object
693 * @return detail view window(elm_win) object
694 * @ingroup TickerNoti
697 elm_tickernoti_detailview_get (const Evas_Object *obj)
699 return elm_tickernoti_win_get (obj);