--- np2/x11/gtk2/gtk_menu.c	2007/01/02 13:11:01	1.5
+++ np2/x11/gtk2/gtk_menu.c	2008/03/13 16:27:39	1.12
@@ -1,4 +1,4 @@
-/*	$Id: gtk_menu.c,v 1.5 2007/01/02 13:11:01 monaka Exp $	*/
+/*	$Id: gtk_menu.c,v 1.12 2008/03/13 16:27:39 monaka Exp $	*/
 
 /*
  * Copyright (c) 2004 NONAKA Kimihiro (aw9k-nnk@asahi-net.or.jp)
@@ -79,6 +79,10 @@ static void cb_reset(GtkAction *action, 
 static void cb_sasiopen(GtkAction *action, gpointer user_data);
 static void cb_sasiremove(GtkAction *action, gpointer user_data);
 #endif
+#if defined(SUPPORT_STATSAVE)
+static void cb_statsave(GtkAction *action, gpointer user_data);
+static void cb_statload(GtkAction *action, gpointer user_data);
+#endif
 
 static void cb_dialog(GtkAction *action, gpointer user_data);
 static void cb_radio(GtkRadioAction *action, GtkRadioAction *current, gpointer user_data);
@@ -91,6 +95,7 @@ static GtkActionEntry menu_entries[] = {
 { "ScreenMenu",   NULL, "Screen",   NULL, NULL, NULL },
 { "DeviceMenu",   NULL, "Device",   NULL, NULL, NULL },
 { "OtherMenu",    NULL, "Other",    NULL, NULL, NULL },
+{ "StatMenu",     NULL, "Stat",     NULL, NULL, NULL },
 
 /* Submenu */
 { "Drive1Menu",   NULL, "Drive_1",   NULL, NULL, NULL },
