raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=7802e9284929471d930f24ae37e74998844873e3

commit 7802e9284929471d930f24ae37e74998844873e3
Author: Maximilian Lika <[email protected]>
Date:   Tue Dec 14 08:53:15 2021 +0000

    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
---
 src/lib/elementary/efl_ui_progressbar.c     | 50 ++++++++++++++++++++
 src/lib/elementary/elm_progressbar_common.h |  1 +
 src/lib/elementary/elm_progressbar_legacy.h | 17 +++++++
 src/lib/elementary/elm_slider.c             | 71 ++++++++++++++++++++++++++---
 src/lib/elementary/elm_slider_common.h      |  1 +
 src/lib/elementary/elm_slider_legacy.h      | 27 +++++++++++
 6 files changed, 160 insertions(+), 7 deletions(-)

diff --git a/src/lib/elementary/efl_ui_progressbar.c 
b/src/lib/elementary/efl_ui_progressbar.c
index bf0f14764a..9fb0bb9114 100644
--- a/src/lib/elementary/efl_ui_progressbar.c
+++ b/src/lib/elementary/efl_ui_progressbar.c
@@ -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)
 {
diff --git a/src/lib/elementary/elm_progressbar_common.h 
b/src/lib/elementary/elm_progressbar_common.h
index 76f48a8a85..bc03570665 100644
--- a/src/lib/elementary/elm_progressbar_common.h
+++ b/src/lib/elementary/elm_progressbar_common.h
@@ -5,6 +5,7 @@
  */
 
 typedef char *(*progressbar_func_type)(double);
+typedef char *(*progressbar_func_full_type)(double, void *);
 typedef void (*progressbar_freefunc_type)(char *);
 
 /**
diff --git a/src/lib/elementary/elm_progressbar_legacy.h 
b/src/lib/elementary/elm_progressbar_legacy.h
index a6b67991be..3f630f8745 100644
--- a/src/lib/elementary/elm_progressbar_legacy.h
+++ b/src/lib/elementary/elm_progressbar_legacy.h
@@ -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.
diff --git a/src/lib/elementary/elm_slider.c b/src/lib/elementary/elm_slider.c
index e5bd17711b..2627731a66 100644
--- a/src/lib/elementary/elm_slider.c
+++ b/src/lib/elementary/elm_slider.c
@@ -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)
 {
diff --git a/src/lib/elementary/elm_slider_common.h 
b/src/lib/elementary/elm_slider_common.h
index dc592202d9..ade333272e 100644
--- a/src/lib/elementary/elm_slider_common.h
+++ b/src/lib/elementary/elm_slider_common.h
@@ -5,6 +5,7 @@
  */
 
 typedef char *(*slider_func_type)(double);
+typedef char *(*slider_func_full_type)(double, void *);
 typedef void (*slider_freefunc_type)(char *);
 
 /**
diff --git a/src/lib/elementary/elm_slider_legacy.h 
b/src/lib/elementary/elm_slider_legacy.h
index 60d29de304..4e1bcf35c1 100644
--- a/src/lib/elementary/elm_slider_legacy.h
+++ b/src/lib/elementary/elm_slider_legacy.h
@@ -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.
  *

-- 


Reply via email to