summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorMichael BOUCHAUD <michael.bouchaud@gmail.com>2012-04-24 23:07:36 +0000
committerMichael BOUCHAUD <michael.bouchaud@gmail.com>2012-04-24 23:07:36 +0000
commit7fbc824940d912947c8dedb7ad8bcd0247536e69 (patch)
treeff826d92a4b6b46fa475849009c6af549457e4d2 /src/lib
parentcd3e2ecb8447f77867d13f387f7f90e53a133e15 (diff)
elementary: fix ELM_CALENDAR_SELECT_MODE_ONDEMAND
SVN revision: 70451
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elm_calendar.c173
-rw-r--r--src/lib/elm_calendar.h2
2 files changed, 108 insertions, 67 deletions
diff --git a/src/lib/elm_calendar.c b/src/lib/elm_calendar.c
index 2e41c5fc3..5e1a3e85c 100644
--- a/src/lib/elm_calendar.c
+++ b/src/lib/elm_calendar.c
@@ -29,9 +29,10 @@ struct _Widget_Data
29 Ecore_Timer *spin, *update_timer; 29 Ecore_Timer *spin, *update_timer;
30 Elm_Calendar_Format_Cb format_func; 30 Elm_Calendar_Format_Cb format_func;
31 const char *weekdays[ELM_DAY_LAST]; 31 const char *weekdays[ELM_DAY_LAST];
32 struct tm current_time, selected_time; 32 struct tm current_time, selected_time, showed_time;
33 Day_Color day_color[42]; // EINA_DEPRECATED 33 Day_Color day_color[42]; // EINA_DEPRECATED
34 Elm_Calendar_Select_Mode select_mode; 34 Elm_Calendar_Select_Mode select_mode;
35 Eina_Bool selected:1;
35}; 36};
36 37
37struct _Elm_Calendar_Mark 38struct _Elm_Calendar_Mark
@@ -130,6 +131,7 @@ static inline void
130_select(Widget_Data *wd, int selected) 131_select(Widget_Data *wd, int selected)
131{ 132{
132 char emission[32]; 133 char emission[32];
134 wd->selected_it = selected;
133 snprintf(emission, sizeof(emission), "cit_%i,selected", selected); 135 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
134 edje_object_signal_emit(wd->calendar, emission, "elm"); 136 edje_object_signal_emit(wd->calendar, emission, "elm");
135} 137}
@@ -204,7 +206,7 @@ _set_month_year(Widget_Data *wd)
204 char *buf; 206 char *buf;
205 207
206 /* Set selected month */ 208 /* Set selected month */
207 buf = wd->format_func(&wd->selected_time); 209 buf = wd->format_func(&wd->showed_time);
208 if (buf) 210 if (buf)
209 { 211 {
210 edje_object_part_text_escaped_set(wd->calendar, "month_text", buf); 212 edje_object_part_text_escaped_set(wd->calendar, "month_text", buf);
@@ -229,15 +231,15 @@ _populate(Evas_Object *obj)
229 231
230 if (wd->today_it > 0) _not_today(wd); 232 if (wd->today_it > 0) _not_today(wd);
231 233
232 maxdays = _maxdays_get(&wd->selected_time); 234 maxdays = _maxdays_get(&wd->showed_time);
233 mon = wd->selected_time.tm_mon; 235 mon = wd->showed_time.tm_mon;
234 yr = wd->selected_time.tm_year; 236 yr = wd->showed_time.tm_year;
235 237
236 _set_month_year(wd); 238 _set_month_year(wd);
237 239
238 /* Set days */ 240 /* Set days */
239 day = 0; 241 day = 0;
240 first_day = wd->selected_time; 242 first_day = wd->showed_time;
241 first_day.tm_mday = 1; 243 first_day.tm_mday = 1;
242 mktime(&first_day); 244 mktime(&first_day);
243 245
@@ -301,11 +303,19 @@ _populate(Evas_Object *obj)
301 { 303 {
302 if ((wd->selected_it > -1) && (wd->selected_it != i)) 304 if ((wd->selected_it > -1) && (wd->selected_it != i))
303 _unselect(wd, wd->selected_it); 305 _unselect(wd, wd->selected_it);
304 306 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
305 if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE) 307 {
306 _select(wd, i); 308 if ((mon == wd->selected_time.tm_mon)
307 309 && (yr == wd->selected_time.tm_year)
308 wd->selected_it = i; 310 && (wd->selected))
311 {
312 _select(wd, i);
313 }
314 }
315 else if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
316 {
317 _select(wd, i);
318 }
309 } 319 }
310 320
311 if ((day) && (day <= maxdays)) 321 if ((day) && (day <= maxdays))
@@ -323,8 +333,8 @@ _populate(Evas_Object *obj)
323 EINA_LIST_FOREACH(wd->marks, l, mark) 333 EINA_LIST_FOREACH(wd->marks, l, mark)
324 { 334 {
325 struct tm *mtime = &mark->mark_time; 335 struct tm *mtime = &mark->mark_time;
326 int month = wd->selected_time.tm_mon; 336 int month = wd->showed_time.tm_mon;
327 int year = wd->selected_time.tm_year; 337 int year = wd->showed_time.tm_year;
328 int mday_it = mtime->tm_mday + wd->first_day_it - 1; 338 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
329 339
330 switch (mark->repeat) 340 switch (mark->repeat)
@@ -488,6 +498,10 @@ _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *so
488static inline void 498static inline void
489_fix_selected_time(Widget_Data *wd) 499_fix_selected_time(Widget_Data *wd)
490{ 500{
501 if (wd->selected_time.tm_mon != wd->showed_time.tm_mon)
502 wd->selected_time.tm_mon = wd->showed_time.tm_mon;
503 if (wd->selected_time.tm_year != wd->showed_time.tm_year)
504 wd->selected_time.tm_year = wd->showed_time.tm_year;
491 mktime(&wd->selected_time); 505 mktime(&wd->selected_time);
492} 506}
493 507
@@ -500,39 +514,43 @@ _update_month(Evas_Object *obj, int delta)
500 if (!wd) return EINA_FALSE; 514 if (!wd) return EINA_FALSE;
501 515
502 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */ 516 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
503 time_check = wd->selected_time; 517 time_check = wd->showed_time;
504 time_check.tm_mon += delta; 518 time_check.tm_mon += delta;
505 if (mktime(&time_check) == -1) 519 if (mktime(&time_check) == -1)
506 return EINA_FALSE; 520 return EINA_FALSE;
507 521
508 wd->selected_time.tm_mon += delta; 522 wd->showed_time.tm_mon += delta;
509 if (wd->selected_time.tm_mon < 0) 523 if (wd->showed_time.tm_mon < 0)
510 { 524 {
511 if (wd->selected_time.tm_year == wd->year_min) 525 if (wd->showed_time.tm_year == wd->year_min)
512 { 526 {
513 wd->selected_time.tm_mon++; 527 wd->showed_time.tm_mon++;
514 return EINA_FALSE; 528 return EINA_FALSE;
515 } 529 }
516 wd->selected_time.tm_mon = 11; 530 wd->showed_time.tm_mon = 11;
517 wd->selected_time.tm_year--; 531 wd->showed_time.tm_year--;
518 } 532 }
519 else if (wd->selected_time.tm_mon > 11) 533 else if (wd->showed_time.tm_mon > 11)
520 { 534 {
521 if (wd->selected_time.tm_year == wd->year_max) 535 if (wd->showed_time.tm_year == wd->year_max)
522 { 536 {
523 wd->selected_time.tm_mon--; 537 wd->showed_time.tm_mon--;
524 return EINA_FALSE; 538 return EINA_FALSE;
525 } 539 }
526 wd->selected_time.tm_mon = 0; 540 wd->showed_time.tm_mon = 0;
527 wd->selected_time.tm_year++; 541 wd->showed_time.tm_year++;
528 } 542 }
529 543
530 maxdays = _maxdays_get(&wd->selected_time); 544 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
531 if (wd->selected_time.tm_mday > maxdays) 545 && (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE))
532 wd->selected_time.tm_mday = maxdays; 546 {
547 maxdays = _maxdays_get(&wd->showed_time);
548 if (wd->selected_time.tm_mday > maxdays)
549 wd->selected_time.tm_mday = maxdays;
533 550
534 _fix_selected_time(wd); 551 _fix_selected_time(wd);
535 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL); 552 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
553 }
536 554
537 return EINA_TRUE; 555 return EINA_TRUE;
538} 556}
@@ -590,7 +608,7 @@ _get_item_day(Evas_Object *obj, int selected_it)
590 if (!wd) return 0; 608 if (!wd) return 0;
591 609
592 day = selected_it - wd->first_day_it + 1; 610 day = selected_it - wd->first_day_it + 1;
593 if ((day < 0) || (day > _maxdays_get(&wd->selected_time))) 611 if ((day < 0) || (day > _maxdays_get(&wd->showed_time)))
594 return 0; 612 return 0;
595 613
596 return day; 614 return day;
@@ -609,11 +627,12 @@ _update_sel_it(Evas_Object *obj, int sel_it)
609 return; 627 return;
610 628
611 _unselect(wd, wd->selected_it); 629 _unselect(wd, wd->selected_it);
630 if (!wd->selected)
631 wd->selected = EINA_TRUE;
612 632
613 wd->selected_it = sel_it;
614 wd->selected_time.tm_mday = day; 633 wd->selected_time.tm_mday = day;
615 _select(wd, wd->selected_it);
616 _fix_selected_time(wd); 634 _fix_selected_time(wd);
635 _select(wd, sel_it);
617 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL); 636 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
618} 637}
619 638
@@ -650,8 +669,8 @@ _update_cur_date(void *data)
650 t = _time_to_next_day(&wd->current_time); 669 t = _time_to_next_day(&wd->current_time);
651 ecore_timer_interval_set(wd->update_timer, t); 670 ecore_timer_interval_set(wd->update_timer, t);
652 671
653 if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) || 672 if ((wd->current_time.tm_mon != wd->showed_time.tm_mon) ||
654 (wd->current_time.tm_year!= wd->selected_time.tm_year)) 673 (wd->current_time.tm_year!= wd->showed_time.tm_year))
655 return ECORE_CALLBACK_RENEW; 674 return ECORE_CALLBACK_RENEW;
656 675
657 day = wd->current_time.tm_mday + wd->first_day_it - 1; 676 day = wd->current_time.tm_mday + wd->first_day_it - 1;
@@ -669,30 +688,9 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
669 688
670 if (!wd) return EINA_FALSE; 689 if (!wd) return EINA_FALSE;
671 if (elm_widget_disabled_get(obj)) return EINA_FALSE; 690 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
672 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE) return EINA_FALSE;
673 691
674 if ((!strcmp(ev->keyname, "Left")) || 692 if ((!strcmp(ev->keyname, "Prior")) ||
675 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string))) 693 ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
676 {
677 _update_sel_it(obj, wd->selected_it-1);
678 }
679 else if ((!strcmp(ev->keyname, "Right")) ||
680 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
681 {
682 _update_sel_it(obj, wd->selected_it+1);
683 }
684 else if ((!strcmp(ev->keyname, "Up")) ||
685 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
686 {
687 _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
688 }
689 else if ((!strcmp(ev->keyname, "Down")) ||
690 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
691 {
692 _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
693 }
694 else if ((!strcmp(ev->keyname, "Prior")) ||
695 ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
696 { 694 {
697 if (_update_month(obj, -1)) _populate(obj); 695 if (_update_month(obj, -1)) _populate(obj);
698 } 696 }
@@ -701,6 +699,45 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
701 { 699 {
702 if (_update_month(obj, 1)) _populate(obj); 700 if (_update_month(obj, 1)) _populate(obj);
703 } 701 }
702
703 else if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
704 && ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
705 || (wd->selected)))
706 {
707 if ((!strcmp(ev->keyname, "Left")) ||
708 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
709 {
710 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
711 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
712 && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
713 _update_sel_it(obj, wd->selected_it-1);
714 }
715 else if ((!strcmp(ev->keyname, "Right")) ||
716 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
717 {
718 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
719 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
720 && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
721 _update_sel_it(obj, wd->selected_it+1);
722 }
723 else if ((!strcmp(ev->keyname, "Up")) ||
724 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
725 {
726 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
727 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
728 && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
729 _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
730 }
731 else if ((!strcmp(ev->keyname, "Down")) ||
732 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
733 {
734 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
735 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
736 && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
737 _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
738 }
739 else return EINA_FALSE;
740 }
704 else return EINA_FALSE; 741 else return EINA_FALSE;
705 742
706 return EINA_TRUE; 743 return EINA_TRUE;
@@ -776,8 +813,9 @@ elm_calendar_add(Evas_Object *parent)
776 } 813 }
777 814
778 current_time = time(NULL); 815 current_time = time(NULL);
779 localtime_r(&current_time, &wd->selected_time); 816 localtime_r(&current_time, &wd->showed_time);
780 wd->current_time = wd->selected_time; 817 wd->current_time = wd->showed_time;
818 wd->selected_time = wd->showed_time;
781 t = _time_to_next_day(&wd->current_time); 819 t = _time_to_next_day(&wd->current_time);
782 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj); 820 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
783 821
@@ -846,11 +884,10 @@ elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
846 wd->year_max = max; 884 wd->year_max = max;
847 else 885 else
848 wd->year_max = wd->year_min; 886 wd->year_max = wd->year_min;
849 if (wd->selected_time.tm_year > wd->year_max) 887 if (wd->showed_time.tm_year > wd->year_max)
850 wd->selected_time.tm_year = wd->year_max; 888 wd->showed_time.tm_year = wd->year_max;
851 if (wd->selected_time.tm_year < wd->year_min) 889 if (wd->showed_time.tm_year < wd->year_min)
852 wd->selected_time.tm_year = wd->year_min; 890 wd->showed_time.tm_year = wd->year_min;
853 _fix_selected_time(wd);
854 _populate(obj); 891 _populate(obj);
855} 892}
856 893
@@ -891,6 +928,7 @@ elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
891 928
892 EINA_SAFETY_ON_NULL_RETURN(selected_time); 929 EINA_SAFETY_ON_NULL_RETURN(selected_time);
893 wd->selected_time = *selected_time; 930 wd->selected_time = *selected_time;
931 _fix_selected_time(wd);
894 _populate(obj); 932 _populate(obj);
895 return; 933 return;
896} 934}
@@ -1010,7 +1048,10 @@ elm_calendar_select_mode_set(Evas_Object *obj, Elm_Calendar_Select_Mode mode)
1010 && (wd->select_mode != mode)) 1048 && (wd->select_mode != mode))
1011 { 1049 {
1012 wd->select_mode = mode; 1050 wd->select_mode = mode;
1013 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS) 1051 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
1052 wd->selected = EINA_FALSE;
1053 if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
1054 || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_DEFAULT))
1014 _select(wd, wd->selected_it); 1055 _select(wd, wd->selected_it);
1015 else 1056 else
1016 _unselect(wd, wd->selected_it); 1057 _unselect(wd, wd->selected_it);
diff --git a/src/lib/elm_calendar.h b/src/lib/elm_calendar.h
index 6778018ab..0eb7eac77 100644
--- a/src/lib/elm_calendar.h
+++ b/src/lib/elm_calendar.h
@@ -92,7 +92,7 @@ typedef enum
92 ELM_CALENDAR_SELECT_MODE_DEFAULT = 0, /**< Default value. a day is always selected. */ 92 ELM_CALENDAR_SELECT_MODE_DEFAULT = 0, /**< Default value. a day is always selected. */
93 ELM_CALENDAR_SELECT_MODE_ALWAYS, /**< a day is always selected. */ 93 ELM_CALENDAR_SELECT_MODE_ALWAYS, /**< a day is always selected. */
94 ELM_CALENDAR_SELECT_MODE_NONE, /**< None of the days can be selected. */ 94 ELM_CALENDAR_SELECT_MODE_NONE, /**< None of the days can be selected. */
95 ELM_CALENDAR_SELECT_MODE_ONDEMAND /**< User may have selected a day or not. (not supported yet)*/ 95 ELM_CALENDAR_SELECT_MODE_ONDEMAND /**< User may have selected a day or not. */
96} _Elm_Calendar_Select_Mode; 96} _Elm_Calendar_Select_Mode;
97 97
98/** 98/**