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

对话框与窗口

开发平台:

Visual C++

  1. // OptionsDialogBar.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 "OptionsDialogBar.h"
  23. #include "CalendarDemoView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // COptionsDialogBar dialog
  31. COptionsDialogBar::COptionsDialogBar(CWnd* /*pParent =NULL*/)
  32. {
  33. //{{AFX_DATA_INIT(COptionsDialogBar)
  34. // NOTE: the ClassWizard will add member initialization here
  35. //}}AFX_DATA_INIT
  36. }
  37. COptionsDialogBar::~COptionsDialogBar()
  38. {
  39. m_Sink.UnadviseAll();
  40. }
  41. void COptionsDialogBar::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialogBar::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(COptionsDialogBar)
  45. // NOTE: the ClassWizard will add DDX and DDV calls here
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(COptionsDialogBar, CDialogBar)
  49. //{{AFX_MSG_MAP(COptionsDialogBar)
  50. ON_WM_CTLCOLOR()
  51. //}}AFX_MSG_MAP
  52. ON_MESSAGE_VOID(WM_INITDIALOG, OnInitDialog)
  53. ON_BN_CLICKED(IDD_MONTH_COMPRESS_WEEKEND_DAYS, OnBnClickedMonthCompressWeekendDays)
  54. ON_BN_CLICKED(IDD_MONTH_SHOW_END_TIME, OnBnClickedMonthShowEndTime)
  55. ON_BN_CLICKED(IDD_MONTH_SHOW_TIME_AS_CLOCKS, OnBnClickedMonthSchowTimeAsClock)
  56. ON_CBN_SELCHANGE(IDC_FIRST_DAY_OF_WEEK_CB, OnCbnSelchangeFirstDayOfWeekCb)
  57. ON_CBN_SELCHANGE(IDD_MONTH_WEEKS_COUNT, OnCbnSelchangeMonthWeeksCount)
  58. ON_CBN_SELCHANGE(IDC_TIME_SCALE, OnCbnSelchangeTimeScale)
  59. ON_BN_CLICKED(IDD_WEEK_SHOW_TIME_AS_CLOCK, OnBnClickedWeekSchowTimeAsClock)
  60. ON_BN_CLICKED(IDD_WEEK_SHOW_END_TIME, OnBnClickedWeekShowEndTime)
  61. ON_CBN_SELCHANGE(IDC_START_TIME_CB, OnCbnSelchangeStartTimeCb)
  62. ON_CBN_SELCHANGE(IDC_END_TIME_CB, OnCbnSelchangeEndTimeCb)
  63. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_SU, OnBnClickedWorkWeekDay)
  64. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_MO, OnBnClickedWorkWeekDay)
  65. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_TU, OnBnClickedWorkWeekDay)
  66. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_WE, OnBnClickedWorkWeekDay)
  67. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_TH, OnBnClickedWorkWeekDay)
  68. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_FR, OnBnClickedWorkWeekDay)
  69. ON_BN_CLICKED(IDC_WORK_WEEK_DAY_SA, OnBnClickedWorkWeekDay)
  70. ON_CBN_SELCHANGE(IDC_TOOLTIP_MODE, OnCbnSelchangeTooltipMode)
  71. END_MESSAGE_MAP()
  72. void COptionsDialogBar::OnInitDialog() 
  73. {
  74. Default();
  75. int i;
  76. if(m_arOptCtrlIDsAll.GetSize() == 0) 
  77. {
  78. VERIFY( m_ctrlWorkWeekDays[0].SubclassDlgItem(IDC_WORK_WEEK_DAY_SU, this));
  79. VERIFY( m_ctrlWorkWeekDays[1].SubclassDlgItem(IDC_WORK_WEEK_DAY_MO, this));
  80. VERIFY( m_ctrlWorkWeekDays[2].SubclassDlgItem(IDC_WORK_WEEK_DAY_TU, this));
  81. VERIFY( m_ctrlWorkWeekDays[3].SubclassDlgItem(IDC_WORK_WEEK_DAY_WE, this));
  82. VERIFY( m_ctrlWorkWeekDays[4].SubclassDlgItem(IDC_WORK_WEEK_DAY_TH, this));
  83. VERIFY( m_ctrlWorkWeekDays[5].SubclassDlgItem(IDC_WORK_WEEK_DAY_FR, this));
  84. VERIFY( m_ctrlWorkWeekDays[6].SubclassDlgItem(IDC_WORK_WEEK_DAY_SA, this));
  85. VERIFY( m_ctrlFirstDayOfWeekCb.SubclassDlgItem(IDC_FIRST_DAY_OF_WEEK_CB, this));
  86. VERIFY( m_ctrlStartTimeCb.SubclassDlgItem(IDC_START_TIME_CB, this));
  87. VERIFY( m_ctrlEndTimeCb.SubclassDlgItem(IDC_END_TIME_CB, this));
  88. for(i = 0; i < 7; i++) 
  89. {
  90. m_arOptCtrlIDsCommon.Add(m_ctrlWorkWeekDays[i].GetDlgCtrlID());
  91. }
  92. m_arOptCtrlIDsCommon.Add(IDC_WORK_WEEK_FRAME);
  93. m_arOptCtrlIDsCommon.Add(IDC_FIRST_DAY_OF_WEEK_CB);
  94. m_arOptCtrlIDsCommon.Add(IDC_FIRST_DAY_OF_WEEK_TEXT);
  95. m_arOptCtrlIDsCommon.Add(IDC_START_TIME_CB);
  96. m_arOptCtrlIDsCommon.Add(IDC_START_TIME_TEXT);
  97. m_arOptCtrlIDsCommon.Add(IDC_END_TIME_CB);
  98. m_arOptCtrlIDsCommon.Add(IDC_END_TIME_TEXT);
  99. m_arOptCtrlIDsCommon.Add(IDC_ADVANCED_FRAME);
  100. m_arOptCtrlIDsCommon.Add(IDC_ADVANCED_OPT_BTN);
  101. m_arOptCtrlIDsCommon.Add(IDC_BOTTOM_FRAME_STATIC);
  102. VERIFY( m_ctrlTooltipMode.SubclassDlgItem(IDC_TOOLTIP_MODE, this));
  103. // Day View ----------------------------
  104. VERIFY( m_ctrlSelchangeTimeScaleCb.SubclassDlgItem(IDC_TIME_SCALE, this));
  105. m_arOptCtrlIDsDayView.Add(IDC_DAY_VIEW_FRAME);
  106. m_arOptCtrlIDsDayView.Add(IDC_TIME_SCALE);
  107. m_arOptCtrlIDsDayView.Add(IDC_TIME_SCALE_TEXT);
  108. m_arOptCtrlIDsDayView.Add(IDC_TIME_ZONE_BTN);
  109. // Month View ----------------------------
  110. VERIFY( m_ctrlMonth_ShowEndTime.SubclassDlgItem(IDD_MONTH_SHOW_END_TIME, this));
  111. VERIFY( m_ctrlMonth_ShowTimeAsClocks.SubclassDlgItem(IDD_MONTH_SHOW_TIME_AS_CLOCKS, this));
  112. VERIFY( m_ctrlMonth_CompressWeekendDays.SubclassDlgItem(IDD_MONTH_COMPRESS_WEEKEND_DAYS, this));
  113. VERIFY( m_ctrlMonth_WeeksCount.SubclassDlgItem(IDD_MONTH_WEEKS_COUNT, this));
  114. m_arOptCtrlIDsMonthView.Add(IDC_MONTH_VIEW_FRAME);
  115. m_arOptCtrlIDsMonthView.Add(IDD_MONTH_SHOW_END_TIME);
  116. m_arOptCtrlIDsMonthView.Add(IDD_MONTH_SHOW_TIME_AS_CLOCKS);
  117. m_arOptCtrlIDsMonthView.Add(IDD_MONTH_COMPRESS_WEEKEND_DAYS);
  118. m_arOptCtrlIDsMonthView.Add(IDD_MONTH_WEEKS_COUNT);
  119. m_arOptCtrlIDsMonthView.Add(IDD_MONTH_WEEKS_COUNT_TEXT);
  120. // Week View ----------------------------
  121. VERIFY( m_ctrlWeek_ShowTimeAsClock.SubclassDlgItem(IDD_WEEK_SHOW_TIME_AS_CLOCK, this));
  122. VERIFY( m_ctrlWeek_ShowEndTime.SubclassDlgItem(IDD_WEEK_SHOW_END_TIME, this));
  123. m_arOptCtrlIDsWeekView.Add(IDC_WEEK_VIEW_FRAME);
  124. m_arOptCtrlIDsWeekView.Add(IDD_WEEK_SHOW_TIME_AS_CLOCK);
  125. m_arOptCtrlIDsWeekView.Add(IDD_WEEK_SHOW_END_TIME);
  126. //===========================================================================
  127. m_arOptCtrlIDsAll.Append(m_arOptCtrlIDsCommon);
  128. m_arOptCtrlIDsAll.Append(m_arOptCtrlIDsDayView);
  129. m_arOptCtrlIDsAll.Append(m_arOptCtrlIDsWeekView);
  130. m_arOptCtrlIDsAll.Append(m_arOptCtrlIDsMonthView);
  131. }
  132. CString strTmp;
  133. //---------------------------------------------------------------------------
  134. for(i = 0; i < 7; i++) 
  135. {
  136. m_ctrlWorkWeekDays[i].SetCheck((i > 0 && i < 6) ? 1 : 0);
  137. }
  138. //---------------------------------------------------------------------------
  139. int arScales[] = {60, 30, 15, 10, 6, 5}; 
  140. m_ctrlSelchangeTimeScaleCb.ResetContent();
  141. for(i = 0; i < sizeof(arScales)/sizeof(arScales[0]); i++) 
  142. {
  143. strTmp.Format(_T("%d minutes"), arScales[i]);
  144. int nIndex = m_ctrlSelchangeTimeScaleCb.AddString(strTmp);
  145. m_ctrlSelchangeTimeScaleCb.SetItemData(nIndex, arScales[i]);
  146. }
  147. m_ctrlSelchangeTimeScaleCb.SetCurSel(1);
  148. //---------------------------------------------------------------------------
  149. TCHAR* srWDays[] = {_T("Sunday"), _T("Monday"), _T("Tuesday"), _T("Wednesday"), _T("Thursday"), _T("Friday"), _T("Saturday")}; 
  150.     
  151. m_ctrlFirstDayOfWeekCb.ResetContent();
  152. for(i = 0; i < 7; i++) 
  153. {
  154. int nIndex = m_ctrlFirstDayOfWeekCb.AddString(srWDays[i]); 
  155. m_ctrlFirstDayOfWeekCb.SetItemData(nIndex, i+1);
  156. }
  157. m_ctrlFirstDayOfWeekCb.SetCurSel(1);
  158. //---------------------------------------------------------------------------
  159. COleDateTimeSpan spHalfHour(0,0,30,0);
  160. COleDateTime dtHours;
  161. dtHours.SetTime(0, 0, 0);
  162. m_ctrlStartTimeCb.ResetContent();
  163. m_ctrlEndTimeCb.ResetContent();
  164. for(i = 0; i < 48; i++) 
  165. {
  166. strTmp.Format(_T("%02d:%02d"), dtHours.GetHour(), dtHours.GetMinute());
  167.         
  168. int nIndex = m_ctrlStartTimeCb.AddString(strTmp); 
  169. m_ctrlStartTimeCb.SetItemData(nIndex, i);
  170. nIndex = m_ctrlEndTimeCb.AddString(strTmp); 
  171. m_ctrlEndTimeCb.SetItemData(nIndex, i);
  172. dtHours += spHalfHour;
  173. }
  174. m_ctrlStartTimeCb.SetCurSel(16);
  175. m_ctrlEndTimeCb.SetCurSel(34);
  176. //-----------------------------------------------------------------------
  177. m_ctrlTooltipMode.ResetContent();
  178. ASSERT(m_ctrlTooltipMode.GetCount() == 0);
  179. int nIdx = m_ctrlTooltipMode.AddString(_T("Standard"));
  180. m_ctrlTooltipMode.SetItemData(nIdx, ctmStandard);
  181. nIdx = m_ctrlTooltipMode.AddString(_T("Custom"));
  182. m_ctrlTooltipMode.SetItemData(nIdx, ctmCustom);
  183. nIdx = m_ctrlTooltipMode.AddString(_T("Disabled"));
  184. m_ctrlTooltipMode.SetItemData(nIdx, ctmDisabled);
  185. //===========================================================================
  186. m_ctrlMonth_ShowEndTime.SetCheck(0);
  187. m_ctrlMonth_ShowTimeAsClocks.SetCheck(0);
  188. m_ctrlMonth_CompressWeekendDays.SetCheck(1);
  189. m_ctrlWeek_ShowTimeAsClock.SetCheck(0);
  190. m_ctrlWeek_ShowEndTime.SetCheck(1);
  191.     
  192. //---------------------------------------------------------------------------
  193. m_ctrlMonth_WeeksCount.ResetContent();
  194. for(i = 2; i <= 6; i++) 
  195. {
  196. strTmp.Format(_T("%d"), i);
  197. int nIndex = m_ctrlMonth_WeeksCount.AddString(strTmp); 
  198. m_ctrlMonth_WeeksCount.SetItemData(nIndex, i);
  199. }
  200. m_ctrlMonth_WeeksCount.SetCurSel(3);
  201. //===========================================================================
  202. }
  203. CXTPCalendarControl* COptionsDialogBar::GetCalendarCtrl()
  204. {
  205. CView* pView = ((CFrameWnd*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView();
  206. ASSERT_KINDOF(CCalendarDemoView, pView);
  207. if (pView)
  208. return &((CCalendarDemoView*)pView)->GetCalendarCtrl();
  209. else
  210. return NULL;
  211. }
  212. void COptionsDialogBar::OnBnClickedMonthCompressWeekendDays()
  213. {
  214. int nCheck = m_ctrlMonth_CompressWeekendDays.GetCheck();
  215. GetCalendarCtrl()->MonthView_SetCompressWeekendDays(nCheck ? TRUE : FALSE);
  216. GetCalendarCtrl()->Populate();
  217. }
  218. void COptionsDialogBar::OnBnClickedMonthShowEndTime()
  219. {
  220. int nCheck = m_ctrlMonth_ShowEndTime.GetCheck();
  221. GetCalendarCtrl()->MonthView_SetShowEndDate(nCheck ? TRUE : FALSE);
  222. GetCalendarCtrl()->Populate();
  223. }
  224. void COptionsDialogBar::OnBnClickedMonthSchowTimeAsClock()
  225. {
  226. int nCheck = m_ctrlMonth_ShowTimeAsClocks.GetCheck();
  227. GetCalendarCtrl()->MonthView_SetShowTimeAsClocks(nCheck ? TRUE : FALSE);
  228. GetCalendarCtrl()->Populate();
  229. }
  230. void COptionsDialogBar::OnCbnSelchangeFirstDayOfWeekCb()
  231. {
  232. int nSel = m_ctrlFirstDayOfWeekCb.GetCurSel();
  233. GetCalendarCtrl()->SetFirstDayOfWeek(nSel+1);
  234. PopulateWorkDays();
  235. }
  236. void COptionsDialogBar::PopulateWorkDays()
  237. {
  238. // update picture
  239. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl()->GetActiveView());
  240. if (pDayView)
  241. {
  242. // show working days interval
  243. COleDateTime dtDayViewStart;
  244. pDayView->GetSelection(&dtDayViewStart);
  245. pDayView->ShowWorkingDays(dtDayViewStart);
  246. }
  247. else
  248. {
  249. GetCalendarCtrl()->Populate();
  250. }
  251. }
  252. void COptionsDialogBar::OnCbnSelchangeMonthWeeksCount()
  253. {
  254. int nSel = m_ctrlMonth_WeeksCount.GetCurSel();
  255. CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, GetCalendarCtrl()->GetActiveView());
  256. if(pMonthView) 
  257. {
  258. pMonthView->GetGrid()->SetWeeksCount(nSel+2);
  259. GetCalendarCtrl()->Populate();
  260. }
  261. }
  262. void COptionsDialogBar::OnCbnSelchangeTimeScale()
  263. {   
  264. int nSel = m_ctrlSelchangeTimeScaleCb.GetCurSel();
  265. if(nSel == CB_ERR) 
  266. {
  267. return;
  268. }
  269. int nScale = (int)m_ctrlSelchangeTimeScaleCb.GetItemData(nSel);
  270. CCalendarDemoView* pView = (CCalendarDemoView*)(((CFrameWnd*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView());
  271. if (pView)
  272. {
  273. pView->SetCalendarTimeScale(nScale);
  274. }
  275. }
  276. void COptionsDialogBar::OnBnClickedWeekSchowTimeAsClock()
  277. {
  278. int nCheck = m_ctrlWeek_ShowTimeAsClock.GetCheck();
  279. GetCalendarCtrl()->WeekView_SetShowTimeAsClocks(nCheck ? TRUE : FALSE);
  280. GetCalendarCtrl()->Populate();
  281. }
  282. void COptionsDialogBar::OnBnClickedWeekShowEndTime()
  283. {
  284. int nCheck = m_ctrlWeek_ShowEndTime.GetCheck();
  285. GetCalendarCtrl()->WeekView_SetShowEndDate(nCheck ? TRUE : FALSE);
  286. GetCalendarCtrl()->Populate();
  287. }
  288. void COptionsDialogBar::OnBnClickedTimeZoneBtn()
  289. {
  290. //CalendarTimezone();
  291. }
  292. void COptionsDialogBar::OnCbnSelchangeStartTimeCb()
  293. {
  294. int nSel = m_ctrlStartTimeCb.GetCurSel();
  295. int nSel2 = m_ctrlEndTimeCb.GetCurSel();
  296. if(nSel == CB_ERR || nSel2 == CB_ERR ) {
  297. return;
  298. }
  299. if(nSel > nSel2) 
  300. {
  301. nSel2 = nSel;
  302. m_ctrlEndTimeCb.SetCurSel(nSel2);
  303. }
  304. COleDateTimeSpan spHalfHour(0,0,30,0);
  305. DWORD dwI = (DWORD)m_ctrlStartTimeCb.GetItemData(nSel);
  306. COleDateTime dtHour = (double)spHalfHour * dwI;
  307.         
  308. GetCalendarCtrl()->SetWorkDayStartTime(dtHour.GetHour(), dtHour.GetMinute(), 0); 
  309. GetCalendarCtrl()->Populate();
  310. }
  311. void COptionsDialogBar::OnCbnSelchangeEndTimeCb()
  312. {
  313. int nSel1 = m_ctrlStartTimeCb.GetCurSel();
  314. int nSel = m_ctrlEndTimeCb.GetCurSel();
  315. if(nSel == CB_ERR || nSel1 == CB_ERR ) {
  316. return;
  317. }
  318. if(nSel < nSel1) 
  319. {
  320. nSel1 = nSel;
  321. m_ctrlStartTimeCb.SetCurSel(nSel1);
  322. }
  323. COleDateTimeSpan spHalfHour(0,0,30,0);
  324. DWORD dwI = (DWORD)m_ctrlEndTimeCb.GetItemData(nSel);
  325. COleDateTime dtHour = (double)spHalfHour * dwI;
  326.         
  327. GetCalendarCtrl()->SetWorkDayEndTime(dtHour.GetHour(), dtHour.GetMinute(), 0); 
  328. GetCalendarCtrl()->Populate();
  329. }
  330. void COptionsDialogBar::OnBnClickedWorkWeekDay()
  331. {
  332. int nWWMask = 0;
  333. for(int i = 0; i < 7; i++) 
  334. {
  335. if(m_ctrlWorkWeekDays[i].GetCheck()) 
  336. {
  337. nWWMask |=  CXTPCalendarUtils::GetDayOfWeekMask(i+1);
  338. }
  339. }
  340. if (nWWMask == 0)
  341. {
  342. m_ctrlWorkWeekDays[0].SetCheck(1);
  343. nWWMask |=  CXTPCalendarUtils::GetDayOfWeekMask(1);
  344. }
  345. GetCalendarCtrl()->SetWorkWeekMask(nWWMask);
  346. PopulateWorkDays();
  347. }
  348. void COptionsDialogBar::OnViewChanged(XTPCalendarViewType viewType)
  349. {
  350. if (viewType == xtpCalendarWeekView)
  351. {
  352. OnBnClickedWeekSchowTimeAsClock();
  353. OnBnClickedWeekShowEndTime();
  354. }
  355. if (viewType == xtpCalendarMonthView)
  356. {
  357. OnBnClickedMonthCompressWeekendDays();
  358. OnBnClickedMonthShowEndTime();
  359. OnCbnSelchangeFirstDayOfWeekCb();
  360. OnCbnSelchangeMonthWeeksCount();
  361. }
  362. }
  363. void COptionsDialogBar::OnCalendarEvent_TimeSacleWasChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  364. {
  365. UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  366. if(Event != XTP_NC_CALENDARVIEWTIMESCALEWASCHANGED) {
  367. ASSERT(FALSE);
  368. return;
  369. }
  370.     
  371. int nCurrScale = -1;
  372. int nSel = m_ctrlSelchangeTimeScaleCb.GetCurSel();
  373. if(nSel != CB_ERR) 
  374. {
  375. nCurrScale = (int)m_ctrlSelchangeTimeScaleCb.GetItemData(nSel);
  376. }
  377. CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, GetCalendarCtrl()->GetActiveView());
  378. if (!pDayView) {
  379. return;
  380. }
  381. COleDateTimeSpan spScale = pDayView->GetScaleInterval();
  382. int nNewScale = (int)spScale.GetTotalMinutes();
  383. if(nCurrScale == nNewScale) {
  384. return;
  385. }
  386. int nCount = m_ctrlSelchangeTimeScaleCb.GetCount();
  387. for(int i = 0; i < nCount; i++) 
  388. {   
  389. if(nNewScale == (int)m_ctrlSelchangeTimeScaleCb.GetItemData(i)) 
  390. {
  391. m_ctrlSelchangeTimeScaleCb.SetCurSel(i);
  392. break;
  393. }
  394. }
  395. }
  396. void COptionsDialogBar::OnCalendarEvent_ViewWasChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  397. {
  398. UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  399. if(Event != XTP_NC_CALENDARVIEWWASCHANGED) {
  400. ASSERT(FALSE);
  401. return;
  402. }
  403. UpdateControlsState();
  404. }
  405. void COptionsDialogBar::Init()
  406. {
  407. Close();
  408. CXTPCalendarControl* pCalendar = GetCalendarCtrl();
  409. if(!pCalendar) {
  410. ASSERT(FALSE);
  411. return;
  412. }
  413. CXTPNotifyConnection* pCConn = pCalendar->GetConnection();
  414. ASSERT(pCConn);
  415. m_Sink.Advise(pCConn, XTP_NC_CALENDARVIEWTIMESCALEWASCHANGED, &COptionsDialogBar::OnCalendarEvent_TimeSacleWasChanged);
  416. m_Sink.Advise(pCConn, XTP_NC_CALENDARVIEWWASCHANGED, &COptionsDialogBar::OnCalendarEvent_ViewWasChanged);
  417. UpdateControlsState();
  418. }
  419. void COptionsDialogBar::Close()
  420. {
  421. m_Sink.UnadviseAll();
  422. }
  423. void COptionsDialogBar::UpdateControlsState()
  424. {
  425. CXTPCalendarControl* pCalendar = GetCalendarCtrl();
  426. CView* pView = ((CFrameWnd*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView();
  427. ASSERT_KINDOF(CCalendarDemoView, pView);
  428. CCalendarDemoView* pDemoView = (CCalendarDemoView*)pView;
  429. if(!pCalendar || !pDemoView) {
  430. ASSERT(FALSE);
  431. return;
  432. }
  433. //===========================================================================
  434. int nWorkWeekMask = pCalendar->GetWorkWeekMask();
  435. CString strTmp;
  436. int i;
  437. //---------------------------------------------------------------------------
  438. for(i = 0; i < 7; i++) {
  439. int nCheck = (nWorkWeekMask & CXTPCalendarUtils::GetDayOfWeekMask(i+1)) ? 1 : 0;
  440. m_ctrlWorkWeekDays[i].SetCheck(nCheck);
  441. }
  442. //---------------------------------------------------------------------------
  443. OnCalendarEvent_TimeSacleWasChanged(XTP_NC_CALENDARVIEWTIMESCALEWASCHANGED, 0, 0);
  444. //---------------------------------------------------------------------------
  445. int nFirstDayOfWeek = pCalendar->GetFirstDayOfWeek();
  446. for(i = 0; i < 7; i++) 
  447. {   
  448. if((int)m_ctrlFirstDayOfWeekCb.GetItemData(i) == nFirstDayOfWeek) {
  449. m_ctrlFirstDayOfWeekCb.SetCurSel(i);
  450. break;
  451. }
  452. }      
  453. //---------------------------------------------------------------------------
  454. COleDateTime dtWWStartTime, dtWWEndTime;
  455. pCalendar->GetWorkDayStartTime(dtWWStartTime);
  456. pCalendar->GetWorkDayEndTime(dtWWEndTime);
  457. int nIndex1 = dtWWStartTime.GetHour()*2 + (dtWWStartTime.GetMinute() ? 1 : 0);
  458. int nIndex2 = dtWWEndTime.GetHour()*2 + (dtWWEndTime.GetMinute() ? 1 : 0);
  459. m_ctrlStartTimeCb.SetCurSel(nIndex1);
  460. m_ctrlEndTimeCb.SetCurSel(nIndex2);
  461. //===========================================================================
  462. m_ctrlMonth_ShowEndTime.SetCheck(pCalendar->MonthView_IsShowEndDate() ? 1 : 0);
  463. m_ctrlMonth_ShowTimeAsClocks.SetCheck(pCalendar->MonthView_IsShowTimeAsClocks() ? 1 : 0);
  464. m_ctrlMonth_CompressWeekendDays.SetCheck(pCalendar->MonthView_IsCompressWeekendDays() ? 1 : 0);
  465. //---------------------------------------------------------------------------
  466. CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, pCalendar->GetActiveView());
  467. if(pMonthView) 
  468. {
  469. int nWCount = pMonthView->GetGrid()->GetWeeksCount();
  470.         
  471. for(i = 0; i < m_ctrlMonth_WeeksCount.GetCount(); i++) 
  472. {   
  473. if((int)m_ctrlMonth_WeeksCount.GetItemData(i) == nWCount) {
  474. m_ctrlMonth_WeeksCount.SetCurSel(i);
  475. break;
  476. }
  477. }
  478. }
  479. //------------------------------------------------------------------------
  480. m_ctrlWeek_ShowTimeAsClock.SetCheck(pCalendar->WeekView_IsShowTimeAsClocks() ? 1 : 0);
  481. m_ctrlWeek_ShowEndTime.SetCheck(pCalendar->WeekView_IsShowEndDate() ? 1 : 0);
  482. //------------------------------------------------------------------------
  483. for(i = 0; i < m_ctrlTooltipMode.GetCount(); i++) {
  484. if((int)m_ctrlTooltipMode.GetItemData(i) == 
  485. pDemoView->m_wndCalendarEx.m_nToolTipMode) 
  486. {
  487. m_ctrlTooltipMode.SetCurSel(i);
  488. break;
  489. }
  490. }
  491. //========================================================================
  492. }
  493. void COptionsDialogBar::OnCbnSelchangeTooltipMode()
  494. {
  495. CCalendarDemoView* pView = (CCalendarDemoView*)(((CFrameWnd*)AfxGetMainWnd())->GetActiveFrame()->GetActiveView());
  496. int nSel = m_ctrlTooltipMode.GetCurSel();
  497. if(nSel != CB_ERR && pView)
  498. {
  499. pView->SetCalendarToolTipMode((int)m_ctrlTooltipMode.GetItemData(nSel));
  500. }
  501. }
  502. HBRUSH COptionsDialogBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  503. {
  504. if (nCtlColor == CTLCOLOR_LISTBOX || nCtlColor == CTLCOLOR_EDIT)
  505. return CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
  506. COLORREF clr = XTPColorManager()->grcDockBar.clrDark;
  507. static CBrush brush;
  508. static COLORREF brushColor = 0;
  509. if (brush.GetSafeHandle() == 0 || brushColor != clr)
  510. {
  511. brush.DeleteObject();
  512. brush.CreateSolidBrush(clr);
  513. brushColor = clr;
  514. }
  515. pDC->SetBkColor(clr);
  516. return brush;
  517. }