OSDN Git Service

Change CopyData to CopyDefault with one argument, and rewrite
[xkeymacs/xkeymacs.git] / xkeymacs / profile.cpp
index 404ca2a..ab168bb 100644 (file)
@@ -20,7 +20,7 @@ static char THIS_FILE[]=__FILE__;
 \r
 Config CProfile::m_Config;\r
 KeyString CProfile::m_KeyString(CProfile::Is106Keyboard() != FALSE);\r
-TCHAR CProfile::m_szAppTitle[MAX_APP][WINDOW_TEXT_LENGTH];\r
+TCHAR CProfile::m_AppTitle[MAX_APP][WINDOW_TEXT_LENGTH];\r
 TASK_LIST CProfile::m_TaskList[MAX_TASKS];\r
 DWORD CProfile::m_dwTasks;\r
 \r
@@ -122,13 +122,13 @@ void CProfile::LevelUp()
        AfxGetApp()->WriteProfileInt(_T(""), _T("Level"), 4);\r
 }\r
 \r
-void CProfile::AddKeyBind2C_(LPCSTR szAppName, BYTE bVk)\r
+void CProfile::AddKeyBind2C_(LPCTSTR appName, BYTE bVk)\r
 {\r
        int nComID;\r
        for (nComID = 0; nComID < MAX_COMMAND; ++nComID)\r
                if (Commands[nComID].fCommand == CCommands::C_)\r
                        break;\r
-       SaveKeyBind(szAppName, nComID, NONE, bVk);\r
+       SaveKeyBind(appName, nComID, NONE, bVk);\r
 }\r
 \r
 void CProfile::LoadRegistry()\r
@@ -151,7 +151,7 @@ void CProfile::LoadRegistry()
                        bDialog = true;\r
                _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE);\r
                entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
-               _tcsncpy_s(m_szAppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE);\r
+               _tcsncpy_s(m_AppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE);\r
                entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
                _tcsncpy_s(m_Config.szWindowText[nAppID], AfxGetApp()->GetProfileString(appName, entry, _T("*")), _TRUNCATE);\r
 \r
@@ -219,50 +219,50 @@ void CProfile::SaveRegistry()
 {\r
        const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));    \r
        for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
-               LPCTSTR szAppName = m_Config.szSpecialApp[nAppID];\r
+               LPCTSTR appName = m_Config.szSpecialApp[nAppID];\r
                CString entry;\r
                entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);\r
-               if (!szAppName[0]) {\r
+               if (!appName[0]) {\r
                        if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty())\r
                                AfxGetApp()->WriteProfileString(section, entry, _T(""));\r
                        continue;\r
                }\r
-               AfxGetApp()->WriteProfileString(section, entry, szAppName);\r
+               AfxGetApp()->WriteProfileString(section, entry, appName);\r
 \r
                entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);\r
-               CString appTitle = m_szAppTitle[nAppID];\r
+               CString appTitle = m_AppTitle[nAppID];\r
                appTitle.TrimLeft(_T(' '));\r
-               AfxGetApp()->WriteProfileString(szAppName, entry, appTitle);\r
+               AfxGetApp()->WriteProfileString(appName, entry, appTitle);\r
                entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);\r
-               AfxGetApp()->WriteProfileString(szAppName, entry, m_Config.szWindowText[nAppID]);\r
+               AfxGetApp()->WriteProfileString(appName, entry, m_Config.szWindowText[nAppID]);\r
 \r
                // Create all commands\r
                for (int nComID = 1; nComID < MAX_COMMAND; ++nComID)\r
-                       SaveKeyBind(szAppName, nComID, 0, 0);\r
+                       SaveKeyBind(appName, nComID, 0, 0);\r
                for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)\r
                        for (int nKey = 0; nKey < MAX_KEY; ++nKey)\r
-                               SaveKeyBind(szAppName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey);\r
+                               SaveKeyBind(appName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey);\r
                for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)\r
                        for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {\r
                                int nType, nKey;\r
                                CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);\r
-                               SaveKeyBind(szAppName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
+                               SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);\r
                        }\r
 \r
                entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nKillRingMax[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nKillRingMax[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bUseDialogSetting[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bUseDialogSetting[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE);\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]);\r
                entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]);\r
                entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bEnableCUA[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bEnableCUA[nAppID]);\r
                entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);\r
-               AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.b326Compatible[nAppID]);\r
+               AfxGetApp()->WriteProfileInt(appName, entry, m_Config.b326Compatible[nAppID]);\r
        }\r
 }\r
 \r
@@ -335,14 +335,14 @@ void CProfile::InitAppList(CProperties& cProperties)
        EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&cProperties));\r
 \r
        for (int i = 0; i < MAX_APP; ++i) {\r
-               LPCTSTR szAppName = m_Config.szSpecialApp[i];\r
-               LPCTSTR szAppTitle = m_szAppTitle[i];\r
-               if (!szAppName[0] || !_tcscmp(szAppName, _T("IME")))\r
+               LPCTSTR appName = m_Config.szSpecialApp[i];\r
+               LPCTSTR appTitle = m_AppTitle[i];\r
+               if (!appName[0] || !_tcscmp(appName, _T("IME")))\r
                        continue;\r
-               if (CString(MAKEINTRESOURCE(IDS_DEFAULT)) == szAppName ||\r
-                               CString(MAKEINTRESOURCE(IDS_DIALOG)) == szAppName)\r
+               if (CString(MAKEINTRESOURCE(IDS_DEFAULT)) == appName ||\r
+                               CString(MAKEINTRESOURCE(IDS_DIALOG)) == appName)\r
                        continue;\r
-               cProperties.AddItem(szAppTitle, szAppName);\r
+               cProperties.AddItem(appTitle, appName);\r
        }\r
        AddIMEInfo(cProperties);\r
 }\r
