From 13aee80bd5b0fc64be61f16076c892ffb87f7f64 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 3 Jun 2017 18:12:40 +0100 Subject: [PATCH] Disk Config dialog: minor bugs fixes (fixes #334) --- source/Configuration/PageDisk.cpp | 53 ++++++++++++++++++++++++------- source/Configuration/PageDisk.h | 1 + source/Disk.cpp | 4 +-- source/Disk.h | 2 +- source/Harddisk.cpp | 4 +-- source/Harddisk.h | 2 +- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index a31cc6a9..6df8bb96 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -158,7 +158,7 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l } TCHAR PathToCiderPress[MAX_PATH] = ""; - RegLoadString(TEXT("Configuration"), REGVALUE_CIDERPRESSLOC, 1, PathToCiderPress,MAX_PATH); + RegLoadString(TEXT(REG_CONFIG), REGVALUE_CIDERPRESSLOC, 1, PathToCiderPress,MAX_PATH); SendDlgItemMessage(hWnd, IDC_CIDERPRESS_FILENAME ,WM_SETTEXT, 0, (LPARAM)PathToCiderPress); CheckDlgButton(hWnd, IDC_HDD_ENABLE, HD_CardIsEnabled() ? BST_CHECKED : BST_UNCHECKED); @@ -207,6 +207,12 @@ void CPageDisk::EnableHDD(HWND hWnd, BOOL bEnable) EnableWindow(GetDlgItem(hWnd, IDC_COMBO_HDD2), bEnable); } +void CPageDisk::EnableDisk(HWND hWnd, BOOL bEnable) +{ + EnableWindow(GetDlgItem(hWnd, IDC_COMBO_DISK1), bEnable); + EnableWindow(GetDlgItem(hWnd, IDC_COMBO_DISK2), bEnable); +} + void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) { // Search from "select hard drive" @@ -214,16 +220,28 @@ void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0); if (IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE)) { + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item + if (dwComboSelection == dwOpenDialogIndex) { - (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); - HD_Select(driveSelected); + EnableHDD(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered + bool bRes = HD_Select(driveSelected); + EnableHDD(hWnd, TRUE); + + if (!bRes) + { + if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a disk... + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox + return; + } + // Add hard drive name as item 0 and select it if (dwOpenDialogIndex > 0) { - //Remove old item first + // Remove old item first SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } + SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(driveSelected)); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); @@ -241,13 +259,12 @@ void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected { if (dwComboSelection > 1) { - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2; if (RemovalConfirmation(uCommand)) { - // unplug selected disk + // Unplug selected disk HD_Unplug(driveSelected); - //Remove drive from list + // Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } else @@ -264,16 +281,29 @@ void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelecte // Search from "select floppy drive" DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultDiskOptions[0]); DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0); + + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item + if (dwComboSelection == dwOpenDialogIndex) { - (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); - DiskSelect(driveSelected); + EnableDisk(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered + bool bRes = DiskSelect(driveSelected); + EnableDisk(hWnd, TRUE); + + if (!bRes) + { + if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a disk... + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox + return; + } + // Add floppy drive name as item 0 and select it if (dwOpenDialogIndex > 0) { //Remove old item first SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } + SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(driveSelected)); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); @@ -291,13 +321,12 @@ void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelecte { if (dwComboSelection > 1) { - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); UINT uCommand = (driveSelected == 0) ? IDC_COMBO_DISK1 : IDC_COMBO_DISK2; if (RemovalConfirmation(uCommand)) { - // eject selected disk + // Eject selected disk DiskEject(driveSelected); - //Remove drive from list + // Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } else diff --git a/source/Configuration/PageDisk.h b/source/Configuration/PageDisk.h index 4e12b729..0764c434 100644 --- a/source/Configuration/PageDisk.h +++ b/source/Configuration/PageDisk.h @@ -26,6 +26,7 @@ protected: private: void InitOptions(HWND hWnd); void EnableHDD(HWND hWnd, BOOL bEnable); + void EnableDisk(HWND hWnd, BOOL bEnable); void HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); void HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); UINT RemovalConfirmation(UINT uCommand); diff --git a/source/Disk.cpp b/source/Disk.cpp index ba1d5d0a..4a5f2983 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -879,9 +879,9 @@ static bool DiskSelectImage(const int iDrive, LPCSTR pszFilename) //=========================================================================== -void DiskSelect(const int iDrive) +bool DiskSelect(const int iDrive) { - DiskSelectImage(iDrive, TEXT("")); + return DiskSelectImage(iDrive, TEXT("")); } //=========================================================================== diff --git a/source/Disk.h b/source/Disk.h index f759bf2f..2e0d2a3a 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -66,7 +66,7 @@ int DiskGetTrack( int drive ); int DiskGetCurrentPhase(); int DiskGetCurrentOffset(); char* DiskGetCurrentState(); -void DiskSelect(const int iDrive); +bool DiskSelect(const int iDrive); void DiskUpdatePosition(DWORD); bool DiskDriveSwap(void); void DiskLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 844220df..37938a81 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -429,9 +429,9 @@ static bool HD_SelectImage(const int iDrive, LPCSTR pszFilename) return bRes; } -void HD_Select(const int iDrive) +bool HD_Select(const int iDrive) { - HD_SelectImage(iDrive, TEXT("")); + return HD_SelectImage(iDrive, TEXT("")); } void HD_Unplug(const int iDrive) diff --git a/source/Harddisk.h b/source/Harddisk.h index 622b1a8d..ca575e84 100644 --- a/source/Harddisk.h +++ b/source/Harddisk.h @@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA LPCTSTR HD_GetFullName(const int iDrive); LPCTSTR HD_GetFullPathName(const int iDrive); void HD_Load_Rom(const LPBYTE pCxRomPeripheral, const UINT uSlot); - void HD_Select(const int iDrive); + bool HD_Select(const int iDrive); void HD_Unplug(const int iDrive); bool HD_IsDriveUnplugged(const int iDrive); void HD_LoadLastDiskImage(const int iDrive);