//\r
\r
#include "stdafx.h"\r
-#include "xkeymacs.h"\r
#include "Key.h"\r
-#include "Profile.h"\r
-#include "104Keyboard.h"\r
-#include "109Keyboard.h"\r
+#include "keyboardlayout.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
\r
void CKey::DrawItem(const LPDRAWITEMSTRUCT lpDrawItemStruct) \r
{\r
- // TODO: Add your code to draw the specified item\r
static const COLORREF BLACK = RGB(0, 0, 0);\r
static const COLORREF RED = RGB(255, 0, 0);\r
static const COLORREF BLUE = RGB(0, 0, 255);\r
switch (m_nKeyType) {\r
case NORMAL_KEY:\r
SetKeyType(PUSHED_KEY);\r
- CProfile::SetDraggingCursor();\r
+ SetDraggingCursor();\r
break;\r
case REMAPPED_KEY:\r
SetKeyType(REMAPPED_PUSHED_KEY);\r
CButton::OnLButtonDown(nFlags, point);\r
}\r
\r
-void CKey::OnLButtonUp(const UINT nFlags, const CPoint point) \r
+void CKey::OnLButtonUp(const UINT nFlags, CPoint point) \r
{\r
if (m_nKeyType == PUSHED_KEY) {\r
SetKeyType(NORMAL_KEY);\r
}\r
\r
+ CKeyboardLayout *parent = reinterpret_cast<CKeyboardLayout *>(GetParent());\r
+ ClientToScreen(&point);\r
if (m_nKeyType == REMAPPED_PUSHED_KEY) {\r
- if (m_nKey == GetPointedKey(point)) {\r
- KeyboardLayout_t *pKeyboardLayout = CProfile::GetKeyboardLayouts(m_nKey);\r
+ if (m_nKey == parent->GetPointedKey(point)) {\r
+ KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nKey);\r
if (pKeyboardLayout) {\r
CString szWindowText;\r
- GetParent()->GetDlgItem(pKeyboardLayout->nBaseControlID)->GetWindowText(szWindowText);\r
+ parent->GetDlgItem(pKeyboardLayout->nBaseControlID)->GetWindowText(szWindowText);\r
SetWindowText(szWindowText);\r
\r
- if (CProfile::Is106Keyboard()) {\r
- ((C109Keyboard*)GetParent())->m_ToolTip.UpdateTipText(CProfile::GetToolTipID(pKeyboardLayout->nToolTipID), this);\r
- } else {\r
- ((C104Keyboard*)GetParent())->m_ToolTip.UpdateTipText(CProfile::GetToolTipID(pKeyboardLayout->nToolTipID), this);\r
- }\r
+ parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pKeyboardLayout->nToolTipID), this);\r
\r
- ScanCodeMapping_t ScanCodeMapping = {{0, 0}, {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefixedScanCode}};\r
- CProfile::SetScanCodeMap(m_HkeyType, ScanCodeMapping);\r
+ ScanCodeMapping mapping = {{0, 0}, {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}};\r
+ parent->SetScanCodeMap(m_HkeyType, mapping);\r
}\r
SetKeyType(ORIGINAL_KEY);\r
} else {\r
}\r
}\r
\r
- int nPointedKey = GetPointedKey(point);\r
+ int nPointedKey = parent->GetPointedKey(point);\r
if (m_nDroppableKey && nPointedKey) {\r
if (m_nDroppableKey != nPointedKey) {\r
- ((CKey*)GetParent()->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
+ reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
if (IsDroppableKey(nPointedKey)) {\r
m_nDroppableKey = nPointedKey;\r
} else {\r
}\r
\r
if (m_nDroppableKey) {\r
- KeyboardLayout_t *pKeyboardLayout = CProfile::GetKeyboardLayouts(m_nDroppableKey);\r
- KeyboardLayout_t *pBaseKeyboardLayout = CProfile::GetKeyboardLayouts(m_nKey);\r
+ KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nDroppableKey);\r
+ KeyboardLayout *pBaseKeyboardLayout = parent->GetKeyboardLayout(m_nKey);\r
if (pKeyboardLayout && pBaseKeyboardLayout) {\r
CString szWindowText;\r
GetWindowText(szWindowText);\r
- GetParent()->GetDlgItem(pKeyboardLayout->nCurrentControlID)->SetWindowText(szWindowText);\r
-\r
- if (CProfile::Is106Keyboard()) {\r
- ((C109Keyboard*)GetParent())->m_ToolTip.UpdateTipText(CProfile::GetToolTipID(pBaseKeyboardLayout->nToolTipID), GetParent()->GetDlgItem(pKeyboardLayout->nCurrentControlID));\r
- } else {\r
- ((C104Keyboard*)GetParent())->m_ToolTip.UpdateTipText(CProfile::GetToolTipID(pBaseKeyboardLayout->nToolTipID), GetParent()->GetDlgItem(pKeyboardLayout->nCurrentControlID));\r
- }\r
-\r
- ((CKey*)GetParent()->GetDlgItem(pKeyboardLayout->nBaseControlID))->SetKeyType(NORMAL_KEY);\r
- ((CKey*)GetParent()->GetDlgItem(pKeyboardLayout->nCurrentControlID))->SetKeyType(REMAPPED_KEY);\r
-\r
- ScanCodeMapping_t ScanCodeMapping = {{pBaseKeyboardLayout->scancode.nScanCode, pBaseKeyboardLayout->scancode.nPrefixedScanCode}, \r
- {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefixedScanCode}};\r
- CProfile::SetScanCodeMap(m_HkeyType, ScanCodeMapping);\r
+ parent->GetDlgItem(pKeyboardLayout->nCurrentControlID)->SetWindowText(szWindowText);\r
+ parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pBaseKeyboardLayout->nToolTipID), parent->GetDlgItem(pKeyboardLayout->nCurrentControlID));\r
+ reinterpret_cast<CKey *>(parent->GetDlgItem(pKeyboardLayout->nBaseControlID))->SetKeyType(NORMAL_KEY);\r
+ reinterpret_cast<CKey*>(parent->GetDlgItem(pKeyboardLayout->nCurrentControlID))->SetKeyType(REMAPPED_KEY);\r
+\r
+ ScanCodeMapping mapping = {{pBaseKeyboardLayout->scancode.nScanCode, pBaseKeyboardLayout->scancode.nPrefix}, \r
+ {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}};\r
+ parent->SetScanCodeMap(m_HkeyType, mapping);\r
}\r
}\r
}\r
m_nDroppableKey = 0;\r
m_nDroppableKeyType = NORMAL_KEY;\r
\r
- CProfile::SetNormalCursor();\r
+ SetNormalCursor();\r
\r
CButton::OnLButtonUp(nFlags, point);\r
}\r
\r
-int CKey::GetPointedKey(const CPoint point)\r
-{\r
- for (int i = 0; i < sizeof(KeyboardLayouts) / sizeof(KeyboardLayouts[0]); ++i) {\r
- if (!GetParent()->GetDlgItem(KeyboardLayouts[i].nBaseControlID)\r
- || !GetParent()->GetDlgItem(KeyboardLayouts[i].nCurrentControlID)) {\r
- continue;\r
- }\r
-\r
- CRect rButton;\r
- GetParent()->GetDlgItem(KeyboardLayouts[i].nBaseControlID)->GetWindowRect(&rButton);\r
- ScreenToClient(&rButton);\r
- if (rButton.PtInRect(point)) {\r
- return KeyboardLayouts[i].nBaseControlID;\r
- }\r
- GetParent()->GetDlgItem(KeyboardLayouts[i].nCurrentControlID)->GetWindowRect(&rButton);\r
- ScreenToClient(&rButton);\r
- if (rButton.PtInRect(point)) {\r
- return KeyboardLayouts[i].nCurrentControlID;\r
- }\r
- }\r
- return 0;\r
-}\r
-\r
-void CKey::OnMouseMove(const UINT nFlags, const CPoint point) \r
+void CKey::OnMouseMove(const UINT nFlags, CPoint point) \r
{\r
if (nFlags & MK_LBUTTON) {\r
+ ClientToScreen(&point);\r
+ CKeyboardLayout *parent = (CKeyboardLayout *)GetParent();\r
if (m_nKeyType == PUSHED_KEY) {\r
- int nPointedKey = GetPointedKey(point);\r
+ int nPointedKey = parent->GetPointedKey(point);\r
if (nPointedKey) {\r
if (nPointedKey != m_nDroppableKey) {\r
if (m_nDroppableKey) {\r
- ((CKey*)GetParent()->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
- CProfile::SetNoCursor();\r
+ reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
+ SetNoCursor();\r
}\r
if (IsDroppableKey(nPointedKey)) {\r
m_nDroppableKey = nPointedKey;\r
- m_nDroppableKeyType = ((CKey*)GetParent()->GetDlgItem(m_nDroppableKey))->GetKeyType();\r
- ((CKey*)GetParent()->GetDlgItem(m_nDroppableKey))->SetKeyType(DROPPABLE_KEY);\r
- CProfile::SetDraggingCursor();\r
+ m_nDroppableKeyType = ((CKey*)parent->GetDlgItem(m_nDroppableKey))->GetKeyType();\r
+ reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(DROPPABLE_KEY);\r
+ SetDraggingCursor();\r
}\r
}\r
} else {\r
if (m_nDroppableKey) {\r
- ((CKey*)GetParent()->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
+ reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);\r
m_nDroppableKey = 0;\r
m_nDroppableKeyType = NORMAL_KEY;\r
- CProfile::SetNoCursor();\r
+ SetNoCursor();\r
}\r
}\r
}\r
\r
if (m_nKeyType == REMAPPED_PUSHED_KEY) {\r
- if (m_nKey != GetPointedKey(point)) {\r
+ if (m_nKey != parent->GetPointedKey(point)) {\r
SetKeyType(REMAPPED_KEY);\r
}\r
}\r
if (m_nKeyType == REMAPPED_KEY) {\r
- if (m_nKey == GetPointedKey(point)) {\r
+ if (m_nKey == parent->GetPointedKey(point)) {\r
SetKeyType(REMAPPED_PUSHED_KEY);\r
}\r
}\r
return FALSE;\r
}\r
\r
- for (int i = 0; i < sizeof(KeyboardLayouts) / sizeof(KeyboardLayouts[0]); ++i) {\r
- if (KeyboardLayouts[i].nBaseControlID != m_nKey) {\r
- continue;\r
- }\r
-\r
- if (KeyboardLayouts[i].nBaseControlID == nKey\r
- || KeyboardLayouts[i].nCurrentControlID == nKey) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
+ KeyboardLayout *pKeyboardLayout = reinterpret_cast<CKeyboardLayout *>(GetParent())->GetKeyboardLayout(m_nKey, TRUE);\r
+ if (!pKeyboardLayout\r
+ || pKeyboardLayout->nBaseControlID == nKey\r
+ || pKeyboardLayout->nCurrentControlID == nKey) {\r
+ return FALSE;\r
}\r
- return FALSE;\r
+ return TRUE;\r
+}\r
+\r
+void CKey::SetDraggingCursor()\r
+{\r
+ HCURSOR hCursor = (HCURSOR)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDC_DRAG_CURSOR),\r
+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
+ ::SetCursor(hCursor);\r
+}\r
+\r
+void CKey::SetNormalCursor()\r
+{\r
+ HCURSOR hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),\r
+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
+ ::SetCursor(hCursor);\r
+}\r
+\r
+void CKey::SetNoCursor()\r
+{\r
+ HCURSOR hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_NO),\r
+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
+ ::SetCursor(hCursor);\r
}\r