#include <gtk/gtk.h>
#ifdef MAC_INTEGRATION
#include <gtkosxapplication.h>
#include <gdk/gdkquartz.h>
#endif

static void check_for_updates_on_click_cb(GtkWidget *widget, GtkWidget *window) {
	fprintf(stdout, "Check for updates clicked\n");
}

int main (int argc, char **argv) {

	GtkWidget *menubar, *filemenu, *window, *file, *vbox, *updatesW;
#ifdef MAC_INTEGRATION
	GtkosxApplication *theApp;
	theApp = g_object_new(GTKOSX_TYPE_APPLICATION,NULL);
#endif
	
	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window),100,100);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	vbox = gtk_vbox_new(FALSE,0);
        gtk_container_add(GTK_CONTAINER(window), vbox);

        menubar = gtk_menu_bar_new();
        filemenu = gtk_menu_new();

        file = gtk_menu_item_new_with_label("File");

	gtk_menu_item_set_submenu(GTK_MENU_ITEM(file),filemenu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menubar),file);

	gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
        gtk_widget_show_all(menubar);
	updatesW = gtk_menu_item_new_with_label("Check for updates...");
	g_signal_connect(G_OBJECT(updatesW),"activate",G_CALLBACK(check_for_updates_on_click_cb),window);
#ifdef MAC_INTEGRATION
        gtk_widget_hide(menubar);
        gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
	//the following line appears to influence the behavior: if uncommented then the updatesW menu item stays sensitive, even after calling gtk_widget_set_sensitive(FALSE) later on
	//gtk_widget_show(updatesW);
	gtkosx_application_insert_app_menu_item(theApp, updatesW, 0);
	gtkosx_application_insert_app_menu_item(theApp, g_object_ref(gtk_separator_menu_item_new()), 1);
        gtkosx_application_set_window_menu(theApp, NULL);
#else
	gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),updatesW);
	gtk_widget_show(updatesW);
#endif

	gtk_widget_show(vbox);
	gtk_widget_show(window);
#ifdef MAC_INTEGRATION
        gtkosx_application_ready(theApp);
#endif

	//the following line makes the menu item disappear
	gtk_widget_set_sensitive(updatesW, FALSE);

	gtk_main();
	return 0;

}
