From 0e31e91e618218cbef20b55e8fc5a5eb695d5e20 Mon Sep 17 00:00:00 2001 From: tomcw Date: Fri, 10 Oct 2014 21:24:50 +0100 Subject: [PATCH] Disk configuration: Minor coding style tweaks & clean-up --- resource/Applewin.rc | 11 --- resource/resource.h | 5 -- source/Configuration/PageDisk.cpp | 125 ++++++++++++++++++------------ source/Configuration/PageDisk.h | 12 +-- 4 files changed, 78 insertions(+), 75 deletions(-) diff --git a/resource/Applewin.rc b/resource/Applewin.rc index 1da8b7f6..52038c89 100644 --- a/resource/Applewin.rc +++ b/resource/Applewin.rc @@ -351,17 +351,6 @@ BEGIN END END -IDR_MENU_DISK_CFG_POPUP MENU -BEGIN - POPUP "Disk Menu" - BEGIN - MENUITEM "Eject disk in Drive 1", ID_DISKMENU_EJECT_DISK1 - MENUITEM "Eject disk in Drive 2", ID_DISKMENU_EJECT_DISK2 - MENUITEM "Unplug harddisk-1", ID_DISKMENU_UNPLUG_HARDDISK1 - MENUITEM "Unplug harddisk-2", ID_DISKMENU_UNPLUG_HARDDISK2 - END -END - ///////////////////////////////////////////////////////////////////////////// // diff --git a/resource/resource.h b/resource/resource.h index 15573251..97d23fcc 100644 --- a/resource/resource.h +++ b/resource/resource.h @@ -44,7 +44,6 @@ #define IDR_PRAVETS_8M_ROM 140 #define IDR_PRAVETS_8C_ROM 142 #define IDR_MENU_DISK_POPUP 143 -#define IDR_MENU_DISK_CFG_POPUP 144 #define IDD_ABOUT 145 #define IDC_CHECK_CONFIRM_REBOOT 146 #define IDC_KEYB_BUFFER_ENABLE 1005 @@ -116,10 +115,6 @@ #define ID_DISKMENU_WRITEPROTECTION_ON 40005 #define ID_DISKMENU_WRITEPROTECTION_OFF 40006 #define ID_DISKMENU_SENDTO_CIDERPRESS 40007 -#define ID_DISKMENU_EJECT_DISK1 40008 -#define ID_DISKMENU_EJECT_DISK2 40009 -#define ID_DISKMENU_UNPLUG_HARDDISK1 40010 -#define ID_DISKMENU_UNPLUG_HARDDISK2 40011 // Next default values for new objects // diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 896ab973..a31cc6a9 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -86,25 +86,29 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l switch (LOWORD(wparam)) { case IDC_COMBO_DISK1: - if (HIWORD(wparam) == CBN_SELCHANGE) { - handleDiskCombo(hWnd, DRIVE_1, LOWORD(wparam)); + if (HIWORD(wparam) == CBN_SELCHANGE) + { + HandleDiskCombo(hWnd, DRIVE_1, LOWORD(wparam)); FrameRefreshStatus(DRAW_BUTTON_DRIVES); } break; case IDC_COMBO_DISK2: - if (HIWORD(wparam) == CBN_SELCHANGE) { - handleDiskCombo(hWnd, DRIVE_2, LOWORD(wparam)); + if (HIWORD(wparam) == CBN_SELCHANGE) + { + HandleDiskCombo(hWnd, DRIVE_2, LOWORD(wparam)); FrameRefreshStatus(DRAW_BUTTON_DRIVES); } break; case IDC_COMBO_HDD1: - if (HIWORD(wparam) == CBN_SELCHANGE) { - handleHDDCombo(hWnd, HARDDISK_1, LOWORD(wparam)); + if (HIWORD(wparam) == CBN_SELCHANGE) + { + HandleHDDCombo(hWnd, HARDDISK_1, LOWORD(wparam)); } break; case IDC_COMBO_HDD2: - if (HIWORD(wparam) == CBN_SELCHANGE) { - handleHDDCombo(hWnd, HARDDISK_2, LOWORD(wparam)); + if (HIWORD(wparam) == CBN_SELCHANGE) + { + HandleHDDCombo(hWnd, HARDDISK_2, LOWORD(wparam)); } break; case IDC_HDD_ENABLE: @@ -123,31 +127,34 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l case WM_INITDIALOG: { - m_PropertySheetHelper.FillComboBox(hWnd,IDC_DISKTYPE,m_discchoices,enhancedisk); + m_PropertySheetHelper.FillComboBox(hWnd, IDC_DISKTYPE, m_discchoices, enhancedisk); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK1, m_defaultDiskOptions, -1); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK2, m_defaultDiskOptions, -1); - m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_HDD1, m_defaultHDDOptions, hdd1Selection); - m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_HDD2, m_defaultHDDOptions, hdd1Selection); + m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_HDD1, m_defaultHDDOptions, -1); + m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_HDD2, m_defaultHDDOptions, -1); - if (strlen(DiskGetFullName(DRIVE_1)) > 0) { + if (strlen(DiskGetFullName(DRIVE_1)) > 0) + { SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(DRIVE_1)); SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_SETCURSEL, 0, 0); } - if (strlen(DiskGetFullName(DRIVE_2)) > 0) { + + if (strlen(DiskGetFullName(DRIVE_2)) > 0) + { SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(DRIVE_2)); SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_SETCURSEL, 0, 0); } - LPCTSTR hd = HD_GetFullName(HARDDISK_1); - if (strlen(hd)>0) { + if (strlen(HD_GetFullName(HARDDISK_1)) > 0) + { SendDlgItemMessage(hWnd, IDC_COMBO_HDD1, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(HARDDISK_1)); - (DWORD)SendDlgItemMessage(hWnd, IDC_COMBO_HDD1, CB_SETCURSEL, 0, 0); + SendDlgItemMessage(hWnd, IDC_COMBO_HDD1, CB_SETCURSEL, 0, 0); } - hd = HD_GetFullName(HARDDISK_2); - if (strlen(hd)>0) { + if (strlen(HD_GetFullName(HARDDISK_2)) > 0) + { SendDlgItemMessage(hWnd, IDC_COMBO_HDD2, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(HARDDISK_2)); - (DWORD)SendDlgItemMessage(hWnd, IDC_COMBO_HDD2, CB_SETCURSEL, 0, 0); + SendDlgItemMessage(hWnd, IDC_COMBO_HDD2, CB_SETCURSEL, 0, 0); } TCHAR PathToCiderPress[MAX_PATH] = ""; @@ -200,17 +207,20 @@ void CPageDisk::EnableHDD(HWND hWnd, BOOL bEnable) EnableWindow(GetDlgItem(hWnd, IDC_COMBO_HDD2), bEnable); } -void CPageDisk::handleHDDCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSelected) +void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) { // Search from "select hard drive" DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultHDDOptions[0]); DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0); - if (IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE)) { - if (dwComboSelection == dwOpenDialogIndex) { + if (IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE)) + { + if (dwComboSelection == dwOpenDialogIndex) + { (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); HD_Select(driveSelected); // Add hard drive name as item 0 and select it - if (dwOpenDialogIndex > 0) { + if (dwOpenDialogIndex > 0) + { //Remove old item first SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } @@ -221,21 +231,27 @@ void CPageDisk::handleHDDCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSele DWORD comboOther = (comboSelected == IDC_COMBO_HDD1) ? IDC_COMBO_HDD2 : IDC_COMBO_HDD1; DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)HD_GetFullName(driveSelected)); - if (duplicated != CB_ERR) { + if (duplicated != CB_ERR) + { SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0); } } - else if (dwComboSelection == (dwOpenDialogIndex+1)){ - if (dwComboSelection > 1) { + else if (dwComboSelection == (dwOpenDialogIndex+1)) + { + if (dwComboSelection > 1) + { SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); - int iCommand = (driveSelected == 0) ? ID_DISKMENU_UNPLUG_HARDDISK1 : ID_DISKMENU_UNPLUG_HARDDISK2; - if (removalConfirmation(iCommand)) { + UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2; + if (RemovalConfirmation(uCommand)) + { // unplug selected disk HD_Unplug(driveSelected); //Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); - } else { + } + else + { SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); } } @@ -243,42 +259,49 @@ void CPageDisk::handleHDDCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSele } } -void CPageDisk::handleDiskCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSelected) +void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) { - // Search from "select hard drive" + // 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); - if (dwComboSelection == dwOpenDialogIndex) { + if (dwComboSelection == dwOpenDialogIndex) + { (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); DiskSelect(driveSelected); - // Add hard drive name as item 0 and select it - if (dwOpenDialogIndex > 0) { + // 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); - // If the HD was in the other combo, remove now + // If the FD was in the other combo, remove now DWORD comboOther = (comboSelected == IDC_COMBO_DISK1) ? IDC_COMBO_DISK2 : IDC_COMBO_DISK1; DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)DiskGetFullName(driveSelected)); - if (duplicated != CB_ERR) { + if (duplicated != CB_ERR) + { SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0); } } - else if (dwComboSelection == (dwOpenDialogIndex + 1)){ - if (dwComboSelection > 1) { + else if (dwComboSelection == (dwOpenDialogIndex + 1)) + { + if (dwComboSelection > 1) + { SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); - int iCommand = (driveSelected == 0) ? ID_DISKMENU_EJECT_DISK1 : ID_DISKMENU_EJECT_DISK2; - if (removalConfirmation(iCommand)) { - // unplug selected disk + UINT uCommand = (driveSelected == 0) ? IDC_COMBO_DISK1 : IDC_COMBO_DISK2; + if (RemovalConfirmation(uCommand)) + { + // eject selected disk DiskEject(driveSelected); //Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } - else { + else + { SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); } } @@ -286,14 +309,15 @@ void CPageDisk::handleDiskCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSel } -int CPageDisk::removalConfirmation(int iCommand) +UINT CPageDisk::RemovalConfirmation(UINT uCommand) { TCHAR szText[100]; bool bMsgBox = true; - if (iCommand == ID_DISKMENU_EJECT_DISK1 || iCommand == ID_DISKMENU_EJECT_DISK2) - wsprintf(szText, "Do you really want to eject the disk in drive-%c ?", '1' + iCommand - ID_DISKMENU_EJECT_DISK1); - else if (iCommand == ID_DISKMENU_UNPLUG_HARDDISK1 || iCommand == ID_DISKMENU_UNPLUG_HARDDISK2) - wsprintf(szText, "Do you really want to unplug harddisk-%c ?", '1' + iCommand - ID_DISKMENU_UNPLUG_HARDDISK1); + + if (uCommand == IDC_COMBO_DISK1 || uCommand == IDC_COMBO_DISK2) + wsprintf(szText, "Do you really want to eject the disk in drive-%c ?", '1' + uCommand - IDC_COMBO_DISK1); + else if (uCommand == IDC_COMBO_HDD1 || uCommand == IDC_COMBO_HDD2) + wsprintf(szText, "Do you really want to unplug harddisk-%c ?", '1' + uCommand - IDC_COMBO_HDD1); else bMsgBox = false; @@ -301,7 +325,8 @@ int CPageDisk::removalConfirmation(int iCommand) { int nRes = MessageBox(g_hFrameWindow, szText, TEXT("Eject/Unplug Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); if (nRes == IDNO) - iCommand = 0; + uCommand = 0; } - return iCommand; -} \ No newline at end of file + + return uCommand; +} diff --git a/source/Configuration/PageDisk.h b/source/Configuration/PageDisk.h index 7a8fcdb7..4e12b729 100644 --- a/source/Configuration/PageDisk.h +++ b/source/Configuration/PageDisk.h @@ -12,9 +12,6 @@ public: m_PropertySheetHelper(PropertySheetHelper) { CPageDisk::ms_this = this; - - hdd1Selection = -1; - hdd2Selection = -1; } virtual ~CPageDisk(){} @@ -29,18 +26,15 @@ protected: private: void InitOptions(HWND hWnd); void EnableHDD(HWND hWnd, BOOL bEnable); - void handleHDDCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSelected); - void handleDiskCombo(HWND hWnd, UINT16 driveSelected, UINT16 comboSelected); - int removalConfirmation(int iCommand); + void HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); + void HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); + UINT RemovalConfirmation(UINT uCommand); static CPageDisk* ms_this; static const TCHAR m_discchoices[]; static const TCHAR m_defaultDiskOptions[]; static const TCHAR m_defaultHDDOptions[]; - int hdd1Selection; - int hdd2Selection; - const PAGETYPE m_Page; CPropertySheetHelper& m_PropertySheetHelper; };