OSDN Git Service

Make minor modifications to the code to handle key configurations.
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Thu, 19 Jan 2012 23:53:51 +0000 (08:53 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Thu, 19 Jan 2012 23:53:51 +0000 (08:53 +0900)
Remove ugly macros in xkeymacs.cpp.

xkeymacs/profile.cpp
xkeymacsdll/ipc.h
xkeymacsdll/xkeymacsdll.cpp
xkeymacsdll/xkeymacsdll.h

index 3b0e26c..05342dc 100644 (file)
@@ -269,7 +269,7 @@ void CProfile::SaveRegistry()
 void CProfile::SetDllData()\r
 {\r
        for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
-               _tcscpy_s(m_Config.FuncDef[nFuncID], CDotXkeymacs::GetFunctionDefinition(nFuncID));\r
+               _tcscpy_s(m_Config.FuncDefs[nFuncID], CDotXkeymacs::GetFunctionDefinition(nFuncID));\r
        for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
                AppConfig& appConfig = m_Config.AppConfig[nAppID];\r
                appConfig.CmdID[CONTROL]['X'] = 0; // C-x is unassigned.\r
index 3be1540..7873c3f 100644 (file)
@@ -18,7 +18,7 @@ struct AppConfig {
        TCHAR WindowText[WINDOW_TEXT_LENGTH];\r
        BYTE SettingStyle;\r
        BYTE CmdID[MAX_COMMAND_TYPE][MAX_KEY];\r
-       BYTE FuncID[MAX_COMMAND_TYPE][MAX_KEY];\r
+       char FuncID[MAX_COMMAND_TYPE][MAX_KEY];\r
        BYTE KillRingMax;\r
        bool Is326Compatible;\r
        bool EnableCUA;\r
@@ -29,7 +29,7 @@ struct AppConfig {
 \r
 struct Config {\r
        AppConfig AppConfig[MAX_APP];\r
-       TCHAR FuncDef[MAX_FUNCTION][MAX_DEFINITION];\r
+       TCHAR FuncDefs[MAX_FUNCTION][MAX_DEFINITION];\r
        bool Is106Keyboard;\r
 };\r
 \r
index fecf659..9641a83 100644 (file)
@@ -224,6 +224,8 @@ HCURSOR CXkeymacsDll::m_hCursor[MAX_STATUS] = {'\0'};
 #pragma data_seg()\r
 \r
 AppConfig* CXkeymacsDll::m_CurrentConfig = NULL;\r
+BYTE (*CXkeymacsDll::m_CmdID)[MAX_KEY];\r
+char (*CXkeymacsDll::m_FuncID)[MAX_KEY];\r
 HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;\r
 HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;\r
 HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;\r
@@ -467,6 +469,8 @@ void CXkeymacsDll::InitKeyboardProc(bool imeState)
                        !imeState && CUtils::IsDialog() && m_CurrentConfig->UseDialogSetting)\r
                // Use Dialog Setting\r
                m_CurrentConfig = GetAppConfig(_T("Dialog"), m_CurrentConfig);\r
+       m_CmdID = m_CurrentConfig->CmdID;\r
+       m_FuncID = m_CurrentConfig->FuncID;\r
 \r
        IconMsg msg[3] = {\r
                {CX_ICON, OFF_ICON, ""},\r
@@ -531,9 +535,6 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
                break;\r
        }\r
 \r
-#define fCommand(nType) (CmdTable::Command(m_CurrentConfig->CmdID[(nType)][nKey]))\r
-#define FuncID (m_CurrentConfig->FuncID[nType][nKey])\r
-\r
        if (bRelease) {\r
                switch (nOrigKey) {\r
                case VK_MENU:\r
@@ -549,7 +550,7 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
                case VK_RWIN:\r
                case VK_APPS:\r
                        for (int i = 0; i < MAX_COMMAND_TYPE; ++i) {\r
-                               int (*fCommand)() = fCommand(i);\r
+                               int (*fCommand)() = CmdTable::Command(m_CmdID[i][nKey]);\r
                                if (fCommand && !(nOrigKey == VK_MENU && fCommand == CCommands::MetaAlt))\r
                                        goto HOOK;\r
                        }\r
@@ -584,7 +585,7 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
        // set command type\r
        int nType = IsDown(VK_SHIFT) * SHIFT | IsControl() * CONTROL | IsMeta() * META | CCommands::bC_x() * CONTROLX;\r
        // Ignore undefined C-x ?\r
-       if (nType & CONTROLX && fCommand(nType) == NULL && FuncID < 0) {\r
+       if (nType & CONTROLX && m_CmdID[nType][nKey] == 0 && m_FuncID[nType][nKey] < 0) {\r
                if (m_CurrentConfig->IgnoreUndefC_x) {\r
                        CCommands::Reset(GOTO_HOOK);\r
                        goto HOOK;\r
@@ -593,7 +594,7 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
        }\r
        // Ignore undefined Meta Ctrl+?\r
        if (CCommands::bM_() && nType & CONTROL) {\r
-               if (fCommand(nType) == NULL && FuncID < 0) {\r
+               if (m_CmdID[nType][nKey] == 0 && m_FuncID[nType][nKey] < 0) {\r
                        if (m_CurrentConfig->IgnoreUndefMetaCtrl) {\r
                                if (CheckOriginal(CONTROL, nKey))\r
                                        goto DO_NOTHING;\r
@@ -612,7 +613,7 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
        if (CheckOriginal(nVirtualType, nOrigKey))\r
                goto DO_NOTHING;\r
 \r
-       int (*fCommand)() = fCommand(nType);\r
+       int (*fCommand)() = CmdTable::Command(m_CmdID[nType][nKey]);\r
        if (fCommand == CCommands::EnableOrDisableXKeymacs) {\r
                ToggleKeyboardHookState();\r
                goto HOOK;\r
@@ -696,13 +697,13 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
        }\r
 \r
 #define OneShotModifier(type, vk, mod) \\r
-       if (fCommand(nType & ~type) == CCommands::OneShotModifier ## mod || \\r
-                       fCommand(nType) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
+       if (CmdTable::Command(m_CmdID[nType & ~type][nKey]) == CCommands::OneShotModifier ## mod || \\r
+                       CmdTable::Command(m_CmdID[nType][nKey]) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
                nOneShotModifier[nKey] = vk; \\r
                DepressKey(vk); \\r
                bCherryOneShotModifier = TRUE; \\r
                goto HOOK; \\r
-       } else if (fCommand(nType & ~CONTROL) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
+       } else if (CmdTable::Command(m_CmdID[nType & ~CONTROL][nKey]) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
                ReleaseKey(vk); \\r
                bCherryOneShotModifier = FALSE; \\r
                Kdu(nKey); \\r
@@ -719,13 +720,12 @@ LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lPa
        if (i == MAX_KEY)\r
                bCherryOneShotModifier = FALSE;\r
 \r
-       if (0 <= FuncID && FuncID < MAX_FUNCTION && m_Config.FuncDef[FuncID][0]) {\r
-               CallFunction(FuncID);\r
+       int id = m_FuncID[nType][nKey];\r
+       if (0 <= id && id < MAX_FUNCTION && m_Config.FuncDefs[id][0]) {\r
+               CallFunction(id);\r
                CCommands::Reset(GOTO_HOOK);\r
                goto HOOK;\r
        }\r
-#undef fCommand\r
-#undef FuncID\r
 \r
        if (!fCommand) {\r
                if (nOrigKey == VK_CONTROL || nOrigKey == VK_MENU || nOrigKey == VK_SHIFT)\r
@@ -822,7 +822,7 @@ exit:
 int CXkeymacsDll::IsPassThrough(BYTE nKey)\r
 {\r
        BYTE bVk = 0;\r
-       const BYTE *pnID = m_CurrentConfig->CmdID[NONE]; \r
+       const BYTE *pnID = m_CmdID[NONE]; \r
        do {\r
                if (IsDown(bVk) && CmdTable::Command(pnID[bVk]) == CCommands::PassThrough) {\r
                        if (bVk == nKey)\r
@@ -1018,7 +1018,7 @@ BOOL CXkeymacsDll::IsMeta()
 BOOL CXkeymacsDll::IsDepressedModifier(int (__cdecl *Modifier)(void), BOOL bPhysicalKey)\r
 {\r
        BYTE bVk = 0;\r
-       const BYTE *pnID = m_CurrentConfig->CmdID[NONE];\r
+       const BYTE *pnID = m_CmdID[NONE];\r
        do {\r
                switch (bVk) {\r
                case VK_SHIFT:\r
@@ -1143,11 +1143,11 @@ void CXkeymacsDll::SetKbMacro(KbdMacro* kbdMacro)
 }\r
 \r
 // call an original command which is defined in dot.xkeymacs\r
-void CXkeymacsDll::CallFunction(int FuncID)\r
+void CXkeymacsDll::CallFunction(int id)\r
 {\r
-       if (FuncID < 0 || FuncID >= MAX_FUNCTION)\r
+       if (id < 0 || id >= MAX_FUNCTION)\r
                return;\r
-       LPCTSTR def = m_Config.FuncDef[FuncID];\r
+       LPCTSTR def = m_Config.FuncDefs[id];\r
        if (!def[0])\r
                return;\r
        std::vector<KeyBind> keybinds;\r
@@ -1185,7 +1185,7 @@ void CXkeymacsDll::CallFunction(int FuncID)
        for (std::vector<KeyBind>::const_iterator p = keybinds.begin(); p != keybinds.end(); ++p) {\r
                int nType = p->nType;\r
                BYTE bVk = p->bVk;\r
-               int (*fCommand)() = nType < MAX_COMMAND_TYPE ? CmdTable::Command(m_CurrentConfig->CmdID[nType][bVk]) : NULL;\r
+               int (*fCommand)() = nType < MAX_COMMAND_TYPE ? CmdTable::Command(m_CmdID[nType][bVk]) : NULL;\r
                if (fCommand) {\r
                        if (fCommand == CCommands::ExecuteExtendedCommand)\r
                                bM_x = TRUE;\r
index 6c2cdb0..7683328 100644 (file)
@@ -55,6 +55,8 @@ public:
 private:\r
        static Config m_Config;\r
        static AppConfig* m_CurrentConfig;\r
+       static BYTE (*m_CmdID)[MAX_KEY];\r
+       static char (*m_FuncID)[MAX_KEY];\r
        static HHOOK m_hHookCallWnd;\r
        static HHOOK m_hHookCallWndRet;\r
        static HHOOK m_hHookGetMessage;\r