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

对话框与窗口

开发平台:

Visual C++

  1. // // XTPCalendarCaptionBarControl.cpp : implementation file
  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/XTPOffice2007Image.h"
  24. #include "XTPCalendarUtils.h"
  25. #include "XTPCalendarThemeOffice2007.h"
  26. #include "XTPCalendarControl.h"
  27. #include "XTPCalendarCaptionBarControl.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. //////////////////////////////////////////////////////////////////////////
  34. IMPLEMENT_DYNAMIC(CXTPCalendarCaptionBarControl, CWnd)
  35. IMPLEMENT_DYNAMIC(CXTPCalendarCaptionBarThemePart, CXTPCalendarWMHandler)
  36. IMPLEMENT_DYNCREATE(CXTPCalendarCaptionBarTheme, CXTPCalendarWMHandler)
  37. CXTPCalendarCaptionBarControl::CXTPCalendarCaptionBarControl()
  38. {
  39. RegisterWindowClass();
  40. m_pTheme = NULL;
  41. SetTheme(new CXTPCalendarCaptionBarTheme());
  42. }
  43. CXTPCalendarCaptionBarControl::~CXTPCalendarCaptionBarControl()
  44. {
  45. CMDTARGET_RELEASE(m_pTheme);
  46. }
  47. BOOL CXTPCalendarCaptionBarControl::RegisterWindowClass(HINSTANCE hInstance /*= NULL*/)
  48. {
  49. return XTPDrawHelpers()->RegisterWndClass(hInstance,
  50. XTPCALENDARCAPTIONBAR_CLASSNAME, /*CS_DBLCLKS |*/ CS_HREDRAW | CS_VREDRAW);
  51. }
  52. BOOL CXTPCalendarCaptionBarControl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  53. {
  54. if (!CWnd::Create(XTPCALENDARCAPTIONBAR_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID))
  55. return FALSE;
  56. AdjustLayout(NULL);
  57. return TRUE;
  58. }
  59. BEGIN_MESSAGE_MAP(CXTPCalendarCaptionBarControl, CWnd)
  60. //{{AFX_MSG_MAP(CXTPCalendarControl)
  61. ON_WM_PAINT()
  62. ON_WM_ERASEBKGND()
  63. ON_WM_SIZE()
  64. ON_WM_LBUTTONDOWN()
  65. ON_WM_LBUTTONUP()
  66. ON_WM_MOUSEMOVE()
  67. ON_WM_KEYDOWN()
  68. ON_WM_KEYUP()
  69. ON_WM_KILLFOCUS()
  70. ON_WM_DESTROY()
  71. //  ON_WM_GETDLGCODE()
  72. ON_WM_ENABLE()
  73. ON_WM_TIMER()
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. void CXTPCalendarCaptionBarControl::SetTheme(CXTPCalendarCaptionBarTheme* pTheme)
  77. {
  78. ASSERT(pTheme);
  79. if (pTheme)
  80. {
  81. CMDTARGET_RELEASE(m_pTheme);
  82. m_pTheme = pTheme;
  83. m_pTheme->SetOwner(this);
  84. m_pTheme->RefreshMetrics();
  85. }
  86. }
  87. void CXTPCalendarCaptionBarControl::AdjustLayout(CDC* pDC, const CRect* prcWnd)
  88. {
  89. CXTPClientRect rcClient(this);
  90. if (prcWnd)
  91. ((CRect&)rcClient) = *prcWnd;
  92. if (m_pTheme)
  93. m_pTheme->AdjustLayout(pDC, rcClient);
  94. }
  95. void CXTPCalendarCaptionBarControl::OnPaint()
  96. {
  97. CXTPClientRect rc(this);
  98. if (rc.IsRectEmpty())
  99. return;
  100. CPaintDC dc(this); // device context for painting
  101. CXTPBufferDC memDC(dc.GetSafeHdc(), rc);
  102. //memDC.FillSolidRect(rc, m_crBack);
  103. if (m_pTheme)
  104. m_pTheme->Draw(&memDC);
  105. }
  106. BOOL CXTPCalendarCaptionBarControl::OnEraseBkgnd(CDC* /*pDC*/)
  107. {
  108. return TRUE;
  109. }
  110. void CXTPCalendarCaptionBarControl::OnSize(UINT nType, int cx, int cy)
  111. {
  112. CWnd::OnSize(nType, cx, cy);
  113. if (!GetSafeHwnd())
  114. return;
  115. CRect rcRect(0, 0, cx, cy);
  116. if (m_pTheme)
  117. m_pTheme->AdjustLayout(NULL, rcRect);
  118. }
  119. void CXTPCalendarCaptionBarControl::OnLButtonDown(UINT nFlags, CPoint point)
  120. {
  121. if (m_pTheme)
  122. m_pTheme->OnLButtonDown(nFlags, point);
  123. if (GetCapture() != this)
  124. SetCapture();
  125. }
  126. void CXTPCalendarCaptionBarControl::OnLButtonUp(UINT nFlags, CPoint point)
  127. {
  128. if (m_pTheme)
  129. m_pTheme->OnLButtonUp(nFlags, point);
  130. if (GetCapture() == this)
  131. ReleaseCapture();
  132. }
  133. void CXTPCalendarCaptionBarControl::OnMouseMove(UINT nFlags, CPoint point)
  134. {
  135. if (m_pTheme)
  136. m_pTheme->OnMouseMove(nFlags, point);
  137. }
  138. void CXTPCalendarCaptionBarControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  139. {
  140. if (m_pTheme)
  141. m_pTheme->OnKeyDown(nChar, nRepCnt, nFlags);
  142. }
  143. void CXTPCalendarCaptionBarControl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  144. {
  145. if (m_pTheme)
  146. m_pTheme->OnKeyUp(nChar, nRepCnt, nFlags);
  147. }
  148. void CXTPCalendarCaptionBarControl::OnTimer(UINT_PTR uTimerID)
  149. {
  150. if (m_pTheme)
  151. m_pTheme->OnTimer(uTimerID);
  152. }
  153. void CXTPCalendarCaptionBarControl::OnDestroy()
  154. {
  155. if (m_pTheme)
  156. m_pTheme->OnBeforeDestroy();
  157. }
  158. void CXTPCalendarCaptionBarControl::OnKillFocus (CWnd* pNewWnd)
  159. {
  160. if (m_pTheme)
  161. m_pTheme->OnKillFocus(pNewWnd);
  162. }
  163. //////////////////////////////////////////////////////////////////////////
  164. CXTPCalendarCaptionBarTheme::CXTPCalendarCaptionBarTheme()
  165. {
  166. m_pCaptionBar   = NULL;
  167. m_pCalendar     = NULL;
  168. m_nCheckHotStateTimerID = 0;
  169. m_bIsSwitchViewButtons = TRUE;
  170. m_bIsScrollDateButtons = TRUE;
  171. m_bIsDateLabel = TRUE;
  172. m_pButtonViewDay = new CSwitchViewButtonPart(this, xtpCalendarCaptionBar_ButtonViewDay);
  173. m_pButtonViewWeek = new CSwitchViewButtonPart(this, xtpCalendarCaptionBar_ButtonViewWeek);
  174. m_pButtonViewMonth = new CSwitchViewButtonPart(this, xtpCalendarCaptionBar_ButtonViewMonth);
  175. m_pButtonViewDay->SetText(XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_DAY));
  176. m_pButtonViewWeek->SetText(XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_WEEK));
  177. m_pButtonViewMonth->SetText(XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_MONTH));
  178. m_pShowWorkWeek = new CRadioButtonPart(this, xtpCalendarCaptionBar_ShowWorkWeek);
  179. m_pShowFullWeek = new CRadioButtonPart(this, xtpCalendarCaptionBar_ShowFullWeek);
  180. m_pShowWorkWeek->SetText(XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_SHOWWORKWEK));
  181. m_pShowFullWeek->SetText(XTPResourceManager()->LoadString(XTP_IDS_CALENDAR_SHOWFULLKWEK));
  182. m_pShowWorkWeek->SetCheck(1);
  183. m_pShowFullWeek->SetCheck(0);
  184. //---------------------------------
  185. m_pScrollPrevDate = new CScrollDateButtonPart(this, xtpCalendarCaptionBar_ScrollPrevDate);
  186. m_pScrollNextDate = new CScrollDateButtonPart(this, xtpCalendarCaptionBar_ScrollNextDate);
  187. m_pDateLabel = new CDateLabelPart(this, xtpCalendarCaptionBar_DateLabel);
  188. m_nPaintTheme = xtpCalendarThemeOffice2007;
  189. RefreshMetrics();
  190. }
  191. CXTPCalendarCaptionBarTheme::~CXTPCalendarCaptionBarTheme()
  192. {
  193. m_Sink.UnadviseAll();
  194. CMDTARGET_RELEASE(m_pButtonViewDay);
  195. CMDTARGET_RELEASE(m_pButtonViewWeek);
  196. CMDTARGET_RELEASE(m_pButtonViewMonth);
  197. CMDTARGET_RELEASE(m_pShowWorkWeek);
  198. CMDTARGET_RELEASE(m_pShowFullWeek);
  199. CMDTARGET_RELEASE(m_pScrollPrevDate);
  200. CMDTARGET_RELEASE(m_pScrollNextDate);
  201. CMDTARGET_RELEASE(m_pDateLabel);
  202. CMDTARGET_RELEASE(m_pCalendar);
  203. }
  204. void CXTPCalendarCaptionBarTheme::OnBeforeDestroy()
  205. {
  206. m_Sink.UnadviseAll();
  207. CMDTARGET_RELEASE(m_pCalendar);
  208. }
  209. void CXTPCalendarCaptionBarTheme::SetOwner(CXTPCalendarCaptionBarControl* pCaptionBar)
  210. {
  211. ASSERT(pCaptionBar);
  212. if (pCaptionBar)
  213. {
  214. m_pCaptionBar = pCaptionBar;
  215. }
  216. }
  217. void CXTPCalendarCaptionBarTheme::AttachCalendar(CXTPCalendarControl* pCalendar)
  218. {
  219. m_Sink.UnadviseAll();
  220. CMDTARGET_RELEASE(m_pCalendar);
  221. m_pCalendar = pCalendar;
  222. CMDTARGET_ADDREF(m_pCalendar);
  223. if (m_pCalendar && m_pCalendar->GetConnection())
  224. {
  225. CXTPNotifyConnection* pConn = m_pCalendar->GetConnection();
  226. m_Sink.Advise(pConn, XTP_NC_CALENDARVIEWWASCHANGED, &CXTPCalendarCaptionBarTheme::OnEvent_Calendar);
  227. m_Sink.Advise(pConn, XTP_NC_CALENDAR_THEME_CHANGED, &CXTPCalendarCaptionBarTheme::OnEvent_Calendar);
  228. UpdateControlsState();
  229. if (XTPOffice2007Images() && XTPOffice2007Images()->GetConnection())
  230. {
  231. m_Sink.Advise(XTPOffice2007Images()->GetConnection(), XTP_NC_COMMON_OFFICE2007IMAGES_CHANGED,
  232.    &CXTPCalendarCaptionBarTheme::OnEvent_Office2007ImagesChanged);
  233. }
  234. }
  235. }
  236. int CXTPCalendarCaptionBarTheme::GetChildHandlersCount()
  237. {
  238. return m_arMembers.GetCount();
  239. }
  240. CXTPCalendarWMHandler* CXTPCalendarCaptionBarTheme::GetChildHandlerAt(int nIndex)
  241. {
  242. return m_arMembers.GetAt(nIndex);
  243. }
  244. void CXTPCalendarCaptionBarTheme::OnMouseMove(UINT nFlags, CPoint point)
  245. {
  246. CXTPCalendarWMHandler::OnMouseMove(nFlags, point);
  247. if (GetOwnerWnd() && m_nCheckHotStateTimerID == 0)
  248. {
  249. m_nCheckHotStateTimerID = GetOwnerWnd()->SetTimer(1, 100, NULL);
  250. }
  251. }
  252. BOOL CXTPCalendarCaptionBarTheme::OnTimer(UINT_PTR uTimerID)
  253. {
  254. if (uTimerID == m_nCheckHotStateTimerID && GetOwnerWnd() &&
  255. ::GetCapture() != GetOwnerWnd()->GetSafeHwnd())
  256. {
  257. BOOL bMouseLeave;
  258. BOOL bChanged = _UpdateControlsHotState(&bMouseLeave);
  259. if (bMouseLeave)
  260. {
  261. GetOwnerWnd()->KillTimer(1);
  262. m_nCheckHotStateTimerID = 0;
  263. }
  264. if (bChanged)
  265. GetOwnerWnd()->Invalidate(FALSE);
  266. return TRUE;
  267. }
  268. return FALSE;
  269. }
  270. CRect CXTPCalendarCaptionBarTheme::CalcMinRect(CDC* /*pDC*/)
  271. {
  272. if (!IsSwitchViewButtons() &&
  273. !IsScrollDateButtons() &&
  274. !IsDateLabel())
  275. {
  276. return CRect(0, 0, 0, 0);
  277. }
  278. CRect rc(0, 0, 525, 71);
  279. if (!IsSwitchViewButtons())
  280. rc.bottom -= 27;
  281. if (!IsScrollDateButtons() && !IsDateLabel())
  282. rc.bottom -= 33;
  283. return rc;
  284. };
  285. void CXTPCalendarCaptionBarTheme::AdjustLayout(CDC* pDC, const CRect& rcRect)
  286. {
  287. if (!pDC && GetOwnerWnd() && GetOwnerWnd()->m_hWnd)
  288. {
  289. CClientDC dc(GetOwnerWnd());
  290. AdjustLayout(&dc, rcRect);
  291. return;
  292. }
  293. m_rcRect = rcRect;
  294. CRect rc00(rcRect.left, rcRect.top, rcRect.left, rcRect.top);
  295. CRect rc = m_rcRect;
  296. //rc.DeflateRect(1, 1, 1, 0);
  297. rc.DeflateRect(0, 1, 0, 0);
  298. int nNextY = rc.top;
  299. m_pButtonViewDay->SetVisible(IsSwitchViewButtons());
  300. m_pButtonViewWeek->SetVisible(IsSwitchViewButtons());
  301. m_pButtonViewMonth->SetVisible(IsSwitchViewButtons());
  302. if (IsSwitchViewButtons())
  303. {
  304. rc.bottom = rc.top + 26;
  305. rc.right = rc.left + 83;
  306. m_pButtonViewDay->AdjustLayout(pDC, rc);
  307. rc.left = m_pButtonViewDay->GetRect().right;
  308. rc.right = rc.left + 83;
  309. m_pButtonViewWeek->AdjustLayout(pDC, rc);
  310. rc.left = m_pButtonViewWeek->GetRect().right;
  311. rc.right = rc.left + 83;
  312. m_pButtonViewMonth->AdjustLayout(pDC, rc);
  313. //--------------------------------------
  314. rc.left = m_pButtonViewMonth->GetRect().right + 21;
  315. rc.right = rc.left + 5;
  316. m_pShowWorkWeek->AdjustLayout(pDC, rc);
  317. rc.left = m_pShowWorkWeek->GetRect().right + 11;
  318. rc.right = rc.left + 5;
  319. m_pShowFullWeek->AdjustLayout(pDC, rc);
  320. //--------------------------------------
  321. // to align next controls
  322. rc = m_pButtonViewDay->GetRect();
  323. nNextY = rc.bottom + 1;
  324. }
  325. else
  326. {
  327. m_pButtonViewDay->AdjustLayout(pDC, rc00);
  328. m_pButtonViewWeek->AdjustLayout(pDC, rc00);
  329. m_pButtonViewMonth->AdjustLayout(pDC, rc00);
  330. m_pShowWorkWeek->SetVisible(FALSE);
  331. m_pShowFullWeek->SetVisible(FALSE);
  332. m_pShowWorkWeek->AdjustLayout(pDC, rc00);
  333. m_pShowFullWeek->AdjustLayout(pDC, rc00);
  334. nNextY = rc.top;
  335. }
  336. int nNextX = rc.left;
  337. //--------------------------------------
  338. m_pScrollPrevDate->SetVisible(IsScrollDateButtons());
  339. m_pScrollNextDate->SetVisible(IsScrollDateButtons());
  340. if (IsScrollDateButtons())
  341. {
  342. rc.top = nNextY + 12;
  343. rc.bottom = rc.top + 20;
  344. rc.left += 20;
  345. rc.right = rc.left + 20;
  346. m_pScrollPrevDate->AdjustLayout(pDC, rc);
  347. rc.left = m_pScrollPrevDate->GetRect().right + 9;
  348. rc.right = rc.left + 20;
  349. m_pScrollNextDate->AdjustLayout(pDC, rc);
  350. nNextX = rc.right;
  351. }
  352. else
  353. {
  354. m_pScrollPrevDate->AdjustLayout(pDC, rc00);
  355. m_pScrollNextDate->AdjustLayout(pDC, rc00);
  356. }
  357. //--------------------------------------
  358. m_pDateLabel->SetVisible(IsDateLabel());
  359. if (IsDateLabel())
  360. {
  361. rc.top = nNextY + 12;
  362. rc.bottom = rc.top + 20;
  363. rc.left = nNextX + 11;
  364. rc.right = m_rcRect.right - 2;
  365. m_pDateLabel->AdjustLayout(pDC, rc);
  366. }
  367. else
  368. {
  369. m_pDateLabel->AdjustLayout(pDC, rc00);
  370. }
  371. }
  372. COLORREF CXTPCalendarCaptionBarTheme::GetColor2(LPCTSTR pcszColorName, COLORREF clrDefault)
  373. {
  374. COLORREF clrColor = COLORREF_NULL;
  375. if (XTPOffice2007Images()->IsValid())
  376. {
  377. clrColor = XTPOffice2007Images()->GetImageColor(_T("CalendarControl"), pcszColorName);
  378. }
  379. if (clrColor == COLORREF_NULL)
  380. {
  381. clrColor = clrDefault;
  382. }
  383. return clrColor;
  384. }
  385. void CXTPCalendarCaptionBarTheme::RefreshMetrics()
  386. {
  387. m_themeButton.OpenTheme(0, L"BUTTON");
  388. LOGFONT lfBaseFont;
  389. ::ZeroMemory(&lfBaseFont, sizeof(lfBaseFont));
  390. BOOL bUseFont2007 = FALSE;
  391. if (GetPaintTheme() >= xtpCalendarThemeOffice2007)
  392. {
  393. m_clrSwitchViewBarBk.SetStandardValue(GetColor2(_T("CaptionBarSwitchViewBarBk"), RGB(173, 209, 255)));
  394. m_clrScrollDateBarBk.SetStandardValue(GetColor2(_T("CaptionBarDateBarBk"), RGB(227, 239, 255)));
  395. m_clrBorders.SetStandardValue(GetColor2(_T("CaptionBarBorders"), RGB(101, 147, 201)));
  396. m_clrTextColor.SetStandardValue(RGB(0, 0, 0));
  397. // Try to set default Office 2007 font,
  398. // otherwise icon font used.
  399. bUseFont2007 = XTPDrawHelpers()->FontExists(XTP_CALENDAR_OFFICE2007_FONT_NAME);
  400. }
  401. else
  402. {
  403. //m_clrSwitchViewBarBk.SetStandardValue(RGB(192, 192, 192));
  404. m_clrSwitchViewBarBk.SetStandardValue(GetSysColor(COLOR_BTNFACE));
  405. if (GetPaintTheme() == xtpCalendarThemeOffice2000)
  406. m_clrScrollDateBarBk.SetStandardValue(RGB(146, 146, 146));
  407. else
  408. m_clrScrollDateBarBk.SetStandardValue(RGB(130, 130, 130));
  409. m_clrBorders.SetStandardValue(RGB(130, 130, 130));
  410. m_clrTextColor.SetStandardValue(RGB(255, 255, 255));
  411. }
  412. if (bUseFont2007)
  413. {
  414. STRCPY_S(lfBaseFont.lfFaceName, LF_FACESIZE, XTP_CALENDAR_OFFICE2007_FONT_NAME);
  415. lfBaseFont.lfCharSet = DEFAULT_CHARSET;
  416. lfBaseFont.lfHeight = -11;
  417. lfBaseFont.lfWeight = FW_NORMAL;
  418. if (XTPSystemVersion()->IsClearTypeTextQualitySupported())
  419. lfBaseFont.lfQuality = 5;
  420. }
  421. else
  422. {
  423. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfBaseFont), &lfBaseFont, 0));
  424. }
  425. m_fntTextFont.SetStandardValue(&lfBaseFont);
  426. //-----------------------------------------------
  427. int nCount = m_arMembers.GetCount();
  428. for (int i = 0; i < nCount; i++)
  429. {
  430. CXTPCalendarCaptionBarThemePart* pPart = m_arMembers.GetAt(i);
  431. ASSERT(pPart);
  432. if (pPart)
  433. pPart->RefreshMetrics();
  434. }
  435. //-----------------------------------------------
  436. AdjustLayout(NULL, GetRect());
  437. }
  438. void CXTPCalendarCaptionBarTheme::Draw(CDC* pDC)
  439. {
  440. #ifdef _DEBUG
  441. pDC->FillSolidRect(GetRect(), RGB(255, 0, 0));
  442. #endif
  443. //_UpdateControlsHotState();
  444. // Fill SwitchViewBar
  445. CRect rcTopPart = m_pButtonViewDay->GetRect();
  446. rcTopPart.right = m_rcRect.right;
  447. pDC->FillSolidRect(rcTopPart, m_clrSwitchViewBarBk);
  448. rcTopPart.top = rcTopPart.bottom;
  449. rcTopPart.bottom++;
  450. pDC->FillSolidRect(rcTopPart, m_clrBorders); // m_clrSwitchViewBarBottomBorder);
  451. // Fill ScrollDateBar
  452. CRect rcBottomPart = m_rcRect;
  453. rcBottomPart.top = rcTopPart.bottom;
  454. pDC->FillSolidRect(rcBottomPart, m_clrScrollDateBarBk);
  455. // Draw borders
  456. CRect rc = m_rcRect;
  457. rc.bottom = rc.top + 1;
  458. pDC->FillSolidRect(rc, m_clrBorders);
  459. // Draw members
  460. int nCount = m_arMembers.GetCount();
  461. for (int i = 0; i < nCount; i++)
  462. {
  463. CXTPCalendarCaptionBarThemePart* pPart = m_arMembers.GetAt(i);
  464. ASSERT(pPart);
  465. if (pPart)
  466. pPart->Draw(pDC);
  467. }
  468. }
  469. //////////////////////////////////////////////////////////////////////////
  470. CXTPCalendarCaptionBarThemePart::CXTPCalendarCaptionBarThemePart(CXTPCalendarCaptionBarTheme* pTheme, int nPartID)
  471. {
  472. ASSERT(pTheme);
  473. m_pTheme = pTheme;
  474. m_nPartID = nPartID;
  475. m_nState = xtpBtnStateNormal;
  476. m_bVisible = TRUE;
  477. if (m_pTheme)
  478. m_pTheme->m_arMembers.Add(this, TRUE);
  479. }
  480. CXTPCalendarCaptionBarThemePart::~CXTPCalendarCaptionBarThemePart()
  481. {
  482. }
  483. void CXTPCalendarCaptionBarThemePart::AdjustLayout(CDC* /*pDC*/, const CRect& rcRect)
  484. {
  485. m_rcRect = rcRect;
  486. }
  487. COLORREF CXTPCalendarCaptionBarThemePart::GetTextColor()
  488. {
  489. if (m_clrTextColor.IsDefaultValue() && m_pTheme)
  490. return (COLORREF)m_pTheme->m_clrTextColor;
  491. return (COLORREF)m_clrTextColor;
  492. }
  493. void CXTPCalendarCaptionBarThemePart::Draw(CDC* /*pDC*/)
  494. {
  495. //  if (!IsVisible())
  496. //      return;
  497. //
  498. //#ifdef _DEBUG
  499. //  if (m_nState == xtpBtnStateMouseOver)
  500. //  {
  501. //      pDC->FillSolidRect(GetRect(), RGB(155, 0, 0));
  502. //  }
  503. //  else if (m_nState & xtpBtnStatePressed)
  504. //  {
  505. //      pDC->FillSolidRect(GetRect(), RGB(255, 0, 0));
  506. //  }
  507. //  else if (m_nState & xtpBtnStateChecked)
  508. //  {
  509. //      pDC->FillSolidRect(GetRect(), RGB(0, 0, 0));
  510. //  }
  511. //  else
  512. //      pDC->FillSolidRect(GetRect(), RGB(51 * m_nPartID % 255, 51 * m_nPartID % 255, 111 * m_nPartID % 255));
  513. //
  514. //#endif
  515. };
  516. BOOL CXTPCalendarCaptionBarThemePart::HitTest(const CPoint& pt)
  517. {
  518. return IsVisible() && m_rcRect.PtInRect(pt);
  519. };
  520. void CXTPCalendarCaptionBarThemePart::Redraw(BOOL bUpdateNow)
  521. {
  522. if (m_pTheme)
  523. m_pTheme->Redraw(bUpdateNow);
  524. }
  525. void CXTPCalendarCaptionBarTheme::Redraw(BOOL bUpdateNow)
  526. {
  527. if (GetOwnerWnd() && GetOwnerWnd()->GetSafeHwnd())
  528. {
  529. GetOwnerWnd()->Invalidate(FALSE);
  530. if (bUpdateNow)
  531. GetOwnerWnd()->UpdateWindow();
  532. }
  533. }
  534. void CXTPCalendarCaptionBarThemePart::OnMouseMove(UINT nFlags, CPoint point)
  535. {
  536. UNREFERENCED_PARAMETER(nFlags);
  537. int nStatePrev = m_nState;
  538. if (HitTest(point))
  539. m_nState = m_nState | xtpBtnStateMouseOver;
  540. else
  541. m_nState = m_nState & (~(xtpBtnStateMouseOver));
  542. if (nStatePrev != m_nState)
  543. Redraw();
  544. }
  545. BOOL CXTPCalendarCaptionBarThemePart::OnLButtonDown(UINT nFlags, CPoint point)
  546. {
  547. UNREFERENCED_PARAMETER(nFlags);
  548. int nStatePrev = m_nState;
  549. BOOL bHitTest = HitTest(point);
  550. if (bHitTest)
  551. {
  552. m_nState = m_nState | xtpBtnStatePressed | xtpBtnStateFocused;
  553. }
  554. else
  555. m_nState = m_nState & (~(xtpBtnStatePressed | xtpBtnStateFocused));
  556. if (nStatePrev != m_nState)
  557. Redraw();
  558. return FALSE; // to allow receive this notification for all other parts (to clear state)
  559. }
  560. BOOL CXTPCalendarCaptionBarThemePart::OnLButtonUp(UINT nFlags, CPoint point)
  561. {
  562. UNREFERENCED_PARAMETER(nFlags);
  563. int nStatePrev = m_nState;
  564. BOOL bHitTest = HitTest(point);
  565. //  if (bHitTest)
  566. //  {
  567. //      TRACE(_T("%d = [PartID=%d] CXTPCalendarCaptionBarThemePart::OnLButtonUP(%d, %d) n"), dbg_xtp_Counter++,
  568. //                      m_nPartID, point.x, point.y);
  569. //  }
  570. if (bHitTest && (m_nState & (xtpBtnStatePressed | xtpBtnStateFocused)))
  571. {
  572. m_nState = m_nState & (~xtpBtnStatePressed);
  573. if (m_pTheme && IsVisible())
  574. m_pTheme->OnPartClick(m_nPartID);
  575. }
  576. m_nState = m_nState & (~xtpBtnStatePressed);
  577. if (nStatePrev != m_nState)
  578. Redraw();
  579. return FALSE; // to allow receive this notification for all other parts (to clear state)
  580. }
  581. void CXTPCalendarCaptionBarTheme::OnEvent_Calendar(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  582. {
  583. UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  584. if (Event == XTP_NC_CALENDARVIEWWASCHANGED)
  585. {
  586. UpdateControlsState();
  587. }
  588. else if (Event == XTP_NC_CALENDAR_THEME_CHANGED)
  589. {
  590. SetPaintTheme(GetCalendarCtrl()->GetPaintTheme());
  591. }
  592. else {
  593. ASSERT(FALSE);
  594. return;
  595. }
  596. if (GetOwnerWnd())
  597. GetOwnerWnd()->Invalidate(FALSE);
  598. }
  599. void CXTPCalendarCaptionBarTheme::OnEvent_Office2007ImagesChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam)
  600. {
  601. UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam);
  602. if (Event == XTP_NC_COMMON_OFFICE2007IMAGES_CHANGED)
  603. {
  604. RefreshMetrics();
  605. Redraw();
  606. }
  607. }
  608. void CXTPCalendarCaptionBarTheme::UpdateControlsState()
  609. {
  610. if (!GetCalendarCtrl() || !GetCalendarCtrl()->GetActiveView())
  611. {
  612. return;
  613. }
  614. m_pShowWorkWeek->SetVisible(FALSE);
  615. m_pShowFullWeek->SetVisible(FALSE);
  616. m_pButtonViewDay->SetCheck(0);
  617. m_pButtonViewWeek->SetCheck(0);
  618. m_pButtonViewMonth->SetCheck(0);
  619. int nViewType = GetCalendarCtrl()->GetActiveView()->GetViewType();
  620. if (nViewType == xtpCalendarDayView)
  621. {
  622. m_pButtonViewDay->SetCheck(1);
  623. }
  624. else if (nViewType == xtpCalendarMonthView)
  625. {
  626. m_pButtonViewMonth->SetCheck(1);
  627. }
  628. else if (nViewType == xtpCalendarWeekView)
  629. {
  630. // the theme 2003 view type.
  631. }
  632. else
  633. {
  634. m_pButtonViewWeek->SetCheck(1);
  635. if (IsSwitchViewButtons())
  636. {
  637. m_pShowWorkWeek->SetVisible(TRUE);
  638. m_pShowFullWeek->SetVisible(TRUE);
  639. }
  640. if (nViewType == xtpCalendarWorkWeekView)
  641. {
  642. m_pShowWorkWeek->SetCheck(1);
  643. m_pShowFullWeek->SetCheck(0);
  644. }
  645. else if (nViewType == xtpCalendarFullWeekView)
  646. {
  647. m_pShowWorkWeek->SetCheck(0);
  648. m_pShowFullWeek->SetCheck(1);
  649. }
  650. else {
  651. ASSERT(FALSE);
  652. }
  653. }
  654. }
  655. void CXTPCalendarCaptionBarTheme::OnPartClick(int nPartID)
  656. {
  657. //  TRACE(_T("%d = CXTPCalendarCaptionBarTheme::OnPartClick(PartID=%d) n"), dbg_xtp_Counter++, nPartID);
  658. //CWaitCursor _wc;
  659. if (!GetCalendarCtrl() || !GetCalendarCtrl()->GetActiveView())
  660. {
  661. ASSERT(FALSE);
  662. return;
  663. }
  664. if (nPartID == xtpCalendarCaptionBar_ButtonViewDay)
  665. {
  666. GetCalendarCtrl()->SwitchActiveView(xtpCalendarDayView);
  667. GetCalendarCtrl()->SetFocus();
  668. }
  669. else if (nPartID == xtpCalendarCaptionBar_ButtonViewWeek)
  670. {
  671. if (m_pShowWorkWeek->GetCheck())
  672. GetCalendarCtrl()->SwitchActiveView(xtpCalendarWorkWeekView);
  673. else
  674. GetCalendarCtrl()->SwitchActiveView(xtpCalendarFullWeekView);
  675. GetCalendarCtrl()->SetFocus();
  676. }
  677. else if (nPartID == xtpCalendarCaptionBar_ButtonViewMonth)
  678. {
  679. GetCalendarCtrl()->SwitchActiveView(xtpCalendarMonthView);
  680. GetCalendarCtrl()->SetFocus();
  681. }
  682. else if (nPartID == xtpCalendarCaptionBar_ShowWorkWeek)
  683. {
  684. GetCalendarCtrl()->SwitchActiveView(xtpCalendarWorkWeekView);
  685. GetCalendarCtrl()->SetFocus();
  686. }
  687. else if (nPartID == xtpCalendarCaptionBar_ShowFullWeek)
  688. {
  689. GetCalendarCtrl()->SwitchActiveView(xtpCalendarFullWeekView);
  690. GetCalendarCtrl()->SetFocus();
  691. }
  692. else if (nPartID == xtpCalendarCaptionBar_ScrollPrevDate ||
  693.  nPartID == xtpCalendarCaptionBar_ScrollNextDate)
  694. {
  695. CXTPCalendarView* pActiveView = GetCalendarCtrl()->GetActiveView();
  696. int nViewType = pActiveView->GetViewType();
  697. BOOL bNext = nPartID == xtpCalendarCaptionBar_ScrollNextDate;
  698. COleDateTime dtSelStart, dtSelEnd, dtFirst;
  699. int nGroupIndex = 0;
  700. BOOL bAllDay = TRUE;
  701. dtFirst = pActiveView->GetViewDayDate(0);
  702. if (!pActiveView->GetSelection(&dtSelStart, &dtSelEnd, &bAllDay, &nGroupIndex))
  703. {
  704. dtSelStart = dtFirst;
  705. dtSelEnd = dtFirst + COleDateTimeSpan(1);
  706. }
  707. if (nViewType == xtpCalendarDayView)
  708. {
  709. int nDays = pActiveView->GetViewDayCount();
  710. dtSelStart += COleDateTimeSpan(bNext ? nDays : -nDays);
  711. dtSelEnd += COleDateTimeSpan(bNext ? nDays : -nDays);
  712. }
  713. else if (nViewType == xtpCalendarWorkWeekView ||
  714.  nViewType == xtpCalendarFullWeekView ||
  715.  nViewType == xtpCalendarWeekView)
  716. {
  717. dtSelStart += COleDateTimeSpan(bNext ? 7 : -7);
  718. dtSelEnd += COleDateTimeSpan(bNext ? 7 : -7);
  719. }
  720. else if (nViewType == xtpCalendarMonthView)
  721. {
  722. int nSelDay = dtSelStart.GetDay();
  723. CXTPCalendarUtils::ShiftDate_Month(dtSelStart, bNext ? 1 : -1, 1);
  724. CXTPCalendarUtils::UpdateMonthDay(dtSelStart, nSelDay);
  725. dtSelEnd = dtSelStart + COleDateTimeSpan(1);
  726. }
  727. else
  728. {
  729. ASSERT(FALSE);
  730. }
  731. pActiveView->SetSelection(dtSelStart, dtSelEnd, bAllDay, nGroupIndex);
  732. GetCalendarCtrl()->SwitchActiveView((XTPCalendarViewType)nViewType);
  733. }
  734. else
  735. {
  736. return;
  737. }
  738. UpdateControlsState();
  739. if (GetOwnerWnd())
  740. GetOwnerWnd()->Invalidate(FALSE);
  741. }
  742. BOOL CXTPCalendarCaptionBarTheme::_UpdateControlsHotState(BOOL* pbMouseLeave)
  743. {
  744. if (pbMouseLeave)
  745. *pbMouseLeave = FALSE;
  746. CPoint ptMouse(0, 0);
  747. if (GetCursorPos(&ptMouse) && GetOwnerWnd())
  748. GetOwnerWnd()->ScreenToClient(&ptMouse);
  749. else
  750. return FALSE;
  751. BOOL bMouseLeave = !m_rcRect.PtInRect(ptMouse);
  752. if (pbMouseLeave)
  753. *pbMouseLeave = bMouseLeave;
  754. if (!bMouseLeave)
  755. return FALSE;
  756. BOOL bResetFocused = CWnd::GetFocus() != GetOwnerWnd();
  757. //-------------------------------------------------------------------------
  758. BOOL bChanged = FALSE;
  759. int nCount = m_arMembers.GetCount();
  760. for (int i = 0; i < nCount; i++)
  761. {
  762. CXTPCalendarCaptionBarThemePart* pPart = m_arMembers.GetAt(i);
  763. ASSERT(pPart);
  764. if (pPart)
  765. {
  766. int nNewState = pPart->GetState() & (~(CXTPCalendarCaptionBarThemePart::xtpBtnStateMouseOver |
  767.    CXTPCalendarCaptionBarThemePart::xtpBtnStatePressed));
  768. if (bResetFocused)
  769. nNewState = nNewState & (~CXTPCalendarCaptionBarThemePart::xtpBtnStateFocused);
  770. if (nNewState != pPart->GetState())
  771. {
  772. pPart->SetState(nNewState);
  773. bChanged = TRUE;
  774. }
  775. }
  776. }
  777. return bChanged;
  778. }
  779. void CXTPCalendarCaptionBarTheme::OnKillFocus (CWnd* pNewWnd)
  780. {
  781. UNREFERENCED_PARAMETER(pNewWnd);
  782. BOOL bChanged = _UpdateControlsHotState();
  783. if (bChanged)
  784. GetOwnerWnd()->Invalidate(FALSE);
  785. }
  786. void CXTPCalendarCaptionBarTheme::CSwitchViewButtonPart::RefreshMetrics()
  787. {
  788. if (GetPaintTheme() <= xtpCalendarThemeOffice2003)
  789. {
  790. m_clrTextColor.SetStandardValue(RGB(0, 0, 0));
  791. }
  792. }
  793. void CXTPCalendarCaptionBarTheme::CSwitchViewButtonPart::AdjustLayout(CDC* pDC, const CRect& rcRect)
  794. {
  795. m_rcRect = rcRect;
  796. if (m_rcRect.IsRectEmpty())
  797. return;
  798. if (pDC)
  799. {
  800. CXTPFontDC autoFont(pDC, GetTheme()->m_fntTextFont);
  801. CSize szText = pDC->GetTextExtent(GetText());
  802. if (szText.cx + 8 > m_rcRect.Width())
  803. m_rcRect.right = m_rcRect.left + szText.cx + 8;
  804. }
  805. }
  806. void CXTPCalendarCaptionBarTheme::CSwitchViewButtonPart::Draw(CDC* pDC)
  807. {
  808. if (!IsVisible())
  809. return;
  810. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_T("CALENDARCAPTIONBARSWITCHVIEWBUTTON"));
  811. CRect rcRect = GetRect();
  812. ASSERT(pImage);
  813. if (!pImage || !GetTheme())
  814. {
  815. pDC->FillSolidRect(rcRect , RGB(155, 0, 0));
  816. return;
  817. }
  818. if (GetPaintTheme() >= xtpCalendarThemeOffice2007)
  819. {
  820. int nImagePart = (m_nState & xtpBtnStateChecked) ? 3 : 0;
  821. if (m_nState & xtpBtnStatePressed)
  822. {
  823. nImagePart += 2;
  824. }
  825. else if (m_nState & xtpBtnStateMouseOver)
  826. {
  827. nImagePart += 1;
  828. }
  829. pImage->DrawImage(pDC, rcRect, pImage->GetSource(nImagePart, 6), CRect(0, 0, 0, 0));
  830. rcRect.left = rcRect.right - 1;
  831. pDC->FillSolidRect(&rcRect, GetTheme()->m_clrBorders);
  832. }
  833. else
  834. {
  835. if (GetTheme()->m_themeButton.IsAppThemed() &&
  836. GetPaintTheme() == xtpCalendarThemeOffice2003)
  837. {
  838. int nState = (m_nState & xtpBtnStatePressed) ? PBS_PRESSED :
  839.  (m_nState & xtpBtnStateMouseOver) ? PBS_HOT: PBS_NORMAL;
  840. if (m_nState & xtpBtnStateChecked)
  841. nState = PBS_PRESSED;
  842. GetTheme()->m_themeButton.DrawThemeBackground(pDC->GetSafeHdc(), BP_PUSHBUTTON, nState, rcRect, NULL);
  843. }
  844. else
  845. {
  846. UINT uFlags = DFCS_BUTTONPUSH | //DFCS_FLAT |
  847. ((m_nState & xtpBtnStateChecked) ? DFCS_CHECKED : 0) |
  848. ((m_nState & xtpBtnStatePressed) ? DFCS_PUSHED : 0); // | (bEnabled ? 0 : DFCS_INACTIVE)
  849. //          if (GetPaintTheme() > xtpCalendarThemeOffice2000)
  850. //              uFlags |= DFCS_FLAT;
  851. ::DrawFrameControl(pDC->GetSafeHdc(), rcRect, DFC_BUTTON, uFlags);
  852. }
  853. }
  854. // drawText
  855. CFont fntTmp;
  856. CXTPFontDC autoFont(pDC, GetTheme()->m_fntTextFont, GetTextColor());
  857. if ((m_nState & xtpBtnStateChecked) && GetPaintTheme() <= xtpCalendarThemeOffice2003)
  858. {
  859. LOGFONT lf;
  860. if (GetTheme()->m_fntTextFont->GetLogFont(&lf))
  861. {
  862. lf.lfWeight = FW_BOLD;
  863. if (fntTmp.CreateFontIndirect(&lf))
  864. autoFont.SetFont(&fntTmp);
  865. }
  866. }
  867. CRect rcText = GetRect();
  868. rcText.DeflateRect(1, 1, 1, 1);
  869. pDC->SetBkMode(TRANSPARENT);
  870. pDC->DrawText(GetText(), rcText, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
  871. }
  872. LPCTSTR CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::_GetImageName()
  873. {
  874. if (m_nPartID == xtpCalendarCaptionBar_ScrollNextDate)
  875. return _T("CALENDARCAPTIONBARNEXTDATEBUTTON");
  876. return _T("CALENDARCAPTIONBARPREVDATEBUTTON");
  877. }
  878. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::AdjustLayout(CDC* /*pDC*/, const CRect& rcRect)
  879. {
  880. m_rcRect = rcRect;
  881. if (m_rcRect.IsRectEmpty())
  882. return;
  883. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_GetImageName());
  884. ASSERT(pImage);
  885. if (!pImage || !GetTheme())
  886. return;
  887. CRect rcImage = pImage->GetSource(0, 4);
  888. m_rcRect.right = m_rcRect.left + rcImage.Width();
  889. m_rcRect.bottom = m_rcRect.top + rcImage.Height();
  890. }
  891. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::Draw(CDC* pDC)
  892. {
  893. if (!IsVisible())
  894. return;
  895. CRect rcRect = GetRect();
  896. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_GetImageName());
  897. ASSERT(pImage);
  898. if (!pImage || !GetTheme())
  899. {
  900. pDC->FillSolidRect(rcRect, RGB(155, 0, 0));
  901. return;
  902. }
  903. if (GetPaintTheme() == xtpCalendarThemeOffice2007)
  904. {
  905. int nImagePart = (m_nState & xtpBtnStatePressed) ? 2 : (m_nState & xtpBtnStateMouseOver) ? 1 : 0;
  906. pImage->DrawImage(pDC, rcRect, pImage->GetSource(nImagePart, 4),
  907. CRect(0, 0, 0, 0), RGB(255, 0, 255));
  908. if (m_nState & xtpBtnStateFocused)
  909. pImage->DrawImage(pDC, GetRect(), pImage->GetSource(3, 4),
  910. CRect(1, 1, 1, 1), RGB(255, 0, 255));
  911. }
  912. else
  913. {
  914. if (GetTheme()->m_themeButton.IsAppThemed() &&
  915. GetPaintTheme() == xtpCalendarThemeOffice2003)
  916. {
  917. int nState = (m_nState & xtpBtnStatePressed) ? PBS_PRESSED :
  918.  (m_nState & xtpBtnStateMouseOver) ? PBS_HOT: PBS_NORMAL;
  919. GetTheme()->m_themeButton.DrawThemeBackground(pDC->GetSafeHdc(), BP_PUSHBUTTON, nState, rcRect, NULL);
  920. }
  921. else
  922. {
  923. UINT uFlags = DFCS_BUTTONPUSH |
  924. ((m_nState & xtpBtnStateChecked) ? DFCS_CHECKED : 0) |
  925. ((m_nState & xtpBtnStatePressed) ? DFCS_PUSHED : 0); // | (bEnabled ? 0 : DFCS_INACTIVE)
  926. //if (GetPaintTheme() > xtpCalendarThemeOffice2000)
  927. //  uFlags = uFlags | DFCS_FLAT;
  928. ::DrawFrameControl(pDC->GetSafeHdc(), rcRect, DFC_BUTTON, uFlags);
  929. }
  930. BOOL bLeftDirection = GetPartID() == xtpCalendarCaptionBar_ScrollPrevDate;
  931. DrawScrollTriangle(pDC, rcRect, bLeftDirection, RGB(0, 0, 0));
  932. }
  933. }
  934. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::_DrawTriangle(CDC* pDC, CPoint pt0, CPoint pt1, CPoint pt2, COLORREF clrColor)
  935. {
  936. CXTPPenDC pen (*pDC, clrColor);
  937. CXTPBrushDC brush (*pDC, clrColor);
  938. CPoint pts[3];
  939. pts[0] = pt0;
  940. pts[1] = pt1;
  941. pts[2] = pt2;
  942. pDC->Polygon(pts, 3);
  943. }
  944. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::DrawScrollTriangle(CDC* pDC, CRect rcRect, BOOL bLeftDirection, COLORREF clrColor)
  945. {
  946. CPoint ptCenter(rcRect.CenterPoint());
  947. ptCenter.y--;
  948. if (bLeftDirection)
  949. {
  950. ptCenter.x -= 3;
  951. _DrawTriangle(pDC, ptCenter, CPoint(ptCenter.x + 4, ptCenter.y - 4),
  952.   CPoint(ptCenter.x + 4, ptCenter.y + 4), clrColor);
  953. }
  954. else
  955. {
  956. ptCenter.x += 2;
  957. _DrawTriangle(pDC, ptCenter, CPoint(ptCenter.x - 4, ptCenter.y - 4),
  958.   CPoint(ptCenter.x - 4, ptCenter.y + 4), clrColor);
  959. }
  960. }
  961. BOOL CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::OnLButtonDown(UINT nFlags, CPoint point)
  962. {
  963. CXTPCalendarCaptionBarThemePart::OnLButtonDown(nFlags, point);
  964. if (GetTheme() && GetTheme()->GetOwnerWnd() && HitTest(point) &&
  965. CWnd::GetFocus() != GetTheme()->GetOwnerWnd() )
  966. {
  967. GetTheme()->GetOwnerWnd()->SetFocus();
  968. }
  969. return FALSE;
  970. }
  971. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  972. {
  973. UNREFERENCED_PARAMETER(nRepCnt);  UNREFERENCED_PARAMETER(nFlags);
  974. if (!IsVisible())
  975. return;
  976. if ((m_nState & xtpBtnStateFocused) && (m_nState & xtpBtnStatePressed) == 0 &&
  977. nChar == VK_SPACE)
  978. {
  979. m_nState |= xtpBtnStatePressed;
  980. Redraw();
  981. }
  982. }
  983. void CXTPCalendarCaptionBarTheme::CScrollDateButtonPart::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  984. {
  985. UNREFERENCED_PARAMETER(nRepCnt);  UNREFERENCED_PARAMETER(nFlags);
  986. if (!IsVisible())
  987. return;
  988. int nMask = xtpBtnStateFocused | xtpBtnStatePressed;
  989. if ((m_nState & nMask) == nMask && nChar == VK_SPACE && GetTheme())
  990. {
  991. GetTheme()->OnPartClick(GetPartID());
  992. }
  993. if (nChar == VK_SPACE)
  994. {
  995. m_nState = m_nState & (~xtpBtnStatePressed);
  996. Redraw();
  997. }
  998. }
  999. void CXTPCalendarCaptionBarTheme::CRadioButtonPart::RefreshMetrics()
  1000. {
  1001. if (GetPaintTheme() <= xtpCalendarThemeOffice2003)
  1002. {
  1003. m_clrTextColor.SetStandardValue(RGB(0, 0, 0));
  1004. }
  1005. }
  1006. void CXTPCalendarCaptionBarTheme::CRadioButtonPart::AdjustLayout(CDC* pDC, const CRect& rcRect)
  1007. {
  1008. m_rcRect = rcRect;
  1009. if (m_rcRect.IsRectEmpty())
  1010. return;
  1011. CSize szRadio(13, 13);
  1012. CRect rcRadio = GetRect();
  1013. if (GetTheme() && GetTheme()->m_themeButton.IsAppThemed())
  1014. {
  1015. GetTheme()->m_themeButton.GetThemePartSize(NULL, BP_RADIOBUTTON, 1, rcRadio, TS_DRAW, &szRadio);
  1016. }
  1017. if (pDC)
  1018. {
  1019. CXTPFontDC autoFont(pDC, GetTheme()->m_fntTextFont);
  1020. CSize szText = pDC->GetTextExtent(GetText());
  1021. if (szRadio.cx + 9 + szText.cx + 8 > m_rcRect.Width())
  1022. m_rcRect.right = m_rcRect.left + szRadio.cx + 9 + szText.cx + 8;
  1023. szRadio.cy = max(szRadio.cy, szText.cy);
  1024. }
  1025. m_rcRect.top += (m_rcRect.Height() - szRadio.cy) / 2 + 1;
  1026. m_rcRect.bottom = m_rcRect.top + szRadio.cy;
  1027. }
  1028. void CXTPCalendarCaptionBarTheme::CRadioButtonPart::Draw(CDC* pDC)
  1029. {
  1030. if (!IsVisible())
  1031. return;
  1032. CSize szRadio(13, 13);
  1033. CRect rcRadio = GetRect();
  1034. BOOL bThemed = GetTheme() && GetTheme()->m_themeButton.IsAppThemed() &&
  1035. GetPaintTheme() >= xtpCalendarThemeOffice2003;
  1036. if (bThemed)
  1037. {
  1038. GetTheme()->m_themeButton.GetThemePartSize(NULL, BP_RADIOBUTTON, 1, rcRadio, TS_DRAW, &szRadio);
  1039. }
  1040. rcRadio.top += (rcRadio.Height() - szRadio.cy) / 2 + 1;
  1041. rcRadio.bottom = rcRadio.top + szRadio.cy;
  1042. rcRadio.right = rcRadio.left + szRadio.cx;
  1043. if (bThemed)
  1044. {
  1045. GetTheme()->m_themeButton.GetThemePartSize(NULL, BP_RADIOBUTTON, 1, rcRadio, TS_DRAW, &szRadio);
  1046. //-------------------
  1047. int nState = (m_nState & xtpBtnStatePressed) ? RBS_UNCHECKEDPRESSED :
  1048.  (m_nState & xtpBtnStateMouseOver) ? RBS_UNCHECKEDHOT: RBS_UNCHECKEDNORMAL;
  1049. if (m_nState & xtpBtnStateChecked)
  1050. nState += 4;
  1051. GetTheme()->m_themeButton.DrawThemeBackground(pDC->GetSafeHdc(), BP_RADIOBUTTON, nState, rcRadio, NULL);
  1052. }
  1053. else
  1054. {
  1055. UINT uFlags = DFCS_BUTTONRADIO | //DFCS_FLAT |
  1056. ((m_nState & xtpBtnStateChecked) ? DFCS_CHECKED : 0) |
  1057. ((m_nState & xtpBtnStatePressed) ? DFCS_PUSHED : 0); // | (bEnabled ? 0 : DFCS_INACTIVE)
  1058. if (GetPaintTheme() > xtpCalendarThemeOffice2000)
  1059. uFlags |= DFCS_FLAT;
  1060. ::DrawFrameControl(pDC->GetSafeHdc(), rcRadio, DFC_BUTTON, uFlags);
  1061. }
  1062. // drawText
  1063. CXTPFontDC autoFont(pDC, GetTheme()->m_fntTextFont, GetTextColor());
  1064. pDC->SetBkMode(TRANSPARENT);
  1065. CRect rcText = GetRect();
  1066. //rcText.top +=2;
  1067. rcText.bottom +=1;
  1068. rcText.left = rcRadio.right + 9;
  1069. pDC->DrawText(GetText(), rcText, DT_BOTTOM | DT_LEFT | DT_SINGLELINE);
  1070. rcText.left--;
  1071. rcText.right++;
  1072. if (m_nState & xtpBtnStatePressed)
  1073. pDC->DrawFocusRect(rcText);
  1074. }
  1075. void CXTPCalendarCaptionBarTheme::CDateLabelPart::RefreshMetrics()
  1076. {
  1077. if (!GetTheme())
  1078. return;
  1079. m_clrTextColor.SetStandardValue(GetTheme()->m_clrTextColor);
  1080. LOGFONT lfBaseFont;
  1081. ::ZeroMemory(&lfBaseFont, sizeof(lfBaseFont));
  1082. GetTheme()->m_fntTextFont->GetLogFont(&lfBaseFont);
  1083. lfBaseFont.lfHeight = -20;
  1084. m_fntTextFont.SetStandardValue(&lfBaseFont);
  1085. }
  1086. void CXTPCalendarCaptionBarTheme::CDateLabelPart::Draw(CDC* pDC)
  1087. {
  1088. if (!IsVisible())
  1089. return;
  1090. CXTPFontDC autoFont(pDC, m_fntTextFont, m_clrTextColor);
  1091. pDC->SetBkMode(TRANSPARENT);
  1092. CXTPCalendarView* pCalView = XTP_SAFE_GET2(GetTheme(), GetCalendarCtrl(), GetActiveView(), NULL);
  1093. ASSERT(pCalView);
  1094. if (!pCalView || !IsVisible())
  1095. return;
  1096. BOOL bShowMonthDay = pCalView->GetViewType() != xtpCalendarMonthView;
  1097. COleDateTime dtDay1 = pCalView->GetViewDayDate(0);
  1098. COleDateTime dtDay2 = pCalView->GetViewDayDate(max(0, pCalView->GetViewDayCount() - 1));
  1099. m_strText = _FormatDate(dtDay1, dtDay2, bShowMonthDay);
  1100. CRect rcText = GetRect();
  1101. //rcText.top +=2;
  1102. rcText.bottom +=1;
  1103. //rcText.left = rcRadio.right + 9;
  1104. UINT uFlags = DT_BOTTOM | DT_SINGLELINE;
  1105. if (GetTheme() && !GetTheme()->IsScrollDateButtons() &&
  1106. GetPaintTheme() < xtpCalendarThemeOffice2007)
  1107. {
  1108. uFlags |= DT_RIGHT;
  1109. rcText.right = max(rcText.left, rcText.right - 9);
  1110. }
  1111. pDC->DrawText(GetText(), rcText, uFlags);
  1112. }
  1113. LPCTSTR CXTPCalendarCaptionBarTheme::CDateLabelPart::_AddSpace(CString& rStr)
  1114. {
  1115. if (!rStr.IsEmpty())
  1116. rStr = rStr + _T(' ');
  1117. return (LPCTSTR)rStr;
  1118. }
  1119. CString CXTPCalendarCaptionBarTheme::CDateLabelPart::_FormatDate(COleDateTime dtDay1, COleDateTime dtDay2,
  1120.  BOOL bShowMonthDay)
  1121. {
  1122. //LOCALE_IDATE  -  short date format ordering
  1123. // 0 Month-Day-Year
  1124. // 1 Day-Month-Year
  1125. // 2 Year-Month-Day
  1126. int nDateOrdering = CXTPCalendarUtils::GetLocaleLong(LOCALE_IDATE);
  1127. CString strDay1(bShowMonthDay ? _T("d") : _T(""));
  1128. CString strDay2(strDay1);
  1129. CString strMonth1;
  1130. CString strMonth2 = _T("MMMM");
  1131. if (dtDay1.GetMonth() != dtDay2.GetMonth())
  1132. strMonth1 = _T("MMMM");
  1133. CString strYear1;
  1134. CString strYear2;
  1135. strYear2 = _T("yyyy");
  1136. if (dtDay1.GetYear() != dtDay2.GetYear())
  1137. strYear1 = _T("yyyy");
  1138. CString strFormat1, strFormat2;
  1139. if (nDateOrdering == 1)
  1140. {
  1141. strFormat1.Format(_T("%s%s%s"), _AddSpace(strDay1), _AddSpace(strMonth1), _AddSpace(strYear1));
  1142. strFormat2.Format(_T("%s%s%s"), _AddSpace(strDay2), _AddSpace(strMonth2), (LPCTSTR)strYear2);
  1143. }
  1144. else
  1145. {
  1146. if (!strYear1.IsEmpty() && !strDay1.IsEmpty())
  1147. strDay1 += _T(",");
  1148. if (!strYear2.IsEmpty() && !strDay2.IsEmpty())
  1149. strDay2 += _T(",");
  1150. strFormat1.Format(_T("%s%s%s"), _AddSpace(strMonth1), _AddSpace(strDay1), _AddSpace(strYear1));
  1151. strFormat2.Format(_T("%s%s%s"), _AddSpace(strMonth2), _AddSpace(strDay2), (LPCTSTR)strYear2);
  1152. }
  1153. //----------------------------------------------------------------------------
  1154. CString strCaption;
  1155. if (!CXTPCalendarUtils::IsEqual(dtDay1, dtDay2))
  1156. {
  1157. strCaption = CXTPCalendarUtils::GetDateFormat(dtDay1, strFormat1);
  1158. strCaption += _T("- ");
  1159. }
  1160. strCaption += CXTPCalendarUtils::GetDateFormat(dtDay2, strFormat2);
  1161. return strCaption;
  1162. }