2 # include "elementary_config.h"
9 #include <Elementary.h>
16 * A calendar is a widget that allows the user to select a date. It has
17 * support to adding check marks (holidays and checks by default). The calendar
18 * is displayed one month at a time.
20 * Weekday names and the function used to format month and year to
21 * be displayed can be set, giving more flexibility to this widget.
23 * Signals that you can add callbacks for are:
25 * "changed" - emitted when the user selects a day or changes the displayed
26 * month, what actually changes the selected day as well.
29 typedef enum _Day_Color // EINA_DEPRECATED
36 typedef struct _Widget_Data Widget_Data;
40 Evas_Object *calendar;
42 double interval, first_interval;
43 int year_min, year_max, spin_speed;
44 int today_it, selected_it, first_day_it;
45 Ecore_Timer *spin, *update_timer;
46 char * (*format_func) (struct tm *selected_time);
47 const char *weekdays[7];
48 struct tm current_time, selected_time;
49 Day_Color day_color[42]; // EINA_DEPRECATED
50 Eina_Bool selection_enabled : 1;
53 struct _Elm_Calendar_Mark
58 const char *mark_type;
59 Elm_Calendar_Mark_Repeat repeat;
62 static const char *widtype = NULL;
63 static void _on_focus_hook(void *data, Evas_Object *obj);
64 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
66 static const char SIG_CHANGED[] = "changed";
68 static const Evas_Smart_Cb_Description _signals[] = {
74 /* Should not be translated, it's used if we failed
75 * getting from locale. */
76 static const char *_days_abbrev[] =
78 "Sun", "Mon", "Tue", "Wed",
82 static int _days_in_month[2][12] =
84 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
85 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
88 static Elm_Calendar_Mark *
89 _mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
91 Widget_Data *wd = elm_widget_data_get(obj);
92 Elm_Calendar_Mark *mark;
95 mark = calloc(1, sizeof(Elm_Calendar_Mark));
96 if (!mark) return NULL;
98 mark->mark_type = eina_stringshare_add(mark_type);
99 mark->mark_time = *mark_time;
100 mark->repeat = repeat;
105 _mark_free(Elm_Calendar_Mark *mark)
107 eina_stringshare_del(mark->mark_type);
112 _sizing_eval(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
115 Evas_Coord minw = -1, minh = -1;
117 elm_coords_finger_size_adjust(8, &minw, 7, &minh);
118 edje_object_size_min_restricted_calc(wd->calendar, &minw, &minh, minw, minh);
119 evas_object_size_hint_min_set(obj, minw, minh);
120 evas_object_size_hint_max_set(obj, -1, -1);
124 _maxdays_get(struct tm *selected_time)
128 month = selected_time->tm_mon;
129 year = selected_time->tm_year + 1900;
131 return _days_in_month[((!(year % 4)) &&
138 _unselect(Widget_Data *wd, int selected)
141 snprintf(emission, sizeof(emission), "cit_%i,unselected", selected);
142 edje_object_signal_emit(wd->calendar, emission, "elm");
146 _select(Widget_Data *wd, int selected)
149 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
150 edje_object_signal_emit(wd->calendar, emission, "elm");
154 _not_today(Widget_Data *wd)
157 snprintf(emission, sizeof(emission), "cit_%i,not_today", wd->today_it);
158 edje_object_signal_emit(wd->calendar, emission, "elm");
163 _today(Widget_Data *wd, int it)
166 snprintf(emission, sizeof(emission), "cit_%i,today", it);
167 edje_object_signal_emit(wd->calendar, emission, "elm");
172 _format_month_year(struct tm *selected_time)
175 if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
180 _cit_mark(Evas_Object *cal, int cit, const char *mtype)
183 snprintf(sign, sizeof(sign), "cit_%i,%s", cit, mtype);
184 edje_object_signal_emit(cal, sign, "elm");
188 _weekday_get(int first_week_day, int day)
190 return (day + first_week_day - 1) % 7;
195 _text_day_color_update(Widget_Data *wd, int pos)
199 switch (wd->day_color[pos])
202 snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
205 snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
208 snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
214 edje_object_signal_emit(wd->calendar, emission, "elm");
219 _text_day_color_set(Widget_Data *wd, Day_Color col, int pos)
221 if ((pos < 0) || (pos >= 42)) return;
222 if (wd->day_color[pos] == col) return;
223 wd->day_color[pos] = col;
224 _text_day_color_update(wd, pos);
228 _populate(Evas_Object *obj)
230 int maxdays, day, mon, year, i;
231 Elm_Calendar_Mark *mark;
232 char part[12], day_s[3];
236 Eina_Bool last_row = EINA_TRUE;
237 Widget_Data *wd = elm_widget_data_get(obj);
241 if (wd->today_it > 0) _not_today(wd);
243 maxdays = _maxdays_get(&wd->selected_time);
244 mon = wd->selected_time.tm_mon;
245 year = wd->selected_time.tm_year;
247 /* Set selected month */
248 buf = wd->format_func(&wd->selected_time);
251 edje_object_part_text_set(wd->calendar, "month_text", buf);
255 edje_object_part_text_set(wd->calendar, "month_text", "");
259 first_day = wd->selected_time;
260 first_day.tm_mday = 1;
263 // Layout of the calendar is changed for removing the unfilled last row.
264 wd->first_day_it = first_day.tm_wday;
266 if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
272 for (i = 0; i < 5; i++)
274 snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
275 edje_object_signal_emit(wd->calendar, emission, "elm");
277 snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
278 edje_object_signal_emit(wd->calendar, emission, "elm");
279 for (i = 0; i < 35; i++)
281 snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
282 edje_object_signal_emit(wd->calendar, emission, "elm");
284 for (i = 35; i < 42; i++)
286 snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
287 edje_object_signal_emit(wd->calendar, emission, "elm");
294 for (i = 0; i < 6; i++)
296 snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
297 edje_object_signal_emit(wd->calendar, emission, "elm");
299 for (i = 0; i < 42; i++)
301 snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
302 edje_object_signal_emit(wd->calendar, emission, "elm");
306 for (i = 0; i < 42; i++)
308 _text_day_color_update(wd, i); // EINA_DEPRECATED
309 if ((!day) && (i == first_day.tm_wday)) day = 1;
311 if ((day == wd->current_time.tm_mday)
312 && (mon == wd->current_time.tm_mon)
313 && (year == wd->current_time.tm_year))
316 if (day == wd->selected_time.tm_mday)
318 if ((wd->selected_it > -1) && (wd->selected_it != i))
319 _unselect(wd, wd->selected_it);
321 if (wd->selection_enabled) _select(wd, i);
326 if ((day) && (day <= maxdays))
327 snprintf(day_s, sizeof(day_s), "%i", day++);
331 snprintf(part, sizeof(part), "cit_%i.text", i);
332 edje_object_part_text_set(wd->calendar, part, day_s);
333 /* Clear previous marks */
334 _cit_mark(wd->calendar, i, "clear");
338 EINA_LIST_FOREACH(wd->marks, l, mark)
340 struct tm *mtime = &mark->mark_time;
341 int month = wd->selected_time.tm_mon;
342 int year = wd->selected_time.tm_year;
343 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
345 switch (mark->repeat)
347 case ELM_CALENDAR_UNIQUE:
348 if ((mtime->tm_mon == month) && (mtime->tm_year == year))
349 _cit_mark(wd->calendar, mday_it, mark->mark_type);
351 case ELM_CALENDAR_DAILY:
352 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
353 (mtime->tm_year < year))
355 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
356 day = mtime->tm_mday;
359 for (; day <= maxdays; day++)
360 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
363 case ELM_CALENDAR_WEEKLY:
364 if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
365 (mtime->tm_year < year))
367 else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
368 day = mtime->tm_mday;
371 for (; day <= maxdays; day++)
372 if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
373 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
376 case ELM_CALENDAR_MONTHLY:
377 if (((mtime->tm_year < year) ||
378 ((mtime->tm_year == year) && (mtime->tm_mon <= month))) &&
379 (mtime->tm_mday <= maxdays))
380 _cit_mark(wd->calendar, mday_it, mark->mark_type);
382 case ELM_CALENDAR_ANNUALLY:
383 if ((mtime->tm_year <= year) && (mtime->tm_mon == month) &&
384 (mtime->tm_mday <= maxdays))
385 _cit_mark(wd->calendar, mday_it, mark->mark_type);
392 _set_headers(Evas_Object *obj)
394 static char part[] = "ch_0.text";
396 Widget_Data *wd = elm_widget_data_get(obj);
399 for (i = 0; i < 7; i++)
402 edje_object_part_text_set(wd->calendar, part, wd->weekdays[i]);
407 _del_hook(Evas_Object *obj)
410 Elm_Calendar_Mark *mark;
411 Widget_Data *wd = elm_widget_data_get(obj);
415 if (wd->spin) ecore_timer_del(wd->spin);
416 if (wd->update_timer) ecore_timer_del(wd->update_timer);
420 EINA_LIST_FREE(wd->marks, mark)
426 for (i = 0; i < 7; i++)
427 eina_stringshare_del(wd->weekdays[i]);
433 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
435 Widget_Data *wd = elm_widget_data_get(obj);
437 if (elm_widget_focus_get(obj))
439 edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
440 evas_object_focus_set(wd->calendar, EINA_TRUE);
444 edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
445 evas_object_focus_set(wd->calendar, EINA_FALSE);
450 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
452 Widget_Data *wd = elm_widget_data_get(obj);
454 edje_object_mirrored_set(wd->calendar, rtl);
458 _theme_hook(Evas_Object *obj)
460 Widget_Data *wd = elm_widget_data_get(obj);
462 _elm_widget_mirrored_reload(obj);
463 _elm_theme_object_set(obj, wd->calendar, "calendar", "base",
464 elm_widget_style_get(obj));
465 _mirrored_set(obj, elm_widget_mirrored_get(obj));
468 edje_object_message_signal_process(wd->calendar);
469 edje_object_scale_set(wd->calendar,
470 elm_widget_scale_get(obj) * _elm_config->scale);
475 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
477 Widget_Data *wd = elm_widget_data_get(obj);
479 edje_object_signal_emit(wd->calendar, emission, source);
483 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
485 Widget_Data *wd = elm_widget_data_get(obj);
487 edje_object_signal_callback_add(wd->calendar, emission,
488 source, func_cb, data);
492 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
494 Widget_Data *wd = elm_widget_data_get(obj);
496 edje_object_signal_callback_del_full(wd->calendar, emission, source, func_cb,
500 /* Set correct tm_wday and tm_yday after other fields changes*/
502 _fix_selected_time(Widget_Data *wd)
504 mktime(&wd->selected_time);
508 _update_month(Evas_Object *obj, int delta)
510 struct tm time_check;
512 Widget_Data *wd = elm_widget_data_get(obj);
513 if (!wd) return EINA_FALSE;
515 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
516 time_check = wd->selected_time;
517 time_check.tm_mon += delta;
518 if (mktime(&time_check) == -1)
521 wd->selected_time.tm_mon += delta;
522 if (wd->selected_time.tm_mon < 0)
524 if (wd->selected_time.tm_year == wd->year_min)
526 wd->selected_time.tm_mon++;
529 wd->selected_time.tm_mon = 11;
530 wd->selected_time.tm_year--;
532 else if (wd->selected_time.tm_mon > 11)
534 if (wd->selected_time.tm_year == wd->year_max)
536 wd->selected_time.tm_mon--;
539 wd->selected_time.tm_mon = 0;
540 wd->selected_time.tm_year++;
543 maxdays = _maxdays_get(&wd->selected_time);
544 if (wd->selected_time.tm_mday > maxdays)
545 wd->selected_time.tm_mday = maxdays;
547 _fix_selected_time(wd);
548 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
554 _spin_value(void *data)
556 Widget_Data *wd = elm_widget_data_get(data);
557 if (!wd) return ECORE_CALLBACK_CANCEL;
558 if (_update_month(data, wd->spin_speed)) _populate(data);
559 wd->interval = wd->interval / 1.05;
560 ecore_timer_interval_set(wd->spin, wd->interval);
561 return ECORE_CALLBACK_RENEW;
565 _button_inc_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
567 Widget_Data *wd = elm_widget_data_get(data);
569 wd->interval = wd->first_interval;
571 if (wd->spin) ecore_timer_del(wd->spin);
572 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
577 _button_dec_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
579 Widget_Data *wd = elm_widget_data_get(data);
581 wd->interval = wd->first_interval;
583 if (wd->spin) ecore_timer_del(wd->spin);
584 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
589 _button_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
591 Widget_Data *wd = elm_widget_data_get(data);
593 wd->interval = wd->first_interval;
594 if (wd->spin) ecore_timer_del(wd->spin);
599 _get_item_day(Evas_Object *obj, int selected_it)
602 Widget_Data *wd = elm_widget_data_get(obj);
605 day = selected_it - wd->first_day_it + 1;
606 if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
613 _update_sel_it(Evas_Object *obj, int sel_it)
616 Widget_Data *wd = elm_widget_data_get(obj);
617 if ((!wd) || (!wd->selection_enabled))
620 day = _get_item_day(obj, sel_it);
624 _unselect(wd, wd->selected_it);
626 wd->selected_it = sel_it;
627 wd->selected_time.tm_mday = day;
628 _select(wd, wd->selected_it);
629 _fix_selected_time(wd);
630 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
634 _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
637 Widget_Data *wd = elm_widget_data_get(data);
638 if ((!wd) || (!wd->selection_enabled))
640 sel_it = atoi(source);
642 _update_sel_it(data, sel_it);
646 _time_to_next_day(struct tm *t)
648 return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
652 _update_cur_date(void *data)
656 Widget_Data *wd = elm_widget_data_get(data);
657 if (!wd) return ECORE_CALLBACK_RENEW;
659 if (wd->today_it > 0) _not_today(wd);
661 current_time = time(NULL);
662 localtime_r(¤t_time, &wd->current_time);
663 t = _time_to_next_day(&wd->current_time);
664 ecore_timer_interval_set(wd->update_timer, t);
666 if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
667 (wd->current_time.tm_year!= wd->selected_time.tm_year))
668 return ECORE_CALLBACK_RENEW;
670 day = wd->current_time.tm_mday + wd->first_day_it - 1;
673 return ECORE_CALLBACK_RENEW;
677 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
679 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
680 Evas_Event_Key_Down *ev = event_info;
681 Widget_Data *wd = elm_widget_data_get(obj);
683 if (!wd) return EINA_FALSE;
684 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
685 if (!wd->selection_enabled) return EINA_FALSE;
687 if ((!strcmp(ev->keyname, "Left")) ||
688 (!strcmp(ev->keyname, "KP_Left")))
690 _update_sel_it(obj, wd->selected_it-1);
692 else if ((!strcmp(ev->keyname, "Right")) ||
693 (!strcmp(ev->keyname, "KP_Right")))
695 _update_sel_it(obj, wd->selected_it+1);
697 else if ((!strcmp(ev->keyname, "Up")) ||
698 (!strcmp(ev->keyname, "KP_Up")))
700 _update_sel_it(obj, wd->selected_it-7);
702 else if ((!strcmp(ev->keyname, "Down")) ||
703 (!strcmp(ev->keyname, "KP_Down")))
705 _update_sel_it(obj, wd->selected_it+7);
707 else if ((!strcmp(ev->keyname, "Prior")) ||
708 (!strcmp(ev->keyname, "KP_Prior")))
710 if (_update_month(obj, -1)) _populate(obj);
712 else if ((!strcmp(ev->keyname, "Next")) ||
713 (!strcmp(ev->keyname, "KP_Next")))
715 if (_update_month(obj, 1)) _populate(obj);
717 else return EINA_FALSE;
723 * Add a new calendar to the parent
725 * @param parent The parent object
726 * @return The new object or NULL if it cannot be created
731 elm_calendar_add(Evas_Object *parent)
734 time_t weekday = 259200; /* Just the first sunday since epoch */
740 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
742 ELM_SET_WIDTYPE(widtype, "calendar");
743 elm_widget_type_set(obj, "calendar");
744 elm_widget_sub_object_add(parent, obj);
745 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
746 elm_widget_data_set(obj, wd);
747 elm_widget_del_hook_set(obj, _del_hook);
748 elm_widget_theme_hook_set(obj, _theme_hook);
749 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
750 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
751 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
752 elm_widget_can_focus_set(obj, EINA_TRUE);
753 elm_widget_event_hook_set(obj, _event_hook);
755 wd->first_interval = 0.85;
759 wd->selected_it = -1;
760 wd->first_day_it = -1;
761 wd->selection_enabled = EINA_TRUE;
762 wd->format_func = _format_month_year;
765 wd->calendar = edje_object_add(e);
766 _elm_theme_object_set(obj, wd->calendar, "calendar", "base", "default");
767 elm_widget_resize_object_set(obj, wd->calendar);
769 edje_object_signal_callback_add(wd->calendar, "elm,action,increment,start",
770 "*", _button_inc_start, obj);
771 edje_object_signal_callback_add(wd->calendar, "elm,action,decrement,start",
772 "*", _button_dec_start, obj);
773 edje_object_signal_callback_add(wd->calendar, "elm,action,stop",
774 "*", _button_stop, obj);
775 edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
776 "*", _day_selected, obj);
778 evas_object_smart_callbacks_descriptions_set(obj, _signals);
780 for (i = 0; i < 7; i++)
782 /* FIXME: I'm not aware of a known max, so if it fails,
783 * just make it larger. :| */
785 /* I don't know of a better way of doing it */
786 if (strftime(buf, sizeof(buf), "%a", gmtime(&weekday)))
788 wd->weekdays[i] = eina_stringshare_add(buf);
792 /* If we failed getting day, get a default value */
793 wd->weekdays[i] = _days_abbrev[i];
794 WRN("Failed getting weekday name for '%s' from locale.",
797 weekday += 86400; /* Advance by a day */
800 current_time = time(NULL);
801 localtime_r(¤t_time, &wd->selected_time);
802 wd->current_time = wd->selected_time;
803 t = _time_to_next_day(&wd->current_time);
804 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
808 _mirrored_set(obj, elm_widget_mirrored_get(obj));
814 * Set weekdays names to display in the calendar.
816 * By default, the following abbreviations are displayed:
817 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
818 * The first string should be related to Sunday, the second to Monday...
820 * The usage should be like this:
822 * const char *weekdays[] =
824 * "Sunday", "Monday", "Tuesday", "Wednesday",
825 * "Thursday", "Friday", "Saturday"
827 * elm_calendar_weekdays_names_set(calendar, weekdays);
830 * @param obj The calendar object
831 * @param weedays Array of seven strings to be used as weekday names.
832 * Warning: it must have 7 elements, or it will access invalid memory.
833 * The strings must be NULL terminated ('@\0').
838 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
841 ELM_CHECK_WIDTYPE(obj, widtype);
842 Widget_Data *wd = elm_widget_data_get(obj);
845 EINA_SAFETY_ON_NULL_RETURN(weekdays);
847 for (i = 0; i < 7; i++)
849 eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
855 * Get weekdays names displayed in the calendar.
857 * By default, the following abbreviations are displayed:
858 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
859 * The first string is related to Sunday, the second to Monday...
861 * @param obj The calendar object
862 * @return Array of seven strings to used as weekday names.
867 elm_calendar_weekdays_names_get(const Evas_Object *obj)
869 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
870 Widget_Data *wd = elm_widget_data_get(obj);
871 if (!wd) return NULL;
876 * Set the interval for the calendar
878 * The interval value is decreased while the user increments or decrements
879 * the calendar value. The next interval value is the previous interval / 1.05,
880 * so it speed up a bit. Default value is 0.85 seconds.
882 * @param obj The calendar object
883 * @param interval The interval value in seconds
888 elm_calendar_interval_set(Evas_Object *obj, double interval)
890 ELM_CHECK_WIDTYPE(obj, widtype);
891 Widget_Data *wd = elm_widget_data_get(obj);
893 wd->first_interval = interval;
897 * Get the interval of the calendar
899 * The interval value is decreased while the user increments or decrements
900 * the calendar value. The next interval value is the previous interval / 1.05,
901 * so it speed up a bit. Default value is 0.85 seconds.
903 * @param obj The calendar object
904 * @return The value of the first interval in seconds
909 elm_calendar_interval_get(const Evas_Object *obj)
911 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
912 Widget_Data *wd = elm_widget_data_get(obj);
914 return wd->first_interval;
918 * Set the minimum and maximum values for the year
920 * Maximum must be greater than minimum, except if you don't wan't to set
922 * Default values are 1902 and -1.
924 * If the maximum year is a negative value, it will be limited depending of the
925 * platform architecture (2037 for 32 bits);
927 * @param obj The calendar object
928 * @param min The minimum year, greater than 1901;
929 * @param max The maximum year;
934 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
936 ELM_CHECK_WIDTYPE(obj, widtype);
937 Widget_Data *wd = elm_widget_data_get(obj);
941 if ((wd->year_min == min) && (wd->year_max == max)) return;
942 wd->year_min = min > 2 ? min : 2;
943 if (max > wd->year_min)
946 wd->year_max = wd->year_min;
947 if (wd->selected_time.tm_year > wd->year_max)
948 wd->selected_time.tm_year = wd->year_max;
949 if (wd->selected_time.tm_year < wd->year_min)
950 wd->selected_time.tm_year = wd->year_min;
951 _fix_selected_time(wd);
956 * Get the minimum and maximum values for the year
958 * Default values are 1902 and -1.
960 * If the maximum year is a negative value, it will be limited depending of the
961 * platform architecture (2037 for 32 bits);
963 * @param obj The calendar object
964 * @param min The minimum year
965 * @param max The maximum year
970 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
972 ELM_CHECK_WIDTYPE(obj, widtype);
973 Widget_Data *wd = elm_widget_data_get(obj);
975 if (min) *min = wd->year_min + 1900;
976 if (max) *max = wd->year_max + 1900;
980 * Enable or disable day selection
982 * Enabled by default. If disabled, the user can select months, but not days.
983 * It should be used if you won't need such selection for the widget usage.
985 * @param obj The calendar object
986 * @param enabled Boolean to enable (true) or disable (false) day selection
991 elm_calendar_day_selection_enabled_set(Evas_Object *obj, Eina_Bool enabled)
993 ELM_CHECK_WIDTYPE(obj, widtype);
994 Widget_Data *wd = elm_widget_data_get(obj);
996 wd->selection_enabled = enabled;
998 _select(wd, wd->selected_it);
1000 _unselect(wd, wd->selected_it);
1004 * Get day selection state
1006 * Enabled by default. If disabled, the user can select months, but not days.
1007 * It should be used if you won't need such selection for the widget usage.
1009 * @param obj The calendar object
1010 * @return True if day selection is enabled, or false otherwise. It will
1011 * return false if it can't get widget data.
1016 elm_calendar_day_selection_enabled_get(const Evas_Object *obj)
1018 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1019 Widget_Data *wd = elm_widget_data_get(obj);
1020 if (!wd) return EINA_FALSE;
1021 return wd->selection_enabled;
1027 * Set the time selected, changing the displayed month if needed.
1028 * Selected time changes when the user changes the month or select a day.
1030 * @param obj The calendar object
1031 * @param selected_time A tm struct to represent the selected date
1036 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
1038 ELM_CHECK_WIDTYPE(obj, widtype);
1039 Widget_Data *wd = elm_widget_data_get(obj);
1042 EINA_SAFETY_ON_NULL_RETURN(selected_time);
1043 wd->selected_time = *selected_time;
1051 * Get the time selected by the user.
1052 * Selected time changes when the user changes the month or select a day.
1054 * @param obj The calendar object
1055 * @param selected_time A tm struct to represent the selected date
1056 * @return It will return false if it can't get widget data, or true otherwise
1061 elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
1063 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1064 Widget_Data *wd = elm_widget_data_get(obj);
1065 if (!wd) return EINA_FALSE;
1066 EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
1067 *selected_time = wd->selected_time;
1072 * Set a function to format the string that will be used to display
1075 * By default it uses strftime with "%B %Y" format string.
1076 * It should allocate the memory that will be used by the string,
1077 * that will be freed by the widget after usage.
1078 * A pointer to the string and a pointer to the time struct will be provided.
1083 * _format_month_year(struct tm *selected_time)
1086 * if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
1087 * return strdup(buf);
1089 * elm_calendar_format_function_set(calendar, _format_month_year);
1092 * @param obj The calendar object
1093 * @param format_function Function to set the month-year string given
1099 elm_calendar_format_function_set(Evas_Object *obj, char * (*format_function) (struct tm *selected_time))
1101 ELM_CHECK_WIDTYPE(obj, widtype);
1102 Widget_Data *wd = elm_widget_data_get(obj);
1104 wd->format_func = format_function;
1108 * Add a new mark to the calendar
1110 * Add a mark that will be drawn in the calendar respecting the insertion time
1111 * and periodicity. It will emit the type as signal to the widget theme.
1112 * By default, it supports "holiday" and "checked", but it can be extended.
1114 * It won't immediately update the calendar, drawing the marks. For this, call
1115 * elm_calendar_marks_draw().
1119 * struct tm selected_time;
1120 * time_t current_time;
1122 * current_time = time(NULL) + 5 * 84600;
1123 * localtime_r(¤t_time, &selected_time);
1124 * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
1126 * current_time = time(NULL) + 1 * 84600;
1127 * localtime_r(¤t_time, &selected_time);
1128 * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
1130 * elm_calendar_marks_draw(cal);
1133 * @param obj The calendar object
1134 * @param mark_type A string used to define the type of mark. It will be
1135 * emitted to the theme, that should display a related modification on these
1136 * days representation.
1137 * @param mark_time A time struct to represent the date of inclusion of the
1138 * mark. For marks that repeats it will just be displayed after the inclusion
1139 * date in the calendar.
1140 * @param repeat Repeat the event following this periodicity. Can be a unique
1141 * mark (that don't repeat), daily, weekly, monthly or annually.
1143 * @return The created mark or NULL upon failure
1147 EAPI Elm_Calendar_Mark *
1148 elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
1150 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1151 Widget_Data *wd = elm_widget_data_get(obj);
1152 Elm_Calendar_Mark *mark;
1153 if (!wd) return NULL;
1155 mark = _mark_new(obj, mark_type, mark_time, repeat);
1156 wd->marks = eina_list_append(wd->marks, mark);
1157 mark->node = eina_list_last(wd->marks);
1162 * Delete mark from the calendar.
1164 * @param mark The mark to delete
1169 elm_calendar_mark_del(Elm_Calendar_Mark *mark)
1174 EINA_SAFETY_ON_NULL_RETURN(mark);
1177 wd = elm_widget_data_get(obj);
1180 wd->marks = eina_list_remove_list(wd->marks, mark->node);
1185 * Remove all the marks from the calendar
1187 * @param obj The calendar object
1192 elm_calendar_marks_clear(Evas_Object *obj)
1194 ELM_CHECK_WIDTYPE(obj, widtype);
1195 Widget_Data *wd = elm_widget_data_get(obj);
1196 Elm_Calendar_Mark *mark;
1199 EINA_LIST_FREE(wd->marks, mark)
1204 * Returns a list of all the calendar marks.
1206 * @param obj The calendar object
1207 * @return An Eina_List* of the calendar marks, or NULL on failure
1211 EAPI const Eina_List *
1212 elm_calendar_marks_get(const Evas_Object *obj)
1214 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1215 Widget_Data *wd = elm_widget_data_get(obj);
1216 if (!wd) return NULL;
1221 * Draw calendar marks.
1223 * Should be used after adding, removing or clearing marks.
1224 * It will go through the entire marks list updating the calendar
1225 * (not a cheap function). So if lots of marks will be added,
1226 * add all the marks and then call this function.
1228 * When the month is changed marks will be drawed.
1230 * @param obj The calendar object
1235 elm_calendar_marks_draw(Evas_Object *obj)
1237 ELM_CHECK_WIDTYPE(obj, widtype);
1238 Widget_Data *wd = elm_widget_data_get(obj);
1244 * Set a text color to the saturday color.
1246 * Deprecated. use elm_calendar_mark_add() instead like:
1249 * struct tm t = { 0, 0, 12, 6, 0, 0, 5, 5, -1 };
1250 * elm_calendar_mark_add(obj, "sat", &t, ELM_CALENDAR_WEEKLY);
1253 * @param obj The calendar object
1254 * @param pos The text position
1258 EINA_DEPRECATED EAPI void
1259 elm_calendar_text_saturday_color_set(Evas_Object *obj, int pos)
1261 ELM_CHECK_WIDTYPE(obj, widtype);
1262 Widget_Data *wd = elm_widget_data_get(obj);
1264 _text_day_color_set(wd, DAY_SATURDAY, pos);
1268 * Set a text color to the sunday color.
1270 * Deprecated. use elm_calendar_mark_add() instead like:
1273 * struct tm t = { 0, 0, 12, 7, 0, 0, 6, 6, -1 };
1274 * elm_calendar_mark_add(obj, "sun", &t, ELM_CALENDAR_WEEKLY);
1277 * @param obj The calendar object
1278 * @param pos The text position
1282 EINA_DEPRECATED EAPI void
1283 elm_calendar_text_sunday_color_set(Evas_Object *obj, int pos)
1285 ELM_CHECK_WIDTYPE(obj, widtype);
1286 Widget_Data *wd = elm_widget_data_get(obj);
1288 _text_day_color_set(wd, DAY_SUNDAY, pos);
1292 * Set a text color to the weekday color.
1294 * Deprecated. use elm_calendar_mark_add() instead like:
1297 * struct tm t = { 0, 0, 12, 1, 0, 0, 0, 0, -1 };
1299 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // monday
1300 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1301 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // tuesday
1302 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1303 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // wednesday
1304 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1305 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // thursday
1306 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1307 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // friday
1310 * @param obj The calendar object
1311 * @param pos The text position
1315 EINA_DEPRECATED EAPI void
1316 elm_calendar_text_weekday_color_set(Evas_Object *obj, int pos)
1318 ELM_CHECK_WIDTYPE(obj, widtype);
1319 Widget_Data *wd = elm_widget_data_get(obj);
1321 _text_day_color_set(wd, DAY_WEEKDAY, pos);