diff --git a/src/lib/elementary/efl_ui_multibuttonentry.c b/src/lib/elementary/efl_ui_multibuttonentry.c index 4cec0b167c..81e2b391ca 100644 --- a/src/lib/elementary/efl_ui_multibuttonentry.c +++ b/src/lib/elementary/efl_ui_multibuttonentry.c @@ -191,6 +191,7 @@ _shrink_mode_set(Evas_Object *obj, { Evas_Coord w = 0; Evas_Coord box_inner_item_width_padding = 0; + Eina_Value val; elm_box_padding_get(sd->box, &box_inner_item_width_padding, NULL); // unpack all items and entry @@ -219,7 +220,6 @@ _shrink_mode_set(Evas_Object *obj, EINA_LIST_FOREACH(sd->items, l, eo_item) { Evas_Coord w_label_count = 0, h = 0; - char *buf; ELM_MULTIBUTTONENTRY_ITEM_DATA_GET(eo_item, item); elm_box_pack_end(sd->box, VIEW(item)); @@ -233,15 +233,15 @@ _shrink_mode_set(Evas_Object *obj, w -= box_inner_item_width_padding; count--; + eina_value_setup(&val, EINA_VALUE_TYPE_INT); + if (count > 0) { - buf = sd->format_func(count, (void *)sd->format_func_data); - if (buf) - { - edje_object_part_text_escaped_set - (sd->end, "elm.text", buf); - free(buf); - } + eina_strbuf_reset(sd->format_strbuf); + eina_value_set(&val, count); + sd->format_cb(sd->format_cb_data, sd->format_strbuf, val); + edje_object_part_text_escaped_set(sd->end, "elm.text", + eina_strbuf_string_get(sd->format_strbuf)); edje_object_size_min_calc(sd->end, &w_label_count, NULL); elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL); @@ -254,13 +254,12 @@ _shrink_mode_set(Evas_Object *obj, item->visible = EINA_FALSE; count++; - buf = sd->format_func(count, (void *)sd->format_func_data); - if (buf) - { - edje_object_part_text_escaped_set - (sd->end, "elm.text", buf); - free(buf); - } + eina_strbuf_reset(sd->format_strbuf); + + eina_value_set(&val, count); + sd->format_cb(sd->format_cb_data, sd->format_strbuf, val); + edje_object_part_text_escaped_set(sd->end, "elm.text", + eina_strbuf_string_get(sd->format_strbuf)); edje_object_size_min_calc(sd->end, &w_label_count, &h); elm_coords_finger_size_adjust(1, &w_label_count, 1, &h); @@ -1639,7 +1638,8 @@ _efl_ui_multibuttonentry_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Multibuttone priv->last_it_select = EINA_TRUE; priv->editable = EINA_TRUE; priv->parent = obj; - priv->format_func = _format_count; + + efl_ui_format_string_set(obj, "+%d"); _view_init(obj, priv); _callbacks_register(obj); @@ -1675,6 +1675,10 @@ _efl_ui_multibuttonentry_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Multibuttone evas_object_del(sd->end); ecore_timer_del(sd->longpress_timer); + if (sd->format_free_cb) sd->format_free_cb(sd->format_cb_data); + efl_ui_format_cb_set(obj, NULL, NULL, NULL); + eina_strbuf_free(sd->format_strbuf); + EINA_LIST_FREE(sd->filter_list, _item_filter) _filter_free(_item_filter); @@ -1735,17 +1739,6 @@ _efl_ui_multibuttonentry_expanded_get(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonent EINA_FALSE : EINA_TRUE; } -EOLIAN static void -_efl_ui_multibuttonentry_format_function_set(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonentry_Data *sd, Efl_Ui_Multibuttonentry_Format_Cb f_func, const void *data) -{ - sd->format_func = f_func; - if (!sd->format_func) sd->format_func = _format_count; - - sd->format_func_data = data; - - _view_update(sd); -} - EOLIAN static void _efl_ui_multibuttonentry_expanded_set(Eo *obj, Efl_Ui_Multibuttonentry_Data *sd, Eina_Bool expanded) { @@ -1998,6 +1991,23 @@ _efl_ui_multibuttonentry_item_filter_remove(Eo *obj EINA_UNUSED, Efl_Ui_Multibut } } +EOLIAN static void +_efl_ui_multibuttonentry_efl_ui_format_format_cb_set(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonentry_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb) +{ + 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(); + + _view_update(sd); +} + static void _efl_ui_multibuttonentry_class_constructor(Efl_Class *klass) { @@ -2100,3 +2110,50 @@ ELM_PART_OVERRIDE_TEXT_GET(efl_ui_multibuttonentry, EFL_UI_MULTIBUTTONENTRY, Efl #include "elm_multibuttonentry_item.eo.c" #include "efl_ui_multibuttonentry.eo.c" + +/* Legacy APIs */ + +typedef struct +{ + Efl_Ui_Multibuttonentry_Format_Cb format_cb; + void *data; +} Mbe_Format_Wrapper_Data ; + +static void +_format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value value) +{ + Mbe_Format_Wrapper_Data *mfwd = data; + char *buf; + int count = 0; + + const Eina_Value_Type *type = eina_value_type_get(&value); + + if (type == EINA_VALUE_TYPE_INT) + eina_value_get(&value, &count); + + buf = mfwd->format_cb(count, mfwd->data); + if (buf) + eina_strbuf_append(str, buf); + free(buf); +} + +static void +_format_legacy_to_format_eo_free_cb(void *data) +{ + Mbe_Format_Wrapper_Data *mfwd = data; + + free(mfwd); +} + +EAPI void +elm_multibuttonentry_format_function_set(Eo *obj, Efl_Ui_Multibuttonentry_Format_Cb format_function, const void *data) +{ + Mbe_Format_Wrapper_Data *mfwd = malloc(sizeof(Mbe_Format_Wrapper_Data)); + + mfwd->format_cb = format_function; + if (!mfwd->format_cb) mfwd->format_cb = _format_count; + + mfwd->data = (void *)data; + + efl_ui_format_cb_set(obj, mfwd, _format_legacy_to_format_eo_cb, _format_legacy_to_format_eo_free_cb); +} diff --git a/src/lib/elementary/efl_ui_multibuttonentry.eo b/src/lib/elementary/efl_ui_multibuttonentry.eo index 9462eb2a76..fb60d2ebcc 100644 --- a/src/lib/elementary/efl_ui_multibuttonentry.eo +++ b/src/lib/elementary/efl_ui_multibuttonentry.eo @@ -1,7 +1,7 @@ type Elm_Multibuttonentry_Item_Filter_Cb: __undefined_type; [[Elementary multibuttonentry item filter callback type]] type Efl_Ui_Multibuttonentry_Format_Cb: __undefined_type; [[Elementary multibuttonentry format callback type]] -class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable) +class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable, Efl.Ui.Format) { [[Elementary multibuttonentry class]] legacy_prefix: elm_multibuttonentry; @@ -32,20 +32,6 @@ class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable) this to $false for single line state.]] } } - @property format_function { - set { - [[Set a function to format the string that will be used to display the hidden items counter. - - If $format_function is $NULL, the default format will be used, - which is $"... + %d". - - @since 1.9]] - } - values { - format_function: Efl_Ui_Multibuttonentry_Format_Cb @nullable; [[Format_function The actual format function]] - data: const(void_ptr) @optional; [[Data User data to passed to $format_function]] - } - } @property items { get { [[Get a list of items in the multibuttonentry]] @@ -183,6 +169,7 @@ class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable) Elm.Widget.widget_event; Efl.Access.children { get; } Efl.Part.part; + Efl.Ui.Format.format_cb { set; } } events { item,selected; [[Called when item was selected]] diff --git a/src/lib/elementary/efl_ui_multibuttonentry_private.h b/src/lib/elementary/efl_ui_multibuttonentry_private.h index 64acf38e87..572e5fa47b 100644 --- a/src/lib/elementary/efl_ui_multibuttonentry_private.h +++ b/src/lib/elementary/efl_ui_multibuttonentry_private.h @@ -88,9 +88,6 @@ struct _Efl_Ui_Multibuttonentry_Data Elm_Multibuttonentry_Item_Data *selected_it; /* selected item */ Elm_Multibuttonentry_Item_Data *focused_it; - Efl_Ui_Multibuttonentry_Format_Cb format_func; - const void *format_func_data; - const char *label_str, *guide_text_str; int n_str; @@ -101,13 +98,17 @@ struct _Efl_Ui_Multibuttonentry_Data Elm_Multibuttonentry_Item_Filter_Cb add_callback; void *add_callback_data; + Ecore_Timer *longpress_timer; + + Efl_Ui_Format_Func_Cb format_cb; + Eina_Free_Cb format_free_cb; + void *format_cb_data; + Eina_Strbuf *format_strbuf; Eina_Bool last_it_select : 1; Eina_Bool editable : 1; Eina_Bool focused : 1; Eina_Bool label_packed : 1; - - Ecore_Timer *longpress_timer; }; /** diff --git a/src/lib/elementary/elc_multibuttonentry_legacy.h b/src/lib/elementary/elc_multibuttonentry_legacy.h index 157ffb645a..8831fe71ca 100644 --- a/src/lib/elementary/elc_multibuttonentry_legacy.h +++ b/src/lib/elementary/elc_multibuttonentry_legacy.h @@ -9,5 +9,22 @@ */ EAPI Evas_Object *elm_multibuttonentry_add(Evas_Object *parent); +/** + * @brief Set a function to format the string that will be used to display the + * hidden items counter. + * + * If @c format_function is @c NULL, the default format will be used, which is + * $"... + %d". + * + * @param[in] obj The object. + * @param[in] format_function Format_function The actual format function + * @param[in] data Data User data to passed to @c format_function + * + * @since 1.9 + * + * @ingroup Multibuttonentry + */ + EAPI void elm_multibuttonentry_format_function_set(Eo *obj, Efl_Ui_Multibuttonentry_Format_Cb format_function, const void *data); + #include "elm_multibuttonentry_item.eo.legacy.h" #include "efl_ui_multibuttonentry.eo.legacy.h"