@@ -108,6 +113,7 @@ static GtkActionEntry menu_entries[] = {
 { "SASI1Menu",    NULL, "SASI-_1",   NULL, NULL, NULL },
 { "SASI2Menu",    NULL, "SASI-_2",   NULL, NULL, NULL },
 #endif
+{ "ScrnSizeMenu", NULL, "Size",      NULL, NULL, NULL },
 { "SoundMenu",    NULL, "_Sound",    NULL, NULL, NULL },
 
 /* MenuItem */
@@ -146,6 +152,28 @@ static GtkActionEntry menu_entries[] = {
 { "serialopt",   NULL, "Se_rial option...", NULL, NULL, G_CALLBACK(cb_dialog) },
 { "soundopt",    NULL, "So_und option...",  NULL, NULL, G_CALLBACK(cb_dialog) },
 { "reset",       NULL, "_Reset",            NULL, NULL, G_CALLBACK(cb_reset) },
+#if defined(SUPPORT_STATSAVE)
+{ "stat00save",  NULL, "Save 0",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat01save",  NULL, "Save 1",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat02save",  NULL, "Save 2",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat03save",  NULL, "Save 3",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat04save",  NULL, "Save 4",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat05save",  NULL, "Save 5",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat06save",  NULL, "Save 6",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat07save",  NULL, "Save 7",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat08save",  NULL, "Save 8",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat09save",  NULL, "Save 9",            NULL, NULL, G_CALLBACK(cb_statsave), },
+{ "stat00load",  NULL, "Load 0",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat01load",  NULL, "Load 1",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat02load",  NULL, "Load 2",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat03load",  NULL, "Load 3",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat04load",  NULL, "Load 4",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat05load",  NULL, "Load 5",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat06load",  NULL, "Load 6",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat07load",  NULL, "Load 7",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat08load",  NULL, "Load 8",            NULL, NULL, G_CALLBACK(cb_statload), },
+{ "stat09load",  NULL, "Load 9",            NULL, NULL, G_CALLBACK(cb_statload), },
+#endif
 };
 static const guint n_menu_entries = G_N_ELEMENTS(menu_entries);
 
@@ -263,6 +291,16 @@ static GtkRadioActionEntry rotate_entrie
 };
 static const guint n_rotate_entries = G_N_ELEMENTS(rotate_entries);
 
+static GtkRadioActionEntry screensize_entries[] = {
+{ "320x200",  NULL, "320x200",  NULL, NULL, 4 },
+{ "480x300",  NULL, "480x300",  NULL, NULL, 6 },
+{ "640x400",  NULL, "640x400",  NULL, NULL, 8 },
+{ "800x500",  NULL, "800x500",  NULL, NULL, 10 },
+{ "960x600",  NULL, "960x600",  NULL, NULL, 12 },
+{ "1280x800", NULL, "1280x800", NULL, NULL, 16 },
+};
+static const guint n_screensize_entries = G_N_ELEMENTS(screensize_entries);
+
 static void cb_beepvol(gint idx);
 static void cb_f12key(gint idx);
 static void cb_framerate(gint idx);
@@ -270,6 +308,7 @@ static void cb_joykey(gint idx);
 static void cb_memory(gint idx);
 static void cb_rotate(gint idx);
 static void cb_screenmode(gint idx);
+static void cb_screensize(gint idx);
 static void cb_soundboard(gint idx);
 
 static const struct {
@@ -284,6 +323,7 @@ static const struct {
 	{ memory_entries, G_N_ELEMENTS(memory_entries), cb_memory },
 	{ rotate_entries, G_N_ELEMENTS(rotate_entries), cb_rotate },
 	{ screenmode_entries, G_N_ELEMENTS(screenmode_entries), cb_screenmode },
+	{ screensize_entries, G_N_ELEMENTS(screensize_entries), cb_screensize },
 	{ soundboard_entries, G_N_ELEMENTS(soundboard_entries), cb_soundboard },
 };
 static const guint n_radiomenu_entries = G_N_ELEMENTS(radiomenu_entries);
@@ -298,7 +338,6 @@ static const gchar *ui_info =
 "   \n"
 "   \n"
 "   \n"
-"   \n"
 "   \n"
 "   \n"
 "  \n"
@@ -340,11 +379,22 @@ static const gchar *ui_info =
 "   \n"
 "   \n"
 "   \n"
-"   \n"
+"   \n"
 "   \n"
 "   \n"
 "   \n"
 "   \n"
+#if defined(SUPPORT_SCREENSIZE)
+"   \n"
+"   
\n"
+#endif
 "   \n"
 "   \n"
 "  \n"
@@ -418,6 +468,31 @@ static const gchar *ui_info =
 "   \n"
 "   \n"
 "  \n"
+#if defined(SUPPORT_STATSAVE)
+"  \n"
+#endif
 " \n"
 "\n";
 
@@ -486,6 +561,8 @@ xmenu_select_item_by_index(MENU_HDL hdl,
 	xmenu_select_item_by_index(NULL, rotate_entries, n_rotate_entries, v);
 #define	xmenu_select_screenmode(v) \
 	xmenu_select_item_by_index(NULL, screenmode_entries, n_screenmode_entries, v);
+#define	xmenu_select_screensize(v) \
+	xmenu_select_item_by_index(NULL, screensize_entries, n_screensize_entries, v);
 #define	xmenu_select_soundboard(v) \
 	xmenu_select_item_by_index(NULL, soundboard_entries, n_soundboard_entries, v);
 
@@ -524,9 +601,13 @@ cb_bmpsave(GtkAction *action, gpointer u
 
 	g_object_set(G_OBJECT(dialog), "show-hidden", TRUE, NULL);
 	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+	if (strlen(bmpfilefolder) == 0) {
+		g_strlcpy(bmpfilefolder, modulefile, sizeof(bmpfilefolder));
+		file_cutname(bmpfilefolder);
+	}
 	utf8 = g_filename_to_utf8(bmpfilefolder, -1, NULL, NULL, NULL);
 	if (utf8) {
-		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), utf8);
+		gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8);
 		g_free(utf8);
 	}
 
@@ -811,6 +892,8 @@ cb_ataopen(GtkAction *action, gpointer u
 	filter = gtk_file_filter_new();
 	if (filter) {
 		gtk_file_filter_set_name(filter, "IDE disk image files");
+		gtk_file_filter_add_pattern(filter, "*.[tT][hH][dD]");
+		gtk_file_filter_add_pattern(filter, "*.[hH][dD][iI]");
 		gtk_file_filter_add_pattern(filter, "*.[nN][hH][dD]");
 		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
 	}
@@ -996,6 +1079,10 @@ cb_newdisk(GtkAction *action, gpointer u
 
 	g_object_set(G_OBJECT(dialog), "show-hidden", TRUE, NULL);
 	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+	if (strlen(fddfolder) == 0) {
+		g_strlcpy(fddfolder, modulefile, sizeof(fddfolder));
+		file_cutname(fddfolder);
+	}
 	utf8 = g_filename_to_utf8(fddfolder, -1, NULL, NULL, NULL);
 	if (utf8) {
 		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), utf8);
@@ -1036,11 +1123,8 @@ cb_newdisk(GtkAction *action, gpointer u
 	}
 	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter[0]);
 
-	if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
-		gtk_widget_destroy(dialog);
-		install_idle_process();
-		return;
-	}
+	if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
+		goto end;
 
 	utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 	if (utf8 == NULL)
