GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

trouble with event propagation

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
vronskij



Joined: 27 Feb 2008
Posts: 3

PostPosted: Wed Feb 27, 2008 10:44 pm    Post subject: trouble with event propagation Reply with quote

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 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

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#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;
}
[/code]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP