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

对话框与窗口

开发平台:

Visual C++

  1. // AdvancedCalendarOptionsDlg.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 "AdvancedCalendarOptionsDlg.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CAdvancedCalendarOptionsDlg dialog
  30. CAdvancedCalendarOptionsDlg::CAdvancedCalendarOptionsDlg(CXTPCalendarControl* pCalendar, CWnd* pParent /*=NULL*/)
  31. : CDialog(CAdvancedCalendarOptionsDlg::IDD, pParent)
  32. {
  33. ASSERT(pCalendar);
  34. m_pCalendar = pCalendar;
  35. //{{AFX_DATA_INIT(CAdvancedCalendarOptionsDlg)
  36. // NOTE: the ClassWizard will add member initialization here
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAdvancedCalendarOptionsDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAdvancedCalendarOptionsDlg)
  43. DDX_Control(pDX, IDC_RADIO_THEME_OFFICE_2007, m_ctrlThemeOffice2007);
  44. DDX_Control(pDX, IDC_RADIO_THEME_OFFICE_2003, m_ctrlThemeOffice2003);
  45. DDX_Control(pDX, IDC_COMBO_THEME_DEFAULT_COLOR, m_ctrlThemeColor);
  46. DDX_Control(pDX, IDC_STATIC_THEME_DEFAULT_COLOR, m_ctrlThemeColorLable);
  47. DDX_Control(pDX, IDC_CHECK_ENABLE_THEMES, m_ctrlEnableThemes);
  48. DDX_Control(pDX, IDC_CHECK_MARKUP, m_ctrlEnableMarkup);
  49. DDX_Control(pDX, IDC_CHECK_GETTEXT, m_ctrlEnableGetText);
  50. DDX_Control(pDX, IDC_CHECK_EDIT_SUBJECT_BY_TAB, m_ctrlEditSubject_ByTAB);
  51. DDX_Control(pDX, IDC_CHECK_EDIT_SUBJECT_BY_MOUSE_CLICK, m_ctrlEditSubject_ByMouseClick);
  52. DDX_Control(pDX, IDC_CHECK_EDIT_SUBJECT_BY_F2, m_ctrlEditSubject_ByF2);
  53. DDX_Control(pDX, IDC_CHECK_EDIT_SUBJECT_AFTER_RESIZE, m_ctrlEditSubject_AfterResize);
  54. DDX_Control(pDX, IDC_CHECK_CREATE_EVENT, m_ctrlInPlaceCreateEvent);
  55. DDX_Control(pDX, IDC_CHECK_OUTLOOKFONTGLYPHS, m_ctrlUseOutlookFontGlyphs);
  56. DDX_Control(pDX, IDC_CHECK_SHOW_TSMINUTES, m_ctrlShowTSMinutes);
  57. DDX_Control(pDX, IDC_CHECK_REMINDERS, m_ctrlReminders);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CAdvancedCalendarOptionsDlg, CDialog)
  61. //{{AFX_MSG_MAP(CAdvancedCalendarOptionsDlg)
  62. ON_BN_CLICKED(IDC_CHECK_ENABLE_THEMES, OnCheckEnableThemes)
  63. ON_BN_CLICKED(IDC_RADIO_THEME_OFFICE_2007, OnRadioThemeOffice2007)
  64. ON_BN_CLICKED(IDC_RADIO_THEME_OFFICE_2003, OnRadioThemeOffice2003)
  65. //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CAdvancedCalendarOptionsDlg message handlers
  69. void CAdvancedCalendarOptionsDlg::OnOK() 
  70. {
  71. CXTPCalendarOptions* pOptions = m_pCalendar ? m_pCalendar->GetCalendarOptions() : NULL;
  72. if (!m_pCalendar || !pOptions) {
  73. ASSERT(FALSE);
  74. return;
  75. }
  76. pOptions->bUseOutlookFontGlyphs = m_ctrlUseOutlookFontGlyphs.GetCheck() ? TRUE : FALSE;
  77. pOptions->bDayView_TimeScaleShowMinutes = m_ctrlShowTSMinutes.GetCheck() ? TRUE : FALSE;
  78. pOptions->bEnableInPlaceCreateEvent = m_ctrlInPlaceCreateEvent.GetCheck() ? TRUE : FALSE;
  79. pOptions->bEnableInPlaceEditEventSubject_ByF2 = m_ctrlEditSubject_ByF2.GetCheck() ? TRUE : FALSE;
  80. pOptions->bEnableInPlaceEditEventSubject_ByMouseClick = m_ctrlEditSubject_ByMouseClick.GetCheck() ? TRUE : FALSE;
  81. pOptions->bEnableInPlaceEditEventSubject_ByTab = m_ctrlEditSubject_ByTAB.GetCheck() ? TRUE : FALSE;
  82. pOptions->bEnableInPlaceEditEventSubject_AfterEventResize = m_ctrlEditSubject_AfterResize.GetCheck() ? TRUE : FALSE;
  83. pOptions->OnOptionsChanged();
  84. m_pCalendar->EnableReminders(m_ctrlReminders.GetCheck() ? TRUE : FALSE);
  85. //===========================
  86. int nEnableThemes = m_ctrlEnableThemes.GetCheck();
  87. if (nEnableThemes)
  88. {
  89. if (m_ctrlThemeOffice2007.GetCheck())
  90. {
  91. CXTPCalendarThemeOffice2007* pTheme2007 = new CXTPCalendarThemeOffice2007();
  92. if (pTheme2007) {
  93. pTheme2007->m_clrBaseColor = m_ctrlThemeColor.GetSelectedColor();
  94. }
  95. m_pCalendar->SetTheme(pTheme2007);
  96. UINT arIDs[5];
  97. arIDs[0] = (UINT)xtpCalendarEventIconIDReminder;
  98. arIDs[1] = (UINT)xtpCalendarEventIconIDOccurrence;
  99. arIDs[2] = (UINT)xtpCalendarEventIconIDException;
  100. arIDs[3] = (UINT)xtpCalendarEventIconIDMeeting;
  101. arIDs[4] = (UINT)xtpCalendarEventIconIDPrivate;
  102. pTheme2007->GetCustomIconsList()->SetIcons(XTP_IDB_CALENDAR_EVENT_GLYPHS, 
  103. arIDs, 5, CSize(16, 11), xtpImageNormal);
  104. m_pCalendar->EnableMarkup(m_ctrlEnableMarkup.GetCheck() ? TRUE : FALSE);
  105. pTheme2007->SetAskItemTextFlags(m_ctrlEnableGetText.GetCheck() ? -1 : 0);
  106. }
  107. //else if (m_ctrlThemeOffice2003.GetCheck())
  108. //{
  109. // CXTPCalendarThemeOffice2003* pTheme2003 = new CXTPCalendarThemeOffice2003();
  110. // if (pTheme2003) {
  111. // pTheme2003->m_clrBaseColor = m_ctrlThemeColor.GetSelectedColor();
  112. // }
  113. // m_pCalendar->SetTheme(pTheme2003);
  114. //}
  115. else {
  116. ASSERT(FALSE);
  117. }
  118. }
  119. else {
  120. m_pCalendar->SetTheme(NULL);
  121. }
  122. //---------------------------
  123. m_pCalendar->Populate();
  124. CDialog::OnOK();
  125. }
  126. BOOL CAdvancedCalendarOptionsDlg::OnInitDialog() 
  127. {
  128. CDialog::OnInitDialog();
  129. CXTPCalendarOptions* pOptions = m_pCalendar ? m_pCalendar->GetCalendarOptions() : NULL;
  130. if (!m_pCalendar || !pOptions) {
  131. ASSERT(FALSE);
  132. return FALSE;
  133. }
  134. m_ctrlReminders .SetCheck(m_pCalendar->IsRemindersEnabled() ? 1:0);
  135. m_ctrlEnableMarkup .SetCheck(m_pCalendar->IsMarkupEnabled() ? 1:0);
  136. m_ctrlUseOutlookFontGlyphs .SetCheck(pOptions->bUseOutlookFontGlyphs ? 1:0);
  137. m_ctrlShowTSMinutes .SetCheck(pOptions->bDayView_TimeScaleShowMinutes ? 1:0);
  138. m_ctrlInPlaceCreateEvent .SetCheck(pOptions->bEnableInPlaceCreateEvent?1:0);
  139. m_ctrlEditSubject_ByF2 .SetCheck(pOptions->bEnableInPlaceEditEventSubject_ByF2?1:0);
  140. m_ctrlEditSubject_ByMouseClick .SetCheck(pOptions->bEnableInPlaceEditEventSubject_ByMouseClick?1:0);
  141. m_ctrlEditSubject_ByTAB .SetCheck(pOptions->bEnableInPlaceEditEventSubject_ByTab?1:0);
  142. m_ctrlEditSubject_AfterResize .SetCheck(pOptions->bEnableInPlaceEditEventSubject_AfterEventResize?1:0);
  143. // Themes 
  144. CXTPCalendarTheme* pTheme = m_pCalendar->GetTheme();
  145. //CXTPCalendarThemeOffice2007* pTheme2007 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, pTheme);
  146. m_ctrlEnableThemes.SetCheck(pTheme != NULL);
  147. InitThemeColors();
  148. OnCheckEnableThemes();
  149. if (pTheme)
  150. {
  151. m_ctrlThemeColor.SelectColor(pTheme->m_clrBaseColor);
  152. m_ctrlEnableGetText.SetCheck(pTheme->GetAskItemTextFlags() ? 1:0);
  153. }
  154. return TRUE;  // return TRUE unless you set the focus to a control
  155.               // EXCEPTION: OCX Property Pages should return FALSE
  156. }
  157. void CAdvancedCalendarOptionsDlg::OnCheckEnableThemes() 
  158. {
  159. CXTPCalendarTheme* pTheme = m_pCalendar->GetTheme();
  160. //CXTPCalendarThemeOffice2003* pTheme2003 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2003, pTheme);
  161. CXTPCalendarTheme* pTheme2003 = NULL;
  162. CXTPCalendarThemeOffice2007* pTheme2007 = DYNAMIC_DOWNCAST(CXTPCalendarThemeOffice2007, pTheme);
  163. int nEnable = m_ctrlEnableThemes.GetCheck();
  164. m_ctrlThemeOffice2003.EnableWindow(FALSE); //nEnable != 0);
  165. m_ctrlThemeOffice2007.EnableWindow(nEnable != 0);
  166. m_ctrlThemeColor  .EnableWindow(nEnable != 0);
  167. m_ctrlThemeColorLable.EnableWindow(nEnable != 0);
  168. m_ctrlEnableMarkup   .EnableWindow(nEnable != 0);
  169. m_ctrlEnableGetText  .EnableWindow(nEnable != 0);
  170. m_ctrlThemeOffice2003.SetCheck(pTheme2003 != NULL);
  171. m_ctrlThemeOffice2007.SetCheck(pTheme2007 != NULL || !pTheme2003 && !pTheme2007);
  172. }
  173. void CAdvancedCalendarOptionsDlg::OnRadioThemeOffice2007() 
  174. {
  175. // TODO: Add your control notification handler code here
  176. }
  177. void CAdvancedCalendarOptionsDlg::OnRadioThemeOffice2003() 
  178. {
  179. // TODO: Add your control notification handler code here
  180. }
  181. void CAdvancedCalendarOptionsDlg::InitThemeColors() 
  182. {
  183. for (int i = 0; i < 15; i++) 
  184. {
  185. m_ctrlThemeColor.AddString(_T(""));
  186. }
  187. m_ctrlThemeColor.SetItemData(0, RGB(93, 140, 201));
  188. m_ctrlThemeColor.SetItemData(1, RGB(114, 164, 90));
  189. m_ctrlThemeColor.SetItemData(2, RGB(190, 104, 134));
  190. m_ctrlThemeColor.SetItemData(3, RGB(90, 164, 164));
  191. m_ctrlThemeColor.SetItemData(4, RGB(113, 113, 205));
  192. m_ctrlThemeColor.SetItemData(5, RGB(92, 166, 116));
  193. m_ctrlThemeColor.SetItemData(6, RGB(93, 105, 105));
  194. m_ctrlThemeColor.SetItemData(7, RGB(157, 157, 87));
  195. m_ctrlThemeColor.SetItemData(8, RGB(140, 110, 200));
  196. m_ctrlThemeColor.SetItemData(9, RGB(169, 143, 93));
  197. m_ctrlThemeColor.SetItemData(10, RGB(90, 164, 140));
  198. m_ctrlThemeColor.SetItemData(11, RGB(97, 151, 177));
  199. m_ctrlThemeColor.SetItemData(12, RGB(139, 139, 139));
  200. m_ctrlThemeColor.SetItemData(13, RGB(255, 209, 81));
  201. //m_ctrlThemeColor.SetItemData(14, RGB(105, 133, 189));
  202. m_ctrlThemeColor.SetItemData(14, RGB(145, 153, 164));
  203. m_ctrlThemeColor.SetCurSel(0);
  204. }
  205. void CComboBoxColors::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  206. {
  207. ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
  208. CDC dc;
  209. dc.Attach(lpDrawItemStruct->hDC);
  210. COLORREF clrBk = (COLORREF)lpDrawItemStruct->itemData;
  211. dc.FillSolidRect(&lpDrawItemStruct->rcItem, clrBk);
  212. if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
  213.   (lpDrawItemStruct->itemState  & ODS_SELECTED))
  214. {
  215. CBrush brFrame(RGB(0,0,0));
  216. dc.FrameRect(&lpDrawItemStruct->rcItem, &brFrame);
  217. }
  218. dc.Detach();
  219. }
  220. void CComboBoxColors::SelectColor(COLORREF clrColor)
  221. {
  222. for (int i = 0; i < GetCount(); i++)
  223. {
  224. if (clrColor == (COLORREF)GetItemData(i)) {
  225. SetCurSel(i);
  226. return;
  227. }
  228. }
  229. }
  230. COLORREF CComboBoxColors::GetSelectedColor(int nDefaultColorIndex)
  231. {
  232. COLORREF clrColor = (COLORREF)-1;
  233. int nSel = GetCurSel();
  234. if (nSel == CB_ERR) {
  235. nSel = nDefaultColorIndex;
  236. }
  237. if (nSel >= 0 && nSel < GetCount()) {
  238. clrColor = (COLORREF)GetItemData(nSel);
  239. }
  240. return clrColor;
  241. }