Re: Adding a user signal to a widget



Hans Oesterholt wrote:
Can anyone tell me how to add a user signal of type G_RUN_ACTION to a widget?
- I can't find G_RUN_ACTION in any header file I have.
Use G_SIGNAL_ACTION instead. There was a type in the reference, as I remember.
- I can't find |gtk_object_class_user_signal_new |in any header file I have.
It's from gtk+-1.2, use g_signal_new() in GTK2.

The following defines new signal for GtkWindow class with G_SIGNAL_ACTION flag:

-- C
#include <gtk/gtk.h>

static void
catcher ()
{
  g_print ("signal catched\n");
}

static void
emitter (GtkWidget * window)
{
  g_signal_emit_by_name (window, "user-signal");
}

int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
  g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), 0);

  g_signal_new ("user-signal",
                gtk_window_get_type (),
                G_SIGNAL_ACTION,
                0,
                NULL, NULL,
                g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0
  );
  g_signal_connect (window, "user-signal", G_CALLBACK (catcher), 0);

  button = gtk_button_new_with_label ("emit");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (emitter), window);

  gtk_container_add (GTK_CONTAINER (window), button);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
-- C

	Olexiy



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]