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