--- np2/x11/gtk2/gtk_menu.c 2004/07/15 14:24:33 1.2
+++ np2/x11/gtk2/gtk_menu.c 2007/01/12 19:09:58 1.7
@@ -1,4 +1,4 @@
-/* $Id: gtk_menu.c,v 1.2 2004/07/15 14:24:33 monaka Exp $ */
+/* $Id: gtk_menu.c,v 1.7 2007/01/12 19:09:58 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"
@@ -67,11 +66,19 @@ static void cb_bmpsave(GtkAction *action
static void cb_change_font(GtkAction *action, gpointer user_data);
static void cb_diskeject(GtkAction *action, gpointer user_data);
static void cb_diskopen(GtkAction *action, gpointer user_data);
+#if defined(SUPPORT_IDEIO)
+static void cb_ataopen(GtkAction *action, gpointer user_data);
+static void cb_ataremove(GtkAction *action, gpointer user_data);
+static void cb_atapiopen(GtkAction *action, gpointer user_data);
+static void cb_atapiremove(GtkAction *action, gpointer user_data);
+#endif
static void cb_midipanic(GtkAction *action, gpointer user_data);
static void cb_newdisk(GtkAction *action, gpointer user_data);
static void cb_reset(GtkAction *action, gpointer user_data);
+#if !defined(SUPPORT_IDEIO)
static void cb_sasiopen(GtkAction *action, gpointer user_data);
static void cb_sasiremove(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);
@@ -90,10 +97,17 @@ static GtkActionEntry menu_entries[] = {
{ "Drive2Menu", NULL, "Drive_2", NULL, NULL, NULL },
{ "Drive3Menu", NULL, "Drive_3", NULL, NULL, NULL },
{ "Drive4Menu", NULL, "Drive_4", NULL, NULL, NULL },
+#if defined(SUPPORT_IDEIO)
+{ "ATA00Menu", NULL, "IDE0-_0", NULL, NULL, NULL },
+{ "ATA01Menu", NULL, "IDE0-_1", NULL, NULL, NULL },
+{ "ATAPIMenu", NULL, "_CD-ROM", NULL, NULL, NULL },
+#endif
{ "KeyboardMenu", NULL, "_Keyboard", NULL, NULL, NULL },
{ "MemoryMenu", NULL, "M_emory", NULL, NULL, NULL },
+#if !defined(SUPPORT_IDEIO)
{ "SASI1Menu", NULL, "SASI-_1", NULL, NULL, NULL },
{ "SASI2Menu", NULL, "SASI-_2", NULL, NULL, NULL },
+#endif
{ "SoundMenu", NULL, "_Sound", NULL, NULL, NULL },
/* MenuItem */
@@ -111,13 +125,23 @@ static GtkActionEntry menu_entries[] = {
{ "disk4open", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_diskopen), },
{ "exit", NULL, "E_xit", NULL, NULL, G_CALLBACK(gtk_main_quit) },
{ "font", NULL, "_Font...", NULL, NULL, G_CALLBACK(cb_change_font), },
+#if defined(SUPPORT_IDEIO)
+{ "ata00open", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_ataopen), },
+{ "ata00remove", NULL, "_Remove", NULL, NULL, G_CALLBACK(cb_ataremove), },
+{ "ata01open", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_ataopen), },
+{ "ata01remove", NULL, "_Remove", NULL, NULL, G_CALLBACK(cb_ataremove), },
+{ "atapiopen", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_atapiopen), },
+{ "atapiremove", NULL, "_Remove", NULL, NULL, G_CALLBACK(cb_atapiremove), },
+#endif
{ "midiopt", NULL, "MIDI _option...", NULL, NULL, G_CALLBACK(cb_dialog) },
{ "midipanic", NULL, "MIDI _panic", NULL, NULL, G_CALLBACK(cb_midipanic) },
{ "newdisk", NULL, "_New disk...", NULL, NULL, G_CALLBACK(cb_newdisk), },
+#if !defined(SUPPORT_IDEIO)
{ "sasi1open", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_sasiopen), },
{ "sasi1remove", NULL, "_Remove", NULL, NULL, G_CALLBACK(cb_sasiremove), },
{ "sasi2open", NULL, "_Open...", NULL, NULL, G_CALLBACK(cb_sasiopen), },
{ "sasi2remove", NULL, "_Remove", NULL, NULL, G_CALLBACK(cb_sasiremove), },
+#endif
{ "screenopt", NULL, "Screen _option...", NULL, NULL, G_CALLBACK(cb_dialog) },
{ "serialopt", NULL, "Se_rial option...", NULL, NULL, G_CALLBACK(cb_dialog) },
{ "soundopt", NULL, "So_und option...", NULL, NULL, G_CALLBACK(cb_dialog) },
@@ -281,6 +305,20 @@ static const gchar *ui_info =
"
\n"
" \n"
" \n"
" \n"
@@ -720,6 +759,193 @@ end:
install_idle_process();
}
+#if defined(SUPPORT_IDEIO)
+static void
+cb_ataopen(GtkAction *action, gpointer user_data)
+{
+ GtkWidget *dialog = NULL;
+ GtkFileFilter *filter;
+ gchar *utf8, *path;
+ struct stat sb;
+ const gchar *name = gtk_action_get_name(action);
+ guint channel, drive;
+
+ UNUSED(user_data);
+
+ /* "ata??open" */
+ if ((strlen(name) < 5)
+ || (!g_ascii_isdigit(name[3]))
+ || (!g_ascii_isdigit(name[4]))) {
+ return;
+ }
+
+ channel = g_ascii_digit_value(name[3]);
+ drive = g_ascii_digit_value(name[4]);
+ if (channel != 0 || drive >= 2)
+ return;
+
+ uninstall_idle_process();
+
+ dialog = gtk_file_chooser_dialog_new("Open a IDE disk image",
+ GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+ if (dialog == NULL)
+ goto end;
+
+ g_object_set(G_OBJECT(dialog), "show-hidden", TRUE, NULL);
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+ utf8 = g_filename_to_utf8(hddfolder, -1, NULL, NULL, NULL);
+ if (utf8) {
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8);
+ g_free(utf8);
+ }
+
+ filter = gtk_file_filter_new();
+ if (filter) {
+ gtk_file_filter_set_name(filter, "All files");
+ gtk_file_filter_add_pattern(filter, "*");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+ }
+ filter = gtk_file_filter_new();
+ if (filter) {
+ gtk_file_filter_set_name(filter, "IDE disk image files");
+ gtk_file_filter_add_pattern(filter, "*.[nN][hH][dD]");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+ }
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
+ goto end;
+
+ utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ if (utf8) {
+ path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL);
+ if (path) {
+ if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IRUSR)) {
+ file_cpyname(hddfolder, path, sizeof(hddfolder));
+ diskdrv_sethdd(2 * channel + drive, path);
+ sysmng_update(SYS_UPDATEOSCFG);
+ }
+ g_free(path);
+ }
+ g_free(utf8);
+ }
+
+end:
+ if (dialog)
+ gtk_widget_destroy(dialog);
+ install_idle_process();
+}
+
+static void
+cb_ataremove(GtkAction *action, gpointer user_data)
+{
+ const gchar *name = gtk_action_get_name(GTK_ACTION(action));
+ guint channel, drive;
+
+ UNUSED(user_data);
+
+ /* "ata??open" */
+ if ((strlen(name) < 5)
+ || (!g_ascii_isdigit(name[3]))
+ || (!g_ascii_isdigit(name[4]))) {
+ return;
+ }
+
+ channel = g_ascii_digit_value(name[3]);
+ drive = g_ascii_digit_value(name[4]);
+ if (channel == 0 && drive < 2) {
+ if (2 * channel + drive < 4) {
+ diskdrv_sethdd(2 * channel + drive, "");
+ }
+ }
+}
+
+static void
+cb_atapiopen(GtkAction *action, gpointer user_data)
+{
+ GtkWidget *dialog = NULL;
+ GtkFileFilter *filter;
+ gchar *utf8, *path;
+ struct stat sb;
+
+ UNUSED(action);
+ UNUSED(user_data);
+
+ uninstall_idle_process();
+
+ dialog = gtk_file_chooser_dialog_new("Open a ATAPI CD-ROM image",
+ GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+ if (dialog == NULL)
+ goto end;
+
+ g_object_set(G_OBJECT(dialog), "show-hidden", TRUE, NULL);
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+ utf8 = g_filename_to_utf8(hddfolder, -1, NULL, NULL, NULL);
+ if (utf8) {
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8);
+ g_free(utf8);
+ }
+
+ filter = gtk_file_filter_new();
+ if (filter) {
+ gtk_file_filter_set_name(filter, "All files");
+ gtk_file_filter_add_pattern(filter, "*");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+ }
+ filter = gtk_file_filter_new();
+ if (filter) {
+ gtk_file_filter_set_name(filter, "ISO CD-ROM image files");
+ gtk_file_filter_add_pattern(filter, "*.[iI][sS][oO]");
+ 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;
+
+ utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ if (utf8) {
+ path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL);
+ if (path) {
+ if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IRUSR)) {
+ file_cpyname(hddfolder, path, sizeof(hddfolder));
+ sxsi_devopen(0x02, path);
+ sysmng_update(SYS_UPDATEOSCFG);
+ }
+ g_free(path);
+ }
+ g_free(utf8);
+ }
+
+end:
+ if (dialog)
+ gtk_widget_destroy(dialog);
+ install_idle_process();
+}
+
+static void
+cb_atapiremove(GtkAction *action, gpointer user_data)
+{
+
+ UNUSED(action);
+ UNUSED(user_data);
+
+ sxsi_devclose(0x02);
+}
+#endif /* SUPPORT_IDEIO */
+
static void
cb_midipanic(GtkAction *action, gpointer user_data)
{
@@ -810,58 +1036,66 @@ 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)
- goto end;
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
+ gtk_widget_destroy(dialog);
+ install_idle_process();
+ return;
+ }
utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
- if (utf8) {
- path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL);
- if (path) {
- kind = -1;
- ext = file_getext(path);
- for (i = 0; i < NELEMENTS(exttbl); i++) {
- if (g_ascii_strcasecmp(ext, exttbl[i].name) == 0) {
- kind = exttbl[i].kind;
- break;
- }
- }
- if (i == NELEMENTS(exttbl)) {
- f = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
- for (i = 0; i < NELEMENTS(filter); i++) {
- if (f == filter[i]) {
- kind = i;
- tmp = g_strjoin(".", path, extname[i]);
- if (tmp) {
- g_free(path);
- path = tmp;
- }
- break;
- }
- }
- }
-
- uninstall_idle_process();
- switch (kind) {
- case 0: /* D88 */
- create_newdisk_fd_dialog(path);
- break;
+ if (utf8 == NULL)
+ goto end;
- case 1: /* HDI */
- case 2: /* THD */
- case 3: /* NHD */
- create_newdisk_hd_dialog(path, kind);
- break;
+ path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL);
+ g_free(utf8);
+ if (path == NULL)
+ goto end;
- default:
+ kind = -1;
+ ext = file_getext(path);
+ for (i = 0; i < NELEMENTS(exttbl); i++) {
+ if (g_ascii_strcasecmp(ext, exttbl[i].name) == 0) {
+ kind = exttbl[i].kind;
+ break;
+ }
+ }
+ if (i == NELEMENTS(exttbl)) {
+ f = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
+ for (i = 0; i < NELEMENTS(filter); i++) {
+ if (f == filter[i]) {
+ kind = i;
+ tmp = g_strjoin(".", path, extname[i], NULL);
+ if (tmp) {
+ g_free(path);
+ path = tmp;
+ }
break;
}
- install_idle_process();
-
- g_free(path);
}
- g_free(utf8);
}
+ /* XXX system has only one modal dialog? */
+ gtk_widget_destroy(dialog);
+
+ switch (kind) {
+ case 0: /* D88 */
+ create_newdisk_fd_dialog(path);
+ break;
+
+ case 1: /* HDI */
+ case 2: /* THD */
+ case 3: /* NHD */
+ create_newdisk_hd_dialog(path, kind);
+ break;
+
+ default:
+ break;
+ }
+ g_free(path);
+
+ install_idle_process();
+ return;
+
end:
if (dialog)
gtk_widget_destroy(dialog);
@@ -879,6 +1113,7 @@ cb_reset(GtkAction *action, gpointer use
pccore_reset();
}
+#if !defined(SUPPORT_IDEIO)
static void
cb_sasiopen(GtkAction *action, gpointer user_data)
{
@@ -968,6 +1203,7 @@ cb_sasiremove(GtkAction *action, gpointe
}
}
}
+#endif /* !SUPPORT_IDEIO */
static void
cb_dialog(GtkAction *action, gpointer user_data)
@@ -1455,6 +1691,73 @@ cb_radio(GtkRadioAction *action, GtkRadi
/*
* create menubar
*/
+static GtkWidget *menubar;
+static guint menubar_timerid;
+
+#define EVENT_MASK (GDK_LEAVE_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)
{
@@ -1488,7 +1791,6 @@ equip_fddrive(GtkUIManager *ui_manager,
GtkWidget *
create_menu(void)
{
- GtkWidget *menubar;
GError *err = NULL;
gint rv;
guint i;
@@ -1556,5 +1858,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);
+}