#include <gtk/gtk.h>

static void
destroy_cb (GtkWidget *widget,
            gpointer   user_data)
{
  gtk_main_quit ();
}

static void
activate_cb (GtkMenuItem *menu_item,
             gpointer     user_data)
{
  g_message ("%s ((%s *) %p, (%s *) %p)",
             G_STRFUNC,
             G_OBJECT_TYPE_NAME (menu_item), menu_item,
             G_OBJECT_TYPE_NAME (user_data), user_data);
}

static void
hide_cb (GtkWidget *widget,
         gpointer   user_data)
{
  GtkWidget *menu_item = user_data;

  g_message ("%s ((%s *) %p, (%s *) %p)",
             G_STRFUNC,
             G_OBJECT_TYPE_NAME (widget), widget,
             G_OBJECT_TYPE_NAME (user_data), user_data);

  gtk_container_remove (GTK_CONTAINER (widget), menu_item);

  g_signal_handlers_disconnect_by_func (widget, hide_cb, user_data);
}

int
main (int   argc,
      char *argv[])
{
  GtkWidget *window;
  GtkWidget *menu_shell;
  GtkWidget *menu_item;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
  menu_shell = gtk_menu_bar_new ();
  gtk_container_add (GTK_CONTAINER (window), menu_shell);
  menu_item = gtk_menu_item_new_with_mnemonic ("_File");
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), menu_item);
  menu_shell = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu_shell);
  menu_item = gtk_menu_item_new_with_mnemonic ("_Activate");
  g_signal_connect (menu_item, "activate", G_CALLBACK (activate_cb), NULL);
  g_signal_connect (menu_shell, "hide", G_CALLBACK (hide_cb), menu_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), menu_item);
  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
