3. Events and callbacks
Germán Arias edited this page 5 years ago

3 Events and Callbacks

Callbacks are used by the application to receive notifications from the system that the user or the system itself has interacted with the user interface of the application. In Eiffel-IUP to set a function as a callback you should use the appropriate procedure to do this. The name of these procedures begin with set_cb. For example to set a callback in a button:

my_button.set_cb_action (agent my_button_action)

All callbacks receive at least the element which activated the action as a parameter (Current). For the specific parameters you should look at the documentation of the desired callback.

The callbacks implemented by the application must return one of the following values (strings):

  • "IUP_DEFAULT": Proceeds normally with user interaction. In case other return values do not apply, the callback should return this value.
  • "IUP_CLOSE": Call exit_loop after return. Depending on the state of the application it will close all windows and exit the application. Applies only to some actions.
  • "IUP_IGNORE": Makes the native system ignore that callback action. Applies only to some actions.
  • "IUP_CONTINUE": Makes the element to ignore the callback and pass the treatment of the execution to the parent element. Applies only to some actions.

Only some callbacks support the last 3 return values. Check each callback documentation. When nothing is documented then only "IUP_DEFAULT" is supported.

An important detail when using callbacks is that they are only called when the user actually executes an action over an element. A callback is not called when the programmer sets a value programmatically. For instance: when the programmer changes a selected item on a list, no callback is called.

The order of callback calling is system dependent. For instance, the resize and the show callbacks are called in different order in Win32 and in X-Windows when the dialog is shown for the first time.

All we have seen until now is a short summary of what is behind the Eiffel-IUP library and concepts that the developer needs to be familiarized with when programming with Eiffel-IUP. From now on, we are going to present how to build an IUP application from the most simple example possible to a complex and full of different resources application.