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 *stime);
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 /* Should not be translated, it's used if we failed
66 * getting from locale. */
67 static const char *_days_abbrev[] =
69 "Sun", "Mon", "Tue", "Wed",
73 static int _days_in_month[2][12] =
75 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
76 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
79 static Elm_Calendar_Mark *
80 _mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
82 Widget_Data *wd = elm_widget_data_get(obj);
83 Elm_Calendar_Mark *mark;
86 mark = calloc(1, sizeof(Elm_Calendar_Mark));
87 if (!mark) return NULL;
89 mark->mark_type = eina_stringshare_add(mark_type);
90 mark->mark_time = *mark_time;
91 mark->repeat = repeat;
96 _mark_free(Elm_Calendar_Mark *mark)
98 eina_stringshare_del(mark->mark_type);
103 _sizing_eval(Evas_Object *obj)
105 Widget_Data *wd = elm_widget_data_get(obj);
106 Evas_Coord minw = -1, minh = -1;
108 elm_coords_finger_size_adjust(8, &minw, 7, &minh);
109 edje_object_size_min_restricted_calc(wd->calendar, &minw, &minh, minw, minh);
110 evas_object_size_hint_min_set(obj, minw, minh);
111 evas_object_size_hint_max_set(obj, -1, -1);
115 _maxdays_get(struct tm *time)
119 month = time->tm_mon;
120 year = time->tm_year + 1900;
122 return _days_in_month[((!(year % 4)) &&
129 _unselect(Widget_Data *wd, int selected)
132 snprintf(emission, sizeof(emission), "cit_%i,unselected", selected);
133 edje_object_signal_emit(wd->calendar, emission, "elm");
137 _select(Widget_Data *wd, int selected)
140 snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
141 edje_object_signal_emit(wd->calendar, emission, "elm");
145 _not_today(Widget_Data *wd)
148 snprintf(emission, sizeof(emission), "cit_%i,not_today", wd->today_it);
149 edje_object_signal_emit(wd->calendar, emission, "elm");
154 _today(Widget_Data *wd, int it)
157 snprintf(emission, sizeof(emission), "cit_%i,today", it);
158 edje_object_signal_emit(wd->calendar, emission, "elm");
163 _format_month_year(struct tm *stime)
166 if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
171 _cit_mark(Evas_Object *cal, int cit, const char *mtype)
174 snprintf(sign, sizeof(sign), "cit_%i,%s", cit, mtype);
175 edje_object_signal_emit(cal, sign, "elm");
179 _weekday_get(int first_week_day, int day)
181 return (day + first_week_day - 1) % 7;
186 _text_day_color_update(Widget_Data *wd, int pos)
190 switch (wd->day_color[pos])
193 snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
196 snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
199 snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
205 edje_object_signal_emit(wd->calendar, emission, "elm");
210 _text_day_color_set(Widget_Data *wd, Day_Color col, int pos)
212 if ((pos < 0) || (pos >= 42)) return;
213 if (wd->day_color[pos] == col) return;
214 wd->day_color[pos] = col;
215 _text_day_color_update(wd, pos);
219 _populate(Evas_Object *obj)
221 int maxdays, day, mon, year, i;
222 Elm_Calendar_Mark *mark;
223 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->selected_time);
235 mon = wd->selected_time.tm_mon;
236 year = wd->selected_time.tm_year;
238 /* Set selected month */
239 buf = wd->format_func(&wd->selected_time);
242 edje_object_part_text_set(wd->calendar, "month_text", buf);
246 edje_object_part_text_set(wd->calendar, "month_text", "");
250 first_day = wd->selected_time;
251 first_day.tm_mday = 1;
254 // Layout of the calendar is changed for removing the unfilled last row.
255 wd->first_day_it = first_day.tm_wday;
257 if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
263 for (i = 0; i < 5; i++)
265 snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
266 edje_object_signal_emit(wd->calendar, emission, "elm");
268 snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
269 edje_object_signal_emit(wd->calendar, emission, "elm");
270 for (i = 0; i < 35; i++)
272 snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
273 edje_object_signal_emit(wd->calendar, emission, "elm");
275 for (i = 35; i < 42; i++)
277 snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
278 edje_object_signal_emit(wd->calendar, emission, "elm");
285 for (i = 0; i < 6; i++)
287 snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
288 edje_object_signal_emit(wd->calendar, emission, "elm");
290 for (i = 0; i < 42; i++)
292 snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
293 edje_object_signal_emit(wd->calendar, emission, "elm");
297 for (i = 0; i < 42; i++)
299 _text_day_color_update(wd, i); // EINA_DEPRECATED
300 if ((!day) && (i == first_day.tm_wday)) day = 1;
302 if ((day == wd->current_time.tm_mday)
303 && (mon == wd->current_time.tm_mon)
304 && (year == wd->current_time.tm_year))
307 if (day == wd->selected_time.tm_mday)
309 if ((wd->selected_it > -1) && (wd->selected_it != i))
310 _unselect(wd, wd->selected_it);
312 if (wd->selection_enabled) _select(wd, i);
317 if ((day) && (day <= maxdays))
318 snprintf(day_s, sizeof(day_s), "%i", day++);
322 snprintf(part, sizeof(part), "cit_%i.text", i);
323 edje_object_part_text_set(wd->calendar, part, day_s);
324 /* Clear previous marks */
325 _cit_mark(wd->calendar, i, "clear");
329 EINA_LIST_FOREACH(wd->marks, l, mark)
331 struct tm *mtime = &mark->mark_time;
332 int mon = wd->selected_time.tm_mon;
333 int year = wd->selected_time.tm_year;
334 int mday_it = mtime->tm_mday + wd->first_day_it - 1;
336 switch (mark->repeat)
338 case ELM_CALENDAR_UNIQUE:
339 if ((mtime->tm_mon == mon) && (mtime->tm_year == year))
340 _cit_mark(wd->calendar, mday_it, mark->mark_type);
342 case ELM_CALENDAR_DAILY:
343 if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
344 (mtime->tm_year < year))
346 else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
347 day = mtime->tm_mday;
350 for (; day <= maxdays; day++)
351 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
354 case ELM_CALENDAR_WEEKLY:
355 if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
356 (mtime->tm_year < year))
358 else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
359 day = mtime->tm_mday;
362 for (; day <= maxdays; day++)
363 if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
364 _cit_mark(wd->calendar, day + wd->first_day_it - 1,
367 case ELM_CALENDAR_MONTHLY:
368 if (((mtime->tm_year < year) ||
369 ((mtime->tm_year == year) && (mtime->tm_mon <= mon))) &&
370 (mtime->tm_mday <= maxdays))
371 _cit_mark(wd->calendar, mday_it, mark->mark_type);
373 case ELM_CALENDAR_ANNUALLY:
374 if ((mtime->tm_year <= year) && (mtime->tm_mon == mon) &&
375 (mtime->tm_mday <= maxdays))
376 _cit_mark(wd->calendar, mday_it, mark->mark_type);
383 _set_headers(Evas_Object *obj)
385 static char part[] = "ch_0.text";
387 Widget_Data *wd = elm_widget_data_get(obj);
390 for (i = 0; i < 7; i++)
393 edje_object_part_text_set(wd->calendar, part, wd->weekdays[i]);
398 _del_hook(Evas_Object *obj)
401 Elm_Calendar_Mark *mark;
402 Widget_Data *wd = elm_widget_data_get(obj);
406 if (wd->spin) ecore_timer_del(wd->spin);
407 if (wd->update_timer) ecore_timer_del(wd->update_timer);
411 EINA_LIST_FREE(wd->marks, mark)
417 for (i = 0; i < 7; i++)
418 eina_stringshare_del(wd->weekdays[i]);
424 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
426 Widget_Data *wd = elm_widget_data_get(obj);
428 if (elm_widget_focus_get(obj))
430 edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
431 evas_object_focus_set(wd->calendar, EINA_TRUE);
435 edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
436 evas_object_focus_set(wd->calendar, EINA_FALSE);
441 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
443 Widget_Data *wd = elm_widget_data_get(obj);
445 edje_object_mirrored_set(wd->calendar, rtl);
449 _theme_hook(Evas_Object *obj)
451 Widget_Data *wd = elm_widget_data_get(obj);
453 _elm_widget_mirrored_reload(obj);
454 _elm_theme_object_set(obj, wd->calendar, "calendar", "base",
455 elm_widget_style_get(obj));
456 _mirrored_set(obj, elm_widget_mirrored_get(obj));
459 edje_object_message_signal_process(wd->calendar);
460 edje_object_scale_set(wd->calendar,
461 elm_widget_scale_get(obj) * _elm_config->scale);
466 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
468 Widget_Data *wd = elm_widget_data_get(obj);
470 edje_object_signal_emit(wd->calendar, emission, source);
474 _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)
476 Widget_Data *wd = elm_widget_data_get(obj);
478 edje_object_signal_callback_add(wd->calendar, emission,
479 source, func_cb, data);
483 _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)
485 Widget_Data *wd = elm_widget_data_get(obj);
487 edje_object_signal_callback_del_full(wd->calendar, emission, source, func_cb,
491 /* Set correct tm_wday and tm_yday after other fields changes*/
493 _fix_selected_time(Widget_Data *wd)
495 mktime(&wd->selected_time);
499 _update_month(Evas_Object *obj, int delta)
501 struct tm time_check;
503 Widget_Data *wd = elm_widget_data_get(obj);
504 if (!wd) return EINA_FALSE;
506 /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
507 time_check = wd->selected_time;
508 time_check.tm_mon += delta;
509 if (mktime(&time_check) == -1)
512 wd->selected_time.tm_mon += delta;
513 if (wd->selected_time.tm_mon < 0)
515 if (wd->selected_time.tm_year == wd->year_min)
517 wd->selected_time.tm_mon++;
520 wd->selected_time.tm_mon = 11;
521 wd->selected_time.tm_year--;
523 else if (wd->selected_time.tm_mon > 11)
525 if (wd->selected_time.tm_year == wd->year_max)
527 wd->selected_time.tm_mon--;
530 wd->selected_time.tm_mon = 0;
531 wd->selected_time.tm_year++;
534 maxdays = _maxdays_get(&wd->selected_time);
535 if (wd->selected_time.tm_mday > maxdays)
536 wd->selected_time.tm_mday = maxdays;
538 _fix_selected_time(wd);
539 evas_object_smart_callback_call(obj, "changed", NULL);
545 _spin_value(void *data)
547 Widget_Data *wd = elm_widget_data_get(data);
548 if (!wd) return ECORE_CALLBACK_CANCEL;
549 if (_update_month(data, wd->spin_speed)) _populate(data);
550 wd->interval = wd->interval / 1.05;
551 ecore_timer_interval_set(wd->spin, wd->interval);
552 return ECORE_CALLBACK_RENEW;
556 _button_inc_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_dec_start(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;
574 if (wd->spin) ecore_timer_del(wd->spin);
575 wd->spin = ecore_timer_add(wd->interval, _spin_value, data);
580 _button_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
582 Widget_Data *wd = elm_widget_data_get(data);
584 wd->interval = wd->first_interval;
585 if (wd->spin) ecore_timer_del(wd->spin);
590 _get_item_day(Evas_Object *obj, int selected_it)
593 Widget_Data *wd = elm_widget_data_get(obj);
596 day = selected_it - wd->first_day_it + 1;
597 if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
604 _update_sel_it(Evas_Object *obj, int sel_it)
607 Widget_Data *wd = elm_widget_data_get(obj);
608 if ((!wd) || (!wd->selection_enabled))
611 day = _get_item_day(obj, sel_it);
615 _unselect(wd, wd->selected_it);
617 wd->selected_it = sel_it;
618 wd->selected_time.tm_mday = day;
619 _select(wd, wd->selected_it);
620 _fix_selected_time(wd);
621 evas_object_smart_callback_call(obj, "changed", NULL);
625 _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
628 Widget_Data *wd = elm_widget_data_get(data);
629 if ((!wd) || (!wd->selection_enabled))
631 sel_it = atoi(source);
633 _update_sel_it(data, sel_it);
637 _time_to_next_day(struct tm *t)
639 return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
643 _update_cur_date(void *data)
647 Widget_Data *wd = elm_widget_data_get(data);
648 if (!wd) return ECORE_CALLBACK_RENEW;
650 if (wd->today_it > 0) _not_today(wd);
652 current_time = time(NULL);
653 localtime_r(¤t_time, &wd->current_time);
654 t = _time_to_next_day(&wd->current_time);
655 ecore_timer_interval_set(wd->update_timer, t);
657 if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
658 (wd->current_time.tm_year!= wd->selected_time.tm_year))
659 return ECORE_CALLBACK_RENEW;
661 day = wd->current_time.tm_mday + wd->first_day_it - 1;
664 return ECORE_CALLBACK_RENEW;
668 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
670 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
671 Evas_Event_Key_Down *ev = event_info;
672 Widget_Data *wd = elm_widget_data_get(obj);
674 if (!wd) return EINA_FALSE;
675 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
676 if (!wd->selection_enabled) return EINA_FALSE;
678 if ((!strcmp(ev->keyname, "Left")) ||
679 (!strcmp(ev->keyname, "KP_Left")))
681 _update_sel_it(obj, wd->selected_it-1);
683 else if ((!strcmp(ev->keyname, "Right")) ||
684 (!strcmp(ev->keyname, "KP_Right")))
686 _update_sel_it(obj, wd->selected_it+1);
688 else if ((!strcmp(ev->keyname, "Up")) ||
689 (!strcmp(ev->keyname, "KP_Up")))
691 _update_sel_it(obj, wd->selected_it-7);
693 else if ((!strcmp(ev->keyname, "Down")) ||
694 (!strcmp(ev->keyname, "KP_Down")))
696 _update_sel_it(obj, wd->selected_it+7);
698 else if ((!strcmp(ev->keyname, "Prior")) ||
699 (!strcmp(ev->keyname, "KP_Prior")))
701 if (_update_month(obj, -1)) _populate(obj);
703 else if ((!strcmp(ev->keyname, "Next")) ||
704 (!strcmp(ev->keyname, "KP_Next")))
706 if (_update_month(obj, 1)) _populate(obj);
708 else return EINA_FALSE;
714 * Add a new calendar to the parent
716 * @param parent The parent object
717 * @return The new object or NULL if it cannot be created
722 elm_calendar_add(Evas_Object *parent)
725 time_t weekday = 259200; /* Just the first sunday since epoch */
731 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
733 ELM_SET_WIDTYPE(widtype, "calendar");
734 elm_widget_type_set(obj, "calendar");
735 elm_widget_sub_object_add(parent, obj);
736 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
737 elm_widget_data_set(obj, wd);
738 elm_widget_del_hook_set(obj, _del_hook);
739 elm_widget_theme_hook_set(obj, _theme_hook);
740 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
741 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
742 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
743 elm_widget_can_focus_set(obj, EINA_TRUE);
744 elm_widget_event_hook_set(obj, _event_hook);
746 wd->first_interval = 0.85;
750 wd->selected_it = -1;
751 wd->first_day_it = -1;
752 wd->selection_enabled = EINA_TRUE;
753 wd->format_func = _format_month_year;
756 wd->calendar = edje_object_add(e);
757 _elm_theme_object_set(obj, wd->calendar, "calendar", "base", "default");
758 elm_widget_resize_object_set(obj, wd->calendar);
760 edje_object_signal_callback_add(wd->calendar, "elm,action,increment,start",
761 "*", _button_inc_start, obj);
762 edje_object_signal_callback_add(wd->calendar, "elm,action,decrement,start",
763 "*", _button_dec_start, obj);
764 edje_object_signal_callback_add(wd->calendar, "elm,action,stop",
765 "*", _button_stop, obj);
766 edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
767 "*", _day_selected, obj);
769 for (i = 0; i < 7; i++)
771 /* FIXME: I'm not aware of a known max, so if it fails,
772 * just make it larger. :| */
774 /* I don't know of a better way of doing it */
775 if (strftime(buf, sizeof(buf), "%a", gmtime(&weekday)))
777 wd->weekdays[i] = eina_stringshare_add(buf);
781 /* If we failed getting day, get a default value */
782 wd->weekdays[i] = _days_abbrev[i];
783 WRN("Failed getting weekday name for '%s' from locale.",
786 weekday += 86400; /* Advance by a day */
789 current_time = time(NULL);
790 localtime_r(¤t_time, &wd->selected_time);
791 wd->current_time = wd->selected_time;
792 t = _time_to_next_day(&wd->current_time);
793 wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
797 _mirrored_set(obj, elm_widget_mirrored_get(obj));
803 * Set weekdays names to display in the calendar.
805 * By default, the following abbreviations are displayed:
806 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
807 * The first string should be related to Sunday, the second to Monday...
809 * The usage should be like this:
811 * const char *weekdays[] =
813 * "Sunday", "Monday", "Tuesday", "Wednesday",
814 * "Thursday", "Friday", "Saturday"
816 * elm_calendar_weekdays_names_set(calendar, weekdays);
819 * @param obj The calendar object
820 * @param weedays Array of seven strings to be used as weekday names.
821 * Warning: it must have 7 elements, or it will access invalid memory.
822 * The strings must be NULL terminated ('@\0').
827 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
830 ELM_CHECK_WIDTYPE(obj, widtype);
831 Widget_Data *wd = elm_widget_data_get(obj);
834 EINA_SAFETY_ON_NULL_RETURN(weekdays);
836 for (i = 0; i < 7; i++)
838 eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
844 * Get weekdays names displayed in the calendar.
846 * By default, the following abbreviations are displayed:
847 * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
848 * The first string is related to Sunday, the second to Monday...
850 * @param obj The calendar object
851 * @return Array of seven strings to used as weekday names.
856 elm_calendar_weekdays_names_get(const Evas_Object *obj)
858 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
859 Widget_Data *wd = elm_widget_data_get(obj);
860 if (!wd) return NULL;
865 * Set the interval for the calendar
867 * The interval value is decreased while the user increments or decrements
868 * the calendar value. The next interval value is the previous interval / 1.05,
869 * so it speed up a bit. Default value is 0.85 seconds.
871 * @param obj The calendar object
872 * @param interval The interval value in seconds
877 elm_calendar_interval_set(Evas_Object *obj, double interval)
879 ELM_CHECK_WIDTYPE(obj, widtype);
880 Widget_Data *wd = elm_widget_data_get(obj);
882 wd->first_interval = interval;
886 * Get the interval of the calendar
888 * The interval value is decreased while the user increments or decrements
889 * the calendar value. The next interval value is the previous interval / 1.05,
890 * so it speed up a bit. Default value is 0.85 seconds.
892 * @param obj The calendar object
893 * @return The value of the first interval in seconds
898 elm_calendar_interval_get(const Evas_Object *obj)
900 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
901 Widget_Data *wd = elm_widget_data_get(obj);
903 return wd->first_interval;
907 * Set the minimum and maximum values for the year
909 * Maximum must be greater than minimum, except if you don't wan't to set
911 * Default values are 1902 and -1.
913 * If the maximum year is a negative value, it will be limited depending of the
914 * platform architecture (2037 for 32 bits);
916 * @param obj The calendar object
917 * @param min The minimum year, greater than 1901;
918 * @param max The maximum year;
923 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
925 ELM_CHECK_WIDTYPE(obj, widtype);
926 Widget_Data *wd = elm_widget_data_get(obj);
930 if ((wd->year_min == min) && (wd->year_max == max)) return;
931 wd->year_min = min > 2 ? min : 2;
933 if (wd->selected_time.tm_year > wd->year_max)
934 wd->selected_time.tm_year = wd->year_max;
935 if (wd->selected_time.tm_year < wd->year_min)
936 wd->selected_time.tm_year = wd->year_min;
937 _fix_selected_time(wd);
942 * Get the minimum and maximum values for the year
944 * Default values are 1902 and -1.
946 * If the maximum year is a negative value, it will be limited depending of the
947 * platform architecture (2037 for 32 bits);
949 * @param obj The calendar object
950 * @param min The minimum year
951 * @param max The maximum year
956 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
958 ELM_CHECK_WIDTYPE(obj, widtype);
959 Widget_Data *wd = elm_widget_data_get(obj);
961 if (min) *min = wd->year_min + 1900;
962 if (max) *max = wd->year_max + 1900;
966 * Enable or disable day selection
968 * Enabled by default. If disabled, the user can select months, but not days.
969 * It should be used if you won't need such selection for the widget usage.
971 * @param obj The calendar object
972 * @param enabled Boolean to enable (true) or disable (false) day selection
977 elm_calendar_day_selection_enabled_set(Evas_Object *obj, Eina_Bool enabled)
979 ELM_CHECK_WIDTYPE(obj, widtype);
980 Widget_Data *wd = elm_widget_data_get(obj);
982 wd->selection_enabled = enabled;
984 _select(wd, wd->selected_it);
986 _unselect(wd, wd->selected_it);
990 * Get day selection state
992 * Enabled by default. If disabled, the user can select months, but not days.
993 * It should be used if you won't need such selection for the widget usage.
995 * @param obj The calendar object
996 * @return True if day selection is enabled, or false otherwise. It will
997 * return false if it can't get widget data.
1002 elm_calendar_day_selection_enabled_get(const Evas_Object *obj)
1004 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1005 Widget_Data *wd = elm_widget_data_get(obj);
1006 if (!wd) return EINA_FALSE;
1007 return wd->selection_enabled;
1013 * Set the time selected, changing the displayed month if needed.
1014 * Selected time changes when the user changes the month or select a day.
1016 * @param obj The calendar object
1017 * @param selected_time A tm struct to represent the selected date
1022 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
1024 ELM_CHECK_WIDTYPE(obj, widtype);
1025 Widget_Data *wd = elm_widget_data_get(obj);
1028 EINA_SAFETY_ON_NULL_RETURN(selected_time);
1029 wd->selected_time = *selected_time;
1037 * Get the time selected by the user.
1038 * Selected time changes when the user changes the month or select a day.
1040 * @param obj The calendar object
1041 * @param selected_time A tm struct to represent the selected date
1042 * @return It will return false if it can't get widget data, or true otherwise
1047 elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
1049 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1050 Widget_Data *wd = elm_widget_data_get(obj);
1051 if (!wd) return EINA_FALSE;
1052 EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
1053 *selected_time = wd->selected_time;
1058 * Set a function to format the string that will be used to display
1061 * By default it uses strftime with "%B %Y" format string.
1062 * It should allocate the memory that will be used by the string,
1063 * that will be freed by the widget after usage.
1064 * A pointer to the string and a pointer to the time struct will be provided.
1069 * _format_month_year(struct tm *stime)
1072 * if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
1073 * return strdup(buf);
1075 * elm_calendar_format_function_set(calendar, _format_month_year);
1078 * @param obj The calendar object
1079 * @param format_function Function to set the month-year string given
1085 elm_calendar_format_function_set(Evas_Object *obj, char * (*format_function) (struct tm *stime))
1087 ELM_CHECK_WIDTYPE(obj, widtype);
1088 Widget_Data *wd = elm_widget_data_get(obj);
1090 wd->format_func = format_function;
1094 * Add a new mark to the calendar
1096 * Add a mark that will be drawn in the calendar respecting the insertion time
1097 * and periodicity. It will emit the type as signal to the widget theme.
1098 * By default, it supports "holiday" and "checked", but it can be extended.
1100 * It won't immediately update the calendar, drawing the marks. For this, call
1101 * elm_calendar_marks_draw().
1105 * struct tm selected_time;
1106 * time_t current_time;
1108 * current_time = time(NULL) + 5 * 84600;
1109 * localtime_r(¤t_time, &selected_time);
1110 * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
1112 * current_time = time(NULL) + 1 * 84600;
1113 * localtime_r(¤t_time, &selected_time);
1114 * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
1116 * elm_calendar_marks_draw(cal);
1119 * @param obj The calendar object
1120 * @param mark_type A string used to define the type of mark. It will be
1121 * emitted to the theme, that should display a related modification on these
1122 * days representation.
1123 * @param mark_time A time struct to represent the date of inclusion of the
1124 * mark. For marks that repeats it will just be displayed after the inclusion
1125 * date in the calendar.
1126 * @param repeat Repeat the event following this periodicity. Can be a unique
1127 * mark (that don't repeat), daily, weekly, monthly or annually.
1129 * @return The created mark or NULL upon failure
1133 EAPI Elm_Calendar_Mark *
1134 elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
1136 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1137 Widget_Data *wd = elm_widget_data_get(obj);
1138 Elm_Calendar_Mark *mark;
1139 if (!wd) return NULL;
1141 mark = _mark_new(obj, mark_type, mark_time, repeat);
1142 wd->marks = eina_list_append(wd->marks, mark);
1143 mark->node = eina_list_last(wd->marks);
1148 * Delete mark from the calendar.
1150 * @param mark The mark to delete
1155 elm_calendar_mark_del(Elm_Calendar_Mark *mark)
1160 EINA_SAFETY_ON_NULL_RETURN(mark);
1163 wd = elm_widget_data_get(obj);
1166 wd->marks = eina_list_remove_list(wd->marks, mark->node);
1171 * Remove all the marks from the calendar
1173 * @param obj The calendar object
1178 elm_calendar_marks_clear(Evas_Object *obj)
1180 ELM_CHECK_WIDTYPE(obj, widtype);
1181 Widget_Data *wd = elm_widget_data_get(obj);
1182 Elm_Calendar_Mark *mark;
1185 EINA_LIST_FREE(wd->marks, mark)
1190 * Returns a list of all the calendar marks.
1192 * @param obj The calendar object
1193 * @return An Eina_List* of the calendar marks, or NULL on failure
1197 EAPI const Eina_List *
1198 elm_calendar_marks_get(const Evas_Object *obj)
1200 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1201 Widget_Data *wd = elm_widget_data_get(obj);
1202 if (!wd) return NULL;
1207 * Draw calendar marks.
1209 * Should be used after adding, removing or clearing marks.
1210 * It will go through the entire marks list updating the calendar
1211 * (not a cheap function). So if lots of marks will be added,
1212 * add all the marks and then call this function.
1214 * When the month is changed marks will be drawed.
1216 * @param obj The calendar object
1221 elm_calendar_marks_draw(Evas_Object *obj)
1223 ELM_CHECK_WIDTYPE(obj, widtype);
1224 Widget_Data *wd = elm_widget_data_get(obj);
1230 * Set a text color to the saturday color.
1232 * Deprecated. use elm_calendar_mark_add() instead like:
1235 * struct tm t = { 0, 0, 12, 6, 0, 0, 5, 5, -1 };
1236 * elm_calendar_mark_add(obj, "sat", &t, ELM_CALENDAR_WEEKLY);
1239 * @param obj The calendar object
1240 * @param pos The text position
1244 EINA_DEPRECATED EAPI void
1245 elm_calendar_text_saturday_color_set(Evas_Object *obj, int pos)
1247 ELM_CHECK_WIDTYPE(obj, widtype);
1248 Widget_Data *wd = elm_widget_data_get(obj);
1250 _text_day_color_set(wd, DAY_SATURDAY, pos);
1254 * Set a text color to the sunday color.
1256 * Deprecated. use elm_calendar_mark_add() instead like:
1259 * struct tm t = { 0, 0, 12, 7, 0, 0, 6, 6, -1 };
1260 * elm_calendar_mark_add(obj, "sun", &t, ELM_CALENDAR_WEEKLY);
1263 * @param obj The calendar object
1264 * @param pos The text position
1268 EINA_DEPRECATED EAPI void
1269 elm_calendar_text_sunday_color_set(Evas_Object *obj, int pos)
1271 ELM_CHECK_WIDTYPE(obj, widtype);
1272 Widget_Data *wd = elm_widget_data_get(obj);
1274 _text_day_color_set(wd, DAY_SUNDAY, pos);
1278 * Set a text color to the weekday color.
1280 * Deprecated. use elm_calendar_mark_add() instead like:
1283 * struct tm t = { 0, 0, 12, 1, 0, 0, 0, 0, -1 };
1285 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // monday
1286 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1287 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // tuesday
1288 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1289 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // wednesday
1290 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1291 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // thursday
1292 * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
1293 * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // friday
1296 * @param obj The calendar object
1297 * @param pos The text position
1301 EINA_DEPRECATED EAPI void
1302 elm_calendar_text_weekday_color_set(Evas_Object *obj, int pos)
1304 ELM_CHECK_WIDTYPE(obj, widtype);
1305 Widget_Data *wd = elm_widget_data_get(obj);
1307 _text_day_color_set(wd, DAY_WEEKDAY, pos);