#include <gtk/gtk.h>

const gchar *ui = 
    "<ui>"
    " <toolbar>"
    "  <toolitem action='IndexButton'>"
    "   <menu action='Menu'>"
    "    <menuitem action='Dummy'/>"
    "    <menuitem action='Quit'/>"
    "   </menu>"
    "  </toolitem>"
    "  <toolitem action='Close'/>"
    " </toolbar>"
    "</ui>";

GtkActionEntry toolbar_items[] = {
    { "IndexButton", GTK_STOCK_INDEX, NULL, NULL, NULL, NULL },
    { "Menu", NULL, NULL, NULL, NULL, NULL },
    { "Dummy", NULL, NULL, NULL, "Nothing", NULL },
    { "Quit", GTK_STOCK_DELETE, NULL, NULL, NULL, gtk_main_quit },
    { "Close", GTK_STOCK_CLOSE, NULL, NULL, NULL, gtk_main_quit }
};

/* I expect: the first button on the toolbar will pop down a 
   menu with two items.

   I get: the first button does nothing, plus an error message:

   Gtk-CRITICAL **: gtk_menu_tool_button_set_menu: assertion 
   `GTK_IS_MENU_TOOL_BUTTON (button)' failed
*/

GtkWidget *make_toolbar (void)
{
    GtkActionGroup *actions;
    GtkAction *action;
    GtkToolItem *proxy;
    GtkUIManager *mgr;
    GError *err = NULL;

    actions = gtk_action_group_new("Actions");
    gtk_action_group_add_actions(actions, toolbar_items, 
				 G_N_ELEMENTS(toolbar_items),
				 NULL);

    proxy = gtk_menu_tool_button_new(NULL, NULL);

    action = gtk_action_group_get_action(actions, "IndexButton");
    proxy = gtk_menu_tool_button_new(NULL, NULL);
    gtk_action_connect_proxy(action, GTK_WIDGET(proxy));

    action = gtk_action_group_get_action(actions, "Menu");
    proxy = gtk_menu_tool_button_new(NULL, NULL);
    gtk_action_connect_proxy(action, GTK_WIDGET(proxy));

    mgr = gtk_ui_manager_new();
    gtk_ui_manager_insert_action_group(mgr, actions, 0);
    g_object_unref(actions);

    gtk_ui_manager_add_ui_from_string(mgr, ui, -1, &err);
    gtk_ui_manager_ensure_update(mgr);

    if (err != NULL) {
	fprintf(stderr, "building toolbar failed: %s", err->message);
	g_error_free(err);
    } 

    return gtk_ui_manager_get_widget(mgr, "/toolbar");
}

int main (int argc, char **argv)
{
    GtkWidget *w;

    gtk_init(&argc, &argv);

    w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(w), 80, -1);

    g_signal_connect(G_OBJECT(w), "destroy",
		     gtk_main_quit, NULL);

    gtk_container_add(GTK_CONTAINER(w), make_toolbar());
    gtk_widget_show_all(w);
    
    gtk_main();

    return 0;
}
