2 # include "elementary_config.h"
9 #include <Elementary.h>
15 * A calendar is a widget that allows the user to select a date. It has
16 * support to adding check marks (holidays and checks by default). The calendar
17 * is displayed one month at a time.
19 * Weekday names and the function used to format month and year to
20 * be displayed can be set, giving more flexibility to this widget.
22 * Signals that you can add callbacks for are:
24 * "changed" - emitted when the user selects a day or changes the displayed
25 * month, what actually changes the selected day as well.
28 typedef enum _Day_Color // EINA_DEPRECATED
35 typedef struct _Widget_Data Widget_Data;
39 Evas_Object *calendar;
41 double interval, first_interval;
42 int year_min, year_max, spin_speed;
43 int today_it, selected_it, first_day_it;
44 Ecore_Timer *spin, *update_timer;
45 char * (*format_func) (struct tm *selected_time);
46 const char *weekdays[7];
47 struct tm current_time, selected_time;
48 Day_Color day_color[42]; // EINA_DEPRECATED
49 Eina_Bool selection_enabled : 1;
52 struct _Elm_Calendar_Mark
57 const char *mark_type;
58 Elm_Calendar_Mark_Repeat repeat;
61 static const char *widtype = NULL;
62 static void _on_focus_hook(void *data, Evas_Object *obj);
63 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
65 static const char SIG_CHANGED[] = "changed";
67 static const Evas_Smart_Cb_Description _signals[] = {
73 /* Should not be translated, it's used if we failed
74 * getting from locale. */
75 static const char *_days_abbrev[] =
77 "Sun", "Mon", "Tue", "Wed",
81 static int _days_in_month[2][12] =
83 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
84 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
87 static Elm_Calendar_Mark *
88 _mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
90 Widget_Data *wd = elm_widget_data_get(obj);
91 Elm_Calendar_Mark *mark;
94 mark = calloc(1, sizeof(Elm_Calendar_Mark));
95 if (!mark) return NULL;
97 mark->mark_type = eina_stringshare_add(mark_type);
98 mark->mark_time = *mark_time;
99 mark->repeat = repeat;
104 _mark_free(Elm_Calendar_Mark *mark)
106 eina_stringshare_del(mark->mark_type);
111 _sizing_eval(Evas_Object *obj)
113 Widget_Data *wd = elm_widget_data_get(obj);
114 Evas_Coord minw = -1, minh = -1;
116 elm_coords_finger_size_adjust(8, &minw, 7, &minh);
117 edje_object_size_min_restricted_calc(wd->calendar, &minw, &minh, minw, minh);
118 evas_object_size_hint_min_set(obj, minw, minh);
119 evas_object_size_hint_max_set(obj, -1, -1);
123 _maxdays_get(struct tm *selected_time)
127 month = selected_time->tm_mon;
128 year = selected_time->tm_year + 1900;
130 return _days_in_month[((!(year % 4)) &&
137 _unselect(Widget_Data *wd, int selected)
140 snprintf(emission, sizeof(emission), "cit_%i,unselected", selected);
141 edje_object_signal_emit(wd->calendar, emission, "elm");
145 _select(Widget_Data *wd, int selected)
148 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
149 edje_object_signal_emit(wd->calendar, emission, "elm");
153 _not_today(Widget_Data *wd)
156 snprintf(emission, sizeof(emission), "cit_%i,not_today", wd->today_it);
157 edje_object_signal_emit(wd->calendar, emission, "elm");
162 _today(Widget_Data *wd, int it)
165 snprintf(emission, sizeof(emission), "cit_%i,today", it);
166 edje_object_signal_emit(wd->calendar, emission, "elm");
171 _format_month_year(struct tm *selected_time)
174 if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
179 _cit_mark(Evas_Object *cal, int cit, const char *mtype)
182 snprintf(sign, sizeof(sign), "cit_%i,%s", cit, mtype);
183 edje_object_signal_emit(cal, sign, "elm");
187 _weekday_get(int first_week_day, int day)
189 return (day + first_week_day - 1) % 7;
194 _text_day_color_update(Widget_Data *wd, int pos)
198 switch (wd->day_color[pos])
201 snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
204 snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
207 snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
213 edje_object_signal_emit(wd->calendar, emission, "elm");
218 _text_day_color_set(Widget_Data *wd, Day_Color col, int pos)
220 if ((pos < 0) || (pos >= 42)) return;
221 if (wd->day_color[pos] == col) return;
222 wd->day_color[pos] = col;
223 _text_day_color_update(wd, pos);
227 _populate(Evas_Object *obj)
229 int maxdays, day, mon, year, i;
230 Elm_Calendar_Mark *mark;
231 char part[12], day_s[3];
235 Eina_Bool last_row = EINA_TRUE;
236 Widget_Data *wd = elm_widget_data_get(obj);
240 if (wd->today_it > 0) _not_today(wd);
242 maxdays = _maxdays_get(&wd->selected_time);
243 mon = wd->selected_time.tm_mon;
244 year = wd->selected_time.tm_year;
246 /* Set selected month */
247 buf = wd->format_func(&wd->selected_time);
250 edje_object_part_text_set(wd->calendar, "month_text", buf);
254 edje_object_part_text_set(wd->calendar, "month_text", "");
258 first_day = wd->selected_time;
259 first_day.tm_mday = 1;
262 // Layout of the calendar is changed for removing the unfilled last row.
263 wd->first_day_it = first_day.tm_wday;
265 if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
271 for (i = 0; i < 5; i++)
273 snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
274 edje_object_signal_emit(wd->calendar, emission, "elm");
276 snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
277 edje_object_signal_emit(wd->calendar, emission, "elm");
278 for (i = 0; i < 35; i++)
280 snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
281 edje_object_signal_emit(wd->calendar, emission, "elm");
283 for (i = 35; i < 42; i++)
285 snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
286 edje_object_signal_emit(wd->calendar, emission, "elm");
293 for (i = 0; i < 6; i++)
295 snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
296 edje_object_signal_emit(wd->calendar, emission, "elm");
298 for (i = 0; i < 42; i++)
300 snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
301 edje_object_signal_emit(wd->calendar, emission, "elm");
305 for (i = 0; i < 42; i++)
307 _text_day_color_update(wd, i); // EINA_DEPRECATED
308 if ((!day) && (i == first_day.tm_wday)) day = 1;
310 if ((day == wd->current_time.tm_mday)
311 && (mon == wd->current_time.tm_mon)
312 && (year == wd->current_time.tm_year))
315 if (day == wd->selected_time.tm_mday)
317 if ((wd->selected_it > -1) && (wd->selected_it != i))
318 _unselect(wd, wd->selected_it);
320 if (wd->selection_enabled) _select(wd, i);
325 if ((day) && (day <= maxdays))
326 snprintf(day_s, sizeof(day_s), "%i", day++);
330 snprintf(part, sizeof(part), "cit_%i.text", i);
331 edje_object_part_text_set(wd->calendar, part, day_s);
332 /* Clear previous marks */
333 _cit_mark(wd->calendar, i, "clear");
337 EINA_LIST_FOREACH(wd->marks, l, mark)
339 struct tm *mtime = &mark->mark_time;
340 int month = wd->selected_time.tm_mon;
341 int year = wd->selected_time.tm_year;
342 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
344 switch (mark->repeat)
346 case ELM_CALENDAR_UNIQUE:
347 if ((mtime->tm_mon == month) && (mtime->tm_year == year))
348 _cit_mark(wd->calendar, mday_it, mark->mark_type);
350 case ELM_CALENDAR_DAILY:
351 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
352 (mtime->tm_year < year))
354 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
355 day = mtime->tm_mday;
358 for (; day <= maxdays; day++)
359 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
362 case ELM_CALENDAR_WEEKLY:
363 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
364 (mtime->tm_year < year))
366 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
367 day = mtime->tm_mday;
370 for (; day <= maxdays; day++)
371 if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
372 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
375 case ELM_CALENDAR_MONTHLY:
376 if (((mtime->tm_year < year) ||
377 ((mtime->tm_year == year) && (mtime->tm_mon <= month))) &&
378 (mtime->tm_mday <= maxdays))
379 _cit_mark(wd->calendar, mday_it, mark->mark_type);
381 case ELM_CALENDAR_ANNUALLY:
382 if ((mtime->tm_year <= year) && (mtime->tm_mon == month) &&
383 (mtime->tm_mday <= maxdays))
384 _cit_mark(wd->calendar, mday_it, mark->mark_type);
391 _set_headers(Evas_Object *obj)
393 static char part[] = "ch_0.text";
395 Widget_Data *wd = elm_widget_data_get(obj);
398 for (i = 0; i < 7; i++)
401 edje_object_part_text_set(wd->calendar, part, wd->weekdays[i]);
406 _del_hook(Evas_Object *obj)
409 Elm_Calendar_Mark *mark;
410 Widget_Data *wd = elm_widget_data_get(obj);
414 if (wd->spin) ecore_timer_del(wd->spin);
415 if (wd->update_timer) ecore_timer_del(wd->update_timer);
419 EINA_LIST_FREE(wd->marks, mark)
425 for (i = 0; i < 7; i++)
426 eina_stringshare_del(wd->weekdays[i]);
432 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
434 Widget_Data *wd = elm_widget_data_get(obj);
436 if (elm_widget_focus_get(obj))
438 edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
439 evas_object_focus_set(wd->calendar, EINA_TRUE);
443 edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
444 evas_object_focus_set(wd->calendar, EINA_FALSE);
449 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
451 Widget_Data *wd = elm_widget_data_get(obj);
453 edje_object_mirrored_set(wd->calendar, rtl);
457 _theme_hook(Evas_Object *obj)
459 Widget_Data *wd = elm_widget_data_get(obj);
461 _elm_widget_mirrored_reload(obj);
462 _elm_theme_object_set(obj, wd->calendar, "calendar", "base",
463 elm_widget_style_get(obj));
464 _mirrored_set(obj, elm_widget_mirrored_get(obj));
467 edje_object_message_signal_process(wd->calendar);
468 edje_object_scale_set(wd->calendar,
469 elm_widget_scale_get(obj) * _elm_config->scale);
474 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
476 Widget_Data *wd = elm_widget_data_get(obj);
478 edje_object_signal_emit(wd->calendar, emission, source);
482 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
484 Widget_Data *wd = elm_widget_data_get(obj);
486 edje_object_signal_callback_add(wd->calendar, emission,
487 source, func_cb, data);
491 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
493 Widget_Data *wd = elm_widget_data_get(obj);
495 edje_object_signal_callback_del_full(wd->calendar, emission, source, func_cb,
499 /* Set correct tm_wday and tm_yday after other fields changes*/
501 _fix_selected_time(Widget_Data *wd)
503 mktime(&wd->selected_time);
507 _update_month(Evas_Object *obj, int delta)
509 struct tm time_check;
511 Widget_Data *wd = elm_widget_data_get(obj);
512 if (!wd) return EINA_FALSE;
514 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
515 time_check = wd->selected_time;
516 time_check.tm_mon += delta;
517 if (mktime(&time_check) == -1)
520 wd->selected_time.tm_mon += delta;
521 if (wd->selected_time.tm_mon < 0)
523 if (wd->selected_time.tm_year == wd->year_min)
525 wd->selected_time.tm_mon++;
528 wd->selected_time.tm_mon = 11;
529 wd->selected_time.tm_year--;
531 else if (wd->selected_time.tm_mon > 11)
533 if (wd->selected_time.tm_year == wd->year_max)
535 wd->selected_time.tm_mon--;
538 wd->selected_time.tm_mon = 0;
539 wd->selected_time.tm_year++;
542 maxdays = _maxdays_get(&wd->selected_time);
543 if (wd->selected_time.tm_mday > maxdays)
544 wd->selected_time.tm_mday = maxdays;
546 _fix_selected_time(wd);
547 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
553 _spin_value(void *data)
555 Widget_Data *wd = elm_widget_data_get(data);
556 if (!wd) return ECORE_CALLBACK_CANCEL;
557 if (_update_month(data, wd->spin_speed)) _populate(data);
558 wd->interval = wd->interval / 1.05;
559 ecore_timer_interval_set(wd->spin, wd->interval);
560 return ECORE_CALLBACK_RENEW;
564 _button_inc_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
566 Widget_Data *wd = elm_widget_data_get(data);
568 wd->interval = wd->first_interval;
570 if (wd->spin) ecore_timer_del(wd->spin);
571 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
576 _button_dec_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
578 Widget_Data *wd = elm_widget_data_get(data);
580 wd->interval = wd->first_interval;
582 if (wd->spin) ecore_timer_del(wd->spin);
583 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
588 _button_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
590 Widget_Data *wd = elm_widget_data_get(data);
592 wd->interval = wd->first_interval;
593 if (wd->spin) ecore_timer_del(wd->spin);
598 _get_item_day(Evas_Object *obj, int selected_it)
601 Widget_Data *wd = elm_widget_data_get(obj);
604 day = selected_it - wd->first_day_it + 1;
605 if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
612 _update_sel_it(Evas_Object *obj, int sel_it)
615 Widget_Data *wd = elm_widget_data_get(obj);
616 if ((!wd) || (!wd->selection_enabled))
619 day = _get_item_day(obj, sel_it);
623 _unselect(wd, wd->selected_it);
625 wd->selected_it = sel_it;
626 wd->selected_time.tm_mday = day;
627 _select(wd, wd->selected_it);
628 _fix_selected_time(wd);
629 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
633 _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
636 Widget_Data *wd = elm_widget_data_get(data);
637 if ((!wd) || (!wd->selection_enabled))
639 sel_it = atoi(source);
641 _update_sel_it(data, sel_it);
645 _time_to_next_day(struct tm *t)
647 return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
651 _update_cur_date(void *data)
655 Widget_Data *wd = elm_widget_data_get(data);
656 if (!wd) return ECORE_CALLBACK_RENEW;
658 if (wd->today_it > 0) _not_today(wd);
660 current_time = time(NULL);
661 localtime_r(¤t_time, &wd->current_time);
662 t = _time_to_next_day(&wd->current_time);
663 ecore_timer_interval_set(wd->update_timer, t);
665 if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
666 (wd->current_time.tm_year!= wd->selected_time.tm_year))
667 return ECORE_CALLBACK_RENEW;
669 day = wd->current_time.tm_mday + wd->first_day_it - 1;
672 return ECORE_CALLBACK_RENEW;
676 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
678 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
679 Evas_Event_Key_Down *ev = event_info;
680 Widget_Data *wd = elm_widget_data_get(obj);
682 if (!wd) return EINA_FALSE;
683 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
684 if (!wd->selection_enabled) return EINA_FALSE;
686 if ((!strcmp(ev->keyname, "Left")) ||
687 (!strcmp(ev->keyname, "KP_Left")))
689 _update_sel_it(obj, wd->selected_it-1);
691 else if ((!strcmp(ev->keyname, "Right")) ||
692 (!strcmp(ev->keyname, "KP_Right")))
694 _update_sel_it(obj, wd->selected_it+1);
696 else if ((!strcmp(ev->keyname, "Up")) ||
697 (!strcmp(ev->keyname, "KP_Up")))
699 _update_sel_it(obj, wd->selected_it-7);
701 else if ((!strcmp(ev->keyname, "Down")) ||
702 (!strcmp(ev->keyname, "KP_Down")))
704 _update_sel_it(obj, wd->selected_it+7);
706 else if ((!strcmp(ev->keyname, "Prior")) ||
707 (!strcmp(ev->keyname, "KP_Prior")))
709 if (_update_month(obj, -1)) _populate(obj);
711 else if ((!strcmp(ev->keyname, "Next")) ||
712 (!strcmp(ev->keyname, "KP_Next")))
714 if (_update_month(obj, 1)) _populate(obj);
716 else return EINA_FALSE;
722 * Add a new calendar to the parent
724 * @param parent The parent object
725 * @return The new object or NULL if it cannot be created
730 elm_calendar_add(Evas_Object *parent)
733 time_t weekday = 259200; /* Just the first sunday since epoch */
739 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
741 ELM_SET_WIDTYPE(widtype, "calendar");
742 elm_widget_type_set(obj, "calendar");
743 elm_widget_sub_object_add(parent, obj);
744 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
745 elm_widget_data_set(obj, wd);
746 elm_widget_del_hook_set(obj, _del_hook);
747 elm_widget_theme_hook_set(obj, _theme_hook);
748 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
749 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
750 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
751 elm_widget_can_focus_set(obj, EINA_TRUE);
752 elm_widget_event_hook_set(obj, _event_hook);
754 wd->first_interval = 0.85;
758 wd->selected_it = -1;
759 wd->first_day_it = -1;
760 wd->selection_enabled = EINA_TRUE;
761 wd->format_func = _format_month_year;
764 wd->calendar = edje_object_add(e);
765 _elm_theme_object_set(obj, wd->calendar, "calendar", "base", "default");
766 elm_widget_resize_object_set(obj, wd->calendar);
768 edje_object_signal_callback_add(wd->calendar, "elm,action,increment,start",
769 "*", _button_inc_start, obj);
770 edje_object_signal_callback_add(wd->calendar, "elm,action,decrement,start",
771 "*", _button_dec_start, obj);
772 edje_object_signal_callback_add(wd->calendar, "elm,action,stop",
773 "*", _button_stop, obj);
774 edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
775 "*", _day_selected, obj);
777 evas_object_smart_callbacks_descriptions_set(obj, _signals);
779 for (i = 0; i < 7; i++)
781 /* FIXME: I'm not aware of a known max, so if it fails,
782 * just make it larger. :| */
784 /* I don't know of a better way of doing it */
785 if (strftime(buf, sizeof(buf), "%a", gmtime(&weekday)))
787 wd->weekdays[i] = eina_stringshare_add(buf);
791 /* If we failed getting day, get a default value */
792 wd->weekdays[i] = _days_abbrev[i];
793 WRN("Failed getting weekday name for '%s' from locale.",
796 weekday += 86400; /* Advance by a day */
799 current_time = time(NULL);
800 localtime_r(¤t_time, &wd->selected_time);
801 wd->current_time = wd->selected_time;
802 t = _time_to_next_day(&wd->current_time);
803 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
807 _mirrored_set(obj, elm_widget_mirrored_get(obj));
813 * Set weekdays names to display in the calendar.
815 * By default, the following abbreviations are displayed:
816 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
817 * The first string should be related to Sunday, the second to Monday...
819 * The usage should be like this:
821 * const char *weekdays[] =
823 * "Sunday", "Monday", "Tuesday", "Wednesday",
824 * "Thursday", "Friday", "Saturday"
826 * elm_calendar_weekdays_names_set(calendar, weekdays);
829 * @param obj The calendar object
830 * @param weedays Array of seven strings to be used as weekday names.
831 * Warning: it must have 7 elements, or it will access invalid memory.
832 * The strings must be NULL terminated ('@\0').
837 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
840 ELM_CHECK_WIDTYPE(obj, widtype);
841 Widget_Data *wd = elm_widget_data_get(obj);
844 EINA_SAFETY_ON_NULL_RETURN(weekdays);
846 for (i = 0; i < 7; i++)
848 eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
854 * Get weekdays names displayed in the calendar.
856 * By default, the following abbreviations are displayed:
857 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
858 * The first string is related to Sunday, the second to Monday...
860 * @param obj The calendar object
861 * @return Array of seven strings to used as weekday names.
866 elm_calendar_weekdays_names_get(const Evas_Object *obj)
868 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
869 Widget_Data *wd = elm_widget_data_get(obj);
870 if (!wd) return NULL;
875 * Set the interval for the calendar
877 * The interval value is decreased while the user increments or decrements
878 * the calendar value. The next interval value is the previous interval / 1.05,
879 * so it speed up a bit. Default value is 0.85 seconds.
881 * @param obj The calendar object
882 * @param interval The interval value in seconds
887 elm_calendar_interval_set(Evas_Object *obj, double interval)
889 ELM_CHECK_WIDTYPE(obj, widtype);
890 Widget_Data *wd = elm_widget_data_get(obj);
892 wd->first_interval = interval;
896 * Get the interval of the calendar
898 * The interval value is decreased while the user increments or decrements
899 * the calendar value. The next interval value is the previous interval / 1.05,
900 * so it speed up a bit. Default value is 0.85 seconds.
902 * @param obj The calendar object
903 * @return The value of the first interval in seconds
908 elm_calendar_interval_get(const Evas_Object *obj)
910 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
911 Widget_Data *wd = elm_widget_data_get(obj);
913 return wd->first_interval;
917 * Set the minimum and maximum values for the year
919 * Maximum must be greater than minimum, except if you don't wan't to set
921 * Default values are 1902 and -1.
923 * If the maximum year is a negative value, it will be limited depending of the
924 * platform architecture (2037 for 32 bits);
926 * @param obj The calendar object
927 * @param min The minimum year, greater than 1901;
928 * @param max The maximum year;
933 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
935 ELM_CHECK_WIDTYPE(obj, widtype);
936 Widget_Data *wd = elm_widget_data_get(obj);
940 if ((wd->year_min == min) && (wd->year_max == max)) return;
941 wd->year_min = min > 2 ? min : 2;
943 if ((max >= wd->year_min) && (wd->selected_time.tm_year > wd->year_max))
944 wd->selected_time.tm_year = wd->year_max;
945 if (wd->selected_time.tm_year < wd->year_min)
946 wd->selected_time.tm_year = wd->year_min;
947 _fix_selected_time(wd);
952 * Get the minimum and maximum values for the year
954 * Default values are 1902 and -1.
956 * If the maximum year is a negative value, it will be limited depending of the
957 * platform architecture (2037 for 32 bits);
959 * @param obj The calendar object
960 * @param min The minimum year
961 * @param max The maximum year
966 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
968 ELM_CHECK_WIDTYPE(obj, widtype);
969 Widget_Data *wd = elm_widget_data_get(obj);
971 if (min) *min = wd->year_min + 1900;
972 if (max) *max = wd->year_max + 1900;
976 * Enable or disable day selection
978 * Enabled by default. If disabled, the user can select months, but not days.
979 * It should be used if you won't need such selection for the widget usage.
981 * @param obj The calendar object
982 * @param enabled Boolean to enable (true) or disable (false) day selection
987 elm_calendar_day_selection_enabled_set(Evas_Object *obj, Eina_Bool enabled)
989 ELM_CHECK_WIDTYPE(obj, widtype);
990 Widget_Data *wd = elm_widget_data_get(obj);
992 wd->selection_enabled = enabled;
994 _select(wd, wd->selected_it);
996 _unselect(wd, wd->selected_it);
1000 * Get day selection state
1002 * Enabled by default. If disabled, the user can select months, but not days.
1003 * It should be used if you won't need such selection for the widget usage.
1005 * @param obj The calendar object
1006 * @return True if day selection is enabled, or false otherwise. It will
1007 * return false if it can't get widget data.
1012 elm_calendar_day_selection_enabled_get(const Evas_Object *obj)
1014 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1015 Widget_Data *wd = elm_widget_data_get(obj);
1016 if (!wd) return EINA_FALSE;
1017 return wd->selection_enabled;
1023 * Set the time selected, changing the displayed month if needed.
1024 * Selected time changes when the user changes the month or select a day.
1026 * @param obj The calendar object
1027 * @param selected_time A tm struct to represent the selected date
1032 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
1034 ELM_CHECK_WIDTYPE(obj, widtype);
1035 Widget_Data *wd = elm_widget_data_get(obj);
1038 EINA_SAFETY_ON_NULL_RETURN(selected_time);
1039 wd->selected_time = *selected_time;
1047 * Get the time selected by the user.
1048 * Selected time changes when the user changes the month or select a day.
1050 * @param obj The calendar object
1051 * @param selected_time A tm struct to represent the selected date
1052 * @return It will return false if it can't get widget data, or true otherwise
1057 elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
1059 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1060 Widget_Data *wd = elm_widget_data_get(obj);
1061 if (!wd) return EINA_FALSE;
1062 EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
1063 *selected_time = wd->selected_time;
1068 * Set a function to format the string that will be used to display
1071 * By default it uses strftime with "%B %Y" format string.
1072 * It should allocate the memory that will be used by the string,
1073 * that will be freed by the widget after usage.
1074 * A pointer to the string and a pointer to the time struct will be provided.
1079 * _format_month_year(struct tm *selected_time)
1082 * if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
1083 * return strdup(buf);
1085 * elm_calendar_format_function_set(calendar, _format_month_year);
1088 * @param obj The calendar object
1089 * @param format_function Function to set the month-year string given
1095 elm_calendar_format_function_set(Evas_Object *obj, char * (*format_function) (struct tm *selected_time))
1097 ELM_CHECK_WIDTYPE(obj, widtype);
1098 Widget_Data *wd = elm_widget_data_get(obj);
1100 wd->format_func = format_function;
1104 * Add a new mark to the calendar
1106 * Add a mark that will be drawn in the calendar respecting the insertion time
1107 * and periodicity. It will emit the type as signal to the widget theme.
1108 * By default, it supports "holiday" and "checked", but it can be extended.
1110 * It won't immediately update the calendar, drawing the marks. For this, call
1111 * elm_calendar_marks_draw().
1115 * struct tm selected_time;
1116 * time_t current_time;
1118 * current_time = time(NULL) + 5 * 84600;
1119 * localtime_r(¤t_time, &selected_time);
1120 * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
1122 * current_time = time(NULL) + 1 * 84600;
1123 * localtime_r(¤t_time, &selected_time);
1124 * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
1126 * elm_calendar_marks_draw(cal);
1129 * @param obj The calendar object
1130 * @param mark_type A string used to define the type of mark. It will be
1131 * emitted to the theme, that should display a related modification on these
1132 * days representation.
1133 * @param mark_time A time struct to represent the date of inclusion of the
1134 * mark. For marks that repeats it will just be displayed after the inclusion
1135 * date in the calendar.
1136 * @param repeat Repeat the event following this periodicity. Can be a unique
1137 * mark (that don't repeat), daily, weekly, monthly or annually.
1139 * @return The created mark or NULL upon failure
1143 EAPI Elm_Calendar_Mark *
1144 elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
1146 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1147 Widget_Data *wd = elm_widget_data_get(obj);
1148 Elm_Calendar_Mark *mark;
1149 if (!wd) return NULL;
1151 mark = _mark_new(obj, mark_type, mark_time, repeat);
1152 wd->marks = eina_list_append(wd->marks, mark);
1153 mark->node = eina_list_last(wd->marks);
1158 * Delete mark from the calendar.
1160 * @param mark The mark to delete
1165 elm_calendar_mark_del(Elm_Calendar_Mark *mark)
1170 EINA_SAFETY_ON_NULL_RETURN(mark);
1173 wd = elm_widget_data_get(obj);
1176 wd->marks = eina_list_remove_list(wd->marks, mark->node);
1181 * Remove all the marks from the calendar
1183 * @param obj The calendar object
1188 elm_calendar_marks_clear(Evas_Object *obj)
1190 ELM_CHECK_WIDTYPE(obj, widtype);
1191 Widget_Data *wd = elm_widget_data_get(obj);
1192 Elm_Calendar_Mark *mark;
1195 EINA_LIST_FREE(wd->marks, mark)
1200 * Returns a list of all the calendar marks.
1202 * @param obj The calendar object
1203 * @return An Eina_List* of the calendar marks, or NULL on failure
1207 EAPI const Eina_List *
1208 elm_calendar_marks_get(const Evas_Object *obj)
1210 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1211 Widget_Data *wd = elm_widget_data_get(obj);
1212 if (!wd) return NULL;
1217 * Draw calendar marks.
1219 * Should be used after adding, removing or clearing marks.
1220 * It will go through the entire marks list updating the calendar
1221 * (not a cheap function). So if lots of marks will be added,
1222 * add all the marks and then call this function.
1224 * When the month is changed marks will be drawed.
1226 * @param obj The calendar object
1231 elm_calendar_marks_draw(Evas_Object *obj)
1233 ELM_CHECK_WIDTYPE(obj, widtype);
1234 Widget_Data *wd = elm_widget_data_get(obj);
1240 * Set a text color to the saturday color.
1242 * Deprecated. use elm_calendar_mark_add() instead like:
1245 * struct tm t = { 0, 0, 12, 6, 0, 0, 5, 5, -1 };
1246 * elm_calendar_mark_add(obj, "sat", &t, ELM_CALENDAR_WEEKLY);
1249 * @param obj The calendar object
1250 * @param pos The text position
1254 EINA_DEPRECATED EAPI void
1255 elm_calendar_text_saturday_color_set(Evas_Object *obj, int pos)
1257 ELM_CHECK_WIDTYPE(obj, widtype);
1258 Widget_Data *wd = elm_widget_data_get(obj);
1260 _text_day_color_set(wd, DAY_SATURDAY, pos);
1264 * Set a text color to the sunday color.
1266 * Deprecated. use elm_calendar_mark_add() instead like:
1269 * struct tm t = { 0, 0, 12, 7, 0, 0, 6, 6, -1 };
1270 * elm_calendar_mark_add(obj, "sun", &t, ELM_CALENDAR_WEEKLY);
1273 * @param obj The calendar object
1274 * @param pos The text position
1278 EINA_DEPRECATED EAPI void
1279 elm_calendar_text_sunday_color_set(Evas_Object *obj, int pos)
1281 ELM_CHECK_WIDTYPE(obj, widtype);
1282 Widget_Data *wd = elm_widget_data_get(obj);
1284 _text_day_color_set(wd, DAY_SUNDAY, pos);
1288 * Set a text color to the weekday color.
1290 * Deprecated. use elm_calendar_mark_add() instead like:
1293 * struct tm t = { 0, 0, 12, 1, 0, 0, 0, 0, -1 };
1295 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // monday
1296 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1297 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // tuesday
1298 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1299 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // wednesday
1300 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1301 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // thursday
1302 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1303 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // friday
1306 * @param obj The calendar object
1307 * @param pos The text position
1311 EINA_DEPRECATED EAPI void
1312 elm_calendar_text_weekday_color_set(Evas_Object *obj, int pos)
1314 ELM_CHECK_WIDTYPE(obj, widtype);
1315 Widget_Data *wd = elm_widget_data_get(obj);
1317 _text_day_color_set(wd, DAY_WEEKDAY, pos);