From 7dcb8f6f1f696db1ac48f57ad3b09e956c51ab87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Thu, 23 Apr 2020 01:24:01 +0200 Subject: [PATCH] win: Add the "Media" menu to the menubar This is an alternative way to mount images to the virtual drives, as many people found the current behavior confusing. --- src/include/86box/language.h | 3 +- src/include/86box/win.h | 1 + src/win/86Box.rc | 1 + src/win/win_stbar.c | 463 +++++++++++++++++++++-------------- src/win/win_ui.c | 3 + 5 files changed, 281 insertions(+), 190 deletions(-) diff --git a/src/include/86box/language.h b/src/include/86box/language.h index f112ec19f..7aa2e17ee 100644 --- a/src/include/86box/language.h +++ b/src/include/86box/language.h @@ -99,6 +99,7 @@ #define IDS_2123 2123 // "Unable to initialize Ghostscript..." #define IDS_2124 2124 // "MO %i (%03i): %ls" #define IDS_2125 2125 // "MO images (*.IM?)\0*.IM..." +#define IDS_2126 2126 // "Media" #define IDS_4096 4096 // "Hard disk (%s)" #define IDS_4097 4097 // "%01i:%01i" @@ -177,7 +178,7 @@ #define IDS_LANG_ENUS IDS_7168 -#define STR_NUM_2048 78 +#define STR_NUM_2048 79 #define STR_NUM_3072 11 #define STR_NUM_4096 18 #define STR_NUM_4352 7 diff --git a/src/include/86box/win.h b/src/include/86box/win.h index 597ebaa59..5498d3f07 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -168,6 +168,7 @@ extern void win_settings_open_ex(HWND hwnd, int category); /* Functions in win_stbar.c: */ extern HWND hwndSBAR; extern void StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst); +extern int MediaMenuHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); /* Functions in win_dialog.c: */ diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 432a0b8c1..214dd945a 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -915,6 +915,7 @@ BEGIN IDS_2123 "Unable to initialize Ghostscript, gsdll32.dll is required for automatic convertion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript files (.ps)." IDS_2124 "MO %i (%03i): %ls" IDS_2125 "MO images (*.IM?)\0*.IM?\0All files (*.*)\0*.*\0" + IDS_2126 "&Media" END STRINGTABLE DISCARDABLE diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index ecb9c8a62..0dfd7af1d 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -72,6 +72,9 @@ static int sb_parts = 0; static int sb_ready = 0; static uint8_t sb_map[256]; +static HMENU hmenuMedia; +static HMENU *media_menu_handles; + /* Also used by win_settings.c */ intptr_t @@ -483,10 +486,33 @@ ui_sb_update_tip(int meaning) } SendMessage(hwndSBAR, SB_SETTIPTEXT, part, (LPARAM)sbTips[part]); + ModifyMenu(hmenuMedia, part, MF_BYPOSITION, (UINT_PTR)media_menu_handles[part], sbTips[part]); } } +static void +MediaMenuDestroyMenus(void) +{ + int i; + + if (sb_parts == 0) return; + + if (! media_menu_handles) return; + + for (i=0; iexit) + cdrom[id].ops->exit(&(cdrom[id])); + cdrom[id].ops = NULL; + memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); + cdrom_image_open(&(cdrom[id]), temp_path); + /* Signal media change to the emulated machine. */ + if (cdrom[id].insert) + cdrom[id].insert(cdrom[id].priv); + cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200; + if (cdrom[id].host_drive == 200) { + ui_sb_check_menu_item(SB_CDROM | id, IDM_CDROM_EMPTY | id, MF_UNCHECKED); + ui_sb_check_menu_item(SB_CDROM | id, IDM_CDROM_IMAGE | id, MF_CHECKED); + ui_sb_update_icon_state(SB_CDROM | id, 0); + } else { + ui_sb_check_menu_item(SB_CDROM | id, IDM_CDROM_IMAGE | id, MF_UNCHECKED); + ui_sb_check_menu_item(SB_CDROM | id, IDM_CDROM_EMPTY | id, MF_CHECKED); + ui_sb_update_icon_state(SB_CDROM | id, 1); + } + ui_sb_enable_menu_item(SB_CDROM | id, IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + ui_sb_update_tip(SB_CDROM | id); + config_save(); + } + break; + + case IDM_ZIP_IMAGE_NEW: + id = item_params & 0x0003; + part = sb_map[SB_ZIP | id]; + NewFloppyDialogCreate(hwnd, id | 0x80, part); /* NewZIPDialogCreate */ + break; + + case IDM_ZIP_IMAGE_EXISTING: + case IDM_ZIP_IMAGE_EXISTING_WP: + id = item_params & 0x0003; + part = sb_map[SB_ZIP | id]; + if ((part == 0xff) || (sb_menu_handles == NULL)) + break; + + ret = file_dlg_w_st(hwnd, IDS_2058, zip_drives[id].image_path, 0); + if (! ret) + ui_sb_mount_zip_img(id, part, (item_id == IDM_ZIP_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); + break; + + case IDM_ZIP_EJECT: + id = item_params & 0x0003; + zip_eject(id); + break; + + case IDM_ZIP_RELOAD: + id = item_params & 0x0003; + zip_reload(id); + break; + + case IDM_MO_IMAGE_NEW: + id = item_params & 0x0003; + part = sb_map[SB_MO | id]; + NewFloppyDialogCreate(hwnd, id | 0x80, part); /* NewZIPDialogCreate */ + break; + + case IDM_MO_IMAGE_EXISTING: + case IDM_MO_IMAGE_EXISTING_WP: + id = item_params & 0x0003; + part = sb_map[SB_MO | id]; + if ((part == 0xff) || (sb_menu_handles == NULL)) + break; + + ret = file_dlg_w_st(hwnd, IDS_2125, mo_drives[id].image_path, 0); + if (! ret) + ui_sb_mount_mo_img(id, part, (item_id == IDM_MO_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); + break; + + case IDM_MO_EJECT: + id = item_params & 0x0003; + mo_eject(id); + break; + + case IDM_MO_RELOAD: + id = item_params & 0x0003; + mo_reload(id); + break; + + default: + return(0); + } + + return(1); +} + /* Handle messages for the Status Bar window. */ #if defined(__amd64__) || defined(__aarch64__) @@ -921,195 +1177,13 @@ static BOOL CALLBACK #endif StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - WCHAR temp_path[1024]; RECT rc; POINT pt; - int ret = 0; int item_id = 0; - int item_params = 0; - int id = 0; - uint8_t part = 0; switch (message) { case WM_COMMAND: - item_id = LOWORD(wParam) & 0xff00; /* low 8 bits */ - item_params = LOWORD(wParam) & 0x00ff; /* high 8 bits */ - - switch (item_id) { - case IDM_FLOPPY_IMAGE_NEW: - id = item_params & 0x0003; - part = sb_map[SB_FLOPPY | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - NewFloppyDialogCreate(hwnd, id, part); - break; - - case IDM_FLOPPY_IMAGE_EXISTING: - case IDM_FLOPPY_IMAGE_EXISTING_WP: - id = item_params & 0x0003; - part = sb_map[SB_FLOPPY | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - ret = file_dlg_w_st(hwnd, IDS_2118, floppyfns[id], 0); - if (! ret) - ui_sb_mount_floppy_img(id, part, (item_id == IDM_FLOPPY_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); - break; - - case IDM_FLOPPY_EJECT: - id = item_params & 0x0003; - part = sb_map[SB_FLOPPY | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - fdd_close(id); - ui_sb_update_icon_state(SB_FLOPPY | id, 1); - EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EXPORT_TO_86F | id, MF_BYCOMMAND | MF_GRAYED); - ui_sb_update_tip(SB_FLOPPY | id); - config_save(); - break; - - case IDM_FLOPPY_EXPORT_TO_86F: - id = item_params & 0x0003; - part = sb_map[SB_FLOPPY | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - ret = file_dlg_w_st(hwnd, IDS_2076, floppyfns[id], 1); - if (! ret) { - plat_pause(1); - ret = d86f_export(id, wopenfilestring); - if (!ret) - ui_msgbox(MBX_ERROR, (wchar_t *)IDS_4108); - plat_pause(0); - } - break; - - case IDM_CDROM_MUTE: - id = item_params & 0x0007; - part = sb_map[SB_CDROM | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - cdrom[id].sound_on ^= 1; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_MUTE | id, cdrom[id].sound_on ? MF_UNCHECKED : MF_CHECKED); - config_save(); - sound_cd_thread_reset(); - break; - - case IDM_CDROM_EMPTY: - id = item_params & 0x0007; - part = sb_map[SB_CDROM | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - cdrom_eject(id); - break; - - case IDM_CDROM_RELOAD: - id = item_params & 0x0007; - part = sb_map[SB_CDROM | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - cdrom_reload(id); - break; - - case IDM_CDROM_IMAGE: - id = item_params & 0x0007; - part = sb_map[SB_CDROM | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - if (!file_dlg_w_st(hwnd, IDS_2075, cdrom[id].image_path, 0)) { - cdrom[id].prev_host_drive = cdrom[id].host_drive; - wcscpy(temp_path, wopenfilestring); - wcscpy(cdrom[id].prev_image_path, cdrom[id].image_path); - if (cdrom[id].ops && cdrom[id].ops->exit) - cdrom[id].ops->exit(&(cdrom[id])); - cdrom[id].ops = NULL; - memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); - cdrom_image_open(&(cdrom[id]), temp_path); - /* Signal media change to the emulated machine. */ - if (cdrom[id].insert) - cdrom[id].insert(cdrom[id].priv); - cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200; - if (cdrom[id].host_drive == 200) { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); - ui_sb_update_icon_state(SB_CDROM | id, 0); - } else { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED); - ui_sb_update_icon_state(SB_CDROM | id, 1); - } - EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - ui_sb_update_tip(SB_CDROM | id); - config_save(); - } - break; - - case IDM_ZIP_IMAGE_NEW: - id = item_params & 0x0003; - part = sb_map[SB_ZIP | id]; - NewFloppyDialogCreate(hwnd, id | 0x80, part); /* NewZIPDialogCreate */ - break; - - case IDM_ZIP_IMAGE_EXISTING: - case IDM_ZIP_IMAGE_EXISTING_WP: - id = item_params & 0x0003; - part = sb_map[SB_ZIP | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - ret = file_dlg_w_st(hwnd, IDS_2058, zip_drives[id].image_path, 0); - if (! ret) - ui_sb_mount_zip_img(id, part, (item_id == IDM_ZIP_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); - break; - - case IDM_ZIP_EJECT: - id = item_params & 0x0003; - zip_eject(id); - break; - - case IDM_ZIP_RELOAD: - id = item_params & 0x0003; - zip_reload(id); - break; - - case IDM_MO_IMAGE_NEW: - id = item_params & 0x0003; - part = sb_map[SB_MO | id]; - NewFloppyDialogCreate(hwnd, id | 0x80, part); /* NewZIPDialogCreate */ - break; - - case IDM_MO_IMAGE_EXISTING: - case IDM_MO_IMAGE_EXISTING_WP: - id = item_params & 0x0003; - part = sb_map[SB_MO | id]; - if ((part == 0xff) || (sb_menu_handles == NULL)) - break; - - ret = file_dlg_w_st(hwnd, IDS_2125, mo_drives[id].image_path, 0); - if (! ret) - ui_sb_mount_mo_img(id, part, (item_id == IDM_MO_IMAGE_EXISTING_WP) ? 1 : 0, wopenfilestring); - break; - - case IDM_MO_EJECT: - id = item_params & 0x0003; - mo_eject(id); - break; - - case IDM_MO_RELOAD: - id = item_params & 0x0003; - mo_reload(id); - break; - - default: - break; - } + MediaMenuHandler(hwnd, message, wParam, lParam); return(0); case WM_LBUTTONDOWN: @@ -1148,6 +1222,7 @@ StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) RECT rectDialog; int dw, dh; uint8_t i; + HMENU hmenu; /* Load our icons into the cache for faster access. */ for (i = 16; i < 18; i++) @@ -1219,6 +1294,8 @@ StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) memset(sb_menu_handles, 0, sb_parts * sizeof(HMENU)); sbTips = (WCHAR **)malloc(sb_parts * sizeof(WCHAR *)); memset(sbTips, 0, sb_parts * sizeof(WCHAR *)); + media_menu_handles = (HMENU *)malloc(sb_parts * sizeof(HMENU)); + memset(media_menu_handles, 0, sb_parts * sizeof(HMENU)); sb_parts = 0; iStatusWidths[sb_parts] = -1; sb_part_meanings[sb_parts] = SB_TEXT; @@ -1227,6 +1304,12 @@ StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) SendMessage(hwndSBAR, SB_SETPARTS, (WPARAM)sb_parts, (LPARAM)iStatusWidths); SendMessage(hwndSBAR, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)L"Welcome to 86Box !"); + + hmenu = GetMenu(hwndParent); + hmenuMedia = CreatePopupMenu(); + InsertMenu(hmenu, 2, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT_PTR)hmenuMedia, plat_get_string(IDS_2126)); + DrawMenuBar(hwndParent); + sb_ready = 1; } @@ -1245,6 +1328,7 @@ ui_sb_check_menu_item(int tag, int id, int chk) return; CheckMenuItem(sb_menu_handles[part], id, chk); + CheckMenuItem(media_menu_handles[part], id, chk); } @@ -1262,6 +1346,7 @@ ui_sb_enable_menu_item(int tag, int id, int flg) return; EnableMenuItem(sb_menu_handles[part], id, flg); + EnableMenuItem(media_menu_handles[part], id, flg); } diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 2a9099c3f..cc4240949 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -594,6 +594,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) svga_dump_vram(); break; #endif + default: + MediaMenuHandler(hwnd, message, wParam, lParam); + break; } return(0);