#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>

static void
exit_cb (GtkWidget *w, gpointer data)
{
  gtk_main_quit ();
}

static void
fdialog_cb (GtkWidget *w, gpointer data)
{
  GtkWidget *wfilesel = gtk_file_selection_new ("Open");
  gtk_widget_set_name (wfilesel, "file_dialog");
  
  gtk_dialog_run (GTK_DIALOG (wfilesel));
  gtk_widget_destroy (wfilesel);
}


int
main(int argc, char *argv[])
{
  GtkWidget *wtop, *wmenub, *wquit, *wvbox;
  
  gtk_init(&argc, &argv);

  wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  wmenub = gtk_menu_bar_new ();
  wvbox = gtk_vbox_new (FALSE, 0);
  wquit = gtk_button_new_with_label ("Quit");
  g_signal_connect (wquit, "clicked", G_CALLBACK(exit_cb), 0);
  g_signal_connect (wtop, "destroy", G_CALLBACK(exit_cb), 0);
  
  {
    GtkWidget *wfile = gtk_menu_item_new_with_label ("File");
    GtkWidget *wmenu = gtk_menu_new ();
    GtkWidget *wit1 = gtk_menu_item_new_with_label ("Open ...");
    GtkWidget *wit2 = gtk_menu_item_new_with_label ("Exit");

    gtk_menu_shell_append (GTK_MENU_SHELL (wmenub), wfile);
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (wfile), wmenu);
    gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), wit1);
    gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), wit2);

    g_signal_connect (wit1, "activate", G_CALLBACK (fdialog_cb), 0);
    g_signal_connect (wit2, "activate", G_CALLBACK (exit_cb), 0);

    gtk_window_set_title (GTK_WINDOW (wtop), "RCtest");
    gtk_window_set_wmclass (GTK_WINDOW (wtop), "menutest", "MEnutest");
    
    gtk_widget_set_name (wtop, "menutest");
    gtk_widget_set_name (wvbox, "vbox");
    gtk_widget_set_name (wmenub, "menubar");
    gtk_widget_set_name (wmenu, "filemenu");
    gtk_widget_set_name (wfile, "file");
    gtk_widget_set_name (wit1, "menuitem_1");
    gtk_widget_set_name (wit2, "menuitem_2");
  }
  
  gtk_container_add (GTK_CONTAINER (wtop), wvbox);
  gtk_box_pack_start (GTK_BOX (wvbox), wmenub, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (wvbox), wquit, FALSE, FALSE, 0);

  
  gtk_widget_show_all (wtop);
  gtk_main ();
}
