forked from enlightenment/efl
Eo event callbacks: Change the way callbacks are stopped.
Instead of using the return value, we now use eo_event_callback_stop() to stop calling other callbacks.
This commit is contained in:
parent
508ba2e249
commit
d648eb5311
|
@ -1047,20 +1047,6 @@ EAPI const Eo_Event_Description *eo_base_legacy_only_event_description_get(const
|
|||
*/
|
||||
#define EO_CALLBACK_PRIORITY_AFTER 100
|
||||
|
||||
/**
|
||||
* @def EO_CALLBACK_STOP
|
||||
* Stop calling callbacks for the even of which the callback was called for.
|
||||
* @see EO_CALLBACK_CONTINUE
|
||||
*/
|
||||
#define EO_CALLBACK_STOP EINA_FALSE
|
||||
|
||||
/**
|
||||
* @def EO_CALLBACK_CONTINUE
|
||||
* Continue calling callbacks for the even of which the callback was called for.
|
||||
* @see EO_CALLBACK_STOP
|
||||
*/
|
||||
#define EO_CALLBACK_CONTINUE EINA_TRUE
|
||||
|
||||
/**
|
||||
* Helper for creating global callback arrays.
|
||||
* The problem is on windows where you can't declare a static array with
|
||||
|
|
|
@ -351,6 +351,15 @@ abstract Eo.Base ()
|
|||
$true otherwise
|
||||
]]
|
||||
}
|
||||
event_callback_stop {
|
||||
[[Stop the current callback call.
|
||||
|
||||
This stops the current callback call. Any other callbacks for the
|
||||
current event will not be called. This is useful when you want to
|
||||
filter out events. You just add higher priority events and call this
|
||||
on certain conditions to block a certain event.
|
||||
]]
|
||||
}
|
||||
event_callback_forwarder_add {
|
||||
[[Add an event callback forwarder for an event and an object.]]
|
||||
params {
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct
|
|||
unsigned short walking_list;
|
||||
unsigned short event_freeze_count;
|
||||
Eina_Bool deletions_waiting : 1;
|
||||
Eina_Bool callback_stopped : 1;
|
||||
} Eo_Base_Data;
|
||||
|
||||
typedef enum {
|
||||
|
@ -1042,6 +1043,7 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
|
|||
const Eo_Event_Description *desc,
|
||||
void *event_info)
|
||||
{
|
||||
Eina_Bool callback_already_stopped = pd->callback_stopped;
|
||||
Eina_Bool ret = EINA_TRUE;
|
||||
Eo_Callback_Description *cb;
|
||||
Eo_Current_Callback_Description *lookup = NULL;
|
||||
|
@ -1100,8 +1102,9 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
|
|||
|
||||
// Handle nested restart of walking list
|
||||
if (lookup) lookup->current = cb->next;
|
||||
it->func((void *) cb->func_data, &ev);
|
||||
/* Abort callback calling if the func says so. */
|
||||
if (!it->func((void *) cb->func_data, &ev))
|
||||
if (pd->callback_stopped)
|
||||
{
|
||||
ret = EINA_FALSE;
|
||||
goto end;
|
||||
|
@ -1122,8 +1125,9 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
|
|||
|
||||
// Handle nested restart of walking list
|
||||
if (lookup) lookup->current = cb->next;
|
||||
cb->items.item.func((void *) cb->func_data, &ev);
|
||||
/* Abort callback calling if the func says so. */
|
||||
if (!cb->items.item.func((void *) cb->func_data, &ev))
|
||||
if (pd->callback_stopped)
|
||||
{
|
||||
ret = EINA_FALSE;
|
||||
goto end;
|
||||
|
@ -1147,10 +1151,18 @@ end:
|
|||
pd->walking_list--;
|
||||
_eo_callbacks_clear(pd);
|
||||
|
||||
pd->callback_stopped = callback_already_stopped;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
EOLIAN static void
|
||||
_eo_base_event_callback_stop(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
|
||||
{
|
||||
pd->callback_stopped = EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_eo_event_forwarder_callback(void *data, const Eo_Event *event)
|
||||
{
|
||||
Eo *new_obj = (Eo *) data;
|
||||
|
@ -1158,7 +1170,10 @@ _eo_event_forwarder_callback(void *data, const Eo_Event *event)
|
|||
|
||||
ret = eo_event_callback_call(new_obj, event->desc, event->info);
|
||||
|
||||
return ret;
|
||||
if (!ret)
|
||||
{
|
||||
eo_event_callback_stop(event->object);
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: Change default priority? Maybe call later? */
|
||||
|
|
|
@ -203,7 +203,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
|
|||
if (tp->base_type->type == EOLIAN_TYPE_REGULAR &&
|
||||
!strcmp(tp->base_type->name, "__builtin_event_cb"))
|
||||
{
|
||||
eina_strbuf_append(buf, "Eina_Bool (*");
|
||||
eina_strbuf_append(buf, "void (*");
|
||||
_append_name(tp, buf);
|
||||
eina_strbuf_append(buf, ")(void *data, const Eo_Event *event)");
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue