// Properties.cpp : implementation file\r
//\r
\r
-#include "stdafx.h"\r
-#include "xkeymacs.h"\r
-#include "Profile.h"\r
-#include "Properties.h"\r
+#include "properties.h"\r
+#include "resource.h"\r
+#include "profile.h"\r
+#include "AppList.h"\r
\r
#ifdef _DEBUG\r
#define new DEBUG_NEW\r
CProperties::CProperties(CWnd* pParent /*=NULL*/)\r
: CDialog(CProperties::IDD, pParent)\r
{\r
- m_nApplicationID = 0;\r
+ m_nAppID = 0;\r
//{{AFX_DATA_INIT(CProperties)\r
m_nSettingStyle = -1;\r
m_nKillRingMax = 0;\r
DDX_Control(pDX, IDC_SELECT_ALL, m_cSelectAll);\r
DDX_Control(pDX, IDC_CLEAR_ALL, m_cClearAll);\r
DDX_Control(pDX, IDC_LOAD_DEFAULT, m_cLoadDefault);\r
- DDX_Control(pDX, IDC_APPLICATION, m_cApplication);\r
+ DDX_Control(pDX, IDC_APPLICATION, m_cAppList);\r
DDX_Radio(pDX, IDC_SETTING_DEFAULT, m_nSettingStyle);\r
DDX_Text(pDX, IDC_KILL_RING_MAX, m_nKillRingMax);\r
DDV_MinMaxInt(pDX, m_nKillRingMax, 0, 2147483647);\r
m_sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT);\r
m_sheet.ModifyStyle( 0, WS_TABSTOP );\r
\r
+ CRect rcArea;\r
+ GetDlgItem(IDC_TAB)->GetWindowRect(&rcArea);\r
+ ScreenToClient(&rcArea);\r
+ m_sheet.SetWindowPos(NULL, rcArea.left - 11, rcArea.top - 8, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);\r
+\r
+ // Fix: Overlapped with buttons due to font size change in CJK Windows 8 or later\r
+ // https://github.com/fujieda/xkeymacs/issues/2\r
CRect rcSheet;\r
- GetDlgItem(IDC_TAB)->GetWindowRect(&rcSheet);\r
- ScreenToClient(&rcSheet);\r
- m_sheet.SetWindowPos(NULL, rcSheet.left - 11, rcSheet.top - 8, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);\r
+ m_sheet.GetWindowRect(&rcSheet);\r
+ CRect rcDialog;\r
+ GetWindowRect(&rcDialog);\r
+ rcDialog.SetRect(rcDialog.left, rcDialog.top, rcDialog.right, rcSheet.bottom + 45);\r
+ MoveWindow(rcDialog, TRUE);\r
\r
+ // Fix: Window size can be changed due to dynamic layout effect\r
+ ModifyStyle(WS_THICKFRAME, DS_MODALFRAME);\r
\r
SetForegroundWindow();\r
\r
- InitApplicationList();\r
+ InitAppList();\r
\r
CProfile::LoadData();\r
- m_szCurrentApplication.LoadString(IDS_DEFAULT);\r
- SetDialogData(m_szCurrentApplication);\r
+ m_appName.LoadString(IDS_DEFAULT);\r
+ SetDialogData();\r
EnableUseDefaultButton(FALSE);\r
EnableLoadDefaultButton(FALSE);\r
\r
\r
void CProperties::OnDropdownApplication() \r
{\r
- InitApplicationList();\r
-\r
- int nID = GetCurrentApplicationID();\r
- if (nID != CB_ERR) {\r
- m_cApplication.SetCurSel(nID);\r
- } else {\r
- GetDialogData();\r
- m_szCurrentApplication.LoadString(IDS_DEFAULT_TITLE);\r
- m_cApplication.SelectString(-1, m_szCurrentApplication);\r
- SetDialogData(m_szCurrentApplication);\r
+ InitAppList();\r
+ int i;\r
+ for (i = 0; i < m_cAppList.GetCount(); ++i) {\r
+ CString appTitle, appName;\r
+ GetAppTitleAndName(i, appTitle, appName);\r
+ if (m_appName == appName)\r
+ m_cAppList.SetCurSel(i);\r
+ }\r
+ if (i == m_cAppList.GetCount()) {\r
+ m_appTitle.LoadString(IDS_DEFAULT_TITLE);\r
+ m_cAppList.SelectString(-1, m_appTitle);\r
+ SetDialogData();\r
}\r
}\r
\r
void CProperties::OnSelchangeApplication() \r
{\r
- GetDialogData();\r
-\r
- CProfile::GetApplicationTitle(&m_cApplication, m_szCurrentApplication, m_cApplication.GetCurSel());\r
- int nStart;\r
- if ((nStart = m_szCurrentApplication.ReverseFind(_T('('))) != -1) {\r
- ++nStart;\r
- m_szCurrentApplication =\r
- m_szCurrentApplication.Mid(nStart, m_szCurrentApplication.GetLength() - nStart - 1);\r
- }\r
-\r
- SetDialogData(m_szCurrentApplication);\r
+ GetAppTitleAndName(m_cAppList.GetCurSel(), m_appTitle, m_appName);\r
+ SetDialogData();\r
EnableControl(ACTIVE_TAB);\r
}\r
\r
-void CProperties::InitApplicationList()\r
+void CProperties::InitAppList()\r
{\r
- CProfile::InitApplicationList(&m_cApplication);\r
-}\r
-\r
-int CProperties::GetCurrentApplicationID()\r
-{\r
- return CProfile::GetCurrentApplicationID(&m_cApplication, m_szCurrentApplication);\r
+ m_cAppList.ResetContent();\r
+ AppList::SetAppList(*this);\r
+ // Add Dialog\r
+ m_cAppList.InsertString(0, CString(MAKEINTRESOURCE(IDS_DIALOG_TITLE)));\r
+ // Add Default\r
+ m_cAppList.InsertString( 0, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
+ m_cAppList.SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
}\r
\r
void CProperties::GetDialogData()\r
{\r
+ UpdateData();\r
if (m_nSettingStyle == SETTING_DEFAULT) {\r
- CProfile::ClearData(m_szCurrentApplication);\r
- } else {\r
- UpdateDialogData(m_szCurrentApplication, TRUE);\r
-\r
- if (m_sheet.GetActivePage() == &m_basic) { // FIXME\r
- m_basic.GetDialogData();\r
- } else if (m_sheet.GetActivePage() == &m_advanced) {\r
- m_advanced.GetDialogData();\r
- } else if (m_sheet.GetActivePage() == &m_list) {\r
- m_list.GetDialogData();\r
- } else {\r
- ASSERT(0);\r
- }\r
+ CProfile::ClearData(m_appName);\r
+ return;\r
}\r
+ m_nAppID = CProfile::AssignAppID(m_appName);\r
+ if (m_nAppID == MAX_APP)\r
+ return;\r
+ CProfile::SetSettingStyle(m_nAppID, m_nSettingStyle);\r
+ CProfile::SetAppTitle(m_nAppID, m_appTitle);\r
+ CProfile::SetKillRingMax(m_nAppID, m_nKillRingMax);\r
+ CProfile::SetUseDialogSetting(m_nAppID, m_cUseDialogSetting.GetCheck() == BST_CHECKED);\r
+ CString szWindowText;\r
+ m_cWindowText.GetWindowText(szWindowText);\r
+ CProfile::SetWindowText(m_nAppID, szWindowText);\r
+\r
+ if (m_sheet.GetActivePage() == &m_basic) // FIXME\r
+ m_basic.GetDialogData();\r
+ else if (m_sheet.GetActivePage() == &m_advanced)\r
+ m_advanced.GetDialogData();\r
+ else if (m_sheet.GetActivePage() == &m_list)\r
+ m_list.GetDialogData();\r
}\r
\r
-void CProperties::SetDialogData(CString szApplicationName)\r
+void CProperties::SetDialogData()\r
{\r
- UpdateDialogData(szApplicationName, FALSE);\r
-\r
- if (m_sheet.GetActivePage() == &m_basic) { // FIXME\r
- m_basic.SetDialogData(szApplicationName);\r
- } else if (m_sheet.GetActivePage() == &m_advanced) {\r
- m_advanced.SetDialogData(szApplicationName);\r
- } else if (m_sheet.GetActivePage() == &m_list) {\r
- m_list.SetDialogData(szApplicationName);\r
- } else {\r
- ASSERT(0);\r
- }\r
+ m_nAppID = CProfile::GetAppID(m_appName);\r
+ m_nSettingStyle = CProfile::GetSettingStyle(m_nAppID);\r
+ if (m_nAppID == MAX_APP)\r
+ m_nAppID = CProfile::DefaultAppID(); // fall back to the default\r
+ EnableUseDefaultButton(m_appName != CString(MAKEINTRESOURCE(IDS_DEFAULT)) &&\r
+ m_appName != CString(MAKEINTRESOURCE(IDS_DIALOG)));\r
+ m_nKillRingMax = CProfile::GetKillRingMax(m_nAppID);\r
+ m_cUseDialogSetting.SetCheck(CProfile::GetUseDialogSetting(m_nAppID) ? BST_CHECKED : BST_UNCHECKED);\r
+ m_cWindowText.SetWindowText(CProfile::GetWindowText(m_nAppID));\r
+ UpdateData(FALSE);\r
+\r
+ if (m_sheet.GetActivePage() == &m_basic) // FIXME\r
+ m_basic.SetDialogData();\r
+ else if (m_sheet.GetActivePage() == &m_advanced)\r
+ m_advanced.SetDialogData();\r
+ else if (m_sheet.GetActivePage() == &m_list)\r
+ m_list.SetDialogData();\r
}\r
\r
-void CProperties::UpdateDialogData(CString szApplicationName, BOOL bSaveAndValidate)\r
+void CProperties::AddItem(const CString& appTitle, const CString& appName)\r
{\r
- if (bSaveAndValidate) { // GetDialogData\r
- UpdateData();\r
- }\r
-\r
- m_nApplicationID = CProfile::GetApplicationIndex(szApplicationName, bSaveAndValidate, &m_nSettingStyle);\r
-\r
- if (CProfile::IsDefault(szApplicationName)\r
- || CProfile::IsDialog(szApplicationName)) {\r
- EnableUseDefaultButton(FALSE);\r
- } else {\r
- EnableUseDefaultButton(TRUE);\r
- }\r
-\r
- // application title\r
- CProfile::UpdateApplicationTitle(&m_cApplication, m_szCurrentApplication, m_nApplicationID, bSaveAndValidate);\r
-\r
- // kill-ring-max\r
- if (bSaveAndValidate) { // GetDialogData\r
- CProfile::SetKillRingMax(m_nApplicationID, m_nKillRingMax);\r
- } else { // SetDialogData\r
- m_nKillRingMax = CProfile::GetKillRingMax(m_nApplicationID);\r
- }\r
-\r
- // Use Dialog Setting\r
- if (bSaveAndValidate) { // GetDialogData\r
- CProfile::SetUseDialogSetting(m_nApplicationID, m_cUseDialogSetting.GetCheck() == BST_CHECKED);\r
- } else { // SetDialogData\r
- m_cUseDialogSetting.SetCheck(CProfile::GetUseDialogSetting(m_nApplicationID) ? BST_CHECKED : BST_UNCHECKED);\r
+ for (int i = 0; i < m_cAppList.GetCount(); ++i) {\r
+ CString tmpTitle, tmpName;\r
+ GetAppTitleAndName(i, tmpTitle, tmpName);\r
+ if (!appName.CompareNoCase(tmpName))\r
+ return;\r
}\r
+ CString trimmed = CString(appTitle).Trim();\r
+ CString item;\r
+ item.Format(IDS_APPLICATION_LIST_ITEM, trimmed, appName);\r
+ m_cAppList.AddString(item);\r
+}\r
\r
- // Check Window Title\r
- if (bSaveAndValidate) { // GetDialogData\r
- CString szWindowText;\r
- m_cWindowText.GetWindowText(szWindowText);\r
- CProfile::SetWindowText(m_nApplicationID, szWindowText);\r
- } else { // SetDialogData\r
- m_cWindowText.SetWindowText(CProfile::GetWindowText(m_nApplicationID));\r
+void CProperties::GetAppTitleAndName(const int nSel, CString& appTitle, CString& appName)\r
+{\r
+ appTitle.Empty();\r
+ appName.Empty();\r
+ CString item;\r
+ if (nSel < 0)\r
+ m_cAppList.GetWindowText(item);\r
+ else\r
+ m_cAppList.GetLBText(nSel, item);\r
+\r
+ if (item == CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE))) {\r
+ appName.LoadString(IDS_DEFAULT);\r
+ return;\r
}\r
-\r
- if (!bSaveAndValidate) { // SetDialogData\r
- UpdateData(FALSE);\r
+ if (item == CString(MAKEINTRESOURCE(IDS_DIALOG_TITLE))) {\r
+ appName.LoadString(IDS_DIALOG);\r
+ return;\r
}\r
+ int nParen = item.ReverseFind(_T('('));\r
+ if (nParen < 0)\r
+ return;\r
+ appTitle = item.Left(nParen);\r
+ appName = item.Mid(nParen + 1, item.GetLength() - nParen -2);\r
}\r
\r
void CProperties::EnableControl(TAB_NAME tab)\r
void CProperties::EnableUseDialogSettingButton(BOOL bEnable)\r
{\r
m_cUseDialogSetting.EnableWindow(bEnable);\r
- if (CProfile::IsDialog(m_szCurrentApplication)) {\r
+ if (m_appName == CString(MAKEINTRESOURCE(IDS_DIALOG)))\r
m_cUseDialogSetting.EnableWindow(FALSE);\r
- }\r
}\r
\r
void CProperties::EnableLoadDefaultButton(BOOL bEnable)\r
{\r
m_cLoadDefault.EnableWindow(bEnable);\r
- if (CProfile::IsDefault(m_szCurrentApplication)) {\r
+ if (m_appName == CString(MAKEINTRESOURCE(IDS_DEFAULT)))\r
m_cLoadDefault.EnableWindow(FALSE);\r
- }\r
}\r
\r
void CProperties::EnableUseDefaultButton(BOOL bEnable)\r
\r
void CProperties::OnLoadDefault() \r
{\r
- CProfile::CopyData(m_szCurrentApplication, CString(MAKEINTRESOURCE(IDS_DEFAULT)));\r
- SetDialogData(m_szCurrentApplication);\r
+ CProfile::CopyDefault(m_appName);\r
+ SetDialogData();\r
}\r
\r
void CProperties::OnSelectAll() \r
{\r
- m_basic.SetAllDialogData(1, TRUE);\r
+ m_basic.SetDefaultBind(1);\r
}\r
\r
void CProperties::OnClearAll() \r
{\r
- m_basic.SetAllDialogData(0, TRUE);\r
+ m_basic.SetDefaultBind(0);\r
}\r
\r
int CProperties::GetApplicationID()\r
{\r
- return m_nApplicationID;\r
+ return m_nAppID;\r
}\r
\r
CString CProperties::GetCurrentApplication()\r
{\r
- return m_szCurrentApplication;\r
+ return m_appName;\r
}\r
\r
void CProperties::OnSettingDefault() \r
{\r
UpdateData();\r
EnableControl(ACTIVE_TAB);\r
-\r
- if (CProfile::GetApplicationIndex(m_szCurrentApplication) == MAX_APP) {\r
- CProfile::CopyData(m_szCurrentApplication, CString(MAKEINTRESOURCE(IDS_DEFAULT)));\r
- SetDialogData(m_szCurrentApplication);\r
- }\r
+ m_nAppID = CProfile::AssignAppID(m_appName);\r
}\r
\r
BOOL CProperties::IsEnableControl()\r