1 #include <Elementary.h>
4 #ifdef HAVE_ELEMENTARY_X
7 # include <evil_langinfo.h>
11 * @defgroup Datefield Datefield
14 * This is a date editfield. it is used to input date and time using keypad
17 typedef struct _Widget_Data Widget_Data;
39 #define MONTH_MAXIMUM 12
40 #define HOUR_24H_MAXIMUM 23
41 #define HOUR_12H_MAXIMUM 12
42 #define MIN_MAXIMUM 59
43 #define YEAR_MAX_LENGTH 4
48 Evas_Object *time_ampm;
49 Evas_Object *ctxpopup;
50 Evas_Object *diskselector;
52 int year, month, day, hour, min;
53 int y_max, m_max, d_max;
54 int y_min, m_min, d_min;
55 int date_format,date_focusedpart;
57 Eina_Bool time_mode:1;
58 Eina_Bool format_exists:1;
59 Eina_Bool ctxpopup_show:1;
62 static const char *widtype = NULL;
64 static void _del_hook(Evas_Object *obj);
65 static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj);
66 static void _theme_hook(Evas_Object *obj);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _datefield_resize_cb(void *data, Evas *e __UNUSED__,
69 Evas_Object *obj, void *event_info __UNUSED__);
70 static void _ampm_clicked_cb(void *data, Evas_Object *obj, void *event_info);
71 static void _signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
72 const char *emission __UNUSED__,
74 static void _diskselector_cb(void *data, Evas_Object *obj __UNUSED__,
76 static void _datefield_focus_set(Evas_Object *data);
77 static int _maximum_day_get(int year, int month);
78 static int _check_date_boundary(Evas_Object *obj, int num, int flag);
79 static char* _get_i18n_string(Evas_Object *obj, nl_item item);
80 static void _date_update(Evas_Object *obj);
83 _del_hook(Evas_Object *obj)
85 Widget_Data *wd = elm_widget_data_get(obj);
92 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
94 Widget_Data *wd = elm_widget_data_get(obj);
96 if (!wd || !wd->base) return ;
100 _theme_hook(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
106 if (!wd || !wd->base) return;
108 if (wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME)
109 _elm_theme_object_set(obj, wd->base, "datefield", "dateandtime",
110 elm_widget_style_get(obj));
111 else if (wd->layout == ELM_DATEFIELD_LAYOUT_DATE)
112 _elm_theme_object_set(obj, wd->base, "datefield", "date",
113 elm_widget_style_get(obj));
114 else if (wd->layout == ELM_DATEFIELD_LAYOUT_TIME)
115 _elm_theme_object_set(obj, wd->base, "datefield", "time",
116 elm_widget_style_get(obj));
120 edje_object_part_unswallow(wd->base,wd->time_ampm);
121 evas_object_del(wd->time_ampm);
122 wd->time_ampm = NULL;
124 if ((wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME
125 || wd->layout == ELM_DATEFIELD_LAYOUT_TIME) && wd->time_mode)
127 wd->time_ampm = elm_button_add(obj);
128 elm_widget_sub_object_add(obj, wd->time_ampm);
129 edje_object_part_swallow(wd->base, "elm.swallow.time.ampm",
131 snprintf(buf,sizeof(buf),"datefield.ampm/%s",elm_widget_style_get(obj));
132 elm_object_style_set(wd->time_ampm, buf);
133 evas_object_size_hint_weight_set(wd->time_ampm, EVAS_HINT_EXPAND,
135 evas_object_size_hint_align_set(wd->time_ampm, EVAS_HINT_FILL,
137 evas_object_smart_callback_add(wd->time_ampm, "clicked",
138 _ampm_clicked_cb, obj);
141 edje_object_scale_set(wd->base,elm_widget_scale_get(obj)*_elm_config->scale);
144 if (wd->format_exists)
145 sprintf(sig, "elm,state,format,%s", elm_datefield_date_format_get(obj));
148 char *str = _get_i18n_string(obj, D_FMT);
151 if (!strcmp(str, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
152 else if (!strcmp(str, "yyddmm"))
153 wd->date_format = DATE_FORMAT_YYDDMM;
154 else if (!strcmp(str, "mmyydd"))
155 wd->date_format = DATE_FORMAT_MMYYDD;
156 else if (!strcmp(str, "mmddyy"))
157 wd->date_format = DATE_FORMAT_MMDDYY;
158 else if (!strcmp(str, "ddyymm"))
159 wd->date_format = DATE_FORMAT_DDYYMM;
160 else if (!strcmp(str, "ddmmyy"))
161 wd->date_format = DATE_FORMAT_DDMMYY;
162 sprintf(sig, "elm,state,format,%s",str);
166 edje_object_signal_emit(wd->base, sig, "elm");
167 edje_object_message_signal_process(wd->base);
174 _sizing_eval(Evas_Object *obj)
176 Widget_Data *wd = elm_widget_data_get(obj);
177 Evas_Coord minw = -1, minh = -1;
179 edje_object_size_min_calc(wd->base, &minw, &minh);
180 evas_object_size_hint_min_set(obj, minw, minh);
181 evas_object_size_hint_max_set(obj, -1, -1);
185 _datefield_resize_cb(void *data,Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
186 void *event_info __UNUSED__)
188 Widget_Data *wd = elm_widget_data_get(data);
190 if (!wd || !wd->base) return ;
192 Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
193 if (disk) evas_object_del(disk);
194 if (wd->ctxpopup_show)
195 wd->ctxpopup_show = EINA_FALSE;
196 evas_object_hide(wd->ctxpopup);
200 _ctxpopup_dismissed_cb(void *data, Evas_Object *obj __UNUSED__,
201 void *event_info __UNUSED__)
203 Widget_Data *wd = elm_widget_data_get(data);
205 if (!wd || !wd->base) return ;
207 Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
208 if (disk) evas_object_del(disk);
209 if (wd->ctxpopup_show)
210 wd->ctxpopup_show = EINA_FALSE;
212 switch (wd->date_focusedpart)
215 edje_object_signal_emit(wd->base, "elm,state,year,focus,out", "elm");
218 edje_object_signal_emit(wd->base, "elm,state,month,focus,out", "elm");
221 edje_object_signal_emit(wd->base, "elm,state,day,focus,out", "elm");
224 edje_object_signal_emit(wd->base, "elm,state,hour,focus,out", "elm");
227 edje_object_signal_emit(wd->base, "elm,state,min,focus,out", "elm");
233 _ampm_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
234 void *event_info __UNUSED__)
236 Widget_Data *wd = elm_widget_data_get(data);
239 if (!wd || !wd->base) return ;
244 str = _get_i18n_string(data, PM_STR);
247 elm_object_text_set(wd->time_ampm, str);
250 wd->hour += HOUR_12H_MAXIMUM;
254 str = _get_i18n_string(data, AM_STR);
257 elm_object_text_set(wd->time_ampm, str);
260 wd->hour -= HOUR_12H_MAXIMUM;
262 evas_object_smart_callback_call(data, "changed", NULL);
266 _signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
267 const char *emission __UNUSED__, const char *source)
269 Widget_Data *wd = elm_widget_data_get(data);
273 if (!strcmp(source, "elm.rect.date.year.over"))
274 wd->date_focusedpart = ENTRY_YEAR;
275 else if (!strcmp(source, "elm.rect.date.month.over"))
276 wd->date_focusedpart = ENTRY_MON;
277 else if (!strcmp(source, "elm.rect.date.day.over"))
278 wd->date_focusedpart = ENTRY_DAY;
279 else if (!strcmp(source, "elm.rect.time.hour.over"))
280 wd->date_focusedpart = ENTRY_HOUR;
281 else if (!strcmp(source, "elm.rect.time.min.over"))
282 wd->date_focusedpart = ENTRY_MIN;
284 _datefield_focus_set(data);
288 _diskselector_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
290 const char *label = elm_diskselector_item_label_get(
291 (Elm_Diskselector_Item *) event_info);
292 Widget_Data *wd = elm_widget_data_get(data);
293 int i=0, mon = 0, hour =0;
295 if (!wd || !wd->base) return;
299 if ((wd->date_focusedpart == ENTRY_YEAR) && (wd->year!=atoi(label)))
301 wd->year = _check_date_boundary(data, atoi(label), ENTRY_YEAR);
302 edje_object_signal_emit(wd->base,"elm,state,year,focus,out","elm");
305 else if (wd->date_focusedpart == ENTRY_MON)
307 char *month_list[] = {
308 E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"),
309 E_("May"), E_("Jun"), E_("Jul"), E_("Aug"),
310 E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
312 for (i=0; i <12; i++)
314 if (!(strcmp(month_list[i],label)))
315 mon = _check_date_boundary(data, i+1, ENTRY_MON);
317 if (wd->month != mon)
320 edje_object_signal_emit(wd->base, "elm,state,month,focus,out",
325 else if ((wd->date_focusedpart == ENTRY_DAY) && (wd->day!=atoi(label)))
327 wd->day = _check_date_boundary(data, atoi(label), ENTRY_DAY);
328 edje_object_signal_emit(wd->base,"elm,state,day,focus,out", "elm");
331 else if (wd->date_focusedpart == ENTRY_HOUR)
333 if ((wd->hour > 12)&& (wd->time_mode)&& (wd->pm))
334 hour = wd->hour - HOUR_12H_MAXIMUM;
337 if (hour!=atoi(label))
339 wd->hour = atoi(label);
340 edje_object_signal_emit(wd->base, "elm,state,hour,focus,out",
345 else if ((wd->date_focusedpart == ENTRY_MIN) && (wd->min!=atoi(label)))
347 wd->min = atoi(label);
348 edje_object_signal_emit(wd->base,"elm,state,min,focus,out", "elm");
351 evas_object_smart_callback_call(data, "changed", NULL);
356 _datefield_focus_set(Evas_Object *data)
358 Elm_Diskselector_Item *item = NULL;
359 Evas_Object *diskselector, *disk, *edj_part = NULL;
360 const char *item_list[138], *value = NULL;
361 int idx, count_start = 0, count_end = 0;
362 Evas_Coord x, y, w, h;
364 Widget_Data *wd = elm_widget_data_get(data);
365 if (!wd || !wd->base) return;
367 diskselector = elm_diskselector_add(elm_widget_top_get(data));
368 elm_object_style_set(diskselector, "extended/timepicker");
369 evas_object_size_hint_weight_set(diskselector, EVAS_HINT_EXPAND,
371 evas_object_size_hint_align_set(diskselector, EVAS_HINT_FILL,EVAS_HINT_FILL);
372 elm_diskselector_display_item_num_set(diskselector, 8);
373 elm_object_focus_allow_set(diskselector, EINA_FALSE);
374 elm_diskselector_side_label_lenght_set(diskselector, 4);
376 char *month_list[] = {
377 E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"), E_("May"), E_("Jun"),
378 E_("Jul"), E_("Aug"), E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
381 if (wd->date_focusedpart == ENTRY_YEAR)
383 edje_object_signal_emit(wd->base, "elm,state,year,focus,in", "elm");
384 value =(char *)edje_object_part_text_get(wd->base,"elm.text.date.year");
385 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
386 "elm.rect.date.year.over");
387 count_start = wd->y_min;
388 if (wd->y_max > wd->y_min)
389 count_end = wd->y_max ;
392 //Maximum limit is set for making it compatible with Calendar widget.
394 else if (wd->date_focusedpart == ENTRY_MON)
396 edje_object_signal_emit(wd->base, "elm,state,month,focus,in", "elm");
397 value=(char *)edje_object_part_text_get(wd->base,"elm.text.date.month");
398 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
399 "elm.rect.date.month.over");
401 count_end = MONTH_MAXIMUM - 1;
403 else if (wd->date_focusedpart == ENTRY_DAY)
405 edje_object_signal_emit(wd->base, "elm,state,day,focus,in", "elm");
406 value = (char *)edje_object_part_text_get(wd->base,"elm.text.date.day");
407 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
408 "elm.rect.date.day.over");
410 count_end = _maximum_day_get(wd->year, wd->month);
412 else if (wd->date_focusedpart == ENTRY_HOUR)
414 edje_object_signal_emit(wd->base, "elm,state,hour,focus,in", "elm");
415 value =(char *)edje_object_part_text_get(wd->base,"elm.text.time.hour");
416 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
417 "elm.rect.time.hour.over");
421 count_end = HOUR_12H_MAXIMUM ;
426 count_end = HOUR_24H_MAXIMUM ;
429 else if (wd->date_focusedpart == ENTRY_MIN)
431 edje_object_signal_emit(wd->base, "elm,state,min,focus,in", "elm");
432 value = (char *)edje_object_part_text_get(wd->base,"elm.text.time.min");
433 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
434 "elm.rect.time.min.over");
436 count_end = MIN_MAXIMUM;
438 if (wd->ctxpopup_show) return;
439 for (idx=count_start; idx<= count_end; idx++)
442 if (wd->date_focusedpart == ENTRY_MON)
443 snprintf(str, sizeof(str), month_list[idx]);
445 snprintf(str, sizeof(str), "%02d", idx);
446 item_list[idx] = eina_stringshare_add(str);
447 if (strcmp(value, item_list[idx]) == 0)
448 item = elm_diskselector_item_append(diskselector,item_list[idx],NULL,
449 _diskselector_cb, data);
451 elm_diskselector_item_append(diskselector, item_list[idx], NULL,
452 _diskselector_cb, data);
453 eina_stringshare_del(item_list[idx]);
455 elm_diskselector_round_set(diskselector, EINA_TRUE);
456 if(item != NULL) elm_diskselector_item_selected_set(item, EINA_TRUE);
458 disk = elm_ctxpopup_content_unset(wd->ctxpopup);
459 if (disk) evas_object_del(disk);
460 elm_ctxpopup_content_set(wd->ctxpopup, diskselector);
461 evas_object_show(wd->ctxpopup);
462 wd->ctxpopup_show = EINA_TRUE;
463 evas_object_geometry_get(edj_part, &x, &y, &w, &h);
464 evas_object_move(wd->ctxpopup, (x+w/2), (y+h) );
468 _maximum_day_get(int year, int month)
470 int day_of_month = 0;
471 if (year == 0 || month == 0) return 0;
483 if ((!(year % 4) && (year % 100)) || !(year % 400))
498 _check_date_boundary(Evas_Object *obj, int num, int flag)
500 Widget_Data *wd = elm_widget_data_get(obj);
501 if (flag == ENTRY_YEAR)
503 if ((num > wd->y_max)&&(wd->y_max > wd->y_min)) num = wd->y_max;
504 else if (num < wd->y_min) num = wd->y_min;
508 else if (flag == ENTRY_MON)
510 if (wd->year == wd->y_max && num > wd->m_max) num = wd->m_max;
511 else if (wd->year == wd->y_min && num < wd->m_min) num = wd->m_min;
512 else if (num > MONTH_MAXIMUM) num = MONTH_MAXIMUM;
513 else if (num <= 0) num = 1;
517 else if (flag == ENTRY_DAY)
519 int day_of_month = _maximum_day_get(wd->year, wd->month);
520 if (wd->year == wd->y_max && wd->month == wd->m_max && num > wd->d_max)
522 else if (wd->year == wd->y_min && wd->month == wd->m_min
523 && num < wd->d_min) num = wd->d_min;
524 else if (num > day_of_month) num = day_of_month;
525 else if (num <= 0) num = 1;
532 _get_i18n_string(Evas_Object *obj, nl_item item)
534 Widget_Data *wd = elm_widget_data_get(obj);
539 if (!wd) return NULL;
541 fmt = nl_langinfo(item);
542 if (!fmt) return NULL;
547 str = calloc(7, sizeof(char));
550 if (fmt[i] == '%' && fmt[i+1])
555 case 'Y': case 'M': case 'D': case 'y': case 'm': case 'd':
556 str[j++] = tolower(fmt[i]);
557 str[j++] = tolower(fmt[i]);
568 str = calloc(strlen(fmt)+1, sizeof(char));
573 str = calloc(3, sizeof(char));
574 if (item == AM_STR) strcpy(str, "AM");
575 else if (item == PM_STR) strcpy(str, "PM");
578 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5:
579 case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10:
580 case ABMON_11: case ABMON_12:
581 str = calloc(strlen(fmt)+1, sizeof(char));
585 if (fmt[i] >= '1' && fmt[i] <= '9')
587 if (fmt[i+1] >= '1' && fmt[i+1] <= '9')
599 _date_update(Evas_Object *obj)
601 Widget_Data *wd = elm_widget_data_get(obj);
602 Evas_Object *diskselector;
603 char str[YEAR_MAX_LENGTH+1] = {0,};
606 if (!wd || !wd->base) return;
608 sprintf(str, "%d", wd->year);
609 edje_object_part_text_set(wd->base, "elm.text.date.year", str);
611 i18n_str = _get_i18n_string(obj, ABMON_1+wd->month-1);
614 edje_object_part_text_set(wd->base, "elm.text.date.month", i18n_str);
618 sprintf(str, "%02d", wd->day);
619 edje_object_part_text_set(wd->base, "elm.text.date.day", str);
621 if (!wd->time_mode) //24 mode
622 sprintf(str, "%02d", wd->hour);
625 if (wd->hour >= HOUR_12H_MAXIMUM)
628 i18n_str = _get_i18n_string(obj, PM_STR);
629 if ((i18n_str)&&(wd->time_ampm))
631 elm_object_text_set(wd->time_ampm, i18n_str);
638 i18n_str = _get_i18n_string(obj, AM_STR);
639 if ((i18n_str)&&(wd->time_ampm))
641 elm_object_text_set(wd->time_ampm, i18n_str);
646 if (wd->hour > HOUR_12H_MAXIMUM)
647 sprintf(str, "%02d", wd->hour - HOUR_12H_MAXIMUM);
648 else if (wd->hour == 0)
649 sprintf(str, "%02d", HOUR_12H_MAXIMUM);
651 sprintf(str, "%02d", wd->hour);
653 edje_object_part_text_set(wd->base, "elm.text.time.hour", str);
654 sprintf(str, "%02d", wd->min);
655 edje_object_part_text_set(wd->base, "elm.text.time.min", str);
657 diskselector = elm_ctxpopup_content_unset(wd->ctxpopup);
658 if (diskselector) evas_object_del(diskselector);
659 evas_object_hide(wd->ctxpopup);
660 if (wd->ctxpopup_show)
661 wd->ctxpopup_show = EINA_FALSE;
666 * Add a new datefield object
667 * The date format and strings are based on current locale
669 * @param parent The parent object
670 * @return The new object or NULL if it cannot be created
675 elm_datefield_add(Evas_Object *parent)
682 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
684 e = evas_object_evas_get(parent);
686 wd = ELM_NEW(Widget_Data);
687 obj = elm_widget_add(e);
688 ELM_SET_WIDTYPE(widtype, "datefield");
689 elm_widget_type_set(obj, "datefield");
690 elm_widget_sub_object_add(parent, obj);
691 elm_widget_data_set(obj, wd);
692 elm_widget_del_hook_set(obj, _del_hook);
693 elm_widget_theme_hook_set(obj, _theme_hook);
694 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
695 elm_widget_can_focus_set(obj, EINA_TRUE);
697 wd->base = edje_object_add(e);
698 elm_widget_resize_object_set(obj, wd->base);
699 edje_object_signal_callback_add(wd->base, "mouse,down,1",
700 "elm.rect.date.year.over", _signal_rect_mouse_down, obj);
701 edje_object_signal_callback_add(wd->base, "mouse,down,1",
702 "elm.rect.date.month.over", _signal_rect_mouse_down, obj);
703 edje_object_signal_callback_add(wd->base, "mouse,down,1",
704 "elm.rect.date.day.over", _signal_rect_mouse_down, obj);
706 edje_object_signal_callback_add(wd->base, "mouse,down,1",
707 "elm.rect.time.hour.over", _signal_rect_mouse_down, obj);
708 edje_object_signal_callback_add(wd->base, "mouse,down,1",
709 "elm.rect.time.min.over", _signal_rect_mouse_down, obj);
711 wd->ctxpopup = elm_ctxpopup_add(elm_widget_top_get(obj));
712 snprintf(buf,sizeof(buf),"extended/timepicker/%s",elm_widget_style_get(obj));
713 elm_object_style_set(wd->ctxpopup, buf);
714 elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
715 elm_ctxpopup_direction_priority_set(wd->ctxpopup,ELM_CTXPOPUP_DIRECTION_DOWN,
716 ELM_CTXPOPUP_DIRECTION_UP,ELM_CTXPOPUP_DIRECTION_LEFT,
717 ELM_CTXPOPUP_DIRECTION_RIGHT);
718 evas_object_size_hint_weight_set(wd->ctxpopup, EVAS_HINT_EXPAND,
720 evas_object_size_hint_align_set(wd->ctxpopup, EVAS_HINT_FILL,EVAS_HINT_FILL);
721 elm_object_focus_allow_set(wd->ctxpopup, EINA_FALSE);
722 evas_object_smart_callback_add(wd->ctxpopup, "dismissed",
723 _ctxpopup_dismissed_cb, obj);
724 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
725 _datefield_resize_cb, obj);
733 wd->year = wd->y_min;
736 wd->ctxpopup_show = EINA_FALSE;
738 wd->layout = ELM_DATEFIELD_LAYOUT_DATEANDTIME;
739 wd->time_mode = EINA_TRUE;
747 * set layout for the datefield
749 * @param obj The datefield object
750 * @param layout set layout for date/time/dateandtime
751 * (default: ELM_DATEFIELD_LAYOUT_DATEANDTIME)
756 elm_datefield_layout_set(Evas_Object *obj, Elm_Datefield_Layout layout)
758 ELM_CHECK_WIDTYPE(obj, widtype);
759 Widget_Data *wd = elm_widget_data_get(obj);
762 if (layout > ELM_DATEFIELD_LAYOUT_DATEANDTIME) return;
764 if (wd->layout != layout)
768 edje_object_part_unswallow(wd->base,wd->time_ampm);
769 evas_object_del(wd->time_ampm);
770 wd->time_ampm = NULL;
779 * get layout of the datefield
781 * @param obj The datefield object
782 * @return layout of the datefield
786 EAPI Elm_Datefield_Layout
787 elm_datefield_layout_get(const Evas_Object *obj)
789 ELM_CHECK_WIDTYPE(obj, widtype) 0;
790 Widget_Data *wd = elm_widget_data_get(obj);
798 * Set selected date of the datefield
800 * @param obj The datefield object
801 * @param year The year to set
802 * @param month The month to set
803 * @param day The day to set
804 * @param hour The hours to set (24hour mode - 0~23)
805 * @param min The minutes to set (0~59)
810 elm_datefield_date_set(Evas_Object *obj, int year, int month, int day, int hour,
813 ELM_CHECK_WIDTYPE(obj, widtype);
814 Widget_Data *wd = elm_widget_data_get(obj);
818 wd->year = _check_date_boundary(obj, year, ENTRY_YEAR);
819 wd->month = _check_date_boundary(obj, month, ENTRY_MON);
820 wd->day = _check_date_boundary(obj, day, ENTRY_DAY);
822 if (hour > HOUR_24H_MAXIMUM) wd->hour = HOUR_24H_MAXIMUM;
823 else if (hour < 0) wd->hour = 0;
824 else wd->hour = hour;
826 if (min > MIN_MAXIMUM) wd->min = MIN_MAXIMUM;
827 else if (min < 0) wd->min = 0;
834 * Get selected date of the datefield
836 * @param obj The datefield object
837 * @param year The pointer to the variable get the selected year
838 * @param month The pointer to the variable get the selected month
839 * @param day The pointer to the variable get the selected day
840 * @param hour The pointer to the variable get the selected hour (24hour mode)
841 * @param hour The pointer to the variable get the selected min
846 elm_datefield_date_get(const Evas_Object *obj, int *year, int *month, int *day,
849 ELM_CHECK_WIDTYPE(obj, widtype);
850 Widget_Data *wd = elm_widget_data_get(obj);
867 * Set upper boundary of the datefield
869 * @param obj The datefield object
870 * @param year The year to set
871 * @param month The month to set
872 * @param day The day to set
878 elm_datefield_date_max_set(Evas_Object *obj, int year, int month, int day)
880 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
881 Widget_Data *wd = elm_widget_data_get(obj);
883 Eina_Bool update = EINA_FALSE;
885 if (!wd) return EINA_FALSE;
886 if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
887 day_of_month = _maximum_day_get(year, month);
888 if (day < 1 || day > day_of_month) return EINA_FALSE;
894 if (wd->year > wd->y_max)
896 wd->year = wd->y_max;
899 if (wd->year == wd->y_max && wd->month > wd->m_max)
901 wd->month = wd->m_max;
904 if (wd->year == wd->y_max && wd->month == wd->m_max && wd->day > wd->d_max)
910 if (update) _date_update(obj);
915 * Get upper boundary of the datefield
917 * @param obj The datefield object
918 * @param year The pointer to the variable get the maximum year
919 * @param month The pointer to the variable get the maximum month
920 * @param day The pointer to the variable get the maximum day
925 elm_datefield_date_max_get(const Evas_Object *obj, int *year, int *month,
928 ELM_CHECK_WIDTYPE(obj, widtype);
929 Widget_Data *wd = elm_widget_data_get(obj);
942 * Set lower boundary of the datefield
944 * @param obj The datefield object
945 * @param year The year to set
946 * @param month The month to set
947 * @param day The day to set
950 * @ingroup Datepicker
953 elm_datefield_date_min_set(Evas_Object *obj, int year, int month, int day)
955 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
956 Widget_Data *wd = elm_widget_data_get(obj);
958 Eina_Bool update = EINA_FALSE;
960 if (!wd) return EINA_FALSE;
961 if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
962 day_of_month = _maximum_day_get(year, month);
963 if (day < 1 || day > day_of_month) return EINA_FALSE;
969 if (wd->year < wd->y_min)
971 wd->year = wd->y_min;
974 if (wd->year == wd->y_min && wd->month < wd->m_min)
976 wd->month = wd->m_min;
979 if (wd->year == wd->y_min && wd->month == wd->m_min && wd->day < wd->d_min)
985 if (update) _date_update(obj);
990 * Get lower boundary of the datefield
992 * @param obj The datefield object
993 * @param year The pointer to the variable get the maximum year
994 * @param month The pointer to the variable get the maximum month
995 * @param day The pointer to the variable get the maximum day
1000 elm_datefield_date_min_get(const Evas_Object *obj, int *year, int *month,
1003 ELM_CHECK_WIDTYPE(obj, widtype);
1004 Widget_Data *wd = elm_widget_data_get(obj);
1017 * Set if the datefield show hours in military or am/pm mode
1019 * @param obj The datefield object
1020 * @param mode option for the hours mode. If true, it is shown as 12h mode,
1021 * if false, it is shown as 24h mode. Default value is true
1023 * @ingroup Datefield
1026 elm_datefield_time_mode_set(Evas_Object *obj, Eina_Bool mode)
1028 ELM_CHECK_WIDTYPE(obj, widtype);
1029 Widget_Data *wd = elm_widget_data_get(obj);
1033 if (wd->time_mode != mode)
1035 wd->time_mode = mode;
1036 if (!wd->time_mode) edje_object_signal_emit(wd->base, "elm,state,mode,24h",
1038 else edje_object_signal_emit(wd->base, "elm,state,mode,12h", "elm");
1039 edje_object_message_signal_process(wd->base);
1045 * get time mode of the datefield
1047 * @param obj The datefield object
1048 * @return time mode (EINA_TRUE: 12hour mode / EINA_FALSE: 24hour mode)
1050 * @ingroup Datefield
1053 elm_datefield_time_mode_get(const Evas_Object *obj)
1055 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1056 Widget_Data *wd = elm_widget_data_get(obj);
1058 if (!wd) return EINA_FALSE;
1060 return wd->time_mode;
1064 * Set date format of datefield
1066 * @param obj The datefield object
1067 * @param fmt The date format, ex) yymmdd. Default value is mmddyy.
1069 * @ingroup Datefield
1072 elm_datefield_date_format_set(Evas_Object *obj, const char *fmt)
1074 ELM_CHECK_WIDTYPE(obj, widtype);
1075 Widget_Data *wd = elm_widget_data_get(obj);
1076 char sig[32] = "elm,state,format,";
1079 if (!wd || !fmt) return;
1084 sig[j++] = tolower(fmt[i++]);
1086 if (j < 32) sig[j] = '\0';
1087 edje_object_signal_emit(wd->base, sig, "elm");
1088 edje_object_message_signal_process(wd->base);
1090 if (strstr(sig, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
1091 else if (strstr(sig, "yyddmm")) wd->date_format = DATE_FORMAT_YYDDMM;
1092 else if (strstr(sig, "mmyydd")) wd->date_format = DATE_FORMAT_MMYYDD;
1093 else if (strstr(sig, "mmddyy")) wd->date_format = DATE_FORMAT_MMDDYY;
1094 else if (strstr(sig, "ddyymm")) wd->date_format = DATE_FORMAT_DDYYMM;
1095 else if (strstr(sig, "ddmmyy")) wd->date_format = DATE_FORMAT_DDMMYY;
1096 wd->format_exists = EINA_TRUE;
1100 * get date format of the datefield
1102 * @param obj The datefield object
1103 * @return date format string. ex) yymmdd
1105 * @ingroup Datefield
1108 elm_datefield_date_format_get(const Evas_Object *obj)
1110 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1111 Widget_Data *wd = elm_widget_data_get(obj);
1113 switch (wd->date_format)
1115 case DATE_FORMAT_YYMMDD: return "yymmdd";
1116 case DATE_FORMAT_YYDDMM: return "yyddmm";
1117 case DATE_FORMAT_MMYYDD: return "mmyydd";
1118 case DATE_FORMAT_MMDDYY: return "mmddyy";
1119 case DATE_FORMAT_DDYYMM: return "ddyymm";
1120 case DATE_FORMAT_DDMMYY: return "ddmmyy";
1121 default: return NULL;
1126 * Add a callback function for input panel state
1128 * @param obj The datefield object
1129 * @param func The function to be called when the event is triggered
1130 * (value will be the Ecore_IMF_Input_Panel_State)
1131 * @param data The data pointer to be passed to @p func
1133 * @ingroup Datefield
1136 elm_datefield_input_panel_state_callback_add(Evas_Object *obj,
1137 void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value),
1140 // This API will be no more in use after the redesigning of datefield widget
1141 //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
1142 // API will be deprecated soon.
1143 printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_add "
1144 "will be deprecated soon \n#####\n");
1148 * Delete a callback function for input panel state
1150 * @param obj The datefield object
1151 * @param func The function to be called when the event is triggered
1153 * @ingroup Datefield
1156 elm_datefield_input_panel_state_callback_del(Evas_Object *obj,
1157 void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value))
1159 // This API will be no more in use after the redesigning of datefield widget
1160 //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
1161 // API will be deprecated soon.
1162 printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_del"
1163 "will be deprecated soon \n#####\n");