From 09a9ae87b694041592caa771c01e7ef86fee128b Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Thu, 7 Jul 2011 18:49:40 +0900 Subject: [PATCH] Remove CData. The application manages settings with struct CONFIG and sets the settings to the DLL by copying it. --- xkeymacs/data.cpp | 140 ----------------- xkeymacs/data.h | 51 ------ xkeymacs/mainfrm.cpp | 2 - xkeymacs/profile.cpp | 280 +++++++++++++-------------------- xkeymacs/profile.h | 4 +- xkeymacs/xkeymacs-vc10.vcxproj | 5 - xkeymacs/xkeymacs-vc10.vcxproj.filters | 6 - xkeymacsdll/xkeymacsdll.cpp | 88 +---------- xkeymacsdll/xkeymacsdll.h | 15 +- 9 files changed, 119 insertions(+), 472 deletions(-) delete mode 100644 xkeymacs/data.cpp delete mode 100644 xkeymacs/data.h diff --git a/xkeymacs/data.cpp b/xkeymacs/data.cpp deleted file mode 100644 index 0e1eb1d..0000000 --- a/xkeymacs/data.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "stdafx.h" -#include "data.h" - -CData::CData() -{ - ClearAll(); -} - -CData::~CData() -{ -} - -void CData::SetWindowText(LPCTSTR lpszWindowText) -{ - m_nWindowTextType = CUtils::GetWindowTextType(lpszWindowText); - if (m_nWindowTextType == IDS_WINDOW_TEXT_IGNORE) { - m_strWindowText = _T('*'); - } else { - m_strWindowText.Format(lpszWindowText); - } -} - -CString CData::GetWindowText() -{ - return m_strWindowText; -} - -void CData::SetApplicationName(LPCTSTR lpszApplicationName) -{ - m_strApplicationName.Format(lpszApplicationName); -} - -CString CData::GetApplicationName() -{ - return m_strApplicationName; -} - -void CData::SetCommandID(int nType, int nKey, int nComID) -{ - ASSERT(nType >= 0 || nType < MAX_COMMAND_TYPE); - ASSERT(nKey <= 0 || nKey < MAX_KEY); - m_nCommandID[nType][nKey] = nComID; -} - -int CData::GetCommandID(int nType, int nKey) -{ - ASSERT(nType >= 0 || nType < MAX_COMMAND_TYPE); - ASSERT(nKey <= 0 || nKey < MAX_KEY); - return m_nCommandID[nType][nKey]; -} - -void CData::ClearAll() -{ - ZeroMemory(m_nCommandID, sizeof(m_nCommandID)); - m_strApplicationName.Empty(); -} - -void CData::SetApplicationTitle(LPCTSTR lpszApplicationTitle) -{ - m_strApplicationTitle.Format(lpszApplicationTitle); - // delete white space at the end of the application title. - while (!m_strApplicationTitle.IsEmpty() && - _istspace(m_strApplicationTitle.GetAt(m_strApplicationTitle.GetLength() - 1))) - m_strApplicationTitle.Delete(m_strApplicationTitle.GetLength() - 1); -} - -CString CData::GetApplicationTitle() -{ - return m_strApplicationTitle; -} - -void CData::SetKillRingMax(int nKillRingMax) -{ - m_nKillRingMax = nKillRingMax; -} - -int CData::GetKillRingMax() -{ - return m_nKillRingMax; -} - -int CData::GetSettingStyle() -{ - return m_nSettingStyle; -} - -void CData::SetSettingStyle(int nSettingStyle) -{ - m_nSettingStyle = nSettingStyle; -} - -void CData::SetIgnoreUndefinedMetaCtrl(BOOL bIgnoreUndefinedMetaCtrl) -{ - m_bIgnoreUndefinedMetaCtrl = bIgnoreUndefinedMetaCtrl; -} - -BOOL CData::GetIgnoreUndefinedMetaCtrl() -{ - return m_bIgnoreUndefinedMetaCtrl; -} - -void CData::SetIgnoreUndefinedC_x(BOOL bIgnoreUndefinedC_x) -{ - m_bIgnoreUndefinedC_x = bIgnoreUndefinedC_x; -} - -BOOL CData::GetIgnoreUndefinedC_x() -{ - return m_bIgnoreUndefinedC_x; -} - -void CData::SetEnableCUA(BOOL bEnableCUA) -{ - m_bEnableCUA = bEnableCUA; -} - -BOOL CData::GetEnableCUA() -{ - return m_bEnableCUA; -} - -void CData::SetUseDialogSetting(BOOL bUseDialogSetting) -{ - m_bUseDialogSetting = bUseDialogSetting; -} - -BOOL CData::GetUseDialogSetting() -{ - return m_bUseDialogSetting; -} - -BOOL CData::Get326Compatible() -{ - return m_b326Compatible; -} - -void CData::Set326Compatible(BOOL b326Compatible) -{ - m_b326Compatible = b326Compatible; -} diff --git a/xkeymacs/data.h b/xkeymacs/data.h deleted file mode 100644 index c0e0682..0000000 --- a/xkeymacs/data.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef DATA_H_INCLUDED -#define DATA_H_INCLUDED - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -class CData -{ -public: - void ClearAll(); - void Set326Compatible(BOOL b326Compatible); - BOOL Get326Compatible(); - CString GetWindowText(); - void SetWindowText(LPCTSTR lpszWindowText); - void SetUseDialogSetting(BOOL bUseDialogSetting); - BOOL GetUseDialogSetting(); - BOOL GetEnableCUA(); - void SetEnableCUA(BOOL bEnableCUA); - BOOL GetIgnoreUndefinedC_x(); - void SetIgnoreUndefinedC_x(BOOL bIgnoreUndefinedC_x); - BOOL GetIgnoreUndefinedMetaCtrl(); - void SetIgnoreUndefinedMetaCtrl(BOOL bIgnoreUndefinedMetaCtrl); - void SetSettingStyle(int nSettingStyle); - int GetSettingStyle(); - void SetKillRingMax(int nKillRingMax); - int GetKillRingMax(); - CString GetApplicationTitle(); - void SetApplicationTitle(LPCTSTR lpszApplicationTitle); - int GetCommandID(int nType, int nKey); - void SetCommandID(int nType, int nKey, int nComID); - CString GetApplicationName(); - void SetApplicationName(LPCTSTR lpszApplicationName); - CData(); - virtual ~CData(); -private: - BOOL m_b326Compatible; - int m_nWindowTextType; - CString m_strWindowText; - BOOL m_bEnableCUA; - BOOL m_bUseDialogSetting; - BOOL m_bIgnoreUndefinedC_x; - BOOL m_bIgnoreUndefinedMetaCtrl; - int m_nSettingStyle; - int m_nKillRingMax; - CString m_strApplicationTitle; - CString m_strApplicationName; - int m_nCommandID[MAX_COMMAND_TYPE][MAX_KEY]; -}; - -#endif // DATA_H_INCLUDED diff --git a/xkeymacs/mainfrm.cpp b/xkeymacs/mainfrm.cpp index 4fc0ae2..092c062 100644 --- a/xkeymacs/mainfrm.cpp +++ b/xkeymacs/mainfrm.cpp @@ -111,8 +111,6 @@ int CMainFrame::OnCreate(const LPCREATESTRUCT lpCreateStruct) return -1; } - CXkeymacsDll::Set106Keyboard(CProfile::Is106Keyboard()); - // init notify icon data NOTIFYICONDATA notifyIconData[MAX_ICON_TYPE] = { { sizeof(NOTIFYICONDATA), m_hWnd, MAIN_ICON, NIF_MESSAGE | NIF_ICON | NIF_TIP, WM_USER_NTFYICON, diff --git a/xkeymacs/profile.cpp b/xkeymacs/profile.cpp index d48d2a9..5564f6d 100644 --- a/xkeymacs/profile.cpp +++ b/xkeymacs/profile.cpp @@ -305,7 +305,8 @@ static const KeyName KeyNames[] = { {0xff, _T("Fn")}, }; -CData CProfile::m_Data[MAX_APP]; +CONFIG CProfile::m_Config; +TCHAR CProfile::m_szAppTitle[MAX_APP][WINDOW_TEXT_LENGTH]; TASK_LIST CProfile::m_TaskList[MAX_TASKS]; DWORD CProfile::m_dwTasks; @@ -494,27 +495,25 @@ void CProfile::LoadRegistry() appName.LoadString(IDS_DEFAULT); } else if (appName == CString(MAKEINTRESOURCE(IDS_DIALOG))) bDialog = true; - m_Data[nAppID].SetApplicationName(appName); - + _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE); entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE); - m_Data[nAppID].SetApplicationTitle(AfxGetApp()->GetProfileString(appName, entry)); + _tcsncpy_s(m_szAppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE); entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT); - m_Data[nAppID].SetWindowText(AfxGetApp()->GetProfileString(appName, entry, _T("*"))); - entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE); + _tcsncpy_s(m_Config.szWindowText[nAppID], AfxGetApp()->GetProfileString(appName, entry, _T("*")), _TRUNCATE); CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)); regApp += _T("\\") + appName; for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) { entry = CCommands::GetCommandName(nComID); HKEY hKey; - const CString& regKey = regApp + _T("\\") + entry; + const CString regKey = regApp + _T("\\") + entry; if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { TCHAR szKeyBind[128]; DWORD dwKeyBind = _countof(szKeyBind); for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) { int nType, nKey; ReadKeyBind(&nType, &nKey, szKeyBind); - m_Data[nAppID].SetCommandID(nType, nKey, nComID); + m_Config.nCommandID[nAppID][nType][nKey] = nComID; dwKeyBind = _countof(szKeyBind); } RegCloseKey(hKey); @@ -524,7 +523,7 @@ void CProfile::LoadRegistry() if (CCommands::GetDefaultControlID(nComID, i) == IDC_CO2) continue; const int nType = CCommands::GetDefaultCommandType(nComID, i); - m_Data[nAppID].SetCommandID(nType, nKey, nComID); + m_Config.nCommandID[nAppID][nType][nKey] = nComID; } } } @@ -546,19 +545,19 @@ void CProfile::LoadRegistry() } entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX); - m_Data[nAppID].SetKillRingMax(AfxGetApp()->GetProfileInt(appName, entry, 1)); + m_Config.nKillRingMax[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1); entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING); - m_Data[nAppID].SetUseDialogSetting(AfxGetApp()->GetProfileInt(appName, entry, 1)); + m_Config.bUseDialogSetting[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1); entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS); - m_Data[nAppID].SetSettingStyle(AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC); + m_Config.nSettingStyle[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC; entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL); - m_Data[nAppID].SetIgnoreUndefinedMetaCtrl(AfxGetApp()->GetProfileInt(appName, entry, 0)); + m_Config.bIgnoreUndefinedMetaCtrl[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0); entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X); - m_Data[nAppID].SetIgnoreUndefinedC_x(AfxGetApp()->GetProfileInt(appName, entry, 0)); + m_Config.bIgnoreUndefinedC_x[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0); entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA); - m_Data[nAppID].SetEnableCUA(AfxGetApp()->GetProfileInt(appName, entry, 0)); + m_Config.bEnableCUA[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0); entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE); - m_Data[nAppID].Set326Compatible(AfxGetApp()->GetProfileInt(appName, entry, 0)); + m_Config.b326Compatible[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0); } } @@ -566,10 +565,10 @@ void CProfile::SaveRegistry() { const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)); for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) { - const CString& appName = m_Data[nAppID].GetApplicationName(); + const LPCTSTR appName = m_Config.szSpecialApp[nAppID]; CString entry; entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID); - if (appName.IsEmpty()) { + if (!appName[0]) { if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty()) AfxGetApp()->WriteProfileString(section, entry, _T("")); continue; @@ -577,20 +576,19 @@ void CProfile::SaveRegistry() AfxGetApp()->WriteProfileString(section, entry, appName); entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE); - CString appTitle = m_Data[nAppID].GetApplicationTitle(); + CString appTitle = m_szAppTitle[nAppID]; appTitle.TrimLeft(_T(' ')); AfxGetApp()->WriteProfileString(appName, entry, appTitle); entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT); - AfxGetApp()->WriteProfileString(appName, entry, m_Data[nAppID].GetWindowText()); + AfxGetApp()->WriteProfileString(appName, entry, m_Config.szWindowText[nAppID]); - CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)); - regApp += _T("\\") + appName; + const CString regApp = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName; // Create all commands for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) SaveCommand(appName, nComID); for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) for (int nKey = 0; nKey < MAX_KEY; ++nKey) - SaveKeyBind(appName, m_Data[nAppID].GetCommandID(nType, nKey), nType, nKey); + SaveKeyBind(appName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey); for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) { int nType, nKey; @@ -599,19 +597,19 @@ void CProfile::SaveRegistry() } entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetKillRingMax()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nKillRingMax[nAppID]); entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetUseDialogSetting()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bUseDialogSetting[nAppID]); entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetSettingStyle() == SETTING_DISABLE); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE); entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedMetaCtrl()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]); entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedC_x()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]); entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetEnableCUA()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.bEnableCUA[nAppID]); entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE); - AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].Get326Compatible()); + AfxGetApp()->WriteProfileInt(appName, entry, m_Config.b326Compatible[nAppID]); } } @@ -631,54 +629,27 @@ void CProfile::SaveData() void CProfile::SetDllData() { - CXkeymacsDll::ClearFunctionDefinition(); - for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) { - CXkeymacsDll::SetFunctionDefinition(nFuncID, CDotXkeymacs::GetFunctionDefinition(nFuncID)); - } + memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID)); + for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) + _tcscpy_s(m_Config.szFunctionDefinition[nFuncID], CDotXkeymacs::GetFunctionDefinition(nFuncID)); for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) { - - CString szApplicationName = m_Data[nAppID].GetApplicationName(); - - if (szApplicationName.IsEmpty()) { - CXkeymacsDll::Clear(nAppID); - continue; - } - - CXkeymacsDll::SetApplicationName(nAppID, szApplicationName); - CXkeymacsDll::SetWindowText(nAppID, m_Data[nAppID].GetWindowText()); - CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 0); - - for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) { - for (int nKey = 0; nKey < MAX_KEY; ++nKey) { - const int nComID = m_Data[nAppID].GetCommandID(nType, nKey); - CXkeymacsDll::SetCommandID(nAppID, nType, nKey, nComID); - if ((nType & CONTROLX) && nComID) { - CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 1); // Commands[1] is C-x - } - } - } - - for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) { + m_Config.nCommandID[nAppID][CONTROL]['X'] = 0; // C-x is unassigned. + for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) + for (int nKey = 0; nKey < MAX_KEY; ++nKey) + if ((nType & CONTROLX) && m_Config.nCommandID[nAppID][nType][nKey]) + m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available. + for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) { - int nType = 0; - int nKey = 0; + int nType, nKey; CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey); - CXkeymacsDll::SetFunctionKey(nFuncID, nAppID, nType, nKey); - if (nType & CONTROLX) { - CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 1); // Commands[1] is C-x - } + m_Config.nFunctionID[nAppID][nType][nKey] = nFuncID; + if (nType & CONTROLX) + m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available. } - } - - CXkeymacsDll::SetKillRingMax(nAppID, m_Data[nAppID].GetKillRingMax()); - CXkeymacsDll::SetUseDialogSetting(nAppID, m_Data[nAppID].GetUseDialogSetting()); - CXkeymacsDll::SetSettingStyle(nAppID, m_Data[nAppID].GetSettingStyle()); - CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(nAppID, m_Data[nAppID].GetIgnoreUndefinedMetaCtrl()); - CXkeymacsDll::SetIgnoreUndefinedC_x(nAppID, m_Data[nAppID].GetIgnoreUndefinedC_x()); - CXkeymacsDll::SetEnableCUA(nAppID, m_Data[nAppID].GetEnableCUA()); - CXkeymacsDll::Set326Compatible(nAppID, m_Data[nAppID].Get326Compatible()); } + m_Config.b106Keyboard = Is106Keyboard(); + CXkeymacsDll::SetConfig(m_Config); CXkeymacsApp *pApp = static_cast(AfxGetApp()); if (!pApp->IsWow64()) return; @@ -938,30 +909,21 @@ void CProfile::InitDllData() void CProfile::ClearData(const CString szCurrentApplication) { - int nAppID; - for (nAppID = 0; nAppID < MAX_APP; ++nAppID) { - if (m_Data[nAppID].GetApplicationName() == szCurrentApplication) { - break; + for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) + if (szCurrentApplication == m_Config.szSpecialApp[nAppID]) { + ZeroMemory(m_Config.nCommandID[nAppID], sizeof(m_Config.nCommandID[nAppID])); + ZeroMemory(m_Config.szSpecialApp[nAppID], CLASS_NAME_LENGTH); + return; } - } - if (nAppID < MAX_APP) { - m_Data[nAppID].ClearAll(); - } } // return count of saved settings int CProfile::GetSavedSettingCount() { int nSavedSetting = 0; - - for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) { - CString szApplicationName; - szApplicationName = m_Data[nAppID].GetApplicationName(); - if (!szApplicationName.IsEmpty()) { + for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) + if (m_Config.szSpecialApp[nAppID][0]) ++nSavedSetting; - } - } - return nSavedSetting; } @@ -975,17 +937,14 @@ void CProfile::InitApplicationList(CComboBox *const cApplicationList) CString szListItem; for (int i = 0; i < MAX_APP; ++i) { - CString szApplicationName = m_Data[i].GetApplicationName(); - CString szApplicationTitle = m_Data[i].GetApplicationTitle(); - if (szApplicationName == _T("IME")) // IDS_IME_FILE_NAME + const LPCTSTR szAppName = m_Config.szSpecialApp[i]; + const LPCTSTR szAppTitle = m_szAppTitle[i]; + if (!szAppName[0] || !_tcscmp(szAppName, _T("IME"))) continue; - szListItem.Format(IDS_APPLICATION_LIST_ITEM, szApplicationTitle, szApplicationName); - if (IsNotSameString(cApplicationList, szListItem) - && !IsDefault(szApplicationName) - && !IsDialog(szApplicationName) - && !szApplicationName.IsEmpty()) { + szListItem.Format(IDS_APPLICATION_LIST_ITEM, szAppTitle, szAppName); + if (IsNotSameString(cApplicationList, szListItem) && + !IsDefault(szAppName) && !IsDialog(szAppName)) cApplicationList->AddString(szListItem); - } } AddIMEInfo(cApplicationList); @@ -1042,45 +1001,34 @@ void CProfile::GetTaskList() // if there is NOT the application in the data, this function takes care of it. int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bSaveAndValidate, int *const nSettingStyle) { - if (!bSaveAndValidate) { // SetDialogData + if (!bSaveAndValidate) // SetDialogData *nSettingStyle = SETTING_UNDEFINED; - } - int nAppID = GetApplicationIndex(szApplicationName); - if (nAppID == MAX_APP) { - if (bSaveAndValidate) { // GetDialogData - for (nAppID = 0; nAppID < MAX_APP; ++nAppID) { - CString sz = m_Data[nAppID].GetApplicationName(); - if (sz.IsEmpty()) { - m_Data[nAppID].SetApplicationName(szApplicationName); + if (bSaveAndValidate) { // GetDialogData + for (nAppID = 0; nAppID < MAX_APP; ++nAppID) + if (!m_Config.szSpecialApp[nAppID][0]) { + _tcsncpy_s(m_Config.szSpecialApp[nAppID], szApplicationName, _TRUNCATE); break; } - } - if (nAppID == MAX_APP) { + if (nAppID == MAX_APP) return nAppID; - } - } else { // SetDialogData - for (nAppID = 0; nAppID < MAX_APP; ++nAppID) { - if (IsDefault(m_Data[nAppID].GetApplicationName())) { + } else { // SetDialogData + for (nAppID = 0; nAppID < MAX_APP; ++nAppID) + if (IsDefault(m_Config.szSpecialApp[nAppID])) { *nSettingStyle = SETTING_DEFAULT; break; } - } - if (nAppID == MAX_APP) { + if (nAppID == MAX_APP) return nAppID; - } } } - - if (bSaveAndValidate) { // GetDialogData - m_Data[nAppID].SetSettingStyle(*nSettingStyle); - } else { // SetDialogData - if (*nSettingStyle == SETTING_UNDEFINED) { // It means that *nSettingStyle != SETTING_DEFAULT. - *nSettingStyle = m_Data[nAppID].GetSettingStyle(); - } + if (bSaveAndValidate) // GetDialogData + m_Config.nSettingStyle[nAppID] = *nSettingStyle; + else { // SetDialogData + if (*nSettingStyle == SETTING_UNDEFINED) // It means that *nSettingStyle != SETTING_DEFAULT. + *nSettingStyle = m_Config.nSettingStyle[nAppID]; } - return nAppID; } @@ -1156,75 +1104,70 @@ void CProfile::UpdateApplicationTitle(CComboBox *const cApplicationList, const C { static CString szApplicationTitle; if (bSaveAndValidate) { // GetDialogData - if (!CProfile::IsDefault(szCurrentApplication)) { - m_Data[nAppID].SetApplicationTitle(szApplicationTitle); - } + if (!CProfile::IsDefault(szCurrentApplication)) + _tcsncpy_s(m_szAppTitle[nAppID], szApplicationTitle, _TRUNCATE); szApplicationTitle.Empty(); - } else { // SetDialogData + } else { // SetDialogData CString szListItem; CProfile::GetApplicationTitle(cApplicationList, szListItem); - int nEndTitle = szListItem.ReverseFind(_T('(')); - if (nEndTitle > 0) { + const int nEndTitle = szListItem.ReverseFind(_T('(')); + if (nEndTitle > 0) szApplicationTitle = szListItem.Left(nEndTitle); - } } } void CProfile::SetCommandID(const int nAppID, const int nType, const int nKey, int nComID) { - if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_) { + if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_) // Change CommandID C_Eisu - for (nComID = 1; nComID < MAX_COMMAND; ++nComID) { - if (Commands[nComID].fCommand == CCommands::C_Eisu) { + for (nComID = 1; nComID < MAX_COMMAND; ++nComID) + if (Commands[nComID].fCommand == CCommands::C_Eisu) break; - } - } - } - m_Data[nAppID].SetCommandID(nType, nKey, nComID); + m_Config.nCommandID[nAppID][nType][nKey] = nComID; } int CProfile::GetCommandID(const int nAppID, const int nType, const int nKey) { - int nComID = m_Data[nAppID].GetCommandID(nType, nKey); - if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_Eisu) { + int nComID = m_Config.nCommandID[nAppID][nType][nKey]; + if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_Eisu) // Change CommandID C_ - for (nComID = 1; nComID < MAX_COMMAND; ++nComID) { - if (Commands[nComID].fCommand == CCommands::C_) { + for (nComID = 1; nComID < MAX_COMMAND; nComID++) + if (Commands[nComID].fCommand == CCommands::C_) break; - } - } - } return nComID; } void CProfile::SetKillRingMax(const int nAppID, const int nKillRingMax) { - m_Data[nAppID].SetKillRingMax(nKillRingMax); + m_Config.nKillRingMax[nAppID] = nKillRingMax; } int CProfile::GetKillRingMax(const int nAppID) { - return m_Data[nAppID].GetKillRingMax(); + return m_Config.nKillRingMax[nAppID]; } void CProfile::SetUseDialogSetting(const int nAppID, const BOOL bUseDialogSetting) { - m_Data[nAppID].SetUseDialogSetting(bUseDialogSetting); + m_Config.bUseDialogSetting[nAppID] = bUseDialogSetting; } BOOL CProfile::GetUseDialogSetting(const int nAppID) { - return m_Data[nAppID].GetUseDialogSetting(); + return m_Config.bUseDialogSetting[nAppID]; } void CProfile::SetWindowText(const int nAppID, const CString szWindowText) { - m_Data[nAppID].SetWindowText(szWindowText); + if (CUtils::GetWindowTextType(szWindowText) == IDS_WINDOW_TEXT_IGNORE) + _tcscpy_s(m_Config.szWindowText[nAppID], _T("*")); + else + _tcsncpy_s(m_Config.szWindowText[nAppID], szWindowText, _TRUNCATE); } CString CProfile::GetWindowText(const int nAppID) { - return m_Data[nAppID].GetWindowText(); + return m_Config.szWindowText[nAppID]; } void CProfile::DeleteAllRegistryData() @@ -1266,21 +1209,22 @@ int CProfile::GetCurrentApplicationID(CComboBox *const cApplicationList, const C return -1; } -void CProfile::CopyData(const CString szDestinationApplication, const CString szSourceApplication) +void CProfile::CopyData(const CString szDstApp, const CString szSrcApp) { int nSettingStyle = SETTING_SPECIFIC; - int nDestinationApplication = GetApplicationIndex(szDestinationApplication, TRUE, &nSettingStyle); - int nSourceApplication = GetApplicationIndex(szSourceApplication); - - CString szApplicationName = m_Data[nDestinationApplication].GetApplicationName(); - CString szApplicationTitle = m_Data[nDestinationApplication].GetApplicationTitle(); - CString szWindowText = m_Data[nDestinationApplication].GetWindowText(); - - m_Data[nDestinationApplication] = m_Data[nSourceApplication]; - - m_Data[nDestinationApplication].SetApplicationName(szApplicationName); - m_Data[nDestinationApplication].SetApplicationTitle(szApplicationTitle); - m_Data[nDestinationApplication].SetWindowText(szWindowText); + const int nDstApp = GetApplicationIndex(szDstApp, TRUE, &nSettingStyle); + const int nSrcApp = GetApplicationIndex(szSrcApp); + +#define CopyMember(member) CopyMemory(&m_Config. ## member ## [nDstApp], &m_Config. ## member ## [nSrcApp], sizeof(m_Config. ## member ## [nSrcApp])) + CopyMember(b326Compatible); + CopyMember(nFunctionID); + CopyMember(bEnableCUA); + CopyMember(bUseDialogSetting); + CopyMember(bIgnoreUndefinedC_x); + CopyMember(bIgnoreUndefinedMetaCtrl); + CopyMember(nKillRingMax); + CopyMember(nCommandID); +#undef CopyMember } // return application index @@ -1288,11 +1232,9 @@ void CProfile::CopyData(const CString szDestinationApplication, const CString sz int CProfile::GetApplicationIndex(const CString szApplicationName) { int nAppID = 0; - for (nAppID = 0; nAppID < MAX_APP; ++nAppID) { - if (m_Data[nAppID].GetApplicationName() == szApplicationName) { + for (nAppID = 0; nAppID < MAX_APP; ++nAppID) + if (szApplicationName == m_Config.szSpecialApp[nAppID]) break; - } - } return nAppID; } @@ -1397,12 +1339,12 @@ void CProfile::ImportProperties() BOOL CProfile::GetEnableCUA(const int nAppID) { - return m_Data[nAppID].GetEnableCUA(); + return m_Config.bEnableCUA[nAppID]; } void CProfile::SetEnableCUA(const int nAppID, const BOOL bEnableCUA) { - m_Data[nAppID].SetEnableCUA(bEnableCUA); + m_Config.bEnableCUA[nAppID] = bEnableCUA; } int CProfile::GetKeyboardSpeed() diff --git a/xkeymacs/profile.h b/xkeymacs/profile.h index 9fc9806..6b4b4dc 100644 --- a/xkeymacs/profile.h +++ b/xkeymacs/profile.h @@ -11,7 +11,6 @@ #include // for Windows NT #include "resource.h" -#include "data.h" struct TASK_LIST { DWORD dwProcessId; @@ -80,7 +79,8 @@ private: static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); static BOOL IsTheString(CString sz, UINT nID); static void SetDllData(); - static CData m_Data[MAX_APP]; + static CONFIG m_Config; + static TCHAR m_szAppTitle[MAX_APP][WINDOW_TEXT_LENGTH]; static void DeleteAllRegistryData(); static TASK_LIST m_TaskList[MAX_TASKS]; static DWORD m_dwTasks; diff --git a/xkeymacs/xkeymacs-vc10.vcxproj b/xkeymacs/xkeymacs-vc10.vcxproj index 215c94d..33ce8f8 100644 --- a/xkeymacs/xkeymacs-vc10.vcxproj +++ b/xkeymacs/xkeymacs-vc10.vcxproj @@ -196,10 +196,6 @@ true true - - true - true - true true @@ -261,7 +257,6 @@ - diff --git a/xkeymacs/xkeymacs-vc10.vcxproj.filters b/xkeymacs/xkeymacs-vc10.vcxproj.filters index be98f33..fc396c9 100644 --- a/xkeymacs/xkeymacs-vc10.vcxproj.filters +++ b/xkeymacs/xkeymacs-vc10.vcxproj.filters @@ -57,9 +57,6 @@ Source Files - - Source Files - Source Files @@ -116,9 +113,6 @@ Header Files - - Header Files - Header Files diff --git a/xkeymacsdll/xkeymacsdll.cpp b/xkeymacsdll/xkeymacsdll.cpp index c3ada2f..3445ed1 100644 --- a/xkeymacsdll/xkeymacsdll.cpp +++ b/xkeymacsdll/xkeymacsdll.cpp @@ -284,6 +284,11 @@ BOOL CXkeymacsDll::LoadConfig() return res; } +void CXkeymacsDll::SetConfig(const CONFIG& config) +{ + m_Config = config; +} + // set hooks LRESULT WINAPI DummyProc(int code, WPARAM wp, LPARAM lp) { return CallNextHookEx(0, code, wp, lp); @@ -938,33 +943,6 @@ void CXkeymacsDll::SetModifierIcons() SendIconMessage(msg, 6); } -void CXkeymacsDll::SetApplicationName(int nAppID, CString szApplicationName) -{ - ZeroMemory(m_Config.szSpecialApp[nAppID], CLASS_NAME_LENGTH); - _tcsncpy_s(m_Config.szSpecialApp[nAppID], szApplicationName, _TRUNCATE); -} - -void CXkeymacsDll::SetWindowText(int nAppID, CString szWindowText) -{ - ZeroMemory(m_Config.szWindowText[nAppID], WINDOW_TEXT_LENGTH); - _tcsncpy_s(m_Config.szWindowText[nAppID], szWindowText, _TRUNCATE); -} - -void CXkeymacsDll::SetCommandID(int nAppID, int nType, int nKey, int nComID) -{ - m_Config.nCommandID[nAppID][nType][nKey] = nComID; -} - -void CXkeymacsDll::SetKillRingMax(int nAppID, int nKillRingMax) -{ - m_Config.nKillRingMax[nAppID] = nKillRingMax; -} - -void CXkeymacsDll::SetUseDialogSetting(int nAppID, BOOL bUseDialogSetting) -{ - m_Config.bUseDialogSetting[nAppID] = bUseDialogSetting; -} - // Clear data of nAppID void CXkeymacsDll::Clear(int nAppID) { @@ -1138,26 +1116,6 @@ void CXkeymacsDll::IncreaseKillRingIndex(int nKillRing) m_nKillRing += nKillRing; } -void CXkeymacsDll::SetSettingStyle(int nAppID, int nSettingStyle) -{ - m_Config.nSettingStyle[nAppID] = nSettingStyle; -} - -void CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(int nAppID, BOOL bIgnoreUndefinedMetaCtrl) -{ - m_Config.bIgnoreUndefinedMetaCtrl[nAppID] = bIgnoreUndefinedMetaCtrl; -} - -void CXkeymacsDll::SetIgnoreUndefinedC_x(int nAppID, BOOL bIgnoreUndefinedC_x) -{ - m_Config.bIgnoreUndefinedC_x[nAppID] = bIgnoreUndefinedC_x; -} - -void CXkeymacsDll::SetEnableCUA(int nAppID, BOOL bEnableCUA) -{ - m_Config.bEnableCUA[nAppID] = bEnableCUA; -} - BOOL CXkeymacsDll::GetEnableCUA() { return m_Config.bEnableCUA[m_nApplicationID]; @@ -1197,11 +1155,6 @@ void CXkeymacsDll::CallMacro() SetModifierState(before, 0); } -void CXkeymacsDll::Set106Keyboard(BOOL b106Keyboard) -{ - m_Config.b106Keyboard = b106Keyboard; -} - BOOL CXkeymacsDll::Is106Keyboard() { return m_Config.b106Keyboard; @@ -1223,32 +1176,6 @@ int CXkeymacsDll::IsPassThrough(BYTE nKey) return CONTINUE; } -void CXkeymacsDll::SetFunctionKey(int nFuncID, int nAppID, int nType, int nKey) -{ - if (nAppID < 0 || MAX_APP <= nAppID - || nType < 0 || MAX_COMMAND_TYPE <= nType - || nKey < 0 || MAX_KEY <= nKey) { - return; - } - - m_Config.nFunctionID[nAppID][nType][nKey] = nFuncID; -} - -void CXkeymacsDll::ClearFunctionDefinition() -{ - memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID)); - memset(m_Config.szFunctionDefinition, 0, sizeof(m_Config.szFunctionDefinition)); -} - -void CXkeymacsDll::SetFunctionDefinition(int nFuncID, CString szDefinition) -{ - if (nFuncID < 0 || nFuncID >= MAX_FUNCTION) - return; - memset(m_Config.szFunctionDefinition[nFuncID], 0, sizeof(m_Config.szFunctionDefinition[nFuncID])); - _tcscpy_s(m_Config.szFunctionDefinition[nFuncID], szDefinition); - return; -} - // call an original command which is defined in dot.xkeymacs void CXkeymacsDll::CallFunction(int nFuncID) { @@ -1606,11 +1533,6 @@ void CXkeymacsDll::DoSetCursor() } } -void CXkeymacsDll::Set326Compatible(int nAppID, BOOL b326Compatible) -{ - m_Config.b326Compatible[nAppID] = b326Compatible; -} - BOOL CXkeymacsDll::Get326Compatible() { return m_Config.b326Compatible[m_nApplicationID]; diff --git a/xkeymacsdll/xkeymacsdll.h b/xkeymacsdll/xkeymacsdll.h index 025d85f..d7d2a6a 100644 --- a/xkeymacsdll/xkeymacsdll.h +++ b/xkeymacsdll/xkeymacsdll.h @@ -66,31 +66,21 @@ class AFX_EXT_CLASS CXkeymacsDll public: static BOOL SaveConfig(); static BOOL LoadConfig(); + static void SetConfig(const CONFIG& config); static void SetM_xTip(const TCHAR *const szPath); static BOOL Get326Compatible(); - static void Set326Compatible(int nAppID, BOOL b326Compatible); static void SetCursorData(HCURSOR hEnable, HCURSOR hDisableTMP, HCURSOR hDisableWOCQ, HICON hDisable, BOOL bEnable); static unsigned int GetMaxKeyInterval(void); static void SetKeyboardSpeed(int nKeyboardSpeed); static int GetAccelerate(void); static void SetAccelerate(int nAccelerate); - static void SetWindowText(int nAppID, CString szWindowText); - static void SetKillRingMax(int nAppID, int nKillRingMax); static void Clear(int nAppID); static BOOL IsKeyboardHook(); - static void SetCommandID(int nAppID, int nType, int nKey, int nComID); - static void SetApplicationName(int nAppID, CString szApplicationName); static void ReleaseHooks(); - static void SetEnableCUA(int nAppID, BOOL bEnableCUA); - static void SetIgnoreUndefinedC_x(int nAppID, BOOL bIgnoreUndefinedC_x); - static void SetIgnoreUndefinedMetaCtrl(int nAppID, BOOL bIgnoreUndefinedMetaCtrl); static void SetHooks(); static void ResetHooks(); - static void SetSettingStyle(int nAppID, int nSettingStyle); - static void SetUseDialogSetting(int nAppID, BOOL bUseDialogSetting); static void AddKillRing(BOOL bNewData = TRUE); static void CallMacro(); - static void ClearFunctionDefinition(); static void StartRecordMacro(); static void EndRecordMacro(); static void DepressKey(BYTE bVk, BOOL bOriginal = TRUE); @@ -102,10 +92,7 @@ public: static BOOL IsDown(BYTE bVk, BOOL bPhysicalKey = TRUE); static void Kdu(BYTE bVk, DWORD n = 1, BOOL bOriginal = TRUE); static void ReleaseKey(BYTE bVk); - static void SetFunctionDefinition(int nFuncID, CString szDefinition); - static void SetFunctionKey(int nFuncID, int nAppID, int nType, int nKey); static BOOL Is106Keyboard(); - static void Set106Keyboard(BOOL b106Keyboard); static void ToggleKeyboardHookState(); static void ShowKeyboardHookState(); static BOOL SendIconMessage(ICONMSG *pMsg, DWORD num); -- 2.11.0