trouble with event propagation
- From: vronskij <vronskij gmail com>
- To: gtk-list gnome org
- Subject: trouble with event propagation
- Date: Sun, 30 Mar 2008 20:50:16 +0200
Hi,
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 these three widgets. First from the button, then from fixed container and from the window.
I must be missing something, cause it is not working. I am getting message only from the button widget.
How should I modify the example, so that the code works?
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));
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]