GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Aug 24, 2016 5:56 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: trouble with event propagation
PostPosted: Wed Feb 27, 2008 10:44 pm 
Familiar Face

Joined: Wed Feb 27, 2008 9:27 pm
Posts: 6

I have a small code example, It should demonstrate the event propagation
in GTK+.

I have three widgets. A button, fixed container and a window. I have three
callbacks. After I click on the button, I expect a message from all parent widgets.
I must be missing something, cause it is not working. I am getting message only from the button widget.

Thanks for your suggestions.

jan bodnar

#include <gtk/gtk.h>

static gboolean button_reached(GtkWidget *widget, GdkEvent *event, gpointer data)
   g_print("button widget reached");

   return FALSE;

static gboolean fixed_reached(GtkWidget *widget, GdkEvent *event,  gpointer data)
   g_print("fixed container reached");

   return FALSE;

static gboolean window_reached(GtkWidget *widget, gpointer data)
   g_print("window widget reached");

   return FALSE;

int main( int argc, char *argv[])

  GtkWidget *window;
  GtkWidget *fixed;
  GtkWidget *button;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
  gtk_window_set_title(GTK_WINDOW(window), "Simple");
  gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);

  fixed = gtk_fixed_new();
  gtk_widget_add_events(fixed, GDK_BUTTON_PRESS_MASK);

  button = gtk_button_new_with_label("Button");
  gtk_fixed_put(GTK_FIXED(fixed), button, 50, 50);
  gtk_container_add(GTK_CONTAINER(window), fixed);

  g_signal_connect(G_OBJECT(button), "button-press-event",
        G_CALLBACK(button_reached), NULL);

  g_signal_connect(G_OBJECT(fixed), "button-press-event",
        G_CALLBACK(fixed_reached), NULL);
  g_signal_connect(G_OBJECT(window), "button-press-event",
        G_CALLBACK(window_reached), NULL);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), G_OBJECT(window));



  return 0;

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group