Synopsis#include <gtk/gtk.h> #define GTK_SIGNAL_OFFSET enum GtkSignalRunType; guint gtk_signal_new (const gchar *name, GtkSignalRunType signal_flags, GtkType object_type, guint function_offset, GtkSignalMarshaller marshaller, GtkType return_val, guint n_args, ...); guint gtk_signal_newv (const gchar *name, GtkSignalRunType signal_flags, GtkType object_type, guint function_offset, GtkSignalMarshaller marshaller, GtkType return_val, guint n_args, GtkType *args); #define gtk_signal_lookup (name,object_type) #define gtk_signal_name (signal_id) void gtk_signal_emit (GtkObject *object, guint signal_id, ...); void gtk_signal_emit_by_name (GtkObject *object, const gchar *name, ...); void gtk_signal_emitv (GtkObject *object, guint signal_id, GtkArg *args); void gtk_signal_emitv_by_name (GtkObject *object, const gchar *name, GtkArg *args); #define gtk_signal_emit_stop (object,signal_id) void gtk_signal_emit_stop_by_name (GtkObject *object, const gchar *name); #define gtk_signal_connect (object,name,func,func_data) #define gtk_signal_connect_after (object,name,func,func_data) #define gtk_signal_connect_object (object,name,func,slot_object) #define gtk_signal_connect_object_after (object,name,func,slot_object) gulong gtk_signal_connect_full (GtkObject *object, const gchar *name, GtkSignalFunc func, GtkCallbackMarshal unsupported, gpointer data, GDestroyNotify destroy_func, gint object_signal, gint after); void gtk_signal_connect_while_alive (GtkObject *object, const gchar *name, GtkSignalFunc func, gpointer func_data, GtkObject *alive_object); void gtk_signal_connect_object_while_alive (GtkObject *object, const gchar *name, GtkSignalFunc func, GtkObject *alive_object); #define gtk_signal_disconnect (object,handler_id) #define gtk_signal_disconnect_by_func (object,func,data) #define gtk_signal_disconnect_by_data (object,data) #define gtk_signal_handler_block (object,handler_id) #define gtk_signal_handler_block_by_func (object,func,data) #define gtk_signal_handler_block_by_data (object,data) #define gtk_signal_handler_unblock (object,handler_id) #define gtk_signal_handler_unblock_by_func (object,func,data) #define gtk_signal_handler_unblock_by_data (object,data) #define gtk_signal_handler_pending (object,signal_id,may_be_blocked) #define gtk_signal_handler_pending_by_func (object,signal_id,may_be_blocked,func,data) #define gtk_signal_default_marshaller DescriptionThe GTK+ signal system merely proxies the GLib signal system now. For future usage, direct use of the GSignal API is recommended, this avoids significant performance hits where GtkArg structures have to be converted into GValues. What are signals?Signals are a way to get notification when something happens and to customize object behavior according to the user's needs. Every signal is uniquely identified by a name, "class_name::signal_name", where signal_name might be something like "clicked" and class_name might be "GtkButton". Note that some other class may also define a "clicked" callback, so long as it doesn't derive from GtkButton. When they are created, they are also assigned a unique positive integer, the signal id (1 is the first signal id- 0 is used to flag an error). Each is also tied to an array of types that describes the prototype of the function pointer(s) (handlers) you may connect to the signal. Finally, every signal has a default handler that is given by a function pointer in its class structure: it is run by default whenever the signal is emitted. (It is possible that a signal will be emitted and a user-defined handler will prevent the default handler from being run.)
Signals are used by everyone, but they are only
created on a per class basis -- so you should not call
call How are signals used?There are two basic actions in the signal handling game. If you want notification of an event, you must connect a function pointer and a data pointer to that signal; the data pointer will be passed as the last argument to the function (so long as you are using the default marshalling functions). You will receive a connection id, a unique positive integer corresponding to that attachment. Functions that want to notify the user of certain actions, emit signals. Basic Terminology
A brief note on how they work.
The functions responsible for translating an array of GtkArgs
to your C compiler's normal semantics are called Marshallers.
They are identified by
gtk_marshal_ DetailsGTK_SIGNAL_OFFSET#define GTK_SIGNAL_OFFSET GTK_STRUCT_OFFSET Warning
Use in place of enum GtkSignalRunTypetypedef enum /*< flags >*/
{
GTK_RUN_FIRST = G_SIGNAL_RUN_FIRST,
GTK_RUN_LAST = G_SIGNAL_RUN_LAST,
GTK_RUN_BOTH = (GTK_RUN_FIRST | GTK_RUN_LAST),
GTK_RUN_NO_RECURSE = G_SIGNAL_NO_RECURSE,
GTK_RUN_ACTION = G_SIGNAL_ACTION,
GTK_RUN_NO_HOOKS = G_SIGNAL_NO_HOOKS
} GtkSignalRunType;
Warning
These configure the signal's emission. They control whether the signal can be emitted recursively on an object and whether to run the default method before or after the user-defined handlers.
gtk_signal_new ()guint gtk_signal_new (const gchar *name,
GtkSignalRunType signal_flags,
GtkType object_type,
guint function_offset,
GtkSignalMarshaller marshaller,
GtkType return_val,
guint n_args,
...);
Warning
Creates a new signal type. (This is usually done in the class initializer.)
gtk_signal_newv ()guint gtk_signal_newv (const gchar *name,
GtkSignalRunType signal_flags,
GtkType object_type,
guint function_offset,
GtkSignalMarshaller marshaller,
GtkType return_val,
guint n_args,
GtkType *args);
Warning
Creates a new signal type. (This is usually done in a class initializer.)
This function take the types as an array, instead of a list
following the arguments. Otherwise the same as
gtk_signal_lookup()#define gtk_signal_lookup(name,object_type) Warning
Given the name of the signal and the type of object it connects to, get the signal's identifying integer. Emitting the signal by number is somewhat faster than using the name each time. It also tries the ancestors of the given type.
gtk_signal_name()#define gtk_signal_name(signal_id) Warning
Given the signal's identifier, finds its name. Two different signals may have the same name, if they have differing types.
gtk_signal_emit ()void gtk_signal_emit (GtkObject *object, guint signal_id, ...); Warning
Emits a signal. This causes the default handler and user-defined handlers to be run.
Here is what 1. Calls the default handler and the user-connected handlers. The default handler will be called first if GTK_RUN_FIRST is set, and last if GTK_RUN_LAST is set. 2. Calls all handlers connected with the "after" flag set.
gtk_signal_emit_by_name ()void gtk_signal_emit_by_name (GtkObject *object, const gchar *name, ...); Warning
Emits a signal. This causes the default handler and user-connected handlers to be run.
gtk_signal_emitv ()void gtk_signal_emitv (GtkObject *object, guint signal_id, GtkArg *args); Warning
Emits a signal. This causes the default handler and user-connected
handlers to be run. This differs from
gtk_signal_emitv_by_name ()void gtk_signal_emitv_by_name (GtkObject *object, const gchar *name, GtkArg *args); Warning
Emits a signal by name. This causes the default handler and user-connected
handlers to be run. This differs from
gtk_signal_emit_stop()#define gtk_signal_emit_stop(object,signal_id) Warning
This function aborts a signal's current emission. It will prevent the default method from running, if the signal was GTK_RUN_LAST and you connected normally (i.e. without the "after" flag). It will print a warning if used on a signal which isn't being emitted.
gtk_signal_emit_stop_by_name ()void gtk_signal_emit_stop_by_name (GtkObject *object, const gchar *name); Warning
This function aborts a signal's current emission.
It is just like
gtk_signal_connect()#define gtk_signal_connect(object,name,func,func_data) Warning
Attaches a function pointer and user data to a signal for a particular object.
The GtkSignalFunction takes a GtkObject as its first parameter.
It will be the same object as the one you're connecting
the hook to. The
All else being equal, signal handlers are invoked in the order
connected (see Here is how one passes an integer as user data, for when you just want to specify a constant int as parameter to your function:
static void button_clicked_int (GtkButton* button, gpointer func_data)
{
g_print ("button pressed: %d\n", GPOINTER_TO_INT (func_data));
}
/* By calling this function, you will make the g_print above
* execute, printing the number passed as `to_print'. */
static void attach_print_signal (GtkButton* button, gint to_print)
{
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (button_clicked_int),
GINT_TO_POINTER (to_print));
}
gtk_signal_connect_after()#define gtk_signal_connect_after(object,name,func,func_data) Warning
Attaches a function pointer and user data to a signal so that this handler will be called after the other handlers.
gtk_signal_connect_object()#define gtk_signal_connect_object(object,name,func,slot_object) Warning
This function is for registering a callback that will call another object's callback. That is, instead of passing the object which is responsible for the event as the first parameter of the callback, it is switched with the user data (so the object which emits the signal will be the last parameter, which is where the user data usually is).
This is useful for passing a standard function in as a callback.
For example, if you wanted a button's press to gtk_signal_connect_object (button, "clicked", gtk_widget_show, window);
gtk_signal_connect_object_after()#define gtk_signal_connect_object_after(object,name,func,slot_object) Warning
Attaches a signal hook to a signal, passing in an alternate object as the first parameter, and guaranteeing that the default handler and all normal handlers are called first.
gtk_signal_connect_full ()gulong gtk_signal_connect_full (GtkObject *object, const gchar *name, GtkSignalFunc func, GtkCallbackMarshal unsupported, gpointer data, GDestroyNotify destroy_func, gint object_signal, gint after); Warning
Attaches a function pointer and user data to a signal with more control.
gtk_signal_connect_while_alive ()void gtk_signal_connect_while_alive (GtkObject *object, const gchar *name, GtkSignalFunc func, gpointer func_data, GtkObject *alive_object); Warning
Attaches a function pointer and another GtkObject to a signal. This function takes an object whose "destroy" signal should be trapped. That way, you don't have to clean up the signal handler when you destroy the object. It is a little less efficient though.
(Instead you may call
gtk_signal_connect_object_while_alive ()void gtk_signal_connect_object_while_alive
(GtkObject *object,
const gchar *name,
GtkSignalFunc func,
GtkObject *alive_object);
Warning
These signal connectors are for signals which refer to objects, so they must not be called after the object is deleted.
Unlike
This function acts just like
gtk_signal_disconnect()#define gtk_signal_disconnect(object,handler_id) Warning
Destroys a user-defined handler connection.
gtk_signal_disconnect_by_func()#define gtk_signal_disconnect_by_func(object,func,data) Warning
Destroys all connections for a particular object, with the given function-pointer and user-data.
gtk_signal_disconnect_by_data()#define gtk_signal_disconnect_by_data(object,data) Warning
Destroys all connections for a particular object, with the given user-data.
gtk_signal_handler_block()#define gtk_signal_handler_block(object,handler_id) Warning
Prevents a user-defined handler from being invoked. All other signal processing will go on as normal, but this particular handler will ignore it.
gtk_signal_handler_block_by_func()#define gtk_signal_handler_block_by_func(object,func,data) Warning
Prevents a user-defined handler from being invoked, by reference to the user-defined handler's function pointer and user data. (It may result in multiple hooks being blocked, if you've called connect multiple times.)
gtk_signal_handler_block_by_data()#define gtk_signal_handler_block_by_data(object,data) Warning
Prevents all user-defined handlers with a certain user data from being invoked.
gtk_signal_handler_unblock()#define gtk_signal_handler_unblock(object,handler_id) Warning
Undoes a block, by connection id. Note that undoing a block doesn't necessarily make the hook callable, because if you block a hook twice, you must unblock it twice.
gtk_signal_handler_unblock_by_func()#define gtk_signal_handler_unblock_by_func(object,func,data) Warning
Undoes a block, by function pointer and data. Note that undoing a block doesn't necessarily make the hook callable, because if you block a hook twice, you must unblock it twice.
gtk_signal_handler_unblock_by_data()#define gtk_signal_handler_unblock_by_data(object,data) Warning
Undoes block(s), to all signals for a particular object with a particular user-data pointer
gtk_signal_handler_pending()#define gtk_signal_handler_pending(object,signal_id,may_be_blocked) Warning
Returns a connection id corresponding to a given signal id and object. One example of when you might use this is when the arguments to the signal are difficult to compute. A class implementor may opt to not emit the signal if no one is attached anyway, thus saving the cost of building the arguments.
gtk_signal_handler_pending_by_func()#define gtk_signal_handler_pending_by_func(object,signal_id,may_be_blocked,func,data) Warning
Returns a connection id corresponding to a given signal id, object, function pointer and user data.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||