809770c29edaab8789fccc031ea735dd74cffeeb
[apps/core/preloaded/calendar.git] / src / view-main-month.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://floralicense.org/license/
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19 #include <vconf.h>
20
21 #include "view.h"
22 #include "detail-view.h"
23 #include "external-ug.h"
24 #include "list-base.h"
25
26 static const char *_name = NULL;
27
28 #define MONTH_CAL_CBAR_H 41
29 #define MONTH_CAL_X 0
30 #define MONTH_CAL_Y 200
31
32 #define ANIMATION_TIME 0.2
33
34 #define INITIAL_FETCH_SIZE 4
35 #define IDLER_FETCH_SIZE 4
36
37 typedef enum{
38         FOCUS_IN_DAILY = 0,
39         FOCUS_IN_WEEKLY
40 }focus_in_month_view_type;
41
42 typedef struct {
43         Evas_Object* container;
44         Evas_Object* month;
45         Evas_Object* month_prev;
46         Evas_Object* month_next;
47 } cal_month_view;
48
49 static void __cal_month_view_del(cal_month_view* view)
50 {
51         evas_object_del(view->container);
52         evas_object_del(view->month);
53         evas_object_del(view->month_prev);
54         evas_object_del(view->month_next);
55         free(view);
56 }
57
58 typedef struct {
59         cal_list_base_h list;
60         cal_month_view* vcur;
61         cal_month_view* vcached_m;
62         cal_month_view* vcached_w;
63         cal_month_view* vcached_l;
64         struct appdata *ad;
65
66         const char *name;
67         Evas_Object *parent;
68
69         Evas_Coord_Rectangle rect;
70         Evas_Coord_Rectangle oringinal_size;
71
72         focus_in_month_view_type calendar_focus_view;
73
74         Eina_List *event_list;
75
76         int single_moved;
77         int multi_touched;
78         int single_flicked;
79         Evas_Coord_Point down1, down2;
80         int down_d;
81         int down_is_called;
82
83         Evas_Coord_Point move1, move2;
84
85         Evas_Object* popup;
86         Ecore_Idler* idler;
87         int event_offset;
88
89         Ecore_Animator *ani;
90         double ani_start;
91
92         Evas_Coord_Rectangle pos_from;
93         Evas_Coord_Rectangle pos_to;
94
95         int d;
96
97         Evas_Coord x;
98         Evas_Coord y;
99
100         int calendar_slide_last_pos;
101 }cal_month_data;
102
103 extern void cal_month_calendar_update_view(Evas_Object *ly);
104
105 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
106 static void __cal_month_update_genlist(cal_month_data *p);
107 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src);
108 static void __cal_month_set_title_text(struct appdata *ad, const struct tm* tm);
109
110 static inline void __cal_month_stop_animation(cal_month_data *p)
111 {
112         if (p->ani)
113                 ecore_animator_del(p->ani);
114
115         p->ani = NULL;
116 }
117
118 static void __cal_month_text_refresh_callback(void *data)
119 {
120         CAL_FN_START;
121
122         c_retm_if(!data, "data is null");
123         cal_month_data *p = data;
124
125         cal_main_update_title_text(p->ad);
126         cal_month_calendar_set_wday_text(p->vcur->month, p->ad->wday_start);
127         elm_object_text_set(p->ad->new_event_button, S_("IDS_COM_BODY_CREATE"));
128
129         elm_genlist_realized_items_update(p->list);
130 }
131
132 static void __cal_month_delete_layout(void *data, Evas *e, Evas_Object *obj, void *ei)
133 {
134         CAL_FN_START;
135
136         c_retm_if(!data, "data is null");
137         c_retm_if(!e, "e is null");
138
139         cal_month_data *p = data;
140
141         _calendar_free_record_list(&p->event_list);
142
143
144         if (p->vcached_m && p->vcached_m != p->vcur) {
145                 __cal_month_view_del(p->vcached_m);
146                 p->vcached_m = NULL;
147         }
148
149         if (p->vcached_w && p->vcached_w != p->vcur) {
150                 __cal_month_view_del(p->vcached_w);
151                 p->vcached_w = NULL;
152         }
153
154         if (p->vcached_l && p->vcached_l != p->vcur) {
155                 __cal_month_view_del(p->vcached_l);
156                 p->vcached_l = NULL;
157         }
158
159         free(p->vcur);
160
161
162         __cal_month_stop_animation(p);
163
164         if (p->idler)
165                 ecore_idler_del(p->idler);
166
167         if (p->popup)
168                 evas_object_del(p->popup);
169
170         cal_lang_manager_remove_callback(__cal_month_text_refresh_callback, p);
171
172         free(p);
173         p = NULL;
174 }
175
176 static void __cal_month_resize_view(void *data, Evas *e, Evas_Object *ly, void *ei)
177 {
178         cal_month_data *p = data;
179
180         cal_util_get_geometry(&p->rect, p->vcur->month);
181 }
182
183 static void __cal_month_get_events(cal_month_data *p)
184 {
185         struct tm tm_start = p->ad->base_tm;
186         tm_start.tm_hour = 0;
187         tm_start.tm_min = 0;
188         tm_start.tm_sec = 0;
189
190         struct tm tm_end = tm_start;
191         tm_end.tm_hour = 23;
192         tm_end.tm_min = 59;
193         tm_end.tm_sec = 59;
194
195         p->event_list = _calendar_get_all_instance_list(&tm_start, &tm_end);
196
197         Eina_List *todo_list = _calendar_get_due_date_task_list(&tm_start, &tm_end, p->ad->is_display_complete_todo, _CALENDAR_TASK_SORT_TYPE_DUEDATE_ASC);
198         p->event_list = eina_list_merge(p->event_list, todo_list);
199 }
200
201 static void __cal_month_update_genlist(cal_month_data *p)
202 {
203         CAL_FN_START;
204
205         c_retm_if(!p, "p is null");
206
207         _calendar_free_record_list(&p->event_list);
208
209         __cal_month_get_events(p);
210
211         if (!p->list)
212                 p->list = cal_list_base_create(p->ad, p->vcur->container, "list/sw", true, NULL, NULL);
213         else
214                 elm_genlist_clear(cal_list_base_get_genlist_p(p->list));
215
216         p->event_offset = 0;
217
218         Eina_List *l = NULL;
219         calendar_record_h record = NULL;
220
221         EINA_LIST_FOREACH(p->event_list, l, record) {
222                 if (record)
223                         cal_list_base_add_item(p->list, record, false);
224         }
225
226         CAL_FN_END;
227 }
228
229 static Evas_Object* __cal_month_create_month_d(cal_month_view* v, cal_month_data *p, int d)
230 {
231         
232         c_retv_if(!p, NULL);
233
234         struct appdata *ad = p->ad;
235         c_retv_if(!ad, NULL);
236
237         struct tm base_tm_bak = ad->base_tm;    
238
239         time_t r = cal_util_update_tm_month(&ad->base_tm, d);
240         c_retv_if(r < 0, NULL);
241
242         Evas_Object *calendar = cal_month_calendar_create_view(ad, v->container, EINA_TRUE);
243
244         ad->base_tm = base_tm_bak;
245
246         return calendar;
247 }
248
249 static void __cal_month_move_prev_month_calendar(cal_month_data *p, Evas_Coord x)
250 {
251         if (p->vcur->month_prev == NULL) {
252                 p->vcur->month_prev = __cal_month_create_month_d(p->vcur, p, -1);
253                 if (!p->vcur->month_prev ) {
254                         Evas_Coord dx = p->move1.x - p->down1.x;
255                         if (dx > 0) {
256                                 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "elm,edge,left", "elm");
257                         }
258                         return;
259                 }
260                 elm_object_part_content_set(p->vcur->container, "cal/sw/left", p->vcur->month_prev);
261         }
262
263         if(0 > p->oringinal_size.x)
264         {
265                 evas_object_move(p->vcur->month_prev, x, p->rect.y);
266         }
267         else
268         {
269                 evas_object_move(p->vcur->month_prev, x, p->oringinal_size.y);
270         }
271
272 }
273
274 static void __cal_month_move_next_month_calendar(cal_month_data *p, Evas_Coord x)
275 {
276         if (p->vcur->month_next == NULL) {
277                 p->vcur->month_next = __cal_month_create_month_d(p->vcur, p, 1);
278                 if (!p->vcur->month_next) {
279                         Evas_Coord dx = p->move1.x - p->down1.x;
280                         if (dx < 0) {
281                                 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "elm,edge,right", "elm");
282                         }
283                         return;
284                 }
285                 elm_object_part_content_set(p->vcur->container, "cal/sw/right", p->vcur->month_next);
286         }
287
288         if(0 > p->oringinal_size.x)
289         {
290                 evas_object_move(p->vcur->month_next, x, p->rect.y);
291         }
292         else
293         {
294                 evas_object_move(p->vcur->month_next, x, p->oringinal_size.y);
295         }
296 }
297
298 static void __cal_month_set_title_text(struct appdata *ad, const struct tm* tm)
299 {
300         c_ret_if(!ad);
301         c_ret_if(!ad->main_navi_item);
302         Elm_Object_Item* title = ad->main_navi_item;
303         cal_util_set_item_time_text(title, "default", CAL_UTIL_DATE_FORMAT_6, NULL, tm);
304 }
305
306 static void __cal_month_update_title_text(cal_month_data* p, int dx)
307 {
308         struct appdata* ad = p->ad;
309         c_retm_if(!ad, "ad is null");
310
311         if ((dx > 0 ? dx : -dx) > (p->rect.w / 2)) {
312                 if (dx > 0) {
313                         if (p->calendar_slide_last_pos <= 0) {
314                                 struct tm t = ad->base_tm;
315                                 cal_util_update_tm_month(&t, -1);
316                                 __cal_month_set_title_text(ad, &t);
317                                 p->calendar_slide_last_pos = 1;
318                         }
319                 } else {
320                         if (p->calendar_slide_last_pos >= 0) {
321                                 struct tm t = ad->base_tm;
322                                 cal_util_update_tm_month(&t, 1);
323                                 __cal_month_set_title_text(ad, &t);
324                                 p->calendar_slide_last_pos = -1;
325                         }
326                 }
327         } else {
328                 if (p->calendar_slide_last_pos != 0) {
329                         __cal_month_set_title_text(ad, &ad->base_tm);
330                         p->calendar_slide_last_pos = 0;
331                 }
332         }
333 }
334
335 static void __cal_month_move_month_calendar(cal_month_data *p)
336 {
337         c_ret_if(!p);
338
339         Evas_Coord th = elm_config_finger_size_get();
340
341         Evas_Coord dx = p->move1.x - p->down1.x;
342         if (!p->single_moved && dx < th && dx > -th)
343                 return;
344
345         if (!p->single_moved)
346                 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "moved", "prog");
347
348         p->single_moved = 1;
349
350         __cal_month_update_title_text(p, dx);
351
352         Evas_Coord x;
353         if (p->oringinal_size.x < 0) {
354                 x = p->rect.x + dx;
355
356                 __cal_month_move_prev_month_calendar(p, x - p->rect.w);
357                 __cal_month_move_next_month_calendar(p, x + p->rect.w);
358                 if (dx > 0) {
359                         if (p->vcur->month_prev) {
360                                 evas_object_move(p->vcur->month, x, p->rect.y);
361                         }
362                 } else {
363                         if (p->vcur->month_next) {
364                                 evas_object_move(p->vcur->month, x, p->rect.y);
365                         }
366                 }
367
368         } else {
369
370                 x = p->oringinal_size.x + dx;
371
372                 __cal_month_move_prev_month_calendar(p, x - p->oringinal_size.w);
373                 __cal_month_move_next_month_calendar(p, x + p->oringinal_size.w);
374                 if (dx > 0) {
375                         if (p->vcur->month_prev) {
376                                 evas_object_move(p->vcur->month, x, p->oringinal_size.y);
377                         }
378                 } else {
379                         if (p->vcur->month_next) {
380                                 evas_object_move(p->vcur->month, x, p->oringinal_size.y);
381                         }
382                 }
383         }
384 }
385
386 static inline void __cal_month_move_objects(cal_month_data *p, Evas_Coord dx)
387 {
388         c_ret_if(!p);
389
390         if(!dx)
391                 return;
392
393         struct appdata *ad = p->ad;
394         c_retm_if(!ad, "ad is null");
395
396         struct tm t;
397         int r = 0;
398
399         if (0 <= dx) {
400
401                 t = ad->base_tm;
402                 r = cal_util_update_tm_month(&t, -1);
403                 c_ret_if(r < 0);
404
405         } else {
406
407                 t = ad->base_tm;
408                 r = cal_util_update_tm_month(&t, 1);
409                 c_ret_if(r < 0);
410         }
411
412         Evas_Coord x = p->pos_from.x + dx;
413
414         __cal_month_move_prev_month_calendar(p, x - p->rect.w);
415         __cal_month_move_next_month_calendar(p, x + p->rect.w);
416
417         if (dx > 0) {
418                 if (p->vcur->month_prev) {
419                         evas_object_move(p->vcur->month, x, p->rect.y);
420                 }
421         } else {
422                 if (p->vcur->month_next) {
423                         evas_object_move(p->vcur->month, x, p->rect.y);
424                 }
425         }
426 }
427
428 static void __cal_month_list_icon_clicked_callback(void *data, Evas_Object *obj, const char *e, const char *src);
429 static void __cal_month_mouse_down_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
430 static void __cal_month_mouse_up_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei);
431
432 static cal_month_view* __cal_month_create_layout(cal_month_data* p)
433 {
434         cal_month_view* v = (cal_month_view*)calloc(1, sizeof(cal_month_view));
435         p->vcur = v;
436
437         Evas_Object* layout;
438
439         layout = cal_util_add_layout(p->ad->naviframe, p->name);
440
441         if (!layout) {
442                 free(v);
443                 return NULL;
444         }
445
446         v->container = layout;
447
448         evas_object_data_set(layout, "priv", p);
449
450         evas_object_hide(layout);
451
452         evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_DOWN, __cal_month_mouse_down_event_callback, p);
453         evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_UP, __cal_month_mouse_up_event_callback, p);
454         evas_object_event_callback_add(layout, EVAS_CALLBACK_RESIZE, __cal_month_resize_view, p);
455
456         v->month = cal_month_calendar_create_view(p->ad, layout, EINA_TRUE);
457         v->month_next = __cal_month_create_month_d(v, p, 1);
458         v->month_prev = __cal_month_create_month_d(v, p, -1);
459
460         elm_object_part_content_set(layout, "cal/sw", v->month);
461         elm_object_part_content_set(layout, "cal/sw/left", v->month_prev);
462         elm_object_part_content_set(layout, "cal/sw/right", v->month_next);
463
464 //      cal_month_calendar_update_select(p->vcur->month);
465
466 //      cal_month_update_view(layout);
467
468 //      cal_month_calendar_update_view(v->month);
469 //      cal_month_calendar_update_view(v->month_next);
470 //      cal_month_calendar_update_view(v->month_prev);
471
472 //      __cal_month_update_genlist(p);
473
474         return v;
475 }
476
477 static void __cal_month_create_missing_parts(cal_month_view* v, cal_month_data* p)
478 {
479         if (v->month == NULL)
480                 v->month = cal_month_calendar_create_view(p->ad, v->container, EINA_TRUE);
481
482         if (v->month_next == NULL)
483                 v->month_next = __cal_month_create_month_d(v, p, 1);
484
485         if (v->month_prev == NULL)
486                 v->month_prev = __cal_month_create_month_d(v, p, -1);
487
488         elm_object_part_content_set(v->container, "cal/sw", v->month);
489         elm_object_part_content_set(v->container, "cal/sw/left", v->month_prev);
490         elm_object_part_content_set(v->container, "cal/sw/right", v->month_next);
491 }
492
493 static void __cal_month_switch_mode(cal_month_data* p)
494 {
495         CAL_ASSERT(p)
496
497         if (p->vcur) {
498                 evas_object_event_callback_del(p->vcur->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback);
499                 edje_object_signal_callback_del(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "changed", "prog", __cal_month_changed_callback);
500                 Evas_Object *layout = elm_object_part_content_unset(p->ad->main, "cont");
501                 evas_object_hide(p->vcur->month);
502                 evas_object_hide(p->vcur->month_next);
503                 evas_object_hide(p->vcur->month_prev);
504                 evas_object_event_callback_del(layout, EVAS_CALLBACK_DEL, __cal_month_delete_layout);
505                 evas_object_hide(layout);
506         }
507
508         if (p->ad->is_landscape_mode) {
509                 p->name = _name = "main/month/weekly/l";
510                 if (p->vcached_l == NULL)
511                         p->vcached_l = __cal_month_create_layout(p);
512                 else
513                         __cal_month_create_missing_parts(p->vcached_l, p);
514                 p->vcur = p->vcached_l;
515         } else {
516                 if (p->ad->daily_events_mode) {
517                         p->name = _name = "main/month/weekly";
518                         if (p->vcached_w == NULL)
519                                 p->vcached_w = __cal_month_create_layout(p);
520                         else
521                                 __cal_month_create_missing_parts(p->vcached_w, p);
522                         p->vcur = p->vcached_w;
523                 } else {
524                         p->name = _name = "main/month";
525                         if (p->vcached_m == NULL)
526                                 p->vcached_m = __cal_month_create_layout(p);
527                         else
528                                 __cal_month_create_missing_parts(p->vcached_m, p);
529                         p->vcur = p->vcached_m;
530                 }
531         }
532
533         evas_object_event_callback_add(p->vcur->container, EVAS_CALLBACK_DEL, __cal_month_delete_layout, p);
534
535         cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "set,default");
536
537         if (!p->ad->daily_events_mode)
538                 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "go,line%d", cal_month_calendar_get_weekline(p->vcur->month));
539
540         evas_object_event_callback_add(p->vcur->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
541         edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "changed", "prog", __cal_month_changed_callback, p);
542
543         evas_object_show(p->vcur->container);
544         elm_object_part_content_set(p->ad->main, "cont", p->vcur->container);
545         cal_main_set_main_content(p->ad, p->vcur->container);
546         evas_object_show(p->vcur->month);
547 }
548
549 static void __cal_month_shift(cal_month_view* v, cal_month_data *p, int d)
550 {
551         if (v == NULL)
552                 return;
553
554         elm_object_part_content_unset(v->container, "cal/sw");
555         elm_object_part_content_unset(v->container, "cal/sw/left");
556         elm_object_part_content_unset(v->container, "cal/sw/right");
557
558         if (d > 0)
559         {
560                 evas_object_del(v->month_prev);
561                 v->month_prev = v->month;
562                 v->month = v->month_next;
563                 if (p->vcur == v)
564                         v->month_next = __cal_month_create_month_d(v, p, 1);
565                 else
566                         v->month_next = NULL;
567         }
568         else
569         {
570                 evas_object_del(v->month_next);
571                 v->month_next = v->month;
572                 v->month = v->month_prev;
573                 if (p->vcur == v)
574                         v->month_prev = __cal_month_create_month_d(v, p, -1);
575                 else
576                         v->month_prev = NULL;
577         }
578
579         elm_object_part_content_set(v->container, "cal/sw", v->month);
580         elm_object_part_content_set(v->container, "cal/sw/left", v->month_prev);
581         elm_object_part_content_set(v->container, "cal/sw/right", v->month_next);
582 }
583
584 static inline int __cal_month_update_month_view(cal_month_data *p, int d)
585 {
586         CAL_ASSERT(p);
587
588         int r;
589
590         r = cal_util_update_tm_month(&p->ad->base_tm, d);
591         if (r == -1)
592                 return -1;
593
594         cal_month_view* vcur = p->vcur;
595
596         edje_object_signal_callback_del(CAL_UTIL_GET_EDJ_DATA(vcur->month), "changed", "prog", __cal_month_changed_callback);
597         evas_object_event_callback_del(vcur->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback);
598
599         __cal_month_shift(p->vcached_m, p, d);
600         __cal_month_shift(p->vcached_w, p, d);
601         __cal_month_shift(p->vcached_l, p, d);
602
603         cal_month_calendar_update_select(vcur->month);
604
605         if (!p->ad->daily_events_mode)
606                 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "go,line%d", cal_month_calendar_get_weekline(p->vcur->month));
607
608         evas_object_show(vcur->container);
609
610         evas_object_event_callback_add(vcur->month, EVAS_CALLBACK_MOUSE_MOVE, __cal_month_mouse_move_event_callback, p);
611         edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "changed", "prog", __cal_month_changed_callback, p);
612
613         __cal_month_update_genlist(p);
614
615         return 0;
616 }
617
618
619 static Eina_Bool __cal_month_animation(void *data)
620 {
621         cal_month_data *p = data;
622         double elapsed_t;
623         Evas_Coord dx;
624
625         elapsed_t = ecore_time_get() - p->ani_start;
626         if (elapsed_t > ANIMATION_TIME)
627                 elapsed_t = ANIMATION_TIME;
628
629         dx = (p->pos_to.x - p->pos_from.x) * cal_util_nsin(elapsed_t / ANIMATION_TIME);
630         __cal_month_move_objects(p, dx);
631
632         if (elapsed_t == ANIMATION_TIME || dx == 0)
633         {
634                 if (p->ani)
635                 {
636                         ecore_animator_del(p->ani);
637                         p->ani = NULL;
638                 }
639
640                 if(p->d)
641                 {
642                         __cal_month_update_month_view(p,p->d);
643                 }
644
645                 p->calendar_slide_last_pos = 0;
646
647                 return ECORE_CALLBACK_CANCEL;
648         }
649
650         return ECORE_CALLBACK_RENEW;
651 }
652
653 static inline void __cal_month_start_animation(cal_month_data *p)
654 {
655         if (p->pos_from.x == p->pos_to.x)
656                 return;
657
658         if (!p->ani)
659                 p->ani = ecore_animator_add(__cal_month_animation, p);
660         p->ani_start = ecore_time_get();
661 }
662
663 static void __cal_month_mouse_up_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
664 {
665         CAL_ASSERT(data);
666         cal_month_data *p = data;
667
668         CAL_ASSERT(p->ad);
669         struct appdata* ad = p->ad;
670
671         Evas_Event_Mouse_Up *ev = ei;
672
673         p->down_is_called = 0;
674
675         if (p->single_flicked) {
676                 int dy = p->down1.y - ev->canvas.y;
677                 p->single_flicked = 0;
678
679                 if (0 < dy) {
680                         cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "expand,up");
681                 } else {
682                         cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "expand,down");
683                 }
684
685         } else if (p->single_moved) {
686                 int dx = p->down1.x - ev->canvas.x;
687                 int d = 1;
688
689                 p->single_moved = 0;
690
691                 if (dx < 0) {
692                         d = -1;
693                         dx = dx * -1;
694                 }
695
696                 cal_util_get_geometry(&p->pos_from,p->vcur->month);
697
698                 if (dx > cal_util_get_flick_distance_threshold())
699                 {
700                         if (d < 0)
701                         {
702                                 p->d = -1;
703                                 p->pos_to.x = p->ad->win_w;
704                                 p->pos_to.y = p->pos_from.y;
705                                 p->pos_to.w = p->pos_from.w;
706                                 p->pos_to.h = p->pos_from.h;
707                         }
708                         else
709                         {
710                                 p->d = 1;
711                                 p->pos_to.x = -(p->ad->win_w);
712                                 p->pos_to.y = p->pos_from.y;
713                                 p->pos_to.w = p->pos_from.w;
714                                 p->pos_to.h = p->pos_from.h;
715                         }
716                         __cal_month_start_animation(p);
717                 }
718                 else
719                 {
720                         p->d = 0;
721                         p->pos_to.x = 0;
722                         p->pos_to.y = p->pos_from.y;
723                         p->pos_to.w = p->pos_from.w;
724                         p->pos_to.h = p->pos_from.h;
725                         __cal_month_start_animation(p);
726                 }
727
728                 return;
729         }
730
731 }
732
733 static void __cal_month_mouse_down_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
734 {
735         cal_month_data *p = data;
736         Evas_Event_Mouse_Down *ev = ei;
737
738         p->down1.x = p->move1.x = ev->canvas.x;
739         p->down1.y = p->move1.y = ev->canvas.y;
740
741         p->down_is_called = 1;
742         p->multi_touched = 0;
743
744         cal_util_get_geometry(&p->oringinal_size,p->vcur->month);
745 }
746
747 static void __cal_month_mouse_move_event_callback(void *data, Evas *e, Evas_Object *ly, void *ei)
748 {
749         c_retm_if(!data,  "data is null");
750         c_retm_if(!ei,  "ei is null");
751
752         cal_month_data *p = data;
753         Evas_Event_Mouse_Move *ev = ei;
754         Evas_Coord th = elm_config_finger_size_get();
755         int y_distance = ev->cur.canvas.y - p->down1.y;
756
757         if (th < abs(y_distance) && !p->ad->daily_events_mode) {
758                 struct appdata* ad = p->ad;
759                 c_ret_if(!ad);
760
761                 if (!p->multi_touched && !p->single_moved && !p->single_flicked) {
762                         edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(p->vcur->month), "moved", "prog");
763                         p->single_flicked = 1;
764                 }
765         }
766
767         if (th < abs(ev->cur.canvas.x - p->down1.x)) {
768                 struct appdata* ad = p->ad;
769                 c_ret_if(!ad);
770
771         }
772
773         if (0 == p->down_is_called)
774                 return;
775
776         p->move1.x = ev->cur.canvas.x;
777         p->move1.y = ev->cur.canvas.y;
778
779         if (!p->multi_touched && !p->single_flicked)
780                 __cal_month_move_month_calendar(p);
781 }
782
783 static void __cal_month_changed_callback(void *data, Evas_Object *obj, const char *e, const char *src)
784 {
785         __cal_month_update_genlist(data);
786 }
787
788 Evas_Object* cal_month_create_view(struct appdata *ad, Evas_Object *main)
789 {
790         CAL_FN_START;
791
792         c_retvm_if(!ad, NULL, "ad is null");
793         c_retvm_if(!main, NULL, "main is null");
794
795         cal_month_data *p;
796         Evas_Object *ly;
797         Evas_Object *month;
798         Evas_Object *list_bg;
799         int r;
800
801         p = calloc(1, sizeof(cal_month_data));
802         c_retv_if (!p, NULL);
803
804         r = vconf_get_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, (int *)&ad->is_display_weeknumber);
805         if (r != 0) {
806                 ERR("vconf_get_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, (int *)&ad->is_display_weeknumber) is failed");
807                 free(p);
808                 return NULL;
809         }
810
811         r = vconf_get_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, (int *)&ad->is_display_complete_todo);
812         if (r != 0) {
813                 ERR("vconf_get_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, (int *)&p->is_display_complete_todo) is failed");
814                 free(p);
815                 return NULL;
816         }
817
818         p->ad = ad;
819
820         ad->tapbar_focus_view = CV_MONTH;
821
822         p->parent = main;
823         p->oringinal_size.x = -1;
824         p->oringinal_size.y = -1;
825         p->oringinal_size.w = -1;
826         p->oringinal_size.h = -1;
827
828         __cal_month_switch_mode(p);
829
830         list_bg = cal_util_add_bg(p->vcur->container, EINA_FALSE);
831         if (!list_bg)
832         {
833                 ERR("cal_util_add_bg(ly, EINA_FALSE) is failed");
834                 evas_object_del(p->vcur->container);
835                 free(p);
836                 return NULL;
837         }
838
839         elm_object_part_content_set(p->vcur->container, "list/base", list_bg);
840
841         cal_lang_manager_add_callback(__cal_month_text_refresh_callback, p)
842
843         CAL_FN_END;
844
845         return p->vcur->container;
846 }
847
848 void cal_month_update_view(Evas_Object *ly)
849 {
850         CAL_FN_START;
851
852         c_retm_if(!ly, "ly is null");
853
854         cal_month_data *p;
855         struct appdata *ad;
856
857         p = CAL_UTIL_GET_PRIV_DATA(ly);
858         if (!p || CAL_STRCMP(p->name, _name)) {
859                 ERR("update month view: Invalid object");
860                 return;
861         }
862
863         ad = p->ad;
864         c_retm_if(!ad, "ad is null");
865
866         if (p->vcached_l != NULL && p->vcur != p->vcached_l) {
867                 __cal_month_view_del(p->vcached_l);
868                 p->vcached_l = NULL;
869         }
870
871         if (p->vcached_m != NULL && p->vcur != p->vcached_m) {
872                 __cal_month_view_del(p->vcached_m);
873                 p->vcached_m = NULL;
874         }
875
876         if (p->vcached_w != NULL && p->vcur != p->vcached_w) {
877                 __cal_month_view_del(p->vcached_w);
878                 p->vcached_w = NULL;
879         }
880
881         cal_month_calendar_update_view(p->vcur->month);
882
883         if (!p->ad->daily_events_mode)
884                 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(p->vcur->container), "go,line%d", cal_month_calendar_get_weekline(p->vcur->month));
885
886         __cal_month_update_genlist(p);
887
888         cal_util_delete_evas_object(&p->vcur->month_prev);
889         cal_util_delete_evas_object(&p->vcur->month_next);
890
891         CAL_FN_END;
892 }