next up previous contents
Next: Widgets Up: Using GTK Previous: Main loop   Contents

Signals and Call-backs

Creating widgets is not all. There should be interactions among widgets defined. These interactions are made using signals and call-backs.

GTK is an event driven toolkit, which means it will sleep in gtk_main (the main processing loop) until an event occurs and control is passed to the appropriate function.

This passing of control is done using the idea of ``signals''. When an event occurs, such as the press of a mouse button, the appropriate signal will be ``emitted'' by the widget that was pressed. This is how GTK performs most of its useful work. There is a set of signals that all widgets inherit, such as ``destroy'', and there are signals that are widget specific, such as ``toggled'' on a toggle button.

A call-back (or call-back function) is a function which is called when a specified signal is emitted by a specified widget.

To connect a signal, a widget and a call-back gtk_signal_connect function is needed. The syntax of this function is given below:

     gint gtk_signal_connect( GtkObject     *object,
                              gchar         *name,
                              GtkSignalFunc  func,
                              gpointer       func_data );

In the routine above, the first argument is the widget which will be emitting the signal, and the second, the name of the signal one wishes to catch. The third is the function one wishes to be called when it is caught, and the fourth, the data one wishes to have been passed to this function.

The function specified in the third argument is called a ``call-back function'', and should generally be of the form:

     void callback_func( GtkWidget *widget,
                         gpointer   callback_data );

Where the first argument will be a pointer to the widget that emitted the signal, and the second, a pointer to the data given as the last argument to the gtk_signal_connect() function as shown above.


next up previous contents
Next: Widgets Up: Using GTK Previous: Main loop   Contents
Igor Wojnicki 2001-02-21