1 #include <Elementary.h>
6 * @defgroup Datefield Datefield
9 * This is a date editfield. it is used to input date and time using keypad
12 typedef struct _Widget_Data Widget_Data;
34 #define MONTH_MAXIMUM 12
35 #define HOUR_24H_MAXIMUM 23
36 #define HOUR_12H_MAXIMUM 12
37 #define MIN_MAXIMUM 59
38 #define YEAR_MAX_LENGTH 4
43 Evas_Object *time_ampm;
44 Evas_Object *ctxpopup;
45 Evas_Object *diskselector;
47 int year, month, day, hour, min;
48 int y_max, m_max, d_max;
49 int y_min, m_min, d_min;
50 int date_format,date_focusedpart;
52 Eina_Bool time_mode:1;
53 Eina_Bool format_exists:1;
54 Eina_Bool ctxpopup_show:1;
57 static const char *widtype = NULL;
59 static void _del_hook(Evas_Object *obj);
60 static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj);
61 static void _theme_hook(Evas_Object *obj);
62 static void _sizing_eval(Evas_Object *obj);
63 static void _datefield_resize_cb(void *data, Evas *e __UNUSED__,
64 Evas_Object *obj, void *event_info __UNUSED__);
65 static void _ampm_clicked_cb(void *data, Evas_Object *obj, void *event_info);
66 static void _signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
67 const char *emission __UNUSED__,
69 static void _diskselector_cb(void *data, Evas_Object *obj __UNUSED__,
71 static void _datefield_focus_set(Evas_Object *data);
72 static int _maximum_day_get(int year, int month);
73 static int _check_date_boundary(Evas_Object *obj, int num, int flag);
74 static char* _get_i18n_string(Evas_Object *obj, nl_item item);
75 static void _date_update(Evas_Object *obj);
78 _del_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
87 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
89 Widget_Data *wd = elm_widget_data_get(obj);
91 if (!wd || !wd->base) return ;
95 _theme_hook(Evas_Object *obj)
97 Widget_Data *wd = elm_widget_data_get(obj);
101 if (!wd || !wd->base) return;
103 if (wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME)
104 _elm_theme_object_set(obj, wd->base, "datefield", "dateandtime",
105 elm_widget_style_get(obj));
106 else if (wd->layout == ELM_DATEFIELD_LAYOUT_DATE)
107 _elm_theme_object_set(obj, wd->base, "datefield", "date",
108 elm_widget_style_get(obj));
109 else if (wd->layout == ELM_DATEFIELD_LAYOUT_TIME)
110 _elm_theme_object_set(obj, wd->base, "datefield", "time",
111 elm_widget_style_get(obj));
115 edje_object_part_unswallow(wd->base,wd->time_ampm);
116 evas_object_del(wd->time_ampm);
117 wd->time_ampm = NULL;
119 if ((wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME
120 || wd->layout == ELM_DATEFIELD_LAYOUT_TIME) && wd->time_mode)
122 wd->time_ampm = elm_button_add(obj);
123 elm_widget_sub_object_add(obj, wd->time_ampm);
124 edje_object_part_swallow(wd->base, "elm.swallow.time.ampm",
126 snprintf(buf,sizeof(buf),"datefield.ampm/%s",elm_widget_style_get(obj));
127 elm_object_style_set(wd->time_ampm, buf);
128 evas_object_size_hint_weight_set(wd->time_ampm, EVAS_HINT_EXPAND,
130 evas_object_size_hint_align_set(wd->time_ampm, EVAS_HINT_FILL,
132 evas_object_smart_callback_add(wd->time_ampm, "clicked",
133 _ampm_clicked_cb, obj);
136 edje_object_scale_set(wd->base,elm_widget_scale_get(obj)*_elm_config->scale);
139 if (wd->format_exists)
140 sprintf(sig, "elm,state,format,%s", elm_datefield_date_format_get(obj));
143 char *str = _get_i18n_string(obj, D_FMT);
146 if (!strcmp(str, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
147 else if (!strcmp(str, "yyddmm"))
148 wd->date_format = DATE_FORMAT_YYDDMM;
149 else if (!strcmp(str, "mmyydd"))
150 wd->date_format = DATE_FORMAT_MMYYDD;
151 else if (!strcmp(str, "mmddyy"))
152 wd->date_format = DATE_FORMAT_MMDDYY;
153 else if (!strcmp(str, "ddyymm"))
154 wd->date_format = DATE_FORMAT_DDYYMM;
155 else if (!strcmp(str, "ddmmyy"))
156 wd->date_format = DATE_FORMAT_DDMMYY;
157 sprintf(sig, "elm,state,format,%s",str);
161 edje_object_signal_emit(wd->base, sig, "elm");
168 _sizing_eval(Evas_Object *obj)
170 Widget_Data *wd = elm_widget_data_get(obj);
171 Evas_Coord minw = -1, minh = -1;
173 edje_object_size_min_calc(wd->base, &minw, &minh);
174 evas_object_size_hint_min_set(obj, minw, minh);
175 evas_object_size_hint_max_set(obj, -1, -1);
179 _datefield_resize_cb(void *data,Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
180 void *event_info __UNUSED__)
182 Widget_Data *wd = elm_widget_data_get(data);
184 if (!wd || !wd->base) return ;
186 Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
187 if (disk) evas_object_del(disk);
188 if (wd->ctxpopup_show)
189 wd->ctxpopup_show = EINA_FALSE;
190 evas_object_hide(wd->ctxpopup);
194 _ctxpopup_dismissed_cb(void *data, Evas_Object *obj __UNUSED__,
195 void *event_info __UNUSED__)
197 Widget_Data *wd = elm_widget_data_get(data);
199 if (!wd || !wd->base) return ;
201 Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
202 if (disk) evas_object_del(disk);
203 if (wd->ctxpopup_show)
204 wd->ctxpopup_show = EINA_FALSE;
206 switch (wd->date_focusedpart)
209 edje_object_signal_emit(wd->base, "elm,state,year,focus,out", "elm");
212 edje_object_signal_emit(wd->base, "elm,state,month,focus,out", "elm");
215 edje_object_signal_emit(wd->base, "elm,state,day,focus,out", "elm");
218 edje_object_signal_emit(wd->base, "elm,state,hour,focus,out", "elm");
221 edje_object_signal_emit(wd->base, "elm,state,min,focus,out", "elm");
227 _ampm_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
228 void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
233 if (!wd || !wd->base) return ;
238 str = _get_i18n_string(data, PM_STR);
241 elm_object_text_set(wd->time_ampm, str);
244 wd->hour += HOUR_12H_MAXIMUM;
248 str = _get_i18n_string(data, AM_STR);
251 elm_object_text_set(wd->time_ampm, str);
254 wd->hour -= HOUR_12H_MAXIMUM;
256 evas_object_smart_callback_call(data, "changed", NULL);
260 _signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
261 const char *emission __UNUSED__, const char *source)
263 Widget_Data *wd = elm_widget_data_get(data);
267 if (!strcmp(source, "elm.rect.date.year.over"))
268 wd->date_focusedpart = ENTRY_YEAR;
269 else if (!strcmp(source, "elm.rect.date.month.over"))
270 wd->date_focusedpart = ENTRY_MON;
271 else if (!strcmp(source, "elm.rect.date.day.over"))
272 wd->date_focusedpart = ENTRY_DAY;
273 else if (!strcmp(source, "elm.rect.time.hour.over"))
274 wd->date_focusedpart = ENTRY_HOUR;
275 else if (!strcmp(source, "elm.rect.time.min.over"))
276 wd->date_focusedpart = ENTRY_MIN;
278 _datefield_focus_set(data);
282 _diskselector_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
284 const char *label = elm_diskselector_item_label_get(
285 (Elm_Diskselector_Item *) event_info);
286 Widget_Data *wd = elm_widget_data_get(data);
287 int i=0, mon = 0, hour =0;
289 if (!wd || !wd->base) return;
293 if ((wd->date_focusedpart == ENTRY_YEAR) && (wd->year!=atoi(label)))
295 wd->year = _check_date_boundary(data, atoi(label), ENTRY_YEAR);
296 edje_object_signal_emit(wd->base,"elm,state,year,focus,out","elm");
299 else if (wd->date_focusedpart == ENTRY_MON)
301 char *month_list[] = {
302 E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"),
303 E_("May"), E_("Jun"), E_("Jul"), E_("Aug"),
304 E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
306 for (i=0; i <12; i++)
308 if (!(strcmp(month_list[i],label)))
309 mon = _check_date_boundary(data, i+1, ENTRY_MON);
311 if (wd->month != mon)
314 edje_object_signal_emit(wd->base, "elm,state,month,focus,out",
319 else if ((wd->date_focusedpart == ENTRY_DAY) && (wd->day!=atoi(label)))
321 wd->day = _check_date_boundary(data, atoi(label), ENTRY_DAY);
322 edje_object_signal_emit(wd->base,"elm,state,day,focus,out", "elm");
325 else if (wd->date_focusedpart == ENTRY_HOUR)
327 if ((wd->hour > 12)&& (wd->time_mode)&& (wd->pm))
328 hour = wd->hour - HOUR_12H_MAXIMUM;
331 if (hour!=atoi(label))
333 wd->hour = atoi(label);
334 edje_object_signal_emit(wd->base, "elm,state,hour,focus,out",
339 else if ((wd->date_focusedpart == ENTRY_MIN) && (wd->min!=atoi(label)))
341 wd->min = atoi(label);
342 edje_object_signal_emit(wd->base,"elm,state,min,focus,out", "elm");
345 evas_object_smart_callback_call(data, "changed", NULL);
350 _datefield_focus_set(Evas_Object *data)
352 Elm_Diskselector_Item *item = NULL;
353 Evas_Object *diskselector, *disk, *edj_part = NULL;
354 const char *item_list[138], *value = NULL;
355 int idx, count_start = 0, count_end = 0;
356 Evas_Coord x, y, w, h;
358 Widget_Data *wd = elm_widget_data_get(data);
359 if (!wd || !wd->base) return;
361 diskselector = elm_diskselector_add(elm_widget_top_get(data));
362 elm_object_style_set(diskselector, "extended/timepicker");
363 evas_object_size_hint_weight_set(diskselector, EVAS_HINT_EXPAND,
365 evas_object_size_hint_align_set(diskselector, EVAS_HINT_FILL,EVAS_HINT_FILL);
366 elm_diskselector_display_item_num_set(diskselector, 8);
367 elm_object_focus_allow_set(diskselector, EINA_FALSE);
368 elm_diskselector_side_label_lenght_set(diskselector, 4);
370 char *month_list[] = {
371 E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"), E_("May"), E_("Jun"),
372 E_("Jul"), E_("Aug"), E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
375 if (wd->date_focusedpart == ENTRY_YEAR)
377 edje_object_signal_emit(wd->base, "elm,state,year,focus,in", "elm");
378 value =(char *)edje_object_part_text_get(wd->base,"elm.text.date.year");
379 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
380 "elm.rect.date.year.over");
381 count_start = wd->y_min;
382 if (wd->y_max > wd->y_min)
383 count_end = wd->y_max ;
386 //Maximum limit is set for making it compatible with Calendar widget.
388 else if (wd->date_focusedpart == ENTRY_MON)
390 edje_object_signal_emit(wd->base, "elm,state,month,focus,in", "elm");
391 value=(char *)edje_object_part_text_get(wd->base,"elm.text.date.month");
392 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
393 "elm.rect.date.month.over");
395 count_end = MONTH_MAXIMUM - 1;
397 else if (wd->date_focusedpart == ENTRY_DAY)
399 edje_object_signal_emit(wd->base, "elm,state,day,focus,in", "elm");
400 value = (char *)edje_object_part_text_get(wd->base,"elm.text.date.day");
401 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
402 "elm.rect.date.day.over");
404 count_end = _maximum_day_get(wd->year, wd->month);
406 else if (wd->date_focusedpart == ENTRY_HOUR)
408 edje_object_signal_emit(wd->base, "elm,state,hour,focus,in", "elm");
409 value =(char *)edje_object_part_text_get(wd->base,"elm.text.time.hour");
410 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
411 "elm.rect.time.hour.over");
415 count_end = HOUR_12H_MAXIMUM ;
420 count_end = HOUR_24H_MAXIMUM ;
423 else if (wd->date_focusedpart == ENTRY_MIN)
425 edje_object_signal_emit(wd->base, "elm,state,min,focus,in", "elm");
426 value = (char *)edje_object_part_text_get(wd->base,"elm.text.time.min");
427 edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
428 "elm.rect.time.min.over");
430 count_end = MIN_MAXIMUM;
432 if (wd->ctxpopup_show) return;
433 for (idx=count_start; idx<= count_end; idx++)
436 if (wd->date_focusedpart == ENTRY_MON)
437 snprintf(str, sizeof(str), month_list[idx]);
439 snprintf(str, sizeof(str), "%02d", idx);
440 item_list[idx] = eina_stringshare_add(str);
441 if (strcmp(value, item_list[idx]) == 0)
442 item = elm_diskselector_item_append(diskselector,item_list[idx],NULL,
443 _diskselector_cb, data);
445 elm_diskselector_item_append(diskselector, item_list[idx], NULL,
446 _diskselector_cb, data);
447 eina_stringshare_del(item_list[idx]);
449 elm_diskselector_round_set(diskselector, EINA_TRUE);
450 if(item != NULL) elm_diskselector_item_selected_set(item, EINA_TRUE);
452 disk = elm_ctxpopup_content_unset(wd->ctxpopup);
453 if (disk) evas_object_del(disk);
454 elm_ctxpopup_content_set(wd->ctxpopup, diskselector);
455 evas_object_show(wd->ctxpopup);
456 wd->ctxpopup_show = EINA_TRUE;
457 evas_object_geometry_get(edj_part, &x, &y, &w, &h);
458 evas_object_move(wd->ctxpopup, (x+w/2), (y+h) );
462 _maximum_day_get(int year, int month)
464 int day_of_month = 0;
465 if (year == 0 || month == 0) return 0;
477 if ((!(year % 4) && (year % 100)) || !(year % 400))
492 _check_date_boundary(Evas_Object *obj, int num, int flag)
494 Widget_Data *wd = elm_widget_data_get(obj);
495 if (flag == ENTRY_YEAR)
497 if ((num > wd->y_max)&&(wd->y_max > wd->y_min)) num = wd->y_max;
498 else if (num < wd->y_min) num = wd->y_min;
502 else if (flag == ENTRY_MON)
504 if (wd->year == wd->y_max && num > wd->m_max) num = wd->m_max;
505 else if (wd->year == wd->y_min && num < wd->m_min) num = wd->m_min;
506 else if (num > MONTH_MAXIMUM) num = MONTH_MAXIMUM;
507 else if (num <= 0) num = 1;
511 else if (flag == ENTRY_DAY)
513 int day_of_month = _maximum_day_get(wd->year, wd->month);
514 if (wd->year == wd->y_max && wd->month == wd->m_max && num > wd->d_max)
516 else if (wd->year == wd->y_min && wd->month == wd->m_min
517 && num < wd->d_min) num = wd->d_min;
518 else if (num > day_of_month) num = day_of_month;
519 else if (num <= 0) num = 1;
526 _get_i18n_string(Evas_Object *obj, nl_item item)
528 Widget_Data *wd = elm_widget_data_get(obj);
533 if (!wd) return NULL;
535 fmt = nl_langinfo(item);
536 if (!fmt) return NULL;
541 str = calloc(7, sizeof(char));
544 if (fmt[i] == '%' && fmt[i+1])
549 case 'Y': case 'M': case 'D': case 'y': case 'm': case 'd':
550 str[j++] = tolower(fmt[i]);
551 str[j++] = tolower(fmt[i]);
562 str = calloc(strlen(fmt)+1, sizeof(char));
567 str = calloc(3, sizeof(char));
568 if (item == AM_STR) strcpy(str, "AM");
569 else if (item == PM_STR) strcpy(str, "PM");
572 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5:
573 case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10:
574 case ABMON_11: case ABMON_12:
575 str = calloc(strlen(fmt)+1, sizeof(char));
579 if (fmt[i] >= '1' && fmt[i] <= '9')
581 if (fmt[i+1] >= '1' && fmt[i+1] <= '9')
593 _date_update(Evas_Object *obj)
595 Widget_Data *wd = elm_widget_data_get(obj);
596 Evas_Object *diskselector;
597 char str[YEAR_MAX_LENGTH+1] = {0,};
600 if (!wd || !wd->base) return;
602 sprintf(str, "%d", wd->year);
603 edje_object_part_text_set(wd->base, "elm.text.date.year", str);
605 i18n_str = _get_i18n_string(obj, ABMON_1+wd->month-1);
608 edje_object_part_text_set(wd->base, "elm.text.date.month", i18n_str);
612 sprintf(str, "%02d", wd->day);
613 edje_object_part_text_set(wd->base, "elm.text.date.day", str);
615 if (!wd->time_mode) //24 mode
616 sprintf(str, "%02d", wd->hour);
619 if (wd->hour >= HOUR_12H_MAXIMUM)
622 i18n_str = _get_i18n_string(obj, PM_STR);
623 if ((i18n_str)&&(wd->time_ampm))
625 elm_object_text_set(wd->time_ampm, i18n_str);
632 i18n_str = _get_i18n_string(obj, AM_STR);
633 if ((i18n_str)&&(wd->time_ampm))
635 elm_object_text_set(wd->time_ampm, i18n_str);
640 if (wd->hour > HOUR_12H_MAXIMUM)
641 sprintf(str, "%02d", wd->hour - HOUR_12H_MAXIMUM);
642 else if (wd->hour == 0)
643 sprintf(str, "%02d", HOUR_12H_MAXIMUM);
645 sprintf(str, "%02d", wd->hour);
647 edje_object_part_text_set(wd->base, "elm.text.time.hour", str);
648 sprintf(str, "%02d", wd->min);
649 edje_object_part_text_set(wd->base, "elm.text.time.min", str);
651 diskselector = elm_ctxpopup_content_unset(wd->ctxpopup);
652 if (diskselector) evas_object_del(diskselector);
653 evas_object_hide(wd->ctxpopup);
654 if (wd->ctxpopup_show)
655 wd->ctxpopup_show = EINA_FALSE;
660 * Add a new datefield object
661 * The date format and strings are based on current locale
663 * @param parent The parent object
664 * @return The new object or NULL if it cannot be created
669 elm_datefield_add(Evas_Object *parent)
676 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
678 e = evas_object_evas_get(parent);
680 wd = ELM_NEW(Widget_Data);
681 obj = elm_widget_add(e);
682 ELM_SET_WIDTYPE(widtype, "datefield");
683 elm_widget_type_set(obj, "datefield");
684 elm_widget_sub_object_add(parent, obj);
685 elm_widget_data_set(obj, wd);
686 elm_widget_del_hook_set(obj, _del_hook);
687 elm_widget_theme_hook_set(obj, _theme_hook);
688 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
689 elm_widget_can_focus_set(obj, EINA_TRUE);
691 wd->base = edje_object_add(e);
692 elm_widget_resize_object_set(obj, wd->base);
693 edje_object_signal_callback_add(wd->base, "mouse,down,1",
694 "elm.rect.date.year.over", _signal_rect_mouse_down, obj);
695 edje_object_signal_callback_add(wd->base, "mouse,down,1",
696 "elm.rect.date.month.over", _signal_rect_mouse_down, obj);
697 edje_object_signal_callback_add(wd->base, "mouse,down,1",
698 "elm.rect.date.day.over", _signal_rect_mouse_down, obj);
700 edje_object_signal_callback_add(wd->base, "mouse,down,1",
701 "elm.rect.time.hour.over", _signal_rect_mouse_down, obj);
702 edje_object_signal_callback_add(wd->base, "mouse,down,1",
703 "elm.rect.time.min.over", _signal_rect_mouse_down, obj);
705 wd->ctxpopup = elm_ctxpopup_add(elm_widget_top_get(obj));
706 snprintf(buf,sizeof(buf),"extended/timepicker/%s",elm_widget_style_get(obj));
707 elm_object_style_set(wd->ctxpopup, buf);
708 elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
709 elm_ctxpopup_direction_priority_set(wd->ctxpopup,ELM_CTXPOPUP_DIRECTION_DOWN,
710 ELM_CTXPOPUP_DIRECTION_UP,ELM_CTXPOPUP_DIRECTION_LEFT,
711 ELM_CTXPOPUP_DIRECTION_RIGHT);
712 evas_object_size_hint_weight_set(wd->ctxpopup, EVAS_HINT_EXPAND,
714 evas_object_size_hint_align_set(wd->ctxpopup, EVAS_HINT_FILL,EVAS_HINT_FILL);
715 elm_object_focus_allow_set(wd->ctxpopup, EINA_FALSE);
716 evas_object_smart_callback_add(wd->ctxpopup, "dismissed",
717 _ctxpopup_dismissed_cb, obj);
718 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
719 _datefield_resize_cb, obj);
727 wd->year = wd->y_min;
730 wd->ctxpopup_show = EINA_FALSE;
732 wd->layout = ELM_DATEFIELD_LAYOUT_DATEANDTIME;
733 wd->time_mode = EINA_TRUE;
741 * set layout for the datefield
743 * @param obj The datefield object
744 * @param layout set layout for date/time/dateandtime
745 * (default: ELM_DATEFIELD_LAYOUT_DATEANDTIME)
750 elm_datefield_layout_set(Evas_Object *obj, Elm_Datefield_Layout layout)
752 ELM_CHECK_WIDTYPE(obj, widtype);
753 Widget_Data *wd = elm_widget_data_get(obj);
756 if (layout > ELM_DATEFIELD_LAYOUT_DATEANDTIME) return;
758 if (wd->layout != layout)
762 edje_object_part_unswallow(wd->base,wd->time_ampm);
763 evas_object_del(wd->time_ampm);
764 wd->time_ampm = NULL;
773 * get layout of the datefield
775 * @param obj The datefield object
776 * @return layout of the datefield
780 EAPI Elm_Datefield_Layout
781 elm_datefield_layout_get(const Evas_Object *obj)
783 ELM_CHECK_WIDTYPE(obj, widtype) 0;
784 Widget_Data *wd = elm_widget_data_get(obj);
792 * Set selected date of the datefield
794 * @param obj The datefield object
795 * @param year The year to set
796 * @param month The month to set
797 * @param day The day to set
798 * @param hour The hours to set (24hour mode - 0~23)
799 * @param min The minutes to set (0~59)
804 elm_datefield_date_set(Evas_Object *obj, int year, int month, int day, int hour,
807 ELM_CHECK_WIDTYPE(obj, widtype);
808 Widget_Data *wd = elm_widget_data_get(obj);
812 wd->year = _check_date_boundary(obj, year, ENTRY_YEAR);
813 wd->month = _check_date_boundary(obj, month, ENTRY_MON);
814 wd->day = _check_date_boundary(obj, day, ENTRY_DAY);
816 if (hour > HOUR_24H_MAXIMUM) wd->hour = HOUR_24H_MAXIMUM;
817 else if (hour < 0) wd->hour = 0;
818 else wd->hour = hour;
820 if (min > MIN_MAXIMUM) wd->min = MIN_MAXIMUM;
821 else if (min < 0) wd->min = 0;
828 * Get selected date of the datefield
830 * @param obj The datefield object
831 * @param year The pointer to the variable get the selected year
832 * @param month The pointer to the variable get the selected month
833 * @param day The pointer to the variable get the selected day
834 * @param hour The pointer to the variable get the selected hour (24hour mode)
835 * @param hour The pointer to the variable get the selected min
840 elm_datefield_date_get(const Evas_Object *obj, int *year, int *month, int *day,
843 ELM_CHECK_WIDTYPE(obj, widtype);
844 Widget_Data *wd = elm_widget_data_get(obj);
861 * Set upper boundary of the datefield
863 * @param obj The datefield object
864 * @param year The year to set
865 * @param month The month to set
866 * @param day The day to set
872 elm_datefield_date_max_set(Evas_Object *obj, int year, int month, int day)
874 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
875 Widget_Data *wd = elm_widget_data_get(obj);
877 Eina_Bool update = EINA_FALSE;
879 if (!wd) return EINA_FALSE;
880 if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
881 day_of_month = _maximum_day_get(year, month);
882 if (day < 1 || day > day_of_month) return EINA_FALSE;
888 if (wd->year > wd->y_max)
890 wd->year = wd->y_max;
893 if (wd->year == wd->y_max && wd->month > wd->m_max)
895 wd->month = wd->m_max;
898 if (wd->year == wd->y_max && wd->month == wd->m_max && wd->day > wd->d_max)
904 if (update) _date_update(obj);
909 * Get upper boundary of the datefield
911 * @param obj The datefield object
912 * @param year The pointer to the variable get the maximum year
913 * @param month The pointer to the variable get the maximum month
914 * @param day The pointer to the variable get the maximum day
919 elm_datefield_date_max_get(const Evas_Object *obj, int *year, int *month,
922 ELM_CHECK_WIDTYPE(obj, widtype);
923 Widget_Data *wd = elm_widget_data_get(obj);
936 * Set lower boundary of the datefield
938 * @param obj The datefield object
939 * @param year The year to set
940 * @param month The month to set
941 * @param day The day to set
944 * @ingroup Datepicker
947 elm_datefield_date_min_set(Evas_Object *obj, int year, int month, int day)
949 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
950 Widget_Data *wd = elm_widget_data_get(obj);
952 Eina_Bool update = EINA_FALSE;
954 if (!wd) return EINA_FALSE;
955 if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
956 day_of_month = _maximum_day_get(year, month);
957 if (day < 1 || day > day_of_month) return EINA_FALSE;
963 if (wd->year < wd->y_min)
965 wd->year = wd->y_min;
968 if (wd->year == wd->y_min && wd->month < wd->m_min)
970 wd->month = wd->m_min;
973 if (wd->year == wd->y_min && wd->month == wd->m_min && wd->day < wd->d_min)
979 if (update) _date_update(obj);
984 * Get lower boundary of the datefield
986 * @param obj The datefield object
987 * @param year The pointer to the variable get the maximum year
988 * @param month The pointer to the variable get the maximum month
989 * @param day The pointer to the variable get the maximum day
994 elm_datefield_date_min_get(const Evas_Object *obj, int *year, int *month,
997 ELM_CHECK_WIDTYPE(obj, widtype);
998 Widget_Data *wd = elm_widget_data_get(obj);
1011 * Set if the datefield show hours in military or am/pm mode
1013 * @param obj The datefield object
1014 * @param mode option for the hours mode. If true, it is shown as 12h mode,
1015 * if false, it is shown as 24h mode. Default value is true
1017 * @ingroup Datefield
1020 elm_datefield_time_mode_set(Evas_Object *obj, Eina_Bool mode)
1022 ELM_CHECK_WIDTYPE(obj, widtype);
1023 Widget_Data *wd = elm_widget_data_get(obj);
1027 if (wd->time_mode != mode)
1029 wd->time_mode = mode;
1030 if (!wd->time_mode) edje_object_signal_emit(wd->base, "elm,state,mode,24h",
1032 else edje_object_signal_emit(wd->base, "elm,state,mode,12h", "elm");
1038 * get time mode of the datefield
1040 * @param obj The datefield object
1041 * @return time mode (EINA_TRUE: 12hour mode / EINA_FALSE: 24hour mode)
1043 * @ingroup Datefield
1046 elm_datefield_time_mode_get(const Evas_Object *obj)
1048 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1049 Widget_Data *wd = elm_widget_data_get(obj);
1051 if (!wd) return EINA_FALSE;
1053 return wd->time_mode;
1057 * Set date format of datefield
1059 * @param obj The datefield object
1060 * @param fmt The date format, ex) yymmdd. Default value is mmddyy.
1062 * @ingroup Datefield
1065 elm_datefield_date_format_set(Evas_Object *obj, const char *fmt)
1067 ELM_CHECK_WIDTYPE(obj, widtype);
1068 Widget_Data *wd = elm_widget_data_get(obj);
1069 char sig[32] = "elm,state,format,";
1072 if (!wd || !fmt) return;
1077 sig[j++] = tolower(fmt[i++]);
1079 if (j < 32) sig[j] = '\0';
1080 edje_object_signal_emit(wd->base, sig, "elm");
1082 if (strstr(sig, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
1083 else if (strstr(sig, "yyddmm")) wd->date_format = DATE_FORMAT_YYDDMM;
1084 else if (strstr(sig, "mmyydd")) wd->date_format = DATE_FORMAT_MMYYDD;
1085 else if (strstr(sig, "mmddyy")) wd->date_format = DATE_FORMAT_MMDDYY;
1086 else if (strstr(sig, "ddyymm")) wd->date_format = DATE_FORMAT_DDYYMM;
1087 else if (strstr(sig, "ddmmyy")) wd->date_format = DATE_FORMAT_DDMMYY;
1088 wd->format_exists = EINA_TRUE;
1092 * get date format of the datefield
1094 * @param obj The datefield object
1095 * @return date format string. ex) yymmdd
1097 * @ingroup Datefield
1100 elm_datefield_date_format_get(const Evas_Object *obj)
1102 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1103 Widget_Data *wd = elm_widget_data_get(obj);
1105 switch (wd->date_format)
1107 case DATE_FORMAT_YYMMDD: return "yymmdd";
1108 case DATE_FORMAT_YYDDMM: return "yyddmm";
1109 case DATE_FORMAT_MMYYDD: return "mmyydd";
1110 case DATE_FORMAT_MMDDYY: return "mmddyy";
1111 case DATE_FORMAT_DDYYMM: return "ddyymm";
1112 case DATE_FORMAT_DDMMYY: return "ddmmyy";
1113 default: return NULL;
1118 * Add a callback function for input panel state
1120 * @param obj The datefield object
1121 * @param func The function to be called when the event is triggered
1122 * (value will be the Ecore_IMF_Input_Panel_State)
1123 * @param data The data pointer to be passed to @p func
1125 * @ingroup Datefield
1128 elm_datefield_input_panel_state_callback_add(Evas_Object *obj,
1129 void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value),
1132 // This API will be no more in use after the redesigning of datefield widget
1133 //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
1134 // API will be deprecated soon.
1135 printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_add "
1136 "will be deprecated soon \n#####\n");
1140 * Delete a callback function for input panel state
1142 * @param obj The datefield object
1143 * @param func The function to be called when the event is triggered
1145 * @ingroup Datefield
1148 elm_datefield_input_panel_state_callback_del(Evas_Object *obj,
1149 void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value))
1151 // This API will be no more in use after the redesigning of datefield widget
1152 //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
1153 // API will be deprecated soon.
1154 printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_del"
1155 "will be deprecated soon \n#####\n");