2 # include "elementary_config.h"
9 #include <Elementary.h>
12 typedef enum _Day_Color // EINA_DEPRECATED
19 typedef struct _Widget_Data Widget_Data;
23 Evas_Object *calendar;
25 double interval, first_interval;
26 int year_min, year_max, spin_speed;
27 int today_it, selected_it, first_day_it;
28 Elm_Calendar_Weekday first_week_day;
29 Ecore_Timer *spin, *update_timer;
30 Elm_Calendar_Format_Cb format_func;
31 const char *weekdays[ELM_DAY_LAST];
32 struct tm current_time, selected_time, showed_time;
33 Day_Color day_color[42]; // EINA_DEPRECATED
34 Elm_Calendar_Select_Mode select_mode;
38 struct _Elm_Calendar_Mark
43 const char *mark_type;
44 Elm_Calendar_Mark_Repeat_Type repeat;
47 static const char *widtype = NULL;
48 static void _on_focus_hook(void *data, Evas_Object *obj);
49 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
51 static const char SIG_CHANGED[] = "changed";
53 static const Evas_Smart_Cb_Description _signals[] = {
59 /* Should not be translated, it's used if we failed
60 * getting from locale. */
61 static const char *_days_abbrev[] =
63 "Sun", "Mon", "Tue", "Wed",
67 static int _days_in_month[2][12] =
69 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
70 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
73 static Elm_Calendar_Mark *
74 _mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat)
76 Widget_Data *wd = elm_widget_data_get(obj);
77 Elm_Calendar_Mark *mark;
80 mark = calloc(1, sizeof(Elm_Calendar_Mark));
81 if (!mark) return NULL;
83 mark->mark_type = eina_stringshare_add(mark_type);
84 mark->mark_time = *mark_time;
85 mark->repeat = repeat;
90 _mark_free(Elm_Calendar_Mark *mark)
92 eina_stringshare_del(mark->mark_type);
97 _sizing_eval(Evas_Object *obj)
99 Widget_Data *wd = elm_widget_data_get(obj);
100 Evas_Coord minw = -1, minh = -1;
102 elm_coords_finger_size_adjust(8, &minw, 7, &minh);
103 edje_object_size_min_restricted_calc(wd->calendar, &minw, &minh, minw, minh);
104 evas_object_size_hint_min_set(obj, minw, minh);
105 evas_object_size_hint_max_set(obj, -1, -1);
109 _maxdays_get(struct tm *selected_time)
113 month = selected_time->tm_mon;
114 year = selected_time->tm_year + 1900;
116 return _days_in_month[((!(year % 4)) &&
123 _unselect(Widget_Data *wd, int selected)
126 snprintf(emission, sizeof(emission), "cit_%i,unselected", selected);
127 edje_object_signal_emit(wd->calendar, emission, "elm");
131 _select(Widget_Data *wd, int selected)
134 wd->selected_it = selected;
135 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
136 edje_object_signal_emit(wd->calendar, emission, "elm");
140 _not_today(Widget_Data *wd)
143 snprintf(emission, sizeof(emission), "cit_%i,not_today", wd->today_it);
144 edje_object_signal_emit(wd->calendar, emission, "elm");
149 _today(Widget_Data *wd, int it)
152 snprintf(emission, sizeof(emission), "cit_%i,today", it);
153 edje_object_signal_emit(wd->calendar, emission, "elm");
158 _format_month_year(struct tm *selected_time)
161 if (!strftime(buf, sizeof(buf), E_("%B %Y"), selected_time)) return NULL;
166 _cit_mark(Evas_Object *cal, int cit, const char *mtype)
169 snprintf(sign, sizeof(sign), "cit_%i,%s", cit, mtype);
170 edje_object_signal_emit(cal, sign, "elm");
174 _weekday_get(int first_week_day, int day)
176 return (day + first_week_day - 1) % ELM_DAY_LAST;
181 _text_day_color_update(Widget_Data *wd, int pos)
185 switch (wd->day_color[pos])
188 snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
191 snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
194 snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
200 edje_object_signal_emit(wd->calendar, emission, "elm");
204 _set_month_year(Widget_Data *wd)
208 /* Set selected month */
209 buf = wd->format_func(&wd->showed_time);
212 edje_object_part_text_escaped_set(wd->calendar, "month_text", buf);
216 edje_object_part_text_escaped_set(wd->calendar, "month_text", "");
220 _populate(Evas_Object *obj)
222 int maxdays, day, mon, yr, i;
223 Elm_Calendar_Mark *mark;
224 char part[12], day_s[3];
227 Eina_Bool last_row = EINA_TRUE;
228 Widget_Data *wd = elm_widget_data_get(obj);
232 if (wd->today_it > 0) _not_today(wd);
234 maxdays = _maxdays_get(&wd->showed_time);
235 mon = wd->showed_time.tm_mon;
236 yr = wd->showed_time.tm_year;
242 first_day = wd->showed_time;
243 first_day.tm_mday = 1;
246 // Layout of the calendar is changed for removing the unfilled last row.
247 if (first_day.tm_wday < (int)wd->first_week_day)
248 wd->first_day_it = first_day.tm_wday + ELM_DAY_LAST - wd->first_week_day;
250 wd->first_day_it = first_day.tm_wday - wd->first_week_day;
252 if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
258 for (i = 0; i < 5; i++)
260 snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
261 edje_object_signal_emit(wd->calendar, emission, "elm");
263 snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
264 edje_object_signal_emit(wd->calendar, emission, "elm");
265 for (i = 0; i < 35; i++)
267 snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
268 edje_object_signal_emit(wd->calendar, emission, "elm");
270 for (i = 35; i < 42; i++)
272 snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
273 edje_object_signal_emit(wd->calendar, emission, "elm");
280 for (i = 0; i < 6; i++)
282 snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
283 edje_object_signal_emit(wd->calendar, emission, "elm");
285 for (i = 0; i < 42; i++)
287 snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
288 edje_object_signal_emit(wd->calendar, emission, "elm");
292 for (i = 0; i < 42; i++)
294 _text_day_color_update(wd, i); // EINA_DEPRECATED
295 if ((!day) && (i == wd->first_day_it)) day = 1;
297 if ((day == wd->current_time.tm_mday)
298 && (mon == wd->current_time.tm_mon)
299 && (yr == wd->current_time.tm_year))
302 if (day == wd->selected_time.tm_mday)
304 if ((wd->selected_it > -1) && (wd->selected_it != i))
305 _unselect(wd, wd->selected_it);
306 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
308 if ((mon == wd->selected_time.tm_mon)
309 && (yr == wd->selected_time.tm_year)
315 else if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
321 if ((day) && (day <= maxdays))
322 snprintf(day_s, sizeof(day_s), "%i", day++);
326 snprintf(part, sizeof(part), "cit_%i.text", i);
327 edje_object_part_text_set(wd->calendar, part, day_s);
328 /* Clear previous marks */
329 _cit_mark(wd->calendar, i, "clear");
333 EINA_LIST_FOREACH(wd->marks, l, mark)
335 struct tm *mtime = &mark->mark_time;
336 int month = wd->showed_time.tm_mon;
337 int year = wd->showed_time.tm_year;
338 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
340 switch (mark->repeat)
342 case ELM_CALENDAR_UNIQUE:
343 if ((mtime->tm_mon == month) && (mtime->tm_year == year))
344 _cit_mark(wd->calendar, mday_it, mark->mark_type);
346 case ELM_CALENDAR_DAILY:
347 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
348 (mtime->tm_year < year))
350 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
351 day = mtime->tm_mday;
354 for (; day <= maxdays; day++)
355 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
358 case ELM_CALENDAR_WEEKLY:
359 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
360 (mtime->tm_year < year))
362 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
363 day = mtime->tm_mday;
366 for (; day <= maxdays; day++)
367 if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
368 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
371 case ELM_CALENDAR_MONTHLY:
372 if (((mtime->tm_year < year) ||
373 ((mtime->tm_year == year) && (mtime->tm_mon <= month))) &&
374 (mtime->tm_mday <= maxdays))
375 _cit_mark(wd->calendar, mday_it, mark->mark_type);
377 case ELM_CALENDAR_ANNUALLY:
378 if ((mtime->tm_year <= year) && (mtime->tm_mon == month) &&
379 (mtime->tm_mday <= maxdays))
380 _cit_mark(wd->calendar, mday_it, mark->mark_type);
387 _set_headers(Evas_Object *obj)
389 static char part[] = "ch_0.text";
391 Widget_Data *wd = elm_widget_data_get(obj);
394 for (i = 0; i < ELM_DAY_LAST; i++)
397 edje_object_part_text_escaped_set
399 wd->weekdays[(i + wd->first_week_day) % ELM_DAY_LAST]);
404 _del_hook(Evas_Object *obj)
407 Elm_Calendar_Mark *mark;
408 Widget_Data *wd = elm_widget_data_get(obj);
412 if (wd->spin) ecore_timer_del(wd->spin);
413 if (wd->update_timer) ecore_timer_del(wd->update_timer);
417 EINA_LIST_FREE(wd->marks, mark)
423 for (i = 0; i < ELM_DAY_LAST; i++)
424 eina_stringshare_del(wd->weekdays[i]);
430 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (elm_widget_focus_get(obj))
436 edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
437 evas_object_focus_set(wd->calendar, EINA_TRUE);
441 edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
442 evas_object_focus_set(wd->calendar, EINA_FALSE);
447 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
449 Widget_Data *wd = elm_widget_data_get(obj);
451 edje_object_mirrored_set(wd->calendar, rtl);
455 _theme_hook(Evas_Object *obj)
457 Widget_Data *wd = elm_widget_data_get(obj);
459 _elm_widget_mirrored_reload(obj);
460 _elm_theme_object_set(obj, wd->calendar, "calendar", "base",
461 elm_widget_style_get(obj));
462 _mirrored_set(obj, elm_widget_mirrored_get(obj));
465 edje_object_message_signal_process(wd->calendar);
466 edje_object_scale_set(wd->calendar,
467 elm_widget_scale_get(obj) * _elm_config->scale);
472 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
474 Widget_Data *wd = elm_widget_data_get(obj);
476 edje_object_signal_emit(wd->calendar, emission, source);
480 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
482 Widget_Data *wd = elm_widget_data_get(obj);
484 edje_object_signal_callback_add(wd->calendar, emission,
485 source, func_cb, data);
489 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
491 Widget_Data *wd = elm_widget_data_get(obj);
493 edje_object_signal_callback_del_full(wd->calendar, emission, source, func_cb,
497 /* Set correct tm_wday and tm_yday after other fields changes*/
499 _fix_selected_time(Widget_Data *wd)
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;
505 mktime(&wd->selected_time);
509 _update_month(Evas_Object *obj, int delta)
511 struct tm time_check;
513 Widget_Data *wd = elm_widget_data_get(obj);
514 if (!wd) return EINA_FALSE;
516 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
517 time_check = wd->showed_time;
518 time_check.tm_mon += delta;
519 if (mktime(&time_check) == -1)
522 wd->showed_time.tm_mon += delta;
523 if (wd->showed_time.tm_mon < 0)
525 if (wd->showed_time.tm_year == wd->year_min)
527 wd->showed_time.tm_mon++;
530 wd->showed_time.tm_mon = 11;
531 wd->showed_time.tm_year--;
533 else if (wd->showed_time.tm_mon > 11)
535 if (wd->showed_time.tm_year == wd->year_max)
537 wd->showed_time.tm_mon--;
540 wd->showed_time.tm_mon = 0;
541 wd->showed_time.tm_year++;
544 if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
545 && (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE))
547 maxdays = _maxdays_get(&wd->showed_time);
548 if (wd->selected_time.tm_mday > maxdays)
549 wd->selected_time.tm_mday = maxdays;
551 _fix_selected_time(wd);
552 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
559 _spin_value(void *data)
561 Widget_Data *wd = elm_widget_data_get(data);
562 if (!wd) return ECORE_CALLBACK_CANCEL;
563 if (_update_month(data, wd->spin_speed)) _populate(data);
564 wd->interval = wd->interval / 1.05;
565 ecore_timer_interval_set(wd->spin, wd->interval);
566 return ECORE_CALLBACK_RENEW;
570 _button_inc_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
572 Widget_Data *wd = elm_widget_data_get(data);
574 wd->interval = wd->first_interval;
576 if (wd->spin) ecore_timer_del(wd->spin);
577 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
582 _button_dec_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
584 Widget_Data *wd = elm_widget_data_get(data);
586 wd->interval = wd->first_interval;
588 if (wd->spin) ecore_timer_del(wd->spin);
589 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
594 _button_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
596 Widget_Data *wd = elm_widget_data_get(data);
598 wd->interval = wd->first_interval;
599 if (wd->spin) ecore_timer_del(wd->spin);
604 _get_item_day(Evas_Object *obj, int selected_it)
607 Widget_Data *wd = elm_widget_data_get(obj);
610 day = selected_it - wd->first_day_it + 1;
611 if ((day < 0) || (day > _maxdays_get(&wd->showed_time)))
618 _update_sel_it(Evas_Object *obj, int sel_it)
621 Widget_Data *wd = elm_widget_data_get(obj);
622 if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
625 day = _get_item_day(obj, sel_it);
629 _unselect(wd, wd->selected_it);
631 wd->selected = EINA_TRUE;
633 wd->selected_time.tm_mday = day;
634 _fix_selected_time(wd);
636 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
640 _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
643 Widget_Data *wd = elm_widget_data_get(data);
644 if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
646 sel_it = atoi(source);
648 _update_sel_it(data, sel_it);
652 _time_to_next_day(struct tm *t)
654 return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
658 _update_cur_date(void *data)
662 Widget_Data *wd = elm_widget_data_get(data);
663 if (!wd) return ECORE_CALLBACK_RENEW;
665 if (wd->today_it > 0) _not_today(wd);
667 current_time = time(NULL);
668 localtime_r(¤t_time, &wd->current_time);
669 t = _time_to_next_day(&wd->current_time);
670 ecore_timer_interval_set(wd->update_timer, t);
672 if ((wd->current_time.tm_mon != wd->showed_time.tm_mon) ||
673 (wd->current_time.tm_year!= wd->showed_time.tm_year))
674 return ECORE_CALLBACK_RENEW;
676 day = wd->current_time.tm_mday + wd->first_day_it - 1;
679 return ECORE_CALLBACK_RENEW;
683 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
685 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
686 Evas_Event_Key_Down *ev = event_info;
687 Widget_Data *wd = elm_widget_data_get(obj);
689 if (!wd) return EINA_FALSE;
690 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
692 if ((!strcmp(ev->keyname, "Prior")) ||
693 ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
695 if (_update_month(obj, -1)) _populate(obj);
697 else if ((!strcmp(ev->keyname, "Next")) ||
698 ((!strcmp(ev->keyname, "KP_Next")) && (!ev->string)))
700 if (_update_month(obj, 1)) _populate(obj);
703 else if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
704 && ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
707 if ((!strcmp(ev->keyname, "Left")) ||
708 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
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);
715 else if ((!strcmp(ev->keyname, "Right")) ||
716 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
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);
723 else if ((!strcmp(ev->keyname, "Up")) ||
724 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
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);
731 else if ((!strcmp(ev->keyname, "Down")) ||
732 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
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);
739 else return EINA_FALSE;
741 else return EINA_FALSE;
747 elm_calendar_add(Evas_Object *parent)
750 time_t weekday = 259200; /* Just the first sunday since epoch */
756 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
758 ELM_SET_WIDTYPE(widtype, "calendar");
759 elm_widget_type_set(obj, "calendar");
760 elm_widget_sub_object_add(parent, obj);
761 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
762 elm_widget_data_set(obj, wd);
763 elm_widget_del_hook_set(obj, _del_hook);
764 elm_widget_theme_hook_set(obj, _theme_hook);
765 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
766 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
767 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
768 elm_widget_can_focus_set(obj, EINA_TRUE);
769 elm_widget_event_hook_set(obj, _event_hook);
771 wd->first_interval = 0.85;
775 wd->selected_it = -1;
776 wd->first_day_it = -1;
777 wd->format_func = _format_month_year;
780 wd->calendar = edje_object_add(e);
781 _elm_theme_object_set(obj, wd->calendar, "calendar", "base", "default");
782 elm_widget_resize_object_set(obj, wd->calendar);
784 edje_object_signal_callback_add(wd->calendar, "elm,action,increment,start",
785 "*", _button_inc_start, obj);
786 edje_object_signal_callback_add(wd->calendar, "elm,action,decrement,start",
787 "*", _button_dec_start, obj);
788 edje_object_signal_callback_add(wd->calendar, "elm,action,stop",
789 "*", _button_stop, obj);
790 edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
791 "*", _day_selected, obj);
793 evas_object_smart_callbacks_descriptions_set(obj, _signals);
795 for (i = 0; i < ELM_DAY_LAST; i++)
797 /* FIXME: I'm not aware of a known max, so if it fails,
798 * just make it larger. :| */
800 /* I don't know of a better way of doing it */
801 if (strftime(buf, sizeof(buf), "%a", gmtime(&weekday)))
803 wd->weekdays[i] = eina_stringshare_add(buf);
807 /* If we failed getting day, get a default value */
808 wd->weekdays[i] = _days_abbrev[i];
809 WRN("Failed getting weekday name for '%s' from locale.",
812 weekday += 86400; /* Advance by a day */
815 current_time = time(NULL);
816 localtime_r(¤t_time, &wd->showed_time);
817 wd->current_time = wd->showed_time;
818 wd->selected_time = wd->showed_time;
819 t = _time_to_next_day(&wd->current_time);
820 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
824 _mirrored_set(obj, elm_widget_mirrored_get(obj));
830 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
833 ELM_CHECK_WIDTYPE(obj, widtype);
834 Widget_Data *wd = elm_widget_data_get(obj);
837 EINA_SAFETY_ON_NULL_RETURN(weekdays);
839 for (i = 0; i < ELM_DAY_LAST; i++)
841 eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
847 elm_calendar_weekdays_names_get(const Evas_Object *obj)
849 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
850 Widget_Data *wd = elm_widget_data_get(obj);
851 if (!wd) return NULL;
856 elm_calendar_interval_set(Evas_Object *obj, double interval)
858 ELM_CHECK_WIDTYPE(obj, widtype);
859 Widget_Data *wd = elm_widget_data_get(obj);
861 wd->first_interval = interval;
865 elm_calendar_interval_get(const Evas_Object *obj)
867 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
868 Widget_Data *wd = elm_widget_data_get(obj);
870 return wd->first_interval;
874 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
876 ELM_CHECK_WIDTYPE(obj, widtype);
877 Widget_Data *wd = elm_widget_data_get(obj);
881 if ((wd->year_min == min) && (wd->year_max == max)) return;
882 wd->year_min = min > 2 ? min : 2;
883 if (max > wd->year_min)
886 wd->year_max = wd->year_min;
887 if (wd->showed_time.tm_year > wd->year_max)
888 wd->showed_time.tm_year = wd->year_max;
889 if (wd->showed_time.tm_year < wd->year_min)
890 wd->showed_time.tm_year = wd->year_min;
895 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
897 ELM_CHECK_WIDTYPE(obj, widtype);
898 Widget_Data *wd = elm_widget_data_get(obj);
900 if (min) *min = wd->year_min + 1900;
901 if (max) *max = wd->year_max + 1900;
904 EINA_DEPRECATED EAPI void
905 elm_calendar_day_selection_disabled_set(Evas_Object *obj, Eina_Bool disabled)
908 elm_calendar_select_mode_set(obj, ELM_CALENDAR_SELECT_MODE_NONE);
910 elm_calendar_select_mode_set(obj, ELM_CALENDAR_SELECT_MODE_DEFAULT);
913 EINA_DEPRECATED EAPI Eina_Bool
914 elm_calendar_day_selection_disabled_get(const Evas_Object *obj)
916 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
917 Widget_Data *wd = elm_widget_data_get(obj);
918 if (!wd) return EINA_FALSE;
919 return !!(wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE);
923 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
925 ELM_CHECK_WIDTYPE(obj, widtype);
926 Widget_Data *wd = elm_widget_data_get(obj);
929 EINA_SAFETY_ON_NULL_RETURN(selected_time);
930 wd->selected_time = *selected_time;
932 wd->selected = EINA_TRUE;
933 if (wd->selected_time.tm_year != wd->showed_time.tm_year)
934 wd->showed_time.tm_year = wd->selected_time.tm_year;
935 if (wd->selected_time.tm_mon != wd->showed_time.tm_mon)
936 wd->showed_time.tm_mon = wd->selected_time.tm_mon;
938 _fix_selected_time(wd);
944 elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
946 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
947 Widget_Data *wd = elm_widget_data_get(obj);
948 if (!wd) return EINA_FALSE;
949 EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
950 if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
953 *selected_time = wd->selected_time;
958 elm_calendar_format_function_set(Evas_Object *obj, Elm_Calendar_Format_Cb format_function)
960 ELM_CHECK_WIDTYPE(obj, widtype);
961 Widget_Data *wd = elm_widget_data_get(obj);
963 wd->format_func = format_function;
967 EAPI Elm_Calendar_Mark *
968 elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat)
970 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
971 Widget_Data *wd = elm_widget_data_get(obj);
972 Elm_Calendar_Mark *mark;
973 if (!wd) return NULL;
975 mark = _mark_new(obj, mark_type, mark_time, repeat);
976 wd->marks = eina_list_append(wd->marks, mark);
977 mark->node = eina_list_last(wd->marks);
982 elm_calendar_mark_del(Elm_Calendar_Mark *mark)
987 EINA_SAFETY_ON_NULL_RETURN(mark);
990 wd = elm_widget_data_get(obj);
993 wd->marks = eina_list_remove_list(wd->marks, mark->node);
998 elm_calendar_marks_clear(Evas_Object *obj)
1000 ELM_CHECK_WIDTYPE(obj, widtype);
1001 Widget_Data *wd = elm_widget_data_get(obj);
1002 Elm_Calendar_Mark *mark;
1005 EINA_LIST_FREE(wd->marks, mark)
1009 EAPI const Eina_List *
1010 elm_calendar_marks_get(const Evas_Object *obj)
1012 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1013 Widget_Data *wd = elm_widget_data_get(obj);
1014 if (!wd) return NULL;
1019 elm_calendar_marks_draw(Evas_Object *obj)
1021 ELM_CHECK_WIDTYPE(obj, widtype);
1022 Widget_Data *wd = elm_widget_data_get(obj);
1028 elm_calendar_first_day_of_week_set(Evas_Object *obj, Elm_Calendar_Weekday day)
1030 ELM_CHECK_WIDTYPE(obj, widtype);
1031 Widget_Data *wd = elm_widget_data_get(obj);
1033 if (day >= ELM_DAY_LAST) return;
1034 if (wd->first_week_day != day)
1036 wd->first_week_day = day;
1042 EAPI Elm_Calendar_Weekday
1043 elm_calendar_first_day_of_week_get(const Evas_Object *obj)
1045 ELM_CHECK_WIDTYPE(obj, widtype) -1;
1046 Widget_Data *wd = elm_widget_data_get(obj);
1048 return wd->first_week_day;
1052 elm_calendar_select_mode_set(Evas_Object *obj, Elm_Calendar_Select_Mode mode)
1054 ELM_CHECK_WIDTYPE(obj, widtype);
1055 Widget_Data *wd = elm_widget_data_get(obj);
1057 if ((mode <= ELM_CALENDAR_SELECT_MODE_ONDEMAND)
1058 && (wd->select_mode != mode))
1060 wd->select_mode = mode;
1061 if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
1062 wd->selected = EINA_FALSE;
1063 if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
1064 || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_DEFAULT))
1065 _select(wd, wd->selected_it);
1067 _unselect(wd, wd->selected_it);
1071 EAPI Elm_Calendar_Select_Mode
1072 elm_calendar_select_mode_get(const Evas_Object *obj)
1074 ELM_CHECK_WIDTYPE(obj, widtype) -1;
1075 Widget_Data *wd = elm_widget_data_get(obj);
1077 return wd->select_mode;