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

void chooser_activated_cb(GtkRecentChooser *chooser, gpointer *data) {
        gchar *fileuri = gtk_recent_chooser_get_current_uri(chooser);

	fprintf(stdout,"fileuri: %s\n", fileuri);
	g_free(fileuri);
}



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

	GtkWidget *menubar, *filemenu, *window, *file, *openrecent_menuW, *vbox;
#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");

	GtkWidget *openrecentW = gtk_recent_chooser_menu_new();
        GtkRecentFilter *filter = gtk_recent_filter_new();
        gtk_recent_filter_add_pattern(filter, "*");
        gtk_recent_chooser_add_filter(GTK_RECENT_CHOOSER(openrecentW), filter);
        gtk_recent_chooser_set_show_tips(GTK_RECENT_CHOOSER(openrecentW), FALSE);
        gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER(openrecentW), FALSE);
        gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(openrecentW), GTK_RECENT_SORT_MRU);
        g_signal_connect(G_OBJECT(openrecentW), "item-activated", G_CALLBACK(chooser_activated_cb), (gpointer) window);

        openrecent_menuW = gtk_menu_item_new_with_label("Open Recent");
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(openrecent_menuW), openrecentW);


	gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),openrecent_menuW);
	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);
#ifdef MAC_INTEGRATION
        gtk_widget_hide(menubar);
        gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
        gtkosx_application_set_window_menu(theApp, NULL);
#endif

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


	gtk_main();
	return 0;

}
