#include <gtk/gtk.h>

GtkWidget *new_menu_item(GtkWidget *menu, const char *str, GtkSignalFunc sf, gpointer data) {
	GtkWidget *menuitem;

        menuitem = gtk_menu_item_new_with_mnemonic(str);

	if (menu)
		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);

	if (sf)
		g_signal_connect(G_OBJECT(menuitem), "activate", sf, data);

	gtk_widget_show_all(menuitem);

	return menuitem;
}

static void do_test_cb() {
        gtk_main_quit();
}

static gboolean menu_leave_cb(GtkWidget *menu, GdkEventCrossing *event, void *data) {
	if(event->detail == GDK_NOTIFY_ANCESTOR) {
		gtk_menu_popdown(GTK_MENU(menu));
                gtk_main_quit();
        }
	return FALSE;
}

static void docklet_menu() {
	static GtkWidget *menu = NULL;

	if (menu) {
		gtk_widget_destroy(menu);
	}

	menu = gtk_menu_new();

        new_menu_item(menu, "Test Menu Item 1", G_CALLBACK(do_test_cb), NULL);
        new_menu_item(menu, "Test Menu Item 2", G_CALLBACK(do_test_cb), NULL);
        new_menu_item(menu, "Test Menu Item 3", G_CALLBACK(do_test_cb), NULL);

	g_signal_connect(menu, "leave-notify-event", G_CALLBACK(menu_leave_cb), NULL);

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

int main(int argc, char* argv[]) {
	gtk_init(&argc, &argv);
        docklet_menu();
	gtk_main();

	return 0;
}

