Add evas_object_event_callback_del_full()

This will check both function and data before removing the callback,
this is useful when you have lots of children monitoring parent, when
one child want to remove its monitoring function, others will remain.

Name is quite difficult to choose, I opted for "_full", but could be
"_with_data" or similar.


SVN revision: 34731
This commit is contained in:
Gustavo Sverzut Barbieri 2008-06-03 20:33:40 +00:00
parent 6267ff56b3
commit b802f4c94a
2 changed files with 61 additions and 0 deletions

View File

@ -865,6 +865,7 @@ extern "C" {
EAPI void evas_object_event_callback_add (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), const void *data);
EAPI void *evas_object_event_callback_del (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info));
EAPI void *evas_object_event_callback_del_full(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), const void *data);
EAPI int evas_async_events_fd_get (void);
EAPI int evas_async_events_process (void);

View File

@ -406,3 +406,63 @@ evas_object_event_callback_del(Evas_Object *obj, Evas_Callback_Type type, void (
}
return NULL;
}
/**
* Delete a callback function from an object
* @param obj Object to remove a callback from
* @param type The type of event that was triggering the callback
* @param func The function that was to be called when the event was triggered
* @param data The data pointer that was to be passed to the callback
* @return The data pointer that was to be passed to the callback
*
* This function removes the most recently added callback from the object
* @p obj which was triggered by the event type @p type and was calling the
* function @p func with data @p data when triggered. If the removal is
* successful it will also return the data pointer that was passed to
* evas_object_event_callback_add() (that will be the same as the parameter)
* when the callback was added to the object. If not successful NULL will be
* returned.
*
* Example:
* @code
* extern Evas_Object *object;
* void *my_data;
* void up_callback(void *data, Evas *e, Evas_Object *obj, void *event_info);
*
* my_data = evas_object_event_callback_del_full(object, EVAS_CALLBACK_MOUSE_UP, up_callback, data);
* @endcode
* @ingroup Evas_Object_Callback_Group
*/
EAPI void *
evas_object_event_callback_del_full(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), const void *data)
{
/* MEM OK */
Evas_Object_List *l;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return NULL;
MAGIC_CHECK_END();
if (!func) return NULL;
if (!obj->callbacks) return NULL;
for (l = obj->callbacks->callbacks; l; l = l->next)
{
Evas_Func_Node *fn;
fn = (Evas_Func_Node *)l;
if ((fn->func == func) && (fn->type == type) && (fn->data == data) && (!fn->delete_me))
{
void *data;
data = fn->data;
fn->delete_me = 1;
obj->callbacks->deletions_waiting = 1;
if (!obj->callbacks->walking_list)
evas_object_event_callback_clear(obj);
return data;
}
}
return NULL;
}