[elm_searchbar & elm_tickernoti] Indentation correction.
[framework/uifw/elementary.git] / src / lib / elm_tickernoti.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup TickerNoti TickerNoti
6  * @ingroup Elementary
7  *
8  */
9
10 typedef struct _Widget_Data Widget_Data;
11
12 struct _Widget_Data
13 {
14    Evas_Object *win_indi;
15    Evas_Object *win_detail;
16    Evas_Object *edje_indi;
17    Evas_Object *edje_detail;
18    Evas_Object *icon_indi;
19    Evas_Object *icon_detail;
20    Evas_Object *button_detail;
21
22    const char *label_indi;
23    const char *label_detail;
24
25    int indicator_height;
26    int angle;
27
28    Elm_Tickernoti_Mode mode;
29 };
30
31 static const char *widtype = NULL;
32 static void _del_hook(Evas_Object *obj);
33 static void _theme_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35
36 static void
37 _del_job(void *data)
38 {
39    Evas_Object *obj = data;
40    evas_object_del(obj);
41 }
42
43 static void
44 _del_hook(Evas_Object *obj)
45 {
46    Widget_Data *wd = elm_widget_data_get(obj);
47    if (!wd) return;
48
49    Evas_Object *p = elm_widget_parent_get(obj);
50    if (p == wd->win_indi) ecore_job_add (_del_job, p);
51    
52    evas_object_del (wd->edje_indi);
53    wd->edje_indi = NULL;
54    evas_object_del (wd->edje_detail);
55    wd->edje_detail = NULL;
56    evas_object_del (wd->win_detail);
57    wd->win_detail = NULL;
58
59    free(wd);
60 }
61
62 static void
63 _theme_hook(Evas_Object *obj)
64 {
65    Widget_Data *wd = elm_widget_data_get(obj);
66    if (!wd) return;
67
68    _elm_theme_object_set (wd->win_indi, wd->edje_indi, "tickernoti", "base", elm_widget_style_get(obj));
69    _elm_theme_object_set (wd->edje_detail, wd->edje_detail, "tickernoti", "2line", elm_widget_style_get(obj));
70
71    edje_object_scale_set (wd->edje_indi, elm_widget_scale_get(obj) * _elm_config->scale);
72    edje_object_scale_set (wd->edje_detail, elm_widget_scale_get(obj) * _elm_config->scale);
73
74    _sizing_eval(obj);
75 }
76
77 static void
78 _sizing_eval(Evas_Object *obj)
79 {
80    Widget_Data *wd = elm_widget_data_get(obj);
81 //   Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
82    if (!wd) return;
83
84 /*
85    edje_object_size_min_calc(wd->win_detail, &minw, &minh);
86    evas_object_size_hint_min_set(obj, minw, minh);
87    evas_object_size_hint_max_set(obj, maxw, maxh);
88    evas_object_size_hint_align_set(obj, maxw, maxh);
89 */
90 }
91
92 static void
93 _make_notification_window (Evas_Object *obj)
94 {
95    Ecore_X_Window xwin;
96 /* elm_win_xwindow_get() must call after elm_win_alpha_set() */
97    xwin = elm_win_xwindow_get (obj);
98    ecore_x_netwm_window_type_set (xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
99 }
100
101 static void _detail_show_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
102 {
103    evas_object_smart_callback_call ((Evas_Object *)data, "detail,show", NULL);
104 }
105
106 static void _detail_hide_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
107 {
108    evas_object_smart_callback_call ((Evas_Object *)data, "detail,hide", NULL);
109 }
110
111 static Evas_Object 
112 *_create_window (Evas_Object *parent, const char *name)
113 {
114    Evas_Object *win;
115
116    win = elm_win_add (parent, name, ELM_WIN_BASIC);
117 /* Property */
118    elm_win_title_set (win, name);
119    elm_win_borderless_set (win, EINA_TRUE);
120    elm_win_autodel_set (win, EINA_TRUE);
121    elm_win_alpha_set (win, EINA_TRUE);
122
123 /* set top window */
124    _make_notification_window (win);
125    
126    return win;
127 }
128
129 static void 
130 _create_tickernoti_indi (Evas_Object *obj)
131 {
132    Widget_Data *wd = elm_widget_data_get(obj);
133    if (!wd) return;
134
135    Evas *e;
136    Evas_Coord w, h;
137
138    char *data_win_height = NULL; 
139
140    ecore_x_window_size_get (ecore_x_window_root_first_get(), &w, &h);
141
142    evas_object_move (wd->win_indi, 0, 0);
143
144    e = evas_object_evas_get (wd->win_indi);
145
146    wd->edje_indi = edje_object_add (e);
147    _elm_theme_object_set (wd->win_indi, wd->edje_indi, "tickernoti", "base", "default");
148    elm_win_resize_object_add (wd->win_indi, wd->edje_indi);
149
150    /* tickernoti indicator height set */
151    data_win_height = (char *)edje_object_data_get (wd->edje_indi, "height");
152    if (data_win_height != NULL && elm_scale_get() > 0.0) 
153      wd->indicator_height = (int)(elm_scale_get() * atoi(data_win_height));
154
155    evas_object_resize (wd->win_indi, w, wd->indicator_height);
156         
157    edje_object_signal_callback_add (wd->edje_indi, "request,detail,show", "", _detail_show_cb, obj);
158    evas_object_show (wd->edje_indi);
159 }
160
161 static void 
162 _create_tickernoti_detail (Evas_Object *obj)
163 {
164    Widget_Data *wd = elm_widget_data_get(obj);
165    if (!wd) return;
166
167    Evas *e;
168    Evas_Coord w, h;
169
170    ecore_x_window_size_get (ecore_x_window_root_first_get(), &w, &h);
171
172    evas_object_resize (wd->win_detail, w, h);
173    evas_object_move (wd->win_detail, 0, 0);
174
175    e = evas_object_evas_get (wd->win_detail);
176
177    wd->edje_detail = edje_object_add (e);
178    _elm_theme_object_set (wd->win_detail, wd->edje_detail, "tickernoti", "2line", "default");
179    elm_win_resize_object_add (wd->win_detail, wd->edje_detail);
180
181    edje_object_signal_callback_add(wd->edje_detail, "request,detail,hide", "", _detail_hide_cb, obj);
182    evas_object_show (wd->edje_detail);
183 }
184
185 static void
186 _show(void *data, Evas *e, Evas_Object *obj, void *event_info)
187 {  
188    Widget_Data *wd = elm_widget_data_get(obj);   
189    if (!wd) return;
190
191    if (wd->mode == ELM_TICKERNOTI_DEFAULT) 
192      {
193         evas_object_hide (wd->win_detail);
194         _make_notification_window (wd->win_indi);
195         evas_object_show (wd->win_indi);
196         edje_object_signal_emit (wd->edje_indi, "effect,show", "bg_1line");
197      }
198    else if (wd->mode == ELM_TICKERNOTI_DETAILVIEW) 
199      {
200         evas_object_hide (wd->win_indi);
201         _make_notification_window (wd->win_detail);
202         evas_object_show (wd->win_detail);
203         edje_object_signal_emit (wd->edje_detail, "effect,show", "bg_2line");
204      }
205 }
206
207 static void
208 _hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
209 {
210    Widget_Data *wd = elm_widget_data_get(obj);
211
212    if (!wd) return;
213    evas_object_hide (obj); 
214    evas_object_hide (wd->win_indi);
215    evas_object_hide (wd->win_detail);
216 }
217
218 /**
219  * Add a tickernoti object to @p parent
220  *
221  * @param parent The parent object
222  *
223  * @return The tickernoti object, or NULL upon failure
224  *
225  * @ingroup TickerNoti
226  */
227 EAPI Evas_Object *
228 elm_tickernoti_add(Evas_Object *parent)
229 {
230    Evas_Object *obj;
231    Evas *e;
232    Widget_Data *wd;
233
234    wd = ELM_NEW(Widget_Data);
235    wd->win_indi = _create_window (parent, "indi");
236    wd->win_detail = _create_window (parent, "detail");
237
238    if (!parent) parent = wd->win_indi;
239
240    e = evas_object_evas_get(parent);
241    obj = elm_widget_add(e);
242    ELM_SET_WIDTYPE(widtype, "tickernoti");
243    elm_widget_type_set(obj, "tickernoti");
244    elm_widget_sub_object_add(parent, obj);
245    elm_widget_data_set(obj, wd);
246    elm_widget_del_hook_set(obj, _del_hook);
247    elm_widget_theme_hook_set(obj, _theme_hook);
248    elm_widget_can_focus_set(obj, 0);
249
250    wd->edje_indi = NULL;
251    wd->edje_detail = NULL;
252    wd->icon_indi = NULL;
253    wd->icon_detail = NULL;
254    wd->button_detail = NULL;
255
256    wd->label_indi = NULL;
257    wd->label_detail = NULL;
258
259    wd->indicator_height = 0;
260    wd->angle = 0;
261
262    wd->mode = ELM_TICKERNOTI_DEFAULT;
263
264    _create_tickernoti_indi (obj);
265    _create_tickernoti_detail (obj);
266
267    evas_object_event_callback_add (obj, EVAS_CALLBACK_SHOW, _show, NULL);
268    evas_object_event_callback_add (obj, EVAS_CALLBACK_HIDE, _hide, NULL);
269
270    return obj;
271 }
272
273
274 /**
275  * Set the icon object used on the tickernoti object
276  *
277  * @param obj The tickernotil object
278  * @param icon The icon object will be used on the tickernoti object
279  * @ingroup TickerNoti
280  */
281 EAPI void 
282 elm_tickernoti_icon_set (const Evas_Object *obj, Evas_Object *icon)
283 {
284    ELM_CHECK_WIDTYPE(obj, widtype);
285    Widget_Data *wd = elm_widget_data_get(obj);
286    if (!wd) return;
287    if (!icon) return;
288    edje_object_part_swallow (wd->edje_indi, "icon", icon);
289    wd->icon_indi = icon;
290 }
291
292 /**
293  * Get the icon object used on the tickernoti object
294  *
295  * @param obj The tickernotil object
296  * @return The icon object inside the tickernoti
297  * @ingroup TickerNoti
298  */
299 EAPI Evas_Object *
300 elm_tickernoti_icon_get (const Evas_Object *obj)
301 {
302    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
303    Widget_Data *wd = elm_widget_data_get(obj);
304    if (!wd) return NULL;
305    return wd->icon_indi;
306 }
307
308 /**
309  * Set the label on the tickernoti object
310  *
311  * @param obj The tickernoti object
312  * @param label The label will be used on the tickernoti object
313  *
314  * @ingroup TickerNoti
315  */
316 EAPI void
317 elm_tickernoti_label_set (Evas_Object *obj, const char *label)
318 {
319    ELM_CHECK_WIDTYPE(obj, widtype);
320    Widget_Data *wd = elm_widget_data_get(obj);
321    if (!wd) return;
322    if (!label) label = "";
323    eina_stringshare_replace(&wd->label_indi, label);
324    edje_object_part_text_set(wd->edje_indi, "text", label);
325    _sizing_eval(obj);
326 }
327
328 /**
329  * Get the label used on the tickernoti object
330  *
331  * @param obj The tickernotil object
332  * @return The string inside the label
333  * @ingroup TickerNoti
334  */
335 EAPI const char *
336 elm_tickernoti_label_get (const Evas_Object *obj)
337 {
338    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
339    Widget_Data *wd = elm_widget_data_get(obj);
340    if (!wd) return NULL;
341    return wd->label_indi;
342 }
343
344 /**
345  * Set the detail label on the tickernoti object
346  *
347  * @param obj The tickernoti object
348  * @param label The label will be used on the tickernoti object
349  *
350  * @ingroup TickerNoti
351  */
352 EAPI void
353 elm_tickernoti_detailview_label_set (Evas_Object *obj, const char *label)
354 {
355    ELM_CHECK_WIDTYPE(obj, widtype);
356    Widget_Data *wd = elm_widget_data_get(obj);
357    if (!wd) return;
358    if (!label) label = "";
359    eina_stringshare_replace(&wd->label_detail, label);
360    edje_object_part_text_set(wd->edje_detail, "text", label);
361    _sizing_eval(obj);
362 }
363
364 /**
365  * Get the detail label used on the tickernoti object
366  *
367  * @param obj The tickernotil object
368  * @return The string inside the label
369  * @ingroup TickerNoti
370  */
371 EAPI const char *
372 elm_tickernoti_detailview_label_get (const Evas_Object *obj)
373 {
374    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
375    Widget_Data *wd = elm_widget_data_get(obj);
376    if (!wd) return NULL;
377    return wd->label_detail;
378 }
379
380 /**
381  * Set the button object used on the tickernoti object
382  *
383  * @param obj The tickernotil object
384  * @param button The button object will be used on the tickernoti object
385  * @ingroup TickerNoti
386  */
387 EAPI void 
388 elm_tickernoti_detailview_button_set (const Evas_Object *obj, Evas_Object *button)
389 {
390    ELM_CHECK_WIDTYPE(obj, widtype);
391    Widget_Data *wd = elm_widget_data_get(obj);
392    if (!wd) return;
393    if (!button) return;
394    edje_object_part_swallow (wd->edje_detail, "button", button);
395    wd->button_detail = button;
396 }
397
398 /**
399  * Get the button object used on the tickernoti object
400  *
401  * @param obj The tickernotil object
402  * @return The button object inside the tickernoti
403  * @ingroup TickerNoti
404  */
405 EAPI Evas_Object *
406 elm_tickernoti_detailview_button_get (const Evas_Object *obj)
407 {
408    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
409    Widget_Data *wd = elm_widget_data_get(obj);
410    if (!wd) return NULL;
411    return wd->button_detail;
412 }
413
414 /**
415  * Set the detail icon object used on the tickernoti object
416  *
417  * @param obj The tickernotil object
418  * @param icon The icon object will be used on the tickernoti object
419  * @ingroup TickerNoti
420  */
421 EAPI void 
422 elm_tickernoti_detailview_icon_set (const Evas_Object *obj, Evas_Object *icon)
423 {
424    ELM_CHECK_WIDTYPE(obj, widtype);
425    Widget_Data *wd = elm_widget_data_get(obj);
426    if (!wd) return;
427    if (!icon) return;
428    edje_object_part_swallow (wd->edje_detail, "icon", icon);
429    wd->icon_detail = icon;
430 }
431
432 /**
433  * Get the detail icon object used on the tickernoti object
434  *
435  * @param obj The tickernotil object
436  * @return The icon object inside the tickernoti
437  * @ingroup TickerNoti
438  */
439 EAPI Evas_Object *
440 elm_tickernoti_detailview_icon_get (const Evas_Object *obj)
441 {
442    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
443    Widget_Data *wd = elm_widget_data_get(obj);
444    if (!wd) return NULL;
445    return wd->icon_detail;
446 }
447
448 /**
449  * Get the rotation used on the tickernoti object
450  *
451  * @param obj The tickernotil object
452  * @return The rotation angle 
453  * @ingroup TickerNoti
454  */
455 EAPI int
456 elm_tickernoti_rotation_get (const Evas_Object *obj)
457 {
458    ELM_CHECK_WIDTYPE(obj, widtype) -1;
459    Widget_Data *wd = elm_widget_data_get(obj);
460    if (!wd) return -1;
461    return wd->angle;
462 }
463
464 /**
465  * Set the rotation used on the tickernoti object
466  *
467  * @param obj The tickernotil object
468  * @param angle The rotation angle will be used on the tickernoti object
469  * @ingroup TickerNoti
470  */
471 EAPI void
472 elm_tickernoti_rotation_set (const Evas_Object *obj, int angle)
473 {
474    ELM_CHECK_WIDTYPE(obj, widtype);
475    Widget_Data *wd = elm_widget_data_get(obj);
476    if (!wd) return;
477
478    Evas_Coord x, y, w, h;
479    Evas_Coord root_w, root_h;
480
481    /* 
482    * manual calculate win_tickernoti_indi window position & size 
483    *  - win_indi is not full size window (480 x 27)
484    */
485    ecore_x_window_size_get (ecore_x_window_root_first_get(), &root_w, &root_h);
486    evas_object_geometry_get (wd->win_indi, &x, &y, &w, &h);
487
488    /* rotate win */
489    switch (angle) 
490      {
491       case 90:
492          w = root_h;
493          h = wd->indicator_height;
494          x = 0;
495          y = 0;
496          break;
497       case -90:
498          w = root_h; 
499          h = wd->indicator_height;
500          x = root_w-h;
501          y = 0;
502          break;
503       case 180:
504          w = root_w;
505          h = wd->indicator_height;
506          x = 0;
507          y = root_h-h;
508          break;
509       default:
510       case 0:
511          w = root_w;
512          h = wd->indicator_height;
513          x = 0;
514          y = 0;
515          break;
516      }
517
518 /* indicator */
519    elm_win_rotation_with_resize_set (wd->win_indi, angle);
520    evas_object_move (wd->win_indi, x, y);
521    evas_object_resize (wd->win_indi, w, h);
522    if (evas_object_visible_get (wd->win_indi)) 
523      {
524         _make_notification_window (wd->win_indi);
525      }
526 /* detail */
527    elm_win_rotation_with_resize_set (wd->win_detail, angle);
528    if (evas_object_visible_get (wd->win_detail))  
529      {
530         _make_notification_window (wd->win_detail);
531      }
532 }
533
534 /**
535  * Get the view mode on the tickernoti object
536  *
537  * @param obj The tickernotil object
538  * @return The view mode
539  * @ingroup TickerNoti
540  */
541 EAPI Elm_Tickernoti_Mode
542 elm_tickernoti_mode_get (const Evas_Object *obj)
543 {
544    ELM_CHECK_WIDTYPE(obj, widtype) -1;
545    Widget_Data *wd = elm_widget_data_get(obj);
546    if (!wd) return -1;
547    return wd->mode;
548 }
549
550 /**
551  * Set the view mode used on the tickernoti object
552  *
553  * @param obj The tickernotil object
554  * @param mode The view mode will be used on the tickernoti object
555  * @ingroup TickerNoti
556  */
557 EAPI void
558 elm_tickernoti_mode_set (const Evas_Object *obj, Elm_Tickernoti_Mode mode)
559 {
560    ELM_CHECK_WIDTYPE(obj, widtype);
561    Widget_Data *wd = elm_widget_data_get(obj);
562    if (!wd) return;
563
564    wd->mode = mode;
565 }
566
567 /**
568  * Get the detail view window(elm_win) on the tickernoti object
569  *
570  * @param obj The tickernotil object
571  * @return detail view window(elm_win) object
572  * @ingroup TickerNoti
573  */
574 EAPI Evas_Object *
575 elm_tickernoti_detailview_get (const Evas_Object *obj)
576 {
577    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
578    Widget_Data *wd = elm_widget_data_get(obj);
579    if (!wd) return NULL;
580    return wd->win_detail;
581 }
582