#endif
#include <Elementary.h>
+static Elm_Multibuttonentry_Format_Cb format_func = NULL;
+
+static char *
+_custom_format(int count, void *data EINA_UNUSED)
+{
+ char buf[32];
+
+ if (!snprintf(buf, sizeof(buf), "+ %d rabbits", count)) return NULL;
+ return strdup(buf);
+}
+
static void
_item_selected_cb(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
}
static void
-_button_clicked_cb(void *data EINA_UNUSED,
+_format_change_cb(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
- printf("%s button is clicked\n", __func__);
+ Evas_Object *mbe = data;
+
+ if (format_func) format_func = NULL;
+ else format_func = _custom_format;
+
+ elm_multibuttonentry_format_function_set(mbe, format_func, NULL);
+
+ printf("Changing format function to %p\n", format_func);
+}
+
+static Evas_Object*
+_format_change_btn_add(Evas_Object *mbe)
+{
+ Evas_Object *btn;
+
+ btn = elm_button_add(mbe);
+ evas_object_smart_callback_add(btn, "clicked", _format_change_cb, mbe);
+ elm_object_text_set(btn, "Change format function");
+ evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ return btn;
}
static Evas_Object*
{
Evas_Object *scr = NULL;
Evas_Object *mbe = NULL;
+ Evas_Object *btn = NULL;
void *data = NULL;
scr = elm_scroller_add(parent);
evas_object_smart_callback_add(mbe, "contracted", _contracted_cb, NULL);
evas_object_smart_callback_add(mbe, "shrink,state,changed", _shrink_state_changed_cb, NULL);
+ btn = _format_change_btn_add(mbe);
+ elm_object_part_content_set(parent, "box", btn);
+
evas_object_resize(mbe, 220, 300);
elm_object_focus_set(mbe, EINA_TRUE);
return scr;
}
-static Evas_Object*
-_add_buttons(Evas_Object *parent)
-{
- Evas_Object *bx = NULL;
- Evas_Object *btn;
-
- bx = elm_box_add(parent);
- elm_box_horizontal_set(bx, EINA_TRUE);
- elm_box_homogeneous_set(bx, EINA_TRUE);
-
- btn = elm_button_add(parent);
- evas_object_smart_callback_add(btn, "clicked", _button_clicked_cb, NULL);
- elm_object_text_set(btn, "click");
- evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
- evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_box_pack_end(bx, btn);
- evas_object_show(btn);
-
- return bx;
-}
-
void
test_multibuttonentry(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
- Evas_Object *win, *sc, *bx;
+ Evas_Object *win, *sc;
Evas_Object *ly;
char buf[PATH_MAX];
sc = _add_multibuttonentry(ly);
elm_object_part_content_set(ly, "multibuttonentry", sc);
- bx = _add_buttons(ly);
- elm_object_part_content_set(ly, "box", bx);
-
evas_object_resize(win, 320, 480);
evas_object_show(win);
}
if (ret) *ret = EINA_TRUE;
}
+static char *
+_format_count(int count, void *data EINA_UNUSED)
+{
+ char buf[32];
+
+ if (!snprintf(buf, sizeof(buf), "... + %d", count)) return NULL;
+ return strdup(buf);
+}
+
static void
_elm_multibuttonentry_smart_theme(Eo *obj, void *_pd, va_list *list)
{
EINA_LIST_FOREACH(sd->items, l, item)
{
Evas_Coord w_label_count = 0, h = 0;
- char buf[MAX_STR];
+ char *buf;
elm_box_pack_end(sd->box, item->button);
evas_object_show(item->button);
if (count > 0)
{
- snprintf(buf, sizeof(buf), "... + %i", count);
- edje_object_part_text_escaped_set(sd->end, "elm.text", buf);
+ 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);
+ }
+
edje_object_size_min_calc(sd->end, &w_label_count, NULL);
elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL);
}
elm_box_unpack(sd->box, item->button);
evas_object_hide(item->button);
item->visible = EINA_FALSE;
-
count++;
- snprintf(buf, sizeof(buf), "... + %d", count);
- edje_object_part_text_escaped_set(sd->end, "elm.text", buf);
+
+ 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);
+ }
+
edje_object_size_min_calc(sd->end, &w_label_count, &h);
elm_coords_finger_size_adjust(1, &w_label_count, 1, &h);
evas_object_size_hint_min_set
priv->last_btn_select = EINA_TRUE;
priv->editable = EINA_TRUE;
priv->parent = obj;
+ priv->format_func = _format_count;
_view_init(obj, priv);
_callbacks_register(obj);
}
EAPI void
+elm_multibuttonentry_format_function_set(Evas_Object *obj,
+ Elm_Multibuttonentry_Format_Cb f_func,
+ const void *data)
+{
+ ELM_MULTIBUTTONENTRY_CHECK(obj);
+
+ eo_do((Eo *) obj, elm_obj_multibuttonentry_format_function_set
+ (f_func, data));
+
+}
+
+static void
+_format_function_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
+{
+ Elm_Multibuttonentry_Smart_Data *sd = _pd;
+
+ sd->format_func = va_arg(*list, Elm_Multibuttonentry_Format_Cb);
+
+ if (!sd->format_func) sd->format_func = _format_count;
+
+ sd->format_func_data = va_arg(*list, void *);
+
+ _view_update(sd);
+}
+
+EAPI void
elm_multibuttonentry_expanded_set(Evas_Object *obj,
Eina_Bool expanded)
{
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND), _item_filter_append),
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND), _item_filter_prepend),
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), _item_filter_remove),
+ EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET), _format_function_set),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND, "Append an item filter function for text inserted in the Multibuttonentry."),
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND, "Prepend a filter function for text inserted in the Multibuttonentry."),
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE, "Remove a filter from the list."),
+ EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET, "Set a function to format the string that will be used to display the hidden items counter."),
EO_OP_DESCRIPTION_SENTINEL
};
static const Eo_Class_Description class_desc = {
*/
typedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const char *item_label, void *item_data, void *data);
+/**
+ * @typedef Elm_Multibuttonentry_Format_Cb
+ *
+ * This callback type is used to format the string that will be used
+ * to display the hidden items counter, when not in expanded mode.
+ *
+ * @param count Number of hidden items
+ * @param data The (context) data passed in to
+ * elm_multibuttonentry_format_function_set()
+ * @return String representing the counter that will be set to
+ * multibuttonentry's counter item's text.
+ *
+ * @see elm_multibuttonentry_format_function_set()
+ * @see elm_multibuttonentry_expanded_set()
+ *
+ * @ingroup Multibuttonentry
+ */
+typedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data);
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND,
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND,
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE,
+ ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET,
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_LAST
};
* @ingroup Multibuttonentry
*/
#define elm_obj_multibuttonentry_item_filter_remove(func, data) ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), EO_TYPECHECK(Elm_Multibuttonentry_Item_Filter_Cb, func), EO_TYPECHECK(void *, data)
+
+/**
+ * @def elm_obj_multibuttonentry_format_function_set
+ * @since 1.9
+ *
+ * Set a function to format the string that will be used to display
+ * the hidden items counter.
+ *
+ * @param[in] format_function The actual format function
+ * @param[in] data User data to passed to @a format_function
+ *
+ * If @a format_function is @c NULL, the default format will be used,
+ * which is @c "... + %d".
+ *
+ * @see elm_multibuttonentry_format_function_set
+ *
+ * @ingroup Multibuttonentry
+ */
+#define elm_obj_multibuttonentry_format_function_set(format_function, data) ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET), EO_TYPECHECK(Elm_Multibuttonentry_Format_Cb, format_function), EO_TYPECHECK(const void *, data)
EAPI void elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data);
/**
+ * Set a function to format the string that will be used to display
+ * the hidden items counter.
+ *
+ * @param[in] obj The multi button entry to get format function changed
+ * @param[in] format_function The actual format function
+ * @param[in] data User data to passed to @a format_function
+ *
+ * If @a format_function is @c NULL, the default format will be used,
+ * which is @c "... + %d".
+ *
+ * @see elm_multibuttonentry_format_function_set
+ * @since 1.9
+ *
+ * @ingroup Multibuttonentry
+ */
+EAPI void
+elm_multibuttonentry_format_function_set(Evas_Object *obj,
+ Elm_Multibuttonentry_Format_Cb f_func,
+ const void *data);
+
+/**
* Sets if the multibuttonentry is to be editable or not.
*
* @param obj The multibuttonentry object
Eina_List *filter_list;
Elm_Object_Item *selected_it; /* selected item */
+ Elm_Multibuttonentry_Format_Cb format_func;
+ const void *format_func_data;
+
const char *label_str, *guide_text_str;
int n_str;