From f5b0054fe02cc3489329a98b10483c4ab1b2cd99 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Mon, 18 Jul 2011 16:45:24 +0900 Subject: [PATCH] Move more code from C104Keyboard and C109Keyboard to CKeyboardLayout, and remove DoDataExchange. --- xkeymacs/104keyboard.cpp | 85 --------------------------------------------- xkeymacs/104keyboard.h | 21 ----------- xkeymacs/109keyboard.cpp | 85 --------------------------------------------- xkeymacs/109keyboard.h | 19 ---------- xkeymacs/keyboardlayout.cpp | 69 +++++++++++++++++++++++++++++++++++- xkeymacs/keyboardlayout.h | 5 +++ 6 files changed, 73 insertions(+), 211 deletions(-) diff --git a/xkeymacs/104keyboard.cpp b/xkeymacs/104keyboard.cpp index c4cef51..4392f2f 100644 --- a/xkeymacs/104keyboard.cpp +++ b/xkeymacs/104keyboard.cpp @@ -2,8 +2,6 @@ // #include "stdafx.h" -#include -#include "xkeymacs.h" #include "104Keyboard.h" #ifdef _DEBUG @@ -23,86 +21,3 @@ C104Keyboard::C104Keyboard(const HKEY_TYPE hkey_type, CWnd *const pParent /*=NUL // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } - -void C104Keyboard::DoDataExchange(CDataExchange *const pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(C104Keyboard) - // NOTE: the ClassWizard will add DDX and DDV calls here - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(C104Keyboard, CDialog) - //{{AFX_MSG_MAP(C104Keyboard) - ON_WM_DESTROY() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// C104Keyboard message handlers - -BOOL C104Keyboard::OnInitDialog() -{ - CDialog::OnInitDialog(); - - CString szWindowText; - CString szFor; - switch (m_HkeyType) { - case CURRENT_USER: - { - TCHAR szUserName[UNLEN + 1] = {'0'}; - DWORD nSize = UNLEN + 1; - if (GetUserName(szUserName, &nSize)) { - szFor.Format(IDS_FOR, szUserName); - } else { - szFor.LoadString(IDS_FOR_LOGGED_ON_USER); - } - } - break; - case LOCAL_MACHINE: - szFor.LoadString(IDS_FOR_ANY_USER); - break; - default: - break; - } - this->GetWindowText(szWindowText); - this->SetWindowText(szWindowText + szFor); - - m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX); - m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline - - InitKeyboardLayout(); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void C104Keyboard::OnOK() -{ - if (LostKeyWarning(m_HkeyType) != IDCANCEL) { - SaveScanCodeMap(m_HkeyType); - - CDialog::OnOK(); - } -} - -void C104Keyboard::OnDestroy() -{ - CDialog::OnDestroy(); - - DestroyKeyboardLayout(); -} - -BOOL C104Keyboard::PreTranslateMessage(MSG *const pMsg) -{ - switch (pMsg->message) { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MOUSEMOVE: - m_ToolTip.RelayEvent(pMsg); - break; - } - - return CDialog::PreTranslateMessage(pMsg); -} diff --git a/xkeymacs/104keyboard.h b/xkeymacs/104keyboard.h index 9c6e95b..6c765a2 100644 --- a/xkeymacs/104keyboard.h +++ b/xkeymacs/104keyboard.h @@ -17,7 +17,6 @@ class C104Keyboard : public CKeyboardLayout { // Construction public: - CToolTipCtrl m_ToolTip; C104Keyboard(HKEY_TYPE hkey_type, CWnd* pParent = NULL); // standard constructor // Dialog Data @@ -25,26 +24,6 @@ public: enum { IDD = IDD_104KEYBOARD }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(C104Keyboard) - public: - virtual BOOL PreTranslateMessage(MSG* pMsg); - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(C104Keyboard) - virtual BOOL OnInitDialog(); - virtual void OnOK(); - afx_msg void OnDestroy(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} diff --git a/xkeymacs/109keyboard.cpp b/xkeymacs/109keyboard.cpp index 5f0d124..efe940b 100644 --- a/xkeymacs/109keyboard.cpp +++ b/xkeymacs/109keyboard.cpp @@ -2,8 +2,6 @@ // #include "stdafx.h" -#include -#include "xkeymacs.h" #include "109Keyboard.h" #ifdef _DEBUG @@ -24,89 +22,6 @@ C109Keyboard::C109Keyboard(const HKEY_TYPE hkey_type, CWnd *const pParent /*=NUL //}}AFX_DATA_INIT } -void C109Keyboard::DoDataExchange(CDataExchange *const pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(C109Keyboard) - // NOTE: the ClassWizard will add DDX and DDV calls here - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(C109Keyboard, CDialog) - //{{AFX_MSG_MAP(C109Keyboard) - ON_WM_DESTROY() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// C109Keyboard message handlers - -BOOL C109Keyboard::OnInitDialog() -{ - CDialog::OnInitDialog(); - - CString szWindowText; - CString szFor; - switch (m_HkeyType) { - case CURRENT_USER: - { - TCHAR szUserName[UNLEN + 1] = {'0'}; - DWORD nSize = UNLEN + 1; - if (GetUserName(szUserName, &nSize)) { - szFor.Format(IDS_FOR, szUserName); - } else { - szFor.LoadString(IDS_FOR_LOGGED_ON_USER); - } - } - break; - case LOCAL_MACHINE: - szFor.LoadString(IDS_FOR_ANY_USER); - break; - default: - break; - } - this->GetWindowText(szWindowText); - this->SetWindowText(szWindowText + szFor); - - m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX); - m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline - - InitKeyboardLayout(); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void C109Keyboard::OnOK() -{ - if (LostKeyWarning(m_HkeyType) != IDCANCEL) { - SaveScanCodeMap(m_HkeyType); - - CDialog::OnOK(); - } -} - -void C109Keyboard::OnDestroy() -{ - CDialog::OnDestroy(); - - DestroyKeyboardLayout(); -} - -BOOL C109Keyboard::PreTranslateMessage(MSG *const pMsg) -{ - switch (pMsg->message) { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MOUSEMOVE: - m_ToolTip.RelayEvent(pMsg); - break; - } - - return CDialog::PreTranslateMessage(pMsg); -} - int C109Keyboard::GetToolTipID(int nToolTipID) { switch (nToolTipID) { diff --git a/xkeymacs/109keyboard.h b/xkeymacs/109keyboard.h index e903f7b..6059d00 100644 --- a/xkeymacs/109keyboard.h +++ b/xkeymacs/109keyboard.h @@ -25,26 +25,7 @@ public: enum { IDD = IDD_109KEYBOARD }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(C109Keyboard) - public: - virtual BOOL PreTranslateMessage(MSG* pMsg); - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation protected: - // Generated message map functions - //{{AFX_MSG(C109Keyboard) - virtual BOOL OnInitDialog(); - virtual void OnOK(); - afx_msg void OnDestroy(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() int GetToolTipID(int nToolTipID); }; diff --git a/xkeymacs/keyboardlayout.cpp b/xkeymacs/keyboardlayout.cpp index 79b2504..bafc3f0 100644 --- a/xkeymacs/keyboardlayout.cpp +++ b/xkeymacs/keyboardlayout.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include #include "keyboardlayout.h" const int MAX_KEYBOARD_LAYOUT = 112; @@ -130,13 +131,79 @@ CKeyboardLayout::~CKeyboardLayout() { } +BEGIN_MESSAGE_MAP(CKeyboardLayout, CDialog) + ON_WM_DESTROY() +END_MESSAGE_MAP() + +BOOL CKeyboardLayout::OnInitDialog() +{ + CDialog::OnInitDialog(); + + CString szWindowText; + CString szFor; + switch (m_HkeyType) { + case CURRENT_USER: + { + TCHAR szUserName[UNLEN + 1] = {'0'}; + DWORD nSize = UNLEN + 1; + if (GetUserName(szUserName, &nSize)) { + szFor.Format(IDS_FOR, szUserName); + } else { + szFor.LoadString(IDS_FOR_LOGGED_ON_USER); + } + } + break; + case LOCAL_MACHINE: + szFor.LoadString(IDS_FOR_ANY_USER); + break; + default: + break; + } + this->GetWindowText(szWindowText); + this->SetWindowText(szWindowText + szFor); + + m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX); + m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline + + InitKeyboardLayout(); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CKeyboardLayout::OnOK() +{ + if (LostKeyWarning(m_HkeyType) != IDCANCEL) { + SaveScanCodeMap(m_HkeyType); + CDialog::OnOK(); + } +} + +void CKeyboardLayout::OnDestroy() +{ + CDialog::OnDestroy(); + DestroyKeyboardLayout(); +} + +BOOL CKeyboardLayout::PreTranslateMessage(MSG *pMsg) +{ + switch (pMsg->message) { + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_MOUSEMOVE: + m_ToolTip.RelayEvent(pMsg); + break; + } + return CDialog::PreTranslateMessage(pMsg); +} + void CKeyboardLayout::InitKeyboardLayout() { m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX); m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline LoadScanCodeMap(m_HkeyType); - for (int i = 0; i < MAX_KEYBOARD_LAYOUT; ++i) { + for (int i = 0; i < MAX_KEYBOARD_LAYOUT; ++i) { if (!GetDlgItem(m_KeyboardLayouts[i].nBaseControlID) || !GetDlgItem(m_KeyboardLayouts[i].nCurrentControlID)) { continue; diff --git a/xkeymacs/keyboardlayout.h b/xkeymacs/keyboardlayout.h index 65ddcd0..dcbe947 100644 --- a/xkeymacs/keyboardlayout.h +++ b/xkeymacs/keyboardlayout.h @@ -42,8 +42,12 @@ private: int Prefix2ID(BYTE nPrefix); DWORD GetScanCodeLength(HKEY_TYPE hkeyType); BOOL ChangedKeyboardLayout(HKEY_TYPE hkeyType); + virtual BOOL PreTranslateMessage(MSG *pMsg); protected: HKEY_TYPE m_HkeyType; + virtual BOOL OnInitDialog(); + virtual void OnOK(); + afx_msg void OnDestroy(); void InitKeyboardLayout(); void CKeyboardLayout::DestroyKeyboardLayout(); BOOL GetScanCodeMap(HKEY_TYPE hkeyType, ScanCode original, ScanCode *current); @@ -52,6 +56,7 @@ protected: int LostKeyWarning(HKEY_TYPE hkeyType); void SaveScanCodeMap(HKEY_TYPE hkeyType); void LoadScanCodeMap(HKEY_TYPE hkeyType); + DECLARE_MESSAGE_MAP() public: CToolTipCtrl *ToolTip(); KeyboardLayout *GetKeyboardLayout(int nKey, BOOL bBase = FALSE); -- 2.11.0