Kiln » TortoiseHg » TortoiseHg
Clone URL:  
KeyboardHelpDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (C) 2011 Fog Creek Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" #include "KeyboardHelpDialog.h" #include "RegistryConfig.h" #include "GlobalData.h" static CString GetKeyName(UINT uKey, bool bExtended = false) { UINT uScanCode = ::MapVirtualKey(uKey, MAPVK_VK_TO_VSC); LONG lParam = (LONG)uScanCode << 16; // Adding this flag prevents a distinction from being made between the left and // right Alt, Control, or Shift keys. lParam |= (1 << 25); // Adding this flag is necessary for certain keys (e.g. Insert, Delete) to be // handled properly. However, it prevents other keys (e.g. Shift) from being // handled properly. Therefore, only use it when necessary. if (bExtended) lParam |= (1 << 24); // Get the name of the key. TCHAR szKeyName[20]; ::GetKeyNameText(lParam, szKeyName, 20); return szKeyName; } static CStringW LookupMenuText(CString strName, CString strLang) { // Search the context menu list to find the menu text for the specified command. // Then, attempt to find a localized string in the registry. for (int i = 0; i < MenuDescListCount; i++) { if (MenuDescList[i].strName == strName) { CStringW strMenuText = MenuDescList[i].strMenuText; if (!strLang.IsEmpty()) { CStringW strDummy; GetCMenuTranslation(strLang, MenuDescList[i].strName, strMenuText, strDummy); } if (strMenuText.Right(3) == "...") { // Strip off any trailing ellipsis from the name. strMenuText.Truncate(strMenuText.GetLength() - 3); } return strMenuText; } } return ""; } LRESULT CKeyboardHelpDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) { CenterWindow(); // Attempt to load localized dialog strings if they exist. CString strLang; GetRegistryConfig("CMenuLang", strLang); if (!strLang.IsEmpty()) { CStringW strMenuText; CStringW strHelpText; GetCMenuTranslation(strLang, "keyboarddialog", strMenuText, strHelpText); if (!strMenuText.IsEmpty()) ::SetWindowTextW(m_hWnd, strMenuText); if (!strHelpText.IsEmpty()) ::SetDlgItemTextW(m_hWnd, IDC_TOPTEXT, strHelpText); } // Set tab stops for the list box. int nTabStop = 100; SendDlgItemMessage(IDC_KEYLIST, LB_SETTABSTOPS, 1, (LPARAM)&nTabStop); // Get the names of the Alt, Control, and Shift keys. CString strAlt = GetKeyName(VK_MENU); CString strControl = GetKeyName(VK_CONTROL); CString strShift = GetKeyName(VK_SHIFT); strAlt += '+'; strControl += '+'; strShift += '+'; // Add each keyboard shortcut to the list box. for (int i = 0; i < KeyShortcutListCount; i++) { CString strKey; WORD wFlags = KeyShortcutList[i].wFlags; if (wFlags & KSF_CONTROL) strKey += strControl; if (wFlags & KSF_ALT) strKey += strAlt; if (wFlags & KSF_SHIFT) strKey += strShift; strKey += GetKeyName(KeyShortcutList[i].wKey, true); strKey += '\t'; strKey += LookupMenuText(KeyShortcutList[i].strName, strLang); SendDlgItemMessage(IDC_KEYLIST, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)strKey); } return 1L; } LRESULT CKeyboardHelpDialog::OnOK(WORD, WORD, HWND, BOOL&) { EndDialog(IDOK); return 1L; }