OSDN Git Service

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