Stopping signals from being passed to parent (possible bug)




Hi,

Am I right in assuming that if you return TRUE from a signal handler
then the signal will NOT be passed on to the widget's parent?

That doesn't always seem to be the case.

Below is a simple program with a hscrollbar in a window, both set
up to pass 'button_press' events to the 'on_button_press' handler,
which always returns TRUE.

If you click on the scrollbar, both the scrollbar and the window
get the event.

(I've also had problems with entry & text - there may be others)

Damon




#include <gtk/gtk.h>

gint
on_button_press(GtkWidget *widget, GdkEvent *event, gpointer data)
{
  g_print("In button_press:%s\n", gtk_widget_get_name(widget));
  /* Return TRUE so parent widgets shouldn't get this signal?? */
  return TRUE;
}

int
main(int argc, char *argv[])
{
  GtkWidget *win, *vbox, *scrollbar, *label;

  gtk_init(&argc, &argv);

  win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize(win, 300, 150);
  gtk_widget_set_events(win, gtk_widget_get_events(win)
   | GDK_BUTTON_PRESS_MASK);
  gtk_signal_connect (GTK_OBJECT (win), "button_press_event",
        GTK_SIGNAL_FUNC(on_button_press), NULL);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (win), vbox);
  gtk_widget_show (vbox);

  label = gtk_label_new("Scrollbar:");
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  scrollbar = gtk_hscrollbar_new(NULL);
  gtk_widget_set_events(scrollbar, gtk_widget_get_events(scrollbar)
   | GDK_BUTTON_PRESS_MASK);
  gtk_signal_connect (GTK_OBJECT (scrollbar), "button_press_event",
        GTK_SIGNAL_FUNC(on_button_press), NULL);
  gtk_box_pack_start (GTK_BOX (vbox), scrollbar, TRUE, TRUE, 0);
  gtk_widget_show (scrollbar);

  gtk_widget_show(win);
  gtk_main();
  return 0;
}







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