From: cedric Date: Mon, 4 Jul 2011 19:56:19 +0000 (+0000) Subject: elementary: make it possible to actually free string returned by value to string... X-Git-Tag: REL_F_I9200_20110722_1~8^2~46^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44f31cf7218812b7a97b3612f78274abad4b0058;p=framework%2Fuifw%2Felementary.git elementary: make it possible to actually free string returned by value to string callback. NOTE: this introduce an API/ABI incompatibility. You need to think if you need to free the data you allocated in the callback, if yes, then you need to provide a function to free that data, if not, you could just set NULL as the third parameter. git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@61019 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index b535d3b..8808e0d 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -4155,7 +4155,8 @@ extern "C" { EAPI const char *elm_slider_unit_format_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); EAPI void elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator) EINA_ARG_NONNULL(1); EAPI const char *elm_slider_indicator_format_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); - EAPI void elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val)) EINA_ARG_NONNULL(1); + EAPI void elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str)) EINA_ARG_NONNULL(1); + EAPI void elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str)) EINA_ARG_NONNULL(1); EAPI void elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) EINA_ARG_NONNULL(1); EAPI Eina_Bool elm_slider_horizontal_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); EAPI void elm_slider_min_max_set(Evas_Object *obj, double min, double max) EINA_ARG_NONNULL(1); diff --git a/src/lib/elm_slider.c b/src/lib/elm_slider.c index 3680670..7001c28 100644 --- a/src/lib/elm_slider.c +++ b/src/lib/elm_slider.c @@ -46,16 +46,25 @@ struct _Widget_Data Evas_Object *icon; Evas_Object *end; Evas_Object *spacer; + + Ecore_Timer *delay; + const char *label; const char *units; const char *indicator; + const char *(*indicator_format_func)(double val); + void (*indicator_format_free)(const char *str); + + const char *(*units_format_func)(double val); + void (*units_format_free)(const char *str); + + double val, val_min, val_max; + Evas_Coord size; + Eina_Bool horizontal : 1; Eina_Bool inverted : 1; Eina_Bool indicator_show : 1; - double val, val_min, val_max; - Ecore_Timer *delay; - Evas_Coord size; }; #define ELM_SLIDER_INVERTED_FACTOR (-1.0) @@ -359,7 +368,14 @@ _units_set(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); if (!wd) return; - if (wd->units) + if (wd->units_format_func) + { + const char *buf; + buf = wd->units_format_func(wd->val); + edje_object_part_text_set(wd->slider, "elm.units", buf); + if (wd->units_format_free) wd->units_format_free(buf); + } + else if (wd->units) { char buf[1024]; @@ -380,6 +396,7 @@ _indicator_set(Evas_Object *obj) const char *buf; buf = wd->indicator_format_func(wd->val); edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf); + if (wd->indicator_format_free) wd->indicator_format_free(buf); } else if (wd->indicator) { @@ -1021,7 +1038,7 @@ elm_slider_inverted_get(const Evas_Object *obj) } /** - * Set the format function pointer for the inducator area + * Set the format function pointer for the indicator area * * Set the callback function to format the indicator string. * See elm_slider_indicator_format_set() for more info on how this works. @@ -1029,16 +1046,42 @@ elm_slider_inverted_get(const Evas_Object *obj) * @param obj The slider object * @param indicator The format string for the indicator display * @param func The indicator format function + * @param free_func The freeing function for the format string * * @ingroup Slider */ EAPI void -elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val)) +elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str)) { ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = elm_widget_data_get(obj); if (!wd) return; wd->indicator_format_func = func; + wd->indicator_format_free = free_func; + _indicator_set(obj); +} + +/** + * Set the format function pointer for the units area + * + * Set the callback function to format the indicator string. + * See elm_slider_units_format_set() for more info on how this works. + * + * @param obj The slider object + * @param indicator The format string for the units display + * @param func The units format function + * @param free_func The freeing function for the format string + * + * @ingroup Slider + */ +EAPI void +elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str)) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + wd->units_format_func = func; + wd->units_format_free = free_func; _indicator_set(obj); }