@@ -1205,6 +1289,48 @@ cb_sasiremove(GtkAction *action, gpointe
 }
 #endif	/* !SUPPORT_IDEIO */
 
+#if defined(SUPPORT_STATSAVE)
+static void
+cb_statsave(GtkAction *action, gpointer user_data)
+{
+	const gchar *name = gtk_action_get_name(GTK_ACTION(action));
+	char ext[4];
+	guint n;
+
+	UNUSED(user_data);
+
+	/* name = "stat??save" */
+	if ((strlen(name) >= 6)
+	 && (g_ascii_isdigit(name[4]))
+	 && (g_ascii_isdigit(name[5]))) {
+		n = g_ascii_digit_value(name[4]) * 10;
+		n += g_ascii_digit_value(name[5]);
+		g_snprintf(ext, sizeof(ext), np2flagext, n);
+		flagsave(ext);
+	}
+}
+
+static void
+cb_statload(GtkAction *action, gpointer user_data)
+{
+	const gchar *name = gtk_action_get_name(GTK_ACTION(action));
+	char ext[4];
+	guint n;
+
+	UNUSED(user_data);
+
+	/* name = "stat??load" */
+	if ((strlen(name) >= 6)
+	 && (g_ascii_isdigit(name[4]))
+	 && (g_ascii_isdigit(name[5]))) {
+		n = g_ascii_digit_value(name[4]) * 10;
+		n += g_ascii_digit_value(name[5]);
+		g_snprintf(ext, sizeof(ext), np2flagext, n);
+		flagload(ext, "Status Load", TRUE);
+	}
+}
+#endif
+
 static void
 cb_dialog(GtkAction *action, gpointer user_data)
 {
@@ -1649,6 +1775,19 @@ cb_screenmode(gint idx)
 }
 
 static void
