diff options
author | WooHyun Jung <wh0705.jung@samsung.com> | 2017-10-27 18:31:59 +0900 |
---|---|---|
committer | WooHyun Jung <wh0705.jung@samsung.com> | 2017-10-31 11:21:15 +0900 |
commit | 02f179628c253de935a96cf6880b237ae268190f (patch) | |
tree | dcee3d357fe34f6e33ed6daf2d2f0c9531af0476 /src/lib | |
parent | de349e1b9e8f34381747ed8d57c56577bd353a6b (diff) | |
download | efl-02f179628c253de935a96cf6880b237ae268190f.tar.gz |
efl_ui_calendar: apply new format_cb
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/elementary/efl_ui_calendar.c | 67 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_calendar.eo | 37 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_calendar.h | 1 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_calendar_common.h | 21 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_calendar_private.h | 7 |
5 files changed, 56 insertions, 77 deletions
diff --git a/src/lib/elementary/efl_ui_calendar.c b/src/lib/elementary/efl_ui_calendar.c index 66ca500bd4..605f8274ff 100644 --- a/src/lib/elementary/efl_ui_calendar.c +++ b/src/lib/elementary/efl_ui_calendar.c @@ -165,27 +165,40 @@ _disable(Efl_Ui_Calendar_Data *sd, elm_layout_signal_emit(sd->obj, emission, "elm"); } -static char * -_format_month_year(struct tm *date) -{ - return eina_strftime(E_("%B %Y"), date); -} - static void _set_month_year(Efl_Ui_Calendar_Data *sd) { - char *buf; sd->filling = EINA_TRUE; - buf = sd->format_func(&sd->shown_date); - - if (buf) + if (sd->format_cb) { - elm_layout_text_set(sd->obj, "month_text", buf); - free(buf); + Eina_Value val; + const char *buf; + + eina_value_setup(&val, EINA_VALUE_TYPE_TM); + eina_value_set(&val, sd->shown_date); + eina_strbuf_reset(sd->format_strbuf); + sd->format_cb(sd->format_cb_data, sd->format_strbuf, val); + buf = eina_strbuf_string_get(sd->format_strbuf); + eina_value_flush(&val); + + if (buf) + elm_layout_text_set(sd->obj, "month_text", buf); + else + elm_layout_text_set(sd->obj, "month_text", ""); + } + else + { + char *buf; + buf = eina_strftime(E_("%B %Y"), &sd->shown_date); + if (buf) + { + elm_layout_text_set(sd->obj, "month_text", buf); + free(buf); + } + else elm_layout_text_set(sd->obj, "month_text", ""); } - else elm_layout_text_set(sd->obj, "month_text", ""); sd->filling = EINA_FALSE; } @@ -504,7 +517,7 @@ _efl_ui_calendar_elm_widget_theme_apply(Eo *obj, Efl_Ui_Calendar_Data *sd) static inline Eina_Bool _fix_date(Efl_Ui_Calendar_Data *sd) { - Eina_Bool fixed = EINA_FALSE; + Eina_Bool no_change = EINA_TRUE; if ((sd->date.tm_year < sd->date_min.tm_year) || ((sd->date.tm_year == sd->date_min.tm_year) && @@ -516,7 +529,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd) sd->date.tm_year = sd->shown_date.tm_year = sd->date_min.tm_year; sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_min.tm_mon; sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_min.tm_mday; - fixed = EINA_TRUE; + no_change = EINA_FALSE; } else if ((sd->date_max.tm_year != -1) && ((sd->date.tm_year > sd->date_max.tm_year) || @@ -529,7 +542,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd) sd->date.tm_year = sd->shown_date.tm_year = sd->date_max.tm_year; sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_max.tm_mon; sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_max.tm_mday; - fixed = EINA_TRUE; + no_change = EINA_FALSE; } else { @@ -539,7 +552,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd) sd->date.tm_year = sd->shown_date.tm_year; } - return fixed; + return no_change; } static Eina_Bool @@ -865,6 +878,9 @@ _efl_ui_calendar_efl_object_destructor(Eo *obj, Efl_Ui_Calendar_Data *sd) ecore_timer_del(sd->spin_year); ecore_timer_del(sd->update_timer); + efl_ui_format_cb_set(obj, NULL, NULL, NULL); + eina_strbuf_free(sd->format_strbuf); + for (i = 0; i < ELM_DAY_LAST; i++) eina_stringshare_del(sd->weekdays[i]); @@ -943,7 +959,7 @@ _efl_ui_calendar_constructor_internal(Eo *obj, Efl_Ui_Calendar_Data *priv) priv->today_it = -1; priv->selected_it = -1; priv->first_day_it = -1; - priv->format_func = _format_month_year; + priv->format_cb = NULL; edje_object_signal_callback_add (wd->resize_obj, "elm,action,selected", "*", @@ -1161,9 +1177,20 @@ _efl_ui_calendar_date_get(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd) } EOLIAN static void -_efl_ui_calendar_format_function_set(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd, Efl_Ui_Calendar_Format_Cb format_function) +_efl_ui_calendar_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Calendar_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb) { - sd->format_func = format_function; + if ((sd->format_cb_data == func_data) && (sd->format_cb == func)) + return; + + if (sd->format_cb_data && sd->format_free_cb) + sd->format_free_cb(sd->format_cb_data); + + sd->format_cb = func; + sd->format_cb_data = func_data; + sd->format_free_cb = func_free_cb; + if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new(); + + evas_object_smart_changed(obj); } EOLIAN static void diff --git a/src/lib/elementary/efl_ui_calendar.eo b/src/lib/elementary/efl_ui_calendar.eo index 6615fa90fb..f1afa05f04 100644 --- a/src/lib/elementary/efl_ui_calendar.eo +++ b/src/lib/elementary/efl_ui_calendar.eo @@ -18,7 +18,7 @@ enum Efl.Ui.Calendar.Weekday last [[Sentinel value to indicate last enum field during iteration]] } -class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action) +class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action, Efl.Ui.Format) { [[Calendar widget @@ -37,36 +37,6 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At day: Efl.Ui.Calendar.Weekday(Efl.Ui.Calendar.Weekday.sunday); [[Weekday enum value, see @Elm.Calendar.Weekday]] } } - @property format_function { - set { - [[Set a function to format the string that will be used to display - month and year; - - By default it uses strftime with "%B %Y" format string. - It should allocate the memory that will be used by the string, - that will be freed by the widget after usage. - A pointer to the string and a pointer to the time struct will be provided. - ]] - /* FIXME-doc - * Example: - * @code - * static char - * _format_month_year(struct tm *selected_time) - * { - * char buf[32]; - * if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL; - * return strdup(buf); - * } - * - * efl_ui_calendar_format_function_set(calendar, _format_month_year); - * @endcode - */ - } - values { - format_function: Efl_Ui_Calendar_Format_Cb; [[Function to set the month-year string given - the selected date.]] - } - } @property date_min { [[Minimum date on calendar.]] set { @@ -121,9 +91,9 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At [[Set the selected date. If the date is greater than the maximum date, the date would be changed to the maximum date with returning $false. In the opposite case with the minimum date, - this would give the same result. + this would give the same result. ]] - return: bool; [[$true, on success, $false otherwise]] + return: bool; [[$true, on success, $false otherwise]] } get { } @@ -142,6 +112,7 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At Elm.Widget.on_focus_update; Elm.Widget.widget_event; Elm.Interface.Atspi_Widget_Action.elm_actions { get; } + Efl.Ui.Format.format_cb { set; } } events { changed; [[Emitted when the selected date in the calendar is changed]] diff --git a/src/lib/elementary/efl_ui_calendar.h b/src/lib/elementary/efl_ui_calendar.h index 9c71188b47..f80dce28d5 100644 --- a/src/lib/elementary/efl_ui_calendar.h +++ b/src/lib/elementary/efl_ui_calendar.h @@ -48,7 +48,6 @@ * @{ */ -#include "efl_ui_calendar_common.h" #ifdef EFL_EO_API_SUPPORT #include "efl_ui_calendar.eo.h" #endif diff --git a/src/lib/elementary/efl_ui_calendar_common.h b/src/lib/elementary/efl_ui_calendar_common.h deleted file mode 100644 index 70a95ad8f2..0000000000 --- a/src/lib/elementary/efl_ui_calendar_common.h +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @addtogroup Elm_Calendar - * - * @{ - */ - -/** - * This callback type is used to format the string that will be used - * to display month and year. - * - * @param stime Struct representing time. - * @return String representing time that will be set to calendar's text. - * - * @see elm_calendar_format_function_set() - */ -typedef char * (*Efl_Ui_Calendar_Format_Cb)(struct tm *stime); - - -/** - * @} - */ diff --git a/src/lib/elementary/efl_ui_calendar_private.h b/src/lib/elementary/efl_ui_calendar_private.h index 7ae261cfa9..4aa00878ea 100644 --- a/src/lib/elementary/efl_ui_calendar_private.h +++ b/src/lib/elementary/efl_ui_calendar_private.h @@ -32,7 +32,6 @@ struct _Efl_Ui_Calendar_Data int spin_speed; int today_it, selected_it, focused_it; Ecore_Timer *spin_month, *spin_year, *update_timer; - Efl_Ui_Calendar_Format_Cb format_func; const char *weekdays[ELM_DAY_LAST]; struct tm current_date, shown_date, date, date_min, date_max; Evas_Object *inc_btn_month; @@ -44,9 +43,13 @@ struct _Efl_Ui_Calendar_Data Eo *items[42]; Efl_Ui_Calendar_Weekday first_week_day; - unsigned char first_day_it; + Efl_Ui_Format_Func_Cb format_cb; + Eina_Free_Cb format_free_cb; + void *format_cb_data; + Eina_Strbuf *format_strbuf; + Eina_Bool selected : 1; Eina_Bool double_spinners : 1; Eina_Bool filling : 1; |