1 #include <Elementary.h>
12 typedef struct _Widget_Data Widget_Data;
13 typedef struct _Datetime_Field Datetime_Field;
14 typedef struct _Datetime_Mod_Api Datetime_Mod_Api;
15 typedef struct _Format_Map Format_Map;
17 #define DATETIME_TYPE_COUNT 6
18 #define MAX_FORMAT_LEN 64
19 #define MAX_SEPARATOR_LEN 6
20 #define MAX_FIELD_FORMAT_LEN 3
21 #define MIN_DAYS_IN_MONTH 28
22 #define BUFFER_SIZE 1024
24 // interface between EDC & C code. Field names & signal names.
25 // values 0 to DATETIME_TYPE_COUNT are valid range, can be substituted for %d.
26 #define EDC_DATETIME_ENABLE_SIG_STR "elm,state,enabled"
27 #define EDC_DATETIME_DISABLE_SIG_STR "elm,state,disabled"
28 #define EDC_DATETIME_FOCUSIN_SIG_STR "elm,action,focus"
29 #define EDC_DATETIME_FOCUSOUT_SIG_STR "elm,action,unfocus"
30 #define EDC_PART_FIELD_STR "field%d"
31 #define EDC_PART_SEPARATOR_STR "separator%d"
32 #define EDC_PART_FIELD_ENABLE_SIG_STR "field%d,enable"
33 #define EDC_PART_FIELD_DISABLE_SIG_STR "field%d,disable"
35 // struct tm does not define the fields in the order from year, month, date, hour, minute.
36 // values are reassigned to an array for easy handling.
37 #define DATETIME_TM_ARRAY(intptr, tmptr) int *intptr[] = {&(tmptr)->tm_year, \
38 &(tmptr)->tm_mon, &(tmptr)->tm_mday, &(tmptr)->tm_hour, &(tmptr)->tm_min}
40 struct _Datetime_Field
42 Evas_Object *item_obj;
43 char fmt[MAX_FIELD_FORMAT_LEN];
44 Elm_Datetime_Field_Type type;
45 const char *separator;
46 int location; // location of the field as per the current format
48 Eina_Bool fmt_exist:1; // whether field format is present or not
49 Eina_Bool visible:1; // whether field can be visible or not
52 struct _Datetime_Mod_Api
54 Elm_Datetime_Module_Data *(*obj_hook) (Evas_Object *obj);
55 void (*obj_unhook) (Elm_Datetime_Module_Data *module_data);
56 Evas_Object *(*field_create) (Elm_Datetime_Module_Data *module_data,
57 Elm_Datetime_Field_Type field_type);
58 void (*field_value_display) (Elm_Datetime_Module_Data *module_data,
65 Datetime_Field field_list[DATETIME_TYPE_COUNT]; // fixed set of fields.
66 struct tm curr_time, min_limit, max_limit;
67 Elm_Datetime_Module_Data *mod_data;
68 char format[MAX_FORMAT_LEN];
69 Eina_Bool user_format:1; // whether user set format or default format.
79 // default limits for individual fields
80 static Format_Map mapping[DATETIME_TYPE_COUNT] = {
81 [ELM_DATETIME_YEAR] = { "Yy", -1, -1 },
82 [ELM_DATETIME_MONTH] = { "mbBh", 0, 11 },
83 [ELM_DATETIME_DATE] = { "de", 1, 31 },
84 [ELM_DATETIME_HOUR] = { "IHkl", 0, 23 },
85 [ELM_DATETIME_MINUTE] = { "M", 0, 59 },
86 [ELM_DATETIME_AMPM] = { "pP", 0, 1 }
89 static const char *multifield_formats = "cxXrRTDF";
91 static Datetime_Mod_Api *dt_mod = NULL;
92 static const char *widtype = NULL;
94 static void _del_hook(Evas_Object *obj);
95 static void _disable_hook(Evas_Object *obj);
96 static void _translate_hook(Evas_Object *obj);
97 static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj);
98 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
99 static void _sizing_eval(Evas_Object *obj);
100 static void _theme_hook(Evas_Object *obj);
101 static void _validate_datetime_limits(struct tm *time1, struct tm *time2, Eina_Bool swap);
102 static void _apply_field_limits(Evas_Object *obj);
103 static void _apply_range_restrictions(Evas_Object *obj, struct tm *time);
104 static const char *_field_format_get(Evas_Object * obj, Elm_Datetime_Field_Type field_type);
105 static void _field_limit_get(Evas_Object * obj, Elm_Datetime_Field_Type field_type,
106 int *range_min, int *range_max);
107 static void _reload_format(Evas_Object *obj);
108 static void _field_list_display(Evas_Object *obj);
109 static void _field_list_arrange(Evas_Object *obj);
110 static void _field_list_init(Evas_Object *obj);
112 static const char SIG_CHANGED[] = "changed";
113 static const char SIG_LANGUAGE_CHANGED[] = "language,changed";
114 static const Evas_Smart_Cb_Description _signals[] = {
116 {SIG_LANGUAGE_CHANGED, ""},
120 static Datetime_Mod_Api *
123 Elm_Module *mod = NULL;
124 if (!(mod = _elm_module_find_as("datetime/api"))) return NULL;
126 mod->api = malloc(sizeof(Datetime_Mod_Api));
127 if (!mod->api) return NULL;
129 ((Datetime_Mod_Api *)(mod->api))->obj_hook = _elm_module_symbol_get(mod, "obj_hook");
130 ((Datetime_Mod_Api *)(mod->api))->obj_unhook = _elm_module_symbol_get(mod, "obj_unhook");
131 ((Datetime_Mod_Api *)(mod->api))->field_create = _elm_module_symbol_get(mod, "field_create");
132 ((Datetime_Mod_Api *)(mod->api))->field_value_display = _elm_module_symbol_get(mod, "field_value_display");
138 _del_hook(Evas_Object *obj)
144 wd = elm_widget_data_get(obj);
147 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
149 tmp = wd->field_list + idx;
150 evas_object_del(tmp->item_obj);
151 eina_stringshare_del(tmp->separator);
154 if ((dt_mod) && (dt_mod->obj_unhook))
155 dt_mod->obj_unhook(wd->mod_data); // module - unhook
161 _disable_hook(Evas_Object *obj)
165 wd = elm_widget_data_get(obj);
166 if (!wd || !wd->base) return;
167 if (elm_widget_disabled_get(obj))
168 edje_object_signal_emit(wd->base, EDC_DATETIME_DISABLE_SIG_STR, "elm");
170 edje_object_signal_emit(wd->base, EDC_DATETIME_ENABLE_SIG_STR, "elm");
174 _translate_hook(Evas_Object *obj)
177 wd = elm_widget_data_get(obj);
180 if (!wd->user_format) _reload_format(obj);
181 else _field_list_display(obj);
182 evas_object_smart_callback_call(obj, SIG_LANGUAGE_CHANGED, NULL);
186 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
190 wd = elm_widget_data_get(obj);
193 if (elm_widget_focus_get(obj))
194 edje_object_signal_emit(wd->base, EDC_DATETIME_FOCUSIN_SIG_STR, "elm");
196 edje_object_signal_emit(wd->base, EDC_DATETIME_FOCUSOUT_SIG_STR, "elm");
200 _datetime_items_get(const Evas_Object *obj)
203 Eina_List *items = NULL;
204 Datetime_Field *field;
208 wd = elm_widget_data_get(obj);
209 if (!wd) return NULL;
211 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
213 field = wd->field_list + idx;
214 if (field->fmt_exist && field->visible) count++;
216 for (loc = 0; loc < count; loc++)
218 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
220 field = wd->field_list + idx;
221 if (field->location == loc)
222 items = eina_list_append(items, field->item_obj);
230 _elm_datetime_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
233 const Eina_List *items;
234 void *(*list_data_get) (const Eina_List *list);
235 Eina_List *(*list_free) (Eina_List *list);
238 wd = elm_widget_data_get(obj);
239 if (!wd) return EINA_FALSE;
241 if ((items = elm_widget_focus_custom_chain_get(obj)))
243 list_data_get = eina_list_data_get;
248 items = _datetime_items_get(obj);
249 list_data_get = eina_list_data_get;
250 list_free = eina_list_free;
251 if (!items) return EINA_FALSE;
254 ret = elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
255 if (list_free) list_free((Eina_List *)items);
261 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
265 wd = elm_widget_data_get(obj);
268 edje_object_mirrored_set(wd->base, rtl);
272 _sizing_eval(Evas_Object *obj)
275 Datetime_Field *field;
276 Evas_Coord minw = -1, minh = -1;
277 unsigned int idx, field_count = 0;
279 wd = elm_widget_data_get(obj);
280 if (!wd || !wd->base) return;
281 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
283 field = wd->field_list + idx;
284 if ((field->visible) && (field->fmt_exist)) field_count ++;
287 elm_coords_finger_size_adjust(field_count, &minw, 1, &minh);
288 edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
289 evas_object_size_hint_min_set(obj, minw, minh);
290 evas_object_size_hint_max_set(obj, -1, -1);
294 _theme_hook(Evas_Object *obj)
297 Datetime_Field *field;
298 char buf[BUFFER_SIZE];
301 wd = elm_widget_data_get(obj);
302 if (!wd || !wd->base) return;
304 _elm_theme_object_set(obj, wd->base, "datetime", "base",
305 elm_widget_style_get(obj));
306 _elm_widget_mirrored_reload(obj);
307 _mirrored_set(obj, elm_widget_mirrored_get(obj));
309 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
311 if (elm_widget_disabled_get(obj))
312 edje_object_signal_emit(wd->base, EDC_DATETIME_DISABLE_SIG_STR,"elm");
314 edje_object_signal_emit(wd->base, EDC_DATETIME_ENABLE_SIG_STR, "elm");
316 if ((!dt_mod) || (!dt_mod->field_value_display)) return;
318 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
320 field = wd->field_list + idx;
321 if (field->fmt_exist && field->visible)
323 snprintf(buf, sizeof(buf), EDC_PART_FIELD_ENABLE_SIG_STR, field->location);
324 edje_object_signal_emit(wd->base, buf, "elm");
325 snprintf(buf, sizeof(buf), EDC_PART_SEPARATOR_STR, field->location);
326 edje_object_part_text_set(wd->base, buf, field->separator);
327 dt_mod->field_value_display(wd->mod_data, field->item_obj);
331 snprintf(buf, sizeof(buf),EDC_PART_FIELD_DISABLE_SIG_STR, field->location);
332 edje_object_signal_emit(wd->base, buf, "elm");
335 edje_object_message_signal_process(wd->base);
340 _max_days_get(int year, int month)
347 localtime_r(&t, &time1);
348 time1.tm_year = year;
349 time1.tm_mon = month;
350 for(day = MIN_DAYS_IN_MONTH; day <= mapping[ELM_DATETIME_DATE].def_max; day++)
354 if (time1.tm_mday == 1) break;
361 _date_cmp(struct tm *time1, struct tm *time2)
364 DATETIME_TM_ARRAY(timearr1, time1);
365 DATETIME_TM_ARRAY(timearr2, time2);
367 for (idx = 0; idx < DATETIME_TYPE_COUNT - 1; idx++)
369 if (*timearr1[idx] != *timearr2[idx])
375 // validates curr_time/min_limt/max_limit according to the newly set value
377 _validate_datetime_limits(struct tm *time1, struct tm *time2, Eina_Bool swap)
381 if (!time1 || !time2) return;
383 t1 = (swap) ? time2 : time1;
384 t2 = (swap) ? time1 : time2;
386 DATETIME_TM_ARRAY(timearr1, time1);
387 DATETIME_TM_ARRAY(timearr2, time2);
388 for (idx = 0; idx < DATETIME_TYPE_COUNT - 1; idx++)
390 if (*timearr1[idx] < *timearr2[idx])
392 memcpy(t1, t2, sizeof(struct tm));
395 else if (*timearr1[idx] > *timearr2[idx])
401 _apply_field_limits(Evas_Object *obj)
404 Datetime_Field *field;
406 unsigned int idx = 0;
408 wd = elm_widget_data_get(obj);
411 DATETIME_TM_ARRAY(timearr, &wd->curr_time);
412 for (idx = 0; idx < DATETIME_TYPE_COUNT - 1; idx++)
414 field = wd->field_list + idx;
416 if (val < field->min)
417 *timearr[idx] = field->min;
418 else if (val > field->max)
419 *timearr[idx] = field->max;
421 _field_list_display(obj);
425 _apply_range_restrictions(Evas_Object *obj, struct tm *tim)
431 wd = elm_widget_data_get(obj);
432 if (!wd || !tim) return;
434 DATETIME_TM_ARRAY(timearr, tim);
435 for (idx = ELM_DATETIME_MONTH; idx < DATETIME_TYPE_COUNT - 1; idx++)
438 min = mapping[idx].def_min;
439 max = mapping[idx].def_max;
440 if (idx == ELM_DATETIME_DATE)
441 max = _max_days_get(tim->tm_year, tim->tm_mon);
450 _field_format_get(Evas_Object * obj, Elm_Datetime_Field_Type field_type)
453 Datetime_Field *field;
455 wd = elm_widget_data_get(obj);
456 if (!wd) return NULL;
458 field = wd->field_list + field_type;
459 if (!field) return NULL;
465 _field_limit_get(Evas_Object * obj, Elm_Datetime_Field_Type field_type, int *range_min, int *range_max)
468 Datetime_Field *field;
469 int min, max, max_days;
472 wd = elm_widget_data_get(obj);
475 field = wd->field_list + field_type;
481 DATETIME_TM_ARRAY(curr_timearr, &wd->curr_time);
482 DATETIME_TM_ARRAY(min_timearr, &wd->min_limit);
483 DATETIME_TM_ARRAY(max_timearr, &wd->max_limit);
485 for (idx = 0; idx < field->type; idx++)
486 if (*curr_timearr[idx] > *min_timearr[idx]) break;
487 if ((idx == field_type) && (min < *min_timearr[field_type]))
488 min = *min_timearr[field_type];
489 if (field_type == ELM_DATETIME_DATE)
491 max_days = _max_days_get(wd->curr_time.tm_year, wd->curr_time.tm_mon);
492 if (max > max_days) max = max_days;
494 for (idx = 0; idx < field->type; idx++)
495 if (*curr_timearr[idx] < *max_timearr[idx]) break;
496 if ((idx == field_type) && (max > *max_timearr[field_type]))
497 max = *max_timearr[field_type];
504 _field_list_display(Evas_Object *obj)
507 Datetime_Field *field;
510 wd = elm_widget_data_get(obj);
513 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
515 field = wd->field_list + idx;
516 if (field->fmt_exist && field->visible)
518 if ((dt_mod) && (dt_mod->field_value_display))
519 dt_mod->field_value_display(wd->mod_data, field->item_obj);
525 _field_list_arrange(Evas_Object *obj)
528 Datetime_Field *field;
529 char buf[BUFFER_SIZE];
532 wd = elm_widget_data_get(obj);
535 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
537 field = wd->field_list + idx;
538 edje_object_part_unswallow(wd->base, field->item_obj);
540 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
542 field = wd->field_list + idx;
543 if (field->visible && field->fmt_exist)
545 snprintf(buf, sizeof(buf), EDC_PART_FIELD_STR, field->location);
546 edje_object_part_swallow(wd->base, buf, field->item_obj);
548 else evas_object_hide(field->item_obj);
551 _field_list_display(obj);
554 // FIXME: provide nl_langinfo on Windows if possible
555 // returns expanded format string for corresponding multi-field format character
557 _expanded_fmt_str_get(char ch)
563 #ifdef HAVE_LANGINFO_H
564 exp_fmt = nl_langinfo(D_T_FMT);
570 #ifdef HAVE_LANGINFO_H
571 exp_fmt = nl_langinfo(D_FMT);
577 #ifdef HAVE_LANGINFO_H
578 exp_fmt = nl_langinfo(T_FMT);
584 #ifdef HAVE_LANGINFO_H
585 exp_fmt = nl_langinfo(T_FMT_AMPM);
594 exp_fmt = "%H:%M:%S";
597 exp_fmt = "%m/%d/%y";
600 exp_fmt = "%Y-%m-%d";
610 _expand_format(char * dt_fmt)
612 char *ptr, *expanded_fmt, ch;
613 char buf[MAX_FORMAT_LEN] = {0,};
614 unsigned int idx = 0, len = 0;
615 Eina_Bool fmt_char = EINA_FALSE;
620 if ((fmt_char) && (strchr(multifield_formats, ch)))
622 // replace the multi-field format characters with corresponding expanded format
623 expanded_fmt = _expanded_fmt_str_get(ch);
624 len = strlen(expanded_fmt);
626 strncat(buf, expanded_fmt, len);
629 else buf[idx++] = ch;
630 if (ch == '%') fmt_char = EINA_TRUE;
631 else fmt_char = EINA_FALSE;
635 strncpy(dt_fmt, buf, MAX_FORMAT_LEN);
639 _parse_format(Evas_Object *obj, char *fmt_ptr)
642 Datetime_Field *field = NULL;
643 unsigned int len = 0, idx, location = 0;
644 char separator[MAX_SEPARATOR_LEN];
646 Eina_Bool fmt_parsing = EINA_FALSE, sep_parsing = EINA_FALSE,
647 sep_lookup = EINA_FALSE;
649 wd = elm_widget_data_get(obj);
651 while ((cur = *fmt_ptr))
655 fmt_parsing = EINA_FALSE;
656 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
658 if (strchr(mapping[idx].fmt_char, cur))
660 field = wd->field_list + idx;
661 // ignore the fields already have or disabled
662 // valid formats, means already parsed & repeated, ignore.
663 if (!field->visible || field->location != -1) break;
665 field->fmt_exist = EINA_TRUE;
666 field->location = location++;
667 sep_lookup = EINA_TRUE;
675 fmt_parsing = EINA_TRUE;
676 sep_parsing = EINA_FALSE;
677 // set the separator to previous field
679 if (field) eina_stringshare_replace(&field->separator, separator);
681 if (sep_parsing && (len < MAX_SEPARATOR_LEN - 1) &&
682 (field->type != ELM_DATETIME_AMPM) &&
683 (!((field->type == ELM_DATETIME_MINUTE) && (cur ==':'))))
684 separator[len++] = cur;
685 if (sep_lookup) sep_parsing = EINA_TRUE;
686 sep_lookup = EINA_FALSE;
689 // return the number of valid fields parsed.
694 _reload_format(Evas_Object *obj)
697 Datetime_Field *field;
698 char buf[BUFFER_SIZE];
699 unsigned int idx, field_count;
702 wd = elm_widget_data_get(obj);
705 // FIXME: provide nl_langinfo on Windows if possible
706 // fetch the default format from Libc.
707 if (!wd->user_format)
708 #ifdef HAVE_LANGINFO_H
709 strncpy(wd->format, nl_langinfo(D_T_FMT), MAX_FORMAT_LEN);
711 strncpy(wd->format, "", MAX_FORMAT_LEN);
714 dt_fmt = (char *)malloc(MAX_FORMAT_LEN);
715 strncpy(dt_fmt, wd->format, MAX_FORMAT_LEN);
717 _expand_format(dt_fmt);
719 // reset all the fields to disable state
720 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
722 field = wd->field_list + idx;
723 field->fmt_exist = EINA_FALSE;
724 field->location = -1;
727 field_count = _parse_format(obj, dt_fmt);
730 // assign locations to disabled fields for uniform usage
731 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
733 field = wd->field_list + idx;
734 if (field->location == -1) field->location = field_count++;
736 if (field->fmt_exist && field->visible)
738 snprintf(buf, sizeof(buf), EDC_PART_FIELD_ENABLE_SIG_STR,
740 edje_object_signal_emit(wd->base, buf, "elm");
744 snprintf(buf, sizeof(buf),EDC_PART_FIELD_DISABLE_SIG_STR,
746 edje_object_signal_emit(wd->base, buf, "elm");
748 snprintf(buf, sizeof(buf), EDC_PART_SEPARATOR_STR, (field->location + 1));
749 edje_object_part_text_set(wd->base, buf, field->separator);
751 edje_object_message_signal_process(wd->base);
752 _field_list_arrange(obj);
756 _field_list_init(Evas_Object *obj)
759 Datetime_Field *field;
763 wd = elm_widget_data_get(obj);
767 localtime_r(&t, &wd->curr_time);
769 mapping[ELM_DATETIME_YEAR].def_min = _elm_config->year_min;
770 mapping[ELM_DATETIME_YEAR].def_max = _elm_config->year_max;
771 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
773 field = wd->field_list + idx;
774 field->type = ELM_DATETIME_YEAR + idx;
776 field->fmt_exist = EINA_FALSE;
777 field->visible = EINA_TRUE;
778 field->min = mapping[idx].def_min;
779 field->max = mapping[idx].def_max;
781 DATETIME_TM_ARRAY(min_timearr, &wd->min_limit);
782 DATETIME_TM_ARRAY(max_timearr, &wd->max_limit);
783 for (idx = 0; idx < DATETIME_TYPE_COUNT-1; idx++)
785 *min_timearr[idx] = mapping[idx].def_min;
786 *max_timearr[idx] = mapping[idx].def_max;
791 elm_datetime_add(Evas_Object *parent)
796 Datetime_Field *field;
799 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
801 ELM_SET_WIDTYPE(widtype, "datetime");
802 elm_widget_type_set(obj, widtype);
803 elm_widget_sub_object_add(parent, obj);
804 elm_widget_data_set(obj, wd);
805 elm_widget_del_hook_set(obj, _del_hook);
806 elm_widget_theme_hook_set(obj, _theme_hook);
807 elm_widget_translate_hook_set(obj, _translate_hook);
808 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
809 elm_widget_disable_hook_set(obj, _disable_hook);
810 elm_widget_can_focus_set(obj, EINA_TRUE);
811 elm_widget_focus_next_hook_set(obj, _elm_datetime_focus_next_hook);
813 wd->base = edje_object_add(e);
814 elm_widget_resize_object_set(obj, wd->base);
815 _elm_theme_object_set(obj, wd->base, "datetime", "base", "default");
816 evas_object_smart_callbacks_descriptions_set(obj, _signals);
818 // module - initialise module for datetime
819 if (!dt_mod) dt_mod = _dt_mod_init();
820 if ((dt_mod) && (dt_mod->obj_hook))
821 wd->mod_data = dt_mod->obj_hook(obj);
822 // update module data
825 wd->mod_data->base = obj;
826 wd->mod_data->field_limit_get = _field_limit_get;
827 wd->mod_data->field_format_get = _field_format_get;
830 _field_list_init(obj);
833 if ((dt_mod)&&(dt_mod->field_create))
835 for (idx = 0; idx < DATETIME_TYPE_COUNT; idx++)
837 field = wd->field_list + idx;
838 field->item_obj = dt_mod->field_create(wd->mod_data, idx);
841 _field_list_arrange(obj);
842 _mirrored_set(obj, elm_widget_mirrored_get(obj));
848 elm_datetime_format_get(const Evas_Object *obj)
850 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
853 wd = elm_widget_data_get(obj);
854 if (!wd) return NULL;
860 elm_datetime_format_set(Evas_Object *obj, const char *fmt)
862 ELM_CHECK_WIDTYPE(obj, widtype);
865 wd = elm_widget_data_get(obj);
870 strncpy(wd->format, fmt, MAX_FORMAT_LEN);
871 wd->user_format = EINA_TRUE;
874 wd->user_format = EINA_FALSE;
880 elm_datetime_field_visible_get(const Evas_Object *obj, Elm_Datetime_Field_Type
883 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
885 Datetime_Field *field;
887 wd = elm_widget_data_get(obj);
888 if (!wd || (fieldtype > ELM_DATETIME_AMPM)) return EINA_FALSE;
890 field = wd->field_list + fieldtype;
891 return field->visible;
895 elm_datetime_field_visible_set(Evas_Object *obj, Elm_Datetime_Field_Type fieldtype,
898 ELM_CHECK_WIDTYPE(obj, widtype);
900 Datetime_Field *field;
902 wd = elm_widget_data_get(obj);
903 if (!wd || (fieldtype > ELM_DATETIME_AMPM)) return;
905 field = wd->field_list + fieldtype;
906 if (field->visible == visible) return;
908 field->visible = visible;
913 elm_datetime_field_limit_get(const Evas_Object *obj, Elm_Datetime_Field_Type fieldtype,
916 ELM_CHECK_WIDTYPE(obj, widtype);
918 Datetime_Field *field;
920 wd = elm_widget_data_get(obj);
921 if (!wd || (fieldtype >= ELM_DATETIME_AMPM)) return;
923 field = wd->field_list + fieldtype;
924 if (min) *min = field->min;
925 if (max) *max = field->max;
929 elm_datetime_field_limit_set(Evas_Object *obj, Elm_Datetime_Field_Type fieldtype,
932 ELM_CHECK_WIDTYPE(obj, widtype);
934 Datetime_Field *field;
936 wd = elm_widget_data_get(obj);
937 if (!wd || (fieldtype >= ELM_DATETIME_AMPM)) return;
939 if (min > max) return;
941 field = wd->field_list + fieldtype;
942 if ((min > mapping[fieldtype].def_min && min < mapping[fieldtype].def_max)
943 || (field->type == ELM_DATETIME_YEAR))
945 if ((max > mapping[fieldtype].def_min && max < mapping[fieldtype].def_max)
946 || (field->type == ELM_DATETIME_YEAR))
949 _apply_field_limits(obj);
953 elm_datetime_value_get(const Evas_Object *obj, struct tm *currtime)
955 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
956 EINA_SAFETY_ON_NULL_RETURN_VAL(currtime, EINA_FALSE);
959 wd = elm_widget_data_get(obj);
960 if (!wd) return EINA_FALSE;
962 *currtime = wd->curr_time;
967 elm_datetime_value_set(Evas_Object *obj, const struct tm *newtime)
969 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
970 EINA_SAFETY_ON_NULL_RETURN_VAL(newtime, EINA_FALSE);
974 wd = elm_widget_data_get(obj);
975 if (!wd) return EINA_FALSE;
977 old_time = wd->curr_time;
978 wd->curr_time = *newtime;
979 // apply default field restrictions for curr_time
980 _apply_range_restrictions(obj, &wd->curr_time);
981 // validate the curr_time according to the min_limt and max_limt
982 _validate_datetime_limits(&wd->curr_time, &wd->min_limit, EINA_FALSE);
983 _validate_datetime_limits(&wd->max_limit, &wd->curr_time, EINA_TRUE);
984 _apply_field_limits(obj);
986 if (!_date_cmp(&old_time, &wd->curr_time))
987 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
993 elm_datetime_value_min_get(const Evas_Object *obj, struct tm *mintime)
995 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
996 EINA_SAFETY_ON_NULL_RETURN_VAL(mintime, EINA_FALSE);
999 wd = elm_widget_data_get(obj);
1000 if (!wd) return EINA_FALSE;
1002 *mintime = wd->min_limit;
1007 elm_datetime_value_min_set(Evas_Object *obj, const struct tm *mintime)
1009 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1010 EINA_SAFETY_ON_NULL_RETURN_VAL(mintime, EINA_FALSE);
1014 wd = elm_widget_data_get(obj);
1015 if (!wd) return EINA_FALSE;
1017 wd->min_limit = *mintime;
1018 old_time = wd->curr_time;
1019 // apply default field restrictions for min_limit
1020 _apply_range_restrictions(obj, &wd->min_limit);
1021 // validate curr_time and max_limt according to the min_limit
1022 _validate_datetime_limits(&wd->max_limit, &wd->min_limit, EINA_FALSE);
1023 _validate_datetime_limits(&wd->curr_time, &wd->min_limit, EINA_FALSE);
1024 _apply_field_limits(obj);
1026 if (!_date_cmp(&old_time, &wd->curr_time))
1027 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
1033 elm_datetime_value_max_get(const Evas_Object *obj, struct tm *maxtime)
1035 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1036 EINA_SAFETY_ON_NULL_RETURN_VAL(maxtime, EINA_FALSE);
1039 wd = elm_widget_data_get(obj);
1040 if (!wd) return EINA_FALSE;
1042 *maxtime = wd->max_limit;
1047 elm_datetime_value_max_set(Evas_Object *obj, const struct tm *maxtime)
1049 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1050 EINA_SAFETY_ON_NULL_RETURN_VAL(maxtime, EINA_FALSE);
1054 wd = elm_widget_data_get(obj);
1055 if (!wd) return EINA_FALSE;
1057 wd->max_limit = *maxtime;
1058 old_time = wd->curr_time;
1059 // apply default field restrictions for max_limit
1060 _apply_range_restrictions(obj, &wd->max_limit);
1061 // validate curr_time and min_limt according to the max_limit
1062 _validate_datetime_limits(&wd->max_limit, &wd->min_limit, EINA_TRUE);
1063 _validate_datetime_limits(&wd->max_limit, &wd->curr_time, EINA_TRUE);
1064 _apply_field_limits(obj);
1066 if (!_date_cmp(&old_time, &wd->curr_time))
1067 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);