From 3d6e44bd91bcbcc92ad3be65d58b093bf11e6066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Briano?= Date: Fri, 29 Oct 2010 18:15:09 +0000 Subject: [PATCH] And as discussed on IRC, for the sake of API consistency (and we'll eventually need it), also del_full() for the text filters. And since I'm there, some documentation. SVN revision: 54003 --- legacy/edje/src/lib/Edje.h | 1 + legacy/edje/src/lib/edje_util.c | 73 ++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/legacy/edje/src/lib/Edje.h b/legacy/edje/src/lib/Edje.h index 08791565e5..b3eeca0022 100644 --- a/legacy/edje/src/lib/Edje.h +++ b/legacy/edje/src/lib/Edje.h @@ -605,6 +605,7 @@ typedef Evas_Object *(*Edje_Item_Provider_Cb) (void *data, Evas_Object *obj, c EAPI void edje_object_text_insert_filter_callback_add (Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data); EAPI void *edje_object_text_insert_filter_callback_del (Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func); + EAPI void *edje_object_text_insert_filter_callback_del_full (Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data); EAPI Eina_Bool edje_object_part_swallow (Evas_Object *obj, const char *part, Evas_Object *obj_swallow); EAPI void edje_object_part_unswallow (Evas_Object *obj, Evas_Object *obj_swallow); diff --git a/legacy/edje/src/lib/edje_util.c b/legacy/edje/src/lib/edje_util.c index d5c2cc9630..5088de123c 100644 --- a/legacy/edje/src/lib/edje_util.c +++ b/legacy/edje/src/lib/edje_util.c @@ -2146,10 +2146,28 @@ edje_object_part_text_cursor_content_get(const Evas_Object *obj, const char *par } /** - * @brief XX + * Add a filter function for newly inserted text. + * + * Whenever text is inserted (not the same as set) into the given @p part, + * the list of filter functions will be called to decide if and how the new + * text will be accepted. + * There are three types of filters, EDJE_TEXT_FILTER_TEXT, + * EDJE_TEXT_FILTER_FORMAT and EDJE_TEXT_FILTER_MARKUP. + * The text parameter in the @p func filter can be modified by the user and + * it's up to him to free the one passed if he's to change the pointer. If + * doing so, the newly set text should be malloc'ed, as once all the filters + * are called Edje will free it. + * If the text is to be rejected, freeing it and setting the pointer to NULL + * will make Edje break out of the filter cycle and reject the inserted + * text. + * + * @see edje_object_text_insert_filter_callback_del + * @see edje_object_text_insert_filter_callback_del_full * * @param obj A valid Evas_Object handle * @param part The part name + * @param func The callback function that will act as filter + * @param data User provided data to pass to the filter function */ EAPI void edje_object_text_insert_filter_callback_add(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data) @@ -2168,10 +2186,19 @@ edje_object_text_insert_filter_callback_add(Evas_Object *obj, const char *part, } /** - * @brief XX + * Delete a function from the filter list. + * + * Delete the given @p func filter from the list in @p part. Returns + * the user data pointer given when added. + * + * @see edje_object_text_insert_filter_callback_add + * @see edje_object_text_insert_filter_callback_del_full * * @param obj A valid Evas_Object handle * @param part The part name + * @param func The function callback to remove + * + * @return The user data pointer if succesful, or NULL otherwise */ EAPI void * edje_object_text_insert_filter_callback_del(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func) @@ -2197,6 +2224,48 @@ edje_object_text_insert_filter_callback_del(Evas_Object *obj, const char *part, return NULL; } +/** + * Delete a function and matching user data from the filter list. + * + * Delete the given @p func filter and @p data user data from the list + * in @p part. + * Returns the user data pointer given when added. + * + * @see edje_object_text_insert_filter_callback_add + * @see edje_object_text_insert_filter_callback_del + * + * @param obj A valid Evas_Object handle + * @param part The part name + * @param func The function callback to remove + * @param data The data passed to the callback function + * + * @return The same data pointer if succesful, or NULL otherwise + */ +EAPI void * +edje_object_text_insert_filter_callback_del_full(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data) +{ + Edje *ed; + Edje_Text_Insert_Filter_Callback *cb; + Eina_List *l; + + ed = _edje_fetch(obj); + if ((!ed) || (!part)) return NULL; + EINA_LIST_FOREACH(ed->text_insert_filter_callbacks, l, cb) + { + if ((!strcmp(cb->part, part)) && (cb->func == func) && + (cb->data == data)) + { + void *data = cb->data; + ed->text_insert_filter_callbacks = + eina_list_remove_list(ed->text_insert_filter_callbacks, l); + eina_stringshare_del(cb->part); + free(cb); + return data; + } + } + return NULL; +} + /** * @brief Swallows an object into the edje. *