Evas smart objects events are the most widely-used type of events in graphical applications, since they are used for signals such as âclickedâ, âclicked,doubleâ (double-click), âpressedâ, etc. They are identified by strings and each smart object is able to define its own events (although the names follow conventions).
Use the evas_object_smart_callback_add()
function to add a callback for an
event to an object. Its prototype is
void evas_object_smart_callback_add(Evas_Object* obj, const char* event, Evas_Smart_Cb func, const void* data )
obj
a smart objectevent
the event's name stringfunc
the callback functiondata
user data to be passed to the callback functionEvas smart objects' âsmart callbackâ has the following signature:
void (* Evas_Smart_Cb) (void *data, Evas_Object *obj, void *event_info)
The callback function definition is similar to
void some_evas_smart_cb(void *data, Evas_Object *obj, void *event_info);
data
is the same as the data
which is given as the parameter to evas_object_smart_callback_add()
.obj
is the object for which the event happened.event_info
is data, which depends on the object type and event at play. The actual type is given in the documentation for the callback that is triggered
The following defines the _button_clicked()
function and sets it as the
callback for the clicked
event of an Evas_Object
(a button here).
static void _button_clicked(void *data, Evas_Object *obj, void *event_info) { // Insert function body here }
static void some_function(void) { // Code to build the window object Evas_Object *button = elm_button_add(window); evas_object_smart_callback_add(button, "clicked", _button_clicked, NULL); }
If some of the arguments are not used by the callback function, the compiler
may raise the âunused parameterâ warning. To avoid it, you can annotate the
argument with the UNUSED__
macro, which is a compiler-independent way to
let the compiler know that the parameter is willingly unused rather than by a
mistake.
<code c>
void cb(void *data UNUSED__, Evas_Object *obj, void *event_info UNUSED__);
</code>
For a given object and event, callbacks are called in the order they have been
added. The
evas_object_smart_callback_add() function does not execute any
special processing if it is called several times with the same callback
function and/or data. Callbacks are called as many times as they have been
added and in the order they have been added.
==== Removing a Callback on an Event: evas_object_smart_callback_del() ====
The
evas_object_smart_callback_del() function enables deleting a callback
for a signal on an object. Its prototype is
<code c>
void* evas_object_smart_callback_del(Evas_Object* obj,
const char* event,
Evas_Smart_Cb func
)
</code>
It removes the first match for the given event and callback and returns the
data pointer that was used in the corresponding call to
evas_object_smart_callback_add()''.
==== Examples ====
=== Basic Usage: Button with a Callback on the âclickedâ Signal ===
<code c>
static void
_button_clicked(void *data UNUSED__, Evas_Object *obj UNUSED__, void *event_info UNUSED__)
{
fprintf(stdout, âButton clicked.\nâ);
fflush(stdout);
elm_exit();
}
static void
_add_button(Evas_Object *window)
{
Evas_Object *button;
button = elm_button_add(window);
elm_object_text_set(button, âClick Me To Exit!â);
evas_object_smart_callback_add(button, âclickedâ, _button_clicked, NULL);
evas_object_show(button);
}
</code>
=== Usage with evas_object_smart_callback_del(): Clicking on the Button Removes the Callback ===
<code c>
static void
_button_clicked(void *data UNUSED__, Evas_Object *obj, void *event_info UNUSED__)
{
fprintf(stdout, âButton clicked.\nâ);
fflush(stdout);
evas_object_smart_callback_del(obj, âclickedâ, _button_clicked);
}
static void
_add_button(Evas_Object *window)
{
Evas_Object *button;
button = elm_button_add(window);
elm_object_text_set(button, âClick Me!â);
evas_object_smart_callback_add(button, âclickedâ, _button_clicked, NULL);
evas_object_show(button);
}
</code>
â-