#include <glib.h>
#include <gtk/gtk.h>

static gboolean
mnemonic_activate_cb (GtkWidget *widget,
                      gboolean   arg1,
                      gpointer   user_data)
{
  gtk_main_quit ();

  return FALSE;
}

static gboolean
expose_event_cb (GtkWidget *window,
                 GdkEvent  *event,
                 GtkWidget *widget)
{
  gtk_widget_mnemonic_activate (widget, FALSE);

  return TRUE;
}

static void
test (void)
{
  GtkWidget *window;
  GtkWidget *widget;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position (GTK_WINDOW (window),
                           GTK_WIN_POS_CENTER_ALWAYS);

  widget = gtk_button_new_with_mnemonic  ("_a");
  gtk_container_add (GTK_CONTAINER (window), widget);

  g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (expose_event_cb), widget);
  g_signal_connect (G_OBJECT (widget), "mnemonic-activate", G_CALLBACK (mnemonic_activate_cb), NULL);

  gtk_widget_show_all (window);

  gtk_main ();

  gtk_widget_destroy (window);
}

int
main (int argc, char *argv[])
{
  gtk_test_init (&argc, &argv, NULL);

  g_test_add_func ("/Button/test_run_1", test);
  g_test_add_func ("/Button/test_run_2", test);

  return g_test_run ();
}
