[Project64] Clean up Settings Page - Keyboard Shortcuts.cpp

This commit is contained in:
zilmar 2015-11-13 08:30:40 +11:00
parent a4c438c20d
commit 1b2febc3c2
1 changed files with 270 additions and 270 deletions

View File

@ -15,362 +15,362 @@
COptionsShortCutsPage::COptionsShortCutsPage(HWND hParent, const RECT & rcDispay) : COptionsShortCutsPage::COptionsShortCutsPage(HWND hParent, const RECT & rcDispay) :
m_EnableReset(false) m_EnableReset(false)
{ {
if (!Create(hParent, rcDispay)) if (!Create(hParent, rcDispay))
{ {
return; return;
} }
SetDlgItemTextW(m_hWnd, IDC_S_CPU_STATE, GS(ACCEL_CPUSTATE_TITLE)); SetDlgItemTextW(m_hWnd, IDC_S_CPU_STATE, GS(ACCEL_CPUSTATE_TITLE));
SetDlgItemTextW(m_hWnd, IDC_MENU_ITEM_TEXT, GS(ACCEL_MENUITEM_TITLE)); SetDlgItemTextW(m_hWnd, IDC_MENU_ITEM_TEXT, GS(ACCEL_MENUITEM_TITLE));
SetDlgItemTextW(m_hWnd, IDC_S_CURRENT_KEYS, GS(ACCEL_CURRENTKEYS_TITLE)); SetDlgItemTextW(m_hWnd, IDC_S_CURRENT_KEYS, GS(ACCEL_CURRENTKEYS_TITLE));
SetDlgItemTextW(m_hWnd, IDC_S_SELECT_SHORT, GS(ACCEL_SELKEY_TITLE)); SetDlgItemTextW(m_hWnd, IDC_S_SELECT_SHORT, GS(ACCEL_SELKEY_TITLE));
SetDlgItemTextW(m_hWnd, IDC_S_CURRENT_ASSIGN, GS(ACCEL_ASSIGNEDTO_TITLE)); SetDlgItemTextW(m_hWnd, IDC_S_CURRENT_ASSIGN, GS(ACCEL_ASSIGNEDTO_TITLE));
SetDlgItemTextW(m_hWnd, IDC_ASSIGN, GS(ACCEL_ASSIGN_BTN)); SetDlgItemTextW(m_hWnd, IDC_ASSIGN, GS(ACCEL_ASSIGN_BTN));
SetDlgItemTextW(m_hWnd, IDC_REMOVE, GS(ACCEL_REMOVE_BTN)); SetDlgItemTextW(m_hWnd, IDC_REMOVE, GS(ACCEL_REMOVE_BTN));
SetDlgItemTextW(m_hWnd, IDC_KEY_PROMPT, GS(ACCEL_DETECTKEY)); SetDlgItemTextW(m_hWnd, IDC_KEY_PROMPT, GS(ACCEL_DETECTKEY));
m_CreateNewShortCut.AttachToDlgItem(m_hWnd, IDC_S_SELECT_SHORT); m_CreateNewShortCut.AttachToDlgItem(m_hWnd, IDC_S_SELECT_SHORT);
m_CpuState.Attach(GetDlgItem(IDC_C_CPU_STATE)); m_CpuState.Attach(GetDlgItem(IDC_C_CPU_STATE));
m_MenuItems.Attach(GetDlgItem(IDC_MENU_ITEMS)); m_MenuItems.Attach(GetDlgItem(IDC_MENU_ITEMS));
m_CurrentKeys.Attach(GetDlgItem(IDC_CURRENT_KEYS)); m_CurrentKeys.Attach(GetDlgItem(IDC_CURRENT_KEYS));
m_VirtualKeyList.Attach(GetDlgItem(IDC_VIRTUALKEY)); m_VirtualKeyList.Attach(GetDlgItem(IDC_VIRTUALKEY));
m_MenuItems.ModifyStyle(0, TVS_SHOWSELALWAYS); m_MenuItems.ModifyStyle(0, TVS_SHOWSELALWAYS);
m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_1)), CMenuShortCutKey::GAME_NOT_RUNNING); m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_1)), CMenuShortCutKey::GAME_NOT_RUNNING);
m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_3)), CMenuShortCutKey::GAME_RUNNING_WINDOW); m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_3)), CMenuShortCutKey::GAME_RUNNING_WINDOW);
m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_4)), CMenuShortCutKey::GAME_RUNNING_FULLSCREEN); m_CpuState.SetItemData(m_CpuState.AddStringW(GS(ACCEL_CPUSTATE_4)), CMenuShortCutKey::GAME_RUNNING_FULLSCREEN);
m_CpuState.SetCurSel(0); m_CpuState.SetCurSel(0);
int VirtualKeyListSize; int VirtualKeyListSize;
VIRTUAL_KEY * VirtualKeyList = CMenuShortCutKey::VirtualKeyList(VirtualKeyListSize); VIRTUAL_KEY * VirtualKeyList = CMenuShortCutKey::VirtualKeyList(VirtualKeyListSize);
for (int count = 0; count < VirtualKeyListSize; count++) for (int count = 0; count < VirtualKeyListSize; count++)
{ {
m_VirtualKeyList.SetItemData(m_VirtualKeyList.AddString(VirtualKeyList[count].Name), VirtualKeyList[count].Key); m_VirtualKeyList.SetItemData(m_VirtualKeyList.AddString(VirtualKeyList[count].Name), VirtualKeyList[count].Key);
} }
OnCpuStateChanged(LBN_SELCHANGE, IDC_C_CPU_STATE, GetDlgItem(IDC_C_CPU_STATE)); OnCpuStateChanged(LBN_SELCHANGE, IDC_C_CPU_STATE, GetDlgItem(IDC_C_CPU_STATE));
CheckResetEnable(); CheckResetEnable();
} }
void COptionsShortCutsPage::CheckResetEnable(void) void COptionsShortCutsPage::CheckResetEnable(void)
{ {
MSC_MAP & ShortCuts = m_ShortCuts.GetShortCuts(); MSC_MAP & ShortCuts = m_ShortCuts.GetShortCuts();
for (MSC_MAP::iterator Item = ShortCuts.begin(); Item != ShortCuts.end(); Item++) for (MSC_MAP::iterator Item = ShortCuts.begin(); Item != ShortCuts.end(); Item++)
{ {
const SHORTCUT_KEY_LIST & ShortCutList = Item->second.GetAccelItems(); const SHORTCUT_KEY_LIST & ShortCutList = Item->second.GetAccelItems();
for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++) for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++)
{ {
if (!ShortCut_item->Inactive() && !ShortCut_item->UserAdded()) if (!ShortCut_item->Inactive() && !ShortCut_item->UserAdded())
{ {
continue; continue;
} }
m_EnableReset = true; m_EnableReset = true;
return; return;
} }
} }
m_EnableReset = false; m_EnableReset = false;
} }
void COptionsShortCutsPage::OnCpuStateChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsShortCutsPage::OnCpuStateChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel()); ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel());
MSC_MAP & ShortCuts = m_ShortCuts.GetShortCuts(); MSC_MAP & ShortCuts = m_ShortCuts.GetShortCuts();
m_MenuItems.DeleteAllItems(); m_MenuItems.DeleteAllItems();
for (MSC_MAP::iterator Item = ShortCuts.begin(); Item != ShortCuts.end(); Item++) for (MSC_MAP::iterator Item = ShortCuts.begin(); Item != ShortCuts.end(); Item++)
{ {
ACCESS_MODE ItemMode = Item->second.AccessMode(); ACCESS_MODE ItemMode = Item->second.AccessMode();
if ((ItemMode & AccessLevel) != AccessLevel) if ((ItemMode & AccessLevel) != AccessLevel)
{ {
continue; continue;
} }
//find Parent //find Parent
HTREEITEM hParent = m_MenuItems.GetChildItem(TVI_ROOT); HTREEITEM hParent = m_MenuItems.GetChildItem(TVI_ROOT);
while (hParent) while (hParent)
{ {
if (m_MenuItems.GetItemData(hParent) == (DWORD_PTR)Item->second.Section()) if (m_MenuItems.GetItemData(hParent) == (DWORD_PTR)Item->second.Section())
{ {
break; break;
} }
hParent = m_MenuItems.GetNextSiblingItem(hParent); hParent = m_MenuItems.GetNextSiblingItem(hParent);
} }
if (hParent == NULL) if (hParent == NULL)
{ {
hParent = m_MenuItems.InsertItemW(TVIF_TEXT | TVIF_PARAM, GS(Item->second.Section()), 0, 0, 0, 0, Item->second.Section(), TVI_ROOT, TVI_LAST); hParent = m_MenuItems.InsertItemW(TVIF_TEXT | TVIF_PARAM, GS(Item->second.Section()), 0, 0, 0, 0, Item->second.Section(), TVI_ROOT, TVI_LAST);
} }
wstring str = GS(Item->second.Title()); wstring str = GS(Item->second.Title());
std::wstring::size_type pos = str.find(L"&"); std::wstring::size_type pos = str.find(L"&");
while (pos != std::wstring::npos) while (pos != std::wstring::npos)
{ {
str.replace(pos, 1, L""); str.replace(pos, 1, L"");
pos = str.find(L"&", pos); pos = str.find(L"&", pos);
} }
pos = str.find(L"..."); pos = str.find(L"...");
while (pos != std::wstring::npos) while (pos != std::wstring::npos)
{ {
str.replace(pos, 3, L""); str.replace(pos, 3, L"");
pos = str.find(L"...", pos); pos = str.find(L"...", pos);
} }
HTREEITEM hItem = m_MenuItems.InsertItemW(TVIF_TEXT | TVIF_PARAM, str.c_str(), 0, 0, 0, 0, (DWORD_PTR)&Item->second, hParent, TVI_LAST); HTREEITEM hItem = m_MenuItems.InsertItemW(TVIF_TEXT | TVIF_PARAM, str.c_str(), 0, 0, 0, 0, (DWORD_PTR)&Item->second, hParent, TVI_LAST);
const SHORTCUT_KEY_LIST & ShortCutList = Item->second.GetAccelItems(); const SHORTCUT_KEY_LIST & ShortCutList = Item->second.GetAccelItems();
for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++) for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++)
{ {
if (!ShortCut_item->Inactive() && !ShortCut_item->UserAdded()) if (!ShortCut_item->Inactive() && !ShortCut_item->UserAdded())
{ {
continue; continue;
} }
m_MenuItems.SetItemState(hItem, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hItem, TVIS_BOLD, TVIS_BOLD);
m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD);
break; break;
} }
} }
} }
void COptionsShortCutsPage::OnRemoveClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsShortCutsPage::OnRemoveClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
HTREEITEM hSelectedItem = m_MenuItems.GetSelectedItem(); HTREEITEM hSelectedItem = m_MenuItems.GetSelectedItem();
if (hSelectedItem == NULL) if (hSelectedItem == NULL)
{ {
g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT)); g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT));
return; return;
} }
HTREEITEM hParent = m_MenuItems.GetParentItem(hSelectedItem); HTREEITEM hParent = m_MenuItems.GetParentItem(hSelectedItem);
if (hParent == NULL) if (hParent == NULL)
{ {
g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT)); g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT));
return; return;
} }
CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hSelectedItem); CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hSelectedItem);
//Make sure an item is selected //Make sure an item is selected
int index = m_CurrentKeys.GetCurSel(); int index = m_CurrentKeys.GetCurSel();
if (index < 0) if (index < 0)
{ {
g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT)); g_Notify->DisplayError(GS(MSG_NO_SEL_SHORTCUT));
return; return;
} }
ShortCut->RemoveItem((CMenuShortCutKey *)m_CurrentKeys.GetItemData(index)); ShortCut->RemoveItem((CMenuShortCutKey *)m_CurrentKeys.GetItemData(index));
m_MenuItems.SetItemState(hSelectedItem, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hSelectedItem, TVIS_BOLD, TVIS_BOLD);
m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD);
m_EnableReset = true; m_EnableReset = true;
RefreshShortCutOptions(hSelectedItem); RefreshShortCutOptions(hSelectedItem);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsShortCutsPage::OnDetectKeyClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsShortCutsPage::OnDetectKeyClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)stInputGetKeys, this, 0, NULL)); CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)stInputGetKeys, this, 0, NULL));
} }
void COptionsShortCutsPage::OnAssignClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsShortCutsPage::OnAssignClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
//Get the virtual key info //Get the virtual key info
int index = m_VirtualKeyList.GetCurSel(); int index = m_VirtualKeyList.GetCurSel();
if (index < 0) if (index < 0)
{ {
g_Notify->DisplayError(GS(MSG_NO_SHORTCUT_SEL)); g_Notify->DisplayError(GS(MSG_NO_SHORTCUT_SEL));
return; return;
} }
WORD key = (WORD)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, index, 0); WORD key = (WORD)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, index, 0);
bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED);
bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED);
bool bShift = (SendDlgItemMessage(IDC_SHIFT, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bShift = (SendDlgItemMessage(IDC_SHIFT, BM_GETCHECK, 0, 0) == BST_CHECKED);
ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel()); ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel());
HTREEITEM hSelectedItem = m_MenuItems.GetSelectedItem(); HTREEITEM hSelectedItem = m_MenuItems.GetSelectedItem();
if (hSelectedItem == NULL) if (hSelectedItem == NULL)
{ {
g_Notify->DisplayError(GS(MSG_NO_MENUITEM_SEL)); g_Notify->DisplayError(GS(MSG_NO_MENUITEM_SEL));
return; return;
} }
HTREEITEM hParent = m_MenuItems.GetParentItem(hSelectedItem); HTREEITEM hParent = m_MenuItems.GetParentItem(hSelectedItem);
if (hParent == NULL) if (hParent == NULL)
{ {
g_Notify->DisplayError(GS(MSG_NO_MENUITEM_SEL)); g_Notify->DisplayError(GS(MSG_NO_MENUITEM_SEL));
return; return;
} }
CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hSelectedItem); CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hSelectedItem);
LanguageStringID strid = m_ShortCuts.GetMenuItemName(key, bCtrl, bAlt, bShift, AccessLevel); LanguageStringID strid = m_ShortCuts.GetMenuItemName(key, bCtrl, bAlt, bShift, AccessLevel);
if (strid != EMPTY_STRING) if (strid != EMPTY_STRING)
{ {
g_Notify->DisplayError(GS(MSG_MENUITEM_ASSIGNED)); g_Notify->DisplayError(GS(MSG_MENUITEM_ASSIGNED));
return; return;
} }
ShortCut->AddShortCut(key, bCtrl, bAlt, bShift, AccessLevel, true, false); ShortCut->AddShortCut(key, bCtrl, bAlt, bShift, AccessLevel, true, false);
m_MenuItems.SetItemState(hSelectedItem, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hSelectedItem, TVIS_BOLD, TVIS_BOLD);
m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD); m_MenuItems.SetItemState(hParent, TVIS_BOLD, TVIS_BOLD);
m_EnableReset = true; m_EnableReset = true;
RefreshShortCutOptions(hSelectedItem); RefreshShortCutOptions(hSelectedItem);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsShortCutsPage::OnShortCutChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsShortCutsPage::OnShortCutChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
//Get the virtual key info //Get the virtual key info
int index = m_VirtualKeyList.GetCurSel(); int index = m_VirtualKeyList.GetCurSel();
if (index < 0) { return; } if (index < 0) { return; }
WORD key = (WORD)m_VirtualKeyList.GetItemData(index); WORD key = (WORD)m_VirtualKeyList.GetItemData(index);
bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED);
bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED);
bool bShift = (SendDlgItemMessage(IDC_SHIFT, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bShift = (SendDlgItemMessage(IDC_SHIFT, BM_GETCHECK, 0, 0) == BST_CHECKED);
ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel()); ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel());
stdstr str; stdstr str;
str.FromUTF16(GS(m_ShortCuts.GetMenuItemName(key, bCtrl, bAlt, bShift, AccessLevel))); str.FromUTF16(GS(m_ShortCuts.GetMenuItemName(key, bCtrl, bAlt, bShift, AccessLevel)));
if (str.length() > 0) if (str.length() > 0)
{ {
str.resize(std::remove(str.begin(), str.end(), '&') - str.begin()); str.resize(std::remove(str.begin(), str.end(), '&') - str.begin());
} }
else else
{ {
str = "None"; str = "None";
} }
SetDlgItemText(IDC_ASSIGNED_MENU_ITEM, str.c_str()); SetDlgItemText(IDC_ASSIGNED_MENU_ITEM, str.c_str());
} }
LRESULT COptionsShortCutsPage::OnMenuItemChanged(LPNMHDR lpnmh) LRESULT COptionsShortCutsPage::OnMenuItemChanged(LPNMHDR lpnmh)
{ {
RefreshShortCutOptions(((LPNMTREEVIEW)lpnmh)->itemNew.hItem); RefreshShortCutOptions(((LPNMTREEVIEW)lpnmh)->itemNew.hItem);
return true; return true;
} }
void COptionsShortCutsPage::RefreshShortCutOptions(HTREEITEM hItem) void COptionsShortCutsPage::RefreshShortCutOptions(HTREEITEM hItem)
{ {
HTREEITEM hParent = m_MenuItems.GetParentItem(hItem); HTREEITEM hParent = m_MenuItems.GetParentItem(hItem);
if (hParent == NULL) if (hParent == NULL)
{ {
return; return;
} }
ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel()); ACCESS_MODE AccessLevel = (ACCESS_MODE)m_CpuState.GetItemData(m_CpuState.GetCurSel());
CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hItem); CShortCutItem * ShortCut = (CShortCutItem *)m_MenuItems.GetItemData(hItem);
m_CurrentKeys.ResetContent(); m_CurrentKeys.ResetContent();
const SHORTCUT_KEY_LIST & ShortCutList = ShortCut->GetAccelItems(); const SHORTCUT_KEY_LIST & ShortCutList = ShortCut->GetAccelItems();
for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++) for (SHORTCUT_KEY_LIST::const_iterator ShortCut_item = ShortCutList.begin(); ShortCut_item != ShortCutList.end(); ShortCut_item++)
{ {
if (ShortCut_item->Inactive()) if (ShortCut_item->Inactive())
{ {
continue; continue;
} }
ACCESS_MODE ItemMode = ShortCut_item->AccessMode(); ACCESS_MODE ItemMode = ShortCut_item->AccessMode();
if ((ItemMode & AccessLevel) != AccessLevel) if ((ItemMode & AccessLevel) != AccessLevel)
{ {
continue; continue;
} }
stdstr Name = ShortCut_item->Name(); stdstr Name = ShortCut_item->Name();
m_CurrentKeys.SetItemData(m_CurrentKeys.AddString(Name.c_str()), (DWORD_PTR)&*ShortCut_item); m_CurrentKeys.SetItemData(m_CurrentKeys.AddString(Name.c_str()), (DWORD_PTR)&*ShortCut_item);
} }
} }
BOOL CALLBACK KeyPromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM /*lParam*/) BOOL CALLBACK KeyPromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM /*lParam*/)
{ {
switch (uMsg) switch (uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
break; break;
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case IDCANCEL: case IDCANCEL:
SetForegroundWindow(GetParent(hDlg)); SetForegroundWindow(GetParent(hDlg));
DestroyWindow(hDlg); DestroyWindow(hDlg);
break; break;
} }
break; break;
default: default:
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
void COptionsShortCutsPage::InputGetKeys(void) void COptionsShortCutsPage::InputGetKeys(void)
{ {
HWND hKeyDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Key_Prompt), m_hWnd, (DLGPROC)KeyPromptDlgProc, (LPARAM)::GetDlgItem(m_hWnd, IDC_VIRTUALKEY)); HWND hKeyDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Key_Prompt), m_hWnd, (DLGPROC)KeyPromptDlgProc, (LPARAM)::GetDlgItem(m_hWnd, IDC_VIRTUALKEY));
::EnableWindow(GetParent(), false); ::EnableWindow(GetParent(), false);
MSG msg; MSG msg;
for (bool fDone = false; !fDone; MsgWaitForMultipleObjects(0, NULL, false, 45, QS_ALLINPUT)) { for (bool fDone = false; !fDone; MsgWaitForMultipleObjects(0, NULL, false, 45, QS_ALLINPUT)) {
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) { if (msg.message == WM_QUIT) {
fDone = true; fDone = true;
::PostMessage(NULL, WM_QUIT, 0, 0); ::PostMessage(NULL, WM_QUIT, 0, 0);
break; break;
} }
if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) { if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) {
int nVirtKey = (int)msg.wParam; int nVirtKey = (int)msg.wParam;
if (nVirtKey == VK_SHIFT) { continue; } if (nVirtKey == VK_SHIFT) { continue; }
if (nVirtKey == VK_CONTROL) { continue; } if (nVirtKey == VK_CONTROL) { continue; }
if (nVirtKey == VK_MENU) { continue; } if (nVirtKey == VK_MENU) { continue; }
SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, (WPARAM)-1, 0); SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, (WPARAM)-1, 0);
for (int count = 0; count < SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETCOUNT, 0, 0); count++) { for (int count = 0; count < SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETCOUNT, 0, 0); count++) {
int Data = (int)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, count, 0); int Data = (int)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, count, 0);
if (Data != nVirtKey) { continue; } if (Data != nVirtKey) { continue; }
SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, count, 0); SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, count, 0);
SendDlgItemMessage(IDC_CTL, BM_SETCHECK, (GetKeyState(VK_CONTROL) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(IDC_CTL, BM_SETCHECK, (GetKeyState(VK_CONTROL) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(IDC_ALT, BM_SETCHECK, (GetKeyState(VK_MENU) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(IDC_ALT, BM_SETCHECK, (GetKeyState(VK_MENU) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(IDC_SHIFT, BM_SETCHECK, (GetKeyState(VK_SHIFT) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(IDC_SHIFT, BM_SETCHECK, (GetKeyState(VK_SHIFT) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(WM_COMMAND, MAKELPARAM(IDC_VIRTUALKEY, LBN_SELCHANGE), (LPARAM)::GetDlgItem(m_hWnd, IDC_VIRTUALKEY)); SendMessage(WM_COMMAND, MAKELPARAM(IDC_VIRTUALKEY, LBN_SELCHANGE), (LPARAM)::GetDlgItem(m_hWnd, IDC_VIRTUALKEY));
SetForegroundWindow(GetParent()); SetForegroundWindow(GetParent());
::DestroyWindow(hKeyDlg); ::DestroyWindow(hKeyDlg);
} }
continue; continue;
} }
if (!::IsDialogMessage(hKeyDlg, &msg)) { if (!::IsDialogMessage(hKeyDlg, &msg)) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
if (!::IsWindow(hKeyDlg)) { fDone = true; } if (!::IsWindow(hKeyDlg)) { fDone = true; }
} }
::SetFocus(GetParent()); ::SetFocus(GetParent());
::EnableWindow(GetParent(), true); ::EnableWindow(GetParent(), true);
} }
void COptionsShortCutsPage::HidePage() void COptionsShortCutsPage::HidePage()
{ {
ShowWindow(SW_HIDE); ShowWindow(SW_HIDE);
} }
void COptionsShortCutsPage::ShowPage() void COptionsShortCutsPage::ShowPage()
{ {
ShowWindow(SW_SHOW); ShowWindow(SW_SHOW);
} }
void COptionsShortCutsPage::ApplySettings(bool /*UpdateScreen*/) void COptionsShortCutsPage::ApplySettings(bool /*UpdateScreen*/)
{ {
m_ShortCuts.Save(); m_ShortCuts.Save();
g_Settings->SaveBool(Info_ShortCutsChanged, true); g_Settings->SaveBool(Info_ShortCutsChanged, true);
} }
bool COptionsShortCutsPage::EnableReset(void) bool COptionsShortCutsPage::EnableReset(void)
{ {
return m_EnableReset; return m_EnableReset;
} }
void COptionsShortCutsPage::ResetPage() void COptionsShortCutsPage::ResetPage()
{ {
m_EnableReset = false; m_EnableReset = false;
m_ShortCuts.Load(true); m_ShortCuts.Load(true);
OnCpuStateChanged(LBN_SELCHANGE, IDC_C_CPU_STATE, GetDlgItem(IDC_C_CPU_STATE)); OnCpuStateChanged(LBN_SELCHANGE, IDC_C_CPU_STATE, GetDlgItem(IDC_C_CPU_STATE));
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
m_CurrentKeys.ResetContent(); m_CurrentKeys.ResetContent();
CSettingsPageImpl<COptionsShortCutsPage>::ResetPage(); CSettingsPageImpl<COptionsShortCutsPage>::ResetPage();
} }