Make passing data pointer to format_cb possible

Summary:
Hello,
For my perl binding it is important that one can pass a data pointer to all callbacks, especially to "Format_Cbs" as in elm_slider_units_format_function_set(), elm_slider_indicator_format_function_set() of elm_progressbar_unit_format_function_set(). Another "problematic" function would be elm_calendar_format_function_set().

Enclosed you find a approach to solve this problem.

It would be wonderful, if the Efl-libraries could make data pointers also in format cbs possible...

Thanks in advance,
Max

Reviewers: bowonryu, eagleeye, zmike, cedric, raster

Reviewed By: raster

Subscribers: raster, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D12298
This commit is contained in:
Maximilian Lika 2021-12-14 08:53:15 +00:00 committed by Carsten Haitzler (Rasterman)
parent f6c99bd806
commit 7802e92849
6 changed files with 160 additions and 7 deletions

View File

@ -955,6 +955,56 @@ elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type
_format_legacy_to_format_eo_free_cb);
}
typedef struct
{
progressbar_func_full_type format_cb;
progressbar_freefunc_type format_free_cb;
void *format_func_data;
} Pb_Full_Format_Wrapper_Data;
static Eina_Bool
_format_legacy_to_format_eo_cb_full(void *data, Eina_Strbuf *str, const Eina_Value value)
{
Pb_Full_Format_Wrapper_Data *pfwd = data;
char *buf = NULL;
double val = 0;
const Eina_Value_Type *type = eina_value_type_get(&value);
if (type == EINA_VALUE_TYPE_DOUBLE)
eina_value_get(&value, &val);
if (pfwd->format_cb)
buf = pfwd->format_cb(val,pfwd->format_func_data);
if (buf)
eina_strbuf_append(str, buf);
if (pfwd->format_free_cb) pfwd->format_free_cb(buf);
return EINA_TRUE;
}
static void
_format_legacy_to_format_eo_full_free_cb(void *data)
{
Pb_Full_Format_Wrapper_Data *pfwd = data;
free(pfwd);
}
EAPI void
elm_progressbar_unit_format_function_set_full(Evas_Object *obj, progressbar_func_full_type func, progressbar_freefunc_type free_func, void* data)
{
EFL_UI_PROGRESSBAR_DATA_GET_OR_RETURN(obj, sd);
Pb_Full_Format_Wrapper_Data *pfwd = malloc(sizeof(Pb_Full_Format_Wrapper_Data));
if (!pfwd) return;
pfwd->format_cb = func;
pfwd->format_free_cb = free_func;
pfwd->format_func_data = data;
sd->is_legacy_format_cb = EINA_TRUE;
efl_ui_format_func_set(obj, pfwd, _format_legacy_to_format_eo_cb_full,
_format_legacy_to_format_eo_full_free_cb);
}
EAPI void
elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
{

View File

@ -5,6 +5,7 @@
*/
typedef char *(*progressbar_func_type)(double);
typedef char *(*progressbar_func_full_type)(double, void *);
typedef void (*progressbar_freefunc_type)(char *);
/**

View File

@ -188,6 +188,23 @@ EAPI const char *elm_progressbar_unit_format_get(const Evas_Object *obj);
*/
EAPI void elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type func, progressbar_freefunc_type free_func);
/**
* @brief Set the format function pointer for the units label
*
* Set the callback function to format the unit string.
*
* See: @ref elm_progressbar_unit_format_set for more info on how this works.
*
* @param[in] func The unit format function
* @param[in] free_func The freeing function for the format string.
* @param[in] The data pointer to be passed to @p func
*
* @since 1.7
*
* @ingroup Elm_Progressbar
*/
EAPI void elm_progressbar_unit_format_function_set_full(Evas_Object *obj, progressbar_func_full_type func, progressbar_freefunc_type free_func, void *data);
/**
* @brief Control whether a given progress bar widget is at "pulsing mode" or
* not.

View File

@ -1270,9 +1270,6 @@ _elm_slider_efl_ui_format_format_cb_set(Eo *obj, Elm_Slider_Data *sd, void *func
if (sd->format_cb_data && sd->format_free_cb)
sd->format_free_cb(sd->format_cb_data);
// sd->format_cb = NULL;
// sd->format_cb_data = NULL;
// sd->format_free_cb = NULL;
if (efl_invalidated_get(obj)) return;
@ -1574,10 +1571,10 @@ _format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value va
const Eina_Value_Type *type = eina_value_type_get(&value);
if (type == EINA_VALUE_TYPE_DOUBLE)
{
if (!eina_value_get(&value, &val)) return EINA_FALSE;
}
{
if (!eina_value_get(&value, &val)) return EINA_FALSE;
}
if (sfwd->format_cb)
buf = sfwd->format_cb(val);
if (buf)
@ -1605,6 +1602,52 @@ elm_slider_units_format_function_set(Evas_Object *obj, slider_func_type func, sl
efl_ui_format_func_set(obj, sfwd, _format_legacy_to_format_eo_cb, _format_legacy_to_format_eo_free_cb);
}
typedef struct
{
slider_func_full_type format_cb;
slider_freefunc_type format_free_cb;
void *format_func_data;
} Slider_Full_Format_Wrapper_Data;
static Eina_Bool
_format_legacy_to_format_eo_cb_full(void *data, Eina_Strbuf *str, const Eina_Value value)
{
Slider_Full_Format_Wrapper_Data *sfwd = data;
char *buf = NULL;
double val = 0;
const Eina_Value_Type *type = eina_value_type_get(&value);
if (type == EINA_VALUE_TYPE_DOUBLE)
eina_value_get(&value, &val);
if (sfwd->format_cb)
buf = sfwd->format_cb(val,sfwd->format_func_data);
if (buf)
eina_strbuf_append(str, buf);
if (sfwd->format_free_cb) sfwd->format_free_cb(buf);
return EINA_TRUE;
}
static void
_format_legacy_to_format_eo_full_free_cb(void *data)
{
Slider_Full_Format_Wrapper_Data *sfwd = data;
free(sfwd);
}
EAPI void
elm_slider_units_format_function_set_full(Evas_Object *obj, slider_func_full_type func, slider_freefunc_type free_func, void *data)
{
Slider_Full_Format_Wrapper_Data *sfwd = malloc(sizeof(Slider_Full_Format_Wrapper_Data));
sfwd->format_cb = func;
sfwd->format_free_cb = free_func;
sfwd->format_func_data = data;
efl_ui_format_func_set(obj, sfwd, _format_legacy_to_format_eo_cb_full, _format_legacy_to_format_eo_full_free_cb);
}
EAPI void
elm_slider_range_enabled_set(Evas_Object *obj, Eina_Bool enable)
{
@ -1720,6 +1763,20 @@ elm_slider_indicator_format_function_set(Evas_Object *obj, slider_func_type func
_format_legacy_to_format_eo_free_cb);
}
EAPI void
elm_slider_indicator_format_function_set_full(Evas_Object *obj, slider_func_full_type func, slider_freefunc_type free_func, void *data)
{
Slider_Full_Format_Wrapper_Data *sfwd = malloc(sizeof(Slider_Full_Format_Wrapper_Data));
sfwd->format_cb = func;
sfwd->format_free_cb = free_func;
sfwd->format_func_data = data;
efl_ui_format_func_set(efl_part(obj, "indicator"), sfwd,
_format_legacy_to_format_eo_cb_full,
_format_legacy_to_format_eo_full_free_cb);
}
EAPI void
elm_slider_indicator_show_on_focus_set(Evas_Object *obj, Eina_Bool flag)
{

View File

@ -5,6 +5,7 @@
*/
typedef char *(*slider_func_type)(double);
typedef char *(*slider_func_full_type)(double, void *);
typedef void (*slider_freefunc_type)(char *);
/**

View File

@ -161,6 +161,19 @@ EAPI const char *elm_slider_unit_format_get(const Evas_Object *obj);
*/
EAPI void elm_slider_units_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func);
/**
* @brief Set the format function pointer for the units label
*
* Set the callback function to format the units string.
*
* @param[in] func The units format function.
* @param[in] free_func The freeing function for the format string.
* @param[in] The data pointer to be passed to @p func
*
* @ingroup Elm_Slider
*/
EAPI void elm_slider_units_format_function_set_full(Evas_Object *obj, slider_func_full_type func, slider_freefunc_type free_func, void *data);
/**
* @brief Set the minimum and maximum values for the slider.
*
@ -285,6 +298,20 @@ EAPI void elm_slider_range_get(const Evas_Object *obj, double *from, double *to)
*/
EAPI void elm_slider_indicator_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func);
/**
* @brief Set the format function pointer for the indicator label
*
* Set the callback function to format the indicator string.
*
* @param[in] obj The object.
* @param[in] func The indicator format function.
* @param[in] free_func The freeing function for the format string.
* @param[in] The data pointer to be passed to @p func
*
* @ingroup Elm_Slider
*/
EAPI void elm_slider_indicator_format_function_set_full(Evas_Object *obj, slider_func_full_type func, slider_freefunc_type free_func, void *data);
/**
* @brief Show the indicator of slider on focus.
*