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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarEventPropertiesDlg.cpp: implementation of the CXTPCalendarEventPropertiesDlg.
  2. //
  3. // This file is a part of the XTREME CALENDAR 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 "Resource.h"
  22. #include "Common/XTPResourceManager.h"
  23. #include "Common/XTPVC50Helpers.h"
  24. #include "XTPCalendarEventPropertiesDlg.h"
  25. #include "XTPCalendarEventRecurrenceDlg.h"
  26. #include "XTPCalendarOccurSeriesChooseDlg.h"
  27. #include "XTPCalendarUtils.h"
  28. #include "XTPCalendarDefines.h"
  29. #include "XTPCalendarData.h"
  30. #include "XTPCalendarControl.h"
  31. #include "XTPCalendarView.h"
  32. #include "XTPCalendarViewDay.h"
  33. #include "XTPCalendarEventLabel.h"
  34. #include "XTPCalendarThemeOffice2007.h"
  35. #ifdef _DEBUG
  36. #define new DEBUG_NEW
  37. #undef THIS_FILE
  38. static char THIS_FILE[] = __FILE__;
  39. #endif
  40. IMPLEMENT_DYNAMIC(CXTPCalendarEventPropertiesDlg, CDialog)
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CXTPCalendarEventPropertiesDlg dialog
  43. BOOL XTPCalendarIsThemeOffice2007(CXTPCalendarControl* pCalendar)
  44. {
  45. ASSERT(pCalendar);
  46. if (!pCalendar || !pCalendar->GetTheme())
  47. return FALSE;
  48. CXTPCalendarThemeOffice2007* ptheme2007 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, pCalendar->GetTheme());
  49. return ptheme2007 != NULL;
  50. }
  51. CXTPCalendarEventCategoryComboBox::CXTPCalendarEventCategoryComboBox()
  52. {
  53. m_nLastKey = 0;
  54. m_pCategories = NULL;
  55. }
  56. CXTPCalendarEventCategoryComboBox::~CXTPCalendarEventCategoryComboBox()
  57. {
  58. CMDTARGET_RELEASE(m_pCategories);
  59. }
  60. BEGIN_MESSAGE_MAP(CXTPCalendarEventCategoryComboBox, CComboBox)
  61. //{{AFX_MSG_MAP(CXTPSyntaxEditColorComboBox)
  62. ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelChange)
  63. ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropDown)
  64. ON_WM_KEYDOWN()
  65. //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67. BOOL CXTPCalendarEventCategoryComboBox::Init(CXTPCalendarEventCategories* pCategories, CXTPCalendarEventCategoryIDs* pChecked)
  68. {
  69. ResetContent();
  70. if (!pCategories || !pChecked)
  71. {
  72. ASSERT(FALSE);
  73. return FALSE;
  74. }
  75. m_pCategories = pCategories;
  76. CMDTARGET_ADDREF(m_pCategories);
  77. int nCount = m_pCategories->GetCount();
  78. for (int i = 0; i < nCount; i++)
  79. {
  80. CXTPCalendarEventCategory* pCat = m_pCategories->GetAt(i);
  81. ASSERT(pCat);
  82. if (pCat)
  83. {
  84. int nIdx = AddString(pCat->GetName());
  85. SetItemDataPtr(nIdx, (void*)pCat);
  86. }
  87. }
  88. m_arChecked.RemoveAll();
  89. m_arChecked.Copy(*pChecked);
  90. return TRUE;
  91. }
  92. void CXTPCalendarEventCategoryComboBox::GetChecked(CXTPCalendarEventCategoryIDs* pChecked, BOOL* pbChanged)
  93. {
  94. if (!pChecked)
  95. return;
  96. if (pbChanged)
  97. {
  98. int nCount = m_arChecked.GetSize();
  99. if (nCount == pChecked->GetSize())
  100. {
  101. for (int i = 0; i < nCount; i++)
  102. {
  103. if (m_arChecked[i] != pChecked->GetAt(i))
  104. {
  105. *pbChanged |= TRUE;
  106. break;
  107. }
  108. }
  109. }
  110. else
  111. {
  112. *pbChanged |= TRUE;
  113. }
  114. }
  115. pChecked->RemoveAll();
  116. pChecked->Copy(m_arChecked);
  117. }
  118. void CXTPCalendarEventCategoryComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
  119. {
  120. ASSERT(lpMIS->CtlType == ODT_COMBOBOX);
  121. lpMIS->itemHeight = (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE)) + 4;
  122. lpMIS->itemWidth = 0;
  123. }
  124. void CXTPCalendarEventCategoryComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  125. {
  126. CDC*  pDC       = CDC::FromHandle(lpDIS->hDC);
  127. UINT  itemState = lpDIS->itemState;
  128. UINT  itemID    = lpDIS->itemID;
  129. CRect rcItem    = lpDIS->rcItem;
  130. if (!m_pCategories)
  131. return;
  132. BOOL bDisabled = ((itemState & ODS_DISABLED) == ODS_DISABLED);
  133. if((itemState & ODS_COMBOBOXEDIT) == ODS_COMBOBOXEDIT)
  134. {
  135. if (bDisabled)
  136. {
  137. pDC->SetTextColor(GetXtremeColor(COLOR_GRAYTEXT));
  138. pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
  139. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_3DFACE));
  140. }
  141. BOOL bCtrlFocused = GetFocus() == this;
  142. if (bCtrlFocused)
  143. {
  144. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_HIGHLIGHT));
  145. pDC->DrawFocusRect(&rcItem);
  146. }
  147. int nOffset = 0;
  148. int nCount = m_arChecked.GetSize();
  149. for (int i = 0; i < nCount; i++)
  150. {
  151. CXTPCalendarEventCategory* pCat = m_pCategories->Find(m_arChecked.GetAt(i));
  152. ASSERT(pCat);
  153. if (pCat)
  154. {
  155. // Draw category color
  156. CRect rcColor = rcItem;
  157. rcColor.left += nOffset;
  158. rcColor.right = rcColor.left + rcColor.Height();
  159. rcColor.DeflateRect(2, 2, 2, 2);
  160. nOffset += rcColor.Height() + 2;
  161. if (bCtrlFocused)
  162. {
  163. CRect rcColor2 = rcColor;
  164. rcColor2.InflateRect(1, 1, 1, 1);
  165. CXTPCalendarTheme::DrawRoundRect(pDC, rcColor2, RGB(255, 255, 255), TRUE, //NULL);
  166. CBrush::FromHandle((HBRUSH)GetStockObject(LTGRAY_BRUSH)));
  167. }
  168. CXTPCalendarTheme::DrawRoundRect(pDC, rcColor, pCat->GetBorderColor(), FALSE,
  169.  pCat->GetBackgroundColor());
  170. }
  171. }
  172. return;
  173. }
  174. if (itemID == (UINT)-1)
  175. return;
  176. CXTPCalendarEventCategory* pCat = (CXTPCalendarEventCategory*)GetItemDataPtr(itemID);
  177. ASSERT(pCat);
  178. if (!pCat)
  179. return;
  180. BOOL bFocus = ((itemState & ODS_FOCUS) == ODS_FOCUS);
  181. int nFIdx = m_arChecked.Find(pCat->GetID());
  182. pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
  183. // draw focus rectangle.
  184. if (bFocus)
  185. {
  186. pDC->SetTextColor(GetXtremeColor(COLOR_HIGHLIGHTTEXT));
  187. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_HIGHLIGHT));
  188. pDC->DrawFocusRect(&rcItem);
  189. }
  190. else if (nFIdx >= 0)
  191. {
  192. pDC->SetTextColor(GetXtremeColor(COLOR_BTNTEXT));
  193. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_BTNFACE));
  194. }
  195. else
  196. {
  197. pDC->SetTextColor(GetXtremeColor(COLOR_WINDOWTEXT));
  198. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_WINDOW));
  199. }
  200. // Draw category color
  201. CRect rcColor = rcItem;
  202. rcColor.right = rcColor.left + rcColor.Height();
  203. rcColor.DeflateRect(3, 3, 3, 3);
  204. if (nFIdx >= 0)
  205. {
  206. CRect rcColor2 = rcColor;
  207. rcColor2.InflateRect(1, 1, 1, 1);
  208. CXTPCalendarTheme::DrawRoundRect(pDC, rcColor2, RGB(255, 255, 255), TRUE, //NULL);
  209. CBrush::FromHandle((HBRUSH)GetStockObject(LTGRAY_BRUSH)));
  210. }
  211. CXTPCalendarTheme::DrawRoundRect(pDC, rcColor, pCat->GetBorderColor(), FALSE,
  212.  pCat->GetBackgroundColor());
  213. // draw text.
  214. CRect rText = rcItem;
  215. rText.left = rcColor.right;
  216. rText.DeflateRect(4, 2, 2, 1);
  217. pDC->SetBkMode(TRANSPARENT);
  218. pDC->DrawText(pCat->GetName(), rText, DT_LEFT | DT_VCENTER| DT_SINGLELINE);
  219. }
  220. int CXTPCalendarEventCategoryComboBox::GetLBCurSel() const
  221. {
  222. if (GetDroppedState() == TRUE)
  223. {
  224. HWND hWnd = ::FindWindow(_T("ComboLBox"), NULL);
  225. if (::IsWindow(hWnd))
  226. {
  227. return (int)::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
  228. }
  229. }
  230. return LB_ERR;
  231. }
  232. void CXTPCalendarEventCategoryComboBox::RedrawLB(BOOL bUpdateNow)
  233. {
  234. if (GetDroppedState() == TRUE)
  235. {
  236. HWND hWnd = ::FindWindow(_T("ComboLBox"), NULL);
  237. if (::IsWindow(hWnd))
  238. {
  239. if (bUpdateNow)
  240. ::UpdateWindow(hWnd);
  241. else
  242. ::InvalidateRect(hWnd, NULL, FALSE);
  243. }
  244. }
  245. }
  246. void CXTPCalendarEventCategoryComboBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  247. {
  248. if (nChar == VK_SPACE && GetDroppedState())
  249. {
  250. _OnSelChange(GetLBCurSel());
  251. Invalidate(FALSE);
  252. RedrawLB();
  253. m_nLastKey = nChar;
  254. return;
  255. }
  256. if (nChar == VK_RETURN && m_nLastKey == VK_SPACE)
  257. {
  258. ShowDropDown(FALSE);
  259. Invalidate(FALSE);
  260. return;
  261. }
  262. m_nLastKey = nChar;
  263. CComboBox::OnKeyDown(nChar, nRepCnt, nFlags);
  264. }
  265. void CXTPCalendarEventCategoryComboBox::OnDropDown()
  266. {
  267. SetCurSel(CB_ERR);
  268. m_nLastKey = 0;
  269. }
  270. void CXTPCalendarEventCategoryComboBox::OnSelChange()
  271. {
  272. if (GetDroppedState())
  273. _OnSelChange(GetCurSel());
  274. }
  275. void CXTPCalendarEventCategoryComboBox::_OnSelChange(int nItemIndex)
  276. {
  277. if (!m_pCategories || nItemIndex == CB_ERR || GetDroppedState() == FALSE)
  278. return;
  279. CXTPCalendarEventCategory* pCat = (CXTPCalendarEventCategory*)GetItemDataPtr(nItemIndex);
  280. ASSERT(pCat);
  281. if (!pCat)
  282. return;
  283. int nFIdx = m_arChecked.Find(pCat->GetID());
  284. if (nFIdx < 0)
  285. m_arChecked.InsertAt(0, pCat->GetID());
  286. else
  287. m_arChecked.RemoveAt(nFIdx);
  288. }
  289. /////////////////////////////////////////////////////////////////////////////
  290. CXTPCalendarEventLabelComboBox::CXTPCalendarEventLabelComboBox()
  291. {
  292. m_pLabels = NULL;
  293. }
  294. CXTPCalendarEventLabelComboBox::~CXTPCalendarEventLabelComboBox()
  295. {
  296. CMDTARGET_RELEASE(m_pLabels);
  297. }
  298. void CXTPCalendarEventLabelComboBox::Init(CXTPCalendarEventLabels*  pLabels)
  299. {
  300. ResetContent();
  301. ASSERT(pLabels);
  302. if (!pLabels)
  303. return;
  304. m_pLabels = pLabels;
  305. CMDTARGET_ADDREF(m_pLabels);
  306. for (int i = 0; i < m_pLabels->GetCount(); i++)
  307. {
  308. CXTPCalendarEventLabel* pLbl = m_pLabels->GetAt(i);
  309. ASSERT(pLbl);
  310. if (!pLbl)
  311. continue;
  312. int nIdx = AddString(pLbl->m_strName);
  313. SetItemData(nIdx, (DWORD_PTR)pLbl->m_nLabelID);
  314. }
  315. }
  316. int CXTPCalendarEventLabelComboBox::GetLabelID() const
  317. {
  318. if (GetCurSel() == CB_ERR)
  319. return XTP_IDS_CALENDAR_EVENT_LABEL_NONE;
  320. return (int)GetItemData(GetCurSel());
  321. }
  322. void CXTPCalendarEventLabelComboBox::SetLabelID(int nID)
  323. {
  324. for (int i = 0; i < GetCount(); i++)
  325. {
  326. if (nID == (int)GetItemData(i))
  327. {
  328. SetCurSel(i);
  329. return;
  330. }
  331. }
  332. SetCurSel(CB_ERR);
  333. }
  334. void CXTPCalendarEventLabelComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
  335. {
  336. ASSERT(lpMIS->CtlType == ODT_COMBOBOX);
  337. lpMIS->itemHeight = (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE));
  338. lpMIS->itemWidth = 0;
  339. }
  340. void CXTPCalendarEventLabelComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  341. {
  342. CDC*  pDC       = CDC::FromHandle(lpDIS->hDC);
  343. UINT  itemState = lpDIS->itemState;
  344. UINT  itemID    = lpDIS->itemID;
  345. CRect rcItem    = lpDIS->rcItem;
  346. if (itemID == (UINT)-1 || !m_pLabels)
  347. {
  348. return;
  349. }
  350. int nLabelID = (int)GetItemData(itemID);
  351. CXTPCalendarEventLabel* pLbl = m_pLabels->Find(nLabelID);
  352. if (!pLbl)
  353. return;
  354. BOOL bDisabled = ((itemState & ODS_DISABLED) == ODS_DISABLED);
  355. BOOL bSelected = ((itemState & ODS_SELECTED) == ODS_SELECTED);
  356. BOOL bFocus    = ((itemState & ODS_FOCUS)    == ODS_FOCUS);
  357. // draw background.
  358. if (bDisabled)
  359. {
  360. pDC->SetTextColor(GetXtremeColor(COLOR_GRAYTEXT));
  361. pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
  362. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_3DFACE));
  363. }
  364. else
  365. {
  366. if (bSelected)
  367. {
  368. pDC->SetTextColor(GetXtremeColor(COLOR_HIGHLIGHTTEXT));
  369. pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
  370. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_HIGHLIGHT));
  371. }
  372. else
  373. {
  374. pDC->SetTextColor(GetXtremeColor(COLOR_WINDOWTEXT));
  375. pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
  376. pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_WINDOW));
  377. }
  378. // draw focus rectangle.
  379. if (bFocus)
  380. {
  381. pDC->DrawFocusRect(&rcItem);
  382. }
  383. }
  384. // determine the size of the color rectangle.
  385. CRect rColor(rcItem);
  386. rColor.DeflateRect(2,2);
  387. rColor.right = rColor.left + rColor.Height();
  388. rColor.bottom = rColor.top + rColor.Height();
  389. // draw color rectangle.
  390. pDC->FillSolidRect(rColor,
  391. bDisabled? GetXtremeColor(COLOR_3DFACE): pLbl->m_clrColor);
  392. pDC->Draw3dRect(rColor,
  393. GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT),
  394. GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT));
  395. // determine the size of the text display.
  396. CRect rText(rColor);
  397. rText.top -= 2;
  398. rText.bottom = rText.top + (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE));
  399. rText.left = rText.right + 4;
  400. rText.right = rcItem.right;
  401. // draw text.
  402. pDC->SetBkMode(TRANSPARENT);
  403. pDC->DrawText(pLbl->m_strName, rText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
  404. }
  405. /////////////////////////////////////////////////////////////////////////////
  406. CXTPCalendarEventPropertiesDlg::CXTPCalendarEventPropertiesDlg(CXTPCalendarControl* pControl,
  407.  BOOL bAddEvent, CWnd* pParent,
  408.  CXTPCalendarEvent* pEditingEvent, UINT nIDTemplate)
  409. {
  410. InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(nIDTemplate), pParent);
  411. m_nAllDayEventSet = -1;
  412. m_bAddEvent = bAddEvent;
  413. m_bAllDayEvent = FALSE;
  414. m_bPrivate = FALSE;
  415. m_bMeeting = FALSE;
  416. m_bReminder = FALSE;
  417. m_nBusyStatus = xtpCalendarBusyStatusUnknown;
  418. m_bOccurrence = TRUE;
  419. CXTPCalendarData* pData = pControl ? pControl->GetDataProvider() : NULL;
  420. if (!pControl || !pData)
  421. {
  422. ASSERT(FALSE);
  423. return;
  424. }
  425. m_ptrControl = pControl;
  426. m_bCategoriesEnabled = XTPCalendarIsThemeOffice2007(m_ptrControl);
  427. m_ptrEditingEvent.SetPtr(pEditingEvent, TRUE);
  428. if (!pEditingEvent)
  429. {
  430. m_ptrEditingEvent = pData->CreateNewEvent();
  431. if (m_ptrEditingEvent)
  432. {
  433. CXTPCalendarView* pView = m_ptrControl->GetActiveView();
  434. ASSERT(pView);
  435. if (pView)
  436. {
  437. COleDateTime dtSelBegin, dtSelEnd;
  438. BOOL bAllDayEvent = FALSE;
  439. int nGroupIndex = 0;
  440. if (!pView->GetSelection(&dtSelBegin, &dtSelEnd, &bAllDayEvent, &nGroupIndex))
  441. {
  442. dtSelBegin = COleDateTime::GetCurrentTime();
  443. dtSelEnd = dtSelBegin + COleDateTimeSpan(0,1, 0,0);
  444. nGroupIndex = 0;
  445. }
  446. UINT uSchID = XTP_SAFE_GET3(pView, GetViewDay_(0), GetViewGroup_(nGroupIndex), GetScheduleID(), XTP_CALENDAR_UNKNOWN_SCHEDULE_ID);
  447. m_ptrEditingEvent->SetStartTime(min(dtSelBegin, dtSelEnd));
  448. m_ptrEditingEvent->SetEndTime(max(dtSelBegin, dtSelEnd));
  449. m_ptrEditingEvent->SetScheduleID(uSchID);
  450. m_nAllDayEventSet = bAllDayEvent ? 1 : 0;
  451. if (!bAllDayEvent)
  452. m_ptrEditingEvent->SetBusyStatus(xtpCalendarBusyStatusBusy);
  453. }
  454. }
  455. }
  456. if (m_ptrEditingEvent)
  457. {
  458. m_dtStartDate = m_ptrEditingEvent->GetStartTime();
  459. m_dtStartTime = m_dtStartDate;
  460. m_dtEndDate = m_ptrEditingEvent->GetEndTime();
  461. m_dtEndTime = m_dtEndDate;
  462. if (m_ptrEditingEvent->IsAllDayEvent() && CXTPCalendarUtils::IsZeroTime(m_dtEndDate))
  463. {
  464. AddEndDate_ResetTime(m_dtStartDate, m_dtEndDate, -1);
  465. }
  466. }
  467. }
  468. #if _MSC_VER < 1200
  469. AFX_INLINE void DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, COleDateTime& value)
  470. {
  471. HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
  472. if (pDX->m_bSaveAndValidate)
  473. CXTPDateTimeHelper::GetDateTimeCtrlTime(hWndCtrl, value);
  474. else
  475. CXTPDateTimeHelper::SetDateTimeCtrlTime(hWndCtrl, value);
  476. }
  477. #endif
  478. void CXTPCalendarEventPropertiesDlg::DoDataExchange(CDataExchange* pDX)
  479. {
  480. CDialog::DoDataExchange(pDX);
  481. DDX_Control(pDX, XTP_IDC_COMBO_SCHEDULEID, m_ctrlScheduleIDCB);
  482. DDX_Control(pDX, XTP_IDC_SCHEDULEID_TEXT, m_ctrlScheduleLabel);
  483. DDX_Control(pDX, XTP_IDC_COMBO_REMINDER, m_ctrlReminderCB);
  484. DDX_Control(pDX, XTP_IDC_COMBO_BUSYSTATE, m_ctrlBusyStatusCB);
  485. DDX_Text(pDX, XTP_IDC_EDIT_SUBJECT, m_strSubject);
  486. DDX_Text(pDX, XTP_IDC_EDIT_LOCATION, m_strLocation);
  487. DDX_Text(pDX, XTP_IDC_EDIT_BODY, m_strBody);
  488. DDX_DateTimeCtrl(pDX, XTP_IDC_DTP_START_DATE, m_dtStartDate);
  489. DDX_DateTimeCtrl(pDX, XTP_IDC_DTP_START_TIME, m_dtStartTime);
  490. DDX_DateTimeCtrl(pDX, XTP_IDC_DTP_END_DATE, m_dtEndDate);
  491. DDX_DateTimeCtrl(pDX, XTP_IDC_DTP_END_TIME, m_dtEndTime);
  492. DDX_CBIndex(pDX, XTP_IDC_COMBO_BUSYSTATE, m_nBusyStatus);
  493. DDX_Check(pDX, XTP_IDC_CHECK_ALLDAY_EVENT, m_bAllDayEvent);
  494. DDX_Check(pDX, XTP_IDC_CHECK_PRIVATE, m_bPrivate);
  495. DDX_Check(pDX, XTP_IDC_CHECK_MEETING, m_bMeeting);
  496. DDX_Check(pDX, XTP_IDC_CHECK_REMINDER, m_bReminder);
  497. }
  498. BEGIN_MESSAGE_MAP(CXTPCalendarEventPropertiesDlg, CDialog)
  499. ON_WM_CREATE()
  500. ON_BN_CLICKED(XTP_IDC_CHECK_REMINDER, OnCheckReminder)
  501. ON_BN_CLICKED(XTP_IDC_BUTTON_RECURRECNCE, OnBnClickedButtonRecurrecnce)
  502. ON_BN_CLICKED(XTP_IDC_CHECK_ALLDAY_EVENT, OnBnClickedCheckAlldayEvent)
  503. END_MESSAGE_MAP()
  504. /////////////////////////////////////////////////////////////////////////////
  505. // CXTPCalendarEventPropertiesDlg message handlers
  506. void CXTPCalendarEventPropertiesDlg::OnOK()
  507. {
  508. UpdateData();
  509. CString strReminder;
  510. m_ctrlReminderCB.GetWindowText(strReminder);
  511. int nReminderMinutes = CXTPCalendarUtils::ParceTimeDuration_min(strReminder);
  512. if (nReminderMinutes == INT_MIN)
  513. {
  514. m_ctrlReminderCB.SetFocus();
  515. XTPResourceManager()->ShowMessageBox(XTP_IDS_CALENDAR_WRONG_VALUE);
  516. return;
  517. }
  518. BOOL bChanged = FALSE;
  519. if (m_ptrEditingEvent->GetRecurrenceState() == xtpCalendarRecurrenceOccurrence)
  520. {
  521. VERIFY(m_ptrEditingEvent->MakeAsRException());
  522. }
  523. if (m_strSubject.Compare(m_ptrEditingEvent->GetSubject()))
  524. {
  525. m_ptrEditingEvent->SetSubject(m_strSubject);
  526. bChanged = TRUE;
  527. }
  528. if (m_strLocation.Compare(m_ptrEditingEvent->GetLocation()))
  529. {
  530. m_ptrEditingEvent->SetLocation(m_strLocation);
  531. bChanged = TRUE;
  532. }
  533. if (m_strBody.Compare(m_ptrEditingEvent->GetBody()))
  534. {
  535. m_ptrEditingEvent->SetBody(m_strBody);
  536. bChanged = TRUE;
  537. }
  538. if (m_bOccurrence)
  539. {
  540. COleDateTime dtStartTime(CXTPCalendarUtils::UpdateTime(m_dtStartDate,
  541.    m_dtStartTime));
  542. COleDateTime dtEndTime(CXTPCalendarUtils::UpdateTime(m_dtEndDate, m_dtEndTime));
  543. if (m_bAllDayEvent && CXTPCalendarUtils::IsZeroTime(m_dtEndDate))
  544. {
  545. AddEndDate_ResetTime(m_dtStartDate, dtEndTime, 1);
  546. }
  547. if (dtStartTime != m_ptrEditingEvent->GetStartTime())
  548. {
  549. m_ptrEditingEvent->SetStartTime(dtStartTime);
  550. bChanged = TRUE;
  551. }
  552. if (dtEndTime != m_ptrEditingEvent->GetEndTime())
  553. {
  554. m_ptrEditingEvent->SetEndTime(dtEndTime);
  555. bChanged = TRUE;
  556. }
  557. if (m_bAllDayEvent != m_ptrEditingEvent->IsAllDayEvent())
  558. {
  559. m_ptrEditingEvent->SetAllDayEvent(m_bAllDayEvent);
  560. bChanged = TRUE;
  561. }
  562. }
  563. else
  564. {
  565. //m_ptrEditingEvent->SetAllDayEvent(FALSE);
  566. m_ptrEditingEvent->SetAllDayEvent(m_bAllDayEvent);
  567. }
  568. if (m_nBusyStatus != m_ptrEditingEvent->GetBusyStatus())
  569. {
  570. m_ptrEditingEvent->SetBusyStatus(m_nBusyStatus);
  571. bChanged = TRUE;
  572. }
  573. if (m_bCategoriesEnabled)
  574. {
  575. m_ctrlCategories.GetChecked(m_ptrEditingEvent->GetCategories(), &bChanged);
  576. }
  577. else
  578. {
  579. if (m_ctrlLabelCB.GetLabelID() != m_ptrEditingEvent->GetLabelID())
  580. {
  581. m_ptrEditingEvent->SetLabelID(m_ctrlLabelCB.GetLabelID());
  582. bChanged = TRUE;
  583. }
  584. }
  585. if (m_bPrivate != m_ptrEditingEvent->IsPrivate())
  586. {
  587. m_ptrEditingEvent->SetPrivate(m_bPrivate);
  588. bChanged = TRUE;
  589. }
  590. if (m_bMeeting != m_ptrEditingEvent->IsMeeting())
  591. {
  592. m_ptrEditingEvent->SetMeeting(m_bMeeting);
  593. bChanged = TRUE;
  594. }
  595. if (m_bReminder != m_ptrEditingEvent->IsReminder())
  596. {
  597. m_ptrEditingEvent->SetReminder(m_bReminder);
  598. bChanged = TRUE;
  599. }
  600. if (m_bReminder)
  601. {
  602. if (nReminderMinutes != m_ptrEditingEvent->GetReminderMinutesBeforeStart())
  603. {
  604. m_ptrEditingEvent->SetReminderMinutesBeforeStart(nReminderMinutes);
  605. bChanged = TRUE;
  606. }
  607. }
  608. int nSelSch = m_ctrlScheduleIDCB.GetCurSel();
  609. if (nSelSch != CB_ERR)
  610. {
  611. UINT uSchID = (UINT)m_ctrlScheduleIDCB.GetItemData(nSelSch);
  612. if (uSchID != m_ptrEditingEvent->GetScheduleID())
  613. {
  614. m_ptrEditingEvent->SetScheduleID(uSchID);
  615. bChanged = TRUE;
  616. }
  617. }
  618. // Update event in data storage
  619. CXTPCalendarControl::CUpdateContext updateContext(m_ptrControl, xtpCalendarUpdateLayout | xtpCalendarUpdateRedraw);
  620. CXTPCalendarData* pData = m_ptrEditingEvent->GetDataProvider();
  621. if (m_bAddEvent)
  622. {
  623. VERIFY(pData->AddEvent(m_ptrEditingEvent));
  624. } else {
  625. VERIFY(pData->ChangeEvent(m_ptrEditingEvent));
  626. }
  627. m_ptrControl->Populate();
  628. CDialog::OnOK();
  629. }
  630. void CXTPCalendarEventPropertiesDlg::OnCancel()
  631. {
  632. CDialog::OnCancel();
  633. }
  634. void CXTPCalendarEventPropertiesDlg::UpdateControlsFromEvent()
  635. {
  636. ASSERT(m_ptrEditingEvent);
  637. m_strSubject = m_ptrEditingEvent->GetSubject();
  638. m_strLocation = m_ptrEditingEvent->GetLocation();
  639. m_strBody = m_ptrEditingEvent->GetBody();
  640. if (m_bCategoriesEnabled)
  641. {
  642. if (m_ptrEditingEvent->GetDataProvider())
  643. m_ctrlCategories.Init(m_ptrEditingEvent->GetDataProvider()->GetEventCategories(),
  644.   m_ptrEditingEvent->GetCategories());
  645. }
  646. else
  647. {
  648. if (m_ptrEditingEvent->GetDataProvider())
  649. m_ctrlLabelCB.Init(m_ptrEditingEvent->GetDataProvider()->GetLabelList());
  650. m_ctrlLabelCB.SetLabelID(m_ptrEditingEvent->GetLabelID());
  651. }
  652. if (m_nAllDayEventSet < 0)
  653. {
  654. m_bAllDayEvent = m_ptrEditingEvent->IsAllDayEvent();
  655. }
  656. else
  657. {
  658. m_bAllDayEvent = m_nAllDayEventSet != 0;
  659. if (m_bAllDayEvent && CXTPCalendarUtils::IsZeroTime(m_dtEndDate))
  660. {
  661. AddEndDate_ResetTime(m_dtStartDate, m_dtEndDate, -1);
  662. }
  663. }
  664. m_bPrivate = m_ptrEditingEvent->IsPrivate();
  665. m_bMeeting = m_ptrEditingEvent->IsMeeting();
  666. m_nBusyStatus = m_ptrEditingEvent->GetBusyStatus();
  667. m_bReminder = m_ptrEditingEvent->IsReminder();
  668. int nMinutes = m_ptrEditingEvent->GetReminderMinutesBeforeStart();
  669. CString strReminder = CXTPCalendarUtils::FormatTimeDuration(nMinutes, FALSE);
  670. m_ctrlReminderCB.SetWindowText(strReminder);
  671. //-----------------------------------------------
  672. CXTPCalendarSchedules* pSchedules = m_ptrEditingEvent->GetDataProvider()->GetSchedules();
  673. ASSERT(pSchedules);
  674. BOOL bSchEnabled = pSchedules && pSchedules->GetCount();
  675. m_ctrlScheduleIDCB.EnableWindow(bSchEnabled);
  676. m_ctrlScheduleLabel.EnableWindow(bSchEnabled);
  677. if (pSchedules)
  678. {
  679. m_ctrlScheduleIDCB.ResetContent();
  680. int nIdx = m_ctrlScheduleIDCB.AddString(_T("-"));
  681. m_ctrlScheduleIDCB.SetItemData(nIdx, (DWORD_PTR)XTP_CALENDAR_UNKNOWN_SCHEDULE_ID);
  682. int nCount = pSchedules->GetCount();
  683. for (int nSchNr = 0; nSchNr < nCount; nSchNr++)
  684. {
  685. CXTPCalendarSchedule* pSch = pSchedules->GetAt(nSchNr);
  686. ASSERT(pSch);
  687. if (pSch)
  688. {
  689. nIdx = m_ctrlScheduleIDCB.AddString(pSch->GetName());
  690. m_ctrlScheduleIDCB.SetItemData(nIdx, (DWORD_PTR)pSch->GetID());
  691. }
  692. }
  693. UINT uSchID = m_ptrEditingEvent->GetScheduleID();
  694. nCount = m_ctrlScheduleIDCB.GetCount();
  695. if (m_bAddEvent && nCount)
  696. {
  697. m_ctrlScheduleIDCB.SetCurSel(0);
  698. }
  699. for (int nSchIDCS = 0; nSchIDCS < nCount; nSchIDCS++)
  700. {
  701. if (m_ctrlScheduleIDCB.GetItemData(nSchIDCS) == uSchID)
  702. {
  703. m_ctrlScheduleIDCB.SetCurSel(nSchIDCS);
  704. break;
  705. }
  706. }
  707. }
  708. UpdateData(FALSE);
  709. }
  710. void CXTPCalendarEventPropertiesDlg::UpdateControlsState()
  711. {
  712. if (GetDlgItem(XTP_IDC_DTP_START_DATE))
  713. {
  714. GetDlgItem(XTP_IDC_DTP_START_DATE)->ShowWindow(m_bOccurrence ? SW_SHOW : SW_HIDE);
  715. }
  716. if (GetDlgItem(XTP_IDC_DTP_START_TIME))
  717. {
  718. GetDlgItem(XTP_IDC_DTP_START_TIME)->ShowWindow(m_bOccurrence && !m_bAllDayEvent ? SW_SHOW : SW_HIDE);
  719. }
  720. if (GetDlgItem(XTP_IDC_DTP_END_DATE))
  721. {
  722. GetDlgItem(XTP_IDC_DTP_END_DATE)->ShowWindow(m_bOccurrence ? SW_SHOW : SW_HIDE);
  723. }
  724. if (GetDlgItem(XTP_IDC_DTP_END_TIME))
  725. {
  726. GetDlgItem(XTP_IDC_DTP_END_TIME)->ShowWindow(m_bOccurrence && !m_bAllDayEvent ? SW_SHOW : SW_HIDE);
  727. }
  728. if (GetDlgItem(XTP_IDC_START_TEXT))
  729. {
  730. GetDlgItem(XTP_IDC_START_TEXT)->ShowWindow(m_bOccurrence ? SW_SHOW : SW_HIDE);
  731. }
  732. if (GetDlgItem(XTP_IDC_END_TEXT))
  733. {
  734. GetDlgItem(XTP_IDC_END_TEXT)->ShowWindow(m_bOccurrence ? SW_SHOW : SW_HIDE);
  735. }
  736. //  if (GetDlgItem(XTP_IDC_CHECK_ALLDAY_EVENT))
  737. //  {
  738. //      GetDlgItem(XTP_IDC_CHECK_ALLDAY_EVENT)->ShowWindow(m_bOccurrence ? SW_SHOW : SW_HIDE);
  739. //  }
  740. m_ctrlReminderCB.EnableWindow(m_bReminder);
  741. }
  742. void CXTPCalendarEventPropertiesDlg::InitReminderComboBox()
  743. {
  744. m_ctrlReminderCB.ResetContent();
  745. m_ctrlReminderCB.AddString(LoadString(XTP_IDS_CALENDAR_MINUTES_0));
  746. m_ctrlReminderCB.AddString(LoadString(XTP_IDS_CALENDAR_MINUTES_1));
  747. m_ctrlReminderCB.AddString(LoadString(XTP_IDS_CALENDAR_MINUTES_5));
  748. m_ctrlReminderCB.AddString(LoadString(XTP_IDS_CALENDAR_MINUTES_10));
  749. m_ctrlReminderCB.AddString(LoadString(XTP_IDS_CALENDAR_MINUTES_15));
  750. }
  751. void CXTPCalendarEventPropertiesDlg::InitBusyStatusComboBox()
  752. {
  753. m_ctrlBusyStatusCB.ResetContent();
  754. m_ctrlBusyStatusCB.AddString(LoadString(XTP_IDS_CALENDAR_TIME_STATUS_FREE));
  755. m_ctrlBusyStatusCB.AddString(LoadString(XTP_IDS_CALENDAR_TIME_STATUS_TENTATIVE));
  756. m_ctrlBusyStatusCB.AddString(LoadString(XTP_IDS_CALENDAR_TIME_STATUS_BUSY));
  757. m_ctrlBusyStatusCB.AddString(LoadString(XTP_IDS_CALENDAR_TIME_STATUS_OUTOFOFFICE));
  758. }
  759. BOOL CXTPCalendarEventPropertiesDlg::OnInitDialog()
  760. {
  761. CDialog::OnInitDialog();
  762. if (m_bCategoriesEnabled)
  763. {
  764. m_ctrlCategories.SubclassDlgItem(XTP_IDC_COMBO_LABEL, this);
  765. if (GetDlgItem(XTP_IDC_LABEL))
  766. {
  767. CString str = XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_CATEGORIES_LABEL);
  768. GetDlgItem(XTP_IDC_LABEL)->SetWindowText(str + _T(":"));
  769. }
  770. }
  771. else
  772. {
  773. m_ctrlLabelCB.SubclassDlgItem(XTP_IDC_COMBO_LABEL, this);
  774. }
  775. InitReminderComboBox();
  776. InitBusyStatusComboBox();
  777. UpdateControlsFromEvent();
  778. UpdateControlsState();
  779. return TRUE;  // return TRUE unless you set the focus to a control
  780. // EXCEPTION: OCX Property Pages should return FALSE
  781. }
  782. void CXTPCalendarEventPropertiesDlg::OnBnClickedButtonRecurrecnce()
  783. {
  784. UpdateData();
  785. BOOL bWasNotRecur = FALSE;
  786. BOOL bUpdateFromEvent = FALSE;
  787. CXTPCalendarEventPtr ptrMasterEvent = m_ptrEditingEvent;
  788. int nRState = ptrMasterEvent->GetRecurrenceState();
  789. if (nRState != xtpCalendarRecurrenceMaster)
  790. {
  791. ptrMasterEvent = m_ptrEditingEvent->CloneEvent();
  792. if (nRState == xtpCalendarRecurrenceNotRecurring)
  793. {
  794. VERIFY(ptrMasterEvent->MakeEventAsRecurrence());
  795. bWasNotRecur = TRUE;
  796. CXTPCalendarRecurrencePatternPtr ptrPattern;
  797. ptrPattern = ptrMasterEvent->GetRecurrencePattern();
  798. COleDateTime dtStartDateTime(CXTPCalendarUtils::UpdateTime(m_dtStartDate, m_dtStartTime));
  799. COleDateTime dtEndDateTime(CXTPCalendarUtils::UpdateTime(m_dtEndDate, m_dtEndTime));
  800. COleDateTimeSpan spDuration = dtEndDateTime- dtStartDateTime;
  801. ptrPattern->SetStartTime(CXTPCalendarUtils::ResetDate(m_dtStartTime));
  802. ptrPattern->SetDurationMinutes((int) spDuration.GetTotalMinutes());
  803. ptrPattern->SetPatternStartDate(CXTPCalendarUtils::ResetTime(m_dtStartDate));
  804. ptrMasterEvent->UpdateRecurrence(ptrPattern);
  805. }
  806. else
  807. {
  808. bUpdateFromEvent = TRUE;
  809. ASSERT(nRState == xtpCalendarRecurrenceOccurrence ||
  810.    nRState == xtpCalendarRecurrenceException);
  811. CXTPCalendarRecurrencePatternPtr ptrPattern;
  812. ptrPattern = m_ptrEditingEvent->GetRecurrencePattern();
  813. ptrMasterEvent = ptrPattern->GetMasterEvent();
  814. }
  815. }
  816. CXTPCalendarEventRecurrenceDlg dlg(ptrMasterEvent, this);
  817. dlg.m_bDisableRemove = bWasNotRecur;
  818. int nRes = (int)dlg.DoModal();
  819. if (nRes == IDOK || nRes == XTP_CALENDAR_DLGRESULT_REMOVE_RECURRENCE)
  820. {
  821. m_ptrEditingEvent = ptrMasterEvent;
  822. m_bOccurrence = m_ptrEditingEvent->GetRecurrenceState() ==
  823. xtpCalendarRecurrenceNotRecurring;
  824. if (bUpdateFromEvent)
  825. {
  826. UpdateData();
  827. UpdateControlsFromEvent();
  828. }
  829. UpdateControlsState();
  830. }
  831. }
  832. int CXTPCalendarEventPropertiesDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  833. {
  834. if (CDialog::OnCreate(lpCreateStruct) == -1)
  835. return -1;
  836. int nType = m_ptrEditingEvent->GetRecurrenceState();
  837. if (nType == xtpCalendarRecurrenceOccurrence || nType == xtpCalendarRecurrenceException)
  838. {
  839. CXTPCalendarOccurSeriesChooseDlg dlg(0, XTP_IDS_CALENDAR_OCURR_SERIES_OPEN);
  840. dlg.SetEvent(m_ptrEditingEvent);
  841. if (dlg.DoModal() != IDOK)
  842. return -1;
  843. m_bOccurrence = dlg.m_bOccur;
  844. if (!m_bOccurrence)
  845. {
  846. CXTPCalendarRecurrencePatternPtr ptrPatternRO;
  847. ptrPatternRO = m_ptrEditingEvent->GetRecurrencePattern();
  848. CXTPCalendarEventPtr ptrMasterRO = ptrPatternRO->GetMasterEvent();
  849. m_ptrEditingEvent = ptrMasterRO->CloneEvent();
  850. }
  851. }
  852. return 0;
  853. }
  854. void CXTPCalendarEventPropertiesDlg::OnBnClickedCheckAlldayEvent()
  855. {
  856. UpdateData();
  857. UpdateControlsState();
  858. if (m_bAllDayEvent && CXTPCalendarUtils::IsZeroTime(m_dtEndTime))
  859. {
  860. AddEndDate_ResetTime(m_dtStartDate, m_dtEndDate, -1);
  861. UpdateData(FALSE);
  862. }
  863. else if (!m_bAllDayEvent && CXTPCalendarUtils::IsZeroTime(m_dtEndTime))
  864. {
  865. AddEndDate_ResetTime(m_dtStartDate, m_dtEndDate, 1);
  866. UpdateData(FALSE);
  867. }
  868. }
  869. void CXTPCalendarEventPropertiesDlg::OnCheckReminder()
  870. {
  871. UpdateData();
  872. UpdateControlsState();
  873. }
  874. void CXTPCalendarEventPropertiesDlg::AddEndDate_ResetTime(COleDateTime dtStartDate, COleDateTime& rdtEndDate, int nDays)
  875. {
  876. COleDateTimeSpan spDiff = CXTPCalendarUtils::ResetTime(rdtEndDate) -
  877. CXTPCalendarUtils::ResetTime(dtStartDate);
  878. if (nDays > 0 || nDays < 0 && (DWORD)(double)spDiff >= (DWORD)(-1 * nDays) )
  879. {
  880. rdtEndDate = CXTPCalendarUtils::ResetTime(rdtEndDate) + COleDateTimeSpan(nDays,0,0,0);
  881. }
  882. }