Hi, On Tue, Oct 31, 2017 at 11:21 AM, WooHyun Jung <[email protected]> wrote:
> woohyun pushed a commit to branch master. > > http://git.enlightenment.org/core/efl.git/commit/?id= > 02f179628c253de935a96cf6880b237ae268190f > > commit 02f179628c253de935a96cf6880b237ae268190f > Author: WooHyun Jung <[email protected]> > Date: Fri Oct 27 18:31:59 2017 +0900 > > efl_ui_calendar: apply new format_cb > --- > src/Makefile_Elementary.am | 1 - > src/bin/elementary/test_calendar.c | 30 ++++++++++--- > src/lib/elementary/efl_ui_calendar.c | 67 > +++++++++++++++++++--------- > src/lib/elementary/efl_ui_calendar.eo | 37 ++------------- > src/lib/elementary/efl_ui_calendar.h | 1 - > src/lib/elementary/efl_ui_calendar_common.h | 21 --------- > src/lib/elementary/efl_ui_calendar_private.h | 7 ++- > 7 files changed, 79 insertions(+), 85 deletions(-) > > diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am > index b83482e047..9cb3aa1d00 100644 > --- a/src/Makefile_Elementary.am > +++ b/src/Makefile_Elementary.am > @@ -373,7 +373,6 @@ includesub_HEADERS = \ > lib/elementary/elm_calendar_legacy.h \ > lib/elementary/elm_calendar_common.h \ > lib/elementary/efl_ui_calendar.h \ > - lib/elementary/efl_ui_calendar_common.h \ > lib/elementary/elm_check.h \ > lib/elementary/efl_ui_check_eo.h \ > lib/elementary/elm_check_legacy.h \ > diff --git a/src/bin/elementary/test_calendar.c b/src/bin/elementary/test_ > calendar.c > index 2bcfc17657..23d4b092b1 100644 > --- a/src/bin/elementary/test_calendar.c > +++ b/src/bin/elementary/test_calendar.c > @@ -404,10 +404,24 @@ _cal_changed_cb(void *data EINA_UNUSED, const > Efl_Event *ev) > max_date.tm_year + 1900); > } > > +static void > +_cal_format_cb(void *data EINA_UNUSED, Eina_Strbuf *str, const Eina_Value > value) > +{ > + char buf[128]; > + struct tm current_time; > + > + if (eina_value_type_get(&value) == EINA_VALUE_TYPE_TM) > + { > + eina_value_get(&value, ¤t_time); > + strftime(buf, sizeof(buf), "%b %y", ¤t_time); > + eina_strbuf_append_printf(str, "<< %s >>", buf); > We already have a function *eina_strbuf_append_strftime()* to do the same job which makes this code shorter and easier to use. + } > +} > + > void > test_efl_ui_calendar(void *data EINA_UNUSED, Evas_Object *obj > EINA_UNUSED, void *event_info EINA_UNUSED) > { > - Evas_Object *win, *box; > + Evas_Object *win, *box, *cal; > struct tm selected_date, min_date, max_date; > time_t current_date; > > @@ -426,12 +440,14 @@ test_efl_ui_calendar(void *data EINA_UNUSED, > Evas_Object *obj EINA_UNUSED, void > efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL), > efl_content_set(win, efl_added)); > > - efl_add(EFL_UI_CALENDAR_CLASS, win, > - efl_ui_calendar_date_set(efl_added, selected_date), > - efl_ui_calendar_date_min_set(efl_added, min_date), > - efl_ui_calendar_date_max_set(efl_added, max_date), > - efl_event_callback_add(efl_added, > EFL_UI_CALENDAR_EVENT_CHANGED, _cal_changed_cb, NULL), > - efl_pack(box, efl_added)); > + cal = efl_add(EFL_UI_CALENDAR_CLASS, win, > + efl_ui_calendar_date_min_set(efl_added, min_date), > + efl_ui_calendar_date_max_set(efl_added, max_date), > + efl_ui_calendar_date_set(efl_added, selected_date), > + efl_event_callback_add(efl_added, > EFL_UI_CALENDAR_EVENT_CHANGED, _cal_changed_cb, NULL), > + efl_pack(box, efl_added)); > + > + efl_ui_format_cb_set(cal, NULL, _cal_format_cb, NULL); > > efl_gfx_size_set(win, EINA_SIZE2D(300, 300)); > } > 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; > > -- > > > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