@@ -459,25 +459,24 @@ void CProfile::AddIMEInfo(CProperties& cProperties)
                cProperties.AddItem(p->szDescription, p->szFileName);\r
 }\r
 \r
-void CProfile::ClearData(const CString szCurrentApplication)\r
+void CProfile::ClearData(LPCTSTR appName)\r
 {\r
-       for (int nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-               if (szCurrentApplication == m_Config.szSpecialApp[nAppID]) {\r
-                       ZeroMemory(m_Config.nCommandID[nAppID], sizeof(m_Config.nCommandID[nAppID]));\r
-                       ZeroMemory(m_Config.szSpecialApp[nAppID], CLASS_NAME_LENGTH);\r
-                       return;\r
-               }\r
+       int n = GetAppID(appName);\r
+       if (n == MAX_APP)\r
+               return;\r
+       ZeroMemory(m_Config.nCommandID[n], sizeof(m_Config.nCommandID[n]));\r
+       ZeroMemory(m_Config.szSpecialApp[n], CLASS_NAME_LENGTH);\r
 }\r
 \r
-void CProfile::CopyData(const CString szDstApp, const CString szSrcApp)\r
+void CProfile::CopyDefault(LPCTSTR appName)\r
 {\r
-       int nDstApp = AssignAppID(szDstApp);\r
-       int nSrcApp = GetAppID(szSrcApp);\r
-       if (nDstApp == MAX_APP || nSrcApp == MAX_APP)\r
+       int dst = AssignAppID(appName);\r
+       int src = DefaultAppID();\r
+       if (src == MAX_APP || dst == MAX_APP)\r
                return;\r
-       SetSettingStyle(nDstApp, SETTING_SPECIFIC);\r
+       SetSettingStyle(dst, SETTING_SPECIFIC);\r
 \r
-#define CopyMember(member) CopyMemory(&m_Config. ## member ## [nDstApp], &m_Config. ## member ## [nSrcApp], sizeof(m_Config. ## member ## [nSrcApp]))\r
+#define CopyMember(member) CopyMemory(&m_Config. ## member ## [dst], &m_Config. ## member ## [src], sizeof(m_Config. ## member ## [src]))\r
        CopyMember(b326Compatible);\r
        CopyMember(nFunctionID);\r
        CopyMember(bEnableCUA);\r
@@ -489,14 +488,14 @@ void CProfile::CopyData(const CString szDstApp, const CString szSrcApp)
 #undef CopyMember\r
 }\r
 \r
-int CProfile::AssignAppID(LPCSTR szAppName)\r
+int CProfile::AssignAppID(LPCTSTR appName)\r
 {\r
-       int nAppID = GetAppID(szAppName);\r
+       int nAppID = GetAppID(appName);\r
        if (nAppID != MAX_APP)\r
                return nAppID;\r
        for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
                if (!m_Config.szSpecialApp[nAppID][0]) {\r
-                       _tcsncpy_s(m_Config.szSpecialApp[nAppID], szAppName, _TRUNCATE);\r
+                       _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE);\r
                        return nAppID;\r
                }\r
        return nAppID;\r
@@ -511,11 +510,11 @@ int CProfile::DefaultAppID()
        return MAX_APP;\r
 }\r
 \r
-int CProfile::GetAppID(LPCSTR szAppName)\r
+int CProfile::GetAppID(LPCTSTR appName)\r
 {\r
        int nAppID = 0;\r
        for (nAppID = 0; nAppID < MAX_APP; ++nAppID)\r
-               if (!_tcscmp(szAppName, m_Config.szSpecialApp[nAppID]))\r
+               if (!_tcscmp(appName, m_Config.szSpecialApp[nAppID]))\r
                        break;\r
        return nAppID;\r
 }\r
@@ -536,7 +535,7 @@ void CProfile::SetSettingStyle(int nAppID, int nSettingStyle)
 \r
 void CProfile::SetAppTitle(int nAppID, const CString& appTitle)\r
 {\r
-       _tcsncpy_s(m_szAppTitle[nAppID], appTitle, _TRUNCATE);\r
+       _tcsncpy_s(m_AppTitle[nAppID], appTitle, _TRUNCATE);\r
 }\r
 \r
 int CProfile::GetCommandID(int nAppID, int nType, int nKey)\r
@@ -590,17 +589,15 @@ void CProfile::SetKillRingMax(int nAppID, int nKillRingMax)
        m_Config.nKillRingMax[nAppID] = static_cast<BYTE>(nKillRingMax > 255 ? 255 : nKillRingMax);\r
 }\r
 \r
-CString CProfile::GetWindowText(int nAppID)\r
+LPCTSTR CProfile::GetWindowText(int nAppID)\r
 {\r
        return m_Config.szWindowText[nAppID];\r
 }\r
 \r
-void CProfile::SetWindowText(int nAppID, const CString szWindowText)\r
+void CProfile::SetWindowText(int nAppID, const CString& text)\r
 {\r
-       if (CUtils::GetWindowTextType(szWindowText) == IDS_WINDOW_TEXT_IGNORE)\r
-               _tcscpy_s(m_Config.szWindowText[nAppID], _T("*"));\r
-       else\r
-               _tcsncpy_s(m_Config.szWindowText[nAppID], szWindowText, _TRUNCATE);\r
+       _tcsncpy_s(m_Config.szWindowText[nAppID],\r
+               CUtils::GetWindowTextType(text) == IDS_WINDOW_TEXT_IGNORE ? _T("*") : text, _TRUNCATE);\r
 }\r
 \r
 BOOL CProfile::Is106Keyboard()\r