--- np2/x11/gtk2/gtk_menu.c	2004/08/14 03:17:53	1.3
+++ np2/x11/gtk2/gtk_menu.c	2007/02/04 11:51:14	1.10
@@ -1,4 +1,4 @@
-/*	$Id: gtk_menu.c,v 1.3 2004/08/14 03:17:53 monaka Exp $	*/
+/*	$Id: gtk_menu.c,v 1.10 2007/02/04 11:51:14 monaka Exp $	*/
 
 /*
  * Copyright (c) 2004 NONAKA Kimihiro (aw9k-nnk@asahi-net.or.jp)
@@ -12,8 +12,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -46,6 +44,7 @@
 #include "pc9861k.h"
 #include "s98.h"
 #include "scrnbmp.h"
+#include "sxsi.h"
 
 #include "kdispwin.h"
 #include "toolwin.h"
@@ -109,6 +108,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 */
@@ -264,6 +264,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);
@@ -271,6 +281,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 {
@@ -285,6 +296,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);
@@ -299,7 +311,6 @@ static const gchar *ui_info =
 "   \n"
 "   \n"
 "   \n"
-"   \n"
 "   \n"
 "   \n"
 "  \n"
@@ -341,11 +352,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"
@@ -487,6 +509,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);
 
@@ -525,9 +549,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);
 	}
 
@@ -906,6 +934,12 @@ cb_atapiopen(GtkAction *action, gpointer
 		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
 	}
 	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+	filter = gtk_file_filter_new();
+	if (filter) {
+		gtk_file_filter_set_name(filter, "CUE CD-ROM image files");
+		gtk_file_filter_add_pattern(filter, "*.[cC][uU][eE]");
+		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+	}
 
 	if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
 		goto end;
@@ -916,7 +950,7 @@ cb_atapiopen(GtkAction *action, gpointer
 		if (path) {
 			if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IRUSR)) {
 				file_cpyname(hddfolder, path, sizeof(hddfolder));
-				diskdrv_setcdrom(DISKDRV_CDROM_ATAPI, path, FALSE);
+				sxsi_devopen(0x02, path);
 				sysmng_update(SYS_UPDATEOSCFG);
 			}
 			g_free(path);
@@ -937,7 +971,7 @@ cb_atapiremove(GtkAction *action, gpoint
 	UNUSED(action);
 	UNUSED(user_data);
 
-	diskdrv_setcdrom(DISKDRV_CDROM_ATAPI, "", FALSE);
+	sxsi_devclose(0x02);
 }
 #endif	/* SUPPORT_IDEIO */
 
@@ -991,6 +1025,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);
@@ -1031,11 +1069,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)
@@ -1059,7 +1094,7 @@ cb_newdisk(GtkAction *action, gpointer u
 		for (i = 0; i < NELEMENTS(filter); i++) {
 			if (f == filter[i]) {
 				kind = i;
-				tmp = g_strjoin(".", path, extname[i]);
+				tmp = g_strjoin(".", path, extname[i], NULL);
 				if (tmp) {
 					g_free(path);
 					path = tmp;
@@ -1644,6 +1679,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;
@@ -1686,6 +1734,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)
 {
@@ -1719,7 +1834,6 @@ equip_fddrive(GtkUIManager *ui_manager, 
 GtkWidget *
 create_menu(void)
 {
-	GtkWidget *menubar;
 	GError *err = NULL;
 	gint rv;
 	guint i;
@@ -1776,6 +1890,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) {
@@ -1787,5 +1902,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);
+}