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

对话框与窗口

开发平台:

Visual C++

  1. // XTThemeManager.h: interface for the CXTThemeManager class.
  2. //
  3. // This file is a part of the XTREME CONTROLS 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. //{{AFX_CODEJOCK_PRIVATE
  21. #if !defined(__XTTHEMEMANAGER_H__)
  22. #define __XTTHEMEMANAGER_H__
  23. //}}AFX_CODEJOCK_PRIVATE
  24. #if _MSC_VER > 1000
  25. #pragma once
  26. #endif // _MSC_VER > 1000
  27. #include "Common/XTPWinThemeWrapper.h"
  28. #include "Common/XTPColorManager.h"
  29. // -------------------------------------------------------------
  30. // Summary:
  31. //     Enumeration used to determine active theme.
  32. // Remarks:
  33. //     XTThemeStyle type defines the constants used by the
  34. //     CXTThemeManger to determine the currently selected theme.
  35. // See Also:
  36. //     CXTThemeManagerStyleFactory::CreateTheme
  37. //
  38. // <KEYWORDS xtThemeDefault, xtThemeOfficeXP, xtThemeOffice2003, xtThemeCustom>
  39. // -------------------------------------------------------------
  40. enum XTThemeStyle
  41. {
  42. xtThemeDefault,     // Windows classic theme.
  43. xtThemeOfficeXP,    // Microsoft(r) Office XP theme.
  44. xtThemeOffice2003,  // Microsoft(r) Office 2003 theme.
  45. xtThemeCustom       // User defined theme.
  46. };
  47. class CXTThemeManagerStyleHost;
  48. class CXTThemeManagerStyleFactory;
  49. class CXTThemeManager;
  50. // ----------------------------------------------------------------------
  51. // Summary:
  52. //     The XTThemeManager function is used for access to the
  53. //     CXTThemeManager class.
  54. // Remarks:
  55. //     Call this function to access CXTThemeManager members. Since
  56. //     this class is designed as a single instance object you can only
  57. //     access its members through this method. You cannot directly
  58. //     instantiate an object of type CXTThemeManager.
  59. // Returns:
  60. //     A pointer to the one and only CXTThemeManager instance.
  61. // Example:
  62. //     The following example demonstrates how to use XTThemeManager.
  63. // <code>
  64. // XTThemeManager()->SetTheme(xtThemeOfficeXP);
  65. // </code>
  66. // See Also:
  67. //     CXTThemeManager
  68. // ----------------------------------------------------------------------
  69. _XTP_EXT_CLASS CXTThemeManager* AFX_CDECL XTThemeManager();
  70. //===========================================================================
  71. // Summary:
  72. //     CXTThemeManagerStyle is standalone class used as base for any components
  73. //     theme.
  74. // Remarks:
  75. //     This is base class for any theme class. I collect information about
  76. //     selected theme and factory(CXTThemeManagerStyleFactory) created it.
  77. // See Also: CXTThemeManagerStyleFactory, CXTThemeManager, CXTThemeManagerStyleHost
  78. //===========================================================================
  79. class _XTP_EXT_CLASS CXTThemeManagerStyle
  80. {
  81. public:
  82. //-------------------------------------------------------------------------
  83. // Summary:
  84. //     Construct a CXTThemeManagerStyle object.
  85. //-------------------------------------------------------------------------
  86. CXTThemeManagerStyle();
  87. //-------------------------------------------------------------------------
  88. // Summary:
  89. //     Destroys a CXTThemeManagerStyle object, handles cleanup and deallocation.
  90. //-------------------------------------------------------------------------
  91. virtual ~CXTThemeManagerStyle();
  92. public:
  93. //-------------------------------------------------------------------------
  94. // Summary:
  95. //     This method is called to refresh the visual metrics of
  96. //     the theme (fonts, colors, etc.).
  97. //-------------------------------------------------------------------------
  98. virtual void RefreshMetrics();
  99. //-----------------------------------------------------------------------
  100. // Summary:
  101. //     Retrieves factory created this theme
  102. // Returns:
  103. //     Pointer to CXTThemeManagerStyleFactory class created the theme
  104. //-----------------------------------------------------------------------
  105. CXTThemeManagerStyleFactory* GetThemeFactory();
  106. //-----------------------------------------------------------------------
  107. // Summary:
  108. //     Retrieves self theme enumerator.
  109. // Returns:
  110. //     Self theme of CXTThemeManagerStyle class. It can be one of the following:
  111. //     * <b>xtThemeDefault</b>    Enables Windows classic theme.
  112. //     * <b>xtThemeOfficeXP</b>   Enables Microsoft(r) Office XP theme.
  113. //     * <b>xtThemeOffice2003</b> Enables Microsoft(r) Office 2003 theme.
  114. //     * <b>xtThemeCustom</b>     Enables User defined theme.
  115. //-----------------------------------------------------------------------
  116. XTThemeStyle GetTheme();
  117. //-----------------------------------------------------------------------
  118. // Summary:
  119. //     Retrieves if default or Microsoft(r) Office theme used.
  120. // Returns:
  121. //     TRUE if xtThemeOfficeXP or xtThemeOffice2003 used.
  122. //-----------------------------------------------------------------------
  123. BOOL IsOfficeTheme();
  124. //-----------------------------------------------------------------------
  125. // Summary:
  126. //      This member function is called by the Theme Manager to capture the
  127. //      area on the parent window underneath the specified owner window.
  128. //      This is then used for rendering the owner transparent.
  129. // Parameters:
  130. //      pWndOwner - Pointer the child of the parent window to take a
  131. //                  snapshot for.
  132. // Returns:
  133. //      TRUE if the parent area was successfully captured, otherwise
  134. //      returns FALSE.
  135. // See Also:
  136. //      DrawTransparentBack
  137. //-----------------------------------------------------------------------
  138. virtual BOOL TakeSnapShot(CWnd* pWndOwner);
  139. //-----------------------------------------------------------------------
  140. // Summary:
  141. //      This member function is called to render the window specified
  142. //      by pWndOwner transparent displaying the parent windows background
  143. //      instead.
  144. // Parameters:
  145. //      pDC - Pointer to pWndOwner device context.
  146. //      pWndOwner - Pointer the child of the parent window to draw
  147. //                  transparent.
  148. // Returns:
  149. //      TRUE if the area was dran transparently, otherwise returns FALSE.
  150. // See Also:
  151. //      TakeSnapShot
  152. //-----------------------------------------------------------------------
  153. virtual BOOL DrawTransparentBack(CDC* pDC, CWnd* pWndOwner);
  154. protected:
  155. CXTThemeManagerStyleFactory*    m_pFactory;     // Self factory class.
  156. XTThemeStyle                    m_enumTheme;    // Self theme enumerator.
  157. CBitmap                         m_bmpSnapShot;  // Used for drawing transparent background.
  158. friend class CXTThemeManagerStyleFactory;
  159. };
  160. //===========================================================================
  161. // Summary:
  162. //     CXTThemeManagerStyleFactory is CObject derived class. It managed themes of corresponded
  163. //     CXTThemeManagerStyleHost class
  164. // Remarks:
  165. //     Each Component supported themes associated with one CXTThemeManagerStyleFactory class
  166. //     which porpoise is to create theme specified for this component.
  167. //     CXTThemeManagerStyleFactory class collect pointer to all CXTThemeManagerStyleHost
  168. //     used it.
  169. //     Use DECLARE_THEME_FACTORY and IMPLEMENT_THEME_FACTORY to create theme factory class.
  170. // See Also: CXTThemeManagerStyle, CXTThemeManager, CXTThemeManagerStyleHost
  171. //===========================================================================
  172. class _XTP_EXT_CLASS CXTThemeManagerStyleFactory : public CObject
  173. {
  174. DECLARE_DYNCREATE(CXTThemeManagerStyleFactory)
  175. public:
  176. //-------------------------------------------------------------------------
  177. // Summary:
  178. //     Construct a CXTThemeManagerStyleFactory object.
  179. //-------------------------------------------------------------------------
  180. CXTThemeManagerStyleFactory();
  181. //-------------------------------------------------------------------------
  182. // Summary:
  183. //     Destroys a CXTThemeManagerStyleFactory object, handles cleanup and deallocation.
  184. //-------------------------------------------------------------------------
  185. virtual ~CXTThemeManagerStyleFactory();
  186. public:
  187. //-----------------------------------------------------------------------
  188. // Summary:
  189. //     This method created specified theme for corresponded CXTThemeManagerStyleHost component
  190. // Remarks:
  191. //     Use IMPLEMENT_THEME_FACTORY macro to create new theme with overridden CreateTheme method
  192. // Parameters:
  193. //     theme - Theme need to create
  194. //-----------------------------------------------------------------------
  195. virtual CXTThemeManagerStyle* CreateTheme(XTThemeStyle theme);
  196. //-----------------------------------------------------------------------
  197. // Summary:
  198. //     Call this method to set safe theme
  199. // Parameters:
  200. //     pTheme - Pointer to custom theme
  201. //     theme  - Theme enumerator.
  202. // Remarks:
  203. //     theme can be one of following values:
  204. //     * <b>xtThemeDefault</b>    Enables Windows classic theme.
  205. //     * <b>xtThemeOfficeXP</b>   Enables Microsoft(r) Office XP theme.
  206. //     * <b>xtThemeOffice2003</b> Enables Microsoft(r) Office 2003 theme.
  207. //-----------------------------------------------------------------------
  208. void SetTheme(XTThemeStyle theme);
  209. void SetTheme(CXTThemeManagerStyle* pTheme); // <COMBINE CXTThemeManagerStyleFactory::SetTheme@XTThemeStyle>
  210. //-------------------------------------------------------------------------
  211. // Summary:
  212. //     This method is called to refresh the visual metrics of
  213. //     the safe theme (fonts, colors, etc.).
  214. // Remarks:
  215. //     It routes call to self m_pTheme:
  216. // Example:
  217. //     The following example demonstrates how to use RefreshMetrics.
  218. // <code>
  219. // if (m_pTheme)
  220. // {
  221. //     m_pTheme->RefreshMetrics();
  222. // }
  223. // </code>
  224. //-------------------------------------------------------------------------
  225. virtual void RefreshMetrics();
  226. //-----------------------------------------------------------------------
  227. // Summary:
  228. //     Retrieves safe theme.
  229. // Returns:
  230. //     Pointer to safe CXTThemeManagerStyle class.
  231. //-----------------------------------------------------------------------
  232. CXTThemeManagerStyle* GetSafeTheme();
  233. protected:
  234. //-----------------------------------------------------------------------
  235. // Summary:
  236. //     This method is called when new theme created.
  237. // Parameters:
  238. //     pTheme - new created theme pointer.
  239. //     theme - style of theme was created.
  240. //-----------------------------------------------------------------------
  241. void OnCreateSafeTheme(CXTThemeManagerStyle* pTheme, XTThemeStyle theme);
  242. private:
  243. DISABLE_COPY_OPERATOR(CXTThemeManagerStyleFactory)
  244. protected:
  245. CXTThemeManagerStyle*                       m_pTheme;       // Safe theme pointer
  246. CTypedSimpleList<CXTThemeManagerStyleHost*> m_hostList;     // Collection of Host objects used this factory.
  247. private:
  248. CXTThemeManagerStyleFactory*                m_pNextFactory;
  249. friend class CXTThemeManager;
  250. friend class CXTThemeManagerStyleHost;
  251. };
  252. //===========================================================================
  253. // Summary:
  254. //     CXTThemeManagerStyleHost is standalone class. It used  as base
  255. //     class for all themed component.
  256. // Remarks:
  257. //     CXTThemeManagerStyleHost is base class for all theme supported
  258. //     components. Use its methods to set specified for individual component
  259. //     theme.
  260. //===========================================================================
  261. class _XTP_EXT_CLASS CXTThemeManagerStyleHost
  262. {
  263. protected:
  264. //-----------------------------------------------------------------------
  265. // Summary:
  266. //     Constructs a CXTThemeManagerStyleHost object.
  267. // Parameters:
  268. //     pThemeFactoryClass - Factory runtime class associated with this class
  269. //-----------------------------------------------------------------------
  270. CXTThemeManagerStyleHost(CRuntimeClass* pThemeFactoryClass);
  271. //-------------------------------------------------------------------------
  272. // Summary:
  273. //     Destroys a CXTThemeManagerStyleHost object, handles cleanup and deallocation.
  274. //-------------------------------------------------------------------------
  275. virtual ~CXTThemeManagerStyleHost();
  276. //-------------------------------------------------------------------------
  277. // Summary:
  278. //     This member function is called to initialize the theme manager style host.
  279. // Parameters:
  280. //     pThemeFactoryClass - Factory runtime class associated with this class
  281. //-----------------------------------------------------------------------
  282. void InitStyleHost(CRuntimeClass* pThemeFactoryClass);
  283. public:
  284. //-----------------------------------------------------------------------
  285. // Summary:
  286. //     Call this method to attach factory to the component.
  287. // Parameters:
  288. //     pFactory - Factory need to be attached.
  289. // Example:
  290. //     The following example demonstrates how to use AttachThemeFactory.
  291. // <code>
  292. // extern CXTCaptionThemeFactory m_buttonFactory;
  293. // m_buttonFactory.SetTheme(xtpThemeOffice2003);
  294. // m_btnOK.AttachThemeFactory(&m_buttonFactory)
  295. // m_btnCancel.AttachThemeFactory(&m_buttonFactory)
  296. // </code>
  297. //-----------------------------------------------------------------------
  298. void AttachThemeFactory(CXTThemeManagerStyleFactory* pFactory);
  299. //-----------------------------------------------------------------------
  300. // Summary:
  301. //     Call this method to set theme for the component
  302. // Parameters:
  303. //     theme - Theme need to be set
  304. //     pTheme - Custom theme need to be set
  305. // Remarks:
  306. //     Theme can be one of following values:
  307. //     * <b>xtThemeDefault</b>    Enables Windows classic theme.
  308. //     * <b>xtThemeOfficeXP</b>   Enables Microsoft(r) Office XP theme.
  309. //     * <b>xtThemeOffice2003</b> Enables Microsoft(r) Office 2003 theme.
  310. // Example:
  311. //     The following example demonstrates how to use SetTheme.
  312. // <code>
  313. // m_btnOK.SetTheme(xtThemeOffice2003)
  314. // m_btnCancel.SetTheme(xtThemeOffice2003)
  315. // </code>
  316. //-----------------------------------------------------------------------
  317. void SetTheme (XTThemeStyle theme);
  318. void SetTheme (CXTThemeManagerStyle* pTheme); // <combine CXTThemeManagerStyleHost::SetTheme@XTThemeStyle>
  319. protected:
  320. //-----------------------------------------------------------------------
  321. // Summary:
  322. //     This method called to create self theme factory class
  323. // Remarks:
  324. //     It creates factory class used runtime class specified in constructor.
  325. // Example:
  326. //     The following example demonstrates how to use CreateThemeFactory.
  327. // <code>
  328. // return (CXTThemeManagerStyleFactory*)m_pThemeFactoryClass->CreateObject();
  329. // </code>
  330. // Returns:
  331. //     Pointer to created CXTThemeManagerStyleFactory class
  332. //-----------------------------------------------------------------------
  333. virtual CXTThemeManagerStyleFactory* CreateThemeFactory();
  334. //-------------------------------------------------------------------------
  335. // Summary:
  336. //     This method is called then self theme is changed. Override this method
  337. //     to redraw or reposition parts of component according of new theme.
  338. // See Also: GetSafeTheme
  339. //-------------------------------------------------------------------------
  340. virtual void OnThemeChanged();
  341. //-----------------------------------------------------------------------
  342. // Summary:
  343. //     Retrieves safe theme of component
  344. // Returns:
  345. //     Pointer to self theme.
  346. //-----------------------------------------------------------------------
  347. CXTThemeManagerStyle* GetSafeTheme() const;
  348. //-----------------------------------------------------------------------
  349. // Summary:
  350. //     Retrieves self factory class
  351. // Returns:
  352. //     Pointer to CXTThemeManagerStyleFactory class.
  353. //-----------------------------------------------------------------------
  354. CXTThemeManagerStyleFactory* GetSafeThemeFactory() const;
  355. protected:
  356. BOOL                         m_bAutoDeleteCustomFactory; // TRUE to delete custom theme factory.
  357. CRuntimeClass*               m_pThemeFactoryClass;       // Runtime class of default theme factory.
  358. CXTThemeManagerStyleFactory* m_pCustomFactory;           // Custom theme factory
  359. CXTThemeManagerStyleFactory* m_pDefaultFactory;          // Default theme factory
  360. private:
  361. CXTThemeManagerStyleHost*    m_pNextHost;
  362. friend class CXTThemeManagerStyleFactory;
  363. };
  364. //===========================================================================
  365. // Summary:
  366. //     CXTThemeManager is standalone class used to manage the visual styles for your
  367. //     application.
  368. // Remarks:
  369. //     CXTThemeManager is used to manage the visual styles for your
  370. //     application.  Add a member of this type to your frame or
  371. //     dialog class to manage your application themes.  See SetTheme
  372. //     for more information on setting themes.
  373. // See Also: XTThemeManager, CXTThemeManagerStyle, CXTThemeManagerStyleHost
  374. //===========================================================================
  375. class _XTP_EXT_CLASS CXTThemeManager : public CNoTrackObject
  376. {
  377. public:
  378. //-------------------------------------------------------------------------
  379. // Summary:
  380. //     Constructs a CXTThemeManager object.
  381. //-------------------------------------------------------------------------
  382. CXTThemeManager();
  383. //-------------------------------------------------------------------------
  384. // Summary:
  385. //     Destroys a CXTThemeManager object, handles cleanup and deallocation.
  386. //-------------------------------------------------------------------------
  387. virtual ~CXTThemeManager();
  388. public:
  389. //-----------------------------------------------------------------------
  390. // Summary:
  391. //     Retrieved theme factory class for specified runtime class.
  392. //     Creates new if no found.
  393. // Parameters:
  394. //     pThemeFactoryClass - Runtime class need to find
  395. // Returns:
  396. //     CXTThemeManagerStyleFactory pointer associated with its runtime class.
  397. // Example:
  398. //     The following example demonstrates how to use GetDefaultThemeFactory.
  399. // <code>
  400. // XTThemeManager()->GetDefaultThemeFactory(RUNTIME_CLASS(CXTCaptionThemeFactory));
  401. // </code>
  402. //-----------------------------------------------------------------------
  403. CXTThemeManagerStyleFactory* GetDefaultThemeFactory(CRuntimeClass* pThemeFactoryClass);
  404. //-----------------------------------------------------------------------
  405. // Summary:
  406. //     Call this method to set theme for all components.
  407. // Parameters:
  408. //     theme - Theme need to set
  409. // Remarks:
  410. //     Theme can be one of following values:
  411. //     * <b>xtThemeDefault</b>    Enables Windows classic theme.
  412. //     * <b>xtThemeOfficeXP</b>   Enables Microsoft(r) Office XP theme.
  413. //     * <b>xtThemeOffice2003</b> Enables Microsoft(r) Office 2003 theme.
  414. // Example:
  415. //     The following example demonstrates how to use SetTheme.
  416. // <code>
  417. // XTThemeManager()->SetTheme(xtThemeOffice2003);
  418. // </code>
  419. // See Also: GetTheme, XTThemeManager
  420. //-----------------------------------------------------------------------
  421. void SetTheme(XTThemeStyle theme);
  422. //-----------------------------------------------------------------------
  423. // Summary:
  424. //     Retrieved default theme for all components
  425. // Returns:
  426. //     Default theme for all components.
  427. // Example:
  428. //     The following example demonstrates how to use GetTheme.
  429. // <code>
  430. // XTThemeManager()->GetTheme();
  431. // </code>
  432. // See Also: SetTheme, XTThemeManager
  433. //-----------------------------------------------------------------------
  434. XTThemeStyle GetTheme();
  435. //-------------------------------------------------------------------------
  436. // Summary:
  437. //     Call this method to refresh visual metrics of all themes.
  438. // See Also: CXTThemeManagerStyle::RefreshMetrics
  439. //-------------------------------------------------------------------------
  440. void RefreshMetrics();
  441. protected:
  442. CMapPtrToPtr                               m_mapDefaultFactories; // Default factories collection
  443. XTThemeStyle                               m_enumTheme;           // Default theme for all components
  444. CTypedSimpleList<CXTThemeManagerStyleFactory*> m_factoryList;     // Collection of all theme factories.
  445. private:
  446. static CProcessLocal<CXTThemeManager>          m_sThemeManager;
  447. friend _XTP_EXT_CLASS CXTThemeManager* AFX_CDECL XTThemeManager();
  448. friend class CXTThemeManagerStyleFactory;
  449. };
  450. //-----------------------------------------------------------------------
  451. // Summary:
  452. //     Use this macro to declare the factory class for specified theme
  453. // Parameters:
  454. //     theClass - Base theme class.
  455. // Example:
  456. //     The following example demonstrates how to use DECLARE_THEME_FACTORY.
  457. // <code>
  458. // DECLARE_THEME_FACTORY(CXTCaptionTheme)
  459. //
  460. // class _XTP_EXT_CLASS CXTCaptionTheme : public CXTThemeManagerStyle
  461. // {
  462. // public:
  463. //     CXTCaptionTheme();
  464. // };
  465. // </code>
  466. // See Also: IMPLEMENT_THEME_FACTORY, CXTThemeManagerStyleFactory
  467. //-----------------------------------------------------------------------
  468. #define DECLARE_THEME_FACTORY(theClass)
  469. //{{AFX_CODEJOCK_PRIVATE
  470. #undef DECLARE_THEME_FACTORY
  471. #define DECLARE_THEME_FACTORY(theClass)
  472. class _XTP_EXT_CLASS theClass##Factory : public CXTThemeManagerStyleFactory
  473. {
  474. DECLARE_DYNCREATE(theClass##Factory)
  475. public:
  476. CXTThemeManagerStyle* CreateTheme(XTThemeStyle theme);
  477. };
  478. //}}AFX_CODEJOCK_PRIVATE
  479. //-----------------------------------------------------------------------
  480. // Summary:
  481. //     Use this macro to implement factory class for specified theme.
  482. // Parameters:
  483. //     theClass - Base theme class.
  484. //     theClassOfficeXP - Theme used for xtThemeOfficeXP style
  485. //     theClassOffice2003 - Theme used for xtThemeOffice2003 style
  486. // Example:
  487. //     The following example demonstrates how to use IMPLEMENT_THEME_FACTORY.
  488. // <code>
  489. // // Implement CXTCaptionThemeFactory class
  490. // IMPLEMENT_THEME_FACTORY(CXTCaptionTheme, CXTCaptionThemeOfficeXP, CXTCaptionThemeOfficeXP)
  491. //
  492. // CXTCaptionTheme::CXTCaptionTheme()
  493. // {
  494. //     RefreshMetrics();
  495. // }
  496. //
  497. // void CXTCaptionTheme::RefreshMetrics()
  498. // {
  499. //     m_clrEdgeShadow.SetStandardValue(
  500. //         GetXtremeColor(COLOR_3DSHADOW));
  501. //     m_clrEdgeLight.SetStandardValue(
  502. //         GetXtremeColor(COLOR_3DHILIGHT));
  503. // }
  504. // </code>
  505. // See Also: DECLARE_THEME_FACTORY, CXTThemeManagerStyleFactory
  506. //-----------------------------------------------------------------------
  507. #define IMPLEMENT_THEME_FACTORY(theClass)
  508. //{{AFX_CODEJOCK_PRIVATE
  509. #undef IMPLEMENT_THEME_FACTORY
  510. #define IMPLEMENT_THEME_FACTORY(theClass)
  511. IMPLEMENT_DYNCREATE(theClass##Factory, CXTThemeManagerStyleFactory)
  512. CXTThemeManagerStyle* theClass##Factory::CreateTheme(XTThemeStyle theme)
  513. {
  514. CXTThemeManagerStyle* pTheme = 0;
  515. switch (theme)
  516. {
  517. case xtThemeOfficeXP:
  518. pTheme = new theClass##OfficeXP();
  519. break;
  520. case xtThemeOffice2003:
  521. pTheme = new theClass##Office2003();
  522. break;
  523. default:
  524. pTheme = new theClass##();
  525. break;
  526. }
  527. OnCreateSafeTheme(pTheme, theme);
  528. return pTheme;
  529. }
  530. #define DECLARE_THEME_HOST(theClass)
  531. public:
  532. theClass##Theme* GetTheme() const;
  533. static theClass##Theme* AFX_CDECL GetDefaultTheme();
  534. static void AFX_CDECL SetDefaultTheme(XTThemeStyle theme);
  535. static void AFX_CDECL SetDefaultTheme(CXTThemeManagerStyle* pTheme);
  536. static CRuntimeClass* AFX_CDECL GetThemeFactoryClass();
  537. #define IMPLEMENT_THEME_HOST(theClass)
  538. theClass##Theme* theClass::GetTheme() const {
  539. return (theClass##Theme*)GetSafeTheme();
  540. }
  541. theClass##Theme* theClass::GetDefaultTheme() {
  542. return (theClass##Theme*)XTThemeManager()->GetDefaultThemeFactory(GetThemeFactoryClass())->GetSafeTheme();
  543. }
  544. void theClass::SetDefaultTheme(XTThemeStyle theme) {
  545. XTThemeManager()->GetDefaultThemeFactory(GetThemeFactoryClass())->SetTheme(theme);
  546. }
  547. void theClass::SetDefaultTheme(CXTThemeManagerStyle* pTheme) {
  548. XTThemeManager()->GetDefaultThemeFactory(GetThemeFactoryClass())->SetTheme(pTheme);
  549. }
  550. CRuntimeClass* theClass::GetThemeFactoryClass() {
  551. return RUNTIME_CLASS(theClass##ThemeFactory);
  552. }
  553. #define DECLARE_THEME_REFRESH(theClass)
  554. protected:
  555. virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
  556. #define IMPLEMENT_THEME_REFRESH(theClass, theBase)
  557. BOOL theClass::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult) {
  558. if (message == WM_SETTINGCHANGE || message == WM_SYSCOLORCHANGE)
  559. {
  560. GetTheme()->RefreshMetrics();
  561. Invalidate(FALSE);
  562. }
  563. return theBase::OnWndMsg(message, wParam, lParam, pResult);
  564. }
  565. #define CXTThemeManagerStyleHostBase CXTThemeManagerStyleHost
  566. //}}AFX_CODEJOCK_PRIVATE
  567. //////////////////////////////////////////////////////////////////////////
  568. AFX_INLINE XTThemeStyle CXTThemeManagerStyle::GetTheme() {
  569. return m_enumTheme;
  570. }
  571. AFX_INLINE CXTThemeManagerStyleFactory* CXTThemeManagerStyle::GetThemeFactory() {
  572. return m_pFactory;
  573. }
  574. AFX_INLINE XTThemeStyle CXTThemeManager::GetTheme() {
  575. return m_enumTheme;
  576. }
  577. AFX_INLINE void CXTThemeManagerStyleFactory::OnCreateSafeTheme(CXTThemeManagerStyle* pTheme, XTThemeStyle theme) {
  578. pTheme->m_enumTheme = theme;
  579. }
  580. //////////////////////////////////////////////////////////////////////
  581. #endif // !defined(__XTTHEMEMANAGER_H__)