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

对话框与窗口

开发平台:

Visual C++

  1. // XTPOffice2007Theme.cpp : implementation of the CXTPOffice2007Theme class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS 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 "Common/XTPDrawHelpers.h"
  22. #include "Common/XTPOffice2007Image.h"
  23. #include "Common/XTPVc80Helpers.h"
  24. #include "Common/XTPHookManager.h"
  25. #include "XTPControls.h"
  26. #include "XTPControl.h"
  27. #include "XTPControlPopup.h"
  28. #include "XTPCommandBar.h"
  29. #include "XTPPopupBar.h"
  30. #include "XTPControlGallery.h"
  31. #include "XTPStatusBar.h"
  32. #include "XTPMessageBar.h"
  33. #include "XTPControlProgress.h"
  34. #include "XTPOffice2007Theme.h"
  35. #include "XTPOffice2007FrameHook.h"
  36. #ifndef OIC_WINLOGO
  37. #define OIC_WINLOGO 32517
  38. #endif
  39. #ifndef LAYOUT_BITMAPORIENTATIONPRESERVED
  40. #define LAYOUT_BITMAPORIENTATIONPRESERVED 0x00000008
  41. #endif
  42. #ifdef _DEBUG
  43. #define new DEBUG_NEW
  44. #undef THIS_FILE
  45. static char THIS_FILE[] = __FILE__;
  46. #endif
  47. //////////////////////////////////////////////////////////////////////
  48. // Construction/Destruction
  49. //////////////////////////////////////////////////////////////////////
  50. class _XTP_EXT_CLASS CXTPControlGalleryOffice2007Theme : public CXTPControlGalleryPaintManager
  51. {
  52. public:
  53. CXTPControlGalleryOffice2007Theme(CXTPPaintManager* pPaintManager)
  54. : CXTPControlGalleryPaintManager(pPaintManager)
  55. {
  56. }
  57. public:
  58. virtual void FillControl(CDC* pDC, CXTPControlGallery* pGallery, CRect rc);
  59. virtual void DrawPopupScrollBar(CDC* pDC, CXTPControlGallery* pGallery);
  60. virtual void DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery);
  61. virtual void DrawLabel(CDC* pDC, CXTPControlGalleryItem* pLabel, CRect rc);
  62. virtual void RefreshMetrics();
  63. protected:
  64. COLORREF m_clrControlGallerySelected;
  65. COLORREF m_clrControlGalleryNormal;
  66. COLORREF m_clrControlGalleryBorder;
  67. };
  68. class _XTP_EXT_CLASS CXTPSliderOffice2007Theme : public CXTPSliderPaintManager
  69. {
  70. public:
  71. CXTPSliderOffice2007Theme(CXTPPaintManager* pPaintManager)
  72. : CXTPSliderPaintManager(pPaintManager)
  73. {
  74. }
  75. public:
  76. virtual void DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery);
  77. virtual void RefreshMetrics();
  78. };
  79. class _XTP_EXT_CLASS CXTPProgressOffice2007Theme : public CXTPProgressPaintManager
  80. {
  81. public:
  82. CXTPProgressOffice2007Theme(CXTPPaintManager* pPaintManager);
  83. public:
  84. virtual void DrawProgress(CDC* pDC, CXTPProgressBase* pGallery);
  85. };
  86. CXTPOffice2007Theme::CXTPOffice2007Theme()
  87. {
  88. m_pShadowManager->SetShadowOptions(xtpShadowOfficeAlpha | xtpShadowShowPopupControl);
  89. m_systemTheme = xtpSystemThemeUnknown;
  90. m_bThemedStatusBar = TRUE;
  91. m_bFrameStatusBar = FALSE;
  92. m_bOffice2007Padding = TRUE;
  93. delete m_pGalleryPaintManager;
  94. m_pGalleryPaintManager = new CXTPControlGalleryOffice2007Theme(this);
  95. delete m_pSliderPaintManager;
  96. m_pSliderPaintManager = new CXTPSliderOffice2007Theme(this);
  97. delete m_pProgressPaintManager;
  98. m_pProgressPaintManager = new CXTPProgressOffice2007Theme(this);
  99. m_pImages = XTPOffice2007Images();
  100. }
  101. CXTPOffice2007Theme::~CXTPOffice2007Theme()
  102. {
  103. m_pImages->RemoveAll();
  104. }
  105. CXTPOffice2007Images* CXTPOffice2007Theme::GetImages() const
  106. {
  107. return m_pImages;
  108. }
  109. void CXTPOffice2007Theme::SetImages(CXTPOffice2007Images* pImages)
  110. {
  111. m_pImages = pImages;
  112. }
  113. void CXTPOffice2007Theme::SetImageHandle(HMODULE hResource, LPCTSTR lpszIniFileName)
  114. {
  115. GetImages()->SetHandle(hResource, lpszIniFileName);
  116. RefreshMetrics();
  117. }
  118. CXTPOffice2007Image* CXTPOffice2007Theme::LoadImage(LPCTSTR lpszFileName)
  119. {
  120. return GetImages()->LoadFile(lpszFileName);
  121. }
  122. BOOL CXTPOffice2007Theme::IsImagesAvailable()
  123. {
  124. return TRUE;
  125. }
  126. COLORREF CXTPOffice2007Theme::GetRectangleTextColor(BOOL bSelected, BOOL bPressed, BOOL bEnabled, BOOL bChecked, BOOL bPopuped, XTPBarType barType, XTPBarPosition barPosition)
  127. {
  128. if (barType == xtpBarTypeMenuBar && !bSelected && bEnabled && !bPressed && !bChecked && !bPopuped)
  129. {
  130. return m_clrMenuBarText;
  131. }
  132. return CXTPOffice2003Theme::GetRectangleTextColor(bSelected, bPressed, bEnabled, bChecked, bPopuped, barType, barPosition);
  133. }
  134. void CXTPOffice2007Theme::RefreshMetrics()
  135. {
  136. CXTPOffice2003Theme::RefreshMetrics();
  137. //////////////////////////////////////////////////////////////////////////
  138. CXTPPaintManager::CNonClientMetrics ncm;
  139. ncm.lfSmCaptionFont.lfWeight = FW_NORMAL;
  140. if (m_bClearTypeTextQuality &&
  141. XTPSystemVersion()->IsClearTypeTextQualitySupported())
  142. {
  143. ncm.lfCaptionFont.lfQuality = 5;
  144. }
  145. ncm.lfCaptionFont.lfWeight = FW_NORMAL;
  146. if (m_bUseOfficeFont && FontExists(m_strOfficeFont))
  147. STRCPY_S(ncm.lfCaptionFont.lfFaceName, LF_FACESIZE, m_strOfficeFont);
  148. if (ncm.lfCaptionFont.lfHeight < 0)
  149. ncm.lfCaptionFont.lfHeight = min(-11, ncm.lfCaptionFont.lfHeight);
  150. m_fontFrameCaption.SetStandardFont(&ncm.lfCaptionFont);
  151. int nBorderSize = 1;
  152. SystemParametersInfo(SPI_GETBORDER, 0, &nBorderSize, FALSE);
  153. m_nFrameCaptionHeight = GetSystemMetrics(SM_CYCAPTION);
  154. m_nFrameCaptionHeight = max(m_nFrameCaptionHeight, 17);
  155. m_nRibbonCaptionHeight = GetSystemMetrics(SM_CYCAPTION) + 1;
  156. m_nRibbonCaptionHeight = max(m_nRibbonCaptionHeight, 18);
  157. //////////////////////////////////////////////////////////////////////////
  158. m_clrStatusTextColor = GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarText"));
  159. m_clrStatusBarShadow = GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarShadow"));
  160. m_clrStatusBarTop.SetStandardValue(GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarFaceTopLight")),
  161. GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarFaceTopDark")));
  162. m_clrStatusBarBottom.SetStandardValue(GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarFaceBottomLight")),
  163. GetImages()->GetImageColor(_T("StatusBar"), _T("StatusBarFaceBottomDark")));
  164. m_clrDockBar.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("DockBarFace")));
  165. m_clrCommandBar.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarFaceLight")),
  166. GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarFaceDark")), 0.75f);
  167. m_clrToolbarShadow.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarFaceShadow")));
  168. m_clrToolbarExpand.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlToolbarExpandLight")),
  169. GetImages()->GetImageColor(_T("Toolbar"), _T("ControlToolbarExpandDark")), 0.75f);
  170. m_clrPopupControl.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlHighlightPopupedLight")),
  171. GetImages()->GetImageColor(_T("Toolbar"), _T("ControlHighlightPopupedDark")));
  172. m_clrMenuGripper.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupGripperLight")),
  173. GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupGripperDark")));
  174. m_clrMenuExpandedGripper.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupExpandedGripperLight")),
  175. GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupExpandedGripperDark")));
  176. m_clrMenuExpand = m_clrPopupControl;
  177. m_pShadowManager->SetShadowColor(0);
  178. m_clrTearOffGripper.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupTearOffGripper")));
  179. m_clrMenuBarText = GetImages()->GetImageColor(_T("Toolbar"), _T("MenuBarText"));
  180. m_arrColor[XPCOLOR_MENUBAR_FACE].SetStandardValue(RGB(246, 246, 246));
  181. m_arrColor[XPCOLOR_MENUBAR_BORDER].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("MenuPopupBorder")));
  182. m_arrColor[XPCOLOR_TOOLBAR_GRIPPER].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarGripper")));
  183. m_arrColor[XPCOLOR_MENUBAR_TEXT].SetStandardValue(0);
  184. m_arrColor[XPCOLOR_HIGHLIGHT_TEXT].SetStandardValue(0);
  185. m_arrColor[XPCOLOR_TOOLBAR_TEXT].SetStandardValue(0);
  186. m_arrColor[XPCOLOR_TOOLBAR_GRAYTEXT].SetStandardValue(RGB(141, 141, 141));
  187. m_arrColor[XPCOLOR_HIGHLIGHT_DISABLED_BORDER].SetStandardValue(RGB(141, 141, 141));
  188. m_arrColor[XPCOLOR_MENUBAR_GRAYTEXT].SetStandardValue(RGB(141, 141, 141));
  189. m_arrColor[XPCOLOR_FRAME].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("WindowFrame")));
  190. m_clrFloatingGripper.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("FloatingBarGripper")));
  191. m_clrFloatingGripperText.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("FloatingBarGripperText")));
  192. m_arrColor[XPCOLOR_FLOATBAR_BORDER].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("FloatingBarBorder")));
  193. m_arrColor[COLOR_APPWORKSPACE].SetStandardValue(GetImages()->GetImageColor(_T("Workspace"), _T("AppWorkspace")));
  194. m_arrColor[XPCOLOR_3DFACE].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("ButtonFace")));
  195. m_arrColor[XPCOLOR_3DSHADOW].SetStandardValue(m_clrToolbarShadow);
  196. m_arrColor[XPCOLOR_TOOLBAR_FACE].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarFace")));
  197. m_arrColor[XPCOLOR_SEPARATOR].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ToolbarSeparator")));
  198. m_arrColor[XPCOLOR_DISABLED].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlDisabledIcon")));
  199. m_clrWorkspaceClientTop = GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientTop"));
  200. m_clrWorkspaceClientMiddle = GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientMiddle"));
  201. m_clrWorkspaceClientBottom =  GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientBottom"));
  202. m_arrColor[XPCOLOR_HIGHLIGHT].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightSelected")));
  203. m_arrColor[XPCOLOR_HIGHLIGHT_BORDER].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightSelectedBorder")));
  204. m_arrColor[XPCOLOR_HIGHLIGHT_PUSHED].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightPressed")));
  205. m_arrColor[XPCOLOR_HIGHLIGHT_PUSHED_BORDER].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightPressedBorder")));
  206. m_arrColor[XPCOLOR_HIGHLIGHT_CHECKED].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightChecked")));
  207. m_arrColor[XPCOLOR_HIGHLIGHT_CHECKED_BORDER].SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightCheckedBorder")));
  208. m_arrColor[XPCOLOR_PUSHED_TEXT].SetStandardValue(0);
  209. m_bLunaTheme = TRUE;
  210. m_grcLunaSelected.SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightSelectedLight")),
  211. GetImages()->GetImageColor(_T("Window"), _T("HighlightSelectedDark")));
  212. m_grcLunaChecked.SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightCheckedLight")),
  213. GetImages()->GetImageColor(_T("Window"), _T("HighlightCheckedDark")));
  214. m_grcLunaPushed.SetStandardValue(GetImages()->GetImageColor(_T("Window"), _T("HighlightPressedLight")),
  215. GetImages()->GetImageColor(_T("Window"), _T("HighlightPressedDark")));
  216. m_clrFrameBorderActive0 = GetImages()->GetImageColor(_T("Window"), _T("BorderActive0"));
  217. m_clrFrameBorderActive1 = GetImages()->GetImageColor(_T("Window"), _T("BorderActive1"));
  218. m_clrFrameBorderActive2 = GetImages()->GetImageColor(_T("Window"), _T("BorderActive2"));
  219. m_clrFrameBorderActive3 = GetImages()->GetImageColor(_T("Window"), _T("BorderActive3"));
  220. m_clrFrameBorderInactive0 = GetImages()->GetImageColor(_T("Window"), _T("BorderInactive0"));
  221. m_clrFrameBorderInactive1 = GetImages()->GetImageColor(_T("Window"), _T("BorderInactive1"));
  222. m_clrFrameBorderInactive2 = GetImages()->GetImageColor(_T("Window"), _T("BorderInactive2"));
  223. m_clrFrameBorderInactive3 = GetImages()->GetImageColor(_T("Window"), _T("BorderInactive3"));
  224. m_clrFrameCaptionTextActiveTitle = GetImages()->GetImageColor(_T("Window"), _T("CaptionTextActiveTitle"));
  225. m_clrFrameCaptionTextInActive = GetImages()->GetImageColor(_T("Window"), _T("CaptionTextInActive"));
  226. m_clrFrameCaptionTextActive = GetImages()->GetImageColor(_T("Window"), _T("CaptionTextActive"));
  227. m_arrColor[XPCOLOR_LABEL].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlLabel")));
  228. m_arrColor[XPCOLOR_EDITCTRLBORDER].SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlEditBorder")));
  229. m_clrDisabledIcon.SetStandardValue(GetImages()->GetImageColor(_T("Toolbar"), _T("ControlDisabledIconLight")),
  230. GetImages()->GetImageColor(_T("Toolbar"), _T("ControlDisabledIconDark")));
  231. m_clrMessageBar.SetStandardValue(GetImages()->GetImageColor(_T("MessageBar"), _T("MessageBarLight")),
  232. GetImages()->GetImageColor(_T("MessageBar"), _T("MessageBarDark")));
  233. m_clrMessageBarFrame = GetImages()->GetImageColor(_T("MessageBar"), _T("MessageBarFrame"));
  234. m_clrMessageBarText = GetImages()->GetImageColor(_T("MessageBar"), _T("MessageBarText"));
  235. m_clrMessageBarFace = GetImages()->GetImageColor(_T("MessageBar"), _T("MessageBar"));
  236. CreateGradientCircle();
  237. }
  238. //////////////////////////////////////////////////////////////////////////
  239. //
  240. void CXTPOffice2007Theme::DrawCaptionText(CDC* pDC, CRect rcCaptionText, CWnd* pSite, BOOL bActive)
  241. {
  242. CString strWindowText;
  243. CXTPDrawHelpers::GetWindowCaption(pSite->GetSafeHwnd(), strWindowText);
  244. pDC->SetBkMode(TRANSPARENT);
  245. CXTPFontDC font(pDC, &m_fontFrameCaption);
  246. pDC->SetTextColor(!bActive ? m_clrFrameCaptionTextInActive : m_clrFrameCaptionTextActive); //RGB(62, 106, 170));
  247. if (pSite->GetStyle() & FWS_PREFIXTITLE)
  248. {
  249. #if _MSC_VER >= 1200
  250. CFrameWnd* pFrame = pSite->IsFrameWnd() ? (CFrameWnd*)pSite : NULL;
  251. CString strTitle = pFrame ? pFrame->GetTitle() : _T("");
  252. if (!strTitle.IsEmpty() && strWindowText.Right(strTitle.GetLength()) == strTitle & ((pSite->GetExStyle() & WS_EX_LAYOUTRTL) == 0))
  253. {
  254. strWindowText.Delete(strWindowText.GetLength() - strTitle.GetLength(), strTitle.GetLength());
  255. pDC->DrawText(strWindowText, rcCaptionText, DT_VCENTER | DT_LEFT| DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
  256. int nExtent = pDC->GetTextExtent(strWindowText).cx;
  257. rcCaptionText.left += nExtent + 2;
  258. if (rcCaptionText.left < rcCaptionText.right - 5)
  259. {
  260. if (bActive) pDC->SetTextColor(m_clrFrameCaptionTextActiveTitle);
  261. pDC->DrawText(strTitle, rcCaptionText, DT_VCENTER | DT_LEFT| DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
  262. }
  263. }
  264. else
  265. #endif
  266. {
  267. pDC->DrawText(strWindowText, rcCaptionText, DT_VCENTER | DT_LEFT| DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
  268. }
  269. }
  270. else
  271. {
  272. pDC->DrawText(strWindowText, rcCaptionText, DT_VCENTER | DT_LEFT| DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
  273. }
  274. }
  275. HICON CXTPOffice2007Theme::GetFrameSmallIcon(CWnd* pFrame)
  276. {
  277. if (!pFrame)
  278. return NULL;
  279. DWORD dwStyle = pFrame->GetStyle();
  280. DWORD dwExStyle = pFrame->GetExStyle();
  281. if (dwExStyle & WS_EX_TOOLWINDOW)
  282. return NULL;
  283. if ((dwStyle & WS_SYSMENU) == 0)
  284. return NULL;
  285. HICON hIcon = (HICON)(DWORD_PTR)::SendMessage(pFrame->m_hWnd, WM_GETICON, ICON_SMALL, 0);
  286. if (hIcon)
  287. return hIcon;
  288. hIcon = (HICON)(DWORD_PTR)::GetClassLongPtr(pFrame->m_hWnd, GCLP_HICONSM);
  289. if (hIcon)
  290. return hIcon;
  291. if (((dwStyle & (WS_BORDER | WS_DLGFRAME)) != WS_DLGFRAME) && ((dwExStyle & WS_EX_DLGMODALFRAME) == 0))
  292. {
  293. ULONG_PTR dwResult;
  294. if (SendMessageTimeout(pFrame->GetSafeHwnd(),
  295. WM_QUERYDRAGICON,
  296. 0,
  297. 0,
  298. SMTO_NORMAL,
  299. 100,
  300. &dwResult))
  301. {
  302. hIcon = (HICON)dwResult;
  303. }
  304. if (hIcon == NULL)
  305. {
  306. hIcon = AfxGetApp()->LoadOEMIcon(OIC_WINLOGO);
  307. }
  308. }
  309. return hIcon;
  310. }
  311. HICON CXTPOffice2007Theme::GetFrameLargeIcon(CWnd* pFrame)
  312. {
  313. if (!pFrame)
  314. return NULL;
  315. HICON hIcon = (HICON)(DWORD_PTR)::SendMessage(pFrame->m_hWnd, WM_GETICON, ICON_BIG, 0);
  316. if (hIcon)
  317. return hIcon;
  318. hIcon = (HICON)(DWORD_PTR)::GetClassLongPtr(pFrame->m_hWnd, GCLP_HICON);
  319. if (hIcon)
  320. return hIcon;
  321. return hIcon;
  322. }
  323. void CXTPOffice2007Theme::DrawRibbonFrame(CDC* pDC, CXTPOffice2007FrameHook* pFrameHook)
  324. {
  325. CWnd* pSite = pFrameHook->GetSite();
  326. BOOL bActive = pFrameHook->IsFrameActive();
  327. CXTPClientRect rcBorders(pSite);
  328. pSite->ClientToScreen(rcBorders);
  329. CXTPWindowRect rc(pSite);
  330. int nRightBorder = rcBorders.left - rc.left, nLeftBorder = rcBorders.left - rc.left, nBorder = pFrameHook->GetFrameBorder();
  331. int nBottomBorder = rc.bottom - rcBorders.bottom;
  332. rc.OffsetRect(-rc.TopLeft());
  333. CRect rcFrame(rc);
  334. int nCaptionHeight = pFrameHook->GetCaptionHeight();
  335. rcFrame.top += nCaptionHeight;
  336. int nStatusHeight = 0;
  337. BOOL bHasStatusBar = pFrameHook->IsFrameHasStatusBar(&nStatusHeight);
  338. int nBordersHeight = bHasStatusBar ? rcFrame.Height() - nStatusHeight - 1 : rcFrame.Height();
  339. if (nLeftBorder > 0) pDC->FillSolidRect(rc.left + 0, rcFrame.top, 1, rcFrame.Height(), bActive ? m_clrFrameBorderActive0 : m_clrFrameBorderInactive0);
  340. if (nLeftBorder > 1) pDC->FillSolidRect(rc.left + 1, rcFrame.top, 1, nBordersHeight, bActive ? m_clrFrameBorderActive1 : m_clrFrameBorderInactive1);
  341. if (nLeftBorder > 2) pDC->FillSolidRect(rc.left + 2, rcFrame.top, 1, nBordersHeight, bActive ? m_clrFrameBorderActive2 : m_clrFrameBorderInactive2);
  342. if (nLeftBorder > 3) pDC->FillSolidRect(rc.left + 3, rcFrame.top, nLeftBorder - 3, nBordersHeight, bActive ? m_clrFrameBorderActive3 : m_clrFrameBorderInactive3);
  343. if (nRightBorder > 0) pDC->FillSolidRect(rc.right - 1, rcFrame.top, 1, rcFrame.Height(), bActive ? m_clrFrameBorderActive0 : m_clrFrameBorderInactive0);
  344. if (nRightBorder > 1) pDC->FillSolidRect(rc.right - 2, rcFrame.top, 1, nBordersHeight, bActive ? m_clrFrameBorderActive1 : m_clrFrameBorderInactive1);
  345. if (nRightBorder > 2) pDC->FillSolidRect(rc.right - 3, rcFrame.top, 1, nBordersHeight, bActive ? m_clrFrameBorderActive2 : m_clrFrameBorderInactive2);
  346. if (nRightBorder > 3) pDC->FillSolidRect(rc.right - nRightBorder, rcFrame.top, nRightBorder - 3, nBordersHeight, bActive ? m_clrFrameBorderActive3 : m_clrFrameBorderInactive3);
  347. pDC->FillSolidRect(rc.left, rc.bottom - 1, rc.Width(), 1,
  348. bActive ? pSite->GetStyle() & WS_MAXIMIZE ? m_clrFrameBorderActive3 : m_clrFrameBorderActive0 : m_clrFrameBorderInactive0);
  349. if (nBottomBorder > 1)
  350. {
  351. pDC->FillSolidRect(rc.left + 1, rc.bottom - nBottomBorder, rc.Width() - 2, nBottomBorder - 1, bActive ? m_clrFrameBorderActive3 : m_clrFrameBorderInactive3);
  352. }
  353. //////////////////////////////////////////////////////////////////////////
  354. CRect rcCaption(rc.left, rc.top, rc.right, rc.top + nCaptionHeight);
  355. if (pFrameHook->IsCaptionVisible())
  356. {
  357. CXTPBufferDC dc(*pDC, rcCaption);
  358. CXTPOffice2007Image* pImage = LoadImage(_T("FRAMETOPLEFT"));
  359. CRect rcSrcTopLeft(pImage->GetSource(bActive ? 0 : 1, 2));
  360. CRect rcTopLeft(rc.left, rc.top, rc.left + rcSrcTopLeft.Width(), rcCaption.bottom);
  361. pImage->DrawImage(&dc, rcTopLeft, rcSrcTopLeft, CRect(0, 5, 0, 3));
  362. //
  363. pImage = LoadImage(_T("FRAMETOPRIGHT"));
  364. CRect rcSrcTopRight(pImage->GetSource(bActive ? 0 : 1, 2));
  365. CRect rcTopRight(rc.right - rcSrcTopRight.Width(), rc.top, rc.right, rcCaption.bottom);
  366. pImage->DrawImage(&dc, rcTopRight, rcSrcTopRight, CRect(0, 5, 0, 3));
  367. pImage = LoadImage(_T("FRAMETOPCENTER"));
  368. CRect rcTopCenter(rc.left + rcTopLeft.Width(), rc.top, rc.right - rcSrcTopRight.Width(), rcCaption.bottom);
  369. pImage->DrawImage(&dc, rcTopCenter, pImage->GetSource(bActive ? 0 : 1, 2), CRect(0, 5, 0, 3));
  370. CRect rcCaptionText(rcCaption);
  371. rcCaptionText.left = 7;
  372. rcCaptionText.DeflateRect(0, nBorder, 0, 3);
  373. HICON hIcon = GetFrameSmallIcon(pSite);
  374. if (hIcon)
  375. {
  376. CSize szIcon(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
  377. int cBorders = nBorder - 1;
  378. int cxySlot = rcCaption.Height() - cBorders;
  379. int nTop = cBorders + (cxySlot - szIcon.cy - 1)/2;
  380. DWORD dwLayout = XTPDrawHelpers()->IsContextRTL(&dc);
  381. if (dwLayout & LAYOUT_RTL)
  382. XTPDrawHelpers()->SetContextRTL(&dc, dwLayout | LAYOUT_BITMAPORIENTATIONPRESERVED);
  383. DrawIconEx(dc.m_hDC, rcCaptionText.left, nTop, hIcon,
  384. szIcon.cx, szIcon.cy, 0, NULL, DI_NORMAL);
  385. if (dwLayout & LAYOUT_RTL)
  386. XTPDrawHelpers()->SetContextRTL(&dc, dwLayout);
  387. rcCaptionText.left = 7 + szIcon.cx + 5;
  388. }
  389. CXTPControls* pCaptionButtons = pFrameHook->GetCaptionButtons();
  390. for (int i = 0; i < pCaptionButtons->GetCount(); i++)
  391. {
  392. CXTPControl* pControl = pCaptionButtons->GetAt(i);
  393. if (!pControl->IsVisible())
  394. continue;
  395. DrawRibbonFrameCaptionButton(&dc, pControl->GetRect(), pControl->GetID(), pControl->GetSelected(), pControl->GetPressed(), pControl->GetEnabled() && bActive);
  396. rcCaptionText.right = min(rcCaptionText.right, pControl->GetRect().left);
  397. }
  398. rcCaptionText.right -= nRightBorder;
  399. DrawCaptionText(&dc, rcCaptionText, pSite, bActive);
  400. }
  401. else
  402. {
  403. CXTPOffice2007Image* pImage = LoadImage(_T("FRAMETOPLEFT"));
  404. CRect rcSrc(pImage->GetSource(bActive ? 0 : 1, 2));
  405. rcSrc.right = nLeftBorder;
  406. CRect rcTopLeft(rc.left, rcCaption.top, rc.left + nLeftBorder, rcCaption.bottom);
  407. pImage->DrawImage(pDC, rcTopLeft, rcSrc, CRect(0, 5, 0, 3));
  408. //////////////////////////////////////////////////////////////////////////
  409. pImage = LoadImage(_T("FRAMETOPRIGHT"));
  410. rcSrc = pImage->GetSource(bActive ? 0 : 1, 2);
  411. rcSrc.left = rcSrc.right - nRightBorder;
  412. CRect rcTopRight(rc.right - nRightBorder, rcCaption.top, rc.right, rcCaption.bottom);
  413. pImage->DrawImage(pDC, rcTopRight, rcSrc, CRect(0, 5, 0, 3));
  414. pImage = LoadImage(_T("FRAMETOPCENTER"));
  415. rcSrc = pImage->GetSource(bActive ? 0 : 1, 2);
  416. rcSrc.bottom = rcSrc.top + nBorder;
  417. CRect rcTopCenter(rc.left + nLeftBorder, rc.top, rc.right - nRightBorder, rc.top + nBorder);
  418. pImage->DrawImage(pDC, rcTopCenter, rcSrc, CRect(0, 0, 0, 0));
  419. }
  420. if (bHasStatusBar)
  421. {
  422. CXTPOffice2007Image* pImage = LoadImage(_T("STATUSBARLIGHT"));
  423. CRect rcSrc(0, 0, nLeftBorder - 1, pImage->GetHeight());
  424. CRect rcLight(rc.left + 1, rc.bottom - nStatusHeight - nBottomBorder, rc.left + nLeftBorder, rc.bottom - nBottomBorder);
  425. pImage->DrawImage(pDC, rcLight, rcSrc, CRect(0, 0, 0, 0));
  426. pImage = LoadImage(_T("STATUSBARDARK"));
  427. rcSrc.SetRect(0, 0, nRightBorder - 1, pImage->GetHeight());
  428. CRect rcDark(rc.right - nRightBorder, rc.bottom - nStatusHeight - nBottomBorder, rc.right - 1, rc.bottom - nBottomBorder);
  429. pImage->DrawImage(pDC, rcDark, rcSrc, CRect(0, 0, 0, 0));
  430. if (nLeftBorder > 3)
  431. {
  432. pImage = LoadImage(_T("FRAMEBOTTOMLEFT"));
  433. rcSrc = pImage->GetSource(bActive ? 0 : 1, 2);
  434. CRect rcBottomLeft(rc.left, rc.bottom - rcSrc.Height(), rc.left + rcSrc.Width(), rc.bottom);
  435. pImage->DrawImage(pDC, rcBottomLeft, rcSrc, CRect(0, 0, 0, 0), 0xFF00FF);
  436. }
  437. if (nRightBorder > 3)
  438. {
  439. pImage = LoadImage(_T("FRAMEBOTTOMRIGHT"));
  440. rcSrc = pImage->GetSource(bActive ? 0 : 1, 2);
  441. CRect rcBottomRight(rc.right - rcSrc.Width(), rc.bottom - rcSrc.Height(), rc.right, rc.bottom);
  442. pImage->DrawImage(pDC, rcBottomRight, rcSrc, CRect(0, 0, 0, 0), 0xFF00FF);
  443. }
  444. }
  445. }
  446. void CXTPOffice2007Theme::DrawRibbonFrameCaptionButton(CDC* pDC, CRect rc, int nId, BOOL bSelected, BOOL bPressed, BOOL bActive)
  447. {
  448. int nState = !bActive ? 3 : bPressed && bSelected ? 2 : bSelected || bPressed ? 1 : 0;
  449. if (bSelected || bPressed)
  450. {
  451. CXTPOffice2007Image* pImage = LoadImage(_T("FRAMECAPTIONBUTTON"));
  452. pImage->DrawImage(pDC, rc, pImage->GetSource(bPressed && bSelected ? 1 : 0, 2), CRect(3, 3, 3, 3), 0xFF00FF);
  453. }
  454. int nGlyphSize = 23;
  455. if (rc.Width() < 27) nGlyphSize = 17;
  456. if (rc.Width() < 15) nGlyphSize = 13;
  457. LPCTSTR lpszButton = nId == SC_CLOSE ? _T("CLOSE") : nId == SC_MINIMIZE ? _T("MINIMIZE") :
  458. nId == SC_MAXIMIZE ? _T("MAXIMIZE") : _T("RESTORE");
  459. CString strImage;
  460. strImage.Format(_T("FRAMECAPTION%s%i"), lpszButton, nGlyphSize);
  461. CXTPOffice2007Image* pImage = LoadImage(strImage);
  462. CRect rcSrc(pImage->GetSource(nState, 5));
  463. CRect rcGlyph(CPoint((rc.right + rc.left - rcSrc.Width()) / 2, (rc.top + rc.bottom - rcSrc.Height()) / 2), rcSrc.Size());
  464. pImage->DrawImage(pDC, rcGlyph, rcSrc, CRect(0, 0, 0, 0), 0xFF00FF);
  465. }
  466. void CXTPOffice2007Theme::FillWorkspace(CDC* pDC, CRect rc, CRect rcExclude)
  467. {
  468. CRgn rgn;
  469. rgn.CreateRectRgnIndirect(rc);
  470. pDC->SelectClipRgn(&rgn);
  471. pDC->ExcludeClipRect(rcExclude);
  472. CXTPOffice2007Image* pImage = LoadImage(_T("WORKSPACETOPLEFT"));
  473. ASSERT(pImage);
  474. if (!pImage)
  475. return;
  476. CRect rcSrc(pImage->GetSource());
  477. CRect rcTopLeft(rc);
  478. rcTopLeft.bottom = rcTopLeft.top + rcSrc.Height();
  479. rcTopLeft.right = rcTopLeft.left + max(rcTopLeft.Width(), rcSrc.Width());
  480. pImage->DrawImage(pDC, rcTopLeft, rcSrc, CRect(rcSrc.Width() - 1, 0, 0, 0));
  481. CRect rcFill(rc.left, rc.top + rcSrc.Height(), rc.right, rc.bottom);
  482. CRect rcFillTop(rcFill.left, rcFill.top, rcFill.right, rcFill.top + rcFill.Height() * 2 / 3);
  483. CRect rcFillBottom(rcFill.left, rcFillTop.bottom, rcFill.right, rcFill.bottom);
  484. XTPDrawHelpers()->GradientFill(pDC, rcFillTop, m_clrWorkspaceClientTop, m_clrWorkspaceClientMiddle, FALSE);
  485. XTPDrawHelpers()->GradientFill(pDC, rcFillBottom, m_clrWorkspaceClientMiddle, m_clrWorkspaceClientBottom, FALSE);
  486. pDC->SelectClipRgn(NULL);
  487. }
  488. HRGN CXTPOffice2007Theme::CalcRibbonFrameRegion(CXTPOffice2007FrameHook* pFrameHook, CSize sz)
  489. {
  490. if (pFrameHook->GetSite()->GetStyle() & WS_MAXIMIZE)
  491. {
  492. return NULL;
  493. }
  494. int cx = sz.cx, cy = sz.cy;
  495. RECT rgnTopFrame[] =
  496. {
  497. {4, 0, cx - 4, 1}, {2, 1, cx - 2, 2}, {1, 2, cx - 1, 3}, {1, 3, cx - 1, 4}, {0, 4, cx, cy - 4}
  498. };
  499. RECT rgnRibbonBottomFrame[] =
  500. {
  501. {1, cy - 4, cx - 1, cy - 2}, {2, cy - 2, cx - 2, cy - 1}, {4, cy - 1, cx - 4, cy - 0}
  502. };
  503. RECT rgnSimpleBottomFrame[] =
  504. {
  505. {0, cy - 4, cx, cy}
  506. };
  507. BOOL bHasStatusBar = pFrameHook->IsFrameHasStatusBar() && pFrameHook->GetFrameBorder() > 3;
  508. int nSizeTopRect = sizeof(rgnTopFrame);
  509. int nSizeBottomRect = bHasStatusBar ? sizeof(rgnRibbonBottomFrame) : sizeof(rgnSimpleBottomFrame);
  510. int nSizeData = sizeof(RGNDATAHEADER) + nSizeTopRect + nSizeBottomRect;
  511. RGNDATA* pRgnData = (RGNDATA*)malloc(nSizeData);
  512. if (!pRgnData)
  513. return NULL;
  514. memcpy(&pRgnData->Buffer, (void*)&rgnTopFrame, nSizeTopRect);
  515. memcpy(&pRgnData->Buffer + nSizeTopRect, bHasStatusBar ? (void*)&rgnRibbonBottomFrame : (void*)&rgnSimpleBottomFrame, nSizeBottomRect);
  516. pRgnData->rdh.dwSize = sizeof(RGNDATAHEADER);
  517. pRgnData->rdh.iType = RDH_RECTANGLES;
  518. pRgnData->rdh.nCount = (nSizeTopRect + nSizeBottomRect) / sizeof(RECT);
  519. pRgnData->rdh.nRgnSize = 0;
  520. pRgnData->rdh.rcBound = CRect(0, 0, cx, cy);
  521. CRgn rgnResult;
  522. VERIFY(rgnResult.CreateFromData(NULL, nSizeData, pRgnData));
  523. free(pRgnData);
  524. return (HRGN)rgnResult.Detach();
  525. }
  526. void CXTPOffice2007Theme::FillStatusBar(CDC* pDC, CXTPStatusBar* pBar)
  527. {
  528. CXTPClientRect rc(pBar);
  529. pDC->FillSolidRect(rc.left, rc.top, rc.Width(), 1, m_clrStatusBarShadow);
  530. XTPDrawHelpers()->GradientFill(pDC, CRect(rc.left, rc.top + 1, rc.right, rc.top + 9),
  531. m_clrStatusBarTop, FALSE);
  532. XTPDrawHelpers()->GradientFill(pDC, CRect(rc.left, rc.top + 9, rc.right, rc.bottom),
  533. m_clrStatusBarBottom, FALSE);
  534. }
  535. void CXTPOffice2007Theme::FillMessageBar(CDC* pDC, CXTPMessageBar* pBar)
  536. {
  537. CXTPClientRect rcClient(pBar);
  538. pDC->FillSolidRect(rcClient, m_clrMessageBarFace);
  539. CRect rcMessage = pBar->GetMessageRect();
  540. pDC->Draw3dRect(rcMessage, m_clrMessageBarFrame, m_clrMessageBarFrame);
  541. rcMessage.DeflateRect(1, 1);
  542. XTPDrawHelpers()->GradientFill(pDC, rcMessage, m_clrMessageBar, FALSE);
  543. }
  544. void CXTPOffice2007Theme::DrawMessageBarButton(CDC* pDC, CXTPMessageBarButton* pButton)
  545. {
  546. BOOL bCloseButton = (pButton->m_nID == SC_CLOSE);
  547. CRect rc(pButton->m_rcButton);
  548. if (pButton->m_bPressed && bCloseButton)
  549. {
  550. pDC->FillSolidRect(rc, GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED));
  551. pDC->Draw3dRect(rc, GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED_BORDER), GetXtremeColor(XPCOLOR_HIGHLIGHT_PUSHED_BORDER));
  552. }
  553. else if (pButton->m_bHot)
  554. {
  555. pDC->FillSolidRect(rc, GetXtremeColor(XPCOLOR_HIGHLIGHT));
  556. pDC->Draw3dRect(rc, GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER), GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDER));
  557. }
  558. else if (!bCloseButton)
  559. {
  560. pDC->FillSolidRect(rc, 0xFFFFFF);
  561. pDC->Draw3dRect(rc, m_clrMessageBarFrame, m_clrMessageBarFrame);
  562. }
  563. if (bCloseButton)
  564. {
  565. CXTPOffice2007Image* pImage = LoadImage(_T("FRAMECAPTIONCLOSE17"));
  566. CRect rcSrc(pImage->GetSource(0, 5));
  567. CRect rcGlyph(CPoint((rc.right + rc.left - rcSrc.Width()) / 2, (rc.top + rc.bottom - rcSrc.Height()) / 2), rcSrc.Size());
  568. pImage->DrawImage(pDC, rcGlyph, rcSrc, CRect(0, 0, 0, 0), 0xFF00FF);
  569. }
  570. }
  571. void CXTPOffice2007Theme::DrawStatusBarPaneBorder(CDC* pDC, CRect rc, CXTPStatusBarPane* /*pPane*/, BOOL bGripperPane)
  572. {
  573. if (!bGripperPane)
  574. {
  575. pDC->FillSolidRect(rc.right - 1, rc.top, 1, rc.Height() - 2, GetXtremeColor(XPCOLOR_SEPARATOR));
  576. pDC->FillSolidRect(rc.right, rc.top, 1, rc.Height() - 2, RGB(255, 255, 255));
  577. }
  578. }
  579. void CXTPOffice2007Theme::DrawStatusBarGripper(CDC* pDC, CRect rcClient)
  580. {
  581. CPoint pt(rcClient.right - 3, rcClient.bottom - 3);
  582. for (int y = 0; y < 3; y++)
  583. {
  584. for (int x = 0; x < 3 - y; x++)
  585. {
  586. pDC->FillSolidRect(pt.x + 1 - x * 4, pt.y + 1 - y * 4, 2, 2, RGB(255, 255, 255));
  587. pDC->FillSolidRect(pt.x + 0 - x * 4, pt.y + 0 - y * 4, 2, 2, GetXtremeColor(XPCOLOR_SEPARATOR));
  588. }
  589. }
  590. }
  591. //////////////////////////////////////////////////////////////////////////
  592. //
  593. void CXTPControlGalleryOffice2007Theme::FillControl(CDC* pDC, CXTPControlGallery* pGallery, CRect rcControl)
  594. {
  595. pDC->FillSolidRect(rcControl,
  596. pGallery->GetParent()->GetPosition() == xtpBarPopup  && pGallery->GetParent()->GetType() == xtpBarTypePopup?
  597. m_pPaintManager->GetXtremeColor(XPCOLOR_MENUBAR_FACE) :
  598. pGallery->GetSelected() && pGallery->GetEnabled() ? m_clrControlGallerySelected : m_clrControlGalleryNormal);
  599. if (pGallery->IsShowBorders())
  600. {
  601. pDC->Draw3dRect(rcControl, m_clrControlGalleryBorder, m_clrControlGalleryBorder);
  602. }
  603. if (pGallery->HasBottomSeparator())
  604. {
  605. pDC->FillSolidRect(rcControl.left, rcControl.bottom - 2, rcControl.Width(), 1, RGB(197, 197, 197));
  606. }
  607. }
  608. void CXTPControlGalleryOffice2007Theme::RefreshMetrics()
  609. {
  610. CXTPControlGalleryPaintManager::RefreshMetrics();
  611. m_cxHScroll = GetSystemMetrics(SM_CXHSCROLL);
  612. m_cyHScroll = GetSystemMetrics(SM_CYHSCROLL);
  613. m_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
  614. m_cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
  615. m_cyPopupUp = 21;
  616. m_cyPopupDown = 19;
  617. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)m_pPaintManager;
  618. m_clrControlGallerySelected = pPaintManager->GetImages()->GetImageColor(_T("Toolbar"), _T("ControlGallerySelected"));
  619. m_clrControlGalleryNormal = pPaintManager->GetImages()->GetImageColor(_T("Toolbar"), _T("ControlGalleryNormal"));
  620. m_clrControlGalleryBorder = pPaintManager->GetImages()->GetImageColor(_T("Toolbar"), _T("ControlGalleryBorder"));
  621. }
  622. void CXTPControlGalleryOffice2007Theme::DrawLabel(CDC* pDC, CXTPControlGalleryItem* pLabel, CRect rcItem)
  623. {
  624. CXTPPaintManager* pPaintManager = m_pPaintManager;
  625. pDC->FillSolidRect(rcItem, pPaintManager->GetXtremeColor(XPCOLOR_LABEL));
  626. pDC->FillSolidRect(rcItem.left, rcItem.bottom - 1, rcItem.Width(), 1, RGB(197, 197, 197));
  627. CXTPFontDC fnt(pDC, pPaintManager->GetRegularBoldFont());
  628. CRect rcText(rcItem);
  629. rcText.DeflateRect(10, 0);
  630. pDC->SetTextColor(pPaintManager->GetXtremeColor(XPCOLOR_MENUBAR_TEXT));
  631. pDC->DrawText(pLabel->GetCaption(), rcText, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
  632. }
  633. void CXTPControlGalleryOffice2007Theme::DrawPopupScrollBar(CDC* pDC, CXTPControlGallery* pGallery)
  634. {
  635. #define GETPARTSTATE3(ht, bEnabled) 
  636. (!bEnabled ? 4 : nPressetHt == ht ? 3 : nHotHt == ht ? 2 : nHotHt > 0 || nPressetHt > 0 ? 1 : 0)
  637. CXTPControlGallery::SCROLLBARTRACKINFO* pSBTrack = pGallery->GetScrollBarTrackInfo();
  638. CXTPControlGallery::SCROLLBARPOSINFO* pSBInfo = pGallery->GetScrollBarPosInfo();
  639. CRect rcControl = pGallery->GetRect();
  640. CRect rcScroll(rcControl.right - 15, rcControl.top, rcControl.right, rcControl.bottom);
  641. CRect rcScrollUp(rcScroll.left, rcScroll.top, rcScroll.right, rcScroll.top + m_cyPopupUp);
  642. CRect rcScrollDown(rcScroll.left, rcScrollUp.bottom, rcScroll.right, rcScrollUp.bottom + m_cyPopupDown);
  643. CRect rcScrollPopup(rcScroll.left, rcScrollDown.bottom, rcScroll.right, rcScroll.bottom);
  644. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)m_pPaintManager;
  645. CXTPOffice2007Image* pImage = pPaintManager->LoadImage(_T("CONTROLGALLERYUP"));
  646. ASSERT(pImage);
  647. if (!pImage)
  648. return;
  649. BOOL bControlEnabled = pGallery->GetEnabled();
  650. BOOL nPressetHt = pSBTrack ? pSBInfo->ht : -1;
  651. BOOL nHotHt = pSBTrack ? -1 : pSBInfo->ht;
  652. if (nHotHt == HTNOWHERE && nPressetHt == -1 && bControlEnabled && IsKeyboardSelected(pGallery->GetSelected()) && pGallery->GetSelectedItem() == -1)
  653. nHotHt = XTP_HTSCROLLPOPUP;
  654. int nState = GETPARTSTATE3(XTP_HTSCROLLUP, (bControlEnabled && pGallery->IsScrollButtonEnabled(XTP_HTSCROLLUP)));
  655. pImage->DrawImage(pDC, rcScrollUp, pImage->GetSource(nState, 5), CRect(3, 3, 3, 3), 0xFF00FF);
  656. nState = GETPARTSTATE3(XTP_HTSCROLLDOWN, (bControlEnabled && pGallery->IsScrollButtonEnabled(XTP_HTSCROLLDOWN)));
  657. pImage = pPaintManager->LoadImage(_T("CONTROLGALLERYDOWN"));
  658. pImage->DrawImage(pDC, rcScrollDown, pImage->GetSource(nState, 5), CRect(3, 3, 3, 3), 0xFF00FF);
  659. nState = GETPARTSTATE3(XTP_HTSCROLLPOPUP, bControlEnabled);
  660. pImage = pPaintManager->LoadImage(_T("CONTROLGALLERYPOPUP"));
  661. pImage->DrawImage(pDC, rcScrollPopup, pImage->GetSource(nState, 5), CRect(3, 3, 3, 3), 0xFF00FF);
  662. }
  663. AFX_INLINE CRect OffsetSourceRect(CRect rc, int nState)
  664. {
  665. rc.OffsetRect(0, (nState - 1) * rc.Height());
  666. return rc;
  667. }
  668. void CXTPControlGalleryOffice2007Theme::DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery)
  669. {
  670. XTPScrollBarStyle barStyle = pGallery->GetScrollBarStyle();
  671. if (barStyle != xtpScrollStyleOffice2007Light && barStyle != xtpScrollStyleOffice2007Dark)
  672. {
  673. CXTPControlGalleryPaintManager::DrawScrollBar(pDC, pGallery);
  674. return;
  675. }
  676. BOOL bLight = (barStyle == xtpScrollStyleOffice2007Light);
  677. #define GETPARTSTATE2(ht) 
  678. (!bEnabled ? 0 : nPressetHt == ht ? 3 : nHotHt == ht ? 2 : nHotHt > 0 || nPressetHt > 0 ? 1 : 0)
  679. CXTPControlGallery::SCROLLBARTRACKINFO* pSBTrack = pGallery->GetScrollBarTrackInfo();
  680. CXTPControlGallery::SCROLLBARPOSINFO* pSBInfo = pGallery->GetScrollBarPosInfo();
  681. BOOL nPressetHt = pSBTrack ? pSBInfo->ht : -1;
  682. BOOL nHotHt = pSBTrack ? -1 : pSBInfo->ht;
  683. int cWidth = (pSBInfo->pxRight - pSBInfo->pxLeft);
  684. if (cWidth <= 0)
  685. {
  686. return;
  687. }
  688. BOOL bEnabled = (pSBInfo->posMax - pSBInfo->posMin - pSBInfo->page + 1 > 0) && pGallery->IsScrollBarEnabled();
  689. int nBtnTrackSize =   pSBInfo->pxThumbBottom - pSBInfo->pxThumbTop;
  690. int nBtnTrackPos = pSBInfo->pxThumbTop - pSBInfo->pxUpArrow;
  691. if (!bEnabled || pSBInfo->pxThumbBottom > pSBInfo->pxDownArrow)
  692. nBtnTrackPos = nBtnTrackSize = 0;
  693. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)m_pPaintManager;
  694. CXTPOffice2007Image* pImageArrowGlyphs = pPaintManager->LoadImage(_T("CONTROLGALLERYSCROLLARROWGLYPHS"));
  695. ASSERT(pImageArrowGlyphs);
  696. if (!pImageArrowGlyphs)
  697. return;
  698. CRect rcArrowGripperSrc(0, 0, 9, 9);
  699. if (pSBInfo->fVert)
  700. {
  701. CXTPOffice2007Image* pImageBackground = pPaintManager->LoadImage(
  702. bLight ? _T("CONTROLGALLERYSCROLLVERTICALLIGHT") : _T("CONTROLGALLERYSCROLLVERTICALDARK"));
  703. ASSERT(pImageBackground);
  704. if (!pImageBackground)
  705. return;
  706. pImageBackground->DrawImage(pDC, pSBInfo->rc, pImageBackground->GetSource(0, 2), CRect(1, 0, 1, 0));
  707. CRect rcVScroll(pSBInfo->rc);
  708. rcVScroll.DeflateRect(1, 0);
  709. CRect rcArrowUp(rcVScroll.left, rcVScroll.top, rcVScroll.right, pSBInfo->pxUpArrow);
  710. CRect rcArrowDown(rcVScroll.left, pSBInfo->pxDownArrow, rcVScroll.right, rcVScroll.bottom);
  711. CXTPOffice2007Image* pImage =  pPaintManager->LoadImage(
  712. bLight ? _T("CONTROLGALLERYSCROLLARROWSVERTICALLIGHT") : _T("CONTROLGALLERYSCROLLARROWSVERTICALDARK"));
  713. ASSERT(pImage);
  714. if (!pImage)
  715. return;
  716. int nState = GETPARTSTATE2(XTP_HTSCROLLUP);
  717. if (nState != 0)
  718. {
  719. pImage->DrawImage(pDC, rcArrowUp, pImage->GetSource(nState, 4), CRect(3, 3, 3, 3));
  720. }
  721. CRect rcArrowUpGripper(CPoint((rcArrowUp.left + rcArrowUp.right - 9) / 2, (rcArrowUp.top + rcArrowUp.bottom - 9) / 2), CSize(9, 9));
  722. pImageArrowGlyphs->DrawImage(pDC, rcArrowUpGripper, OffsetSourceRect(rcArrowGripperSrc, !bEnabled ? ABS_UPDISABLED : nState != 0 ? ABS_UPHOT : ABS_UPNORMAL), CRect(0, 0, 0, 0), RGB(255, 0, 255));
  723. nState = GETPARTSTATE2(XTP_HTSCROLLDOWN);
  724. if (nState != 0)
  725. {
  726. pImage->DrawImage(pDC, rcArrowDown, pImage->GetSource(nState, 4), CRect(3, 3, 3, 3));
  727. }
  728. CRect rcArrowDownGripper(CPoint((rcArrowDown.left + rcArrowDown.right - 9) / 2, (rcArrowDown.top + rcArrowDown.bottom - 9) / 2), CSize(9, 9));
  729. pImageArrowGlyphs->DrawImage(pDC, rcArrowDownGripper, OffsetSourceRect(rcArrowGripperSrc, !bEnabled ? ABS_DOWNDISABLED : nState != 0 ? ABS_DOWNHOT : ABS_DOWNNORMAL), CRect(0, 0, 0, 0), RGB(255, 0, 255));
  730. CRect rcTrack(rcVScroll.left, rcArrowUp.bottom, rcVScroll.right, rcArrowDown.top);
  731. if (!rcTrack.IsRectEmpty())
  732. {
  733. CRect rcLowerTrack(rcTrack.left - 1, rcTrack.top, rcTrack.right + 1, rcTrack.top + nBtnTrackPos);
  734. CRect rcBtnTrack(rcTrack.left, rcLowerTrack.bottom, rcTrack.right, rcLowerTrack.bottom + nBtnTrackSize);
  735. CRect rcUpperTrack(rcTrack.left - 1, rcBtnTrack.bottom, rcTrack.right + 1, rcTrack.bottom);
  736. if (!rcLowerTrack.IsRectEmpty() && (GETPARTSTATE2(XTP_HTSCROLLUPPAGE) == 3))
  737. {
  738. pImageBackground->DrawImage(pDC, rcLowerTrack,
  739. pImageBackground->GetSource(1, 2), CRect(1, 0, 1, 0));
  740. }
  741. if (!rcBtnTrack.IsRectEmpty())
  742. {
  743. nState = GETPARTSTATE2(XTP_HTSCROLLTHUMB);
  744. if (nState > 0) nState--;
  745. pImage =  pPaintManager->LoadImage(_T("CONTROLGALLERYSCROLLTHUMBVERTICAL"));
  746. ASSERT(pImage);
  747. if (!pImage)
  748. return;
  749. pImage->DrawImage(pDC, rcBtnTrack, pImage->GetSource(nState, 3), CRect(5, 5, 5, 5));
  750. if (rcBtnTrack.Height() > 10)
  751. {
  752. pImage =  pPaintManager->LoadImage(_T("CONTROLGALLERYSCROLLTHUMBGRIPPERVERTICAL"));
  753. CRect rcGripper(CPoint(rcBtnTrack.CenterPoint().x - 3, rcBtnTrack.CenterPoint().y - 4), CSize(8, 8));
  754. pImage->DrawImage(pDC, rcGripper, pImage->GetSource(nState, 3), CRect(0, 0, 0, 0));
  755. }
  756. }
  757. if (!rcUpperTrack.IsRectEmpty() && (GETPARTSTATE2(XTP_HTSCROLLDOWNPAGE) == 3))
  758. {
  759. pImageBackground->DrawImage(pDC, rcUpperTrack,
  760. pImageBackground->GetSource(1, 2), CRect(1, 0, 1, 0));
  761. }
  762. }
  763. }
  764. else
  765. {
  766. CXTPOffice2007Image* pImageBackground = pPaintManager->LoadImage(
  767. bLight ? _T("CONTROLGALLERYSCROLLHORIZONTALLIGHT") : _T("CONTROLGALLERYSCROLLHORIZONTALDARK"));
  768. if (!pImageBackground)
  769. {
  770. CXTPControlGalleryPaintManager::DrawScrollBar(pDC, pGallery);
  771. return;
  772. }
  773. pImageBackground->DrawImage(pDC, pSBInfo->rc, pImageBackground->GetSource(0, 2), CRect(0, 1, 0, 1));
  774. CRect rcHScroll(pSBInfo->rc);
  775. rcHScroll.DeflateRect(0, 1);
  776. CRect rcArrowLeft(rcHScroll.left, rcHScroll.top, pSBInfo->pxUpArrow, rcHScroll.bottom);
  777. CRect rcArrowRight(pSBInfo->pxDownArrow, rcHScroll.top, rcHScroll.right, rcHScroll.bottom);
  778. CXTPOffice2007Image* pImage =  pPaintManager->LoadImage(
  779. bLight ? _T("CONTROLGALLERYSCROLLARROWSHORIZONTALLIGHT") : _T("CONTROLGALLERYSCROLLARROWSHORIZONTALDARK"));
  780. ASSERT(pImage);
  781. if (!pImage)
  782. return;
  783. int nState = GETPARTSTATE2(XTP_HTSCROLLUP);
  784. if (nState != 0)
  785. {
  786. pImage->DrawImage(pDC, rcArrowLeft, pImage->GetSource(nState, 4), CRect(3, 3, 3, 3));
  787. }
  788. CRect rcArrowLeftGripper(CPoint((rcArrowLeft.left + rcArrowLeft.right - 9) / 2, (rcArrowLeft.top + rcArrowLeft.bottom - 9) / 2), CSize(9, 9));
  789. pImageArrowGlyphs->DrawImage(pDC, rcArrowLeftGripper, OffsetSourceRect(rcArrowGripperSrc, !bEnabled ? ABS_LEFTDISABLED : nState != 0 ? ABS_LEFTHOT : ABS_LEFTNORMAL), CRect(0, 0, 0, 0), RGB(255, 0, 255));
  790. nState = GETPARTSTATE2(XTP_HTSCROLLDOWN);
  791. if (nState != 0)
  792. {
  793. pImage->DrawImage(pDC, rcArrowRight, pImage->GetSource(nState, 4), CRect(3, 3, 3, 3));
  794. }
  795. CRect rcArrowRightGripper(CPoint((rcArrowRight.left + rcArrowRight.right - 9) / 2, (rcArrowRight.top + rcArrowRight.bottom - 9) / 2), CSize(9, 9));
  796. pImageArrowGlyphs->DrawImage(pDC, rcArrowRightGripper, OffsetSourceRect(rcArrowGripperSrc, !bEnabled ? ABS_RIGHTDISABLED : nState != 0 ? ABS_RIGHTHOT : ABS_RIGHTNORMAL), CRect(0, 0, 0, 0), RGB(255, 0, 255));
  797. CRect rcTrack(rcArrowLeft.right, rcHScroll.top, rcArrowRight.left, rcHScroll.bottom);
  798. if (!rcTrack.IsRectEmpty())
  799. {
  800. CRect rcLowerTrack(rcTrack.left, rcTrack.top - 1, rcTrack.left + nBtnTrackPos, rcTrack.bottom + 1);
  801. CRect rcBtnTrack(rcLowerTrack.right, rcTrack.top, rcLowerTrack.right + nBtnTrackSize, rcTrack.bottom);
  802. CRect rcUpperTrack(rcBtnTrack.right, rcTrack.top - 1, rcTrack.right, rcTrack.bottom + 1);
  803. if (!rcLowerTrack.IsRectEmpty() && (GETPARTSTATE2(XTP_HTSCROLLUPPAGE) == 3))
  804. {
  805. pImageBackground->DrawImage(pDC, rcLowerTrack,
  806. pImageBackground->GetSource(1, 2), CRect(0, 1, 0, 1));
  807. }
  808. if (!rcBtnTrack.IsRectEmpty())
  809. {
  810. nState = GETPARTSTATE2(XTP_HTSCROLLTHUMB);
  811. if (nState > 0) nState--;
  812. pImage =  pPaintManager->LoadImage(_T("CONTROLGALLERYSCROLLTHUMBHORIZONTAL"));
  813. ASSERT(pImage);
  814. if (!pImage)
  815. return;
  816. pImage->DrawImage(pDC, rcBtnTrack, pImage->GetSource(nState, 3), CRect(5, 5, 5, 5));
  817. if (rcBtnTrack.Width() > 10)
  818. {
  819. pImage =  pPaintManager->LoadImage(_T("CONTROLGALLERYSCROLLTHUMBGRIPPERHORIZONTAL"));
  820. CRect rcGripper(CPoint(rcBtnTrack.CenterPoint().x - 3, rcBtnTrack.CenterPoint().y - 4), CSize(8, 8));
  821. pImage->DrawImage(pDC, rcGripper, pImage->GetSource(nState, 3), CRect(0, 0, 0, 0));
  822. }
  823. }
  824. if (!rcUpperTrack.IsRectEmpty() && (GETPARTSTATE2(XTP_HTSCROLLDOWNPAGE) == 3))
  825. {
  826. pImageBackground->DrawImage(pDC, rcUpperTrack,
  827. pImageBackground->GetSource(1, 2), CRect(0, 1, 0, 1));
  828. }
  829. }
  830. }
  831. }
  832. //////////////////////////////////////////////////////////////////////////
  833. // CXTPControlSliderOffice2007Theme
  834. void CXTPSliderOffice2007Theme::RefreshMetrics()
  835. {
  836. CXTPSliderPaintManager::RefreshMetrics();
  837. CXTPOffice2007Image* pImage = ((CXTPOffice2007Theme*)m_pPaintManager)->LoadImage(_T("SLIDERUP"));
  838. if (pImage)
  839. {
  840. m_cyHScroll = pImage->GetSource(0, 3).Height();
  841. m_cxHScroll = pImage->GetSource(0, 3).Width();
  842. }
  843. m_cThumb = 11;
  844. }
  845. void CXTPSliderOffice2007Theme::DrawScrollBar(CDC* pDC, CXTPScrollBase* pGallery)
  846. {
  847. #define GETPARTSTATE4(ht) (nPressetHt == ht ? 2 : nHotHt == ht ? 1 : 0)
  848. CXTPScrollBase::SCROLLBARTRACKINFO* pSBTrack = pGallery->GetScrollBarTrackInfo();
  849. CXTPScrollBase::SCROLLBARPOSINFO* pSBInfo = pGallery->GetScrollBarPosInfo();
  850. BOOL nPressetHt = pSBTrack ? (pSBTrack->bTrackThumb || pSBTrack->fHitOld ? pSBInfo->ht : -1) : -1;
  851. BOOL nHotHt = pSBTrack ? -1 : pSBInfo->ht;
  852. int cWidth = (pSBInfo->pxRight - pSBInfo->pxLeft);
  853. if (cWidth <= 0)
  854. {
  855. return;
  856. }
  857. BOOL bEnabled = (pSBInfo->posMax - pSBInfo->posMin - pSBInfo->page + 1 > 0) && pGallery->IsScrollBarEnabled();
  858. int nBtnTrackSize =   pSBInfo->pxThumbBottom - pSBInfo->pxThumbTop;
  859. int nBtnTrackPos = pSBInfo->pxThumbTop - pSBInfo->pxUpArrow;
  860. if (!bEnabled || pSBInfo->pxThumbBottom > pSBInfo->pxDownArrow)
  861. nBtnTrackPos = nBtnTrackSize = 0;
  862. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)m_pPaintManager;
  863. if (!pSBInfo->fVert)
  864. {
  865. CRect rcHScroll(pSBInfo->rc);
  866. CRect rcArrowLeft(rcHScroll.left, rcHScroll.top, pSBInfo->pxUpArrow, rcHScroll.bottom);
  867. CRect rcArrowRight(pSBInfo->pxDownArrow, rcHScroll.top, rcHScroll.right, rcHScroll.bottom);
  868. CRect rcTrack(rcArrowLeft.right, rcHScroll.top, rcArrowRight.left, rcHScroll.bottom);
  869. CRect rcBtnTrack(rcTrack.left + nBtnTrackPos, rcTrack.top, rcTrack.left + nBtnTrackPos + nBtnTrackSize, rcTrack.bottom);
  870. CXTPOffice2007Image* pImage =  pPaintManager->LoadImage(_T("SLIDERTRACK"));
  871. ASSERT(pImage);
  872. if (!pImage)
  873. return;
  874. CRect rcTrackDest(CPoint(rcTrack.left, (rcTrack.top + rcTrack.bottom - pImage->GetHeight()) / 2), CSize(rcTrack.Width(), pImage->GetHeight()));
  875. pImage->DrawImage(pDC, rcTrackDest, pImage->GetSource());
  876. pImage =  pPaintManager->LoadImage(_T("SLIDERTICK"));
  877. CXTPScrollBase::SLIDERTICKS* pTicks = pGallery->GetTicks();
  878. if (!pTicks || (pSBInfo->posMax <= pSBInfo->posMin))
  879. {
  880. CRect rcTrackTickDest(CPoint((rcTrackDest.left + rcTrackDest.right - pImage->GetWidth()) / 2,
  881. (rcTrackDest.top + rcTrackDest.bottom - pImage->GetHeight()) / 2), pImage->GetExtent());
  882. pImage->DrawImage(pDC, rcTrackTickDest, pImage->GetSource(), CRect(0, 0, 0, 0), 0xFF00FF);
  883. }
  884. else
  885. {
  886. rcTrackDest.DeflateRect(6, 0);
  887. for (int i = 0; i < pTicks->nCount; i++)
  888. {
  889. double dTick = pTicks->pTicks[i];
  890. double dPos = (dTick - pSBInfo->posMin) * rcTrackDest.Width() / (pSBInfo->posMax - pSBInfo->posMin);
  891. if (dPos >= 0 && dPos <= rcTrackDest.Width())
  892. {
  893. CRect rcTrackTickDest(CPoint(rcTrackDest.left + (int)dPos - pImage->GetWidth() / 2,
  894. (rcTrackDest.top + rcTrackDest.bottom - pImage->GetHeight()) / 2), pImage->GetExtent());
  895. pImage->DrawImage(pDC, rcTrackTickDest, pImage->GetSource(), CRect(0, 0, 0, 0), 0xFF00FF);
  896. }
  897. }
  898. }
  899. pImage = pPaintManager->LoadImage(_T("SLIDERUP"));
  900. pImage->DrawImage(pDC, rcArrowLeft, pImage->GetSource(GETPARTSTATE4(XTP_HTSCROLLUP), 3));
  901. pImage = pPaintManager->LoadImage(_T("SLIDERDOWN"));
  902. pImage->DrawImage(pDC, rcArrowRight, pImage->GetSource(GETPARTSTATE4(XTP_HTSCROLLDOWN), 3));
  903. if (bEnabled)
  904. {
  905. pImage = pPaintManager->LoadImage(_T("SLIDERTHUMB"));
  906. CRect rcImgSrc = pImage->GetSource(
  907. nPressetHt == XTP_HTSCROLLTHUMB  ? 2 : nPressetHt == XTP_HTSCROLLUPPAGE || nPressetHt == XTP_HTSCROLLDOWNPAGE ||
  908. nHotHt == XTP_HTSCROLLUPPAGE || nHotHt == XTP_HTSCROLLDOWNPAGE || nHotHt == XTP_HTSCROLLTHUMB ? 1 : 0, 3);
  909. CRect rcBtnTrackDest(CPoint((rcBtnTrack.left + rcBtnTrack.right - rcImgSrc.Width()) / 2,
  910. (rcBtnTrack.top + rcBtnTrack.bottom - rcImgSrc.Height()) / 2), rcImgSrc.Size());
  911. pImage->DrawImage(pDC, rcBtnTrackDest, rcImgSrc);
  912. }
  913. }
  914. }
  915. //////////////////////////////////////////////////////////////////////////
  916. // CXTPProgressOffice2007Theme
  917. CXTPProgressOffice2007Theme::CXTPProgressOffice2007Theme(CXTPPaintManager* pPaintManager)
  918. : CXTPProgressPaintManager(pPaintManager)
  919. {
  920. m_cyProgress = 12;
  921. }
  922. void CXTPProgressOffice2007Theme::DrawProgress(CDC* pDC, CXTPProgressBase* pProgressBar)
  923. {
  924. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)m_pPaintManager;
  925. CXTPOffice2007Image* pImage =  pPaintManager->LoadImage(_T("PROGRESSTRACK"));
  926. ASSERT(pImage);
  927. if (!pImage)
  928. return;
  929. CRect rc = pProgressBar->GetProgressRect();
  930. pImage->DrawImage(pDC, rc, pImage->GetSource(), CRect(2, 2, 2, 2), 0xFF00FF);
  931. int nLower, nUpper, nPos;
  932. pProgressBar->GetRange(nLower, nUpper);
  933. nPos = pProgressBar->GetPos();
  934. rc.DeflateRect(2, 2);
  935. int nWidth = rc.Width();
  936. int x = MulDiv(nWidth, nPos - nLower, nUpper - nLower);
  937. pImage =  pPaintManager->LoadImage(_T("PROGRESSCHUNK"));
  938. ASSERT(pImage);
  939. if (!pImage)
  940. return;
  941. CRect rcSrc(pImage->GetSource());
  942. rcSrc.right -= 4;
  943. CRect rcDest(rc.left, rc.top, rc.left + x, rc.bottom);
  944. if (rcDest.Width() < rcSrc.Width())
  945. rcSrc.left = rcSrc.right - rcDest.Width();
  946. pImage->DrawImage(pDC, rcDest, rcSrc, CRect(2, 2, 2, 2), 0xFF00FF);
  947. if (rc.left + x < rc.right - 1)
  948. {
  949. int nShadow = min(4, rc.right - rc.left - x);
  950. rcSrc = CRect(rcSrc.right, rcSrc.top, rcSrc.right + nShadow, rcSrc.bottom);
  951. rcDest = CRect(rcDest.right, rcDest.top, rcDest.right + nShadow, rcDest.bottom);
  952. pImage->DrawImage(pDC, rcDest, rcSrc, CRect(0, 2, 0, 2), 0xFF00FF);
  953. return;
  954. }
  955. }