Re: Question on emission hooks
- From: "Nickolay V. Shmyrev" <nshmyrev yandex ru>
- To: Lucas Di Pentima <lucas lunix com ar>
- Cc: Gnome Development <gnome-devel-list gnome org>
- Subject: Re: Question on emission hooks
- Date: Sat, 02 Oct 2004 18:30:30 +0400
Hello.
Sorry for style of my first answer, it seems that you have quite old
glib, because now (in 2.4.0 )it is impossible to g_signal_lookup on
G_TYPE_OBJECT, since it is not G_TYPE_IS_INSTANTIABLE, that's why I
thought that you are trying to to add emission hook to "notify" signale
of your type GWP_TYPE_SHIP, not G_TYPE_OBJECT.
Even if you can get signal_id, it is not clear, that you can add
emission hook to that signal, because signal can have flag
G_SIGNAL_NO_HOOKS. The "notify" signal of g_object is exactly such
signal, that is why you get warning message.
Look at glib sources:
gobject_signals[NOTIFY] =
g_signal_new ("notify",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE |
G_SIGNAL_DETAILED | G_STRUCT_OFFSET (GObjectClass, notify),
NULL, NULL,
g_cclosure_marshal_VOID__PARAM,
G_TYPE_NONE,
1, G_TYPE_PARAM);
g_signal_add_emission_hook (guint signal_id,
GQuark detail,
GSignalEmissionHook hook_func,
gpointer hook_data,
GDestroyNotify data_destroy)
{
static gulong seq_hook_id = 1;
SignalNode *node;
GHook *hook;
SignalHook *signal_hook;
g_return_val_if_fail (signal_id > 0, 0);
g_return_val_if_fail (hook_func != NULL, 0);
SIGNAL_LOCK ();
node = LOOKUP_SIGNAL_NODE (signal_id);
if (!node || node->destroyed || (node->flags & G_SIGNAL_NO_HOOKS))
{
g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
SIGNAL_UNLOCK ();
return 0;
}
Otherwise, all goes fine:
#include <gtk/gtk.h>
static gboolean
clicked_emission_hook (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
g_message ("HOOK!!!");
return TRUE;
}
static gboolean
on_clicked (GObject *button, gpointer data)
{
g_message ("ACTIVATE!!!");
return TRUE;
}
int main (int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label ("Push me");
gtk_container_add (GTK_CONTAINER(window), button);
gtk_widget_show_all (window);
g_signal_add_emission_hook (g_signal_lookup("clicked",
GTK_TYPE_BUTTON),
0, clicked_emission_hook, NULL, NULL);
g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(on_clicked),
NULL);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]