CalendarResourcesDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:26k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // CalendarResourcesDlg.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "calendardemo.h"
  22. #include "CalendarResourcesDlg.h"
  23. #include "DataProvidersOptions.h"
  24. //#include "XTPCalendarCustomProperties.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. //////////////////////////////////////////////////////////////////////////
  31. CString GetDPType(int nDPType)
  32. {
  33. CString strDPType = _T("?");
  34. if (nDPType == xtpCalendarDataProviderMemory) {
  35. strDPType = _T("XML/Bin");
  36. } else if (nDPType == xtpCalendarDataProviderDatabase) {
  37. strDPType = _T("DB");
  38. } else if (nDPType == xtpCalendarDataProviderMAPI) {
  39. strDPType = _T("MAPI");
  40. }
  41. else {
  42. ASSERT(FALSE);
  43. }
  44. return strDPType;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CCalendarResourcesDlg dialog
  48. CCalendarResourcesDlg::CCalendarResourcesDlg(
  49. CXTPCalendarResourcesManager* pRCMan, 
  50. CWnd* pParent /*=NULL*/)
  51. : CDialog(CCalendarResourcesDlg::IDD, pParent)
  52. {
  53. ASSERT(pRCMan);
  54. m_pRCMan = pRCMan;
  55. m_bChangeEditRcName_internal = TRUE;
  56. m_nRcNameAuto_StoredState = -1;
  57. //{{AFX_DATA_INIT(CCalendarResourcesDlg)
  58. //}}AFX_DATA_INIT
  59. }
  60. void CCalendarResourcesDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CCalendarResourcesDlg)
  64. DDX_Control(pDX, IDC_BTN_RESOURCES_MOVE_DOWN, m_ctrlResourcesMoveDown);
  65. DDX_Control(pDX, IDC_BTN_RESOURCES_MOVE_UP, m_ctrlResourcesMoveUp);
  66. DDX_Control(pDX, IDC_LISTCTRL_DATA_PROVIDERS, m_ctrlDataProviders);
  67. DDX_Control(pDX, IDC_BTN_DATA_PROVIDER_DELETE, m_ctrlDataProviderDelete);
  68. DDX_Control(pDX, IDC_BTN_DATA_PROVIDER_EDIT, m_ctrlDataProviderEdit);
  69. DDX_Control(pDX, IDC_BTN_DATA_PROVIDER_ADD, m_ctrlDataProviderAdd);
  70. DDX_Control(pDX, IDC_LIST_RESOURCES, m_ctrlResources);
  71. DDX_Control(pDX, IDC_BTN_RESOURCES_DELETE, m_ctrlResourcesDelete);
  72. DDX_Control(pDX, IDC_BTN_RESOURCES_ADD, m_ctrlResourcesAdd);
  73. DDX_Control(pDX, IDC_EDIT_RC_NAME, m_ctrlRCName);
  74. DDX_Control(pDX, IDC_CHK_RC_NAME_AUTO, m_ctrlRCNameAuto);
  75. DDX_Control(pDX, IDC_CMB_RC_DATA_PROVIDER, m_ctrlRCDataProvider);
  76. DDX_Control(pDX, IDC_LIST_SCHEDULES, m_ctrlSchedules);
  77. DDX_Control(pDX, IDC_CHK_SCHEDULES_ALL, m_ctrlSchedulesAll);
  78. DDX_Control(pDX, IDC_BTN_SCHEDULES_DELEDE, m_ctrlSchedulesDelete);
  79. DDX_Control(pDX, IDC_BTN_SCHEDULES_ADD, m_ctrlSchedulesAdd);
  80. DDX_Control(pDX, IDC_BTN_SCHEDULES_CHANGE, m_ctrlScheduleChangeName);
  81. DDX_Control(pDX, IDC_EDIT_SCHEDULE_NEW_NAME, m_ctrlScheduleNewName);
  82. //}}AFX_DATA_MAP
  83. }
  84. BEGIN_MESSAGE_MAP(CCalendarResourcesDlg, CDialog)
  85. //{{AFX_MSG_MAP(CCalendarResourcesDlg)
  86. ON_BN_CLICKED(IDC_BTN_DATA_PROVIDER_ADD, OnBtnDataProviderAdd)
  87. ON_BN_CLICKED(IDC_BTN_DATA_PROVIDER_DELETE, OnBtnDataProviderDelete)
  88. ON_BN_CLICKED(IDC_BTN_DATA_PROVIDER_EDIT, OnBtnDataProviderEdit)
  89. ON_BN_CLICKED(IDC_BTN_RESOURCES_ADD, OnBtnResourcesAdd)
  90. ON_BN_CLICKED(IDC_BTN_RESOURCES_DELETE, OnBtnResourcesDelete)
  91. ON_BN_CLICKED(IDC_BTN_SCHEDULES_ADD, OnBtnSchedulesAdd)
  92. ON_BN_CLICKED(IDC_BTN_SCHEDULES_DELEDE, OnBtnSchedulesDelede)
  93. ON_BN_CLICKED(IDC_BTN_SCHEDULES_CHANGE, OnBtnSchedulesChange)
  94. ON_BN_CLICKED(IDC_CHK_RC_NAME_AUTO, OnChkRcNameAuto)
  95. ON_BN_CLICKED(IDC_CHK_SCHEDULES_ALL, OnChkSchedulesAll)
  96. ON_EN_CHANGE(IDC_EDIT_RC_NAME, OnChangeEditRcName)
  97. ON_LBN_SELCHANGE(IDC_LIST_RESOURCES, OnSelchangeListResources)
  98. ON_LBN_SELCHANGE(IDC_LIST_SCHEDULES, OnSelchangeListSchedules)
  99. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LISTCTRL_DATA_PROVIDERS, OnItemchangedListctrlDataProviders)
  100. ON_CBN_SELCHANGE(IDC_CMB_RC_DATA_PROVIDER, OnSelchangeCmbRcDataProvider)
  101. ON_LBN_KILLFOCUS(IDC_LIST_SCHEDULES, OnKillfocusListSchedules)
  102. ON_BN_CLICKED(IDC_BTN_RESOURCES_MOVE_DOWN, OnBtnResourcesMoveDown)
  103. ON_BN_CLICKED(IDC_BTN_RESOURCES_MOVE_UP, OnBtnResourcesMoveUp)
  104. //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CCalendarResourcesDlg message handlers
  108. BOOL CCalendarResourcesDlg::OnInitDialog() 
  109. {
  110. CDialog::OnInitDialog();
  111. m_ctrlDataProviders.InsertColumn(0, _T(""), 0, 25);
  112. m_ctrlDataProviders.InsertColumn(1, _T("Type"), 0, 90);
  113. m_ctrlDataProviders.InsertColumn(2, _T("Data"), 0, 280);
  114. ListView_SetExtendedListViewStyle(m_ctrlDataProviders.GetSafeHwnd(), LVS_EX_FULLROWSELECT);
  115. UpdateDataProvidersList();
  116. UpdateResourcesList();
  117. UpdateResourceInfoPane();
  118. m_ctrlSchedules.setParentDlg(this);
  119. // TODO: Add extra initialization here
  120. return TRUE;  // return TRUE unless you set the focus to a control
  121.               // EXCEPTION: OCX Property Pages should return FALSE
  122. }
  123. void CCalendarResourcesDlg::UpdateDataProvidersList()
  124. {
  125. // Clear old list
  126. int nSel = m_ctrlDataProviders.GetNextItem(-1, LVNI_FOCUSED);
  127. m_ctrlDataProviders.DeleteAllItems();
  128. ASSERT(m_pRCMan);
  129. if (!m_pRCMan) {
  130. return;
  131. }
  132. // Iterate all data providers
  133. int nCount = m_pRCMan->GetDataProvidersCount();
  134. for (int i = 0; i < nCount; i++)
  135. {
  136. CXTPCalendarData* pDP = m_pRCMan->GetDataProvider(i);
  137. ASSERT(pDP);
  138. if (!pDP) {
  139. continue;
  140. }
  141. int nIndex = m_ctrlDataProviders.GetItemCount();
  142. CString strIndex; 
  143. strIndex.Format(_T("%d"), nIndex);
  144. CString strDPType = GetDPType(pDP->GetType());
  145. CString strData = pDP->GetDataSource();
  146. nIndex = m_ctrlDataProviders.InsertItem(nIndex, strIndex);
  147. m_ctrlDataProviders.SetItem(nIndex, 1, LVIF_TEXT, strDPType, -1, 0, 0, 0);
  148. m_ctrlDataProviders.SetItem(nIndex, 2, LVIF_TEXT, strData, -1, 0, 0, 0);
  149. }
  150. if (nSel >= 0 && m_ctrlDataProviders.GetItemCount())
  151. {
  152. UINT uFSmask = LVNI_FOCUSED|LVNI_SELECTED;
  153. nSel = min(m_ctrlDataProviders.GetItemCount() - 1, nSel);
  154. m_ctrlDataProviders.SetItemState(nSel, uFSmask, uFSmask);
  155. }
  156. UpdateDataProviders_RCCombo();
  157. }
  158. void CCalendarResourcesDlg::UpdateDataProviders_RCCombo()
  159. {
  160. m_ctrlRCDataProvider.ResetContent();
  161. ASSERT(m_pRCMan);
  162. if (!m_pRCMan) {
  163. return;
  164. }
  165. int nCount = m_pRCMan->GetDataProvidersCount();
  166. for (int i = 0; i < nCount; i++)
  167. {
  168. CXTPCalendarData* pDP = m_pRCMan->GetDataProvider(i);
  169. ASSERT(pDP);
  170. if (!pDP) {
  171. continue;
  172. }
  173. CString strDP; 
  174. strDP.Format(_T("%d - (%s) %s"), i, GetDPType(pDP->GetType()), pDP->GetDataSource());
  175. int nIndex = m_ctrlRCDataProvider.AddString(strDP);
  176. m_ctrlRCDataProvider.SetItemData(nIndex, (DWORD_PTR)pDP);
  177. }
  178. UpdateSchedulesList();
  179. }
  180. void CCalendarResourcesDlg::UpdateResourcesList()
  181. {
  182. int nSel = m_ctrlResources.GetCurSel();
  183. m_ctrlResources.ResetContent();
  184. ASSERT(m_pRCMan);
  185. if (!m_pRCMan) {
  186. return;
  187. }
  188. int nCount = m_pRCMan->GetResourcesCount();
  189. for (int i = 0; i < nCount; i++)
  190. {
  191. CXTPCalendarResourceDescription* pRCDesc = m_pRCMan->GetResource(i);
  192. if (!pRCDesc || !pRCDesc->m_ptrResource) {
  193. ASSERT(FALSE);
  194. continue;
  195. }
  196. int nIndex = m_ctrlResources.AddString(pRCDesc->m_ptrResource->GetName());
  197. m_ctrlResources.SetCheck(nIndex, pRCDesc->m_bEnabled ? 1 : 0);
  198. m_ctrlResources.SetItemData(nIndex, (DWORD_PTR)pRCDesc);
  199. }
  200. if (nSel >= 0 && m_ctrlResources.GetCount())
  201. {
  202. nSel = min(m_ctrlResources.GetCount() - 1, nSel);
  203. m_ctrlResources.SetCurSel(nSel);
  204. m_ctrlResources.SetSel(nSel);
  205. }
  206. }
  207. void CCalendarResourcesDlg::UpdateResourceInfoPane()
  208. {
  209. ASSERT(m_pRCMan);
  210.     // Get current resource description
  211. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  212. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource)
  213. {
  214. EnableResourceInfoPane(FALSE);
  215. return;
  216. }
  217. EnableResourceInfoPane(TRUE);
  218. // Update properties
  219. m_bChangeEditRcName_internal = TRUE;
  220. m_ctrlRCName.SetWindowText(pRCDesc->m_ptrResource->GetName());
  221. m_bChangeEditRcName_internal = FALSE;
  222. m_ctrlRCNameAuto.SetCheck(pRCDesc->m_bGenerateName);
  223. m_ctrlRCName.EnableWindow(!pRCDesc->m_bGenerateName);
  224. // Set corresponding data provider in combobox
  225. int nDPIndex = -1;
  226. CXTPCalendarData* pData = pRCDesc->m_ptrResource->GetDataProvider();
  227. if (pData)
  228. {
  229. CString strConStr = pData->GetConnectionString();
  230. m_pRCMan->GetDataProvider(strConStr, &nDPIndex);
  231. if (nDPIndex < 0 || nDPIndex >= m_ctrlRCDataProvider.GetCount()) {
  232. nDPIndex = -1;
  233. }
  234. }
  235. m_ctrlRCDataProvider.SetCurSel(nDPIndex);
  236. // continue
  237. m_ctrlSchedulesAll.SetCheck(0);
  238. UpdateSchedulesList();
  239. ProcessAutoName();
  240. }
  241. void CCalendarResourcesDlg::UpdateSchedulesList()
  242. {
  243. ASSERT(m_pRCMan);
  244. int nSelSch = m_ctrlSchedules.GetCurSel();
  245. m_ctrlSchedules.ResetContent();
  246. m_ctrlScheduleNewName.SetWindowText(_T(""));
  247. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  248. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource)
  249. {
  250. EnableSchedulesInfoControls(FALSE);
  251. return;
  252. }
  253. //------------------------------------------------------------------
  254. CXTPCalendarResource* pRC = pRCDesc->m_ptrResource;
  255. CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL;
  256. CXTPCalendarSchedules* pSchedules = pData ? pData->GetSchedules() : NULL;
  257. if (!pSchedules) 
  258. {
  259. EnableSchedulesInfoControls(FALSE);
  260. return;
  261. }
  262. EnableSchedulesInfoControls(TRUE);
  263. // Iterate schedules
  264. int nCount = pSchedules->GetCount();
  265. for (int i = 0; i < nCount; i++)
  266. {
  267. CXTPCalendarSchedule* pSch = pSchedules->GetAt(i);
  268. ASSERT(pSch);
  269. if (!pSch) {
  270. continue;
  271. }
  272.         
  273. int nIndex = m_ctrlSchedules.AddString(pSch->GetName());
  274. m_ctrlSchedules.SetItemData(nIndex, (DWORD)pSch->GetID());
  275. BOOL bVisible = pRC->ExistsScheduleID(pSch->GetID(), FALSE);
  276. m_ctrlSchedules.SetCheck(nIndex, bVisible ? 1 : 0);
  277. }
  278. if (nSelSch >= 0 && m_ctrlSchedules.GetCount())
  279. {
  280. nSelSch = min(m_ctrlSchedules.GetCount() - 1, nSelSch);
  281. m_ctrlSchedules.SetSel(nSelSch);
  282. }
  283. //-----------
  284. m_ctrlSchedulesAll.SetCheck(pRC->IsSchedulesSetEmpty() ? 1 : 0);
  285. UpdateSchedulesAll_DependsCtrls();
  286. }
  287. void CCalendarResourcesDlg::UpdateSchedulesAll_DependsCtrls()
  288. {
  289. int nCheck = m_ctrlSchedulesAll.GetCheck();
  290. if (nCheck)
  291. m_ctrlSchedules.LockAllCheckBoxes(0);
  292. else
  293. m_ctrlSchedules.UnlockAllCheckBoxes();
  294. }
  295. void CCalendarResourcesDlg::EnableResourceInfoPane(BOOL bEnable)
  296. {
  297. m_ctrlRCName.EnableWindow(bEnable);
  298. m_ctrlRCNameAuto.EnableWindow(bEnable);
  299. m_ctrlRCDataProvider.EnableWindow(bEnable);
  300. EnableSchedulesInfoControls(bEnable);
  301. }
  302. void CCalendarResourcesDlg::EnableSchedulesInfoControls(BOOL bEnable)
  303. {
  304. m_ctrlSchedulesAll.EnableWindow(bEnable);
  305. m_ctrlSchedules.EnableWindow(bEnable);
  306. m_ctrlSchedulesDelete.EnableWindow(bEnable);
  307. m_ctrlSchedulesAdd.EnableWindow(bEnable);
  308. m_ctrlScheduleNewName.EnableWindow(bEnable);
  309. }
  310. //****************
  311. void CCalendarResourcesDlg::OnBtnDataProviderAdd() 
  312. {
  313. ASSERT(m_pRCMan);
  314. if (!m_pRCMan) {
  315. return;
  316. }
  317. CDataProvidersOptions dlgDP;
  318. dlgDP.m_bInitFromProfile = FALSE;
  319. dlgDP.m_bSaveToProfile = FALSE;
  320. int nDlgRes = (int)dlgDP.DoModal();
  321. if (nDlgRes != IDOK) {
  322. return;
  323. }
  324. ASSERT(!dlgDP.m_strConnectionString.IsEmpty());
  325. // Already present ?
  326. ASSERT(!m_pRCMan->GetDataProvider(dlgDP.m_strConnectionString));
  327. const int eDPFAll = CXTPCalendarResourcesManager::xtpCalendarDPF_CreateIfNotExists |
  328. CXTPCalendarResourcesManager::xtpCalendarDPF_SaveOnDestroy | 
  329. CXTPCalendarResourcesManager::xtpCalendarDPF_CloseOnDestroy;
  330. m_pRCMan->AddDataProvider(dlgDP.m_strConnectionString, eDPFAll);
  331. UpdateDataProvidersList();
  332. }
  333. void CCalendarResourcesDlg::OnBtnDataProviderDelete() 
  334. {
  335. ASSERT(m_pRCMan);
  336. if (!m_pRCMan) {
  337. return;
  338. }
  339. int nSel = m_ctrlDataProviders.GetNextItem(-1, LVNI_FOCUSED);
  340. if (nSel >= 0 && nSel < m_ctrlDataProviders.GetItemCount())
  341. {
  342. m_pRCMan->RemoveDataProvider(nSel);
  343. UpdateDataProvidersList();
  344. }
  345. }
  346. void CCalendarResourcesDlg::OnBtnDataProviderEdit() 
  347. {
  348. ASSERT(m_pRCMan);
  349. if (!m_pRCMan) {
  350. return;
  351. }
  352.     // get selected data provider
  353. int nSel = m_ctrlDataProviders.GetNextItem(-1, LVNI_FOCUSED);
  354. if (nSel < 0 || nSel >= m_ctrlDataProviders.GetItemCount()) {
  355. return;
  356. }
  357. if (!m_pRCMan->GetDataProvider(nSel)) {
  358. ASSERT(FALSE);
  359. return;
  360. }
  361. // Prepare and show DP options dialog
  362. CDataProvidersOptions dlgDP;
  363. dlgDP.m_bInitFromProfile = FALSE;
  364. dlgDP.m_bSaveToProfile = FALSE;
  365. dlgDP.m_strConnectionString = m_pRCMan->GetDataProvider(nSel)->GetConnectionString();
  366. int nDlgRes = (int)dlgDP.DoModal();
  367. if (nDlgRes != IDOK) {
  368. return;
  369. }
  370. ASSERT(!dlgDP.m_strConnectionString.IsEmpty());
  371. // Already present ?
  372. int n = 0;
  373. ASSERT(!m_pRCMan->GetDataProvider(dlgDP.m_strConnectionString, &n) || n == nSel);
  374. UNREFERENCED_PARAMETER(n);
  375. m_pRCMan->SetDataProvider(nSel, dlgDP.m_strConnectionString, TRUE);
  376. UpdateDataProvidersList();
  377. }
  378. //****************
  379. void CCalendarResourcesDlg::OnBtnResourcesAdd() 
  380. {
  381. ASSERT(m_pRCMan);
  382. if (!m_pRCMan) {
  383. return;
  384. }
  385. m_pRCMan->AddResource(_T("new resource"), TRUE);
  386. UpdateResourcesList();
  387. int nCount = m_ctrlResources.GetCount();
  388. if (nCount) 
  389. {
  390. m_ctrlResources.SetCurSel(-1);
  391. m_ctrlResources.SetCurSel(nCount-1);
  392. m_ctrlResources.SetSel(nCount-1);
  393. }
  394. UpdateResourceInfoPane();
  395. }
  396. void CCalendarResourcesDlg::OnBtnResourcesDelete() 
  397. {
  398. if (!m_pRCMan) {
  399. return;
  400. }
  401. int nSel = m_ctrlResources.GetCurSel();
  402. if (nSel >= 0 && m_ctrlResources.GetCount())
  403. {
  404. m_pRCMan->RemoveResource(nSel);
  405. UpdateResourcesList();
  406. }
  407. UpdateResourceInfoPane();
  408. }
  409. void CCalendarResourcesDlg::OnBtnResourcesMoveDown() 
  410. {
  411. ASSERT(m_pRCMan);
  412. int nIndex = -1;
  413. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc(&nIndex);
  414. if (!m_pRCMan || !pRCDesc) {
  415. return;
  416. }
  417. if (nIndex+1 >= m_pRCMan->GetResourcesCount()) {
  418. return;
  419. }
  420. m_pRCMan->MoveResource(nIndex, nIndex + 1);
  421. m_ctrlResources.SetCurSel(nIndex + 1);
  422. m_ctrlResources.SetSel(nIndex + 1);
  423. UpdateResourcesList();
  424. UpdateResourceInfoPane();
  425. }
  426. void CCalendarResourcesDlg::OnBtnResourcesMoveUp() 
  427. {
  428. ASSERT(m_pRCMan);
  429. int nIndex = -1;
  430. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc(&nIndex);
  431. if (!m_pRCMan || !pRCDesc) {
  432. return;
  433. }
  434. if (nIndex - 1 < 0) {
  435. return;
  436. }
  437. m_pRCMan->MoveResource(nIndex, nIndex - 1);
  438. m_ctrlResources.SetCurSel(nIndex - 1);
  439. m_ctrlResources.SetSel(nIndex - 1);
  440. UpdateResourcesList();
  441. UpdateResourceInfoPane();
  442. }
  443. //****************
  444. void CCalendarResourcesDlg::OnBtnSchedulesAdd() 
  445. {
  446. CString strNewSchName;
  447. m_ctrlScheduleNewName.GetWindowText(strNewSchName);
  448.     
  449. if (strNewSchName.IsEmpty()) {
  450. return;
  451. }
  452. ASSERT(m_pRCMan);
  453. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  454. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource) {
  455. return;
  456. }
  457. CXTPCalendarResource* pRC = pRCDesc->m_ptrResource;
  458. CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL;
  459. CXTPCalendarSchedules* pSchedules = pData ? pData->GetSchedules() : NULL;
  460. if (!pSchedules) {
  461. return;
  462. }
  463. pSchedules->AddNewSchedule(strNewSchName);
  464. //-------------------------------------------------------
  465. UpdateSchedulesList_saveState();
  466. int nSchCount = m_ctrlSchedules.GetCount();
  467. if (nSchCount > 0)
  468. {
  469. int nSchSel = nSchCount-1;
  470. m_ctrlSchedules.SetCurSel(nSchSel);
  471. m_ctrlSchedules.SetSel(nSchSel);
  472. m_ctrlSchedules.GetText(nSchSel, strNewSchName);
  473. m_ctrlScheduleNewName.SetWindowText(strNewSchName);
  474. }
  475. ProcessAutoName();
  476. }
  477. void CCalendarResourcesDlg::OnBtnSchedulesDelede() 
  478. {
  479. int nSchSel = m_ctrlSchedules.GetCurSel();
  480. int nSchCount = m_ctrlSchedules.GetCount();
  481. if (nSchSel < 0 || nSchSel >= nSchCount) {
  482. return;
  483. }
  484. ASSERT(m_pRCMan);
  485. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  486. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource) {
  487. return;
  488. }
  489. CXTPCalendarResource* pRC = pRCDesc->m_ptrResource;
  490. CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL;
  491. CXTPCalendarSchedules* pSchedules = pData ? pData->GetSchedules() : NULL;
  492. if (!pSchedules) {
  493. return;
  494. }
  495. UINT uSchID = (UINT)m_ctrlSchedules.GetItemData(nSchSel);
  496. pSchedules->RemoveSchedule(uSchID);
  497. //-------------------------------------------------------
  498. UpdateSchedulesList_saveState();
  499. ProcessAutoName();
  500. }
  501. void CCalendarResourcesDlg::OnBtnSchedulesChange()
  502. {
  503. int nSchSel = m_ctrlSchedules.GetCurSel();
  504. int nSchCount = m_ctrlSchedules.GetCount();
  505. if (nSchSel < 0 || nSchSel >= nSchCount) {
  506. return;
  507. }
  508. ASSERT(m_pRCMan);
  509. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  510. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource) {
  511. return;
  512. }
  513. CXTPCalendarResource* pRC = pRCDesc->m_ptrResource;
  514. CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL;
  515. CXTPCalendarSchedules* pSchedules = pData ? pData->GetSchedules() : NULL;
  516. if (!pSchedules) {
  517. return;
  518. }
  519. CString strSchName;
  520. m_ctrlScheduleNewName.GetWindowText(strSchName);
  521. UINT uSchID = (UINT)m_ctrlSchedules.GetItemData(nSchSel);
  522. pSchedules->SetScheduleName(uSchID, strSchName);
  523. //-------------------------------------------------------
  524. UpdateSchedulesList_saveState();
  525. ProcessAutoName();
  526. }
  527. void CCalendarResourcesDlg::UpdateSchedulesList_saveState()
  528. {
  529. int nSchSel = m_ctrlSchedules.GetCurSel();
  530. BOOL bAll_Enabled = m_ctrlSchedulesAll.IsWindowEnabled();
  531. UpdateSchedulesList();
  532. m_ctrlSchedulesAll.EnableWindow(bAll_Enabled);
  533. UpdateSchedulesAll_DependsCtrls();
  534. int nSchCount = m_ctrlSchedules.GetCount();
  535. nSchSel = min(nSchSel, nSchCount-1);
  536. if (nSchSel >= 0)
  537. {
  538. m_ctrlSchedules.SetCurSel(nSchSel);
  539. m_ctrlSchedules.SetSel(nSchSel);
  540. CString strSchName;
  541. m_ctrlSchedules.GetText(nSchSel, strSchName);
  542. m_ctrlScheduleNewName.SetWindowText(strSchName);
  543. }
  544. }
  545. //****************
  546. void CCalendarResourcesDlg::OnChkRcNameAuto() 
  547. {
  548. ApplyUpdateRcNameAuto();
  549. ProcessAutoName();
  550. }
  551. void CCalendarResourcesDlg::ApplyUpdateRcNameAuto() 
  552. {
  553. ASSERT(m_pRCMan);
  554. int nIndex = -1;
  555. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc(&nIndex);
  556. if (!m_pRCMan || !pRCDesc) {
  557. return;
  558. }
  559. int nCheck = m_ctrlRCNameAuto.GetCheck();
  560. m_ctrlRCName.EnableWindow(!nCheck);
  561. pRCDesc->m_bGenerateName = !!nCheck;
  562. }
  563. void CCalendarResourcesDlg::OnChkSchedulesAll() 
  564. {
  565. UpdateSchedulesAll_DependsCtrls();
  566. ApplySchedules();
  567. ProcessAutoName();
  568. }
  569. void CCalendarResourcesDlg::OnChangeEditRcName() 
  570. {
  571. if (m_bChangeEditRcName_internal) {
  572. return;
  573. }
  574. ASSERT(m_pRCMan);
  575. int nIndex = -1;
  576. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc(&nIndex);
  577. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource) {
  578. return;
  579. }
  580. m_nRcNameAuto_StoredState = -1;
  581. CString strName;
  582. m_ctrlRCName.GetWindowText(strName);
  583. pRCDesc->m_ptrResource->SetName(strName);
  584. m_ctrlResources.DeleteString(nIndex);
  585. nIndex = m_ctrlResources.InsertString(nIndex, strName);
  586. m_ctrlResources.SetCheck(nIndex, pRCDesc->m_bEnabled ? 1 : 0);
  587. m_ctrlResources.SetItemData(nIndex, (DWORD_PTR)pRCDesc);
  588. m_ctrlResources.SetCurSel(nIndex);
  589. m_ctrlResources.SetSel(nIndex);
  590. m_ctrlResources.Invalidate();
  591. }
  592. void CCalendarResourcesDlg::OnSelchangeListResources() 
  593. {
  594. m_nRcNameAuto_StoredState = -1;
  595. UpdateResourceInfoPane();
  596. }
  597. void CCalendarResourcesDlg::OnSelchangeListSchedules() 
  598. {
  599. }
  600. void CCalendarResourcesDlg::OnItemchangedListctrlDataProviders(NMHDR* pNMHDR, LRESULT* pResult) 
  601. {
  602. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  603. // TODO: Add your control notification handler code here
  604. pNMListView;
  605. *pResult = 0;
  606. }
  607. //****************
  608. void CCalendarResourcesDlg::OnCancel() 
  609. {
  610. // TODO: Add extra cleanup here
  611. CDialog::OnCancel();
  612. }
  613. void CCalendarResourcesDlg::OnOK() 
  614. {
  615. ASSERT(m_pRCMan);
  616. if (!m_pRCMan) {
  617. CDialog::OnOK();
  618. return;
  619. }
  620. int nCount = m_ctrlResources.GetCount();
  621. for (int i = 0; i < nCount; i++)
  622. {
  623. CXTPCalendarResourceDescription* pRCDesc = 
  624. (CXTPCalendarResourceDescription*)m_ctrlResources.GetItemData(i);
  625. if (!pRCDesc) 
  626. {
  627. ASSERT(FALSE);
  628. continue;
  629. }
  630. pRCDesc->m_bEnabled = !!m_ctrlResources.GetCheck(i);
  631. }
  632. CDialog::OnOK();
  633. }
  634. void CCalendarResourcesDlg::OnSelchangeCmbRcDataProvider() 
  635. {
  636. ASSERT(m_pRCMan);
  637. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  638. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource)
  639. {
  640. UpdateResourceInfoPane();
  641. return;
  642. }
  643. //------------------------------------------------------------------
  644. CXTPCalendarData* pData = NULL;
  645. int nDPSel = m_ctrlRCDataProvider.GetCurSel();
  646. if (nDPSel >= 0 && nDPSel < m_pRCMan->GetDataProvidersCount()) {
  647. pData = m_pRCMan->GetDataProvider(nDPSel);
  648. }
  649. pRCDesc->m_ptrResource->SetDataProvider(pData);
  650. UpdateSchedulesList();
  651. }
  652. void CCalendarResourcesDlg::OnKillfocusListSchedules() 
  653. {
  654. }
  655. void CCalendarResourcesDlg::ApplySchedules() 
  656. {
  657. ASSERT(m_pRCMan);
  658. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  659. if (!m_pRCMan || !pRCDesc || !pRCDesc->m_ptrResource) {
  660. return;
  661. }
  662. //------------------------------------------------------------------
  663. CXTPCalendarResource* pRC = pRCDesc->m_ptrResource;
  664. if (!pRC->GetSchedules()) {
  665. ASSERT(FALSE);
  666. return;
  667. }
  668. //====================================================
  669. pRC->GetSchedules()->RemoveAll();
  670. if (m_ctrlSchedulesAll.GetCheck()) {
  671. return;
  672. }
  673. //====================================================
  674. int nCount = m_ctrlSchedules.GetCount();
  675. for (int i = 0; i < nCount; i++)
  676. {
  677. int nCheck = m_ctrlSchedules.GetCheck(i);
  678. if (nCheck) 
  679. {
  680. UINT uSchID = (UINT)m_ctrlSchedules.GetItemData(i);
  681. pRC->GetSchedules()->Add(uSchID);
  682. }
  683. }
  684. }
  685. CXTPCalendarResourceDescription* CCalendarResourcesDlg::GetSelRCDesc(int* pnIndex) 
  686. {
  687. ASSERT(m_pRCMan);
  688. if (!m_pRCMan) {
  689. return NULL;
  690. }
  691. int nRCSel = m_ctrlResources.GetCurSel();
  692. if (nRCSel < 0 || nRCSel >= m_ctrlResources.GetCount()){
  693. return NULL;
  694. }
  695. CXTPCalendarResourceDescription* pRCDesc = (CXTPCalendarResourceDescription*)m_ctrlResources.GetItemData(nRCSel);
  696. if (pnIndex) {
  697. *pnIndex = nRCSel;
  698. }
  699. return pRCDesc;
  700. }
  701. void CCalendarResourcesDlg::ProcessAutoName()
  702. {
  703. CXTPCalendarResourceDescription* pRCDesc = GetSelRCDesc();
  704. if (!pRCDesc || !pRCDesc->m_ptrResource || 
  705. !pRCDesc->m_ptrResource->GetSchedules() )
  706. {
  707. return;
  708. }
  709. if (!pRCDesc->m_ptrResource->GetDataProvider() || 
  710. !pRCDesc->m_ptrResource->GetDataProvider()->GetSchedules()) 
  711. {
  712. m_ctrlRCNameAuto.SetCheck(0);
  713. ApplyUpdateRcNameAuto();
  714. m_ctrlRCNameAuto.EnableWindow(FALSE);
  715. return;
  716. }
  717. CString strNameNew = _CalcAutoRCName();
  718. BOOL bAutoName_enabled = !strNameNew.IsEmpty();
  719. m_ctrlRCNameAuto.EnableWindow(bAutoName_enabled);
  720. if (bAutoName_enabled) 
  721. {
  722. if (m_ctrlRCNameAuto.GetCheck() || m_nRcNameAuto_StoredState == 1)
  723. {
  724. m_nRcNameAuto_StoredState = -1;
  725. if (m_ctrlRCNameAuto.GetCheck() == 0) 
  726. {
  727. m_ctrlRCNameAuto.SetCheck(1); 
  728. ApplyUpdateRcNameAuto();
  729. }
  730. CString strNamePrev;
  731. m_ctrlRCName.GetWindowText(strNamePrev);
  732. if (strNameNew != strNamePrev) {
  733. m_ctrlRCName.SetWindowText(strNameNew);
  734. }
  735. }
  736. }
  737. else
  738. {
  739. if (m_nRcNameAuto_StoredState == -1) {
  740. m_nRcNameAuto_StoredState = m_ctrlRCNameAuto.GetCheck();
  741. }
  742. m_ctrlRCNameAuto.SetCheck(0);
  743. ApplyUpdateRcNameAuto();
  744. }
  745. }
  746. CString CCalendarResourcesDlg::_CalcAutoRCName() 
  747. {
  748. ASSERT(m_pRCMan);
  749. int nCount = m_ctrlSchedules.GetCount();
  750. if (m_ctrlSchedulesAll.GetCheck())
  751. {
  752. return _T("");
  753. }
  754.     // Automatic name calculation algorithm could be any of your choice.
  755. // There is implemented a simplest one with some redundancy
  756. int nCheckedCount = 0;
  757. CString strName;
  758. for (int i = 0; i < nCount; i++)
  759. {
  760. int nCheck = m_ctrlSchedules.GetCheck(i);
  761. if (nCheck) 
  762. {
  763. CString strText;
  764. m_ctrlSchedules.GetText(i, strText);
  765. nCheckedCount++;
  766. strName += strName.IsEmpty() ? _T("") : _T(", ");
  767. strName += strText;
  768. }
  769. }
  770. return nCheckedCount == 1 ? strName : _T("");
  771. }
  772. void CCalendarResourcesDlg::_OnSelchangeSchedules()
  773. {
  774. ApplySchedules();
  775. ProcessAutoName();
  776. int nSchSel = m_ctrlSchedules.GetCurSel();
  777. int nSchCount = m_ctrlSchedules.GetCount();
  778. if (nSchSel < 0 || nSchSel >= nSchCount) {
  779. return;
  780. }
  781. CString strSchName;
  782. m_ctrlSchedules.GetText(nSchSel, strSchName);
  783. m_ctrlScheduleNewName.SetWindowText(strSchName);
  784. }
  785. //////////////////////////////////////////////////////////////////////////
  786. BEGIN_MESSAGE_MAP(CCheckListBox_withEvents, CCheckListBox)
  787. ON_WM_LBUTTONDOWN()
  788. ON_WM_LBUTTONDBLCLK()
  789. ON_WM_KEYDOWN()
  790. END_MESSAGE_MAP()
  791. CCheckListBox_withEvents::CCheckListBox_withEvents() 
  792. {
  793. m_pParentDlg = NULL;
  794. m_nCheckLocked = -1;
  795. }
  796. void CCheckListBox_withEvents::setParentDlg(CCalendarResourcesDlg* pParentDlg) 
  797. {
  798. m_pParentDlg = pParentDlg;
  799. }
  800. void CCheckListBox_withEvents::OnLButtonDown(UINT nFlags, CPoint point)
  801. {
  802. CCheckListBox::OnLButtonDown(nFlags, point);
  803. _OnCheckChanged();
  804. }
  805. void CCheckListBox_withEvents::OnLButtonDblClk(UINT nFlags, CPoint point)
  806. {
  807. CCheckListBox::OnLButtonDblClk(nFlags, point);
  808. _OnCheckChanged();
  809. }
  810. void CCheckListBox_withEvents::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  811. {
  812. CCheckListBox::OnKeyDown(nChar, nRepCnt, nFlags);
  813. _OnCheckChanged();
  814. }
  815. void CCheckListBox_withEvents::_OnCheckChanged()
  816. {
  817. if (m_nCheckLocked >= 0) {
  818. AllSetCheck(m_nCheckLocked);
  819. }
  820. if (m_pParentDlg) {
  821. m_pParentDlg->_OnSelchangeSchedules();
  822. }
  823. }
  824. void CCheckListBox_withEvents::AllSetCheck(int nCheck)
  825. {
  826. int nCount = GetCount();
  827. for (int i = 0; i < nCount; i++)
  828. {
  829. int nCheck_i = GetCheck(i);
  830. if (nCheck != nCheck_i) 
  831. {
  832. SetCheck(i, nCheck);
  833. }
  834. }
  835. }
  836. void CCheckListBox_withEvents::LockAllCheckBoxes(int nCheckLocked)
  837. {
  838. m_nCheckLocked = nCheckLocked;
  839. if (m_nCheckLocked >= 0) {
  840. AllSetCheck(m_nCheckLocked);
  841. }
  842. }
  843. void CCheckListBox_withEvents::UnlockAllCheckBoxes(int nCheck)
  844. {
  845. int nLocked = m_nCheckLocked;
  846. m_nCheckLocked = -1;
  847. if (nLocked >= 0 && nCheck >= 0) {
  848. AllSetCheck(nCheck);
  849. }
  850. }