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 *stime);
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);
65 static const char *_days_abbrev[] =
67 "Sun", "Mon", "Tue", "Wed",
71 static int _days_in_month[2][12] =
73 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
74 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
77 static Elm_Calendar_Mark *
78 _mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
80 Widget_Data *wd = elm_widget_data_get(obj);
81 Elm_Calendar_Mark *mark;
84 mark = calloc(1, sizeof(Elm_Calendar_Mark));
85 if (!mark) return NULL;
87 mark->mark_type = eina_stringshare_add(mark_type);
88 mark->mark_time = *mark_time;
89 mark->repeat = repeat;
94 _mark_free(Elm_Calendar_Mark *mark)
96 eina_stringshare_del(mark->mark_type);
101 _sizing_eval(Evas_Object *obj)
103 Widget_Data *wd = elm_widget_data_get(obj);
104 Evas_Coord minw = -1, minh = -1;
106 elm_coords_finger_size_adjust(8, &minw, 7, &minh);
107 edje_object_size_min_restricted_calc(wd->calendar, &minw, &minh, minw, minh);
108 evas_object_size_hint_min_set(obj, minw, minh);
109 evas_object_size_hint_max_set(obj, -1, -1);
113 _maxdays_get(struct tm *time)
117 month = time->tm_mon;
118 year = time->tm_year + 1900;
120 return _days_in_month[((!(year % 4)) &&
127 _unselect(Widget_Data *wd, int selected)
130 snprintf(emission, sizeof(emission), "cit_%i,unselected", selected);
131 edje_object_signal_emit(wd->calendar, emission, "elm");
135 _select(Widget_Data *wd, int selected)
138 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
139 edje_object_signal_emit(wd->calendar, emission, "elm");
143 _not_today(Widget_Data *wd)
146 snprintf(emission, sizeof(emission), "cit_%i,not_today", wd->today_it);
147 edje_object_signal_emit(wd->calendar, emission, "elm");
152 _today(Widget_Data *wd, int it)
155 snprintf(emission, sizeof(emission), "cit_%i,today", it);
156 edje_object_signal_emit(wd->calendar, emission, "elm");
161 _format_month_year(struct tm *stime)
164 if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
169 _cit_mark(Evas_Object *cal, int cit, const char *mtype)
172 snprintf(sign, sizeof(sign), "cit_%i,%s", cit, mtype);
173 edje_object_signal_emit(cal, sign, "elm");
177 _weekday_get(int first_week_day, int day)
179 return (day + first_week_day - 1) % 7;
184 _text_day_color_update(Widget_Data *wd, int pos)
188 switch (wd->day_color[pos])
191 snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
194 snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
197 snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
203 edje_object_signal_emit(wd->calendar, emission, "elm");
208 _text_day_color_set(Widget_Data *wd, Day_Color col, int pos)
210 if ((pos < 0) || (pos >= 42)) return;
211 if (wd->day_color[pos] == col) return;
212 wd->day_color[pos] = col;
213 _text_day_color_update(wd, pos);
217 _populate(Evas_Object *obj)
219 int maxdays, day, mon, year, i;
220 Elm_Calendar_Mark *mark;
221 char part[12], day_s[3];
225 Eina_Bool last_row = EINA_TRUE;
226 Widget_Data *wd = elm_widget_data_get(obj);
230 if (wd->today_it > 0) _not_today(wd);
232 maxdays = _maxdays_get(&wd->selected_time);
233 mon = wd->selected_time.tm_mon;
234 year = wd->selected_time.tm_year;
236 /* Set selected month */
237 buf = wd->format_func(&wd->selected_time);
240 edje_object_part_text_set(wd->calendar, "month_text", buf);
244 edje_object_part_text_set(wd->calendar, "month_text", "");
248 first_day = wd->selected_time;
249 first_day.tm_mday = 1;
252 // Layout of the calendar is changed for removing the unfilled last row.
253 wd->first_day_it = first_day.tm_wday;
255 if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
261 for (i = 0; i < 5; i++)
263 snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
264 edje_object_signal_emit(wd->calendar, emission, "elm");
266 snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
267 edje_object_signal_emit(wd->calendar, emission, "elm");
268 for (i = 0; i < 35; i++)
270 snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
271 edje_object_signal_emit(wd->calendar, emission, "elm");
273 for (i = 35; i < 42; i++)
275 snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
276 edje_object_signal_emit(wd->calendar, emission, "elm");
283 for (i = 0; i < 6; i++)
285 snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
286 edje_object_signal_emit(wd->calendar, emission, "elm");
288 for (i = 0; i < 42; i++)
290 snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
291 edje_object_signal_emit(wd->calendar, emission, "elm");
295 for (i = 0; i < 42; i++)
297 _text_day_color_update(wd, i); // EINA_DEPRECATED
298 if ((!day) && (i == first_day.tm_wday)) day = 1;
300 if ((day == wd->current_time.tm_mday)
301 && (mon == wd->current_time.tm_mon)
302 && (year == wd->current_time.tm_year))
305 if (day == wd->selected_time.tm_mday)
307 if ((wd->selected_it > -1) && (wd->selected_it != i))
308 _unselect(wd, wd->selected_it);
310 if (wd->selection_enabled) _select(wd, i);
315 if ((day) && (day <= maxdays))
316 snprintf(day_s, sizeof(day_s), "%i", day++);
320 snprintf(part, sizeof(part), "cit_%i.text", i);
321 edje_object_part_text_set(wd->calendar, part, day_s);
322 /* Clear previous marks */
323 _cit_mark(wd->calendar, i, "clear");
327 EINA_LIST_FOREACH(wd->marks, l, mark)
329 struct tm *mtime = &mark->mark_time;
330 int mon = wd->selected_time.tm_mon;
331 int year = wd->selected_time.tm_year;
332 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
334 switch (mark->repeat)
336 case ELM_CALENDAR_UNIQUE:
337 if ((mtime->tm_mon == mon) && (mtime->tm_year == year))
338 _cit_mark(wd->calendar, mday_it, mark->mark_type);
340 case ELM_CALENDAR_DAILY:
341 if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
342 (mtime->tm_year < year))
344 else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
345 day = mtime->tm_mday;
348 for (; day <= maxdays; day++)
349 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
352 case ELM_CALENDAR_WEEKLY:
353 if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
354 (mtime->tm_year < year))
356 else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
357 day = mtime->tm_mday;
360 for (; day <= maxdays; day++)
361 if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
362 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
365 case ELM_CALENDAR_MONTHLY:
366 if (((mtime->tm_year < year) ||
367 ((mtime->tm_year == year) && (mtime->tm_mon <= mon))) &&
368 (mtime->tm_mday <= maxdays))
369 _cit_mark(wd->calendar, mday_it, mark->mark_type);
371 case ELM_CALENDAR_ANNUALLY:
372 if ((mtime->tm_year <= year) && (mtime->tm_mon == mon) &&
373 (mtime->tm_mday <= maxdays))
374 _cit_mark(wd->calendar, mday_it, mark->mark_type);
381 _set_headers(Evas_Object *obj)
383 static char part[] = "ch_0.text";
385 Widget_Data *wd = elm_widget_data_get(obj);
388 for (i = 0; i < 7; i++)
391 edje_object_part_text_set(wd->calendar, part, wd->weekdays[i]);
396 _del_hook(Evas_Object *obj)
399 Elm_Calendar_Mark *mark;
400 Widget_Data *wd = elm_widget_data_get(obj);
404 if (wd->spin) ecore_timer_del(wd->spin);
405 if (wd->update_timer) ecore_timer_del(wd->update_timer);
409 EINA_LIST_FREE(wd->marks, mark)
415 for (i = 0; i < 7; i++)
416 eina_stringshare_del(wd->weekdays[i]);
422 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
424 Widget_Data *wd = elm_widget_data_get(obj);
426 if (elm_widget_focus_get(obj))
428 edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
429 evas_object_focus_set(wd->calendar, EINA_TRUE);
433 edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
434 evas_object_focus_set(wd->calendar, EINA_FALSE);
439 _theme_hook(Evas_Object *obj)
441 Widget_Data *wd = elm_widget_data_get(obj);
443 _elm_theme_object_set(obj, wd->calendar, "calendar", "base",
444 elm_widget_style_get(obj));
447 edje_object_message_signal_process(wd->calendar);
448 edje_object_scale_set(wd->calendar,
449 elm_widget_scale_get(obj) * _elm_config->scale);
454 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
456 Widget_Data *wd = elm_widget_data_get(obj);
458 edje_object_signal_emit(wd->calendar, emission, source);
462 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
464 Widget_Data *wd = elm_widget_data_get(obj);
466 edje_object_signal_callback_add(wd->calendar, emission,
467 source, func_cb, data);
471 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
473 Widget_Data *wd = elm_widget_data_get(obj);
475 edje_object_signal_callback_del_full(wd->calendar, emission, source, func_cb,
479 /* Set correct tm_wday and tm_yday after other fields changes*/
481 _fix_selected_time(Widget_Data *wd)
483 mktime(&wd->selected_time);
487 _update_month(Evas_Object *obj, int delta)
489 struct tm time_check;
491 Widget_Data *wd = elm_widget_data_get(obj);
492 if (!wd) return EINA_FALSE;
494 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
495 time_check = wd->selected_time;
496 time_check.tm_mon += delta;
497 if (mktime(&time_check) == -1)
500 wd->selected_time.tm_mon += delta;
501 if (wd->selected_time.tm_mon < 0)
503 if (wd->selected_time.tm_year == wd->year_min)
505 wd->selected_time.tm_mon++;
508 wd->selected_time.tm_mon = 11;
509 wd->selected_time.tm_year--;
511 else if (wd->selected_time.tm_mon > 11)
513 if (wd->selected_time.tm_year == wd->year_max)
515 wd->selected_time.tm_mon--;
518 wd->selected_time.tm_mon = 0;
519 wd->selected_time.tm_year++;
522 maxdays = _maxdays_get(&wd->selected_time);
523 if (wd->selected_time.tm_mday > maxdays)
524 wd->selected_time.tm_mday = maxdays;
526 _fix_selected_time(wd);
527 evas_object_smart_callback_call(obj, "changed", NULL);
533 _spin_value(void *data)
535 Widget_Data *wd = elm_widget_data_get(data);
536 if (!wd) return ECORE_CALLBACK_CANCEL;
537 if (_update_month(data, wd->spin_speed)) _populate(data);
538 wd->interval = wd->interval / 1.05;
539 ecore_timer_interval_set(wd->spin, wd->interval);
540 return ECORE_CALLBACK_RENEW;
544 _button_inc_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
546 Widget_Data *wd = elm_widget_data_get(data);
548 wd->interval = wd->first_interval;
550 if (wd->spin) ecore_timer_del(wd->spin);
551 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
556 _button_dec_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
558 Widget_Data *wd = elm_widget_data_get(data);
560 wd->interval = wd->first_interval;
562 if (wd->spin) ecore_timer_del(wd->spin);
563 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
568 _button_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
570 Widget_Data *wd = elm_widget_data_get(data);
572 wd->interval = wd->first_interval;
573 if (wd->spin) ecore_timer_del(wd->spin);
578 _get_item_day(Evas_Object *obj, int selected_it)
581 Widget_Data *wd = elm_widget_data_get(obj);
584 day = selected_it - wd->first_day_it + 1;
585 if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
592 _update_sel_it(Evas_Object *obj, int sel_it)
595 Widget_Data *wd = elm_widget_data_get(obj);
596 if ((!wd) || (!wd->selection_enabled))
599 day = _get_item_day(obj, sel_it);
603 _unselect(wd, wd->selected_it);
605 wd->selected_it = sel_it;
606 wd->selected_time.tm_mday = day;
607 _select(wd, wd->selected_it);
608 _fix_selected_time(wd);
609 evas_object_smart_callback_call(obj, "changed", NULL);
613 _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
616 Widget_Data *wd = elm_widget_data_get(data);
617 if ((!wd) || (!wd->selection_enabled))
619 sel_it = atoi(source);
621 _update_sel_it(data, sel_it);
625 _time_to_next_day(struct tm *t)
627 return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
631 _update_cur_date(void *data)
635 Widget_Data *wd = elm_widget_data_get(data);
636 if (!wd) return ECORE_CALLBACK_RENEW;
638 if (wd->today_it > 0) _not_today(wd);
640 current_time = time(NULL);
641 localtime_r(¤t_time, &wd->current_time);
642 t = _time_to_next_day(&wd->current_time);
643 ecore_timer_interval_set(wd->update_timer, t);
645 if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
646 (wd->current_time.tm_year!= wd->selected_time.tm_year))
647 return ECORE_CALLBACK_RENEW;
649 day = wd->current_time.tm_mday + wd->first_day_it - 1;
652 return ECORE_CALLBACK_RENEW;
656 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
658 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
659 Evas_Event_Key_Down *ev = event_info;
660 Widget_Data *wd = elm_widget_data_get(obj);
662 if (!wd) return EINA_FALSE;
663 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
664 if (!wd->selection_enabled) return EINA_FALSE;
666 if ((!strcmp(ev->keyname, "Left")) ||
667 (!strcmp(ev->keyname, "KP_Left")))
669 _update_sel_it(obj, wd->selected_it-1);
671 else if ((!strcmp(ev->keyname, "Right")) ||
672 (!strcmp(ev->keyname, "KP_Right")))
674 _update_sel_it(obj, wd->selected_it+1);
676 else if ((!strcmp(ev->keyname, "Up")) ||
677 (!strcmp(ev->keyname, "KP_Up")))
679 _update_sel_it(obj, wd->selected_it-7);
681 else if ((!strcmp(ev->keyname, "Down")) ||
682 (!strcmp(ev->keyname, "KP_Down")))
684 _update_sel_it(obj, wd->selected_it+7);
686 else if ((!strcmp(ev->keyname, "Prior")) ||
687 (!strcmp(ev->keyname, "KP_Prior")))
689 if (_update_month(obj, -1)) _populate(obj);
691 else if ((!strcmp(ev->keyname, "Next")) ||
692 (!strcmp(ev->keyname, "KP_Next")))
694 if (_update_month(obj, 1)) _populate(obj);
696 else return EINA_FALSE;
702 * Add a new calendar to the parent
704 * @param parent The parent object
705 * @return The new object or NULL if it cannot be created
710 elm_calendar_add(Evas_Object *parent)
718 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
720 wd = ELM_NEW(Widget_Data);
721 e = evas_object_evas_get(parent);
723 obj = elm_widget_add(e);
724 ELM_SET_WIDTYPE(widtype, "calendar");
725 elm_widget_type_set(obj, "calendar");
726 elm_widget_sub_object_add(parent, obj);
727 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
728 elm_widget_data_set(obj, wd);
729 elm_widget_del_hook_set(obj, _del_hook);
730 elm_widget_theme_hook_set(obj, _theme_hook);
731 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
732 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
733 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
734 elm_widget_can_focus_set(obj, EINA_TRUE);
735 elm_widget_event_hook_set(obj, _event_hook);
737 wd->first_interval = 0.85;
741 wd->selected_it = -1;
742 wd->first_day_it = -1;
743 wd->selection_enabled = EINA_TRUE;
744 wd->format_func = _format_month_year;
747 wd->calendar = edje_object_add(e);
748 _elm_theme_object_set(obj, wd->calendar, "calendar", "base", "default");
749 elm_widget_resize_object_set(obj, wd->calendar);
751 edje_object_signal_callback_add(wd->calendar, "elm,action,increment,start",
752 "*", _button_inc_start, obj);
753 edje_object_signal_callback_add(wd->calendar, "elm,action,decrement,start",
754 "*", _button_dec_start, obj);
755 edje_object_signal_callback_add(wd->calendar, "elm,action,stop",
756 "*", _button_stop, obj);
757 edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
758 "*", _day_selected, obj);
760 for (i = 0; i < 7; i++)
761 wd->weekdays[i] = eina_stringshare_add(_days_abbrev[i]);
763 current_time = time(NULL);
764 localtime_r(¤t_time, &wd->selected_time);
765 wd->current_time = wd->selected_time;
766 t = _time_to_next_day(&wd->current_time);
767 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
776 * Set weekdays names to display in the calendar.
778 * By default, the following abbreviations are displayed:
779 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
780 * The first string should be related to Sunday, the second to Monday...
782 * The usage should be like this:
784 * const char *weekdays[] =
786 * "Sunday", "Monday", "Tuesday", "Wednesday",
787 * "Thursday", "Friday", "Saturday"
789 * elm_calendar_weekdays_names_set(calendar, weekdays);
792 * @param obj The calendar object
793 * @param weedays Array of seven strings to be used as weekday names.
794 * Warning: it must have 7 elements, or it will access invalid memory.
795 * The strings must be NULL terminated ('@\0').
800 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
803 ELM_CHECK_WIDTYPE(obj, widtype);
804 Widget_Data *wd = elm_widget_data_get(obj);
807 EINA_SAFETY_ON_NULL_RETURN(weekdays);
809 for (i = 0; i < 7; i++)
811 eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
817 * Get weekdays names displayed in the calendar.
819 * By default, the following abbreviations are displayed:
820 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
821 * The first string is related to Sunday, the second to Monday...
823 * @param obj The calendar object
824 * @return Array of seven strings to used as weekday names.
829 elm_calendar_weekdays_names_get(const Evas_Object *obj)
831 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
832 Widget_Data *wd = elm_widget_data_get(obj);
833 if (!wd) return NULL;
838 * Set the interval for the calendar
840 * The interval value is decreased while the user increments or decrements
841 * the calendar value. The next interval value is the previous interval / 1.05,
842 * so it speed up a bit. Default value is 0.85 seconds.
844 * @param obj The calendar object
845 * @param interval The interval value in seconds
850 elm_calendar_interval_set(Evas_Object *obj, double interval)
852 ELM_CHECK_WIDTYPE(obj, widtype);
853 Widget_Data *wd = elm_widget_data_get(obj);
855 wd->first_interval = interval;
859 * Get the interval of the calendar
861 * The interval value is decreased while the user increments or decrements
862 * the calendar value. The next interval value is the previous interval / 1.05,
863 * so it speed up a bit. Default value is 0.85 seconds.
865 * @param obj The calendar object
866 * @return The value of the first interval in seconds
871 elm_calendar_interval_get(const Evas_Object *obj)
873 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
874 Widget_Data *wd = elm_widget_data_get(obj);
876 return wd->first_interval;
880 * Set the minimum and maximum values for the year
882 * Maximum must be greater than minimum, except if you don't wan't to set
884 * Default values are 1902 and -1.
886 * If the maximum year is a negative value, it will be limited depending of the
887 * platform architecture (2037 for 32 bits);
889 * @param obj The calendar object
890 * @param min The minimum year, greater than 1901;
891 * @param max The maximum year;
896 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
898 ELM_CHECK_WIDTYPE(obj, widtype);
899 Widget_Data *wd = elm_widget_data_get(obj);
903 if ((wd->year_min == min) && (wd->year_max == max)) return;
904 wd->year_min = min > 2 ? min : 2;
905 if (wd->selected_time.tm_year > wd->year_max)
906 wd->selected_time.tm_year = wd->year_max;
907 if (wd->selected_time.tm_year < wd->year_min)
908 wd->selected_time.tm_year = wd->year_min;
909 _fix_selected_time(wd);
914 * Get the minimum and maximum values for the year
916 * Default values are 1902 and -1.
918 * If the maximum year is a negative value, it will be limited depending of the
919 * platform architecture (2037 for 32 bits);
921 * @param obj The calendar object
922 * @param min The minimum year
923 * @param max The maximum year
928 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
930 ELM_CHECK_WIDTYPE(obj, widtype);
931 Widget_Data *wd = elm_widget_data_get(obj);
933 if (min) *min = wd->year_min + 1900;
934 if (max) *max = wd->year_max + 1900;
938 * Enable or disable day selection
940 * Enabled by default. If disabled, the user can select months, but not days.
941 * It should be used if you won't need such selection for the widget usage.
943 * @param obj The calendar object
944 * @param enabled Boolean to enable (true) or disable (false) day selection
949 elm_calendar_day_selection_enabled_set(Evas_Object *obj, Eina_Bool enabled)
951 ELM_CHECK_WIDTYPE(obj, widtype);
952 Widget_Data *wd = elm_widget_data_get(obj);
954 wd->selection_enabled = enabled;
956 _select(wd, wd->selected_it);
958 _unselect(wd, wd->selected_it);
962 * Get day selection state
964 * Enabled by default. If disabled, the user can select months, but not days.
965 * It should be used if you won't need such selection for the widget usage.
967 * @param obj The calendar object
968 * @return True if day selection is enabled, or false otherwise. It will
969 * return false if it can't get widget data.
974 elm_calendar_day_selection_enabled_get(const Evas_Object *obj)
976 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
977 Widget_Data *wd = elm_widget_data_get(obj);
978 if (!wd) return EINA_FALSE;
979 return wd->selection_enabled;
985 * Set the time selected, changing the displayed month if needed.
986 * Selected time changes when the user changes the month or select a day.
988 * @param obj The calendar object
989 * @param selected_time A tm struct to represent the selected date
994 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
996 ELM_CHECK_WIDTYPE(obj, widtype);
997 Widget_Data *wd = elm_widget_data_get(obj);
1000 EINA_SAFETY_ON_NULL_RETURN(selected_time);
1001 wd->selected_time = *selected_time;
1009 * Get the time selected by the user.
1010 * Selected time changes when the user changes the month or select a day.
1012 * @param obj The calendar object
1013 * @param selected_time A tm struct to represent the selected date
1014 * @return It will return false if it can't get widget data, or true otherwise
1019 elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
1021 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1022 Widget_Data *wd = elm_widget_data_get(obj);
1023 if (!wd) return EINA_FALSE;
1024 EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
1025 *selected_time = wd->selected_time;
1030 * Set a function to format the string that will be used to display
1033 * By default it uses strftime with "%B %Y" format string.
1034 * It should allocate the memory that will be used by the string,
1035 * that will be freed by the widget after usage.
1036 * A pointer to the string and a pointer to the time struct will be provided.
1041 * _format_month_year(struct tm *stime)
1044 * if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
1045 * return strdup(buf);
1047 * elm_calendar_format_function_set(calendar, _format_month_year);
1050 * @param obj The calendar object
1051 * @param format_function Function to set the month-year string given
1057 elm_calendar_format_function_set(Evas_Object *obj, char * (*format_function) (struct tm *stime))
1059 ELM_CHECK_WIDTYPE(obj, widtype);
1060 Widget_Data *wd = elm_widget_data_get(obj);
1062 wd->format_func = format_function;
1066 * Add a new mark to the calendar
1068 * Add a mark that will be drawn in the calendar respecting the insertion time
1069 * and periodicity. It will emit the type as signal to the widget theme.
1070 * By default, it supports "holiday" and "checked", but it can be extended.
1072 * It won't immediately update the calendar, drawing the marks. For this, call
1073 * elm_calendar_marks_draw().
1077 * struct tm selected_time;
1078 * time_t current_time;
1080 * current_time = time(NULL) + 5 * 84600;
1081 * localtime_r(¤t_time, &selected_time);
1082 * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
1084 * current_time = time(NULL) + 1 * 84600;
1085 * localtime_r(¤t_time, &selected_time);
1086 * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
1088 * elm_calendar_marks_draw(cal);
1091 * @param obj The calendar object
1092 * @param mark_type A string used to define the type of mark. It will be
1093 * emitted to the theme, that should display a related modification on these
1094 * days representation.
1095 * @param mark_time A time struct to represent the date of inclusion of the
1096 * mark. For marks that repeats it will just be displayed after the inclusion
1097 * date in the calendar.
1098 * @param repeat Repeat the event following this periodicity. Can be a unique
1099 * mark (that don't repeat), daily, weekly, monthly or annually.
1101 * @return The created mark or NULL upon failure
1105 EAPI Elm_Calendar_Mark *
1106 elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
1108 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1109 Widget_Data *wd = elm_widget_data_get(obj);
1110 Elm_Calendar_Mark *mark;
1111 if (!wd) return NULL;
1113 mark = _mark_new(obj, mark_type, mark_time, repeat);
1114 wd->marks = eina_list_append(wd->marks, mark);
1115 mark->node = eina_list_last(wd->marks);
1120 * Delete mark from the calendar.
1122 * @param mark The mark to delete
1127 elm_calendar_mark_del(Elm_Calendar_Mark *mark)
1132 EINA_SAFETY_ON_NULL_RETURN(mark);
1135 wd = elm_widget_data_get(obj);
1138 wd->marks = eina_list_remove_list(wd->marks, mark->node);
1143 * Remove all the marks from the calendar
1145 * @param obj The calendar object
1150 elm_calendar_marks_clear(Evas_Object *obj)
1152 ELM_CHECK_WIDTYPE(obj, widtype);
1153 Widget_Data *wd = elm_widget_data_get(obj);
1154 Elm_Calendar_Mark *mark;
1157 EINA_LIST_FREE(wd->marks, mark)
1162 * Returns a list of all the calendar marks.
1164 * @param obj The calendar object
1165 * @return An Eina_List* of the calendar marks, or NULL on failure
1169 EAPI const Eina_List *
1170 elm_calendar_marks_get(const Evas_Object *obj)
1172 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1173 Widget_Data *wd = elm_widget_data_get(obj);
1174 if (!wd) return NULL;
1179 * Draw calendar marks.
1181 * Should be used after adding, removing or clearing marks.
1182 * It will go through the entire marks list updating the calendar
1183 * (not a cheap function). So if lots of marks will be added,
1184 * add all the marks and then call this function.
1186 * When the month is changed marks will be drawed.
1188 * @param obj The calendar object
1193 elm_calendar_marks_draw(Evas_Object *obj)
1195 ELM_CHECK_WIDTYPE(obj, widtype);
1196 Widget_Data *wd = elm_widget_data_get(obj);
1202 * Set a text color to the saturday color.
1204 * Deprecated. use elm_calendar_mark_add() instead like:
1207 * struct tm t = { 0, 0, 12, 6, 0, 0, 5, 5, -1 };
1208 * elm_calendar_mark_add(obj, "sat", &t, ELM_CALENDAR_WEEKLY);
1211 * @param obj The calendar object
1212 * @param pos The text position
1216 EINA_DEPRECATED EAPI void
1217 elm_calendar_text_saturday_color_set(Evas_Object *obj, int pos)
1219 ELM_CHECK_WIDTYPE(obj, widtype);
1220 Widget_Data *wd = elm_widget_data_get(obj);
1222 _text_day_color_set(wd, DAY_SATURDAY, pos);
1226 * Set a text color to the sunday color.
1228 * Deprecated. use elm_calendar_mark_add() instead like:
1231 * struct tm t = { 0, 0, 12, 7, 0, 0, 6, 6, -1 };
1232 * elm_calendar_mark_add(obj, "sun", &t, ELM_CALENDAR_WEEKLY);
1235 * @param obj The calendar object
1236 * @param pos The text position
1240 EINA_DEPRECATED EAPI void
1241 elm_calendar_text_sunday_color_set(Evas_Object *obj, int pos)
1243 ELM_CHECK_WIDTYPE(obj, widtype);
1244 Widget_Data *wd = elm_widget_data_get(obj);
1246 _text_day_color_set(wd, DAY_SUNDAY, pos);
1250 * Set a text color to the weekday color.
1252 * Deprecated. use elm_calendar_mark_add() instead like:
1255 * struct tm t = { 0, 0, 12, 1, 0, 0, 0, 0, -1 };
1257 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // monday
1258 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1259 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // tuesday
1260 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1261 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // wednesday
1262 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1263 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // thursday
1264 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1265 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // friday
1268 * @param obj The calendar object
1269 * @param pos The text position
1273 EINA_DEPRECATED EAPI void
1274 elm_calendar_text_weekday_color_set(Evas_Object *obj, int pos)
1276 ELM_CHECK_WIDTYPE(obj, widtype);
1277 Widget_Data *wd = elm_widget_data_get(obj);
1279 _text_day_color_set(wd, DAY_WEEKDAY, pos);