diff --git a/data/elementary/themes/Makefile.am b/data/elementary/themes/Makefile.am index 3ae20fa023..89878644d8 100644 --- a/data/elementary/themes/Makefile.am +++ b/data/elementary/themes/Makefile.am @@ -103,7 +103,6 @@ elementary/themes/edc/elm/colorclass.edc \ elementary/themes/edc/elm/conform.edc \ elementary/themes/edc/elm/ctxpopup.edc \ elementary/themes/edc/elm/cursor.edc \ -elementary/themes/edc/elm/datetime.edc \ elementary/themes/edc/elm/dayselector.edc \ elementary/themes/edc/elm/diskselector.edc \ elementary/themes/edc/elm/entry.edc \ diff --git a/data/elementary/themes/default.edc b/data/elementary/themes/default.edc index 701aba09ca..9756132caf 100644 --- a/data/elementary/themes/default.edc +++ b/data/elementary/themes/default.edc @@ -36,7 +36,6 @@ collections { #include "edc/elm/access.edc" #include "edc/elm/photo.edc" #include "edc/elm/focus.edc" -#include "edc/elm/datetime.edc" #include "edc/elm/uiclock.edc" #include "edc/elm/player.edc" #include "edc/elm/thumb.edc" diff --git a/data/elementary/themes/edc/elm/datetime.edc b/data/elementary/themes/edc/elm/datetime.edc deleted file mode 100644 index 18ecf75d21..0000000000 --- a/data/elementary/themes/edc/elm/datetime.edc +++ /dev/null @@ -1,203 +0,0 @@ -#define DATETIME_FIELD(_pos) \ - part { \ - name: "field"#_pos; type: SWALLOW; \ - scale: 1; \ - clip_to: "clip"; \ - description { state: "default" 0.0; \ - visible: 0; \ - min: 0 0; \ - align: 0.0 0.5; \ - fixed: 1 1; \ - rel1.relative: 1.0 0.0; \ - rel1.to: "separator"#_pos; \ - rel2.relative: 1.0 1.0; \ - rel2.to: "separator"#_pos; \ - } \ - description { state: "enable" 0.0; \ - inherit: "default" 0.0; \ - visible: 1; \ - min: 8 10; \ - } \ - } \ - programs{ \ - program { name: "field_"#_pos"enabled"; \ - signal: "field"#_pos",enable"; source: "elm"; \ - action: STATE_SET "enable" 0.0; \ - target: "field"#_pos; \ - } \ - program { name: "field_"#_pos"disabled"; \ - signal: "field"#_pos",disable"; source: "elm"; \ - action: STATE_SET "default" 0.0; \ - target: "field"#_pos; \ - } \ - } -#define DATETIME_SEPARATOR(_pos, _after) \ - part { \ - name: "separator"#_pos; type: TEXT; \ - scale: 1; \ - effect: SHADOW BOTTOM; \ - clip_to: "disclip"; \ - description { state: "default" 0.0; \ - visible: 0; \ - min: 0 0; \ - align: 0.0 0.5; \ - fixed: 1 0; \ - rel1 { \ - relative: 1.0 0.0; \ - to: "field"#_after; \ - } \ - rel2 { \ - relative: 1.0 1.0; \ - to: "field"#_after; \ - } \ - color_class: "datetime_separator_text"; \ - text { \ - font: "Sans"; size: 10; \ - min: 1 0; \ - ellipsis: -1; \ - align: 0.5 0.5; \ - text_class: "datetime_separator_text"; \ - } \ - } \ - description { state: "enable" 0.0; \ - inherit: "default" 0.0; \ - visible: 1; \ - min: 8 10; \ - } \ - } \ - part { \ - name: "separator"#_pos"d"; type: TEXT; \ - scale: 1; \ - effect: SHADOW BOTTOM; \ - clip_to: "disclip2"; \ - description { state: "default" 0.0; \ - visible: 0; \ - rel1.to: "separator"#_pos; \ - rel2.to: "separator"#_pos; \ - color_class: "datetime_separator_text_disabled"; \ - text { \ - text_source: "separator"#_pos; \ - font: "Sans"; size: 10; \ - text_class: "datetime_separator_text_disabled"; \ - } \ - } \ - description { state: "enable" 0.0; \ - inherit: "default" 0.0; \ - visible: 1; \ - } \ - } \ - programs { \ - program { \ - signal: "field"#_after",enable"; source: "elm"; \ - action: STATE_SET "enable" 0.0; \ - target: "separator"#_pos; \ - target: "separator"#_pos"d"; \ - } \ - program { \ - signal: "field"#_after",disable"; source: "elm"; \ - action: STATE_SET "default" 0.0; \ - target: "separator"#_pos; \ - target: "separator"#_pos"d"; \ - } \ - } -group { name: "elm/datetime/base/default"; - parts { - part { name: "bg"; type: RECT; - description { state: "default" 0.0; - color_class: "datetime_bg"; - } - } - part { name: "clip"; type: RECT; - description { state: "default" 0.0; - rel1.to: "separator0"; - rel2.to: "separator7"; - } - } - part { name: "disclip"; type: RECT; - clip_to: "clip"; - description { state: "default" 0.0; - rel1.to: "separator0"; - rel2.to: "separator7"; - } - description { state: "disabled" 0.0; - inherit: "default" 0.0; - visible: 0; - } - } - part { name: "disclip2"; type: RECT; - clip_to: "clip"; - description { state: "default" 0.0; - rel1.to: "separator0"; - rel2.to: "separator7"; - visible: 0; - } - description { state: "disabled" 0.0; - inherit: "default" 0.0; - visible: 1; - } - } - part { name: "separator0"; type: SPACER; - scale: 1; - description { state: "default" 0.0; - min: 8 10; - align: 0.0 0.5; - fixed: 1 0; - rel2.relative: 0.0 1.0; - } - } - DATETIME_FIELD(0) - DATETIME_SEPARATOR(1,0) - DATETIME_FIELD(1) - DATETIME_SEPARATOR(2,1) - DATETIME_FIELD(2) - DATETIME_SEPARATOR(3,2) - DATETIME_FIELD(3) - DATETIME_SEPARATOR(4,3) - DATETIME_FIELD(4) - DATETIME_SEPARATOR(5,4) - DATETIME_FIELD(5) - DATETIME_SEPARATOR(6,5) - part { name: "separator7"; type: SPACER; - description { state: "default" 0.0; - rel1.to: "separator6"; - rel1.relative: 1.0 0.0; - min: 8 10; - } - } - part { name: "discover"; type: RECT; - description { state: "default" 0.0; - rel1.to: "separator0"; - rel2.to: "separator7"; - visible: 0; - color: 0 0 0 0; - } - description { state: "disabled" 0.0; - inherit: "default" 0.0; - visible: 1; - } - } - part { name: "elm.access"; type: RECT; repeat_events: 1; - description { state: "default" 0.0; - color: 0 0 0 0; - } - } - } - programs { - program { - signal: "elm,state,disabled"; source: "elm"; - action: STATE_SET "disabled" 0.0; - target: "disclip"; - target: "disclip2"; - target: "discover"; - } - program { - signal: "elm,state,enabled"; source: "elm"; - action: STATE_SET "default" 0.0; - target: "disclip"; - target: "disclip2"; - target: "discover"; - } - } -} -#undef DATETIME_SEPARATOR -#undef DATETIME_FIELD diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index 39692219bd..7679950ca5 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -13,7 +13,6 @@ elm_public_eolian_files = \ lib/elementary/elm_combobox.eo \ lib/elementary/elm_conformant.eo \ lib/elementary/elm_ctxpopup.eo \ - lib/elementary/elm_datetime.eo \ lib/elementary/elm_dayselector.eo \ lib/elementary/elm_entry.eo \ lib/elementary/elm_fileselector.eo \ @@ -217,7 +216,6 @@ includesunstable_HEADERS = \ lib/elementary/elm_widget_container.h \ lib/elementary/elm_widget_combobox.h \ lib/elementary/elm_widget_ctxpopup.h \ - lib/elementary/elm_widget_datetime.h \ lib/elementary/elm_widget_dayselector.h \ lib/elementary/elm_widget_diskselector.h \ lib/elementary/elm_widget_entry.h \ @@ -350,9 +348,6 @@ includesub_HEADERS = \ lib/elementary/elm_conform_legacy.h \ lib/elementary/elm_cursor.h \ lib/elementary/elm_datetime.h \ - lib/elementary/elm_datetime_common.h \ - lib/elementary/elm_datetime_eo.h \ - lib/elementary/elm_datetime_legacy.h \ lib/elementary/elm_dayselector.h \ lib/elementary/elm_dayselector_eo.h \ lib/elementary/elm_dayselector_legacy.h \ @@ -969,34 +964,6 @@ modules_elementary_access_output_module_la_DEPENDENCIES = @USE_ELEMENTARY_INTERN modules_elementary_access_output_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ modules_elementary_access_output_module_la_LIBTOOLFLAGS = --tag=disable-static -## datetime_input_ctxpopup - -moduledatetime_input_ctxpopuppkgdir = $(libdir)/elementary/modules/datetime_input_ctxpopup/$(MODULE_ARCH) -moduledatetime_input_ctxpopuppkg_LTLIBRARIES = modules/elementary/datetime_input_ctxpopup/module.la - -# Workaround for broken parallel install support in automake (relink issue) -# http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7328 -install_moduledatetime_input_ctxpopuppkgLTLIBRARIES = install-moduledatetime_input_ctxpopuppkgLTLIBRARIES -$(install_moduledatetime_input_ctxpopuppkgLTLIBRARIES): install-libLTLIBRARIES - -modules_elementary_datetime_input_ctxpopup_module_la_SOURCES = \ -modules/elementary/datetime_input_ctxpopup/datetime_input_ctxpopup.c -modules_elementary_datetime_input_ctxpopup_module_la_CPPFLAGS = \ --DELM_INTERNAL_API_ARGESFSDFEFC=1 \ --I. \ --I$(top_builddir) \ --I$(top_srcdir) \ --I$(top_srcdir)/src/lib/elementary \ --I$(top_builddir)/src/lib/elementary \ --DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" \ --DPACKAGE_LIB_DIR=\"$(libdir)\" \ --DELEMENTARY_BUILD \ -@ELEMENTARY_CFLAGS@ -modules_elementary_datetime_input_ctxpopup_module_la_LIBADD = @USE_ELEMENTARY_LIBS@ -modules_elementary_datetime_input_ctxpopup_module_la_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@ -modules_elementary_datetime_input_ctxpopup_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ -modules_elementary_datetime_input_ctxpopup_module_la_LIBTOOLFLAGS = --tag=disable-static - ## clock_input_ctxpopup moduleclock_input_ctxpopuppkgdir = $(libdir)/elementary/modules/clock_input_ctxpopup/$(MODULE_ARCH) diff --git a/src/lib/elementary/elm_datetime.c b/src/lib/elementary/elm_datetime.c index a880edd5c4..9b7da2bd83 100644 --- a/src/lib/elementary/elm_datetime.c +++ b/src/lib/elementary/elm_datetime.c @@ -6,12 +6,6 @@ #include #include "elm_priv.h" -#include "elm_widget_datetime.h" - -#define MY_CLASS ELM_DATETIME_CLASS - -#define MY_CLASS_NAME "Elm_Datetime" -#define MY_CLASS_NAME_LEGACY "elm_datetime" #ifdef HAVE_LOCALE_H # include @@ -21,1110 +15,83 @@ # include #endif -#define MAX_SEPARATOR_LEN 6 -#define MIN_DAYS_IN_MONTH 28 -#define BUFFER_SIZE 1024 - -/* interface between EDC & C code (field & signal names). values 0 to - * ELM_DATETIME_TYPE_COUNT are in the valid range, and must get in the - * place of "%d". - */ -#define EDC_DATETIME_FOCUSIN_SIG_STR "elm,action,focus" -#define EDC_DATETIME_FOCUSOUT_SIG_STR "elm,action,unfocus" -#define EDC_PART_FIELD_STR "field%d" -#define EDC_PART_SEPARATOR_STR "separator%d" -#define EDC_PART_FIELD_ENABLE_SIG_STR "field%d,enable" -#define EDC_PART_FIELD_DISABLE_SIG_STR "field%d,disable" - -/* struct tm does not define the fields in the order year, month, - * date, hour, minute. values are reassigned to an array for easy - * handling. - */ -#define DATETIME_TM_ARRAY(intptr, tmptr) \ - int *intptr[] = { \ - &(tmptr)->tm_year, \ - &(tmptr)->tm_mon, \ - &(tmptr)->tm_mday, \ - &(tmptr)->tm_hour, \ - &(tmptr)->tm_min, \ - &(tmptr)->tm_sec} - -// default limits for individual fields -static Format_Map mapping[ELM_DATETIME_TYPE_COUNT] = { - [ELM_DATETIME_YEAR] = { "Yy", -1, -1, "" }, - [ELM_DATETIME_MONTH] = { "mbBh", 0, 11, "" }, - [ELM_DATETIME_DATE] = { "de", 1, 31, "" }, - [ELM_DATETIME_HOUR] = { "IHkl", 0, 23, "" }, - [ELM_DATETIME_MINUTE] = { "M", 0, 59, ":" }, - [ELM_DATETIME_AMPM] = { "pP", 0, 1, "" } -}; - -static const char *multifield_formats = "cxXrRTDF"; -static const char *ignore_separators = "()"; -static Datetime_Mod_Api *dt_mod = NULL; - -static const char SIG_CHANGED[] = "changed"; -static const Evas_Smart_Cb_Description _smart_callbacks[] = { - {SIG_CHANGED, ""}, - {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */ - {SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */ - {SIG_LAYOUT_FOCUSED, ""}, /**< handled by elm_layout */ - {SIG_LAYOUT_UNFOCUSED, ""}, /**< handled by elm_layout */ - {NULL, NULL} -}; - -static Datetime_Mod_Api * -_dt_mod_init() -{ - Elm_Module *mod = NULL; - - if (!(mod = _elm_module_find_as("datetime/api"))) return NULL; - - mod->api = malloc(sizeof(Datetime_Mod_Api)); - if (!mod->api) return NULL; - - ((Datetime_Mod_Api *)(mod->api))->obj_hook = - _elm_module_symbol_get(mod, "obj_hook"); - ((Datetime_Mod_Api *)(mod->api))->obj_unhook = - _elm_module_symbol_get(mod, "obj_unhook"); - ((Datetime_Mod_Api *)(mod->api))->obj_hide = - _elm_module_symbol_get(mod, "obj_hide"); - ((Datetime_Mod_Api *)(mod->api))->field_create = - _elm_module_symbol_get(mod, "field_create"); - ((Datetime_Mod_Api *)(mod->api))->field_value_display = - _elm_module_symbol_get(mod, "field_value_display"); - - return mod->api; -} - -static void -_field_list_display(Evas_Object *obj) -{ - Datetime_Field *field; - unsigned int idx = 0; - - ELM_DATETIME_DATA_GET(obj, sd); - - if (!dt_mod || !dt_mod->field_value_display) return; - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - if (field->fmt_exist && field->visible) - dt_mod->field_value_display(sd->mod_data, field->item_obj); - } -} - -// FIXME: provide nl_langinfo on Windows if possible -// returns expanded format string for corresponding multi-field format character -static char * -_expanded_fmt_str_get(char ch) -{ - char *exp_fmt = ""; - switch (ch) - { - case 'c': -#if defined(HAVE_LANGINFO_H) || defined (HAVE_EVIL) - exp_fmt = nl_langinfo(D_T_FMT); -#else - exp_fmt = ""; -#endif - break; - - case 'x': -#if defined(HAVE_LANGINFO_H) || defined (HAVE_EVIL) - exp_fmt = nl_langinfo(D_FMT); -#else - exp_fmt = ""; -#endif - break; - - case 'X': -#if defined(HAVE_LANGINFO_H) || defined (HAVE_EVIL) - exp_fmt = nl_langinfo(T_FMT); -#else - exp_fmt = ""; -#endif - break; - - case 'r': -#if defined(HAVE_LANGINFO_H) || defined (HAVE_EVIL) - exp_fmt = nl_langinfo(T_FMT_AMPM); -#else - exp_fmt = ""; -#endif - break; - - case 'R': - exp_fmt = "%H:%M"; - break; - - case 'T': - exp_fmt = "%H:%M:%S"; - break; - - case 'D': - exp_fmt = "%m/%d/%y"; - break; - - case 'F': - exp_fmt = "%Y-%m-%d"; - break; - - default: - exp_fmt = ""; - break; - } - - return exp_fmt; -} - -static void -_expand_format(char *dt_fmt) -{ - char *ptr, *expanded_fmt, ch; - unsigned int idx = 0, len = 0; - char buf[ELM_DATETIME_MAX_FORMAT_LEN] = {0, }; - Eina_Bool fmt_char = EINA_FALSE; - - ptr = dt_fmt; - while ((ch = *ptr)) - { - if ((fmt_char) && (strchr(multifield_formats, ch))) - { - /* replace the multi-field format characters with - * corresponding expanded format */ - expanded_fmt = _expanded_fmt_str_get(ch); - len = strlen(expanded_fmt); - buf[--idx] = 0; - strncat(buf, expanded_fmt, len); - idx += len; - } - else buf[idx++] = ch; - - if (ch == '%') fmt_char = EINA_TRUE; - else fmt_char = EINA_FALSE; - - ptr++; - } - - buf[idx] = 0; - strncpy(dt_fmt, buf, ELM_DATETIME_MAX_FORMAT_LEN); -} - -static void -_field_list_arrange(Evas_Object *obj) -{ - Datetime_Field *field; - char buf[BUFFER_SIZE]; - int idx; - Eina_Bool freeze; - - ELM_DATETIME_DATA_GET(obj, sd); - - freeze = sd->freeze_sizing; - sd->freeze_sizing = EINA_TRUE; - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - snprintf(buf, sizeof(buf), EDC_PART_FIELD_STR, field->location); - - if (field->visible && field->fmt_exist) - { - evas_object_hide(elm_layout_content_unset(obj, buf)); - elm_layout_content_set(obj, buf, field->item_obj); - } - else - evas_object_hide(elm_layout_content_unset(obj, buf)); - } - sd->freeze_sizing = freeze; - - elm_layout_sizing_eval(obj); - _field_list_display(obj); -} - -static unsigned int -_parse_format(Evas_Object *obj, - char *fmt_ptr) -{ - Eina_Bool fmt_parsing = EINA_FALSE, sep_parsing = EINA_FALSE, - sep_lookup = EINA_FALSE; - unsigned int len = 0, idx = 0, location = 0; - char separator[MAX_SEPARATOR_LEN]; - Datetime_Field *field = NULL; - char cur; - - ELM_DATETIME_DATA_GET(obj, sd); - - while ((cur = *fmt_ptr)) - { - if (fmt_parsing) - { - if (cur == '_' || cur == '-' || cur == '0' || cur == '^' || cur == '#') - { - fmt_ptr++; - continue; - } - fmt_parsing = EINA_FALSE; - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - if (strchr(mapping[idx].fmt_char, cur)) - { - field = sd->field_list + idx; - /* ignore the fields already have or disabled - * valid formats, means already parsed & - * repeated, ignore. */ - if (field->location != -1) break; - field->fmt[1] = cur; - field->fmt_exist = EINA_TRUE; - field->location = location++; - sep_lookup = EINA_TRUE; - len = 0; - break; - } - } - } - if (cur == '%') - { - fmt_parsing = EINA_TRUE; - sep_parsing = EINA_FALSE; - // set the separator to previous field - separator[len] = 0; - if (field) eina_stringshare_replace(&field->separator, separator); - } - // ignore the set of chars (global, field specific) as field separators - if (sep_parsing && - (len < MAX_SEPARATOR_LEN - 1) && - (field->type != ELM_DATETIME_AMPM) && - (!strchr(ignore_separators, cur)) && - (!strchr(mapping[idx].ignore_sep, cur))) - separator[len++] = cur; - if (sep_lookup) sep_parsing = EINA_TRUE; - sep_lookup = EINA_FALSE; - fmt_ptr++; - } - // return the number of valid fields parsed. - return location; -} - -static void -_reload_format(Evas_Object *obj) -{ - unsigned int idx, field_count; - Datetime_Field *field; - char buf[BUFFER_SIZE]; - char *dt_fmt; - - ELM_DATETIME_DATA_GET(obj, sd); - ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); - - // FIXME: provide nl_langinfo on Windows if possible - // fetch the default format from Libc. - if (!sd->user_format) -#if defined(HAVE_LANGINFO_H) || defined (HAVE_EVIL) - strncpy(sd->format, nl_langinfo(D_T_FMT), ELM_DATETIME_MAX_FORMAT_LEN); -#else - strncpy(sd->format, "", ELM_DATETIME_MAX_FORMAT_LEN); -#endif - sd->format[ELM_DATETIME_MAX_FORMAT_LEN - 1] = '\0'; - - dt_fmt = (char *)malloc(ELM_DATETIME_MAX_FORMAT_LEN); - if (!dt_fmt) return; - - strncpy(dt_fmt, sd->format, ELM_DATETIME_MAX_FORMAT_LEN); - - _expand_format(dt_fmt); - - // reset all the fields to disable state - sd->enabled_field_count = 0; - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - field->fmt_exist = EINA_FALSE; - field->location = -1; - } - - field_count = _parse_format(obj, dt_fmt); - free(dt_fmt); - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - if (field->fmt_exist && field->visible) - sd->enabled_field_count++; - } - - // assign locations to disabled fields for uniform usage - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - if (field->location == -1) field->location = field_count++; - - if (field->fmt_exist && field->visible) - { - snprintf(buf, sizeof(buf), EDC_PART_FIELD_ENABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - } - else - { - snprintf(buf, sizeof(buf), EDC_PART_FIELD_DISABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - } - snprintf - (buf, sizeof(buf), EDC_PART_SEPARATOR_STR, (field->location + 1)); - elm_layout_text_set(obj, buf, field->separator); - } - - edje_object_message_signal_process(wd->resize_obj); - _field_list_arrange(obj); -} - -EOLIAN static Eina_Bool -_elm_datetime_elm_widget_translate(Eo *obj, Elm_Datetime_Data *sd) -{ - if (!sd->user_format) _reload_format(obj); - else _field_list_display(obj); - - elm_obj_widget_translate(efl_super(obj, MY_CLASS)); - - return EINA_TRUE; -} - -static Eina_List * -_datetime_items_get(const Evas_Object *obj) -{ - Eina_List *items = NULL; - Datetime_Field *field; - unsigned int idx; - Datetime_Field *sorted_fields[ELM_DATETIME_TYPE_COUNT]; - - ELM_DATETIME_DATA_GET(obj, sd); - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - sorted_fields[field->location] = field; - } - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sorted_fields[idx]; - if (field->fmt_exist && field->visible) - items = eina_list_append(items, field->item_obj); - } - - // ACCESS - if (_elm_config->access_mode == ELM_ACCESS_MODE_ON) - items = eina_list_append(items, sd->access_obj); - - return items; -} - -EOLIAN static Eina_Bool -_elm_datetime_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Datetime_Data *_pd EINA_UNUSED) -{ - return EINA_TRUE; -} - -EOLIAN static Eina_Bool -_elm_datetime_elm_widget_focus_next(Eo *obj, Elm_Datetime_Data *_pd EINA_UNUSED, Elm_Focus_Direction dir, Evas_Object **next, Elm_Object_Item **next_item) -{ - const Eina_List *items; - Eina_List *(*list_free)(Eina_List *list); - void *(*list_data_get)(const Eina_List *list); - - Eina_Bool int_ret; - - if ((items = elm_widget_focus_custom_chain_get(obj))) - { - list_data_get = eina_list_data_get; - list_free = NULL; - } - else - { - items = _datetime_items_get(obj); - list_data_get = eina_list_data_get; - list_free = eina_list_free; - if (!items) return EINA_FALSE; - } - - int_ret = elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next, next_item); - if (list_free) list_free((Eina_List *)items); - - return int_ret; -} - -EOLIAN static Eina_Bool -_elm_datetime_elm_widget_on_focus(Eo *obj, Elm_Datetime_Data *sd, Elm_Object_Item *item EINA_UNUSED) -{ - Eina_Bool int_ret = EINA_FALSE; - - int_ret = elm_obj_widget_on_focus(efl_super(obj, MY_CLASS), NULL); - if (!int_ret) return EINA_FALSE; - - if (!elm_widget_focus_get(obj)) - { - if ((dt_mod) && (dt_mod->obj_hide)) - dt_mod->obj_hide(sd->mod_data); - } - - return EINA_TRUE; -} - -EOLIAN static Eina_Bool -_elm_datetime_elm_widget_disable(Eo *obj, Elm_Datetime_Data *sd) -{ - Datetime_Field *field; - unsigned int idx = 0; - Eina_Bool int_ret = EINA_FALSE; - - int_ret = elm_obj_widget_disable(efl_super(obj, MY_CLASS)); - if (!int_ret) return EINA_FALSE; - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - elm_object_disabled_set(field->item_obj, elm_object_disabled_get(obj)); - } - return EINA_TRUE; -} - -EOLIAN static void -_elm_datetime_elm_layout_sizing_eval(Eo *obj, Elm_Datetime_Data *sd) -{ - Evas_Coord minw = -1, minh = -1; - - if (sd->freeze_sizing) return; - - ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); - - if (sd->enabled_field_count) - elm_coords_finger_size_adjust(sd->enabled_field_count, &minw, 1, &minh); - - edje_object_size_min_restricted_calc - (wd->resize_obj, &minw, &minh, minw, minh); - evas_object_size_hint_min_set(obj, minw, minh); - evas_object_size_hint_max_set(obj, -1, -1); -} - -EOLIAN static Elm_Theme_Apply -_elm_datetime_elm_widget_theme_apply(Eo *obj, Elm_Datetime_Data *sd) -{ - Elm_Theme_Apply int_ret = ELM_THEME_APPLY_FAILED; - - Datetime_Field *field; - char buf[BUFFER_SIZE]; - unsigned int idx; - - ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, ELM_THEME_APPLY_FAILED); - - int_ret = elm_obj_widget_theme_apply(efl_super(obj, MY_CLASS)); - if (!int_ret) return ELM_THEME_APPLY_FAILED; - - if ((!dt_mod) || (!dt_mod->field_value_display)) return int_ret; - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - if (field->fmt_exist && field->visible) - { - snprintf(buf, sizeof(buf), EDC_PART_FIELD_ENABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - - snprintf - (buf, sizeof(buf), EDC_PART_SEPARATOR_STR, field->location); - elm_layout_text_set(obj, buf, field->separator); - - dt_mod->field_value_display(sd->mod_data, field->item_obj); - } - else - { - snprintf(buf, sizeof(buf), EDC_PART_FIELD_DISABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - } - } - - edje_object_message_signal_process(wd->resize_obj); - elm_layout_sizing_eval(obj); - - return int_ret; -} - -static int -_max_days_get(int year, - int month) -{ - struct tm time1; - time_t t; - int day; - - t = time(NULL); - localtime_r(&t, &time1); - time1.tm_year = year; - time1.tm_mon = month; - for (day = MIN_DAYS_IN_MONTH; day <= mapping[ELM_DATETIME_DATE].def_max; - day++) - { - time1.tm_mday = day; - mktime(&time1); - /* To restrict month wrapping because of summer time in some locales, - * ignore day light saving mode in mktime(). */ - time1.tm_isdst = -1; - if (time1.tm_mday == 1) break; - } - day--; - - return day; -} - -static Eina_Bool -_date_cmp(const struct tm *time1, - const struct tm *time2) -{ - unsigned int idx; - - const DATETIME_TM_ARRAY(timearr1, time1); - const DATETIME_TM_ARRAY(timearr2, time2); - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - if (*timearr1[idx] != *timearr2[idx]) - return EINA_FALSE; - } - - return EINA_TRUE; -} - -static Eina_Bool -_field_cmp(Elm_Datetime_Field_Type field_type, - struct tm *time1, - struct tm *time2) -{ - DATETIME_TM_ARRAY(timearr1, time1); - DATETIME_TM_ARRAY(timearr2, time2); - - if (*timearr1[field_type] != *timearr2[field_type]) - return EINA_FALSE; - else - return EINA_TRUE; -} - -// validates curr_time/min_limt/max_limit according to the newly set value -static void -_validate_datetime_limits(struct tm *time1, - struct tm *time2, - Eina_Bool swap) -{ - struct tm *t1, *t2; - unsigned int idx; - - if (!time1 || !time2) return; - - t1 = (swap) ? time2 : time1; - t2 = (swap) ? time1 : time2; - - DATETIME_TM_ARRAY(timearr1, time1); - DATETIME_TM_ARRAY(timearr2, time2); - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT - 1; idx++) - { - if (*timearr1[idx] < *timearr2[idx]) - { - memcpy(t1, t2, sizeof(struct tm)); - break; - } - else if (*timearr1[idx] > *timearr2[idx]) - break; - } -} - -static void -_apply_field_limits(Evas_Object *obj) -{ - Datetime_Field *field; - unsigned int idx = 0; - int val; - - ELM_DATETIME_DATA_GET(obj, sd); - - DATETIME_TM_ARRAY(timearr, &sd->curr_time); - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT - 1; idx++) - { - field = sd->field_list + idx; - val = *timearr[idx]; - if (val < field->min) - *timearr[idx] = field->min; - else if (val > field->max) - *timearr[idx] = field->max; - } - - _field_list_display(obj); -} - -static void -_apply_range_restrictions(struct tm *tim) -{ - unsigned int idx; - int val, min, max; - - if (!tim) return; - - DATETIME_TM_ARRAY(timearr, tim); - for (idx = ELM_DATETIME_MONTH; idx < ELM_DATETIME_TYPE_COUNT - 1; idx++) - { - val = *timearr[idx]; - min = mapping[idx].def_min; - max = mapping[idx].def_max; - if (idx == ELM_DATETIME_DATE) - max = _max_days_get(tim->tm_year, tim->tm_mon); - if (val < min) - *timearr[idx] = min; - else if (val > max) - *timearr[idx] = max; - } -} - -static const char * -_field_format_get(Evas_Object *obj, - Elm_Datetime_Field_Type field_type) -{ - Datetime_Field *field; - - if (field_type > ELM_DATETIME_AMPM) return NULL; - - ELM_DATETIME_DATA_GET(obj, sd); - - field = sd->field_list + field_type; - - return field->fmt; -} - -static void -_field_limit_get(Evas_Object *obj, - Elm_Datetime_Field_Type field_type, - int *range_min, - int *range_max) -{ - int min, max, max_days; - Datetime_Field *field; - unsigned int idx; - - if (field_type > ELM_DATETIME_MINUTE) return; - - ELM_DATETIME_DATA_GET(obj, sd); - - field = sd->field_list + field_type; - - min = field->min; - max = field->max; - - DATETIME_TM_ARRAY(curr_timearr, &sd->curr_time); - DATETIME_TM_ARRAY(min_timearr, &sd->min_limit); - DATETIME_TM_ARRAY(max_timearr, &sd->max_limit); - - for (idx = 0; idx < field->type; idx++) - if (*curr_timearr[idx] > *min_timearr[idx]) break; - if ((idx == field_type) && (min < *min_timearr[field_type])) - min = *min_timearr[field_type]; - if (field_type == ELM_DATETIME_DATE) - { - max_days = _max_days_get(sd->curr_time.tm_year, sd->curr_time.tm_mon); - if (max > max_days) max = max_days; - } - for (idx = 0; idx < field->type; idx++) - if (*curr_timearr[idx] < *max_timearr[idx]) break; - if ((idx == field_type) && (max > *max_timearr[field_type])) - max = *max_timearr[field_type]; - - *range_min = min; - *range_max = max; -} - -static void -_field_list_init(Evas_Object *obj) -{ - Datetime_Field *field; - unsigned int idx; - time_t t; - - ELM_DATETIME_DATA_GET(obj, sd); - - t = time(NULL); - localtime_r(&t, &sd->curr_time); - - mapping[ELM_DATETIME_YEAR].def_min = _elm_config->year_min; - mapping[ELM_DATETIME_YEAR].def_max = _elm_config->year_max; - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = sd->field_list + idx; - field->type = ELM_DATETIME_YEAR + idx; - field->fmt[0] = '%'; - field->fmt_exist = EINA_FALSE; - field->visible = EINA_TRUE; - field->min = mapping[idx].def_min; - field->max = mapping[idx].def_max; - } - DATETIME_TM_ARRAY(min_timearr, &sd->min_limit); - DATETIME_TM_ARRAY(max_timearr, &sd->max_limit); - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT - 1; idx++) - { - *min_timearr[idx] = mapping[idx].def_min; - *max_timearr[idx] = mapping[idx].def_max; - } -} - -static char * -_access_info_cb(void *data, Evas_Object *obj EINA_UNUSED) -{ - char *ret; - Eina_Strbuf *buf; - buf = eina_strbuf_new(); - - ELM_DATETIME_DATA_GET(data, sd); - eina_strbuf_append_printf(buf, - "%d year, %d month, %d date, %d hour, %d minute", - sd->curr_time.tm_year, sd->curr_time.tm_mon + 1, - sd->curr_time.tm_mday, sd->curr_time.tm_hour, - sd->curr_time.tm_min); - - ret = eina_strbuf_string_steal(buf); - eina_strbuf_free(buf); - return ret; -} - -EOLIAN static void -_elm_datetime_efl_canvas_group_group_add(Eo *obj, Elm_Datetime_Data *priv) -{ - Datetime_Field *field; - int idx; - - efl_canvas_group_add(efl_super(obj, MY_CLASS)); - elm_widget_sub_object_parent_add(obj); - - // module - initialise module for datetime - if (!dt_mod) dt_mod = _dt_mod_init(); - if (dt_mod) - { - if (dt_mod->obj_hook) - { - priv->mod_data = dt_mod->obj_hook(obj); - - // update module data - if (priv->mod_data) - { - priv->mod_data->base = obj; - priv->mod_data->field_limit_get = _field_limit_get; - priv->mod_data->field_format_get = _field_format_get; - } - } - - if (dt_mod->field_create) - { - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - field = priv->field_list + idx; - field->item_obj = dt_mod->field_create(priv->mod_data, idx); - } - } - } - - priv->freeze_sizing = EINA_TRUE; - if (!elm_layout_theme_set(obj, "datetime", "base", - elm_widget_style_get(obj))) - CRI("Failed to set layout!"); - - _field_list_init(obj); - _reload_format(obj); - - elm_widget_can_focus_set(obj, EINA_TRUE); - - priv->freeze_sizing = EINA_FALSE; - elm_layout_sizing_eval(obj); - - // ACCESS - if (_elm_config->access_mode == ELM_ACCESS_MODE_ON) - { - Elm_Access_Info *ai; - - priv->access_obj = _elm_access_edje_object_part_object_register - (obj, elm_layout_edje_get(obj), "elm.access"); - if (!priv->access_obj) - priv->access_obj = _elm_access_edje_object_part_object_register - (obj, elm_layout_edje_get(obj), "access"); - - ai = _elm_access_info_get(priv->access_obj); - _elm_access_text_set(ai, ELM_ACCESS_TYPE, "date time"); - _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, obj); - } -} - -EOLIAN static void -_elm_datetime_efl_canvas_group_group_del(Eo *obj, Elm_Datetime_Data *sd) -{ - Datetime_Field *tmp; - unsigned int idx; - - for (idx = 0; idx < ELM_DATETIME_TYPE_COUNT; idx++) - { - tmp = sd->field_list + idx; - evas_object_del(tmp->item_obj); - eina_stringshare_del(tmp->separator); - } - - if ((dt_mod) && (dt_mod->obj_unhook)) - dt_mod->obj_unhook(sd->mod_data); // module - unhook - - efl_canvas_group_del(efl_super(obj, MY_CLASS)); -} +#include "elm_datetime.h" EAPI Evas_Object * elm_datetime_add(Evas_Object *parent) { EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); - Evas_Object *obj = efl_add(MY_CLASS, parent); + Evas_Object *obj = efl_add(EFL_UI_CLOCK_CLASS, parent); return obj; } -EOLIAN static Eo * -_elm_datetime_efl_object_constructor(Eo *obj, Elm_Datetime_Data *_pd EINA_UNUSED) +EAPI void +elm_datetime_format_set(Evas_Object *obj, + const char *fmt) { - obj = efl_constructor(efl_super(obj, MY_CLASS)); - efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY); - evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks); - elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_DATE_EDITOR); - - return obj; + efl_ui_clock_format_set(obj, fmt); } -EOLIAN static const char* -_elm_datetime_format_get(Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd) +EAPI const char * +elm_datetime_format_get(const Evas_Object *obj) { - return sd->format; + return efl_ui_clock_format_get(obj); } -EOLIAN static void -_elm_datetime_format_set(Eo *obj, Elm_Datetime_Data *sd, const char *fmt) +EAPI void +elm_datetime_field_limit_set(Evas_Object *obj, Elm_Datetime_Field_Type type, int min, int max) { - if (fmt) - { - strncpy(sd->format, fmt, ELM_DATETIME_MAX_FORMAT_LEN); - sd->format[ELM_DATETIME_MAX_FORMAT_LEN - 1] = '\0'; - sd->user_format = EINA_TRUE; - } - else sd->user_format = EINA_FALSE; - - _reload_format(obj); + efl_ui_clock_field_limit_set(obj, type, min, max); } -EOLIAN static Eina_Bool -_elm_datetime_field_visible_get(const Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd, Elm_Datetime_Field_Type fieldtype) +EAPI void +elm_datetime_field_limit_get(const Evas_Object *obj, Elm_Datetime_Field_Type fieldtype, int *min, int *max) { - Datetime_Field *field; - - if (fieldtype > ELM_DATETIME_AMPM) return EINA_FALSE; - - field = sd->field_list + fieldtype; - - return field->visible; + efl_ui_clock_field_limit_get(obj, fieldtype, min, max); } -EOLIAN static void -_elm_datetime_field_visible_set(Eo *obj, Elm_Datetime_Data *sd, Elm_Datetime_Field_Type fieldtype, Eina_Bool visible) +EAPI Eina_Bool +elm_datetime_value_min_set(Evas_Object *obj, const Efl_Time *mintime) { - char buf[BUFFER_SIZE]; - Datetime_Field *field; - - if (fieldtype > ELM_DATETIME_AMPM) return; - - field = sd->field_list + fieldtype; - visible = !!visible; - if (field->visible == visible) return; - - field->visible = visible; - - sd->freeze_sizing = EINA_TRUE; - if (visible) - { - sd->enabled_field_count++; - - if (!field->fmt_exist) return; - - snprintf(buf, sizeof(buf), EDC_PART_FIELD_ENABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - - ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); - edje_object_message_signal_process(wd->resize_obj); - - snprintf(buf, sizeof(buf), EDC_PART_FIELD_STR, field->location); - elm_layout_content_unset(obj, buf); - elm_layout_content_set(obj, buf, field->item_obj); - } - else - { - sd->enabled_field_count--; - - if (!field->fmt_exist) return; - - snprintf(buf, sizeof(buf), EDC_PART_FIELD_DISABLE_SIG_STR, - field->location); - elm_layout_signal_emit(obj, buf, "elm"); - - ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); - edje_object_message_signal_process(wd->resize_obj); - - snprintf(buf, sizeof(buf), EDC_PART_FIELD_STR, field->location); - evas_object_hide(elm_layout_content_unset(obj, buf)); - } - sd->freeze_sizing = EINA_FALSE; - - elm_layout_sizing_eval(obj); - - if (!visible) return; - if (!dt_mod || !dt_mod->field_value_display) return; - - dt_mod->field_value_display(sd->mod_data, field->item_obj); + return efl_ui_clock_value_min_set(obj, (Efl_Time *)mintime); } -EOLIAN static void -_elm_datetime_field_limit_get(const Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd, Elm_Datetime_Field_Type fieldtype, int *min, int *max) +EAPI Eina_Bool +elm_datetime_value_min_get(const Evas_Object *obj, Efl_Time *mintime) { - Datetime_Field *field; - - if (fieldtype >= ELM_DATETIME_AMPM) return; - - field = sd->field_list + fieldtype; - if (min) *min = field->min; - if (max) *max = field->max; + return efl_ui_clock_value_min_get(obj, mintime); } -EOLIAN static void -_elm_datetime_field_limit_set(Eo *obj, Elm_Datetime_Data *sd, Elm_Datetime_Field_Type fieldtype, int min, int max) +EAPI Eina_Bool +elm_datetime_value_set(Evas_Object *obj, const Efl_Time *newtime) { - Datetime_Field *field; - struct tm old_time; - - if (fieldtype >= ELM_DATETIME_AMPM) return; - - if (min > max) return; - - old_time = sd->curr_time; - field = sd->field_list + fieldtype; - if (((min >= mapping[fieldtype].def_min) && - (min <= mapping[fieldtype].def_max)) || - (field->type == ELM_DATETIME_YEAR)) - field->min = min; - if (((max >= mapping[fieldtype].def_min) && - (max <= mapping[fieldtype].def_max)) || - (field->type == ELM_DATETIME_YEAR)) - field->max = max; - - _apply_field_limits(obj); - - if (!_field_cmp(fieldtype, &old_time, &sd->curr_time)) - efl_event_callback_legacy_call(obj, ELM_DATETIME_EVENT_CHANGED, NULL); - + return efl_ui_clock_value_set(obj, (Efl_Time *)newtime); } -EOLIAN static Eina_Bool -_elm_datetime_value_get(const Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd, struct tm *currtime) +EAPI Eina_Bool elm_datetime_value_get(const Evas_Object *obj, Efl_Time *currtime) { - EINA_SAFETY_ON_NULL_RETURN_VAL(currtime, EINA_FALSE); - - *currtime = sd->curr_time; - return EINA_TRUE; + return efl_ui_clock_value_get(obj, currtime); } -EOLIAN static Eina_Bool -_elm_datetime_value_set(Eo *obj, Elm_Datetime_Data *sd, const struct tm *newtime) +EAPI void +elm_datetime_field_visible_set(Evas_Object *obj, Elm_Datetime_Field_Type fieldtype, Eina_Bool visible) { - EINA_SAFETY_ON_NULL_RETURN_VAL(newtime, EINA_FALSE); - - if (_date_cmp(&sd->curr_time, newtime)) return EINA_TRUE; - sd->curr_time = *newtime; - // apply default field restrictions for curr_time - _apply_range_restrictions(&sd->curr_time); - // validate the curr_time according to the min_limt and max_limt - _validate_datetime_limits(&sd->curr_time, &sd->min_limit, EINA_FALSE); - _validate_datetime_limits(&sd->max_limit, &sd->curr_time, EINA_TRUE); - _apply_field_limits(obj); - - efl_event_callback_legacy_call(obj, ELM_DATETIME_EVENT_CHANGED, NULL); - - return EINA_TRUE; + efl_ui_clock_field_visible_set(obj, fieldtype, visible); } -EOLIAN static Eina_Bool -_elm_datetime_value_min_get(const Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd, struct tm *mintime) +EAPI Eina_Bool elm_datetime_field_visible_get(const Evas_Object *obj, Elm_Datetime_Field_Type fieldtype) { - EINA_SAFETY_ON_NULL_RETURN_VAL(mintime, EINA_FALSE); - - *mintime = sd->min_limit; - return EINA_TRUE; + return efl_ui_clock_field_visible_get(obj, fieldtype); } -EOLIAN static Eina_Bool -_elm_datetime_value_min_set(Eo *obj, Elm_Datetime_Data *sd, const struct tm *mintime) +EAPI Eina_Bool +elm_datetime_value_max_set(Evas_Object *obj, const Efl_Time *maxtime) { - struct tm old_time; - - EINA_SAFETY_ON_NULL_RETURN_VAL(mintime, EINA_FALSE); - - if (_date_cmp(&sd->min_limit, mintime)) return EINA_TRUE; - sd->min_limit = *mintime; - old_time = sd->curr_time; - // apply default field restrictions for min_limit - _apply_range_restrictions(&sd->min_limit); - // validate curr_time and max_limt according to the min_limit - _validate_datetime_limits(&sd->max_limit, &sd->min_limit, EINA_FALSE); - _validate_datetime_limits(&sd->curr_time, &sd->min_limit, EINA_FALSE); - _apply_field_limits(obj); - - if (!_date_cmp(&old_time, &sd->curr_time)) - efl_event_callback_legacy_call(obj, ELM_DATETIME_EVENT_CHANGED, NULL); - - return EINA_TRUE; + return efl_ui_clock_value_max_set(obj, (Efl_Time *)maxtime); } -EOLIAN static Eina_Bool -_elm_datetime_value_max_get(const Eo *obj EINA_UNUSED, Elm_Datetime_Data *sd, struct tm *maxtime) +EAPI Eina_Bool +elm_datetime_value_max_get(const Evas_Object *obj, Efl_Time *maxtime) { - EINA_SAFETY_ON_NULL_RETURN_VAL(maxtime, EINA_FALSE); - - *maxtime = sd->max_limit; - return EINA_TRUE; + return efl_ui_clock_value_max_get(obj, maxtime); } - -EOLIAN static Eina_Bool -_elm_datetime_value_max_set(Eo *obj, Elm_Datetime_Data *sd, const struct tm *maxtime) -{ - struct tm old_time; - - EINA_SAFETY_ON_NULL_RETURN_VAL(maxtime, EINA_FALSE); - - if (_date_cmp(&sd->max_limit, maxtime)) return EINA_TRUE; - sd->max_limit = *maxtime; - old_time = sd->curr_time; - // apply default field restrictions for max_limit - _apply_range_restrictions(&sd->max_limit); - // validate curr_time and min_limt according to the max_limit - _validate_datetime_limits(&sd->max_limit, &sd->min_limit, EINA_TRUE); - _validate_datetime_limits(&sd->max_limit, &sd->curr_time, EINA_TRUE); - _apply_field_limits(obj); - - if (!_date_cmp(&old_time, &sd->curr_time)) - efl_event_callback_legacy_call(obj, ELM_DATETIME_EVENT_CHANGED, NULL); - - return EINA_TRUE; -} - -EOLIAN static void -_elm_datetime_class_constructor(Efl_Class *klass) -{ - evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass); -} - -#include "elm_datetime.eo.c" diff --git a/src/lib/elementary/elm_datetime.eo b/src/lib/elementary/elm_datetime.eo deleted file mode 100644 index f81b32c7b3..0000000000 --- a/src/lib/elementary/elm_datetime.eo +++ /dev/null @@ -1,309 +0,0 @@ -import efl_types; - -enum Elm.Datetime.Field_Type -{ - [[Identifies a Datetime field, The widget supports 6 fields : Year, month, - Date, Hour, Minute, AM/PM - ]] - - legacy: elm_datetime; - year = 0, [[Indicates Year field.]] - month = 1, [[Indicates Month field.]] - date = 2, [[Indicates Date field.]] - hour = 3, [[Indicates Hour field.]] - minute = 4, [[Indicates Minute field.]] - ampm = 5, [[Indicates AM/PM field .]] -} - -class Elm.Datetime (Elm.Layout) -{ - legacy_prefix: elm_datetime; - eo_prefix: elm_obj_datetime; - event_prefix: elm_datetime; - methods { - @property format { - set { - [[Set the datetime format. Format is a combination of allowed - Libc date format specifiers like: "%b %d, %Y %I : %M %p". - - Maximum allowed format length is 64 chars. - - Format can include separators for each individual datetime - field except for AM/PM field. - - Each separator can be a maximum of 6 UTF-8 bytes. - Space is also taken as a separator. - - These specifiers can be arranged in any order and the widget - will display the fields accordingly. - - Default format is taken as per the system locale settings. - ]] - /* FIXME-doc - Following are the allowed set of format specifiers for each datetime field. - - @b %%Y : The year as a decimal number including the century. - - @b %%y : The year as a decimal number without a century (range 00 to 99). - - @b %%m : The month as a decimal number (range 01 to 12). - - @b %%b : The abbreviated month name according to the current locale. - - @b %%B : The full month name according to the current locale. - - @b %%h : The abbreviated month name according to the current locale(same as %%b). - - @b %%d : The day of the month as a decimal number (range 01 to 31). - - @b %%e : The day of the month as a decimal number (range 1 to 31). single - digits are preceded by a blank. - - @b %%I : The hour as a decimal number using a 12-hour clock (range 01 to 12). - - @b %%H : The hour as a decimal number using a 24-hour clock (range 00 to 23). - - @b %%k : The hour (24-hour clock) as a decimal number (range 0 to 23). single - digits are preceded by a blank. - - @b %%l : The hour (12-hour clock) as a decimal number (range 1 to 12); single - digits are preceded by a blank. - - @b %%M : The minute as a decimal number (range 00 to 59). - - @b %%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'. - - @b %%P : Like %p but in lower case: 'am' or 'pm' or a corresponding string for - the current locale. - - @b %%c : The preferred date and time representation for the current locale. - - @b %%x : The preferred date representation for the current locale without the time. - - @b %%X : The preferred time representation for the current locale without the date. - - @b %%r : The complete calendar time using the AM/PM format of the current locale. - - @b %%R : The hour and minute in decimal numbers using the format %H:%M. - - @b %%T : The time of day in decimal numbers using the format %H:%M:%S. - - @b %%D : The date using the format %%m/%%d/%%y. - - @b %%F : The date using the format %%Y-%%m-%%d. - */ - } - get { - [[Get the datetime format.]] - } - values { - fmt: string @nullable; [[The datetime format.]] - } - } - field_limit_set { - [[Set the field limits of a field. - - Limits can be set to individual fields, independently, except - for AM/PM field. Any field can display the values only in between - these minimum and maximum limits unless the corresponding time - value is restricted from MinTime to MaxTime. That is, min/max - field limits always works under the limitations of mintime/maxtime. - - There is no provision to set the limits of AM/PM field. - ]] - params { - @in fieldtype: Elm.Datetime.Field_Type; [[Type of the field. #ELM_DATETIME_YEAR etc.]] - @in min: int; [[Reference to field's minimum value.]] - @in max: int; [[Reference to field's maximum value.]] - } - } - field_limit_get @const { - [[ Get the field limits of a field. - - Limits can be set to individual fields, independently, except - for AM/PM field. Any field can display the values only in between - these minimum and maximum limits unless the corresponding time - value is restricted from MinTime to MaxTime. That is, min/max - field limits always works under the limitations of mintime/maxtime. - - There is no provision to set the limits of AM/PM field. - ]] - params { - @in fieldtype: Elm.Datetime.Field_Type; [[Type of the field. #ELM_DATETIME_YEAR etc.]] - @out min: int; [[Reference to field's minimum value.]] - @out max: int; [[Reference to field's maximum value.]] - } - } - value_min_set { - [[Set the lower boundary of a field. - - 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 is from 0 to 59. - ]] - - return: bool; [[$true if minimum value is accepted.]] - params { - @in mintime: const(Efl.Time)*; [[Time structure containing the minimum time value.]] - } - } - value_min_get @const { - [[Get the lower boundary of a field. - - 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 is from 0 to 59. - ]] - return: bool; [[$true if minimum value is successfully returned.]] - params { - @inout mintime: Efl.Time; [[Time structure.]] - } - } - value_set { - [[Set the current value of a Datetime object. - - 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 is from 0 to 59. - ]] - return: bool; [[$true if current time is set successfully.]] - params { - @in newtime: const(Efl.Time)*; [[Time structure filled with values to be set.]] - } - } - value_get @const { - [[Get the current value of a Datetime object. - - 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 is from 0 to 59. - ]] - return: bool; [[$true if current time is returned successfully.]] - params { - @inout currtime: Efl.Time; [[Time structure.]] - } - } - field_visible_set { - [[Set a field to be visible or not. - - Setting this API to $true does not ensure that the field is - visible, apart from this, the field's format must be present - in Datetime overall format. If a field's visibility is set - to $false then it won't appear even though its format is - present in overall format. So if and only if this API is - set true and the corresponding field's format is present - in Datetime format, the field is visible. - - By default the field visibility is set to $true. - ]] - params { - @in fieldtype: Elm.Datetime.Field_Type; [[Type of the field. #ELM_DATETIME_YEAR etc.]] - @in visible: bool; [[$true field can be visible, $false otherwise.]] - } - } - field_visible_get @const { - [[ Get whether a field can be visible/not.]] - return: bool; [[$true, if field can be visible. $false otherwise.]] - params { - @in fieldtype: Elm.Datetime.Field_Type; [[Type of the field. #ELM_DATETIME_YEAR etc.]] - } - } - value_max_set { - [[Set the upper boundary of a field. - - 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 is from 0 to 59. - ]] - return: bool; [[$true if maximum value is accepted.]] - params { - @in maxtime: const(Efl.Time)*; [[Time structure containing the maximum time value.]] - } - } - value_max_get @const { - [[Get the upper boundary of a field. - - 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 is from 0 to 59. - ]] - return: bool; [[$true if maximum value is returned successfully.]] - params { - @inout maxtime: Efl.Time; [[Time structure containing the maximum time value.]] - } - } - } - implements { - class.constructor; - Efl.Object.constructor; - Efl.Canvas.Group.group_add; - Efl.Canvas.Group.group_del; - Elm.Widget.theme_apply; - Elm.Widget.focus_next_manager_is; - Elm.Widget.focus_next; - Elm.Widget.disable; - Elm.Widget.on_focus; - Elm.Widget.translate; - Elm.Layout.sizing_eval; - } - events { - changed; - } - -} diff --git a/src/lib/elementary/elm_datetime.h b/src/lib/elementary/elm_datetime.h index 48c7ac42d3..9a111a1be9 100644 --- a/src/lib/elementary/elm_datetime.h +++ b/src/lib/elementary/elm_datetime.h @@ -196,12 +196,272 @@ * @{ */ -#include "elm_datetime_common.h" -#ifdef EFL_EO_API_SUPPORT -#include "elm_datetime_eo.h" -#endif -#ifndef EFL_NOLEGACY_API_SUPPORT -#include "elm_datetime_legacy.h" +/** Identifies a Datetime field, The widget supports 6 fields : Year, month, + ** Date, Hour, Minute, AM/PM + ** + ** @ingroup Elm_Datetime + **/ + +#ifndef _ELM_DATE_TIME_H +#define _ELM_DATE_TIME_H +typedef enum +{ + ELM_DATETIME_YEAR = 0, /**< Indicates Year field. */ + ELM_DATETIME_MONTH = 1, /**< Indicates Month field. */ + ELM_DATETIME_DATE = 2, /**< Indicates Date field. */ + ELM_DATETIME_HOUR = 3, /**< Indicates Hour field. */ + ELM_DATETIME_MINUTE = 4, /**< Indicates Minute field. */ + ELM_DATETIME_AMPM = 5 /**< Indicates AM/PM field . */ +} Elm_Datetime_Field_Type; + +/** + * @brief Adds a new datetime Widget + * + * The default datetime format and corresponding strings are based on current locale. + * + * @param parent The parent object + * @return The new object or NULL if it cannot be created + * + * This function inserts a new datetime widget on the canvas. + * + * @ingroup Elm_Datetime + */ +EAPI Evas_Object *elm_datetime_add(Evas_Object *parent); + +/** + * @brief Set the datetime format. Format is a combination of allowed Libc date + * format specifiers like: "%b %d, %Y %I : %M %p". + * + * Maximum allowed format length is 64 chars. + * + * Format can include separators for each individual datetime field except for + * AM/PM field. + * + * Each separator can be a maximum of 6 UTF-8 bytes. Space is also taken as a + * separator. + * + * These specifiers can be arranged in any order and the widget will display + * the fields accordingly. + * + * Default format is taken as per the system locale settings. + * + * @param[in] fmt The datetime format. + * + * @ingroup Elm_Datetime + */ +EAPI void elm_datetime_format_set(Evas_Object *obj, const char *fmt); + +/** + * @brief Get the datetime format. + * + * @return The datetime format. + * + * @ingroup Elm_Datetime + */ +EAPI const char *elm_datetime_format_get(const Evas_Object *obj); + +/** + * @brief Set the field limits of a field. + * + * Limits can be set to individual fields, independently, except for AM/PM + * field. Any field can display the values only in between these minimum and + * maximum limits unless the corresponding time value is restricted from + * MinTime to MaxTime. That is, min/max field limits always works under the + * limitations of mintime/maxtime. + * + * There is no provision to set the limits of AM/PM field. + * + * @param[in] fieldtype Type of the field. #ELM_DATETIME_YEAR etc. + * @param[in] min Reference to field's minimum value. + * @param[in] max Reference to field's maximum value. + * + * @ingroup Elm_Datetime + */ +EAPI void elm_datetime_field_limit_set(Evas_Object *obj, Elm_Datetime_Field_Type type, int min, int max); + +/** + * @brief Get the field limits of a field. + * + * Limits can be set to individual fields, independently, except for AM/PM + * field. Any field can display the values only in between these minimum and + * maximum limits unless the corresponding time value is restricted from + * MinTime to MaxTime. That is, min/max field limits always works under the + * limitations of mintime/maxtime. + * + * There is no provision to set the limits of AM/PM field. + * + * @param[in] fieldtype Type of the field. #ELM_DATETIME_YEAR etc. + * @param[out] min Reference to field's minimum value. + * @param[out] max Reference to field's maximum value. + * + * @ingroup Elm_Datetime + */ +EAPI void elm_datetime_field_limit_get(const Evas_Object *obj, Elm_Datetime_Field_Type fieldtype, int *min, int *max); + +/** + * @brief Set the lower boundary of a field. + * + * 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 is from 0 to 59. + * + * @param[in] mintime Time structure containing the minimum time value. + * + * @return @c true if minimum value is accepted. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_min_set(Evas_Object *obj, const Efl_Time *mintime); + +/** + * @brief Get the lower boundary of a field. + * + * 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 is from 0 to 59. + * + * @param[in,out] mintime Time structure. + * + * @return @c true if minimum value is successfully returned. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_min_get(const Evas_Object *obj, Efl_Time *mintime); + +/** + * @brief Set the current value of a Datetime object. + * + * 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 is from 0 to 59. + * + * @param[in] newtime Time structure filled with values to be set. + * + * @return @c true if current time is set successfully. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_set(Evas_Object *obj, const Efl_Time *newtime); + +/** + * @brief Get the current value of a Datetime object. + * + * 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 is from 0 to 59. + * + * @param[in,out] currtime Time structure. + * + * @return @c true if current time is returned successfully. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_get(const Evas_Object *obj, Efl_Time *currtime); + +/** + * @brief Set a field to be visible or not. + * + * Setting this API to @c true does not ensure that the field is visible, apart + * from this, the field's format must be present in Datetime overall format. + * If a field's visibility is set to @c false then it won't appear even though + * its format is present in overall format. So if and only if this API is set + * true and the corresponding field's format is present in Datetime format, the + * field is visible. + * + * By default the field visibility is set to @c true. + * + * @param[in] fieldtype Type of the field. #ELM_DATETIME_YEAR etc. + * @param[in] visible @c true field can be visible, @c false otherwise. + * + * @ingroup Elm_Datetime + */ +EAPI void elm_datetime_field_visible_set(Evas_Object *obj, Elm_Datetime_Field_Type fieldtype, Eina_Bool visible); + +/** + * @brief Get whether a field can be visible/not. + * + * @param[in] fieldtype Type of the field. #ELM_DATETIME_YEAR etc. + * + * @return @c true, if field can be visible. @c false otherwise. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_field_visible_get(const Evas_Object *obj, Elm_Datetime_Field_Type fieldtype); + +/** + * @brief Set the upper boundary of a field. + * + * 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 is from 0 to 59. + * + * @param[in] maxtime Time structure containing the maximum time value. + * + * @return @c true if maximum value is accepted. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_max_set(Evas_Object *obj, const Efl_Time *maxtime); + +/** + * @brief Get the upper boundary of a field. + * + * 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 is from 0 to 59. + * + * @param[in,out] maxtime Time structure containing the maximum time value. + * + * @return @c true if maximum value is returned successfully. + * + * @ingroup Elm_Datetime + */ +EAPI Eina_Bool elm_datetime_value_max_get(const Evas_Object *obj, Efl_Time *maxtime); + +#define ELM_DATETIME_EVENT_CHANGED EFL_UI_CLOCK_EVENT_CHANGED + #endif /** * @} diff --git a/src/lib/elementary/elm_datetime_common.h b/src/lib/elementary/elm_datetime_common.h deleted file mode 100644 index af246c817a..0000000000 --- a/src/lib/elementary/elm_datetime_common.h +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @addtogroup Elm_Datetime - * - * @{ - */ - -/** - * @} - */ diff --git a/src/lib/elementary/elm_datetime_eo.h b/src/lib/elementary/elm_datetime_eo.h deleted file mode 100644 index 0bb9a70d89..0000000000 --- a/src/lib/elementary/elm_datetime_eo.h +++ /dev/null @@ -1 +0,0 @@ -#include "elm_datetime.eo.h" \ No newline at end of file diff --git a/src/lib/elementary/elm_datetime_legacy.h b/src/lib/elementary/elm_datetime_legacy.h deleted file mode 100644 index 7cf1397191..0000000000 --- a/src/lib/elementary/elm_datetime_legacy.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @brief Adds a new datetime Widget - * - * The default datetime format and corresponding strings are based on current locale. - * - * @param parent The parent object - * @return The new object or NULL if it cannot be created - * - * This function inserts a new datetime widget on the canvas. - * - * @ingroup Elm_Datetime - */ -EAPI Evas_Object *elm_datetime_add(Evas_Object *parent); - -#include "elm_datetime.eo.legacy.h" diff --git a/src/lib/elementary/elm_widget_datetime.h b/src/lib/elementary/elm_widget_datetime.h deleted file mode 100644 index 8e735848ac..0000000000 --- a/src/lib/elementary/elm_widget_datetime.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef ELM_WIDGET_DATETIME_H -#define ELM_WIDGET_DATETIME_H - -#include "Elementary.h" - -/* DO NOT USE THIS HEADER UNLESS YOU ARE PREPARED FOR BREAKING OF YOUR - * CODE. THIS IS ELEMENTARY'S INTERNAL WIDGET API (for now) AND IS NOT - * FINAL. CALL elm_widget_api_check(ELM_INTERNAL_API_VERSION) TO CHECK - * IT AT RUNTIME. - */ - -/** - * @addtogroup Widget - * @{ - * - * @section elm-datetime-class The Elementary Datetime Class - * - * Elementary, besides having the @ref Datetime widget, exposes its - * foundation -- the Elementary Datetime Class -- in order to create other - * widgets which are a datetime with some more logic on top. - */ - -/** - * Base layout smart data extended with datetime instance data. - */ -typedef struct _Elm_Datetime_Module_Data Elm_Datetime_Module_Data; -typedef struct _Elm_Datetime_Data Elm_Datetime_Data; -typedef struct _Datetime_Field Datetime_Field; -typedef struct _Datetime_Mod_Api Datetime_Mod_Api; -typedef struct _Format_Map Format_Map; - -#define ELM_DATETIME_TYPE_COUNT 6 -#define ELM_DATETIME_MAX_FORMAT_LEN 64 -#define ELM_DATETIME_MAX_FIELD_FORMAT_LEN 3 - -struct _Elm_Datetime_Module_Data -{ - Evas_Object *base; - void (*field_limit_get)(Evas_Object *obj, - Elm_Datetime_Field_Type field_type, - int *range_min, - int *range_max); - const char *(*field_format_get)(Evas_Object * obj, - Elm_Datetime_Field_Type field_type); -}; - -struct _Datetime_Field -{ - Evas_Object *item_obj; - char fmt[ELM_DATETIME_MAX_FIELD_FORMAT_LEN]; - Elm_Datetime_Field_Type type; - const char *separator; - int location; /* location of the field as per - * current format */ - int min, max; - Eina_Bool fmt_exist : 1; /* whether field format is - * present or not */ - Eina_Bool visible : 1; /* whether field can be - * visible or not */ -}; - -struct _Datetime_Mod_Api -{ - Elm_Datetime_Module_Data *(*obj_hook)(Evas_Object * obj); - void (*obj_unhook)(Elm_Datetime_Module_Data *mdata); - void (*obj_hide)(Elm_Datetime_Module_Data *mdata); - Evas_Object *(*field_create)(Elm_Datetime_Module_Data * mdata, - Elm_Datetime_Field_Type ftype); - void (*field_value_display)(Elm_Datetime_Module_Data - *mdata, - Evas_Object *obj); -}; - -struct _Elm_Datetime_Data -{ - /* fixed set of fields. */ - Datetime_Field field_list[ELM_DATETIME_TYPE_COUNT]; - struct tm curr_time, min_limit, max_limit; - Elm_Datetime_Module_Data *mod_data; - char format[ELM_DATETIME_MAX_FORMAT_LEN]; - Evas_Object *access_obj; - int enabled_field_count; - Eina_Bool user_format : 1; /* whether user set - * format or default - * format. */ - Eina_Bool freeze_sizing : 1; /* freeze sizing_eval to - * reduce unnecessary sizing */ -}; - -struct _Format_Map -{ - char *fmt_char; - int def_min; - int def_max; - char *ignore_sep; -}; - -/** - * @} - */ - -#define ELM_DATETIME_DATA_GET(o, sd) \ - Elm_Datetime_Data * sd = efl_data_scope_get(o, ELM_DATETIME_CLASS) - -#define ELM_DATETIME_DATA_GET_OR_RETURN(o, ptr) \ - ELM_DATETIME_DATA_GET(o, ptr); \ - if (EINA_UNLIKELY(!ptr)) \ - { \ - CRI("No widget data for object %p (%s)", \ - o, evas_object_type_get(o)); \ - return; \ - } - -#define ELM_DATETIME_DATA_GET_OR_RETURN_VAL(o, ptr, val) \ - ELM_DATETIME_DATA_GET(o, ptr); \ - if (EINA_UNLIKELY(!ptr)) \ - { \ - CRI("No widget data for object %p (%s)", \ - o, evas_object_type_get(o)); \ - return val; \ - } - -#define ELM_DATETIME_CHECK(obj) \ - if (EINA_UNLIKELY(!efl_isa((obj), ELM_DATETIME_CLASS))) \ - return - -#endif diff --git a/src/modules/elementary/datetime_input_ctxpopup/datetime_input_ctxpopup.c b/src/modules/elementary/datetime_input_ctxpopup/datetime_input_ctxpopup.c deleted file mode 100644 index 7a15df41cf..0000000000 --- a/src/modules/elementary/datetime_input_ctxpopup/datetime_input_ctxpopup.c +++ /dev/null @@ -1,406 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "elementary_config.h" -#endif - -#include -#include "elm_widget.h" -#include "elm_widget_datetime.h" - -#define DATETIME_FIELD_COUNT 6 -#define FIELD_FORMAT_LEN 3 -#define DISKSELECTOR_MIN_ITEMS 4 -#define BUFF_SIZE 1024 - -typedef struct _Ctxpopup_Module_Data Ctxpopup_Module_Data; -typedef struct _DiskItem_Data DiskItem_Data; - -struct _Ctxpopup_Module_Data -{ - Elm_Datetime_Module_Data mod_data; - Evas_Object *ctxpopup; -}; - -struct _DiskItem_Data -{ - Ctxpopup_Module_Data *ctx_mod; - Elm_Datetime_Field_Type sel_field_type; - unsigned int sel_field_value; -}; - -static void -_diskselector_item_free_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - free(data); -} - -static void -_ctxpopup_dismissed_cb(void *data, const Efl_Event *event) -{ - Ctxpopup_Module_Data *ctx_mod; - ctx_mod = (Ctxpopup_Module_Data *)data; - evas_object_del(event->object); - ctx_mod->ctxpopup = NULL; -} - -static void -_datetime_resize_cb(void *data, Evas *e EINA_UNUSED,Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Ctxpopup_Module_Data *ctx_mod; - - ctx_mod = (Ctxpopup_Module_Data *)data; - if (!ctx_mod || !ctx_mod->ctxpopup) return; - - evas_object_hide(ctx_mod->ctxpopup); -} - -static void -_datetime_move_cb(void *data, Evas *e EINA_UNUSED,Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Ctxpopup_Module_Data *ctx_mod; - - ctx_mod = (Ctxpopup_Module_Data *)data; - if (!ctx_mod || !ctx_mod->ctxpopup) return; - - evas_object_hide(ctx_mod->ctxpopup); -} - -static void -_field_value_set(struct tm *tim, Elm_Datetime_Field_Type field_type, int val) -{ - if (field_type >= (DATETIME_FIELD_COUNT - 1)) return; - - int *timearr[]= { &tim->tm_year, &tim->tm_mon, &tim->tm_mday, &tim->tm_hour, &tim->tm_min }; - *timearr[field_type] = val; -} - -static int -_field_value_get(struct tm *tim, Elm_Datetime_Field_Type field_type) -{ - if (field_type >= (DATETIME_FIELD_COUNT - 1)) return -1; - - int *timearr[]= { &tim->tm_year, &tim->tm_mon, &tim->tm_mday, &tim->tm_hour, &tim->tm_min }; - return (*timearr[field_type]); -} - -static void -_diskselector_cb(void *data EINA_UNUSED, const Efl_Event *event) -{ - DiskItem_Data *disk_data; - struct tm curr_time; - const char *fmt; - - disk_data = (DiskItem_Data *)elm_object_item_data_get(event->info); - if (!disk_data || !(disk_data->ctx_mod)) - { - efl_event_callback_stop(event->object); - return; - } - - elm_datetime_value_get(disk_data->ctx_mod->mod_data.base, &curr_time); - fmt = disk_data->ctx_mod->mod_data.field_format_get(disk_data->ctx_mod->mod_data.base, disk_data->sel_field_type); - if ((disk_data->sel_field_type == ELM_DATETIME_HOUR) && ((!strncmp(fmt, "%I", FIELD_FORMAT_LEN)) || - (!strncmp(fmt, "%l", FIELD_FORMAT_LEN))) && (curr_time.tm_hour >= 12)) - disk_data->sel_field_value += 12; - _field_value_set(&curr_time, disk_data->sel_field_type, disk_data->sel_field_value); - elm_datetime_value_set(disk_data->ctx_mod->mod_data.base, &curr_time); - evas_object_hide(disk_data->ctx_mod->ctxpopup); -} - -static void -_ampm_clicked_cb(void *data, const Efl_Event *event EINA_UNUSED) -{ - Ctxpopup_Module_Data *ctx_mod; - struct tm curr_time; - - ctx_mod = (Ctxpopup_Module_Data *)data; - if (!ctx_mod) - { - efl_event_callback_stop(event->object); - return; - } - - elm_datetime_value_get(ctx_mod->mod_data.base, &curr_time); - if (curr_time.tm_hour >= 12) curr_time.tm_hour -= 12; - else curr_time.tm_hour += 12; - elm_datetime_value_set(ctx_mod->mod_data.base, &curr_time); -} - -static void -_field_clicked_cb(void *data, const Efl_Event *event) -{ - Ctxpopup_Module_Data *ctx_mod; - Evas_Object *diskselector; - Elm_Object_Item *item; - DiskItem_Data *disk_data; - Elm_Datetime_Field_Type field_type; - time_t t; - struct tm time1; - char buf[BUFF_SIZE], label[BUFF_SIZE]; - const char *fmt; - int idx, min, max, val; - unsigned int display_item_num, text_len = 0; - Evas_Coord x = 0, y = 0, w = 0, h = 0, width; - - ctx_mod = (Ctxpopup_Module_Data *)data; - if (!ctx_mod) - { - efl_event_callback_stop(event->object); - return; - } - - snprintf(buf, sizeof(buf), "datetime/%s", elm_object_style_get(event->object)); - - if (ctx_mod->ctxpopup) - evas_object_del(ctx_mod->ctxpopup); - ctx_mod->ctxpopup = elm_ctxpopup_add(event->object); - elm_object_style_set(ctx_mod->ctxpopup, buf); - elm_ctxpopup_horizontal_set(ctx_mod->ctxpopup, EINA_TRUE); - evas_object_size_hint_weight_set(ctx_mod->ctxpopup, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(ctx_mod->ctxpopup, EVAS_HINT_FILL, 0.5); - efl_event_callback_add - (ctx_mod->ctxpopup, ELM_CTXPOPUP_EVENT_DISMISSED, _ctxpopup_dismissed_cb, ctx_mod); - elm_ctxpopup_hover_parent_set(ctx_mod->ctxpopup, elm_widget_top_get(event->object)); - - diskselector = elm_diskselector_add(elm_widget_top_get(ctx_mod->mod_data.base)); - efl_event_callback_add - (diskselector, EFL_UI_EVENT_CLICKED, _diskselector_cb, NULL); - elm_object_style_set(diskselector, buf); - elm_object_content_set(ctx_mod->ctxpopup, diskselector); - - t = time(NULL); - localtime_r(&t, &time1); - - field_type = (Elm_Datetime_Field_Type )evas_object_data_get(event->object, "_field_type"); - fmt = ctx_mod->mod_data.field_format_get(ctx_mod->mod_data.base, field_type); - elm_datetime_value_get(ctx_mod->mod_data.base, &time1); - val = _field_value_get(&time1, field_type); - ctx_mod->mod_data.field_limit_get(ctx_mod->mod_data.base, field_type, &min, &max); - - time1.tm_mday = 1; // To avoid month wrapping, set the first day of the month to start with. - - if ((field_type == ELM_DATETIME_HOUR) && ((!strncmp(fmt, "%I", FIELD_FORMAT_LEN)) || - (!strncmp(fmt, "%l", FIELD_FORMAT_LEN)))) - { - if (max >= 12) max -= 12; - if (val >= 12) val -= 12; - if (min >= 12) min -= 12; - } - for (idx = min; idx <= max; idx++) - { - _field_value_set(&time1, field_type, idx); - strftime(label, BUFF_SIZE, fmt, &time1); - if (strlen(label) > text_len) text_len = strlen(label); - if (idx == val) - { - item = elm_diskselector_item_append(diskselector, label, NULL, NULL, NULL); - elm_diskselector_item_selected_set(item, EINA_TRUE); - } - else - { - disk_data = (DiskItem_Data *) malloc (sizeof(DiskItem_Data)); - disk_data->ctx_mod = ctx_mod; - disk_data->sel_field_type = field_type; - disk_data->sel_field_value = idx; - item = elm_diskselector_item_append(diskselector, label, NULL, NULL, disk_data); - elm_object_item_del_cb_set(item, _diskselector_item_free_cb); - } - } - elm_diskselector_side_text_max_length_set(diskselector, text_len); - - evas_object_geometry_get(event->object, &x, &y, &w, &h); - evas_object_geometry_get(elm_widget_top_get(ctx_mod->mod_data.base), NULL, NULL, &width, NULL); - evas_object_size_hint_min_set(ctx_mod->ctxpopup, width, -1); - display_item_num = width / (w + elm_config_finger_size_get()); - // always display even number of items to avoid autoselection - if (display_item_num % 2) display_item_num -= 1; - if (display_item_num < DISKSELECTOR_MIN_ITEMS) - display_item_num = DISKSELECTOR_MIN_ITEMS; - elm_diskselector_display_item_num_set(diskselector, display_item_num); - elm_diskselector_round_enabled_set(diskselector, EINA_TRUE); - - elm_ctxpopup_direction_priority_set(ctx_mod->ctxpopup, ELM_CTXPOPUP_DIRECTION_DOWN, - ELM_CTXPOPUP_DIRECTION_UP, -1, -1); - evas_object_move(ctx_mod->ctxpopup, (x+w/2), (y+h)); - - // if the direction of Ctxpopup is upwards, move it to the top of datetime - if (elm_ctxpopup_direction_get(ctx_mod->ctxpopup) == ELM_CTXPOPUP_DIRECTION_UP) - { - elm_ctxpopup_direction_priority_set(ctx_mod->ctxpopup, ELM_CTXPOPUP_DIRECTION_UP, - ELM_CTXPOPUP_DIRECTION_DOWN, -1, -1); - evas_object_move(ctx_mod->ctxpopup, (x + w / 2), y); - } - evas_object_show(ctx_mod->ctxpopup); -} - -static void -_access_set(Evas_Object *obj, Elm_Datetime_Field_Type field_type) -{ - const char* type = NULL; - - switch (field_type) - { - case ELM_DATETIME_YEAR: - type = "datetime field, year"; - break; - - case ELM_DATETIME_MONTH: - type = "datetime field, month"; - break; - - case ELM_DATETIME_DATE: - type = "datetime field, date"; - break; - - case ELM_DATETIME_HOUR: - type = "datetime field, hour"; - break; - - case ELM_DATETIME_MINUTE: - type = "datetime field, minute"; - break; - - case ELM_DATETIME_AMPM: - type = "datetime field, AM PM"; - break; - - default: - break; - } - - _elm_access_text_set - (_elm_access_info_get(obj), ELM_ACCESS_TYPE, type); - _elm_access_callback_set - (_elm_access_info_get(obj), ELM_ACCESS_STATE, NULL, NULL); -} - -// module funcs for the specific module type -EAPI void -field_value_display(Elm_Datetime_Module_Data *module_data, Evas_Object *obj) -{ - Ctxpopup_Module_Data *ctx_mod; - Elm_Datetime_Field_Type field_type; - struct tm tim; - char buf[BUFF_SIZE]; - const char *fmt; - - ctx_mod = (Ctxpopup_Module_Data *)module_data; - if (!ctx_mod || !obj) return; - - elm_datetime_value_get(ctx_mod->mod_data.base, &tim); - field_type = (Elm_Datetime_Field_Type )evas_object_data_get(obj, "_field_type"); - fmt = ctx_mod->mod_data.field_format_get(ctx_mod->mod_data.base, field_type); - buf[0] = 0; - strftime(buf, sizeof(buf), fmt, &tim); - if ((!buf[0]) && ((!strcmp(fmt, "%p")) || (!strcmp(fmt, "%P")))) - { - // yes BUFF_SIZE is more than 2 bytes! - if (tim.tm_hour < 12) strcpy(buf, "AM"); - else strcpy(buf, "PM"); - } - elm_object_text_set(obj, buf); -} - -EAPI Evas_Object * -field_create(Elm_Datetime_Module_Data *module_data, Elm_Datetime_Field_Type field_type) -{ - Ctxpopup_Module_Data *ctx_mod; - Evas_Object *field_obj; - - ctx_mod = (Ctxpopup_Module_Data *)module_data; - if (!ctx_mod) return NULL; - - if (field_type == ELM_DATETIME_AMPM) - { - field_obj = elm_button_add(ctx_mod->mod_data.base); - efl_event_callback_add - (field_obj, EFL_UI_EVENT_CLICKED, _ampm_clicked_cb, ctx_mod); - } - else - { - field_obj = elm_entry_add(ctx_mod->mod_data.base); - elm_entry_single_line_set(field_obj, EINA_TRUE); - elm_entry_editable_set(field_obj, EINA_FALSE); - elm_entry_input_panel_enabled_set(field_obj, EINA_FALSE); - elm_entry_context_menu_disabled_set(field_obj, EINA_TRUE); - efl_event_callback_add - (field_obj, EFL_UI_EVENT_CLICKED, _field_clicked_cb, ctx_mod); - } - evas_object_data_set(field_obj, "_field_type", (void *)field_type); - - // ACCESS - _access_set(field_obj, field_type); - - return field_obj; -} - -EAPI Elm_Datetime_Module_Data * -obj_hook(Evas_Object *obj) -{ - Ctxpopup_Module_Data *ctx_mod; - ctx_mod = calloc(1, sizeof(Ctxpopup_Module_Data)); - if (!ctx_mod) return NULL; - - evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, - _datetime_resize_cb, ctx_mod); - evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, - _datetime_move_cb, ctx_mod); - - return ((Elm_Datetime_Module_Data*)ctx_mod); -} - -EAPI void -obj_unhook(Elm_Datetime_Module_Data *module_data) -{ - Ctxpopup_Module_Data *ctx_mod; - - ctx_mod = (Ctxpopup_Module_Data *)module_data; - if (!ctx_mod) return; - - if (ctx_mod->ctxpopup) - evas_object_del(ctx_mod->ctxpopup); - - free(ctx_mod); - ctx_mod = NULL; -} - -EAPI void -obj_hide(Elm_Datetime_Module_Data *module_data) -{ - Ctxpopup_Module_Data *ctx_mod; - - ctx_mod = (Ctxpopup_Module_Data *)module_data; - if (!ctx_mod) return; - - if (ctx_mod->ctxpopup) - evas_object_hide(ctx_mod->ctxpopup); -} - -// module api funcs needed -EAPI int -elm_modapi_init(void *m EINA_UNUSED) -{ - return 1; // succeed always -} - -EAPI int -elm_modapi_shutdown(void *m EINA_UNUSED) -{ - return 1; // succeed always -} - -static Eina_Bool -_module_init(void) -{ - return EINA_TRUE; -} - -static void -_module_shutdown(void) -{ -} - -EINA_MODULE_INIT(_module_init); -EINA_MODULE_SHUTDOWN(_module_shutdown);