GtkMenuItem bug (I think)

  Save the body of this message as failure.c and compile with :

  gcc `gtk-config --cflags` failure.c -o failure `gtk-config --libs`

 * I believe the following code demonstrates a Gtk+ bug in the latest
 * CVS version. I am creating a menu item with
 * gtk_menu_item_new_with_label(). Right after it is created, and
 * right before calling gtk_main(), calling gtk_container_children()
 * on it returns a non-empty list. However, calling
 * gtk_container_children() on it from the "activate" signal callback
 * results in NULL. Either there is a bug here or I am majorly
 * misunderstanding something. This behavior has been reproduced by
 * others with this test program.  

#include <gtk/gtk.h>

test_callback (GtkWidget *widget, void *data) 
  GList *children;

  children = gtk_container_children(GTK_CONTAINER(widget));

  if (NULL==children) {
    puts("children NULL in callback!");
  } else {
    puts("children not NULL in callback!");

main (int argc, char **argv)
  GtkWidget *window;
  GtkWidget *option_menu;
  GtkWidget *menu;
  GtkWidget *menu_item;
  GList *children;

  gtk_init (&argc, &argv);

  menu_item = gtk_menu_item_new_with_label("Test case.");
  children = gtk_container_children(GTK_CONTAINER(menu_item));

  if (NULL==children) {
    puts("children intially NULL!");
  } else {
    puts("children intially not NULL!");

  gtk_signal_connect(GTK_OBJECT(menu_item), "activate", 
		     test_callback, NULL);

  menu = gtk_menu_new();
  gtk_menu_append(GTK_MENU(menu), menu_item);

  option_menu = gtk_option_menu_new();
  gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);

  window = gtk_window_new(GTK_TOPLEVEL);
  gtk_container_add(GTK_CONTAINER(window), option_menu);

  if (NULL==children) {
    puts("children NULL before gtk_main!");
  } else {
    puts("children not NULL before gtk_main!");

  gtk_main ();
  return 0;

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