9e241b6f9c23aff3572f56a431229806e2cc3987
[apps/home/calendar.git] / src / view-main-month.c
1 /*
2
3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
4
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
7
8 PROPRIETARY/CONFIDENTIAL
9
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
15
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
22
23 */
24
25
26 #include <vconf.h>
27
28 #include "view.h"
29 #include "detail.h"
30 #include "edit-repeat.h"
31 #include "external-ug.h"
32
33 static const char *_name = NULL;
34
35 #define MONTH_CAL_CBAR_H 41
36 #define MONTH_CAL_X 0
37 #define MONTH_CAL_Y 200
38
39 #define ANIMATION_TIME 0.2
40
41 #define INITIAL_FETCH_SIZE 4
42 #define IDLER_FETCH_SIZE 4
43
44
45 typedef enum{
46         FOCUS_IN_DAILY = 0,
47         FOCUS_IN_WEEKLY
48 }focus_in_month_view_type;
49
50 typedef struct {
51         const char *name;
52         struct appdata *ad;
53         Evas_Object *parent;
54         Evas_Object *ly; // self
55
56         Evas_Object *month;
57         Evas_Object *month_left;
58         Evas_Object *month_right;
59         Evas_Coord_Rectangle rect;
60         Evas_Coord_Rectangle oringinal_size;
61
62         focus_in_month_view_type calendar_focus_view;
63
64         Evas_Object *gl;
65         struct calsvc *csv;
66
67         int single_moved;
68         int multi_touched;
69         Evas_Coord_Point down1, down2;
70         int down_d;
71         int down_is_called;
72
73         Evas_Coord_Point move1, move2;
74
75         Ecore_Idler *idler;
76         int event_offset;
77
78         Ecore_Animator *ani;
79         double ani_start;
80
81         Evas_Coord_Rectangle pos_from;
82         Evas_Coord_Rectangle pos_to;
83
84         int d;
85
86
87 }cal_month_data;
88 extern void cal_month_update_month_calendar(Evas_Object *ly, struct tm *t);
89 static Evas_Object *__cal_month_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part);
90 static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, const char *part);
91 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
92 static void __cal_month_update_genlist(cal_month_data *p);
93 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src);
94 static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info);
95
96 static Elm_Genlist_Item_Class itc = {
97         .item_style = "3text.5icon",
98         .func.content_get = __cal_month_get_genlist_item_icon,
99         .func.text_get = __cal_month_get_genlist_item_label,
100 };
101
102 static int is_hour24;
103 static Calendar_color calendar_color;
104
105 static inline void __cal_month_stop_animation(cal_month_data *p)
106 {
107         if (p->ani)
108                 ecore_animator_del(p->ani);
109
110         p->ani = NULL;
111 }
112
113 static void __cal_month_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
114 {
115         CAL_FN_START;
116
117         c_retm_if(!data, "data is null");
118         c_retm_if(!e, "e is null");
119
120         cal_month_data *p = data;
121
122         CALENDAR_SVC_FREE_CS(&p->csv);
123
124         __cal_month_stop_animation(p);
125
126         if (p->idler)
127                 ecore_idler_del(p->idler);
128
129         evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
130
131         free(p);
132
133         DBG("");
134 }
135
136 static void __cal_month_resize_view(void *data, Evas *e, Evas_Object *ly, void *ei)
137 {
138         cal_month_data *p = data;
139
140         cal_util_get_geometry(&p->rect, p->month);
141 }
142
143 static void __cal_month_make_time_text(time_t t, struct tm *tm, char *buf, int sz)
144 {
145         struct tm ttm;
146         const char* date;
147         const char* time;
148
149         localtime_r(&t, &ttm);
150
151         if(is_hour24)
152                 time = CAL_UTIL_TIME_FORMAT_6;
153         else
154                 time = CAL_UTIL_TIME_FORMAT_1;
155
156         if (ttm.tm_year != tm->tm_year)
157                 date = CAL_UTIL_DATE_FORMAT_11;
158         else if (ttm.tm_mon != tm->tm_mon)
159                 date = CAL_UTIL_DATE_FORMAT_10;
160         else if (ttm.tm_mday != tm->tm_mday)
161                 date = CAL_UTIL_DATE_FORMAT_9;
162         else
163                 date = NULL;
164
165         cal_util_get_time_text(buf, sz, NULL, time, &ttm);
166 }
167
168 static char* __cal_month_get_time_text(struct tmnode *tm, cal_month_data *p)
169 {
170         char buf[512];
171         char stime[512];
172
173         __cal_month_make_time_text(tm->st, &p->ad->base_tm, stime, sizeof(stime));
174
175         snprintf(buf, sizeof(buf), "%s", stime);
176         return strdup(buf);
177 }
178
179 static Evas_Object *__cal_month_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
180 {
181         Evas_Object *icon = NULL;
182         struct tmnode *tm = (struct tmnode *)data;
183         int r;
184         cal_struct *cs = NULL;
185         cal_struct *calendar = NULL;
186         cal_month_data* p = NULL;
187
188         if(!tm)
189         {
190                 ERR("tm is null");
191                 return NULL;
192         }
193
194         cs = tm->cs;
195         if(!cs)
196         {
197                 ERR("cs is null");
198                 return NULL;
199         }
200
201         p = CAL_UTIL_GET_PRIV_DATA(obj);
202
203         if (!CAL_STRCMP(part, "elm.swallow.colorbar"))
204         {
205                 r = CALENDAR_SVC_GET(CAL_STRUCT_CALENDAR, CALENDAR_SVC_STRUCT_GET_INT(cs,CAL_VALUE_INT_CALENDAR_ID), NULL, &calendar);
206                 if (r != CAL_SUCCESS)
207                 {
208                         ERR("CALENDAR_SVC_GET fail. %d", r);
209                         return NULL;
210                 }
211
212                 icon = evas_object_rectangle_add(evas_object_evas_get(obj));
213                 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
214
215                 CALENDAR_SVC_GET_CALENDAR_COLOR(calendar, &calendar_color);
216
217                 evas_object_color_set(icon, calendar_color.red, calendar_color.green, calendar_color.blue, calendar_color.alpha);
218
219                 CALENDAR_SVC_STRUCT_FREE(&calendar);
220
221                 return icon;
222         }
223
224         return NULL;
225 }
226
227 static char* __cal_month_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
228 {
229         cal_month_data *p;
230         struct tmnode *tm = (struct tmnode *)data;
231         const char *str;
232
233         if (!tm || !tm->cs)
234                 return NULL;
235
236         if (!CAL_STRCMP(part, "elm.text.1"))
237         {
238                 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_SUMMARY);
239                 if (str)
240                         return strdup(str);
241
242                 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
243         }
244         else if (!CAL_STRCMP(part, "elm.text.2"))
245         {
246                 str = CALENDAR_SVC_STRUCT_GET_STR(tm->cs, CAL_VALUE_TXT_LOCATION);
247                 if (str)
248                         return strdup(str);
249
250                 return strdup(C_("IDS_CLD_BODY_NO_LOCATION_SELECTED"));
251         }
252         else if (!CAL_STRCMP(part, "elm.text.3"))
253         {
254                 int allday = CALENDAR_SVC_STRUCT_GET_INT(tm->cs, CAL_VALUE_INT_ALL_DAY_EVENT);
255                 if (allday)
256                         return strdup(C_("IDS_COM_BODY_ALL_DAY"));
257
258                 p = CAL_UTIL_GET_PRIV_DATA(obj);
259                 return __cal_month_get_time_text(tm, p);
260         }
261
262         return NULL;
263 }
264
265 static void __cal_month_genlist_item_select_callback(void *data, Evas_Object *obj, void *ei)
266 {
267         struct tmnode* tm = data;
268         cal_struct *cs = tm->cs;
269         int idx;
270         Elm_Object_Item *it;
271         cal_month_data *p;
272         int repeat;
273
274         it = elm_genlist_selected_item_get(obj);
275         if (it)
276                 elm_genlist_item_selected_set(it, EINA_FALSE);
277
278         idx = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_INDEX);
279
280         p = CAL_UTIL_GET_PRIV_DATA(obj);
281         CAL_ASSERT(p);
282
283         repeat = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_REPEAT_TERM);
284         if(repeat)
285         {
286                 memcpy(p->ad->tm, tm, sizeof(struct tmnode));
287         }
288         p->ad->cid = idx;
289
290         cal_detail_create_view(p->ad, p->parent);
291 }
292
293 static void __cal_month_get_events(cal_month_data *p)
294 {
295         time_t st, et;
296
297         cal_util_get_day_time_t(&p->ad->base_tm, &st, &et);
298
299         p->csv = CALENDAR_SVC_GET_EVENT(p->ad->acct_id, st, et);
300 }
301
302 static void __cal_month_update_genlist(cal_month_data *p)
303 {
304         c_retm_if(!p, "p is null");
305
306         Evas_Object* gl;
307         Eina_List *l;
308         struct tmnode *tm;
309         int count = 0;
310
311         CALENDAR_SVC_FREE_CS(&p->csv);
312         __cal_month_get_events(p);
313
314         if (!p->csv || !p->csv->tmlist || !eina_list_count(p->csv->tmlist))
315         {
316                 if (p->gl)
317                         elm_genlist_clear(p->gl);
318
319                 return;
320         }
321
322         if (!p->gl)
323         {
324                 gl = elm_genlist_add(p->ly);
325                 if (gl)
326                 {
327                         p->gl = gl;
328                         elm_object_part_content_set(p->ly, "list/sw", gl);
329                         evas_object_data_set(gl, "priv", p);
330                 }
331         }
332         else
333                 elm_genlist_clear(p->gl);
334
335         p->event_offset = 0;
336
337         EINA_LIST_FOREACH(p->csv->tmlist, l, tm)
338         {
339                 if (tm)
340                 {
341                         elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
342
343                         count ++;
344                         p->event_offset++;
345
346                         //First time, Just need to show 4 items. Another items will be add with idler
347                         if (count == INITIAL_FETCH_SIZE)
348                                 return;
349                 }
350         }
351 }
352
353 static Eina_Bool __cal_month_update_genlist_with_idler(void* data)
354 {
355         CAL_FN_START;
356
357         c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
358
359         Eina_List *l, *event_list;
360         struct tmnode *tm;
361         int count = 0;
362
363         cal_month_data* p = data;
364         c_retvm_if(!p, ECORE_CALLBACK_CANCEL, "p is null");
365
366         if (!p->gl)
367         {
368                 ERR("p->gl is null");
369                 p->idler = NULL;
370                 return ECORE_CALLBACK_CANCEL;
371         }
372
373         if (!p->csv)
374         {
375                 ERR("p->csv is null");
376                 p->idler = NULL;
377                 return ECORE_CALLBACK_CANCEL;
378         }
379
380         event_list = eina_list_nth_list(p->csv->tmlist, p->event_offset);
381
382         EINA_LIST_FOREACH(event_list, l, tm)
383         {
384                 if (tm)
385                 {
386                         elm_genlist_item_append(p->gl, &itc, tm, NULL, ELM_GENLIST_ITEM_NONE, __cal_month_genlist_item_select_callback, tm);
387
388                         count ++;
389                         p->event_offset++;
390
391                         if (count == IDLER_FETCH_SIZE && p->event_offset < eina_list_count(p->csv->tmlist))
392                                 return ECORE_CALLBACK_RENEW;
393                 }
394         }
395
396         p->idler = NULL;
397
398         CAL_FN_END;
399
400         return ECORE_CALLBACK_CANCEL;
401 }
402
403 static Evas_Object* __cal_month_create_month_d(cal_month_data *p, int d)
404 {
405         struct tm t;
406         struct appdata *ad = p->ad;
407         int r;
408
409         t = ad->base_tm;
410
411         r = cal_util_update_tm_month(&t, d);
412         if (r == -1)
413                 return cal_util_add_layout(p->ly, "rect/empty");
414
415         return cal_month_calendar_create_content(&t, ad, p->parent, EINA_TRUE);
416 }
417
418 static void __cal_month_move_month_calendar_to_left(cal_month_data *p, Evas_Coord x)
419 {
420         if (p->month_left == NULL) {
421                 p->month_left = __cal_month_create_month_d(p, -1);
422                 elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
423         }
424
425         if(0 > p->oringinal_size.x)
426         {
427                 evas_object_move(p->month_left, x, p->rect.y);
428         }
429         else
430         {
431                 evas_object_move(p->month_left, x, p->oringinal_size.y);
432         }
433 }
434
435 static void __cal_month_move_month_calendar_to_right(cal_month_data *p, Evas_Coord x)
436 {
437         if (p->month_right == NULL) {
438                 p->month_right = __cal_month_create_month_d(p, 1);
439                 elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
440         }
441
442         if(0 > p->oringinal_size.x)
443         {
444                 evas_object_move(p->month_right, x, p->rect.y);
445         }
446         else
447         {
448                 evas_object_move(p->month_right, x, p->oringinal_size.y);
449         }
450
451 }
452
453 static void __cal_month_move_month_calendar(cal_month_data *p)
454 {
455         Evas_Coord dx;
456         Evas_Coord x;
457
458         dx = p->move1.x - p->down1.x;
459         if (!p->single_moved && dx < 15 && dx > -15)
460                 return;
461
462         if (!p->single_moved)
463                 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->month), "moved", "prog");
464
465         p->single_moved = 1;
466
467         if(0 > p->oringinal_size.x)
468         {
469                 x = p->rect.x + dx;
470
471                 evas_object_move(p->month, x, p->rect.y);
472
473                 __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
474                 __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
475         }
476         else
477         {
478                 x = p->oringinal_size.x + dx;
479
480                 evas_object_move(p->month, x, p->oringinal_size.y);
481
482                 __cal_month_move_month_calendar_to_left(p, x - p->oringinal_size.w);
483                 __cal_month_move_month_calendar_to_right(p, x + p->oringinal_size.w);
484         }
485 }
486
487 static inline void __cal_month_move_objects(cal_month_data *p, Evas_Coord dx)
488 {
489         CAL_ASSERT(p);
490
491         if(!dx)
492                 return;
493
494         Evas_Coord x;
495
496         x = p->pos_from.x + dx;
497
498         evas_object_move(p->month, x, p->rect.y);
499
500         __cal_month_move_month_calendar_to_left(p, x - p->rect.w);
501         __cal_month_move_month_calendar_to_right(p, x + p->rect.w);
502 }
503
504
505 static inline int __cal_month_update_month_view(cal_month_data *p, int d)
506 {
507         CAL_ASSERT(p);
508
509         int r;
510
511         r = cal_util_update_tm_month(&p->ad->base_tm, d);
512         if (r == -1)
513                 return -1;
514
515         edje_object_signal_callback_del(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback);
516         evas_object_event_callback_del(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback);
517
518         elm_object_part_content_unset(p->ly, "cal/sw");
519         elm_object_part_content_unset(p->ly, "cal/sw/left");
520         elm_object_part_content_unset(p->ly, "cal/sw/right");
521
522         if(d > 0)
523         {
524                 evas_object_del(p->month_left);
525                 p->month_left = p->month;
526                 p->month = p->month_right;
527                 p->month_right = __cal_month_create_month_d(p, 1);
528         }
529         else if(d < 0)
530         {
531                 evas_object_del(p->month_right);
532                 p->month_right = p->month;
533                 p->month = p->month_left;
534                 p->month_left = __cal_month_create_month_d(p, -1);
535         }
536         else
537         {
538                 ERR("");
539                 CAL_ASSERT(EINA_FALSE);
540         }
541
542         cal_month_calendar_update_select(p->month);
543         cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
544
545         elm_object_part_content_set(p->ly, "cal/sw", p->month);
546         elm_object_part_content_set(p->ly, "cal/sw/left", p->month_left);
547         elm_object_part_content_set(p->ly, "cal/sw/right", p->month_right);
548
549         evas_object_show(p->ly);
550
551         evas_object_event_callback_add(p->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
552         edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->month), "changed", "prog", __cal_month_changed_callback, p);
553
554         __cal_month_update_genlist(p);
555
556         return 0;
557 }
558
559
560 static Eina_Bool __cal_month_animation(void *data)
561 {
562         cal_month_data *p = data;
563         double elapsed_t;
564         Evas_Coord dx;
565
566         elapsed_t = ecore_time_get() - p->ani_start;
567         if (elapsed_t > ANIMATION_TIME)
568                 elapsed_t = ANIMATION_TIME;
569
570         dx = (p->pos_to.x - p->pos_from.x) * cal_util_nsin(elapsed_t / ANIMATION_TIME);
571         __cal_month_move_objects(p, dx);
572
573         if (elapsed_t == ANIMATION_TIME || dx == 0)
574         {
575                 if (p->ani)
576                 {
577                         ecore_animator_del(p->ani);
578                         p->ani = NULL;
579                 }
580
581                 if(p->d)
582                 {
583                         __cal_month_update_month_view(p,p->d);
584                 }
585
586                 return ECORE_CALLBACK_CANCEL;
587         }
588
589         return ECORE_CALLBACK_RENEW;
590 }
591
592 static inline void __cal_month_start_animation(cal_month_data *p)
593 {
594         if (p->pos_from.x == p->pos_to.x)
595                 return;
596
597         if (!p->ani)
598                 p->ani = ecore_animator_add(__cal_month_animation, p);
599         p->ani_start = ecore_time_get();
600 }
601
602
603 static void __cal_month_mouse_up_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
604 {
605         CAL_ASSERT(data);
606         cal_month_data *p = data;
607
608         CAL_ASSERT(p->ad);
609         struct appdata* ad = p->ad;
610
611         Evas_Event_Mouse_Up *ev = ei;
612
613         p->down_is_called = 0;
614
615         if (p->single_moved)
616         {
617                 int dx = p->down1.x - ev->canvas.x;
618                 int d = 1;
619
620                 p->single_moved = 0;
621
622                 if (dx < 0) {
623                         d = -1;
624                         dx = dx * -1;
625                 }
626
627                 cal_util_get_geometry(&p->pos_from,p->month);
628
629
630                 if (dx > (p->rect.w >> 1))
631                 {
632                         if (d < 0)
633                         {
634                                 p->d = -1;
635                                 p->pos_to.x = p->ad->win_w;
636                                 p->pos_to.y = p->pos_from.y;
637                                 p->pos_to.w = p->pos_from.w;
638                                 p->pos_to.h = p->pos_from.h;
639                         }
640                         else
641                         {
642                                 p->d = 1;
643                                 p->pos_to.x = -(p->ad->win_w);
644                                 p->pos_to.y = p->pos_from.y;
645                                 p->pos_to.w = p->pos_from.w;
646                                 p->pos_to.h = p->pos_from.h;
647                         }
648                         __cal_month_start_animation(p);
649                 }
650                 else
651                 {
652                         __cal_month_move_month_calendar_to_left(p, MONTH_CAL_X - ad->win_w);
653                         __cal_month_move_month_calendar_to_right(p, MONTH_CAL_X + ad->win_w);
654                         evas_object_move(p->month, MONTH_CAL_X, p->pos_from.y);
655                 }
656
657                 return;
658         }
659
660 }
661
662 static void __cal_month_mouse_down_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
663 {
664         cal_month_data *p = data;
665         Evas_Event_Mouse_Down *ev = ei;
666
667         p->down1.x = p->move1.x = ev->canvas.x;
668         p->down1.y = p->move1.y = ev->canvas.y;
669
670         p->down_is_called = 1;
671
672         cal_util_get_geometry(&p->oringinal_size,p->month);
673 }
674
675 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
676 {
677         cal_month_data *p = data;
678         Evas_Event_Mouse_Move *ev = ei;
679
680         if (0 == p->down_is_called)
681                 return;
682
683         p->move1.x = ev->cur.canvas.x;
684         p->move1.y = ev->cur.canvas.y;
685
686         if (!p->multi_touched)
687                 __cal_month_move_month_calendar(p);
688 }
689
690 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src)
691 {
692         __cal_month_update_genlist(data);
693 }
694
695 static void __cal_month_rendering_flush_callback(void *data, Evas *e, void *event_info)
696 {
697         CAL_FN_START;
698
699         c_retm_if(!data, "data is null");
700         c_retm_if(!e, "evas is null");
701
702         evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback);
703
704         cal_month_data* p = data;
705
706         if (!p->gl || p->idler ||!p->csv || eina_list_count(p->csv->tmlist) == p->event_offset)
707                 return;
708
709         p->idler = ecore_idler_add(__cal_month_update_genlist_with_idler, p);
710         c_retm_if(!p->idler, "p->idler is null");
711
712         CAL_FN_END;
713 }
714
715 Evas_Object* cal_month_create_view(struct appdata *ad, Evas_Object *main)
716 {
717         CAL_FN_START;
718
719         c_retvm_if(!ad, NULL, "ad is null");
720         c_retvm_if(!main, NULL, "main is null");
721
722         cal_month_data *p;
723         Evas_Object *ly;
724         Evas_Object *month;
725         Evas_Object *list_bg;
726
727         p = calloc(1, sizeof(cal_month_data));
728         c_retvm_if(!p, NULL, "calloc(1, sizeof(cal_month_data)) is failed");
729
730         vconf_get_int(CAL_VCONFKEY_FOCUS_VIEW, (int*)&p->calendar_focus_view);
731
732         if (FOCUS_IN_DAILY == p->calendar_focus_view)
733         {
734                 ad->is_weekly = FALSE;
735                 p->name = _name = "main/month";
736         }
737         else if (FOCUS_IN_WEEKLY == p->calendar_focus_view)
738         {
739                 ad->is_weekly = TRUE;
740                 p->name = _name = "main/month/weekly";
741         }
742         else
743                 return NULL;
744
745         p->ad = ad;
746
747         is_hour24 = ad->is_hour24;
748
749         p->parent = main;
750         p->oringinal_size.x = -1;
751         p->oringinal_size.y = -1;
752         p->oringinal_size.w = -1;
753         p->oringinal_size.h = -1;
754         ly = cal_util_add_layout(ad->nv, p->name);
755         if (!ly) {
756                 free(p);
757                 return NULL;
758         }
759         evas_object_data_set(ly, "priv", p);
760         p->ly = ly;
761
762         month = cal_month_calendar_create_content(&ad->base_tm, ad, main, EINA_FALSE);
763         if (!month)
764         {
765                 ERR("cal_month_calendar_create_content(&ad->base_tm, ad, ly, EINA_FALSE) is failed");
766                 evas_object_del(ly);
767                 free(p);
768                 return NULL;
769         }
770
771         elm_object_part_content_set(ly, "cal/sw", month);
772         p->month = month;
773         edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(month), "changed", "prog", __cal_month_changed_callback, p);
774
775         list_bg = cal_util_add_bg(ly, EINA_FALSE);
776         if (!list_bg)
777         {
778                 ERR("cal_util_add_bg(ly, EINA_FALSE) is failed");
779                 evas_object_del(ly);
780                 free(p);
781                 return NULL;
782         }
783
784         elm_object_part_content_set(ly, "list/base", list_bg);
785
786         evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, __cal_month_delete_layout, p);
787         evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_DOWN, __cal_month_mouse_down_event_callback, p);
788         evas_object_event_callback_add(ly, EVAS_CALLBACK_MOUSE_UP, __cal_month_mouse_up_event_callback, p);
789         evas_object_event_callback_add(month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
790         evas_object_event_callback_add(ly, EVAS_CALLBACK_RESIZE, __cal_month_resize_view, p);
791
792         CAL_FN_END;
793
794         return ly;
795 }
796
797 void cal_month_update_view(Evas_Object *ly)
798 {
799         CAL_FN_START;
800
801         c_retm_if(!ly, "ly is null");
802
803         cal_month_data *p;
804         struct appdata *ad;
805         Evas *e;
806
807         p = CAL_UTIL_GET_PRIV_DATA(ly);
808         if (!p || CAL_STRCMP(p->name, _name)) {
809                 ERR("update month view: Invalid object");
810                 return;
811         }
812
813         ad = p->ad;
814         c_retm_if(!ad, "ad is null");
815
816         cal_month_update_month_calendar(p->month, &ad->base_tm);
817         cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->ly), "go,line%d", cal_month_get_weekline(p->month));
818
819         __cal_month_update_genlist(p);
820
821         cal_util_delete_evas_object(&p->month_left);
822         cal_util_delete_evas_object(&p->month_right);
823
824         e = evas_object_evas_get(ly);
825         c_retm_if(!e, "evas_object_evas_get(ly) is failed");
826
827         evas_event_callback_add(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __cal_month_rendering_flush_callback,p);
828
829         CAL_FN_END;
830 }
831