+cb_screensize(gint idx)
+{
+	guint value;
+
+	if (idx >= 0) {
+		value = screensize_entries[idx].value;
+	} else {
+		value = 0;
+	}
+	scrnmng_setmultiple(value);
+}
+
+static void
 cb_soundboard(gint idx)
 {
 	guint value;
@@ -1691,6 +1830,73 @@ cb_radio(GtkRadioAction *action, GtkRadi
 /*
  * create menubar
  */
+static GtkWidget *menubar;
+static guint menubar_timerid;
+
+#define	EVENT_MASK	(GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK)
+
+static gboolean
+menubar_timeout(gpointer p)
+{
+
+	UNUSED(p);
+
+	if (menubar_timerid) {
+		g_source_remove(menubar_timerid);
+		menubar_timerid = 0;
+	}
+
+	if (scrnmode & SCRNMODE_FULLSCREEN) {
+		xmenu_hide();
+	}
+
+	return TRUE;
+}
+
+/*
+ - Signal: gboolean GtkWidget::enter_notify_event (GtkWidget *widget,
+          GdkEventCrossing *event, gpointer user_data)
+*/
+static gboolean
+enter_notify_evhandler(GtkWidget *w, GdkEventCrossing *ev, gpointer p)
+{
+
+	UNUSED(w);
+	UNUSED(ev);
+	UNUSED(p);
+
+	if (menubar_timerid) {
+		g_source_remove(menubar_timerid);
+		menubar_timerid = 0;
+	}
+
+	return TRUE;
+}
+
+/*
+ - Signal: gboolean GtkWidget::leave_notify_event (GtkWidget *widget,
+          GdkEventCrossing *event, gpointer user_data)
+*/
+static gboolean
+leave_notify_evhandler(GtkWidget *w, GdkEventCrossing *ev, gpointer p)
+{
+
+	UNUSED(w);
+	UNUSED(ev);
+	UNUSED(p);
+
+	if (menubar_timerid) {
+		g_source_remove(menubar_timerid);
+		menubar_timerid = 0;
+	}
+
+	if (scrnmode & SCRNMODE_FULLSCREEN) {
+		menubar_timerid = g_timeout_add(1000, menubar_timeout, NULL);
+	}
+
+	return TRUE;
+}
+
 static void
 equip_fddrive(GtkUIManager *ui_manager, guint no)
 {
@@ -1724,7 +1930,6 @@ equip_fddrive(GtkUIManager *ui_manager, 
 GtkWidget *
 create_menu(void)
 {
-	GtkWidget *menubar;
 	GError *err = NULL;
 	gint rv;
 	guint i;
@@ -1781,6 +1986,7 @@ create_menu(void)
 	xmenu_select_memory(np2cfg.EXTMEM);
 	xmenu_select_rotate(scrnmode & SCRNMODE_ROTATEMASK);
 	xmenu_select_screenmode(scrnmode & SCRNMODE_FULLSCREEN);
+	xmenu_select_screensize(SCREEN_DEFMUL);
 	xmenu_select_soundboard(np2cfg.SOUND_SW);
 
 	if (np2cfg.fddequip) {
@@ -1792,5 +1998,44 @@ create_menu(void)
 	}
 
 	menubar = gtk_ui_manager_get_widget(menu_hdl.ui_manager, "/MainMenu");
+
+	gtk_widget_add_events(menubar, EVENT_MASK);
+	g_signal_connect(GTK_OBJECT(menubar), "enter_notify_event",
+	            GTK_SIGNAL_FUNC(enter_notify_evhandler), NULL);
+	g_signal_connect(GTK_OBJECT(menubar), "leave_notify_event",
+	            GTK_SIGNAL_FUNC(leave_notify_evhandler), NULL);
+
 	return menubar;
 }
+
+void
+xmenu_hide(void)
+{
+
+	gtk_widget_hide(menubar);
+}
+
+void
+xmenu_show(void)
+{
+
+	gtk_widget_show(menubar);
+}
+
+void
+xmenu_toggle_menu(void)
+{
+
+	if (GTK_WIDGET_VISIBLE(menubar))
+		xmenu_hide();
+	else
+		xmenu_show();
+}
+
+void
+xmenu_select_screen(UINT8 mode)
+{
+
+	xmenu_select_rotate(mode & SCRNMODE_ROTATEMASK);
+	xmenu_select_screenmode(mode & SCRNMODE_FULLSCREEN);
+}