1 // 109Keyboard.cpp : implementation file
\r
6 #include "xkeymacs.h"
\r
7 #include "109Keyboard.h"
\r
10 #define new DEBUG_NEW
\r
12 static char THIS_FILE[] = __FILE__;
\r
15 /////////////////////////////////////////////////////////////////////////////
\r
16 // C109Keyboard dialog
\r
19 C109Keyboard::C109Keyboard(const HKEY_TYPE hkey_type, CWnd *const pParent /*=NULL*/)
\r
20 : CDialog(C109Keyboard::IDD, pParent)
\r
22 //{{AFX_DATA_INIT(C109Keyboard)
\r
23 // NOTE: the ClassWizard will add member initialization here
\r
25 m_HkeyType = hkey_type;
\r
29 void C109Keyboard::DoDataExchange(CDataExchange *const pDX)
\r
31 CDialog::DoDataExchange(pDX);
\r
32 //{{AFX_DATA_MAP(C109Keyboard)
\r
33 // NOTE: the ClassWizard will add DDX and DDV calls here
\r
38 BEGIN_MESSAGE_MAP(C109Keyboard, CDialog)
\r
39 //{{AFX_MSG_MAP(C109Keyboard)
\r
44 /////////////////////////////////////////////////////////////////////////////
\r
45 // C109Keyboard message handlers
\r
47 BOOL C109Keyboard::OnInitDialog()
\r
49 CDialog::OnInitDialog();
\r
51 CString szWindowText;
\r
53 switch (m_HkeyType) {
\r
56 TCHAR szUserName[UNLEN + 1] = {'0'};
\r
57 DWORD nSize = UNLEN + 1;
\r
58 if (GetUserName(szUserName, &nSize)) {
\r
59 szFor.Format(IDS_FOR, szUserName);
\r
61 szFor.LoadString(IDS_FOR_LOGGED_ON_USER);
\r
66 szFor.LoadString(IDS_FOR_ANY_USER);
\r
71 this->GetWindowText(szWindowText);
\r
72 this->SetWindowText(szWindowText + szFor);
\r
74 m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX);
\r
75 m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline
\r
77 CProfile::LoadScanCodeMap(m_HkeyType);
\r
78 for (int i = 0; i < sizeof(KeyboardLayouts) / sizeof(KeyboardLayouts[0]); ++i) {
\r
79 if (!GetDlgItem(KeyboardLayouts[i].nBaseControlID)
\r
80 || !GetDlgItem(KeyboardLayouts[i].nCurrentControlID)) {
\r
84 KeyboardLayouts[i].pBaseKey = new CKey(KeyboardLayouts[i].nBaseControlID, NORMAL_KEY, m_HkeyType);
\r
85 KeyboardLayouts[i].pBaseKey->SubclassDlgItem(KeyboardLayouts[i].nBaseControlID, this);
\r
86 m_ToolTip.AddTool(GetDlgItem(KeyboardLayouts[i].nBaseControlID), CProfile::GetToolTipID(KeyboardLayouts[i].nToolTipID));
\r
88 KeyboardLayouts[i].pCurrentKey = new CKey(KeyboardLayouts[i].nCurrentControlID, ORIGINAL_KEY, m_HkeyType);
\r
89 KeyboardLayouts[i].pCurrentKey->SubclassDlgItem(KeyboardLayouts[i].nCurrentControlID, this);
\r
90 m_ToolTip.AddTool(GetDlgItem(KeyboardLayouts[i].nCurrentControlID), CProfile::GetToolTipID(KeyboardLayouts[i].nToolTipID));
\r
92 ScanCode current = {'\0'};
\r
93 if (CProfile::GetScanCodeMap(m_HkeyType, KeyboardLayouts[i].scancode, ¤t)) {
\r
94 KeyboardLayouts[i].pCurrentKey->SetKeyType(REMAPPED_KEY);
\r
96 CString szWindowText;
\r
97 GetDlgItem(CProfile::GetBaseControlID(current))->GetWindowText(szWindowText);
\r
98 GetDlgItem(KeyboardLayouts[i].nCurrentControlID)->SetWindowText(szWindowText);
\r
100 KeyboardLayout *pKeyboardLayout = CProfile::GetKeyboardLayouts(CProfile::GetBaseControlID(current));
\r
101 if (pKeyboardLayout) {
\r
102 m_ToolTip.UpdateTipText(CProfile::GetToolTipID(pKeyboardLayout->nToolTipID), GetDlgItem(KeyboardLayouts[i].nCurrentControlID));
\r
107 return TRUE; // return TRUE unless you set the focus to a control
\r
108 // EXCEPTION: OCX Property Pages should return FALSE
\r
111 void C109Keyboard::OnOK()
\r
113 if (CProfile::LostKeyWarning(m_HkeyType) != IDCANCEL) {
\r
114 CProfile::SaveScanCodeMap(m_HkeyType);
\r
120 void C109Keyboard::OnDestroy()
\r
122 CDialog::OnDestroy();
\r
124 for (int i = 0; i < sizeof(KeyboardLayouts) / sizeof(KeyboardLayouts[0]); ++i) {
\r
125 if (!GetDlgItem(KeyboardLayouts[i].nBaseControlID)
\r
126 || !GetDlgItem(KeyboardLayouts[i].nCurrentControlID)) {
\r
130 if (KeyboardLayouts[i].pBaseKey) {
\r
131 delete KeyboardLayouts[i].pBaseKey;
\r
132 KeyboardLayouts[i].pBaseKey = NULL;
\r
134 if (KeyboardLayouts[i].pCurrentKey) {
\r
135 delete KeyboardLayouts[i].pCurrentKey;
\r
136 KeyboardLayouts[i].pCurrentKey = NULL;
\r
141 BOOL C109Keyboard::PreTranslateMessage(MSG *const pMsg)
\r
143 // TODO: Add your specialized code here and/or call the base class
\r
144 switch (pMsg->message) {
\r
145 case WM_LBUTTONDOWN:
\r
148 m_ToolTip.RelayEvent(pMsg);
\r
152 return CDialog::PreTranslateMessage(pMsg);
\r