1 // Properties.cpp : implementation file
\r
5 #include "xkeymacs.h"
\r
7 #include "Properties.h"
\r
10 #define new DEBUG_NEW
\r
12 static char THIS_FILE[] = __FILE__;
\r
15 /////////////////////////////////////////////////////////////////////////////
\r
16 // CProperties dialog
\r
19 CProperties::CProperties(CWnd* pParent /*=NULL*/)
\r
20 : CDialog(CProperties::IDD, pParent)
\r
22 m_nApplicationID = 0;
\r
23 //{{AFX_DATA_INIT(CProperties)
\r
24 m_nSettingStyle = -1;
\r
30 void CProperties::DoDataExchange(CDataExchange* pDX)
\r
32 CDialog::DoDataExchange(pDX);
\r
33 //{{AFX_DATA_MAP(CProperties)
\r
34 DDX_Control(pDX, IDC_WINDOW_TEXT, m_cWindowText);
\r
35 DDX_Control(pDX, IDC_KILL_RING_MAX, m_cKillRingMax);
\r
36 DDX_Control(pDX, IDC_USE_DIALOG_SETTING, m_cUseDialogSetting);
\r
37 DDX_Control(pDX, IDC_SELECT_ALL, m_cSelectAll);
\r
38 DDX_Control(pDX, IDC_CLEAR_ALL, m_cClearAll);
\r
39 DDX_Control(pDX, IDC_LOAD_DEFAULT, m_cLoadDefault);
\r
40 DDX_Control(pDX, IDC_APPLICATION, m_cApplication);
\r
41 DDX_Radio(pDX, IDC_SETTING_DEFAULT, m_nSettingStyle);
\r
42 DDX_Text(pDX, IDC_KILL_RING_MAX, m_nKillRingMax);
\r
43 DDV_MinMaxInt(pDX, m_nKillRingMax, 0, 2147483647);
\r
48 BEGIN_MESSAGE_MAP(CProperties, CDialog)
\r
49 //{{AFX_MSG_MAP(CProperties)
\r
50 ON_CBN_DROPDOWN(IDC_APPLICATION, OnDropdownApplication)
\r
51 ON_CBN_SELCHANGE(IDC_APPLICATION, OnSelchangeApplication)
\r
52 ON_BN_CLICKED(IDC_APPLY, OnApply)
\r
53 ON_BN_CLICKED(IDC_LOAD_DEFAULT, OnLoadDefault)
\r
54 ON_BN_CLICKED(IDC_SELECT_ALL, OnSelectAll)
\r
55 ON_BN_CLICKED(IDC_CLEAR_ALL, OnClearAll)
\r
56 ON_BN_CLICKED(IDC_SETTING_DEFAULT, OnSettingDefault)
\r
57 ON_BN_CLICKED(IDC_SETTING_DISABLE, OnSettingDisable)
\r
58 ON_BN_CLICKED(IDC_SETTING_SPECIFIC, OnSettingSpecific)
\r
62 /////////////////////////////////////////////////////////////////////////////
\r
63 // CProperties message handlers
\r
65 BOOL CProperties::OnInitDialog()
\r
67 CDialog::OnInitDialog();
\r
69 while (m_sheet.GetPageCount()) {
\r
70 m_sheet.RemovePage(0);
\r
73 m_sheet.AddPage(&m_basic);
\r
74 m_sheet.AddPage(&m_advanced);
\r
75 m_sheet.AddPage(&m_list);
\r
77 m_sheet.Create(this, WS_CHILD | WS_VISIBLE, 0);
\r
78 m_sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT);
\r
79 m_sheet.ModifyStyle( 0, WS_TABSTOP );
\r
82 GetDlgItem(IDC_TAB)->GetWindowRect(&rcSheet);
\r
83 ScreenToClient(&rcSheet);
\r
84 m_sheet.SetWindowPos(NULL, rcSheet.left - 11, rcSheet.top - 8, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
\r
87 SetForegroundWindow();
\r
89 InitApplicationList();
\r
91 CProfile::LoadRegistryData();
\r
92 m_szCurrentApplication.LoadString(IDS_DEFAULT);
\r
93 SetDialogData(m_szCurrentApplication);
\r
94 EnableUseDefaultButton(FALSE);
\r
95 EnableLoadDefaultButton(FALSE);
\r
97 EnableControl(BASIC_TAB);
\r
99 return TRUE; // return TRUE unless you set the focus to a control
\r
100 // EXCEPTION: OCX Property Pages should return FALSE
\r
103 void CProperties::OnDropdownApplication()
\r
105 InitApplicationList();
\r
107 int nID = GetCurrentApplicationID();
\r
108 if (nID != CB_ERR) {
\r
109 m_cApplication.SetCurSel(nID);
\r
112 m_szCurrentApplication.LoadString(IDS_DEFAULT_TITLE);
\r
113 m_cApplication.SelectString(-1, m_szCurrentApplication);
\r
114 SetDialogData(m_szCurrentApplication);
\r
118 void CProperties::OnSelchangeApplication()
\r
122 CProfile::GetApplicationTitle(&m_cApplication, m_szCurrentApplication, m_cApplication.GetCurSel());
\r
124 if ((nStart = m_szCurrentApplication.ReverseFind(_T('('))) != -1) {
\r
126 m_szCurrentApplication =
\r
127 m_szCurrentApplication.Mid(nStart, m_szCurrentApplication.GetLength() - nStart - 1);
\r
130 SetDialogData(m_szCurrentApplication);
\r
131 EnableControl(ACTIVE_TAB);
\r
134 void CProperties::InitApplicationList()
\r
136 CProfile::InitApplicationList(&m_cApplication);
\r
139 int CProperties::GetCurrentApplicationID()
\r
141 return CProfile::GetCurrentApplicationID(&m_cApplication, m_szCurrentApplication);
\r
144 void CProperties::GetDialogData()
\r
146 if (m_nSettingStyle == SETTING_DEFAULT) {
\r
147 CProfile::ClearData(m_szCurrentApplication);
\r
149 UpdateDialogData(m_szCurrentApplication, TRUE);
\r
151 if (m_sheet.GetActivePage() == &m_basic) { // FIXME
\r
152 m_basic.GetDialogData();
\r
153 } else if (m_sheet.GetActivePage() == &m_advanced) {
\r
154 m_advanced.GetDialogData();
\r
155 } else if (m_sheet.GetActivePage() == &m_list) {
\r
156 m_list.GetDialogData();
\r
163 void CProperties::SetDialogData(CString szApplicationName)
\r
165 UpdateDialogData(szApplicationName, FALSE);
\r
167 if (m_sheet.GetActivePage() == &m_basic) { // FIXME
\r
168 m_basic.SetDialogData(szApplicationName);
\r
169 } else if (m_sheet.GetActivePage() == &m_advanced) {
\r
170 m_advanced.SetDialogData(szApplicationName);
\r
171 } else if (m_sheet.GetActivePage() == &m_list) {
\r
172 m_list.SetDialogData(szApplicationName);
\r
178 void CProperties::UpdateDialogData(CString szApplicationName, BOOL bSaveAndValidate)
\r
180 if (bSaveAndValidate) { // GetDialogData
\r
184 m_nApplicationID = CProfile::GetApplicationIndex(szApplicationName, bSaveAndValidate, &m_nSettingStyle);
\r
186 if (CProfile::IsDefault(szApplicationName)
\r
187 || CProfile::IsDialog(szApplicationName)) {
\r
188 EnableUseDefaultButton(FALSE);
\r
190 EnableUseDefaultButton(TRUE);
\r
193 // application title
\r
194 CProfile::UpdateApplicationTitle(&m_cApplication, m_szCurrentApplication, m_nApplicationID, bSaveAndValidate);
\r
197 if (bSaveAndValidate) { // GetDialogData
\r
198 CProfile::SetKillRingMax(m_nApplicationID, m_nKillRingMax);
\r
199 } else { // SetDialogData
\r
200 m_nKillRingMax = CProfile::GetKillRingMax(m_nApplicationID);
\r
203 // Use Dialog Setting
\r
204 if (bSaveAndValidate) { // GetDialogData
\r
205 CProfile::SetUseDialogSetting(m_nApplicationID, m_cUseDialogSetting.GetCheck() == BST_CHECKED);
\r
206 } else { // SetDialogData
\r
207 m_cUseDialogSetting.SetCheck(CProfile::GetUseDialogSetting(m_nApplicationID) ? BST_CHECKED : BST_UNCHECKED);
\r
210 // Check Window Title
\r
211 if (bSaveAndValidate) { // GetDialogData
\r
212 CString szWindowText;
\r
213 m_cWindowText.GetWindowText(szWindowText);
\r
214 CProfile::SetWindowText(m_nApplicationID, szWindowText);
\r
215 } else { // SetDialogData
\r
216 m_cWindowText.SetWindowText(CProfile::GetWindowText(m_nApplicationID));
\r
219 if (!bSaveAndValidate) { // SetDialogData
\r
224 void CProperties::EnableControl(TAB_NAME tab)
\r
226 if (tab & ACTIVE_TAB) {
\r
227 if (m_sheet.GetActivePage() == &m_basic) { // FIXME
\r
229 } else if (m_sheet.GetActivePage() == &m_advanced) {
\r
230 tab = ADVANCED_TAB;
\r
231 } else if (m_sheet.GetActivePage() == &m_list) {
\r
236 BOOL bEnable = (m_nSettingStyle == SETTING_SPECIFIC);
\r
238 m_cKillRingMax.EnableWindow(bEnable);
\r
239 EnableLoadDefaultButton(bEnable);
\r
241 m_cSelectAll.EnableWindow(bEnable && tab & BASIC_TAB);
\r
242 m_cClearAll.EnableWindow(bEnable && tab & BASIC_TAB);
\r
244 EnableUseDialogSettingButton(bEnable);
\r
246 m_cWindowText.EnableWindow(bEnable);
\r
248 if (tab & BASIC_TAB) {
\r
249 m_basic.EnableControl();
\r
251 if (tab & ADVANCED_TAB) {
\r
252 m_advanced.EnableControl();
\r
254 if (tab & LIST_TAB) {
\r
255 m_list.EnableControl();
\r
259 void CProperties::EnableUseDialogSettingButton(BOOL bEnable)
\r
261 m_cUseDialogSetting.EnableWindow(bEnable);
\r
262 if (CProfile::IsDialog(m_szCurrentApplication)) {
\r
263 m_cUseDialogSetting.EnableWindow(FALSE);
\r
267 void CProperties::EnableLoadDefaultButton(BOOL bEnable)
\r
269 m_cLoadDefault.EnableWindow(bEnable);
\r
270 if (CProfile::IsDefault(m_szCurrentApplication)) {
\r
271 m_cLoadDefault.EnableWindow(FALSE);
\r
275 void CProperties::EnableUseDefaultButton(BOOL bEnable)
\r
277 if (GetDlgItem(IDC_SETTING_DEFAULT)) {
\r
278 GetDlgItem(IDC_SETTING_DEFAULT)->EnableWindow(bEnable);
\r
282 void CProperties::OnOK()
\r
289 void CProperties::OnCancel()
\r
291 CProfile::LoadRegistryData();
\r
293 CDialog::OnCancel();
\r
296 void CProperties::OnApply()
\r
299 CProfile::SaveRegistryData();
\r
302 void CProperties::OnLoadDefault()
\r
304 CProfile::CopyData(m_szCurrentApplication, CString(MAKEINTRESOURCE(IDS_DEFAULT)));
\r
305 SetDialogData(m_szCurrentApplication);
\r
308 void CProperties::OnSelectAll()
\r
310 m_basic.SetAllDialogData(1, TRUE);
\r
313 void CProperties::OnClearAll()
\r
315 m_basic.SetAllDialogData(0, TRUE);
\r
318 int CProperties::GetApplicationID()
\r
320 return m_nApplicationID;
\r
323 CString CProperties::GetCurrentApplication()
\r
325 return m_szCurrentApplication;
\r
328 void CProperties::OnSettingDefault()
\r
330 UpdateData(); // get data
\r
331 EnableControl(ACTIVE_TAB);
\r
334 void CProperties::OnSettingDisable()
\r
337 EnableControl(ACTIVE_TAB);
\r
340 void CProperties::OnSettingSpecific()
\r
343 EnableControl(ACTIVE_TAB);
\r
345 if (CProfile::GetApplicationIndex(m_szCurrentApplication) == MAX_APP) {
\r
346 CProfile::CopyData(m_szCurrentApplication, CString(MAKEINTRESOURCE(IDS_DEFAULT)));
\r
347 SetDialogData(m_szCurrentApplication);
\r
351 BOOL CProperties::IsEnableControl()
\r
353 return m_nSettingStyle == SETTING_SPECIFIC;
\r