--- truecrypt/mount/hotkeys.c 2018/04/24 16:43:32 1.1.1.1 +++ truecrypt/mount/hotkeys.c 2018/04/24 17:03:35 1.1.1.11 @@ -1,8 +1,9 @@ -/* -Copyright (c) 2004-2005 TrueCrypt Foundation. All rights reserved. +/* + Copyright (c) 2005 TrueCrypt Foundation. All rights reserved. -Covered by TrueCrypt License 2.0 the full text of which is contained in the file -License.txt included in TrueCrypt binary and source code distribution archives. + Governed by the TrueCrypt License 2.7 the full text of which is contained + in the file License.txt included in TrueCrypt binary and source code + distribution packages. */ #include @@ -145,15 +146,19 @@ void UnregisterAllHotkeys (HWND hwndDlg, } -void RegisterAllHotkeys (HWND hwndDlg, TCHOTKEY hotkeys[]) +BOOL RegisterAllHotkeys (HWND hwndDlg, TCHOTKEY hotkeys[]) { + BOOL result = TRUE; int i; for (i = 0; i < NBR_HOTKEYS; i++) { - if (hotkeys[i].vKeyCode != 0) - RegisterHotKey (hwndDlg, i, hotkeys[i].vKeyModifiers, hotkeys[i].vKeyCode); + if (hotkeys[i].vKeyCode != 0 + && !RegisterHotKey (hwndDlg, i, hotkeys[i].vKeyModifiers, hotkeys[i].vKeyCode)) + result = FALSE; } + + return result; } @@ -186,6 +191,14 @@ static void DisplayHotkeyList (HWND hwnd item.pszText = GetString ("HK_DISMOUNT_ALL"); break; + case HK_WIPE_CACHE: + item.pszText = GetString ("HK_WIPE_CACHE"); + break; + + case HK_DISMOUNT_ALL_AND_WIPE: + item.pszText = GetString ("HK_DISMOUNT_ALL_AND_WIPE"); + break; + case HK_FORCE_DISMOUNT_ALL_AND_WIPE: item.pszText = GetString ("HK_FORCE_DISMOUNT_ALL_AND_WIPE"); break; @@ -202,6 +215,10 @@ static void DisplayHotkeyList (HWND hwnd item.pszText = GetString ("HK_SHOW_HIDE_MAIN_WINDOW"); break; + case HK_CLOSE_SECURITY_TOKEN_SESSIONS: + item.pszText = GetString ("IDM_CLOSE_ALL_TOKEN_SESSIONS"); + break; + default: item.pszText = L"[?]"; } @@ -250,39 +267,45 @@ static void DisplayHotkeyList (HWND hwnd -BOOL WINAPI HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hList = GetDlgItem (hwndDlg, IDC_HOTKEY_LIST); + HWND hwndMainDlg = hwndDlg; WORD lw = LOWORD (wParam); WORD hw = HIWORD (wParam); static BOOL bKeyScanOn; static BOOL bTPlaySoundOnHotkeyMountDismount; - static BOOL bTDisplayMsgBoxOnHotkeyDismount; + static BOOL bTDisplayMsgBoxOnHotkeyDismount; + + while (GetParent (hwndMainDlg) != NULL) + { + hwndMainDlg = GetParent (hwndMainDlg); + } switch (msg) { case WM_INITDIALOG: { LVCOLUMNW col; - + bKeyScanOn = FALSE; nSelectedHotkeyId = -1; currentVKeyCode = 0; memcpy (tmpHotkeys, Hotkeys, sizeof(tmpHotkeys)); - SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0, + SendMessageW (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP ); memset (&col,0,sizeof(col)); col.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT; col.pszText = GetString ("ACTION"); - col.cx = 220; + col.cx = CompensateXDPI (341); col.fmt = LVCFMT_LEFT; SendMessageW (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&col); col.pszText = GetString ("SHORTCUT"); - col.cx = 210; + col.cx = CompensateXDPI (190); col.fmt = LVCFMT_LEFT; SendMessageW (hList,LVM_INSERTCOLUMNW,1,(LPARAM)&col); @@ -358,6 +381,8 @@ BOOL WINAPI HotkeysDlgProc (HWND hwndDlg if (lw == IDC_HOTKEY_ASSIGN) { + BOOL bOwnActiveShortcut = FALSE; + if (nSelectedHotkeyId >= 0 && currentVKeyCode != 0) { UINT modifiers = 0; @@ -394,15 +419,18 @@ BOOL WINAPI HotkeysDlgProc (HWND hwndDlg break; } + bOwnActiveShortcut = ShortcutInUse (currentVKeyCode, modifiers, Hotkeys); + // Test if the shortcut can be assigned without errors - if (!RegisterHotKey (hwndDlg, nSelectedHotkeyId, modifiers, currentVKeyCode)) + if (!bOwnActiveShortcut + && !RegisterHotKey (hwndDlg, nSelectedHotkeyId, modifiers, currentVKeyCode)) { handleWin32Error(hwndDlg); return 1; } else { - if (!UnregisterHotKey (hwndDlg, nSelectedHotkeyId)) + if (!bOwnActiveShortcut && !UnregisterHotKey (hwndDlg, nSelectedHotkeyId)) handleWin32Error(hwndDlg); tmpHotkeys[nSelectedHotkeyId].vKeyCode = currentVKeyCode; @@ -472,9 +500,9 @@ BOOL WINAPI HotkeysDlgProc (HWND hwndDlg if (lw == IDOK) { - UnregisterAllHotkeys (GetParent (hwndDlg), Hotkeys); + UnregisterAllHotkeys (hwndMainDlg, Hotkeys); memcpy (Hotkeys, tmpHotkeys, sizeof(Hotkeys)); - RegisterAllHotkeys (GetParent (hwndDlg), Hotkeys); + RegisterAllHotkeys (hwndMainDlg, Hotkeys); KillTimer (hwndDlg, 0xfe); bPlaySoundOnHotkeyMountDismount = bTPlaySoundOnHotkeyMountDismount; bDisplayMsgBoxOnHotkeyDismount = bTDisplayMsgBoxOnHotkeyDismount;