--- np2/x11/gtk2/gtk_menu.c 2004/07/15 14:24:33 1.2 +++ np2/x11/gtk2/gtk_menu.c 2011/12/20 03:10:00 1.26 @@ -1,7 +1,5 @@ -/* $Id: gtk_menu.c,v 1.2 2004/07/15 14:24:33 monaka Exp $ */ - /* - * Copyright (c) 2004 NONAKA Kimihiro (aw9k-nnk@asahi-net.or.jp) + * Copyright (c) 2004-2011 NONAKA Kimihiro * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -12,8 +10,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 +42,7 @@ #include "pc9861k.h" #include "s98.h" #include "scrnbmp.h" +#include "sxsi.h" #include "kdispwin.h" #include "toolwin.h" @@ -61,17 +58,32 @@ #include "gtk2/gtk_menu.h" #include "gtk2/gtk_keyboard.h" +#ifndef NSTATSAVE +#define NSTATSAVE 10 +#endif /* normal */ static void cb_bmpsave(GtkAction *action, gpointer user_data); 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 +#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); @@ -84,16 +96,25 @@ 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 }, { "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 +{ "ScrnSizeMenu", NULL, "Size", NULL, NULL, NULL }, { "SoundMenu", NULL, "_Sound", NULL, NULL, NULL }, /* MenuItem */ @@ -111,17 +132,49 @@ 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) }, { "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); @@ -188,6 +241,7 @@ static GtkRadioActionEntry f12key_entrie { "f12mouse", NULL, "F12 = _Mouse", NULL, NULL, 0 }, { "f12copy", NULL, "F12 = Co_py", NULL, NULL, 1 }, { "f12stop", NULL, "F12 = S_top", NULL, NULL, 2 }, +{ "f12help", NULL, "F12 = _Help", NULL, NULL, 7 }, { "f12equal", NULL, "F12 = tenkey [=]", NULL, NULL, 4 }, { "f12comma", NULL, "F12 = tenkey [,]", NULL, NULL, 3 }, }; @@ -239,6 +293,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); @@ -246,6 +310,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 { @@ -260,6 +325,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); @@ -274,13 +340,30 @@ static const gchar *ui_info = " \n" " \n" " \n" -" \n" " \n" " \n" " \n" +#if defined(SUPPORT_STATSAVE) +" \n" +" \n" +#endif " \n" " \n" " \n" +#if defined(SUPPORT_IDEIO) +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +#else /* !SUPPORT_IDEIO */ " \n" " \n" " \n" @@ -289,6 +372,7 @@ static const gchar *ui_info = " \n" " \n" " \n" +#endif /* SUPPORT_IDEIO */ " \n" " \n" " \n" @@ -301,11 +385,22 @@ static const gchar *ui_info = " \n" " \n" " \n" -" \n" +" \n" " \n" " \n" " \n" " \n" +#if defined(SUPPORT_SCREENSIZE) +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +#endif " \n" " \n" " \n" @@ -322,6 +417,7 @@ static const gchar *ui_info = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" @@ -447,6 +543,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); @@ -466,9 +564,6 @@ cb_bmpsave(GtkAction *action, gpointer u SCRNBMP bmp = NULL; FILEH fh; - UNUSED(action); - UNUSED(user_data); - uninstall_idle_process(); bmp = scrnbmp(); @@ -483,11 +578,18 @@ cb_bmpsave(GtkAction *action, gpointer u 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); + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); +#if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 8 + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), + TRUE); +#endif + 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); } @@ -512,6 +614,12 @@ cb_bmpsave(GtkAction *action, gpointer u if (utf8) { path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); if (path) { + gchar *ext = file_getext(path); + if (strlen(ext) != 3 || file_cmpname(ext, "bmp")) { + gchar *tmp = g_strjoin(".", path, "bmp", NULL); + g_free(path); + path = tmp; + } file_cpyname(bmpfilefolder, path, sizeof(bmpfilefolder)); sysmng_update(SYS_UPDATEOSCFG); fh = file_create(path); @@ -540,9 +648,6 @@ cb_change_font(GtkAction *action, gpoint gchar *utf8, *path; struct stat sb; - UNUSED(action); - UNUSED(user_data); - uninstall_idle_process(); dialog = gtk_file_chooser_dialog_new("Open a font file", @@ -553,8 +658,7 @@ cb_change_font(GtkAction *action, gpoint 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); + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); utf8 = g_filename_to_utf8(np2cfg.fontfile, -1, NULL, NULL, NULL); if (utf8) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8); @@ -606,8 +710,6 @@ cb_diskeject(GtkAction *action, gpointer const gchar *name = gtk_action_get_name(action); guint drive; - UNUSED(user_data); - /* name = "disk?eject" */ if ((strlen(name) >= 5) && (g_ascii_isdigit(name[4]))) { drive = g_ascii_digit_value(name[4]) - 1; @@ -628,8 +730,6 @@ cb_diskopen(GtkAction *action, gpointer const gchar *name = gtk_action_get_name(action); guint drive; - UNUSED(user_data); - if ((strlen(name) < 5) || (!g_ascii_isdigit(name[4]))) return; drive = g_ascii_digit_value(name[4]) - 1; @@ -644,8 +744,7 @@ cb_diskopen(GtkAction *action, gpointer 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); + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); utf8 = g_filename_to_utf8(fddfolder, -1, NULL, NULL, NULL); if (utf8) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8); @@ -671,6 +770,7 @@ cb_diskopen(GtkAction *action, gpointer gtk_file_filter_add_pattern(filter, "*.2[hH][dD]"); gtk_file_filter_add_pattern(filter, "*.[fF][dD][iI]"); gtk_file_filter_add_pattern(filter, "*.[fF][sS]"); + gtk_file_filter_add_pattern(filter, "*.[fF][lL][pP]"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } filter = gtk_file_filter_new(); @@ -720,12 +820,186 @@ end: install_idle_process(); } +#if defined(SUPPORT_IDEIO) static void -cb_midipanic(GtkAction *action, gpointer user_data) +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; + + /* "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; + + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); + 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, "*.[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); + } + 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; + + /* "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; + + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); + 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) +{ + + sxsi_devclose(0x02); +} +#endif /* SUPPORT_IDEIO */ + +static void +cb_midipanic(GtkAction *action, gpointer user_data) +{ rs232c_midipanic(); mpu98ii_midipanic(); @@ -755,9 +1029,6 @@ cb_newdisk(GtkAction *action, gpointer u int kind; int i; - UNUSED(action); - UNUSED(user_data); - uninstall_idle_process(); dialog = gtk_file_chooser_dialog_new("Create new disk image file", @@ -768,8 +1039,15 @@ cb_newdisk(GtkAction *action, gpointer u 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); + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); +#if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 8 + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), + TRUE); +#endif + 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); @@ -783,7 +1061,7 @@ cb_newdisk(GtkAction *action, gpointer u filter[0] = gtk_file_filter_new(); if (filter[0]) { - gtk_file_filter_set_name(filter[0], "D88 floppy disk image"); + gtk_file_filter_set_name(filter[0], "D88 floppy disk image (*.d88,*.d98,*.88d,*.98d)"); gtk_file_filter_add_pattern(filter[0], "*.[dD]88"); gtk_file_filter_add_pattern(filter[0], "*.88[dD]"); gtk_file_filter_add_pattern(filter[0], "*.[dD]98"); @@ -792,19 +1070,19 @@ cb_newdisk(GtkAction *action, gpointer u } filter[1] = gtk_file_filter_new(); if (filter[1]) { - gtk_file_filter_set_name(filter[1], "Anex86 hard disk image files"); + gtk_file_filter_set_name(filter[1], "Anex86 hard disk image (*.hdi)"); gtk_file_filter_add_pattern(filter[1], "*.[hH][dD][iI]"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter[1]); } filter[2] = gtk_file_filter_new(); if (filter[2]) { - gtk_file_filter_set_name(filter[2], "T98 hard disk image files"); + gtk_file_filter_set_name(filter[2], "T98 hard disk image (*.thd)"); gtk_file_filter_add_pattern(filter[2], "*.[tT][hH][dD]"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter[2]); } filter[3] = gtk_file_filter_new(); if (filter[3]) { - gtk_file_filter_set_name(filter[3], "T98-Next hard disk image files"); + gtk_file_filter_set_name(filter[3], "T98-Next hard disk image (*.nhd)"); gtk_file_filter_add_pattern(filter[3], "*.[nN][hH][dD]"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter[3]); } @@ -814,54 +1092,59 @@ cb_newdisk(GtkAction *action, gpointer u 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) { - 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); @@ -872,13 +1155,11 @@ static void cb_reset(GtkAction *action, gpointer user_data) { - UNUSED(action); - UNUSED(user_data); - pccore_cfgupdate(); pccore_reset(); } +#if !defined(SUPPORT_IDEIO) static void cb_sasiopen(GtkAction *action, gpointer user_data) { @@ -889,8 +1170,6 @@ cb_sasiopen(GtkAction *action, gpointer const gchar *name = gtk_action_get_name(action); guint drive; - UNUSED(user_data); - if ((strlen(name) < 5) || (!g_ascii_isdigit(name[4]))) return; drive = g_ascii_digit_value(name[4]) - 1; @@ -905,8 +1184,7 @@ cb_sasiopen(GtkAction *action, gpointer 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); + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); utf8 = g_filename_to_utf8(hddfolder, -1, NULL, NULL, NULL); if (utf8) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8); @@ -958,8 +1236,6 @@ cb_sasiremove(GtkAction *action, gpointe const gchar *name = gtk_action_get_name(GTK_ACTION(action)); guint drive; - UNUSED(user_data); - /* name = "sasi?eject" */ if ((strlen(name) >= 5) && (g_ascii_isdigit(name[4]))) { drive = g_ascii_digit_value(name[4]) - 1; @@ -968,14 +1244,51 @@ 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; + + /* 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; + + /* 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) { const gchar *name = gtk_action_get_name(action); - UNUSED(user_data); - if (g_ascii_strcasecmp(name, "configure") == 0) { create_configure_dialog(); } else if (g_ascii_strcasecmp(name, "soundopt") == 0) { @@ -1002,8 +1315,6 @@ cb_clockdisp(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.DISPCLK & 1) ^ (b ? 1 : 0); if (f) { np2oscfg.DISPCLK ^= 1; @@ -1019,8 +1330,6 @@ cb_dispvsync(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.DISPSYNC ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.DISPSYNC = !np2cfg.DISPSYNC; @@ -1034,8 +1343,6 @@ cb_framedisp(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.DISPCLK & 2) ^ (b ? 2 : 0); if (f) { np2oscfg.DISPCLK ^= 2; @@ -1051,8 +1358,6 @@ cb_jastsound(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.jastsnd ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2oscfg.jastsnd = !np2oscfg.jastsnd; @@ -1066,8 +1371,6 @@ cb_joyrapid(GtkToggleAction *action, gpo gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.BTN_RAPID ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.BTN_RAPID = !np2cfg.BTN_RAPID; @@ -1081,8 +1384,6 @@ cb_joyreverse(GtkToggleAction *action, g gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.BTN_MODE ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.BTN_MODE = !np2cfg.BTN_MODE; @@ -1096,8 +1397,6 @@ cb_keydisplay(GtkToggleAction *action, g gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.keydisp ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2oscfg.keydisp = !np2oscfg.keydisp; @@ -1116,8 +1415,6 @@ cb_mousemode(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.MOUSE_SW ? 1 : 0) ^ (b ? 1 : 0); if (f) { mouse_running(MOUSE_XOR); @@ -1132,8 +1429,6 @@ cb_mouserapid(GtkToggleAction *action, g gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.MOUSERAPID ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.MOUSERAPID = !np2cfg.MOUSERAPID; @@ -1147,8 +1442,6 @@ cb_nowait(GtkToggleAction *action, gpoin gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.NOWAIT ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2oscfg.NOWAIT = !np2oscfg.NOWAIT; @@ -1162,8 +1455,6 @@ cb_realpalettes(GtkToggleAction *action, gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.RASTER ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.RASTER = !np2cfg.RASTER; @@ -1179,8 +1470,6 @@ cb_s98logging(GtkToggleAction *action, g gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (s98logging ? 1 : 0) ^ (b ? 1 : 0); if (f) { s98logging = !s98logging; @@ -1202,8 +1491,6 @@ cb_seeksound(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.MOTOR ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2cfg.MOTOR = !np2cfg.MOTOR; @@ -1217,8 +1504,6 @@ cb_softkeyboard(GtkToggleAction *action, gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.softkbd ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2oscfg.softkbd = !np2oscfg.softkbd; @@ -1237,8 +1522,6 @@ cb_toolwindow(GtkToggleAction *action, g gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2oscfg.toolwin ? 1 : 0) ^ (b ? 1 : 0); if (f) { np2oscfg.toolwin = !np2oscfg.toolwin; @@ -1257,8 +1540,6 @@ cb_xctrlkey(GtkToggleAction *action, gpo gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.XSHIFT & 2) ^ (b ? 2 : 0); if (f) { np2cfg.XSHIFT ^= 2; @@ -1273,8 +1554,6 @@ cb_xgrphkey(GtkToggleAction *action, gpo gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.XSHIFT & 4) ^ (b ? 4 : 0); if (f) { np2cfg.XSHIFT ^= 4; @@ -1289,8 +1568,6 @@ cb_xshiftkey(GtkToggleAction *action, gp gboolean b = gtk_toggle_action_get_active(action); gboolean f; - UNUSED(user_data); - f = (np2cfg.XSHIFT & 1) ^ (b ? 1 : 0); if (f) { np2cfg.XSHIFT ^= 1; @@ -1413,6 +1690,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; @@ -1435,8 +1725,6 @@ cb_radio(GtkRadioAction *action, GtkRadi guint menu_idx = (guint)GPOINTER_TO_INT(user_data); gint i; - UNUSED(current); /* emitted item */ - if (menu_idx < n_radiomenu_entries) { for (i = 0; i < radiomenu_entries[menu_idx].count; i++) { if (radiomenu_entries[menu_idx].entry[i].value == value) @@ -1455,10 +1743,107 @@ 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) +{ + + 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) +{ + + 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) +{ + + 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; +} + +#if defined(SUPPORT_STATSAVE) +static void +create_menu_statsave(GtkUIManager *ui_manager, int num) +{ + char *name, *action; + guint id; + int i; + + if (num <= 0) + return; + + /* Save %d */ + for (i = 0; i < num; i++) { + id = gtk_ui_manager_new_merge_id(ui_manager); + name = g_strdup_printf("Save %d", i); + action = g_strdup_printf("stat%02dsave", i); + gtk_ui_manager_add_ui(ui_manager, id, "/MainMenu/Stat", + name, action, GTK_UI_MANAGER_MENUITEM, FALSE); + g_free(action); + g_free(name); + } + + /* separator */ + id = gtk_ui_manager_new_merge_id(ui_manager); + gtk_ui_manager_add_ui(ui_manager, id, "/MainMenu/Stat", + "", "", GTK_UI_MANAGER_SEPARATOR, FALSE); + + /* Load %d */ + for (i = 0; i < num; i++) { + id = gtk_ui_manager_new_merge_id(ui_manager); + name = g_strdup_printf("Load %d", i); + action = g_strdup_printf("stat%02dload", i); + gtk_ui_manager_add_ui(ui_manager, id, "/MainMenu/Stat", + name, action, GTK_UI_MANAGER_MENUITEM, FALSE); + g_free(action); + g_free(name); + } +} +#endif + static void equip_fddrive(GtkUIManager *ui_manager, guint no) { - char path[32], name[32], action[32]; + char *path, *name, *action; guint id; if (no >= 4) @@ -1466,29 +1851,37 @@ equip_fddrive(GtkUIManager *ui_manager, no++; id = gtk_ui_manager_new_merge_id(ui_manager); - g_snprintf(name, sizeof(name), "Drive%d", no); - g_snprintf(action, sizeof(action), "Drive%dMenu", no); + name = g_strdup_printf("Drive%d", no); + action = g_strdup_printf("Drive%dMenu", no); gtk_ui_manager_add_ui(ui_manager, id, "/MainMenu/FDD", name, action, GTK_UI_MANAGER_MENU, FALSE); + g_free(action); + g_free(name); + + path = g_strdup_printf("/MainMenu/FDD/Drive%d", no); - g_snprintf(path, sizeof(path), "/MainMenu/FDD/Drive%d", no); id = gtk_ui_manager_new_merge_id(ui_manager); - g_snprintf(name, sizeof(name), "Drive%dOpen", no); - g_snprintf(action, sizeof(action), "disk%dopen", no); + name = g_strdup_printf("Drive%dOpen", no); + action = g_strdup_printf("disk%dopen", no); gtk_ui_manager_add_ui(ui_manager, id, path, name, action, GTK_UI_MANAGER_MENUITEM, FALSE); + g_free(action); + g_free(name); id = gtk_ui_manager_new_merge_id(ui_manager); - g_snprintf(name, sizeof(name), "Drive%dEject", no); - g_snprintf(action, sizeof(action), "disk%deject", no); + name = g_strdup_printf("Drive%dEject", no); + action = g_strdup_printf("disk%deject", no); gtk_ui_manager_add_ui(ui_manager, id, path, name, action, GTK_UI_MANAGER_MENUITEM, FALSE); + g_free(action); + g_free(name); + + g_free(path); } GtkWidget * create_menu(void) { - GtkWidget *menubar; GError *err = NULL; gint rv; guint i; @@ -1519,6 +1912,19 @@ create_menu(void) return NULL; } +#if defined(SUPPORT_STATSAVE) + if (np2oscfg.statsave) { + create_menu_statsave(menu_hdl.ui_manager, NSTATSAVE); + } +#endif + if (np2cfg.fddequip) { + for (i = 0; i < 4; i++) { + if (np2cfg.fddequip & (1 << i)) { + equip_fddrive(menu_hdl.ui_manager, i); + } + } + } + xmenu_toggle_item(NULL, "dispvsync", np2cfg.DISPSYNC); xmenu_toggle_item(NULL, "joyrapid", np2cfg.BTN_RAPID); xmenu_toggle_item(NULL, "joyreverse", np2cfg.BTN_MODE); @@ -1545,16 +1951,48 @@ 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) { - for (i = 0; i < 4; i++) { - if (np2cfg.fddequip & (1 << i)) { - equip_fddrive(menu_hdl.ui_manager, i); - } - } - } - 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", + G_CALLBACK(enter_notify_evhandler), NULL); + g_signal_connect(GTK_OBJECT(menubar), "leave_notify_event", + G_CALLBACK(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_get_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); +}