Next, you'll want to arrange to respond when users
manipulate the widgets. In this simple application,
there are two interesting things that can happen: the
user can click the button, or close the window using
a window manager decoration. Widgets (actually, all
GtkObjects) emit signals when something
interesting happens a program might want to respond
to. To respond to a signal, you "connect a callback"
to it---i.e., register a function to be called when
the signal is emitted. Here's that code again:
gtk_signal_connect(GTK_OBJECT(window),
"delete_event",
GTK_SIGNAL_FUNC(delete_event_cb),
NULL);
gtk_signal_connect(GTK_OBJECT(button),
"clicked",
GTK_SIGNAL_FUNC(button_click_cb),
label);
|
gtk_signal_connect()
specifies the
GtkObject to monitor, which signal to connect
to, the callback to connect, and finally a user_data argument---this
is an arbitrary
gpointer which will be passed to the callback.
The macro GTK_SIGNAL_FUNC()
casts the callback to a standard function signature;
since callbacks have a variety of type signatures,
the alternative would be dozens of gtk_signal_connect() variants.
GTK+ performs copious runtime sanity checking; the
GTK_OBJECT() macro includes
a runtime type check in addition to a C cast, and gtk_signal_connect() will
verify that the object can actually emit the signal
you've specified.