OSDN Git Service

10015e807baf521d3c9a895dc78c8688bb402b53
[xkeymacs/xkeymacs.git] / xkeymacs / propertiesadvanced.cpp
1 // PropertiesAdvanced.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "xkeymacs.h"\r
6 #include "DotXkeymacs.h"\r
7 #include "Profile.h"\r
8 #include "Properties.h"\r
9 #include "PropertiesAdvanced.h"\r
10 \r
11 #ifdef _DEBUG\r
12 #define new DEBUG_NEW\r
13 #undef THIS_FILE\r
14 static char THIS_FILE[] = __FILE__;\r
15 #endif\r
16 \r
17 /////////////////////////////////////////////////////////////////////////////\r
18 // CPropertiesAdvanced property page\r
19 int     CPropertiesAdvanced::m_nAppID = 0;\r
20 int CPropertiesAdvanced::m_nCommandID = 0;\r
21 CEdit * CPropertiesAdvanced::m_pNewKey = NULL;\r
22 CButton * CPropertiesAdvanced::m_pAssign = NULL;\r
23 CStatic * CPropertiesAdvanced::m_pCurrentlyAssigned = NULL;\r
24 CListBox * CPropertiesAdvanced::m_pCurrentKeys = NULL;\r
25 HHOOK CPropertiesAdvanced::m_hKeyboardHook = NULL;\r
26 BOOL CPropertiesAdvanced::m_bC_x = FALSE;\r
27 BOOL CPropertiesAdvanced::m_bC = TRUE;\r
28 BOOL CPropertiesAdvanced::m_bM = TRUE;\r
29 BOOL CPropertiesAdvanced::m_bShift = TRUE;\r
30 int CPropertiesAdvanced::m_nAssignCommandType = 0;\r
31 int CPropertiesAdvanced::m_nAssignKey = 0;\r
32 int CPropertiesAdvanced::m_nCommandIDs[MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};\r
33 \r
34 IMPLEMENT_DYNCREATE(CPropertiesAdvanced, CPropertyPage)\r
35 \r
36 CPropertiesAdvanced::CPropertiesAdvanced() : CPropertyPage(CPropertiesAdvanced::IDD)\r
37 {\r
38         //{{AFX_DATA_INIT(CPropertiesAdvanced)\r
39         m_bEnableCUA = FALSE;\r
40         //}}AFX_DATA_INIT\r
41 }\r
42 \r
43 CPropertiesAdvanced::~CPropertiesAdvanced()\r
44 {\r
45 }\r
46 \r
47 void CPropertiesAdvanced::DoDataExchange(CDataExchange* pDX)\r
48 {\r
49         CPropertyPage::DoDataExchange(pDX);\r
50         //{{AFX_DATA_MAP(CPropertiesAdvanced)\r
51         DDX_Control(pDX, IDC_CURRENTLY_ASSIGNED, m_cCurrentlyAssigned);\r
52         DDX_Control(pDX, IDC_RESET_ALL, m_cResetAll);\r
53         DDX_Control(pDX, IDC_REMOVE, m_cRemove);\r
54         DDX_Control(pDX, IDC_NEW_KEY, m_cNewKey);\r
55         DDX_Control(pDX, IDC_DESCRIPTION, m_cDescription);\r
56         DDX_Control(pDX, IDC_CURRENT_KEYS, m_cCurrentKeys);\r
57         DDX_Control(pDX, IDC_COMMANDS, m_cCommands);\r
58         DDX_Control(pDX, IDC_CATEGORY, m_cCategory);\r
59         DDX_Control(pDX, IDC_ASSIGN, m_cAssign);\r
60         DDX_Check(pDX, IDC_ENABLE_CUA, m_bEnableCUA);\r
61         //}}AFX_DATA_MAP\r
62 }\r
63 \r
64 \r
65 BEGIN_MESSAGE_MAP(CPropertiesAdvanced, CPropertyPage)\r
66         //{{AFX_MSG_MAP(CPropertiesAdvanced)\r
67         ON_WM_CREATE()\r
68         ON_CBN_SELCHANGE(IDC_CATEGORY, OnSelchangeCategory)\r
69         ON_LBN_SELCHANGE(IDC_COMMANDS, OnSelchangeCommands)\r
70         ON_LBN_SELCHANGE(IDC_CURRENT_KEYS, OnSelchangeCurrentKeys)\r
71         ON_EN_SETFOCUS(IDC_NEW_KEY, OnSetfocusNewKey)\r
72         ON_BN_CLICKED(IDC_ASSIGN, OnAssign)\r
73         ON_BN_CLICKED(IDC_REMOVE, OnRemove)\r
74         ON_BN_CLICKED(IDC_RESET_ALL, OnResetAll)\r
75         ON_BN_CLICKED(IDC_C_X, OnCX)\r
76         ON_EN_KILLFOCUS(IDC_NEW_KEY, OnKillfocusNewKey)\r
77         ON_BN_CLICKED(IDC_ENABLE_CUA, OnEnableCua)\r
78         //}}AFX_MSG_MAP\r
79 END_MESSAGE_MAP()\r
80 \r
81 /////////////////////////////////////////////////////////////////////////////\r
82 // CPropertiesAdvanced message handlers\r
83 \r
84 BOOL CPropertiesAdvanced::OnSetActive() \r
85 {\r
86         m_pProperties->EnableControl(ADVANCED_TAB);\r
87         SetDialogData();\r
88 \r
89         return CPropertyPage::OnSetActive();\r
90 }\r
91 \r
92 void CPropertiesAdvanced::SetDialogData()\r
93 {\r
94         m_nAppID = m_pProperties->GetApplicationID();\r
95         if (m_nAppID == MAX_APP)\r
96                 return;\r
97         InitCommandIDs();\r
98         m_bEnableCUA = CProfile::GetEnableCUA(m_nAppID);\r
99         SetCurrentKeys();\r
100         UpdateData(FALSE);\r
101 }\r
102 \r
103 void CPropertiesAdvanced::GetDialogData()\r
104 {\r
105         UpdateData();\r
106 }\r
107 \r
108 int CPropertiesAdvanced::OnCreate(LPCREATESTRUCT lpCreateStruct) \r
109 {\r
110         if (CPropertyPage::OnCreate(lpCreateStruct) == -1)\r
111                 return -1;\r
112 \r
113         m_pProperties = (CProperties *)GetParent()->GetParent();\r
114 \r
115         return 0;\r
116 }\r
117 \r
118 BOOL CPropertiesAdvanced::OnKillActive() \r
119 {\r
120         GetDialogData();\r
121 \r
122         return CPropertyPage::OnKillActive();\r
123 }\r
124 \r
125 void CPropertiesAdvanced::EnableControl()\r
126 {\r
127         BOOL bEnable = m_pProperties->IsEnableControl();\r
128 \r
129         m_cCategory.EnableWindow(bEnable);\r
130         m_cCommands.EnableWindow(bEnable);\r
131         m_cCurrentKeys.EnableWindow(bEnable);\r
132         m_cNewKey.EnableWindow(bEnable);\r
133 \r
134         m_cAssign.EnableWindow(FALSE);\r
135         m_cRemove.EnableWindow(FALSE);\r
136         m_cResetAll.EnableWindow(bEnable);\r
137 }\r
138 \r
139 BOOL CPropertiesAdvanced::OnInitDialog() \r
140 {\r
141         CPropertyPage::OnInitDialog();\r
142 \r
143         m_nAppID = m_pProperties->GetApplicationID();\r
144         InitCategoryList();\r
145         SetCommands();\r
146 \r
147         SetDialogData();\r
148 \r
149         m_cAssign.EnableWindow(FALSE);\r
150         m_cRemove.EnableWindow(FALSE);\r
151 \r
152         m_cCurrentlyAssigned.SetWindowText(_T(""));\r
153 \r
154         return TRUE;  // return TRUE unless you set the focus to a control\r
155                       // EXCEPTION: OCX Property Pages should return FALSE\r
156 }\r
157 \r
158 void CPropertiesAdvanced::InitCategoryList()\r
159 {\r
160         int nCategoryIDs[128] = {'\0'};\r
161 \r
162         // get all category type\r
163         m_cCategory.ResetContent();\r
164         for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
165                 CString szCommandName = CCommands::GetCommandName(nComID);\r
166                 if (szCommandName.IsEmpty()) {\r
167                         break;\r
168                 }\r
169                 int nCategoryID = CCommands::GetCategoryID(nComID);\r
170                 if (!nCategoryID) {\r
171                         continue;\r
172                 }\r
173 \r
174                 BOOL bExist = FALSE;\r
175                 int i;\r
176                 for (i = 0; nCategoryIDs[i]; ++i) {\r
177                         if (nCategoryIDs[i] == nCategoryID) {\r
178                                 bExist = TRUE;\r
179                         }\r
180                 }\r
181                 if (!bExist) {\r
182                         nCategoryIDs[i] = nCategoryID;\r
183                 }\r
184         }\r
185 \r
186         // sort category type in combo box\r
187         int nMinimumID = 0;\r
188         for (int i = 0; nCategoryIDs[i]; ++i) {\r
189                 int nID = 0;\r
190                 for (int j = 0; nCategoryIDs[j]; ++j) {\r
191                         if (nMinimumID < nCategoryIDs[j]\r
192                          && (nID == 0 || nCategoryIDs[j] < nID)) {\r
193                                 nID = nCategoryIDs[j];\r
194                         }\r
195                 }\r
196                 m_cCategory.InsertString(-1, CString(MAKEINTRESOURCE(nID)));\r
197                 nMinimumID = nID;\r
198         }\r
199 \r
200         if (CDotXkeymacs::GetFunctionNumber()) {\r
201                 m_cCategory.InsertString(-1, CString(MAKEINTRESOURCE(IDS_ORIGINAL)));\r
202         }\r
203 \r
204         m_cCategory.SetCurSel(0);\r
205 }\r
206 \r
207 void CPropertiesAdvanced::SetCommands()\r
208 {\r
209         m_cCommands.ResetContent();\r
210 \r
211         CString szCategory;\r
212         m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
213         if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
214                 for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
215                         CString szCommandName = CCommands::GetCommandName(nComID);\r
216                         if (szCommandName.IsEmpty()) {\r
217                                 break;\r
218                         }\r
219 \r
220                         if (szCategory == CString(MAKEINTRESOURCE(CCommands::GetCategoryID(nComID)))) {\r
221                                 m_cCommands.AddString(szCommandName);\r
222                         }\r
223                 }\r
224         } else {\r
225                 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
226                         BOOL bOriginal = TRUE;\r
227                         for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {\r
228                                 CString szCommandName = CCommands::GetCommandName(nComID);\r
229                                 if (szCommandName.IsEmpty()) {\r
230                                         break;\r
231                                 }\r
232 \r
233                                 if (szCommandName == CDotXkeymacs::GetFunctionSymbol(nFuncID)) {\r
234                                         bOriginal = FALSE;      // overwriting build-in keybindings\r
235                                         break;\r
236                                 }\r
237                         }\r
238                         if (bOriginal) {\r
239                                 m_cCommands.AddString(CDotXkeymacs::GetFunctionSymbol(nFuncID));\r
240                         }\r
241                 }\r
242         }\r
243 \r
244         m_cCommands.SetCurSel(0);\r
245         SetCurrentKeys();\r
246 }\r
247 \r
248 void CPropertiesAdvanced::SetCurrentKeys()\r
249 {\r
250         m_cCurrentKeys.ResetContent();\r
251         m_cRemove.EnableWindow(FALSE);\r
252 \r
253         CString szCategory;\r
254         m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
255 \r
256         CString szCurrentCommandName;\r
257         m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
258 \r
259         if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
260                 for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {\r
261                         for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
262                                 if (CCommands::GetCommandName(CProfile::GetCommandID(m_nAppID, nType, nKey)) == szCurrentCommandName) {\r
263                                         CString sz;\r
264                                         sz.Format(_T("%s%s"), CProfile::CommandType2String(nType), CProfile::Key2String(nKey));\r
265                                         m_cCurrentKeys.AddString(sz);\r
266                                 }\r
267                         }\r
268                 }\r
269 \r
270                 CString szCommandName;\r
271                 for (int nComID = 0; nComID < MAX_COMMAND; ++nComID) {\r
272                         szCommandName = CCommands::GetCommandName(nComID);\r
273                         if (szCommandName.IsEmpty()) {\r
274                                 break;\r
275                         }\r
276                         if (szCommandName == szCurrentCommandName) {\r
277                                 m_nCommandID = nComID;\r
278                                 break;\r
279                         }\r
280                 }\r
281 \r
282                 m_cDescription.SetWindowText(CString(MAKEINTRESOURCE(CCommands::GetDescriptionID(m_nCommandID))));\r
283 \r
284                 // overwrite by original command's description if needed\r
285                 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {\r
286                         if (szCommandName == CDotXkeymacs::GetFunctionSymbol(nFuncID)) {\r
287                                 m_cDescription.SetWindowText(CDotXkeymacs::GetFunctionDefinition(szCurrentCommandName));\r
288                                 break;\r
289                         }\r
290                 }\r
291         } else {\r
292                 const int nIndex = CDotXkeymacs::GetIndex(szCurrentCommandName);\r
293                 for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nIndex, m_nAppID); ++nKeyID) {\r
294                         int nType = 0;\r
295                         int nKey = 0;\r
296                         CDotXkeymacs::GetKey(nIndex, m_nAppID, nKeyID, &nType, &nKey);\r
297 \r
298                         CString sz;\r
299                         sz.Format(_T("%s%s"), CProfile::CommandType2String(nType), CProfile::Key2String(nKey));\r
300                         m_cCurrentKeys.AddString(sz);\r
301                 }\r
302 \r
303                 m_cDescription.SetWindowText(CDotXkeymacs::GetFunctionDefinition(szCurrentCommandName));\r
304         }\r
305 }\r
306 \r
307 void CPropertiesAdvanced::OnSelchangeCategory() \r
308 {\r
309         SetCommands();\r
310         ClearNewKey();\r
311 }\r
312 \r
313 void CPropertiesAdvanced::OnSelchangeCommands() \r
314 {\r
315         BOOL bEnableWindow = FALSE;\r
316         CString szCurrentCommandName;\r
317         m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
318         if (szCurrentCommandName.CompareNoCase(_T("C-"))\r
319          && szCurrentCommandName.CompareNoCase(_T("Meta for Alt"))\r
320          && szCurrentCommandName.CompareNoCase(_T("Pass Through"))) {\r
321                 bEnableWindow = TRUE;\r
322         }\r
323         GetDlgItem(IDC_C_X)->EnableWindow(bEnableWindow);\r
324         m_bC = bEnableWindow;\r
325         m_bM = bEnableWindow;\r
326         m_bShift = bEnableWindow;\r
327 \r
328         SetCurrentKeys();\r
329         ClearNewKey();\r
330 }\r
331 \r
332 void CPropertiesAdvanced::OnSelchangeCurrentKeys() \r
333 {\r
334         TCHAR szKeyBind[128] = {'\0'};\r
335         m_cCurrentKeys.GetText(m_cCurrentKeys.GetCurSel(), szKeyBind);\r
336         CProfile::ReadKeyBind(m_nRemoveCommandType, m_nRemoveKey, szKeyBind);\r
337         m_cRemove.EnableWindow();\r
338 }\r
339 \r
340 void CPropertiesAdvanced::OnSetfocusNewKey() \r
341 {\r
342         m_pNewKey = &m_cNewKey;\r
343         m_pAssign = &m_cAssign;\r
344         m_pCurrentlyAssigned = &m_cCurrentlyAssigned;\r
345         m_pCurrentKeys = &m_cCurrentKeys;\r
346         m_hKeyboardHook = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)CPropertiesAdvanced::KeyboardProc, NULL, AfxGetApp()->m_nThreadID);\r
347 \r
348         m_bC_x = IsDlgButtonChecked(IDC_C_X) && GetDlgItem(IDC_C_X)->IsWindowEnabled();\r
349 }\r
350 \r
351 void CPropertiesAdvanced::OnAssign() \r
352 {\r
353         // Remove Current Setting\r
354         CProfile::SetCommandID(m_nAppID, m_nAssignCommandType, m_nAssignKey, 0);\r
355         SetCommandID(m_nAssignCommandType, m_nAssignKey, 0);\r
356         CDotXkeymacs::RemoveKey(m_nAppID, m_nAssignCommandType, m_nAssignKey);\r
357 \r
358         // Assign New Setting\r
359         CString szItem;\r
360         szItem.Format(_T("%s%s"), CProfile::CommandType2String(m_nAssignCommandType), CProfile::Key2String(m_nAssignKey));\r
361         if (m_cCurrentKeys.FindString(-1, szItem) == LB_ERR) {  // This key bind has not assignd to the same command yet.\r
362                 CString szCategory;\r
363                 m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
364 \r
365                 if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
366                         CProfile::SetCommandID(m_nAppID, m_nAssignCommandType, m_nAssignKey, m_nCommandID);\r
367                         SetCommandID(m_nAssignCommandType, m_nAssignKey, m_nCommandID);\r
368                 } else {\r
369                         CString szCurrentCommandName;\r
370                         m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
371                         CDotXkeymacs::SetKey(CDotXkeymacs::GetIndex(szCurrentCommandName), m_nAppID, m_nAssignCommandType, m_nAssignKey);\r
372                 }\r
373                 m_cCurrentKeys.AddString(szItem);\r
374         }\r
375 \r
376         ClearNewKey();\r
377 }\r
378 \r
379 void CPropertiesAdvanced::OnRemove() \r
380 {\r
381         CString szCategory;\r
382         m_cCategory.GetLBText(m_cCategory.GetCurSel(), szCategory);\r
383 \r
384         if (szCategory.Compare(CString(MAKEINTRESOURCE(IDS_ORIGINAL)))) {\r
385                 CProfile::SetCommandID(m_nAppID, m_nRemoveCommandType, m_nRemoveKey, 0);\r
386                 SetCommandID(m_nRemoveCommandType, m_nRemoveKey, 0);\r
387         } else {\r
388                 CString szCurrentCommandName;\r
389                 m_cCommands.GetText(m_cCommands.GetCurSel(), szCurrentCommandName);\r
390                 CDotXkeymacs::RemoveKey(CDotXkeymacs::GetIndex(szCurrentCommandName), m_nAppID, m_nRemoveCommandType, m_nRemoveKey);\r
391         }\r
392 \r
393         m_cCurrentKeys.DeleteString(m_cCurrentKeys.GetCurSel());\r
394         m_cRemove.EnableWindow(FALSE);\r
395         m_nRemoveCommandType = 0;\r
396         m_nRemoveKey = 0;\r
397 }\r
398 \r
399 void CPropertiesAdvanced::OnResetAll() \r
400 {\r
401         CProfile::LoadData();\r
402         InitCommandIDs();\r
403         SetCurrentKeys();\r
404 }\r
405 \r
406 void CPropertiesAdvanced::ClearNewKey()\r
407 {\r
408         m_cNewKey.SetWindowText(_T(""));\r
409         m_cAssign.EnableWindow(FALSE);\r
410         m_nAssignCommandType = 0;\r
411         m_nAssignKey = 0;\r
412         m_cCurrentlyAssigned.SetWindowText(_T(""));\r
413 }\r
414 \r
415 LRESULT CALLBACK CPropertiesAdvanced::KeyboardProc(int code, WPARAM wParam, LPARAM lParam)\r
416 {\r
417         if (code < 0 || code == HC_NOREMOVE) {\r
418                 return ::CallNextHookEx(m_hKeyboardHook, code, wParam, lParam);\r
419         }\r
420 \r
421         if (lParam & BEING_RELEASED) {  // Key Up\r
422         } else {                                                // Key Down\r
423                 switch (wParam) {\r
424                 case VK_CONTROL:\r
425                         if (lParam & EXTENDED_KEY) {\r
426                                 wParam = VK_RCONTROL;\r
427                         } else {\r
428                                 wParam = VK_LCONTROL;\r
429                         }\r
430                         break;\r
431                 case VK_MENU:\r
432                         if (lParam & EXTENDED_KEY) {\r
433                                 wParam = VK_RMENU;\r
434                         } else {\r
435                                 wParam = VK_LMENU;\r
436                         }\r
437                         break;\r
438                 case VK_SHIFT:\r
439                         if (lParam & EXTENDED_KEY) {\r
440                                 wParam = VK_RSHIFT;\r
441                         } else {\r
442                                 wParam = VK_LSHIFT;\r
443                         }\r
444                         break;\r
445                 default:\r
446                         break;\r
447                 }\r
448                 m_nAssignKey = wParam;\r
449                 SetNewKey();\r
450         }\r
451 \r
452         return TRUE;\r
453 }\r
454 \r
455 void CPropertiesAdvanced::SetNewKey()\r
456 {\r
457         CString szNewKey;\r
458         int nType = NONE;\r
459 \r
460         if (m_bC_x) {\r
461                 szNewKey += _T("Ctrl+X ");\r
462                 nType += CONTROLX;\r
463         }\r
464         if (IsCtrlDown()) {\r
465                 szNewKey += _T("Ctrl+");\r
466                 nType += CONTROL;\r
467         }\r
468         if (IsMetaDown()) {\r
469                 szNewKey += _T("Meta+");\r
470                 nType += META;\r
471         }\r
472         if (IsShiftDown()) {\r
473                 szNewKey += _T("Shift+");\r
474                 nType += SHIFT;\r
475         }\r
476 \r
477         m_nAssignCommandType = nType;\r
478 \r
479         szNewKey += CProfile::Key2String(m_nAssignKey);\r
480         if (m_pNewKey) {\r
481                 m_pNewKey->SetWindowText(szNewKey);\r
482         }\r
483 \r
484         if (m_pAssign) {\r
485                 BOOL bEnable = TRUE;\r
486                 if (m_pCurrentKeys\r
487                  && m_pCurrentKeys->FindString(-1, szNewKey) != LB_ERR) {       // This key bind is already assigned.\r
488                         bEnable = FALSE;\r
489                 }\r
490                 m_pAssign->EnableWindow(bEnable);\r
491         }\r
492 \r
493         if (m_pCurrentlyAssigned) {\r
494                 CString szCurrentlyAssigned(_T("Currently assigned to:\n"));\r
495 \r
496                 if (m_nCommandIDs[m_nAssignCommandType][m_nAssignKey] || CDotXkeymacs::GetIndex(m_nAppID, m_nAssignCommandType, m_nAssignKey) == -1) {\r
497                         szCurrentlyAssigned += CCommands::GetCommandName(m_nCommandIDs[m_nAssignCommandType][m_nAssignKey]);\r
498                 } else {\r
499                         szCurrentlyAssigned += CDotXkeymacs::GetFunctionSymbol(CDotXkeymacs::GetIndex(m_nAppID, m_nAssignCommandType, m_nAssignKey));\r
500                 }\r
501                 m_pCurrentlyAssigned->SetWindowText(szCurrentlyAssigned);\r
502         }\r
503 }\r
504 \r
505 void CPropertiesAdvanced::SetCommandID(int nType, int nKey, int nComID)\r
506 {\r
507         m_nCommandIDs[nType][nKey] = nComID;\r
508 \r
509         // Set C-x if it is needed.\r
510         if ((nType & CONTROLX)) {\r
511                 // Get CommandID of C-x.\r
512                 int nCommandIDofC_x;\r
513                 for (nCommandIDofC_x = 0; nCommandIDofC_x < MAX_COMMAND; ++nCommandIDofC_x) {\r
514                         if (!_tcsicmp(CCommands::GetCommandName(nCommandIDofC_x), _T("C-x"))) {\r
515                                 break;\r
516                         }\r
517                 }\r
518 \r
519                 if (nComID) {\r
520                         m_nCommandIDs[CONTROL]['X'] = nCommandIDofC_x;\r
521                 } else {\r
522                         for (int i = 0; i < MAX_COMMAND_TYPE; ++i) {    // i is command-type.\r
523                                 if (!(i & CONTROLX)) {\r
524                                         continue;\r
525                                 }\r
526                                 for (int j = 0; j < MAX_KEY; ++j) {             // j is key.\r
527                                         if (m_nCommandIDs[i][j]) {\r
528                                                 m_nCommandIDs[CONTROL]['X'] = nCommandIDofC_x;  // needless\r
529                                                 return;\r
530                                         }\r
531                                 }\r
532                         }\r
533                         m_nCommandIDs[CONTROL]['X'] = 0;\r
534                 }\r
535         }\r
536 }\r
537 \r
538 void CPropertiesAdvanced::InitCommandIDs()\r
539 {\r
540         for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {\r
541                 for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
542                         SetCommandID(nType, nKey, CProfile::GetCommandID(m_nAppID, nType, nKey));\r
543                 }\r
544         }\r
545 }\r
546 \r
547 void CPropertiesAdvanced::OnCX() \r
548 {\r
549         if (m_nAssignKey) {\r
550                 OnSetfocusNewKey();\r
551                 SetNewKey();\r
552         }\r
553 }\r
554 \r
555 void CPropertiesAdvanced::OnKillfocusNewKey() \r
556 {\r
557         if (m_hKeyboardHook) {\r
558                 ::UnhookWindowsHookEx(m_hKeyboardHook);\r
559         }\r
560         m_hKeyboardHook = NULL;\r
561 }\r
562 \r
563 void CPropertiesAdvanced::OnEnableCua() \r
564 {\r
565         UpdateData();\r
566         CProfile::SetEnableCUA(m_nAppID, m_bEnableCUA);\r
567 }\r
568 \r
569 BOOL CPropertiesAdvanced::IsCtrlDown()\r
570 {\r
571         return m_bC && IsFooDown(CString(_T("C-")));\r
572 }\r
573 \r
574 BOOL CPropertiesAdvanced::IsMetaDown()\r
575 {\r
576         return m_bM && IsFooDown(CString(_T("Meta for Alt")));\r
577 }\r
578 \r
579 BOOL CPropertiesAdvanced::IsShiftDown()\r
580 {\r
581         // temporary code\r
582         return m_bShift\r
583                 && (GetKeyState(VK_SHIFT ) < 0\r
584                  || GetKeyState(VK_LSHIFT) < 0\r
585                  || GetKeyState(VK_RSHIFT) < 0);\r
586 \r
587 //      return m_bShift && IsFooDown(CString("Foo"));\r
588 }\r
589 \r
590 BOOL CPropertiesAdvanced::IsFooDown(CString szCommandName)\r
591 {\r
592         for (int nKey = 0; nKey < MAX_KEY; ++nKey) {\r
593                 if (CCommands::GetCommandName(CProfile::GetCommandID(0, NONE, nKey)) == szCommandName) {        // FIXME\r
594                         if (GetKeyState(nKey) < 0) {\r
595                                 return TRUE;\r
596                         }\r
597                 }\r
598         }\r
599         return FALSE;\r
600 }\r