OSDN Git Service

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