#include <gtk/gtk.h>

static void activate_cb (GtkAction *action)
{
  g_print ("Action %s activated\n", gtk_action_get_name (action));
}

static void mnemonics_toggled_cb (GtkToggleButton *button,
                                  GtkWidget *widget)
{
  g_object_set (gtk_widget_get_settings (widget),
                "gtk-enable-mnemonics",
                gtk_toggle_button_get_active (button),
                NULL);
}

static GtkActionEntry entries[] = {
  { "File", NULL, "_File" }, /* with mnemonic! */
  { "Edit", NULL, "Edit" },  /* without mnemonic! */

  { "Item1",  NULL,  "File item 1",     "<alt>F", NULL, G_CALLBACK (activate_cb) },
  { "Item2",  NULL,  "File item 2",     "<alt>E", NULL, G_CALLBACK (activate_cb) },
  { "Item3",  NULL,  "Edit item 1",     "<alt>K", NULL, G_CALLBACK (activate_cb) },
};

static const char ui_data[] =
"<ui>"
"<menubar>"
"<menu action=\"File\">"
"<menuitem action=\"Item1\" />"
"<menuitem action=\"Item2\" />"
"</menu>"
"<menu action=\"Edit\">"
"<menuitem action=\"Item3\" />"
"</menu>"
"</menubar>"
"</ui>";

int
main (int argc, char **argv)
{
  GtkActionGroup *action_group;
  GtkUIManager *merge;
  GtkWidget *window, *vbox, *button;
  
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  vbox = gtk_vbox_new (FALSE, 6);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  action_group = gtk_action_group_new ("Actions");
  gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), NULL);

  merge = gtk_ui_manager_new ();
  gtk_ui_manager_insert_action_group (merge, action_group, 0);
  gtk_ui_manager_add_ui_from_string (merge, ui_data, sizeof (ui_data) - 1, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_ui_manager_get_widget (merge, "/menubar"), FALSE, FALSE, 0);
  g_object_unref (action_group);

  gtk_window_add_accel_group (GTK_WINDOW (window),
			      gtk_ui_manager_get_accel_group (merge));
  
  button = gtk_check_button_new_with_label ("Menubar mnemonics");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
  g_signal_connect (button, "toggled", G_CALLBACK (mnemonics_toggled_cb), window);
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  gtk_box_pack_start (GTK_BOX (vbox), gtk_entry_new (), FALSE, FALSE, 0);
  
  gtk_widget_show_all (vbox);

  gtk_window_present (GTK_WINDOW (window));

  gtk_main ();

  g_object_unref (merge);

  return 0;
}
