#include <gtk/gtk.h>

static void
baa_selected (GtkWidget *item, gpointer *user_data)
{
	g_printerr ("Baa!\n");
	gtk_widget_destroy (gtk_widget_get_toplevel (item));
}

static void
button_clicked (GtkWidget *button, gpointer data)
{
	GtkWidget *menu, *item, *submenu;

	menu = gtk_menu_new ();
	gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (button));

	item = gtk_image_menu_item_new_with_mnemonic ("Moo");
	gtk_widget_show (item);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
	submenu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);

	item = gtk_image_menu_item_new_with_mnemonic ("Baa");
	gtk_widget_show (item);
	gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
	g_signal_connect (G_OBJECT (item),
			  "activate",
			  G_CALLBACK (baa_selected), NULL);


	gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0,
			gtk_get_current_event_time());
}


int
main (int argc, char **argv)
{
  GtkWidget *window, *hbox;
  GtkWidget *button;
  
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 0);

  g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
  gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_widget_show (hbox);

  button = gtk_button_new_with_label ("Refresh");
  gtk_box_pack_start (GTK_BOX (hbox),
		      button,
		      FALSE, FALSE,
		      2);
  gtk_widget_show (button);
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (button_clicked), 
		    NULL);

  
  gtk_widget_show (window);

  gtk_main ();

  return 0;
}
