+#include <locale.h>
#include <Elementary.h>
#include "elm_priv.h"
-#ifdef HAVE_ELEMENTARY_X
-# include <langinfo.h>
-#else
-# include <evil_langinfo.h>
-#endif
-
/**
* @defgroup Datefield Datefield
* @ingroup Elementary
*
- * This is a date editfield. it is used to input date and time using keypad
+ * This is a date edit field. it is used to input date and time using
+ * diskselector integrated ctxpopup.
+ *
+ * Datefield Format can be like "%b %d, %Y %I : %M %p".
+ * Maximum allowed format length is 32 chars.
+ * Format can include separators for each individual datefield item.
+ * Each separator can be a maximum of 6 UTF-8 bytes.
+ * Space is also taken as a separator.
+ * Following are the allowed set of format specifiers for each datefield item.
+ * These specifiers can be arranged at any order as per user requirement and
+ * their value will be replaced in the format as mentioned below.
+ * %Y : The year as a decimal number including the century.
+ * %y : The year as a decimal number without a century (range 00 to 99)
+ * %m : The month as a decimal number (range 01 to 12).
+ * %b : The abbreviated month name according to the current locale.
+ * %B : The full month name according to the current locale.
+ * %d : The day of the month as a decimal number (range 01 to 31).
+ * %I : The hour as a decimal number using a 12-hour clock (range 01 to 12).
+ * %H : The hour as a decimal number using a 24-hour clock (range 00 to 23).
+ * %k : The hour (24-hour clock) as a decimal number (range 0 to 23). single
+ * digits are preceded by a blank.
+ * %l : The hour (12-hour clock) as a decimal number (range 1 to 12); single
+ * digits are preceded by a blank.
+ * %M : The minute as a decimal number (range 00 to 59).
+ * %p : Either 'AM' or 'PM' according to the given time value, or the
+ * corresponding strings for the current locale. Noon is treated as 'PM'
+ * and midnight as 'AM'
+ * %P : Like %p but in lowercase: 'am' or 'pm' or a corresponding string for
+ * the current locale.
+ * For more reference, see the below link:
+ * http://www.gnu.org/s/hello/manual/libc.html#Formatting-Calendar-Time
+ * Default format is taken as per the system display language and Region format.
+ *
*/
typedef struct _Widget_Data Widget_Data;
-enum
+#define DATEFIELD_TYPE_COUNT 6
+#define BUFFER_SIZE 64
+#define MAX_FORMAT_LEN 32
+#define MAX_SEPARATOR_LEN 6
+#define MAX_ITEM_FORMAT_LEN 3
+#define DISKSELECTOR_ITEMS_NUM_MIN 4
+
+// Interface between EDC & C code. Item names & signal names.
+// Values 0 to 6 are valid range, can be substituted for %d.
+#define EDC_DATEFIELD_ENABLE_SIG_STR "elm,state,enabled"
+#define EDC_DATEFIELD_DISABLE_SIG_STR "elm,state,disabled"
+#define EDC_DATEFIELD_FOCUSIN_SIG_STR "elm,action,focus"
+#define EDC_DATEFIELD_FOCUSOUT_SIG_STR "elm,action,unfocus"
+#define EDC_PART_ITEM_STR "item%d"
+#define EDC_PART_SEPARATOR_STR "separator%d"
+#define EDC_PART_ITEM_OVER_STR "item%d.over"
+#define EDC_PART_ITEM_ENABLE_SIG_STR "item%d,enable"
+#define EDC_PART_ITEM_DISABLE_SIG_STR "item%d,disable"
+#define EDC_PART_ITEM_FOCUSIN_SIG_STR "item%d,focus,in"
+#define EDC_PART_ITEM_FOCUSOUT_SIG_STR "item%d,focus,out"
+#define EDC_PART_ITEM_STYLE_DEFAULT_SIG_STR "item%d,style,default"
+#define EDC_PART_ITEM_STYLE_AMPM_SIG_STR "item%d,style,ampm"
+
+#define DEFAULT_FORMAT "%b %d, %Y %I : %M %p"
+
+typedef struct _Format_Map
{
- DATE_FORMAT_YYMMDD,
- DATE_FORMAT_YYDDMM,
- DATE_FORMAT_MMYYDD,
- DATE_FORMAT_MMDDYY,
- DATE_FORMAT_DDYYMM,
- DATE_FORMAT_DDMMYY,
- DATE_FORMAT_MAX
+ Elm_Datefield_ItemType type;
+ char fmt_char[5];
+ int def_min;
+ int def_max;
+}Format_Map;
+
+static const Format_Map mapping[DATEFIELD_TYPE_COUNT] = {
+ { ELM_DATEFIELD_YEAR, "Yy", 70, 137 },
+ { ELM_DATEFIELD_MONTH, "mbB", 0, 11 },
+ { ELM_DATEFIELD_DATE, "d", 1, 31 },
+ { ELM_DATEFIELD_HOUR, "IHkl", 0, 23 },
+ { ELM_DATEFIELD_MINUTE, "M", 0, 59 },
+ { ELM_DATEFIELD_AMPM, "pP", 0, 1 }
};
-enum
-{
- ENTRY_YEAR,
- ENTRY_MON,
- ENTRY_DAY,
- ENTRY_HOUR,
- ENTRY_MIN
-};
+static int _days_in_month[12] = { 31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31 };
+
+typedef enum _Elm_Datefield_HourType
+ {
+ ELM_DATEFIELD_HOUR_12 = 1000,
+ ELM_DATEFIELD_HOUR_24,
+ ELM_DATEFIELD_HOUR_NA
+ } Elm_Datefield_HourType;
-#define MONTH_MAXIMUM 12
-#define HOUR_24H_MAXIMUM 23
-#define HOUR_12H_MAXIMUM 12
-#define MIN_MAXIMUM 59
-#define YEAR_MAX_LENGTH 4
+
+typedef struct _Datefield_Item
+{
+ char fmt[MAX_ITEM_FORMAT_LEN];
+ Elm_Datefield_ItemType type;
+ Elm_Datefield_HourType hour_type;
+ const char *content; //string to be displayed
+ const char *separator;
+ int location; //location of the item as per the current format
+ int *value;
+ int min, max;
+ int default_min, default_max;
+ Eina_Bool fmt_exist:1; //if item format is present or not
+ Eina_Bool enabled:1; //if item is to be shown or not
+ Eina_Bool abs_min:1;
+ Eina_Bool abs_max:1;
+} Datefield_Item;
struct _Widget_Data
{
Evas_Object *base;
- Evas_Object *time_ampm;
+ struct tm *time;
+ int ampm;
+ Datefield_Item *item_list; //Fixed set of items, so no Eina list.
Evas_Object *ctxpopup;
- Evas_Object *diskselector;
- unsigned int layout;
- int year, month, day, hour, min;
- int y_max, m_max, d_max;
- int y_min, m_min, d_min;
- int date_format,date_focusedpart;
- Eina_Bool pm:1;
- Eina_Bool time_mode:1;
- Eina_Bool format_exists:1;
- Eina_Bool ctxpopup_show:1;
+ Datefield_Item *selected_it;
+ char format[MAX_FORMAT_LEN];
+ Eina_Bool user_format:1; //whether user set format or the default format.
};
+typedef struct _DiskItem_Data
+{
+ Evas_Object *datefield;
+ unsigned int sel_item_value;
+} DiskItem_Data;
+
static const char *widtype = NULL;
static void _del_hook(Evas_Object *obj);
static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj);
-static void _theme_hook(Evas_Object *obj);
+static void _disable_hook(Evas_Object *obj);
+static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
static void _sizing_eval(Evas_Object *obj);
-static void _datefield_resize_cb(void *data, Evas *e __UNUSED__,
- Evas_Object *obj, void *event_info __UNUSED__);
-static void _ampm_clicked_cb(void *data, Evas_Object *obj, void *event_info);
-static void _signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
- const char *emission __UNUSED__,
- const char *source);
+static void _theme_hook(Evas_Object *obj);
+static void _ctxpopup_dismissed_cb(void *data, Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__);
+static void _datefield_resize_cb(void *data, Evas *e __UNUSED__,Evas_Object *obj
+ __UNUSED__, void *event_info __UNUSED__);
+static void _datefield_move_cb(void *data, Evas *e __UNUSED__,Evas_Object *obj
+ __UNUSED__, void *event_info __UNUSED__);
+
+static void _update_items(Evas_Object *obj);
+static void _field_value_set(Evas_Object * obj, Elm_Datefield_ItemType type,
+ int value, Eina_Bool adjust_time);
static void _diskselector_cb(void *data, Evas_Object *obj __UNUSED__,
- void *event_info);
-static void _datefield_focus_set(Evas_Object *data);
-static int _maximum_day_get(int year, int month);
-static int _check_date_boundary(Evas_Object *obj, int num, int flag);
-static char* _get_i18n_string(Evas_Object *obj, nl_item item);
-static void _date_update(Evas_Object *obj);
+ void *event_info __UNUSED__);
+static void _ampm_clicked (void *data);
+static void _diskselector_item_free_cb(void *data, Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__);
+static void _load_field_options(Evas_Object * data, Evas_Object *diskselector,
+ Datefield_Item *it);
+static void _datefield_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
+ const char *emission __UNUSED__, const char *source);
+static void _format_reload(Evas_Object *obj);
+static void _item_list_init(Evas_Object *obj);
+
+static const char SIG_CHANGED[] = "changed";
+static const Evas_Smart_Cb_Description _signals[] = {
+ {SIG_CHANGED, ""},
+ {NULL, NULL}
+};
static void
_del_hook(Evas_Object *obj)
{
- Widget_Data *wd = elm_widget_data_get(obj);
-
- if (!wd) return ;
- free(wd);
-}
+ Widget_Data *wd;
+ Datefield_Item *tmp;
+ unsigned int idx;
-static void
-_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
-{
- Widget_Data *wd = elm_widget_data_get(obj);
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ if (wd->time) free(wd->time);
+ for (idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
+ {
+ tmp = wd->item_list + idx;
+ eina_stringshare_replace(&tmp->content, NULL);
+ eina_stringshare_replace(&tmp->separator, NULL);
+ }
+ if (wd->item_list) free(wd->item_list);
+ evas_object_del(wd->ctxpopup);
- if (!wd || !wd->base) return ;
+ free(wd);
}
static void
-_theme_hook(Evas_Object *obj)
+_disable_hook(Evas_Object *obj)
{
- Widget_Data *wd = elm_widget_data_get(obj);
- char sig[32] = {0,};
- char buf[1024];
+ Widget_Data *wd;
+ wd = elm_widget_data_get(obj);
if (!wd || !wd->base) return;
-
- if (wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME)
- _elm_theme_object_set(obj, wd->base, "datefield", "dateandtime",
- elm_widget_style_get(obj));
- else if (wd->layout == ELM_DATEFIELD_LAYOUT_DATE)
- _elm_theme_object_set(obj, wd->base, "datefield", "date",
- elm_widget_style_get(obj));
- else if (wd->layout == ELM_DATEFIELD_LAYOUT_TIME)
- _elm_theme_object_set(obj, wd->base, "datefield", "time",
- elm_widget_style_get(obj));
-
- if (wd->time_ampm)
- {
- edje_object_part_unswallow(wd->base,wd->time_ampm);
- evas_object_del(wd->time_ampm);
- wd->time_ampm = NULL;
- }
- if ((wd->layout == ELM_DATEFIELD_LAYOUT_DATEANDTIME
- || wd->layout == ELM_DATEFIELD_LAYOUT_TIME) && wd->time_mode)
+ if (elm_widget_disabled_get(obj))
{
- wd->time_ampm = elm_button_add(obj);
- elm_widget_sub_object_add(obj, wd->time_ampm);
- edje_object_part_swallow(wd->base, "elm.swallow.time.ampm",
- wd->time_ampm);
- snprintf(buf,sizeof(buf),"datefield.ampm/%s",elm_widget_style_get(obj));
- elm_object_style_set(wd->time_ampm, buf);
- evas_object_size_hint_weight_set(wd->time_ampm, EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(wd->time_ampm, EVAS_HINT_FILL,
- EVAS_HINT_FILL);
- evas_object_smart_callback_add(wd->time_ampm, "clicked",
- _ampm_clicked_cb, obj);
+ evas_object_hide(wd->ctxpopup);
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_DISABLE_SIG_STR,"elm");
}
+ else
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_ENABLE_SIG_STR, "elm");
+}
- edje_object_scale_set(wd->base,elm_widget_scale_get(obj)*_elm_config->scale);
+static void
+_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
+{
+ Widget_Data *wd;
- //set date format
- if (wd->format_exists)
- sprintf(sig, "elm,state,format,%s", elm_datefield_date_format_get(obj));
+ wd = elm_widget_data_get(obj);
+ if (!wd ) return;
+ if (elm_widget_focus_get(obj))
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_FOCUSIN_SIG_STR, "elm");
else
- {
- char *str = _get_i18n_string(obj, D_FMT);
- if (str)
- {
- if (!strcmp(str, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
- else if (!strcmp(str, "yyddmm"))
- wd->date_format = DATE_FORMAT_YYDDMM;
- else if (!strcmp(str, "mmyydd"))
- wd->date_format = DATE_FORMAT_MMYYDD;
- else if (!strcmp(str, "mmddyy"))
- wd->date_format = DATE_FORMAT_MMDDYY;
- else if (!strcmp(str, "ddyymm"))
- wd->date_format = DATE_FORMAT_DDYYMM;
- else if (!strcmp(str, "ddmmyy"))
- wd->date_format = DATE_FORMAT_DDMMYY;
- sprintf(sig, "elm,state,format,%s",str);
- free(str);
- }
- }
- edje_object_signal_emit(wd->base, sig, "elm");
- edje_object_message_signal_process(wd->base);
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_FOCUSOUT_SIG_STR, "elm");
+}
- _date_update(obj);
- _sizing_eval(obj);
+static void
+_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
+{
+ Widget_Data *wd;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ evas_object_hide(wd->ctxpopup);
+ edje_object_mirrored_set(wd->base, rtl);
}
static void
_sizing_eval(Evas_Object *obj)
{
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
Evas_Coord minw = -1, minh = -1;
+ wd = elm_widget_data_get(obj);
+ if (!wd || !wd->base) return;
edje_object_size_min_calc(wd->base, &minw, &minh);
evas_object_size_hint_min_set(obj, minw, minh);
evas_object_size_hint_max_set(obj, -1, -1);
}
static void
-_datefield_resize_cb(void *data,Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
- void *event_info __UNUSED__)
+_theme_hook(Evas_Object *obj)
{
- Widget_Data *wd = elm_widget_data_get(data);
+ Widget_Data *wd;
+ Datefield_Item *it;
+ char buf[BUFFER_SIZE];
+ unsigned int idx;
+ //Evas_Object *diskselector;
- if (!wd || !wd->base) return ;
+ wd = elm_widget_data_get(obj);
+ if (!wd || !wd->base) return;
+ _elm_theme_object_set(obj, wd->base, "datefield", "base",
+ elm_widget_style_get(obj));
+ _elm_widget_mirrored_reload(obj);
+ _mirrored_set(obj, elm_widget_mirrored_get(obj));
- Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
- if (disk) evas_object_del(disk);
- if (wd->ctxpopup_show)
- wd->ctxpopup_show = EINA_FALSE;
- evas_object_hide(wd->ctxpopup);
+ snprintf(buf, sizeof(buf), "datefield/%s", elm_object_style_get(obj));
+ elm_object_style_set(wd->ctxpopup, buf);
+ /*//Enabled once elm_object_content_get() API comes to git.
+ if (diskselector = elm_object_content_get(wd->ctxpopup))
+ elm_object_style_set(diskselector, buf);*/
+ edje_object_scale_set(wd->base,elm_widget_scale_get(obj)*_elm_config->scale);
+
+ if (elm_widget_disabled_get(obj))
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_DISABLE_SIG_STR,"elm");
+ else
+ edje_object_signal_emit(wd->base, EDC_DATEFIELD_ENABLE_SIG_STR, "elm");
+
+ for (idx= 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
+ {
+ it = wd->item_list + idx;
+ if (it->fmt_exist && it->enabled )
+ {
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STR, it->location);
+ edje_object_part_text_set(wd->base, buf, it->content);
+ snprintf(buf, sizeof(buf), EDC_PART_SEPARATOR_STR, it->location);
+ edje_object_part_text_set(wd->base, buf, it->separator);
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_ENABLE_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ if (it->type == ELM_DATEFIELD_AMPM)
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STYLE_AMPM_SIG_STR,
+ it->location);
+ else
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STYLE_DEFAULT_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ }
+ else
+ {
+ snprintf(buf, sizeof(buf),EDC_PART_ITEM_DISABLE_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ }
+ }
+ edje_object_message_signal_process(wd->base);
+ _sizing_eval(obj);
}
static void
_ctxpopup_dismissed_cb(void *data, Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
- Widget_Data *wd = elm_widget_data_get(data);
-
- if (!wd || !wd->base) return ;
+ Widget_Data *wd;
+ Evas_Object *diskselector;
+ char buf[BUFFER_SIZE];
- Evas_Object *disk = elm_ctxpopup_content_unset(wd->ctxpopup);
- if (disk) evas_object_del(disk);
- if (wd->ctxpopup_show)
- wd->ctxpopup_show = EINA_FALSE;
+ wd = elm_widget_data_get(data);
+ if (!wd || !wd->base) return;
+ diskselector = elm_ctxpopup_content_unset(wd->ctxpopup);
+ if (diskselector) evas_object_del(diskselector);
- switch (wd->date_focusedpart)
+ if (wd->selected_it)
{
- case ENTRY_YEAR:
- edje_object_signal_emit(wd->base, "elm,state,year,focus,out", "elm");
- break;
- case ENTRY_MON:
- edje_object_signal_emit(wd->base, "elm,state,month,focus,out", "elm");
- break;
- case ENTRY_DAY:
- edje_object_signal_emit(wd->base, "elm,state,day,focus,out", "elm");
- break;
- case ENTRY_HOUR:
- edje_object_signal_emit(wd->base, "elm,state,hour,focus,out", "elm");
- break;
- case ENTRY_MIN:
- edje_object_signal_emit(wd->base, "elm,state,min,focus,out", "elm");
- break;
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_FOCUSOUT_SIG_STR,
+ wd->selected_it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ wd->selected_it = NULL;
}
}
static void
-_ampm_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
- void *event_info __UNUSED__)
+_datefield_resize_cb(void *data, Evas *e __UNUSED__,Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__)
{
- Widget_Data *wd = elm_widget_data_get(data);
- char *str;
-
- if (!wd || !wd->base) return ;
+ Widget_Data *wd;
- wd->pm = !wd->pm;
- if (wd->pm)
- {
- str = _get_i18n_string(data, PM_STR);
- if (str)
- {
- elm_object_text_set(wd->time_ampm, str);
- free(str);
- }
- wd->hour += HOUR_12H_MAXIMUM;
- }
- else
- {
- str = _get_i18n_string(data, AM_STR);
- if (str)
- {
- elm_object_text_set(wd->time_ampm, str);
- free(str);
- }
- wd->hour -= HOUR_12H_MAXIMUM;
- }
- evas_object_smart_callback_call(data, "changed", NULL);
+ wd = elm_widget_data_get(data);
+ if (!wd) return;
+ evas_object_hide(wd->ctxpopup);
}
static void
-_signal_rect_mouse_down(void *data, Evas_Object *obj __UNUSED__,
- const char *emission __UNUSED__, const char *source)
+_datefield_move_cb(void *data, Evas *e __UNUSED__,Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__)
{
- Widget_Data *wd = elm_widget_data_get(data);
+ Widget_Data *wd;
+ wd = elm_widget_data_get(data);
if (!wd) return;
-
- if (!strcmp(source, "elm.rect.date.year.over"))
- wd->date_focusedpart = ENTRY_YEAR;
- else if (!strcmp(source, "elm.rect.date.month.over"))
- wd->date_focusedpart = ENTRY_MON;
- else if (!strcmp(source, "elm.rect.date.day.over"))
- wd->date_focusedpart = ENTRY_DAY;
- else if (!strcmp(source, "elm.rect.time.hour.over"))
- wd->date_focusedpart = ENTRY_HOUR;
- else if (!strcmp(source, "elm.rect.time.min.over"))
- wd->date_focusedpart = ENTRY_MIN;
-
- _datefield_focus_set(data);
+ evas_object_hide(wd->ctxpopup);
}
static void
-_diskselector_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
+_contextual_field_limit_get(Evas_Object * obj, Datefield_Item * it,
+ Eina_Bool hr_fmt_check, int *range_min, int *range_max)
{
- const char *label = elm_diskselector_item_label_get(
- (Elm_Diskselector_Item *) event_info);
- Widget_Data *wd = elm_widget_data_get(data);
- int i=0, mon = 0, hour =0;
+ Widget_Data *wd;
+ Datefield_Item * tmp;
+ unsigned int idx;
+ int ctx_max;
+ Eina_Bool min_limit = EINA_TRUE;
+ Eina_Bool max_limit = EINA_TRUE;
- if (!wd || !wd->base) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || !it) return;
- if (label)
- {
- if ((wd->date_focusedpart == ENTRY_YEAR) && (wd->year!=atoi(label)))
- {
- wd->year = _check_date_boundary(data, atoi(label), ENTRY_YEAR);
- edje_object_signal_emit(wd->base,"elm,state,year,focus,out","elm");
- _date_update(data);
- }
- else if (wd->date_focusedpart == ENTRY_MON)
- {
- char *month_list[] = {
- E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"),
- E_("May"), E_("Jun"), E_("Jul"), E_("Aug"),
- E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
- };
- for (i=0; i <12; i++)
- {
- if (!(strcmp(month_list[i],label)))
- mon = _check_date_boundary(data, i+1, ENTRY_MON);
- }
- if (wd->month != mon)
- {
- wd->month = mon;
- edje_object_signal_emit(wd->base, "elm,state,month,focus,out",
- "elm");
- _date_update(data);
- }
- }
- else if ((wd->date_focusedpart == ENTRY_DAY) && (wd->day!=atoi(label)))
+ //Top to down check for current field relative min/max limit
+ if (!it->abs_min || !it->abs_max )
+ {
+ for (idx = ELM_DATEFIELD_YEAR; idx < it->type; idx++)
{
- wd->day = _check_date_boundary(data, atoi(label), ENTRY_DAY);
- edje_object_signal_emit(wd->base,"elm,state,day,focus,out", "elm");
- _date_update(data);
+ tmp = wd->item_list + idx;
+ if (max_limit && (*(tmp->value) < tmp->max)) max_limit= EINA_FALSE;
+ if (min_limit && (*(tmp->value) > tmp->min)) min_limit= EINA_FALSE;
}
- else if (wd->date_focusedpart == ENTRY_HOUR)
+ }
+
+ if (it->abs_min || min_limit) (*range_min) = it->min;
+ else (*range_min) = it->default_min;
+
+ if (it->abs_max || max_limit) (*range_max) = it->max;
+ else (*range_max) = it->default_max;
+
+ ctx_max = it->default_max;
+ if (it->type == ELM_DATEFIELD_DATE )
+ {
+ ctx_max = _days_in_month[wd->time->tm_mon];
+ // Check for Leap year Feb.
+ if (__isleap((wd->time->tm_year)) && wd->time->tm_mon == 1) ctx_max= 29;
+ }
+ else if (it->type == ELM_DATEFIELD_HOUR && hr_fmt_check &&
+ it->hour_type == ELM_DATEFIELD_HOUR_12 ) ctx_max = 11;
+
+ if (*range_max > ctx_max) *range_max = ctx_max;
+}
+
+static void
+_update_items(Evas_Object *obj)
+{
+ Widget_Data *wd;
+ Datefield_Item *it;
+ char buf[BUFFER_SIZE];
+ unsigned int idx= 0;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd || !wd->base) return;
+ for (idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
+ {
+ it = wd->item_list + idx;
+ if ( it->fmt_exist && it->enabled )
{
- if ((wd->hour > 12)&& (wd->time_mode)&& (wd->pm))
- hour = wd->hour - HOUR_12H_MAXIMUM;
- else
- hour = wd->hour;
- if (hour!=atoi(label))
+ strftime(buf, BUFFER_SIZE, it->fmt, wd->time);
+
+ // FIXME: no locale string availble from Libc...
+ if ((!strncmp(buf, "",1)) && (it->type == ELM_DATEFIELD_AMPM))
{
- wd->hour = atoi(label);
- edje_object_signal_emit(wd->base, "elm,state,hour,focus,out",
- "elm");
- _date_update(data);
+ if (wd->ampm) strncpy(buf, E_("PM"), BUFFER_SIZE);
+ else strncpy(buf, E_("AM"), BUFFER_SIZE);
}
+ eina_stringshare_replace(&it->content, buf);
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STR, it->location);
+ edje_object_part_text_set(wd->base, buf, it->content);
}
- else if ((wd->date_focusedpart == ENTRY_MIN) && (wd->min!=atoi(label)))
- {
- wd->min = atoi(label);
- edje_object_signal_emit(wd->base,"elm,state,min,focus,out", "elm");
- _date_update(data);
- }
- evas_object_smart_callback_call(data, "changed", NULL);
}
}
static void
-_datefield_focus_set(Evas_Object *data)
+_field_value_set(Evas_Object * obj, Elm_Datefield_ItemType item_type, int value,
+ Eina_Bool adjust_time)
{
- Elm_Diskselector_Item *item = NULL;
- Evas_Object *diskselector, *disk, *edj_part = NULL;
- const char *item_list[138], *value = NULL;
- int idx, count_start = 0, count_end = 0;
- Evas_Coord x, y, w, h;
-
- Widget_Data *wd = elm_widget_data_get(data);
- if (!wd || !wd->base) return;
-
- diskselector = elm_diskselector_add(elm_widget_top_get(data));
- elm_object_style_set(diskselector, "extended/timepicker");
- evas_object_size_hint_weight_set(diskselector, EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(diskselector, EVAS_HINT_FILL,EVAS_HINT_FILL);
- elm_diskselector_display_item_num_set(diskselector, 8);
- elm_object_focus_allow_set(diskselector, EINA_FALSE);
- elm_diskselector_side_label_lenght_set(diskselector, 4);
+ Widget_Data *wd;
+ Datefield_Item * it;
+ unsigned int idx;
+ int min, max;
+ Eina_Bool value_changed = EINA_FALSE;
- char *month_list[] = {
- E_("Jan"), E_("Feb"), E_("Mar"), E_("Apr"), E_("May"), E_("Jun"),
- E_("Jul"), E_("Aug"), E_("Sep"), E_("Oct"), E_("Nov"), E_("Dec"),
- };
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
- if (wd->date_focusedpart == ENTRY_YEAR)
- {
- edje_object_signal_emit(wd->base, "elm,state,year,focus,in", "elm");
- value = edje_object_part_text_get(wd->base,"elm.text.date.year");
- edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
- "elm.rect.date.year.over");
- count_start = wd->y_min;
- if (wd->y_max > wd->y_min)
- count_end = wd->y_max ;
- else
- count_end = 2037 ;
- //Maximum limit is set for making it compatible with Calendar widget.
- }
- else if (wd->date_focusedpart == ENTRY_MON)
- {
- edje_object_signal_emit(wd->base, "elm,state,month,focus,in", "elm");
- value= edje_object_part_text_get(wd->base,"elm.text.date.month");
- edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
- "elm.rect.date.month.over");
- count_start = 0;
- count_end = MONTH_MAXIMUM - 1;
- }
- else if (wd->date_focusedpart == ENTRY_DAY)
+ if (item_type == ELM_DATEFIELD_AMPM)
{
- edje_object_signal_emit(wd->base, "elm,state,day,focus,in", "elm");
- value = edje_object_part_text_get(wd->base,"elm.text.date.day");
- edj_part =(Evas_Object *) edje_object_part_object_get(wd->base,
- "elm.rect.date.day.over");
- count_start = 1;
- count_end = _maximum_day_get(wd->year, wd->month);
+ if ( value == wd->ampm ) return;
+ item_type = ELM_DATEFIELD_HOUR;
+ value = (wd->time->tm_hour + 12) % 24;
+ adjust_time = EINA_FALSE;
}
- else if (wd->date_focusedpart == ENTRY_HOUR)
+
+ it = wd->item_list + item_type;
+ _contextual_field_limit_get(obj, it, EINA_FALSE, &min, &max);
+
+ //12 hr format & PM then add 12 to value.
+ if (adjust_time && it->type == ELM_DATEFIELD_HOUR &&
+ it->hour_type == ELM_DATEFIELD_HOUR_12 && wd->ampm && value < 12)
+ value += 12;
+
+ if (value < min) value = min;
+ else if (value > max) value = max;
+ if ( *(it->value) == value) return;
+ *(it->value) = value;
+ value_changed = EINA_TRUE;
+
+ //Validate & reset lower order fields
+ for ( idx = item_type+1; idx < DATEFIELD_TYPE_COUNT; idx++ )
{
- edje_object_signal_emit(wd->base, "elm,state,hour,focus,in", "elm");
- value = edje_object_part_text_get(wd->base,"elm.text.time.hour");
- edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
- "elm.rect.time.hour.over");
- if (wd->time_mode)
+ it = wd->item_list + idx;
+ _contextual_field_limit_get(obj, it, EINA_FALSE, &min, &max);
+ //Validate current value against context based Min/Max restriction.
+ if (*it->value < min)
{
- count_start = 1;
- count_end = HOUR_12H_MAXIMUM ;
+ *it->value = min;
+ value_changed = EINA_TRUE;
}
- else
+ else if (*it->value > max)
{
- count_start = 0;
- count_end = HOUR_24H_MAXIMUM ;
+ *it->value = max;
+ value_changed = EINA_TRUE;
}
}
- else if (wd->date_focusedpart == ENTRY_MIN)
- {
- edje_object_signal_emit(wd->base, "elm,state,min,focus,in", "elm");
- value = edje_object_part_text_get(wd->base,"elm.text.time.min");
- edj_part = (Evas_Object *)edje_object_part_object_get(wd->base,
- "elm.rect.time.min.over");
- count_start = 0;
- count_end = MIN_MAXIMUM;
- }
- if (wd->ctxpopup_show) return;
- for (idx=count_start; idx<= count_end; idx++)
- {
- char str[5];
- if (wd->date_focusedpart == ENTRY_MON)
- snprintf(str, sizeof(str), month_list[idx]);
- else
- snprintf(str, sizeof(str), "%02d", idx);
- item_list[idx] = eina_stringshare_add(str);
- if ((value) && (strcmp(value, item_list[idx]) == 0))
- item = elm_diskselector_item_append(diskselector,item_list[idx],NULL,
- _diskselector_cb, data);
- else
- elm_diskselector_item_append(diskselector, item_list[idx], NULL,
- _diskselector_cb, data);
- eina_stringshare_del(item_list[idx]);
- }
- elm_diskselector_round_set(diskselector, EINA_TRUE);
- if(item != NULL) elm_diskselector_item_selected_set(item, EINA_TRUE);
+ //update AM/PM state
+ wd->ampm = (wd->time->tm_hour > 11 );
+ _update_items(obj);
- disk = elm_ctxpopup_content_unset(wd->ctxpopup);
- if (disk) evas_object_del(disk);
- elm_ctxpopup_content_set(wd->ctxpopup, diskselector);
- evas_object_show(wd->ctxpopup);
- wd->ctxpopup_show = EINA_TRUE;
- evas_object_geometry_get(edj_part, &x, &y, &w, &h);
- evas_object_move(wd->ctxpopup, (x+w/2), (y+h) );
+ if (value_changed)
+ evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
}
-static int
-_maximum_day_get(int year, int month)
+static void
+_diskselector_cb(void *data, Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__)
{
- int day_of_month = 0;
- if (year == 0 || month == 0) return 0;
+ DiskItem_Data *cb_data;
+ Widget_Data *wd;
- switch (month)
- {
- case 4:
- case 6:
- case 9:
- case 11:
- day_of_month = 30;
- break;
- case 2:
- {
- if ((!(year % 4) && (year % 100)) || !(year % 400))
- day_of_month = 29;
- else
- day_of_month = 28;
- }
- break;
- default:
- day_of_month = 31;
- break;
- }
+ cb_data = (DiskItem_Data *)data;
+ if (!cb_data) return;
+ wd = elm_widget_data_get(cb_data->datefield);
+ if (!wd ) return;
+
+ _field_value_set(cb_data->datefield, wd->selected_it->type,
+ cb_data->sel_item_value, EINA_TRUE);
- return day_of_month;
+ evas_object_hide(wd->ctxpopup);
}
-static int
-_check_date_boundary(Evas_Object *obj, int num, int flag)
+static void
+_ampm_clicked (void *data)
{
- Widget_Data *wd = elm_widget_data_get(obj);
- if (flag == ENTRY_YEAR)
- {
- if ((num > wd->y_max)&&(wd->y_max > wd->y_min)) num = wd->y_max;
- else if (num < wd->y_min) num = wd->y_min;
- return num;
- }
+ Widget_Data *wd;
+ char buf[BUFFER_SIZE];
- else if (flag == ENTRY_MON)
- {
- if (wd->year == wd->y_max && num > wd->m_max) num = wd->m_max;
- else if (wd->year == wd->y_min && num < wd->m_min) num = wd->m_min;
- else if (num > MONTH_MAXIMUM) num = MONTH_MAXIMUM;
- else if (num <= 0) num = 1;
- return num;
- }
+ wd = elm_widget_data_get(data);
+ if (!wd || !wd->base) return;
- else if (flag == ENTRY_DAY)
- {
- int day_of_month = _maximum_day_get(wd->year, wd->month);
- if (wd->year == wd->y_max && wd->month == wd->m_max && num > wd->d_max)
- num = wd->d_max;
- else if (wd->year == wd->y_min && wd->month == wd->m_min
- && num < wd->d_min) num = wd->d_min;
- else if (num > day_of_month) num = day_of_month;
- else if (num <= 0) num = 1;
- return num;
- }
- return num;
+ _field_value_set( data, ELM_DATEFIELD_AMPM, !wd->ampm, EINA_FALSE );
+
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_FOCUSOUT_SIG_STR,
+ wd->selected_it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ wd->selected_it = NULL;
}
-static char*
-_get_i18n_string(Evas_Object *obj, nl_item item)
+static void
+_diskselector_item_free_cb(void *data, Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__)
{
- Widget_Data *wd = elm_widget_data_get(obj);
- const char *fmt;
- char *str = NULL;
- int i = 0, j = 0;
+ if (data) free(data);
+}
+\r
+static void
+_load_field_options(Evas_Object * data, Evas_Object *diskselector,
+ Datefield_Item *it)
+{
+ Widget_Data *wd;
+ DiskItem_Data *disk_data;
+ Elm_Diskselector_Item *item;
+ int idx, min, max, selected_val;
+ int text_len, max_len = 0;
+ char item_label[BUFFER_SIZE];
+ int cur_val, date_val;
+
+ wd = elm_widget_data_get(data);
+ if (!wd) return;
- if (!wd) return NULL;
+ cur_val = *(it->value);
+ date_val = wd->time->tm_mday;
+ _contextual_field_limit_get(data, it, EINA_TRUE, &min, &max );
- fmt = nl_langinfo(item);
- if (!fmt) return NULL;
+ selected_val = *(it->value);
+ wd->time->tm_mday = 1;
+ // If 12hr format & PM, reduce 12
+ if (it->hour_type == ELM_DATEFIELD_HOUR_12 && wd->ampm) selected_val -= 12;
- switch (item)
+ for (idx = min; idx <= max; idx++)\r
{
- case D_FMT:
- str = calloc(7, sizeof(char));
- while (fmt[i])
- {
- if (fmt[i] == '%' && fmt[i+1])
- {
- i++;
- switch (fmt[i])
- {
- case 'Y': case 'M': case 'D': case 'y': case 'm': case 'd':
- str[j++] = tolower(fmt[i]);
- str[j++] = tolower(fmt[i]);
- break;
- }
- }
- i++;
- }
- return str;
- case AM_STR:
- case PM_STR:
- if (strlen(fmt) > 0)
- {
- str = calloc(strlen(fmt)+1, sizeof(char));
- strcpy(str, fmt);
- }
- else
- {
- str = calloc(3, sizeof(char));
- if (item == AM_STR) strcpy(str, "AM");
- else if (item == PM_STR) strcpy(str, "PM");
- }
- return str;
- case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: case ABMON_5:
- case ABMON_6: case ABMON_7: case ABMON_8: case ABMON_9: case ABMON_10:
- case ABMON_11: case ABMON_12:
- str = calloc(strlen(fmt)+1, sizeof(char));
- while (fmt[i])
- {
- str[j++] = fmt[i];
- if (fmt[i] >= '1' && fmt[i] <= '9')
- {
- if (fmt[i+1] >= '1' && fmt[i+1] <= '9')
- str[j] = fmt[i+1];
- break;
- }
- i++;
- }
- return str;
+ *(it->value) = idx;
+ strftime(item_label, BUFFER_SIZE, it->fmt, wd->time );
+ text_len = strlen(item_label);
+ if (text_len > max_len ) max_len = text_len; //Store max. label length
+
+ if (idx == selected_val) //Selected Item, dont attach a callback handler
+ {
+ item = elm_diskselector_item_append(diskselector, item_label,
+ NULL, NULL, NULL);
+ elm_diskselector_item_selected_set(item, EINA_TRUE);
+ }
+ else
+ {
+ disk_data = (DiskItem_Data *) malloc (sizeof(DiskItem_Data));
+ disk_data->datefield = data;
+ disk_data->sel_item_value = idx;
+ item = elm_diskselector_item_append(diskselector,
+ item_label, NULL, _diskselector_cb, disk_data);
+ elm_diskselector_item_del_cb_set(item, _diskselector_item_free_cb);
+ }
}
- return NULL;
+ *(it->value) = cur_val;
+ wd->time->tm_mday = date_val;
+ elm_diskselector_side_label_length_set(diskselector, max_len);
}
static void
-_date_update(Evas_Object *obj)
+_datefield_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
+ const char *emission __UNUSED__, const char *source)
{
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd = elm_widget_data_get(data);
Evas_Object *diskselector;
- char str[YEAR_MAX_LENGTH+1] = {0,};
- char *i18n_str;
+ const Evas_Object *edj_part;
+ char buf[BUFFER_SIZE];
+ unsigned int idx = 0, idx1 = 0, display_item_num;
+ Evas_Coord x = 0, y = 0, w = 0, h = 0;
+ Evas_Coord disksel_width;
if (!wd || !wd->base) return;
+ if (elm_widget_disabled_get(data)) return;
- sprintf(str, "%d", wd->year);
- edje_object_part_text_set(wd->base, "elm.text.date.year", str);
+ wd->selected_it = NULL;
+ //Locate the selected Index & Selected Datefield_Item
+ for (idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
+ {
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_OVER_STR, idx);
+ if (!strncmp(buf, source, sizeof(buf)))
+ {
+ for (idx1 = 0; idx1 < DATEFIELD_TYPE_COUNT; idx1++ )
+ {
+ if ((wd->item_list + idx1)->location == (int)idx)
+ {
+ wd->selected_it = wd->item_list + idx1;
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ if ( !wd->selected_it || !wd->selected_it->fmt_exist
+ || !wd->selected_it->enabled ) return;
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_FOCUSIN_SIG_STR,
+ wd->selected_it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
- i18n_str = _get_i18n_string(obj, ABMON_1+wd->month-1);
- if (i18n_str)
+ if ( wd->selected_it->type == ELM_DATEFIELD_AMPM )
{
- edje_object_part_text_set(wd->base, "elm.text.date.month", i18n_str);
- free(i18n_str);
+ _ampm_clicked (data);
+ return;
}
- sprintf(str, "%02d", wd->day);
- edje_object_part_text_set(wd->base, "elm.text.date.day", str);
+ //Recreating diskselector everytime due to diskselector behavior
+ diskselector = elm_diskselector_add(elm_widget_top_get(data));
+ snprintf(buf, sizeof(buf), "datefield/%s", elm_object_style_get(data));
+ elm_object_style_set(diskselector, buf);
- if (!wd->time_mode) //24 mode
- sprintf(str, "%02d", wd->hour);
- else
+ //Load the options list
+ _load_field_options(data, diskselector, wd->selected_it);
+
+ elm_ctxpopup_direction_priority_set(wd->ctxpopup, ELM_CTXPOPUP_DIRECTION_DOWN,
+ ELM_CTXPOPUP_DIRECTION_UP, -1, -1);
+ elm_object_content_set(wd->ctxpopup, diskselector);
+ snprintf(buf,sizeof(buf), EDC_PART_ITEM_STR, wd->selected_it->location);
+ edj_part = edje_object_part_object_get(wd->base, buf);
+ evas_object_geometry_get(edj_part, &x, &y, &w, &h);
+ evas_object_move(wd->ctxpopup, (x+w/2), (y+h));
+
+ //If the direction of Ctxpopup is upwards, move it to the top of datefield
+ if (elm_ctxpopup_direction_get (wd->ctxpopup) == ELM_CTXPOPUP_DIRECTION_UP)
{
- if (wd->hour >= HOUR_12H_MAXIMUM)
+ elm_ctxpopup_direction_priority_set(wd->ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
+ ELM_CTXPOPUP_DIRECTION_DOWN, -1, -1);
+ evas_object_move(wd->ctxpopup, (x+w/2), y);
+ }
+ evas_object_show(wd->ctxpopup);
+
+ evas_object_geometry_get(diskselector, NULL, NULL, &disksel_width, NULL);
+ display_item_num = disksel_width / (w + elm_finger_size_get());
+ //odd number of items leads to auto selection.
+ //making as event number of item to prevent auto selection.
+ if (display_item_num%2) display_item_num-=1;
+ if (display_item_num < DISKSELECTOR_ITEMS_NUM_MIN)
+ display_item_num = DISKSELECTOR_ITEMS_NUM_MIN;
+
+ elm_diskselector_display_item_num_set(diskselector, display_item_num);
+ elm_diskselector_round_set(diskselector, EINA_TRUE);
+}
+
+static unsigned int
+_parse_format( Evas_Object *obj )
+{
+ Widget_Data *wd;
+ Datefield_Item *it = NULL;
+ unsigned int len = 0, idx, location = 0;
+ char separator[MAX_SEPARATOR_LEN];
+ char *fmt_ptr;
+ char cur;
+ Eina_Bool fmt_parsing = EINA_FALSE, sep_parsing = EINA_FALSE,
+ sep_lookup = EINA_FALSE;
+
+ wd = elm_widget_data_get(obj);
+ fmt_ptr = wd->format;
+
+ while ( (cur = *fmt_ptr ) )
+ {
+ if (fmt_parsing)
{
- wd->pm = EINA_TRUE;
- i18n_str = _get_i18n_string(obj, PM_STR);
- if ((i18n_str)&&(wd->time_ampm))
+ for ( idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
{
- elm_object_text_set(wd->time_ampm, i18n_str);
- free(i18n_str);
+ if ( strchr( mapping[idx].fmt_char, cur ) )
+ {
+ it = wd->item_list + idx;
+ //Ignore the items already have or disabled
+ //valid formats, means already parsed & repeated, ignore.
+ if (!it->enabled || it->location != -1) break;
+ it->fmt[1] = cur;
+
+ //set the hour display format 12h/24h
+ if (it->type == ELM_DATEFIELD_HOUR)
+ {
+ if (cur == 'H' || cur == 'k' )
+ it->hour_type = ELM_DATEFIELD_HOUR_24;
+ else if (cur == 'I' || cur == 'l' )
+ it->hour_type = ELM_DATEFIELD_HOUR_12;
+ }
+ else it->hour_type = ELM_DATEFIELD_HOUR_NA;
+
+ it->fmt_exist = EINA_TRUE;
+ it->location = location++;
+ fmt_parsing = EINA_FALSE;
+ sep_lookup = EINA_TRUE;
+ len = 0;
+ break;
+ }
}
}
- else
+
+ if (cur == '%')
{
- wd->pm = EINA_FALSE;
- i18n_str = _get_i18n_string(obj, AM_STR);
- if ((i18n_str)&&(wd->time_ampm))
- {
- elm_object_text_set(wd->time_ampm, i18n_str);
- free(i18n_str);
- }
+ fmt_parsing = EINA_TRUE;
+ sep_parsing = EINA_FALSE;
+ // Set the separator to previous Item
+ separator[len] = 0;
+ if (it) eina_stringshare_replace(&it->separator, separator);
}
+ if (sep_parsing && (len < MAX_SEPARATOR_LEN-1)) separator[len++] = cur;
+ if (sep_lookup) sep_parsing = EINA_TRUE;
+ sep_lookup = EINA_FALSE;
+ fmt_ptr++;
+ }
+ // Return the number of valid items parsed.
+ return location;
+}
- if (wd->hour > HOUR_12H_MAXIMUM)
- sprintf(str, "%02d", wd->hour - HOUR_12H_MAXIMUM);
- else if (wd->hour == 0)
- sprintf(str, "%02d", HOUR_12H_MAXIMUM);
+static void
+_format_reload(Evas_Object *obj)
+{
+ Widget_Data *wd;
+ Datefield_Item *it;
+ char buf[BUFFER_SIZE];
+ unsigned int idx, location;
+ char *def_fmt;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ // fetch the format from locale specific po file.
+ if (!wd->user_format )
+ {
+ def_fmt = E_("DateTimeFormat");
+ if (!strncmp(def_fmt, "DateTimeFormat", sizeof("DateTimeFormat")))
+ strncpy(wd->format, DEFAULT_FORMAT, MAX_FORMAT_LEN );
else
- sprintf(str, "%02d", wd->hour);
+ strncpy(wd->format, def_fmt, MAX_FORMAT_LEN );
}
- edje_object_part_text_set(wd->base, "elm.text.time.hour", str);
- sprintf(str, "%02d", wd->min);
- edje_object_part_text_set(wd->base, "elm.text.time.min", str);
- diskselector = elm_ctxpopup_content_unset(wd->ctxpopup);
- if (diskselector) evas_object_del(diskselector);
- evas_object_hide(wd->ctxpopup);
- if (wd->ctxpopup_show)
- wd->ctxpopup_show = EINA_FALSE;
+ //reset all the items to disable state
+ for ( idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++ )
+ {
+ it = wd->item_list + idx;
+ eina_stringshare_replace(&it->content, NULL);
+ it->fmt_exist = EINA_FALSE;
+ it->location = -1;
+ }
+ location = _parse_format( obj );
+
+ //assign locations to disabled fields for uniform usage
+ for (idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++)
+ {
+ it = wd->item_list + idx;
+ if (it->location == -1) it->location = location++;
+
+ if (it->fmt_exist && it->enabled)
+ {
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_ENABLE_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ if (it->type == ELM_DATEFIELD_AMPM)
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STYLE_AMPM_SIG_STR,
+ it->location);
+ else
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_STYLE_DEFAULT_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ }
+ else
+ {
+ snprintf(buf, sizeof(buf),EDC_PART_ITEM_DISABLE_SIG_STR,
+ it->location);
+ edje_object_signal_emit(wd->base, buf, "elm");
+ }
+ snprintf(buf, sizeof(buf), EDC_PART_SEPARATOR_STR, it->location+1);
+ edje_object_part_text_set(wd->base, buf, it->separator);
+ }
+ edje_object_message_signal_process(wd->base);
+ _update_items(obj);
}
+static void
+_item_list_init(Evas_Object *obj)
+{
+ Widget_Data *wd;
+ Datefield_Item *it;
+ char buf[BUFFER_SIZE];
+ unsigned int idx;
+ time_t t;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ wd->item_list = calloc(1, DATEFIELD_TYPE_COUNT * sizeof(Datefield_Item));
+ wd->time = calloc(1, sizeof(struct tm));
+ t = time(NULL);
+ localtime_r(&t, wd->time);
+
+ (wd->item_list + ELM_DATEFIELD_YEAR)->value = &wd->time->tm_year;
+ (wd->item_list + ELM_DATEFIELD_MONTH)->value = &wd->time->tm_mon;
+ (wd->item_list + ELM_DATEFIELD_DATE)->value = &wd->time->tm_mday;
+ (wd->item_list + ELM_DATEFIELD_HOUR)->value = &wd->time->tm_hour;
+ (wd->item_list + ELM_DATEFIELD_MINUTE)->value = &wd->time->tm_min;
+ (wd->item_list + ELM_DATEFIELD_AMPM)->value = &wd->ampm;
+ wd->ampm = (wd->time->tm_hour > 11 );
+
+ for (idx = 0; idx < DATEFIELD_TYPE_COUNT; idx++)
+ {
+ it = wd->item_list + idx;
+ it->type = ELM_DATEFIELD_YEAR + idx;
+ it->fmt[0] = '%';
+ it->fmt_exist = EINA_FALSE;
+ it->enabled = EINA_TRUE;
+ it->min = mapping[idx].def_min;
+ it->default_min = mapping[idx].def_min;
+ it->max = mapping[idx].def_max;
+ it->default_max = mapping[idx].def_max;
+ snprintf(buf, sizeof(buf), EDC_PART_ITEM_OVER_STR, idx);
+ edje_object_signal_callback_add(wd->base, "mouse,clicked,1", buf,
+ _datefield_clicked_cb, obj);
+ }
+}
/**
- * Add a new datefield object
+ * @brief Add a new datefield Widget
* The date format and strings are based on current locale
*
- * @param parent The parent object
+ * @param[in] parent The parent object
* @return The new object or NULL if it cannot be created
*
* @ingroup Datefield
{
Evas_Object *obj;
Evas *e;
- char buf[4096];
Widget_Data *wd;
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
ELM_SET_WIDTYPE(widtype, "datefield");
- elm_widget_type_set(obj, "datefield");
+ elm_widget_type_set(obj, widtype);
elm_widget_sub_object_add(parent, obj);
elm_widget_data_set(obj, wd);
elm_widget_del_hook_set(obj, _del_hook);
elm_widget_theme_hook_set(obj, _theme_hook);
elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
+ elm_widget_disable_hook_set(obj, _disable_hook);
elm_widget_can_focus_set(obj, EINA_TRUE);
wd->base = edje_object_add(e);
elm_widget_resize_object_set(obj, wd->base);
- edje_object_signal_callback_add(wd->base, "mouse,down,1",
- "elm.rect.date.year.over", _signal_rect_mouse_down, obj);
- edje_object_signal_callback_add(wd->base, "mouse,down,1",
- "elm.rect.date.month.over", _signal_rect_mouse_down, obj);
- edje_object_signal_callback_add(wd->base, "mouse,down,1",
- "elm.rect.date.day.over", _signal_rect_mouse_down, obj);
-
- edje_object_signal_callback_add(wd->base, "mouse,down,1",
- "elm.rect.time.hour.over", _signal_rect_mouse_down, obj);
- edje_object_signal_callback_add(wd->base, "mouse,down,1",
- "elm.rect.time.min.over", _signal_rect_mouse_down, obj);
+ _elm_theme_object_set(obj, wd->base, "datefield", "base", "default");
+ evas_object_smart_callbacks_descriptions_set(obj, _signals);
+
+ _item_list_init(obj);
+ _format_reload(obj);
wd->ctxpopup = elm_ctxpopup_add(elm_widget_top_get(obj));
- snprintf(buf,sizeof(buf),"extended/timepicker/%s",elm_widget_style_get(obj));
- elm_object_style_set(wd->ctxpopup, buf);
+ elm_object_style_set(wd->ctxpopup, "datefield/default");
elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
- elm_ctxpopup_direction_priority_set(wd->ctxpopup,ELM_CTXPOPUP_DIRECTION_DOWN,
- ELM_CTXPOPUP_DIRECTION_UP,ELM_CTXPOPUP_DIRECTION_LEFT,
- ELM_CTXPOPUP_DIRECTION_RIGHT);
evas_object_size_hint_weight_set(wd->ctxpopup, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(wd->ctxpopup, EVAS_HINT_FILL,EVAS_HINT_FILL);
- elm_object_focus_allow_set(wd->ctxpopup, EINA_FALSE);
evas_object_smart_callback_add(wd->ctxpopup, "dismissed",
_ctxpopup_dismissed_cb, obj);
evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
_datefield_resize_cb, obj);
-
- wd->y_min = 1900;
- wd->m_min = 1;
- wd->d_min = 1;
- wd->y_max = -1;
- wd->m_max = 12;
- wd->d_max = 31;
- wd->year = wd->y_min;
- wd->month = 1;
- wd->day = 1;
- wd->ctxpopup_show = EINA_FALSE;
-
- wd->layout = ELM_DATEFIELD_LAYOUT_DATEANDTIME;
- wd->time_mode = EINA_TRUE;
-
- _theme_hook(obj);
+ evas_object_event_callback_add(wd->base, EVAS_CALLBACK_MOVE,
+ _datefield_move_cb, obj);
+ _mirrored_set(obj, elm_widget_mirrored_get(obj));
return obj;
}
/**
- * set layout for the datefield
+ * Set the format of datefield. Formats can be like "%b %d, %Y %I : %M %p".
+ * Maximum allowed format length is 32 chars.
+ * Format can include separators for each individual datefield item.
+ * Each separator can be a maximum of 6 UTF-8 bytes.
+ * Space is also taken as a separator.
+ * Following are the allowed set of format specifiers for each datefield item.
+ * These specifiers can be arranged at any order as per user requirement and
+ * their value will be replaced in the format as mentioned below.
+ * %Y : The year as a decimal number including the century.
+ * %y : The year as a decimal number without a century (range 00 to 99)
+ * %m : The month as a decimal number (range 01 to 12).
+ * %b : The abbreviated month name according to the current locale.
+ * %B : The full month name according to the current locale.
+ * %d : The day of the month as a decimal number (range 01 to 31).
+ * %I : The hour as a decimal number using a 12-hour clock (range 01 to 12).
+ * %H : The hour as a decimal number using a 24-hour clock (range 00 to 23).
+ * %k : The hour (24-hour clock) as a decimal number (range 0 to 23). single
+ * digits are preceded by a blank.
+ * %l : The hour (12-hour clock) as a decimal number (range 1 to 12); single
+ * digits are preceded by a blank.
+ * %M : The minute as a decimal number (range 00 to 59).
+ * %p : Either 'AM' or 'PM' according to the given time value, or the
+ * corresponding strings for the current locale. Noon is treated as 'PM'
+ * and midnight as 'AM'
+ * %P : Like %p but in lowercase: 'am' or 'pm' or a corresponding string for
+ * the current locale.
+ * Default format is taken as per the system display language and Region format.
*
- * @param obj The datefield object
- * @param layout set layout for date/time/dateandtime
- * (default: ELM_DATEFIELD_LAYOUT_DATEANDTIME)
+ * @param[in] obj The datefield object
+ * @param[in] fmt The date format
*
- * @ingroup Datefield
*/
EAPI void
-elm_datefield_layout_set(Evas_Object *obj, Elm_Datefield_Layout layout)
+elm_datefield_format_set(Evas_Object *obj, const char *fmt)
{
ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
+ wd = elm_widget_data_get(obj);
if (!wd) return;
- if (layout > ELM_DATEFIELD_LAYOUT_DATEANDTIME) return;
- if (wd->layout != layout)
+ if (fmt)
{
- if (wd->time_ampm)
- {
- edje_object_part_unswallow(wd->base,wd->time_ampm);
- evas_object_del(wd->time_ampm);
- wd->time_ampm = NULL;
- }
- wd->layout = layout;
- _theme_hook(obj);
+ strncpy( wd->format, fmt, MAX_FORMAT_LEN );
+ wd->user_format = EINA_TRUE;
}
- return;
-}
-
-/**
- * get layout of the datefield
- *
- * @param obj The datefield object
- * @return layout of the datefield
- *
- * @ingroup Datefield
- */
-EAPI Elm_Datefield_Layout
-elm_datefield_layout_get(const Evas_Object *obj)
-{
- ELM_CHECK_WIDTYPE(obj, widtype) 0;
- Widget_Data *wd = elm_widget_data_get(obj);
+ else wd->user_format = EINA_FALSE;
- if (!wd) return 0;
-
- return wd->layout;
+ _format_reload(obj);
}
/**
- * Set selected date of the datefield
+ * Get the format of datefield. Formats can be like "%b %d, %Y %I : %M %p".
+ * Maximum allowed format length is 32 chars.
+ * Format can include separators for each individual datefield item.
+ * Each separator can be a maximum of 6 UTF-8 bytes.
+ * Space is also taken as a separator.
+ * Following are the allowed set of format specifiers for each datefield item.
+ * These specifiers can be arranged at any order as per user requirement and
+ * their value will be replaced in the format as mentioned below.
+ * %Y : The year as a decimal number including the century.
+ * %y : The year as a decimal number without a century (range 00 to 99)
+ * %m : The month as a decimal number (range 01 to 12).
+ * %b : The abbreviated month name according to the current locale.
+ * %B : The full month name according to the current locale.
+ * %d : The day of the month as a decimal number (range 01 to 31).
+ * %I : The hour as a decimal number using a 12-hour clock (range 01 to 12).
+ * %H : The hour as a decimal number using a 24-hour clock (range 00 to 23).
+ * %k : The hour (24-hour clock) as a decimal number (range 0 to 23). single
+ * digits are preceded by a blank.
+ * %l : The hour (12-hour clock) as a decimal number (range 1 to 12); single
+ * digits are preceded by a blank.
+ * %M : The minute as a decimal number (range 00 to 59).
+ * %p : Either 'AM' or 'PM' according to the given time value, or the
+ * corresponding strings for the current locale. Noon is treated as 'PM'
+ * and midnight as 'AM'
+ * %P : Like %p but in lowercase: 'am' or 'pm' or a corresponding string for
+ * the current locale.
+ * Default format is taken as per the system display language and Region format.
*
- * @param obj The datefield object
- * @param year The year to set
- * @param month The month to set
- * @param day The day to set
- * @param hour The hours to set (24hour mode - 0~23)
- * @param min The minutes to set (0~59)
+ * @param[in] obj The datefield object
+ * @return date format string. ex) %b %d, %Y %I : %M %p
*
- * @ingroup Datefield
*/
-EAPI void
-elm_datefield_date_set(Evas_Object *obj, int year, int month, int day, int hour,
- int min)
+EAPI char *
+elm_datefield_format_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
-
- if (!wd) return;
-
- wd->year = _check_date_boundary(obj, year, ENTRY_YEAR);
- wd->month = _check_date_boundary(obj, month, ENTRY_MON);
- wd->day = _check_date_boundary(obj, day, ENTRY_DAY);
-
- if (hour > HOUR_24H_MAXIMUM) wd->hour = HOUR_24H_MAXIMUM;
- else if (hour < 0) wd->hour = 0;
- else wd->hour = hour;
-
- if (min > MIN_MAXIMUM) wd->min = MIN_MAXIMUM;
- else if (min < 0) wd->min = 0;
- else wd->min = min;
-
- _date_update(obj);
+ if (!wd ) return NULL;
+ return strdup(wd->format);
}
/**
- * Get selected date of the datefield
+ * @brief Set the selected value of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Month value range is from 0 to 11
+ * Date value range is from 1 to 31 according to the month value.
+ * The hour value should be set according to 24hr format (0~23)
+ * Minute value range is from 0 to 59.
+ * AM/PM. Value 0 for AM and 1 for PM.
+ * If the value is beyond the range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
- * @param obj The datefield object
- * @param year The pointer to the variable get the selected year
- * @param month The pointer to the variable get the selected month
- * @param day The pointer to the variable get the selected day
- * @param hour The pointer to the variable get the selected hour (24hour mode)
- * @param hour The pointer to the variable get the selected min
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @param[in] value The data to be set. ex. year/month/date/hour/minute/ampm
*
* @ingroup Datefield
*/
EAPI void
-elm_datefield_date_get(const Evas_Object *obj, int *year, int *month, int *day,
- int *hour, int *min)
+elm_datefield_item_value_set(Evas_Object *obj, Elm_Datefield_ItemType itemtype,
+ int value)
{
ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
+ Datefield_Item *it;
- if (!wd) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return;
- if (year)
- *year = wd->year;
- if (month)
- *month = wd->month;
- if (day)
- *day = wd->day;
- if (hour)
- *hour = wd->hour;
- if (min)
- *min = wd->min;
+ it = wd->item_list + itemtype;
+ _field_value_set(obj, it->type, value, EINA_FALSE);
}
/**
- * Set upper boundary of the datefield
+ * @brief Get Current value date of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Month value range is from 0 to 11
+ * Date value range is from 1 to 31 according to the month value.
+ * The hour value should be set according to 24hr format (0~23)
+ * Minute value range is from 0 to 59.
+ * AM/PM. Value 0 for AM and 1 for PM.
+ * If the value is beyond the range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
- * @param obj The datefield object
- * @param year The year to set
- * @param month The month to set
- * @param day The day to set
- * @return TRUE/FALSE
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return int The value of the field.
*
* @ingroup Datefield
*/
-EAPI Eina_Bool
-elm_datefield_date_max_set(Evas_Object *obj, int year, int month, int day)
+EAPI int
+elm_datefield_item_value_get(const Evas_Object *obj, Elm_Datefield_ItemType
+ itemtype)
{
- ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
- Widget_Data *wd = elm_widget_data_get(obj);
- int day_of_month;
- Eina_Bool update = EINA_FALSE;
-
- if (!wd) return EINA_FALSE;
- if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
- day_of_month = _maximum_day_get(year, month);
- if (day < 1 || day > day_of_month) return EINA_FALSE;
-
- wd->y_max = year;
- wd->m_max = month;
- wd->d_max = day;
+ ELM_CHECK_WIDTYPE(obj, widtype) -1;
+ Widget_Data *wd;
- if (wd->year > wd->y_max)
- {
- wd->year = wd->y_max;
- update = EINA_TRUE;
- }
- if (wd->year == wd->y_max && wd->month > wd->m_max)
- {
- wd->month = wd->m_max;
- update = EINA_TRUE;
- }
- if (wd->year == wd->y_max && wd->month == wd->m_max && wd->day > wd->d_max)
- {
- wd->day = wd->d_max;
- update = EINA_TRUE;
- }
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return -1;
- if (update) _date_update(obj);
- return EINA_TRUE;
+ return (*(wd->item_list + itemtype)->value);
}
+
/**
- * Get upper boundary of the datefield
+ * @brief Enable/Disable an item of the datefield
*
- * @param obj The datefield object
- * @param year The pointer to the variable get the maximum year
- * @param month The pointer to the variable get the maximum month
- * @param day The pointer to the variable get the maximum day
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @param[in] enable Item is Enabled or disabled.
*
* @ingroup Datefield
*/
+
EAPI void
-elm_datefield_date_max_get(const Evas_Object *obj, int *year, int *month,
- int *day)
+elm_datefield_item_enabled_set(Evas_Object *obj, Elm_Datefield_ItemType itemtype,
+ Eina_Bool enable)
{
ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
+ Datefield_Item *it;
- if (!wd) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return;
- if (year)
- *year = wd->y_max;
- if (month)
- *month = wd->m_max;
- if (day)
- *day = wd->d_max;
+ it = wd->item_list + itemtype;
+ if ( it->enabled == enable ) return;
+ it->enabled = enable;
+ _format_reload(obj);
}
/**
- * Set lower boundary of the datefield
+ * @brief Get whether the item is Enabled/Disabled
*
- * @param obj The datefield object
- * @param year The year to set
- * @param month The month to set
- * @param day The day to set
- * @return TRUE/FALSE
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return EINA_TRUE = Item is Enabled or EINA_FALSE = disabled.
*
- * @ingroup Datepicker
+ * @ingroup Datefield
*/
+
EAPI Eina_Bool
-elm_datefield_date_min_set(Evas_Object *obj, int year, int month, int day)
+elm_datefield_item_enabled_get(const Evas_Object *obj, Elm_Datefield_ItemType itemtype)
{
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
- Widget_Data *wd = elm_widget_data_get(obj);
- int day_of_month;
- Eina_Bool update = EINA_FALSE;
-
- if (!wd) return EINA_FALSE;
- if (month < 1 || month > MONTH_MAXIMUM) return EINA_FALSE;
- day_of_month = _maximum_day_get(year, month);
- if (day < 1 || day > day_of_month) return EINA_FALSE;
+ Widget_Data *wd;
+ Datefield_Item *it;
- wd->y_min = year;
- wd->m_min = month;
- wd->d_min = day;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return EINA_FALSE;
- if (wd->year < wd->y_min)
- {
- wd->year = wd->y_min;
- update = EINA_TRUE;
- }
- if (wd->year == wd->y_min && wd->month < wd->m_min)
- {
- wd->month = wd->m_min;
- update = EINA_TRUE;
- }
- if (wd->year == wd->y_min && wd->month == wd->m_min && wd->day < wd->d_min)
- {
- wd->day = wd->d_min;
- update = EINA_TRUE;
- }
-
- if (update) _date_update(obj);
- return EINA_TRUE;
+ it = wd->item_list + itemtype;
+ return it->enabled;
}
/**
- * Get lower boundary of the datefield
- *
- * @param obj The datefield object
- * @param year The pointer to the variable get the maximum year
- * @param month The pointer to the variable get the maximum month
- * @param day The pointer to the variable get the maximum day
+ * @brief Get lower boundary of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Month default value range is from 0 to 11
+ * Date default value range is from 1 to 31 according to the month value.
+ * Hour default value will be in terms of 24 hr format (0~23)
+ * Minute default value range will be from 0 to 59.
+ * AM/PM. Value 0 for AM and 1 for PM.
+ * If the value is beyond the range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @param[in] value The minimum value of the field that is to be set.
* @ingroup Datefield
*/
EAPI void
-elm_datefield_date_min_get(const Evas_Object *obj, int *year, int *month,
- int *day)
+elm_datefield_item_min_set(Evas_Object *obj, Elm_Datefield_ItemType itemtype,
+ int value, Eina_Bool abs_limit)
{
ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
+ Datefield_Item *it;
- if (!wd) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return;
+
+ it = wd->item_list + itemtype;
+ if ( it->type != ELM_DATEFIELD_YEAR && value < it->default_min )
+ it->min = it->default_min;
+ else
+ it->min = value;
- if (year)
- *year = wd->y_min;
- if (month)
- *month = wd->m_min;
- if (day)
- *day = wd->d_min;
+ if(it->min > it->max ) it->max = it->min;
+ it->abs_min = abs_limit;
+ _field_value_set(obj, it->type, *(it->value), EINA_FALSE); // Trigger the validation
}
/**
- * Set if the datefield show hours in military or am/pm mode
+ * @brief Get lower boundary of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Year default range is from 70 to 137.
+ * Month default value range is from 0 to 11
+ * Date default value range is from 1 to 31 according to the month value.
+ * Hour default value will be in terms of 24 hr format (0~23)
+ * Minute default value range will be from 0 to 59.
+ * AM/PM. Value 0 for AM and 1 for PM.
+ * If the value is beyond the range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
- * @param obj The datefield object
- * @param mode option for the hours mode. If true, it is shown as 12h mode,
- * if false, it is shown as 24h mode. Default value is true
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return int The minimum value of the field.
*
- * @ingroup Datefield
+ * @ingroup Datepicker
*/
-EAPI void
-elm_datefield_time_mode_set(Evas_Object *obj, Eina_Bool mode)
+EAPI int
+elm_datefield_item_min_get(const Evas_Object *obj, Elm_Datefield_ItemType
+ itemtype)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
+ ELM_CHECK_WIDTYPE(obj, widtype) -1;
+ Widget_Data *wd;
- if (!wd) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return -1;
- if (wd->time_mode != mode)
- {
- wd->time_mode = mode;
- if (!wd->time_mode)
- edje_object_signal_emit(wd->base, "elm,state,mode,24h","elm");
- else
- edje_object_signal_emit(wd->base, "elm,state,mode,12h", "elm");
- edje_object_message_signal_process(wd->base);
- _date_update(obj);
- }
+ return ((wd->item_list + itemtype)->min);
}
/**
- * get time mode of the datefield
+ * @brief Get whether the minimum value of the item is absolute or not
*
- * @param obj The datefield object
- * @return time mode (EINA_TRUE: 12hour mode / EINA_FALSE: 24hour mode)
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return EINA_TRUE = Minimim is absolute or EINA_FALSE = Minimum is relative.
*
* @ingroup Datefield
*/
+
EAPI Eina_Bool
-elm_datefield_time_mode_get(const Evas_Object *obj)
+elm_datefield_item_min_is_absolute(const Evas_Object *obj,
+ Elm_Datefield_ItemType itemtype)
{
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
- if (!wd) return EINA_FALSE;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return EINA_FALSE;
- return wd->time_mode;
+ return ((wd->item_list + itemtype)->abs_min);
}
/**
- * Set date format of datefield
+ * @brief Set upper boundary of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Month:default value range is from 0 to 11
+ * Date : default value range is from 1 to 31 according to the month value.
+ * Hour : default value will be in terms of 24 hr format (0~23)
+ * Minute : default value range will be from 0 to 59.
+ * AM/PM: Value 0 for AM and 1 for PM.
+ * If the value is beyond the contextual range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
- * @param obj The datefield object
- * @param fmt The date format, ex) yymmdd. Default value is mmddyy.
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @param[in] value The maximum field value that is to be set.
*
* @ingroup Datefield
*/
EAPI void
-elm_datefield_date_format_set(Evas_Object *obj, const char *fmt)
+elm_datefield_item_max_set(Evas_Object *obj, Elm_Datefield_ItemType itemtype,
+ int value, Eina_Bool abs_limit )
{
ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- char sig[32] = "elm,state,format,";
- int i = 0, j;
+ Widget_Data *wd;
+ Datefield_Item *it;
- if (!wd || !fmt) return;
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return;
- j = strlen(sig);
- while (j < 31 )
- {
- sig[j++] = tolower(fmt[i++]);
- }
- if (j < 32) sig[j] = '\0';
- edje_object_signal_emit(wd->base, sig, "elm");
- edje_object_message_signal_process(wd->base);
+ it = wd->item_list + itemtype;
+ if (it->type != ELM_DATEFIELD_YEAR && value > it->default_max )
+ it->max = it->default_max;
+ else
+ it->max = value;
- if (strstr(sig, "yymmdd")) wd->date_format = DATE_FORMAT_YYMMDD;
- else if (strstr(sig, "yyddmm")) wd->date_format = DATE_FORMAT_YYDDMM;
- else if (strstr(sig, "mmyydd")) wd->date_format = DATE_FORMAT_MMYYDD;
- else if (strstr(sig, "mmddyy")) wd->date_format = DATE_FORMAT_MMDDYY;
- else if (strstr(sig, "ddyymm")) wd->date_format = DATE_FORMAT_DDYYMM;
- else if (strstr(sig, "ddmmyy")) wd->date_format = DATE_FORMAT_DDMMYY;
- wd->format_exists = EINA_TRUE;
+ if(it->max < it->min) it->min = it->max;
+ it->abs_max = abs_limit;
+
+ _field_value_set(obj, it->type, *(it->value), EINA_FALSE); // Trigger the validation
}
/**
- * get date format of the datefield
+ * @brief Get upper boundary of the datefield
+ * Year : years since 1900. Negative value represents year below 1900. (
+ * year value -30 represents 1870). Year default range is from 70 to 137.
+ * Month default value range is from 0 to 11
+ * Date default value range is from 1 to 31 according to the month value.
+ * Hour default value will be in terms of 24 hr format (0~23)
+ * Minute default value range will be from 0 to 59.
+ * AM/PM. Value 0 for AM and 1 for PM.
+ * If the value is beyond the range,
+ * a) Value is less than Min range value, then Min range value is set.
+ * b) Greater than Max range value, then Max Range value is set.
+ * Both Min and Max range of individual fields are bound to the current context.
*
- * @param obj The datefield object
- * @return date format string. ex) yymmdd
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return int The maximum value of the field.
*
* @ingroup Datefield
*/
-EAPI const char *
-elm_datefield_date_format_get(const Evas_Object *obj)
+EAPI int
+elm_datefield_item_max_get(const Evas_Object *obj, Elm_Datefield_ItemType
+ itemtype)
{
- ELM_CHECK_WIDTYPE(obj, widtype) NULL;
- Widget_Data *wd = elm_widget_data_get(obj);
+ ELM_CHECK_WIDTYPE(obj, widtype) -1;
+ Widget_Data *wd;
- switch (wd->date_format)
- {
- case DATE_FORMAT_YYMMDD: return "yymmdd";
- case DATE_FORMAT_YYDDMM: return "yyddmm";
- case DATE_FORMAT_MMYYDD: return "mmyydd";
- case DATE_FORMAT_MMDDYY: return "mmddyy";
- case DATE_FORMAT_DDYYMM: return "ddyymm";
- case DATE_FORMAT_DDMMYY: return "ddmmyy";
- default: return NULL;
- }
-}
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return -1;
-/**
- * Add a callback function for input panel state
- *
- * @param obj The datefield object
- * @param func The function to be called when the event is triggered
- * (value will be the Ecore_IMF_Input_Panel_State)
- * @param data The data pointer to be passed to @p func
- *
- * @ingroup Datefield
- */
-EAPI void
-elm_datefield_input_panel_state_callback_add(Evas_Object *obj,
- void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value),
- void *data)
-{
- // This API will be no more in use after the redesigning of datefield widget
- //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
- // API will be deprecated soon.
- printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_add "
- "will be deprecated soon \n#####\n");
+ return ((wd->item_list + itemtype)->max);
}
/**
- * Delete a callback function for input panel state
+ * @brief Get whether the max value of the item is absolute or not
*
- * @param obj The datefield object
- * @param func The function to be called when the event is triggered
+ * @param[in] obj The datefield object
+ * @param[in] itemtype The field type of datefield. ELM_DATEFIELD_YEAR etc.
+ * @return EINA_TRUE = Max is absolute or EINA_FALSE = Max is relative.
*
* @ingroup Datefield
*/
-EAPI void
-elm_datefield_input_panel_state_callback_del(Evas_Object *obj,
- void (*pEventCallbackFunc) (void *data, Evas_Object *obj, int value))
+
+EAPI Eina_Bool
+elm_datefield_item_max_is_absolute(const Evas_Object *obj,
+ Elm_Datefield_ItemType itemtype)
{
- // This API will be no more in use after the redesigning of datefield widget
- //with ctxpopup & diskselector instead of using entry objects edited by Vkpd.
- // API will be deprecated soon.
- printf( "#####\nWARNING: API elm_datefield_input_panel_state_callback_del"
- "will be deprecated soon \n#####\n");
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ Widget_Data *wd;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd || itemtype > ELM_DATEFIELD_AMPM ) return EINA_FALSE;
+
+ return ((wd->item_list + itemtype)->abs_max);
}
+