Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
27 KiB

  1. //-------------------------------------------------------------------------//
  2. // NCTheme.h
  3. //-------------------------------------------------------------------------//
  4. #ifndef __NC_THEME_H__
  5. #define __NC_THEME_H__
  6. #include "handlers.h"
  7. //---------------------------------------------------------------------------//
  8. // Enable/disable rude message dumping
  9. //
  10. //---------------------------------------------------------------------------//
  11. //#define _ENABLE_MSG_SPEW_
  12. //---------------------------------------------------------------------------//
  13. // Enable/disable rude scrollinfo dumping
  14. //
  15. //#define _ENABLE_SCROLL_SPEW_
  16. //---------------------------------------------------------------------------//
  17. // Debug CThemeWnd, critsec double deletion
  18. #define DEBUG_THEMEWND_DESTRUCTOR
  19. //---------------------------------------------------------------------------
  20. // Target window theme class flags
  21. #define TWCF_DIALOG 0x00000001
  22. #define TWCF_FRAME 0x00000002
  23. #define TWCF_TOOLFRAME 0x00000004
  24. #define TWCF_SCROLLBARS 0x00000010
  25. #define TWCF_CLIENTEDGE 0x00010000 // not targetted per se
  26. #define TWCF_NCTHEMETARGETMASK 0x0000FFFF
  27. #define TWCF_ALL (TWCF_DIALOG|TWCF_FRAME|TWCF_TOOLFRAME|\
  28. TWCF_SCROLLBARS|TWCF_CLIENTEDGE)
  29. #define TWCF_ANY TWCF_ALL
  30. //---------------------------------------------------------------------------
  31. // per-window NC rectangle identifiers.
  32. typedef enum _eNCWNDMETRECT
  33. {
  34. #define NCRC_FIRST NCRC_WINDOW
  35. NCRC_WINDOW = 0, // window rect
  36. NCRC_CLIENT = 1, // client rect
  37. NCRC_UXCLIENT = 2, // client rect, computed based on theme layout.
  38. NCRC_CONTENT = 3, // frame content area (client area + scrollbars + clientedge)
  39. NCRC_MENUBAR = 4, // menubar rect
  40. // the following members should be in same sequence as eFRAMEPARTS
  41. NCRC_CAPTION = 5, // window frame caption segment
  42. NCRC_FRAMELEFT = 6, // window frame left segment
  43. NCRC_FRAMERIGHT = 7, // window frame right segment
  44. NCRC_FRAMEBOTTOM = 8,// window frame bottom segment
  45. #define NCRC_FRAMEFIRST NCRC_CAPTION
  46. #define NCRC_FRAMELAST NCRC_FRAMEBOTTOM
  47. NCRC_CAPTIONTEXT = 9,// caption text rect
  48. NCRC_CLIENTEDGE = 10,// client edge inner rect
  49. NCRC_HSCROLL = 11, // horizontal scrollbar
  50. NCRC_VSCROLL = 12, // vertical scrollbar
  51. NCRC_SIZEBOX = 13, // gripper box
  52. NCRC_SYSBTN = 14, // system button/icon
  53. // Standard frame button
  54. // (followed by identically ordered MDI frame buttons!!)
  55. #define NCBTNFIRST NCRC_CLOSEBTN
  56. NCRC_CLOSEBTN = 15, // close btn
  57. NCRC_MINBTN = 16, // minimize/restore button
  58. NCRC_MAXBTN = 17, // maximize/restore button
  59. NCRC_HELPBTN = 18, // help button
  60. #define NCBTNLAST NCRC_HELPBTN
  61. #define NCBTNRECTS ((NCBTNLAST - NCBTNFIRST)+1)
  62. // MDI frame buttons for maximized MDI child
  63. // (preceeded by identically ordered standard frame buttons!!)
  64. #define NCMDIBTNFIRST NCRC_MDICLOSEBTN
  65. NCRC_MDICLOSEBTN = 19,// MDI child close btn
  66. NCRC_MDIMINBTN = 20, // MDI child minimize/restore button
  67. NCRC_MDIMAXBTN = 21, // MDI child maximize/restore button
  68. NCRC_MDISYSBTN = 22, // MDI child system button/icon
  69. NCRC_MDIHELPBTN = 23, // MDI child help button
  70. #define NCMDIBTNLAST NCRC_MDIHELPBTN
  71. #define NCMDIBTNRECTS ((NCMDIBTNLAST- NCMDIBTNFIRST)+1)
  72. #ifdef LAME_BUTTON
  73. NCRC_LAMEBTN, // "Comments..." (formerly "Lame...") link.
  74. #endif LAME_BUTTON,
  75. NCRC_COUNT, // count of rectangles
  76. } eNCWNDMETRECT;
  77. //---------------------------------------------------------------------------
  78. // NCWNDMET::rgframeparts array indices
  79. typedef enum _eFRAMEPARTS
  80. {
  81. iCAPTION,
  82. iFRAMELEFT,
  83. iFRAMERIGHT,
  84. iFRAMEBOTTOM,
  85. cFRAMEPARTS,
  86. } eFRAMEPARTS;
  87. //---------------------------------------------------------------------------
  88. // nonclient window metrics
  89. typedef struct _NCWNDMET
  90. {
  91. //----------------------//
  92. // per-window metrics
  93. BOOL fValid; //
  94. BOOL fFrame; // WS_CAPTION style?
  95. BOOL fSmallFrame; // toolframe style?
  96. BOOL fMin; // minimized.
  97. BOOL fMaxed; // maximized
  98. BOOL fFullMaxed; // full-screen maximized or maximized child window.
  99. ULONG dwStyle; // WINDOWINFO::dwStyle
  100. ULONG dwExStyle; // WINDOWINFO::dwExStyle
  101. ULONG dwWindowStatus; // WINDOWINFO::dwWindowStatus
  102. ULONG dwStyleClass; // style class.
  103. WINDOWPARTS rgframeparts[cFRAMEPARTS]; // rendered frame parts
  104. WINDOWPARTS rgsizehitparts[cFRAMEPARTS]; // frame resizing border hit test template parts.
  105. FRAMESTATES framestate; // current frame & caption state
  106. HFONT hfCaption; // Font handle for dynamically resizing caption. This handle
  107. // is not owned by NCWNDMET, and should not be destroyed with it.
  108. COLORREF rgbCaption; // color of caption text.
  109. SIZE sizeCaptionText; // size of caption text
  110. MARGINS CaptionMargins; // Margins for in-frame caption
  111. int iMinButtonPart; // restore / minimize as appropriate
  112. int iMaxButtonPart; // restore / maximize as appropriate
  113. CLOSEBUTTONSTATES rawCloseBtnState; // zero-relative close button state. Final state must be computed using the MAKE_BTNSTATE macro.
  114. CLOSEBUTTONSTATES rawMinBtnState; // zero-relative min btnstate. Final state must be computed using the MAKE_BTNSTATE macro.
  115. CLOSEBUTTONSTATES rawMaxBtnState; // zero-relative max btnstate. Final state must be computed using the MAKE_BTNSTATE macro.
  116. int cyMenu; // return value of CalcMenuBar or Gsm(SM_CYMENUSIZE)
  117. int cnMenuOffsetLeft; // left menubar margin from window edge
  118. int cnMenuOffsetRight; // right menubar margin from window edge
  119. int cnMenuOffsetTop; // top menubar margin from window edge
  120. int cnBorders; // window border width, according to USER
  121. RECT rcS0[NCRC_COUNT]; // nonclient area component rects, screen relative coords
  122. RECT rcW0[NCRC_COUNT]; // nonclient area component rects, window relative coords
  123. } NCWNDMET, *PNCWNDMET;
  124. //---------------------------------------------------------------------------
  125. // nonclient part transparency bitfield
  126. typedef struct
  127. {
  128. BOOL fCaption : 1;
  129. BOOL fSmallCaption: 1;
  130. BOOL fMinCaption : 1;
  131. BOOL fSmallMinCaption : 1;
  132. BOOL fMaxCaption : 1;
  133. BOOL fSmallMaxCaption : 1;
  134. BOOL fFrameLeft : 1;
  135. BOOL fFrameRight : 1;
  136. BOOL fFrameBottom : 1;
  137. BOOL fSmFrameLeft : 1;
  138. BOOL fSmFrameRight : 1;
  139. BOOL fSmFrameBottom : 1;
  140. BOOL fReserved0 : 1;
  141. BOOL fReserved1 : 1;
  142. BOOL fReserved2 : 1;
  143. BOOL fReserved3 : 1;
  144. } NCTRANSPARENCY, *PNCTRANSPARENCY;
  145. //---------------------------------------------------------------------------
  146. // nonclient theme metrics
  147. typedef struct _NCTHEMEMET
  148. {
  149. HTHEME hTheme; // theme handle
  150. HTHEME hThemeTab; // tab's theme handle for "prop sheet" dialogs
  151. SIZE sizeMinimized; // size of minimized window
  152. BOOL fCapSizingTemplate:1; // has a caption sizing template
  153. BOOL fLeftSizingTemplate:1; // has a left frame sizing template
  154. BOOL fRightSizingTemplate:1; // has a frame right sizing template
  155. BOOL fBottomSizingTemplate:1; // has a frame bottom sizing template
  156. BOOL fSmCapSizingTemplate:1; // has a small caption sizing template
  157. BOOL fSmLeftSizingTemplate:1; // has a small left frame sizing template
  158. BOOL fSmRightSizingTemplate:1; // has a small frame right sizing template
  159. BOOL fSmBottomSizingTemplate:1;// has a small frame bottom sizing template
  160. MARGINS marCaptionText; // margin member values of {0,0,0,0} are interpreted as default
  161. MARGINS marMinCaptionText; // margin member values of {0,0,0,0} are interpreted as default
  162. MARGINS marMaxCaptionText; // margin member values of {0,0,0,0} are interpreted as default
  163. MARGINS marSmCaptionText; // margin member values of {0,0,0,0} are interpreted as default
  164. int dyMenuBar; // difference between SM_CYMENU and SM_CYMENUSIZE.
  165. int cyMaxCaption; // height of maximized window caption (for top/button caption only)
  166. int cnSmallMaximizedWidth; // width of maximized window caption (for left/right caption only)
  167. int cnSmallMaximizedHeight;// height of maximized window caption (for top/button caption only)
  168. SIZE sizeBtn; // size of normal nonclient button
  169. SIZE sizeSmBtn; // size of toolframe nonclient button
  170. HBRUSH hbrTabDialog; // brush for special tab dialogs
  171. HBITMAP hbmTabDialog; // must save the bitmap to keep the brush valid
  172. NCTRANSPARENCY nct; // cached transparency checks.
  173. struct {
  174. BOOL fValid;
  175. int cxBtn;
  176. int cxSmBtn;
  177. } theme_sysmets;
  178. } NCTHEMEMET, *PNCTHEMEMET;
  179. //---------------------------------------------------------------------------
  180. typedef struct _NCEVALUATE
  181. {
  182. // IN params:
  183. BOOL fIgnoreWndRgn;
  184. // CThemeWnd::_Evaluate OUT params:
  185. ULONG fClassFlags;
  186. ULONG dwStyle;
  187. ULONG dwExStyle;
  188. BOOL fExile;
  189. PVOID pvWndCompat; // optional
  190. } NCEVALUATE, *PNCEVALUATE;
  191. //---------------------------------------------------------------------------
  192. // nonclient theme metric API
  193. BOOL GetCurrentNcThemeMetrics( OUT NCTHEMEMET* pnctm );
  194. HTHEME GetCurrentNcThemeHandle();
  195. HRESULT AcquireNcThemeMetrics();
  196. BOOL IsValidNcThemeMetrics( NCTHEMEMET* pnctm );
  197. BOOL ThemeNcAdjustWindowRect( NCTHEMEMET* pnctm, LPCRECT prcSrc, LPCRECT prcDest, BOOL fWantClientRect );
  198. void InitNcThemeMetrics( NCTHEMEMET* pnctm = NULL );
  199. void ClearNcThemeMetrics( NCTHEMEMET* pnctm = NULL );
  200. //---------------------------------------------------------------------------
  201. typedef struct _NCPAINTOVERIDE
  202. {
  203. NCWNDMET* pncwm;
  204. NCTHEMEMET nctm;
  205. } NCPAINTOVERIDE, *PNCPAINTOVERIDE;
  206. //---------------------------------------------------------------------------
  207. class CMdiBtns;
  208. //---------------------------------------------------------------------------
  209. // Hook state flags
  210. #define HOOKSTATE_IN_DWP 0x00000001 // prevents Post-wndproc OWP from deleting the themewnd
  211. #define HOOKSTATE_DETACH_WINDOWDESTROY 0x00000002 // tags themewnd for detach on window death
  212. #define HOOKSTATE_DETACH_THEMEDESTROY 0x00000004 // tags themewnd for detach on theme death
  213. //---------------------------------------------------------------------------
  214. class CThemeWnd
  215. //---------------------------------------------------------------------------
  216. {
  217. public:
  218. // ref counting
  219. LONG AddRef();
  220. LONG Release();
  221. // access operators
  222. operator HWND() { return _hwnd; }
  223. operator HTHEME() { return _hTheme; }
  224. // theme object attach/detach methods
  225. static ULONG EvaluateWindowStyle( HWND hwnd );
  226. static ULONG EvaluateStyle( DWORD dwStyle, DWORD dwExStyle );
  227. static CThemeWnd* Attach( HWND hwnd, IN OUT OPTIONAL NCEVALUATE* pnce = NULL ); // attaches CThemeWnd instance from window
  228. static CThemeWnd* FromHwnd( HWND hwnd ); // Retrieves CThemeWnd instance from window
  229. static CThemeWnd* FromHdc( HDC hdc, int cScanAncestors = 0 ); // maximum number of ancestor windows to grock.
  230. static void Detach( HWND hwnd, DWORD dwDisposition ); // detaches CThemeWnd instance from window
  231. static void DetachAll( DWORD dwDisposition ); // detaches all CThemeWnd instances in the current process
  232. static void RemoveWindowProperties(HWND hwnd, BOOL fDestroying);
  233. static BOOL Reject( HWND hwnd, BOOL fExile );
  234. static BOOL Fail( HWND hwnd );
  235. BOOL Revoke(); // revokes theming on a themed window
  236. BOOL TestCF( ULONG fClassFlag ) const
  237. { return (_fClassFlags & fClassFlag) != 0; }
  238. // Theme state
  239. BOOL IsNcThemed();
  240. BOOL IsFrameThemed();
  241. // set/remove/change theme
  242. void SetFrameTheme( ULONG dwFlags, IN OPTIONAL WINDOWINFO* pwi );
  243. void RemoveFrameTheme( ULONG dwFlags );
  244. void ChangeTheme( THEME_MSG* ptm );
  245. #define FTF_CREATE 0x00000001 // 'soft' theme the window during creation sequence.
  246. #define FTF_REDRAW 0x00000010 // force frame redraw.
  247. #define FTF_NOMODIFYRGN 0x00000040 // don't touch window region.
  248. #define FTF_NOMODIFYPLACEMENT 0x00000080 // don't move the window
  249. // Theme revocation
  250. #define RF_NORMAL 0x00000001
  251. #define RF_REGION 0x00000002
  252. #define RF_TYPEMASK 0x0000FFFF
  253. #define RF_DEFER 0x00010000 // defer revocation until next WM_WINDOWPOSCHANGED
  254. #define RF_INREVOKE 0x00020000
  255. void SetRevokeFlags( ULONG dwFlags ) {_dwRevokeFlags = dwFlags;}
  256. DWORD GetRevokeFlags() const {return _dwRevokeFlags;}
  257. DWORD IsRevoked( IN OPTIONAL ULONG dwFlags = 0 ) const
  258. {return dwFlags ? TESTFLAG(_dwRevokeFlags, dwFlags) :
  259. TESTFLAG(_dwRevokeFlags, RF_TYPEMASK);}
  260. void EnterRevoke() {AddRef(); _dwRevokeFlags |= RF_INREVOKE;}
  261. void LeaveRevoke() {_dwRevokeFlags &= ~RF_INREVOKE; Release();}
  262. // NCPaint hooking:
  263. BOOL InNcPaint() const { return _cNcPaint != 0; }
  264. void EnterNcPaint() { _cNcPaint++; }
  265. void LeaveNcPaint() { _cNcPaint--; }
  266. BOOL InNcThemePaint() const { return _cNcThemePaint != 0; }
  267. void EnterNcThemePaint() { _cNcThemePaint++; }
  268. void LeaveNcThemePaint() { _cNcThemePaint--; }
  269. // window region state
  270. void SetDirtyFrameRgn( BOOL fDirty, BOOL fFrameChanged = FALSE );
  271. BOOL DirtyFrameRgn() const { return _fDirtyFrameRgn; }
  272. BOOL AssigningFrameRgn() const { return _fAssigningFrameRgn; }
  273. BOOL AssignedFrameRgn() const { return _fAssignedFrameRgn; }
  274. // window region management
  275. void AssignFrameRgn( BOOL fAssign, DWORD dwFlags );
  276. HRGN CreateCompositeRgn( IN const NCWNDMET* pncwm,
  277. OUT HRGN rghrgnParts[],
  278. OUT HRGN rghrgnTemplates[] /* arrays presumed cFRAMEPARTS in length */);
  279. // metrics/layout/state helpers.
  280. BOOL GetNcWindowMetrics( IN OPTIONAL LPCRECT prcWnd,
  281. OUT OPTIONAL NCWNDMET** ppncwm,
  282. OUT OPTIONAL NCTHEMEMET* pnctm,
  283. IN DWORD dwOptions );
  284. #define NCWMF_RECOMPUTE 0x00000001 // recompute values
  285. #define NCWMF_PREVIEW 0x00000002 // Only used for the preview forces recalculating of NCTHEMEMET
  286. void ReleaseNcWindowMetrics( IN NCWNDMET* pncwm );
  287. BOOL InThemeSettingChange() const {return _fInThemeSettingChange;}
  288. void EnterThemeSettingChange() {_fInThemeSettingChange = TRUE;}
  289. void LeaveThemeSettingChange() {_fInThemeSettingChange = FALSE;}
  290. UINT NcCalcMenuBar( int, int, int ); // user32!CalcMenuBar wrap
  291. void ScreenToWindow( LPPOINT prgPts, UINT cPts );
  292. void ScreenToWindowRect( LPRECT prc );
  293. // MDI frame state.
  294. void UpdateMDIFrameStuff( HWND hwndMDIClient, BOOL fSetMenu = FALSE );
  295. void ThemeMDIMenuButtons( BOOL fTheme, BOOL fRedraw );
  296. void ModifyMDIMenubar( BOOL fTheme, BOOL fRedraw );
  297. // hit testing and mouse tracking
  298. WORD NcBackgroundHitTest( POINT ptHit, LPCRECT prcWnd, DWORD dwStyle, DWORD dwExStyle, FRAMESTATES fs,
  299. const WINDOWPARTS rgiParts[],
  300. const WINDOWPARTS rgiTemplates[],
  301. const RECT rgrcParts[] /* all arrays presumed cFRAMEPARTS in length */);
  302. // determines whether the indicated button should be tracked on mouse events.
  303. BOOL ShouldTrackFrameButton( UINT uHitcode );
  304. // Track mouse on NC frame button; copies back appropriate syscmd (SC_) code and target window,
  305. // returns TRUE if tracking was handled, otherwise FALSE if default tracking is required.
  306. BOOL TrackFrameButton( IN HWND hwnd, IN INT uHitCode, OUT OPTIONAL WPARAM* puSysCmd,
  307. BOOL fHottrack = FALSE );
  308. // hot NC hittest identifier accessors
  309. int GetNcHotItem() { return _htHot; }
  310. void SetNcHotItem(int htHot) { _htHot = htHot; }
  311. // style change handling
  312. void StyleChanged( UINT iGWL, DWORD dwOld, DWORD dwNew );
  313. BOOL SuppressingStyleMsgs() { return _fSuppressStyleMsgs; }
  314. void SuppressStyleMsgs() { _fSuppressStyleMsgs = TRUE; }
  315. void AllowStyleMsgs() { _fSuppressStyleMsgs = FALSE; }
  316. // App icon management
  317. HICON AcquireFrameIcon( DWORD dwStyle, DWORD dwExStyle, BOOL fWinIniChange );
  318. void SetFrameIcon(HICON hIcon) { _hAppIcon = hIcon; }
  319. // non-client painting
  320. void NcPaint( IN OPTIONAL HDC hdc,
  321. IN ULONG dwFlags,
  322. IN OPTIONAL HRGN hrgnUpdate,
  323. IN OPTIONAL PNCPAINTOVERIDE pncpo );
  324. #define NCPF_DEFAULT 0x00000000
  325. #define NCPF_ACTIVEFRAME 0x00000001
  326. #define NCPF_INACTIVEFRAME 0x00000002
  327. #define DC_BACKGROUND 0x00010000
  328. #define DC_ENTIRECAPTION 0xFFFFFFFF
  329. void NcPaintCaption( IN HDC hdcOut,
  330. IN NCWNDMET* pncwm,
  331. IN BOOL fBuffered,
  332. IN OPTIONAL DWORD dwCaptionFlags = DC_ENTIRECAPTION,
  333. IN DTBGOPTS *pdtbopts = NULL );
  334. #define RNCF_CAPTION 0x00000001
  335. #define RNCF_SCROLLBAR 0x00000002
  336. #define RNCF_FRAME 0x00000004
  337. #define RNCF_ALL 0xFFFFFFFF
  338. BOOL HasRenderedNcPart( DWORD dwField ) const { return TESTFLAG(_dwRenderedNcParts, dwField); }
  339. void SetRenderedNcPart( DWORD dwField ) { _dwRenderedNcParts |= dwField; }
  340. void ClearRenderedNcPart( DWORD dwField ) { _dwRenderedNcParts &= ~dwField; }
  341. void LockRedraw( BOOL bLock ) { _cLockRedraw += (bLock ? 1 : -1); }
  342. BOOL HasProcessedEraseBk() { return _fProcessedEraseBk; }
  343. void ProcessedEraseBk(BOOL fProcessed) { _fProcessedEraseBk = fProcessed; }
  344. // Maxed MDI child button ownerdraw implementation
  345. HWND GetMDIClient() const { return _hwndMDIClient; }
  346. CMdiBtns* LoadMdiBtns( IN OPTIONAL HDC hdc, IN OPTIONAL UINT uSysCmd = 0 );
  347. void UnloadMdiBtns( IN OPTIONAL UINT uSysCmd = 0 );
  348. // resource management
  349. void InitWindowMetrics();
  350. // lame button support
  351. #ifdef LAME_BUTTON
  352. // ExStyles not defined by user
  353. #define WS_EX_LAMEBUTTONON 0x00000800L
  354. #define WS_EX_LAMEBUTTON 0x00008000L
  355. void ClearLameResources();
  356. void InitLameResources();
  357. void DrawLameButton(HDC hdc, IN const NCWNDMET* pncwm);
  358. void GetLameButtonMetrics( NCWNDMET* pncwm, const SIZE* psizeCaption );
  359. #else
  360. # define ClearLameResources()
  361. # define InitLameResources()
  362. # define DrawLameButton(hdc, pncwm)
  363. # define GetLameButtonMetrics(pncwm, psize)
  364. #endif // LAME_BUTTON
  365. // Debugging:
  366. #ifdef DEBUG
  367. void Spew( DWORD dwSpewFlags, LPCTSTR pszFmt, LPCTSTR pszWndClassList = NULL );
  368. static void SpewAll( DWORD dwSpewFlags, LPCTSTR pszFmt, LPCTSTR pszWndClassList = NULL );
  369. static void SpewLeaks();
  370. #endif DEBUG
  371. // CThemeWnd object-window association
  372. private:
  373. static ULONG _Evaluate( HWND hwnd, NCEVALUATE* pnce );
  374. static ULONG _EvaluateExclusions( HWND hwnd, NCEVALUATE* pnce );
  375. BOOL _AttachInstance( HWND hwnd, HTHEME hTheme, ULONG fTargetFlags, PVOID pvWndCompat );
  376. BOOL _DetachInstance( DWORD dwDisposition );
  377. void _CloseTheme();
  378. static BOOL CALLBACK _DetachDesktopWindowsCB( HWND hwnd, LPARAM dwProcessId );
  379. // Ctor, Dtor
  380. private: // auto-instantiated and deleted through friends
  381. CThemeWnd();
  382. ~CThemeWnd();
  383. // Misc private methods
  384. private:
  385. static BOOL _PostWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  386. static BOOL _PostDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  387. static BOOL _PreDefWindowProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  388. static HTHEME _AcquireThemeHandle( HWND hwnd, IN OUT ULONG *pfClassFlags );
  389. void _AssignRgn( HRGN hrgn, DWORD dwFlags );
  390. void _FreeRegionHandles();
  391. // Private data
  392. private:
  393. CHAR _szHead[9]; // header signature used for object validation
  394. HWND _hwnd;
  395. LONG _cRef; // ref count.
  396. HTHEME _hTheme; // theme handle
  397. DWORD _dwRenderedNcParts; // mask of the NC elements we've drawn, to decide if we should track them
  398. ULONG _dwRevokeFlags; // theme revoke flags
  399. ULONG _fClassFlags; // theming class flag bits
  400. NCWNDMET _ncwm; // per-window metrics
  401. HICON _hAppIcon; // application's icon
  402. HRGN _hrgnWnd; // cached window region.
  403. HRGN _rghrgnParts[cFRAMEPARTS]; // cached nc component subregions.
  404. HRGN _rghrgnSizingTemplates[cFRAMEPARTS]; // cached nc frame resizing hittest template subregions.
  405. BOOL _fDirtyFrameRgn; // State flag: window region needs updating.
  406. BOOL _fFrameThemed; // SetFrameTheme() has been invoked on a valid frame window
  407. BOOL _fAssigningFrameRgn;// SetWindowRgn state flag.
  408. BOOL _fAssignedFrameRgn; // Region state flag
  409. BOOL _fSuppressStyleMsgs; // Suppress style change messages to arrive at the WndProc
  410. BOOL _fProcessedEraseBk;
  411. BOOL _fInThemeSettingChange; // window is being sent a theme setting change message.
  412. BOOL _fDetached; // Detached object; leave it alone!
  413. BOOL _fThemedMDIBtns; // MDI menubar buttons have been themed-rendered.
  414. BOOL _fCritSectsInit; // critical section(s) have been initialize
  415. HWND _hwndMDIClient; // MDICLIENT child window.
  416. int _cLockRedraw; // paint lock reference count.
  417. int _cNcPaint; // NCPAINT message ref count
  418. int _cNcThemePaint; // Indicator: we're painting the nonclient area.
  419. SIZE _sizeRgn; // window rgn size.
  420. int _htHot; // hittest code of the current hot NC element
  421. CMdiBtns* _pMdiBtns;
  422. CRITICAL_SECTION _cswm; // serializes access to _ncwm.
  423. #ifdef DEBUG_THEMEWND_DESTRUCTOR
  424. BOOL _fDestructed; // destructor has been called.
  425. BOOL _fDeleteCritsec; // deleted WNDMET critsec
  426. #endif DEBUG_THEMEWND_DESTRUCTOR
  427. #ifdef LAME_BUTTON
  428. HFONT _hFontLame; // font used to draw the lame button text
  429. SIZE _sizeLame; // the text extent of the lame text
  430. #endif // LAME_BUTTON
  431. static LONG _cObj; // instance count
  432. #ifdef DEBUG
  433. public:
  434. TCHAR _szCaption[MAX_PATH];
  435. TCHAR _szWndClass[MAX_PATH];
  436. #endif DEBUG
  437. CHAR _szTail[4]; // tail signature used for object validation
  438. // Message tracking
  439. public:
  440. // Friends
  441. friend LRESULT _ThemeDefWindowProc( HWND, UINT, WPARAM, LPARAM, BOOL );
  442. friend BOOL ThemePreWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  443. friend BOOL ThemePostWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  444. friend BOOL ThemePreDefDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  445. friend BOOL ThemePrePostDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  446. friend BOOL ThemePostDefDlgProc(HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID**);
  447. };
  448. //------------------------------------------ -------------------------------//
  449. // forwards:
  450. // Internal sysmet wrappers. These functions can be more efficient than
  451. // calling through USER32, and support theme preview functionality.
  452. int NcGetSystemMetrics(int);
  453. BOOL NcGetNonclientMetrics( OUT OPTIONAL NONCLIENTMETRICS* pncm, BOOL fRefresh = FALSE );
  454. void NcClearNonclientMetrics();
  455. HFONT NcGetCaptionFont( BOOL fSmallCaption );
  456. HWND NcPaintWindow_Find(); // retrieves window in current thread that is processing NCPAINT
  457. //
  458. void PrintClientNotHandled(HWND hwnd);
  459. // hook function workers
  460. int _InternalGetSystemMetrics( int, BOOL& fHandled );
  461. BOOL _InternalSystemParametersInfo( UINT, UINT, PVOID, UINT, BOOL fUnicode, BOOL& fHandled );
  462. //------------------------------------------ -------------------------------//
  463. /// debug spew
  464. #define NCTF_THEMEWND 0x00000001
  465. #define NCTF_AWR 0x00000002 // ThemeAdjustWindowRectEx vs Calcsize
  466. #define NCTF_SETFRAMETHEME 0x00000004 //
  467. #define NCTF_CALCWNDPOS 0x00000008 // WM_NCCALCSIZE, WM_WINDOWPOSCHANGED.
  468. #define NCTF_RGNWND 0x00000010 // region window debugging
  469. #define NCTF_MDIBUTTONS 0x00000020 // region window debugging
  470. #define NCTF_NCPAINT 0x00000040 // debug painting
  471. #define NCTF_SYSMETS 0x00000080 // system metrics calls
  472. #define NCTF_ALWAYS 0xFFFFFFFF // always trace
  473. #ifdef DEBUG
  474. void CDECL _NcTraceMsg( ULONG uFlags, LPCTSTR pszFmt, ...);
  475. void INIT_THEMEWND_DBG( CThemeWnd* pwnd );
  476. void SPEW_RECT( ULONG ulTrace, LPCTSTR pszMsg, LPCRECT prc );
  477. void SPEW_MARGINS( ULONG ulTrace, LPCTSTR pszMsg, LPCRECT prcParent, LPCRECT prcChild );
  478. void SPEW_RGNRECT( ULONG ulTrace, LPCTSTR pszMsg, HRGN hrgn, int iPartID );
  479. void SPEW_WINDOWINFO( ULONG ulTrace, WINDOWINFO* );
  480. void SPEW_NCWNDMET( ULONG ulTrace, LPCTSTR, NCWNDMET* );
  481. void SPEW_SCROLLINFO( ULONG ulTrace, LPCTSTR pszMsg, HWND hwnd, LPCSCROLLINFO psi );
  482. void SPEW_THEMEMSG( ULONG ulTrace, LPCTSTR pszMsg, THEME_MSG* ptm );
  483. # define SPEW_THEMEWND(pwnd,dwFlags,txt,classlist) (pwnd)->Spew( dwFlags, txt, classlist )
  484. # define SPEW_THEMEWND_LEAKS(pwnd) (pwnd)->SpewLeaks()
  485. #else // DEBUG
  486. inline void CDECL _NcTraceMsg( ULONG uFlags, LPCTSTR pszFmt, ...) {}
  487. # define INIT_THEMEWND_DBG( pwnd );
  488. # define SPEW_RECT( ulTrace, pszMsg, prc )
  489. # define SPEW_MARGINS( ulTrace, pszMsg, prcParent, prcChild )
  490. # define SPEW_RGNRECT( ulTrace, pszMsg, hrgn, iPartID )
  491. # define SPEW_WINDOWINFO( ulTrace, pwi )
  492. # define SPEW_NCWNDMET( ulTrace, pszMsg, pncwm )
  493. # define SPEW_SCROLLINFO( ulTrace, pszMsg, hwnd, psi )
  494. # define SPEW_THEMEMSG( ulTrace, pszMsg, ptm )
  495. # define SPEW_THEMEWND(pwnd,dwFlags,txt,classlist) (pwnd)->Spew( dwFlags, txt, classlist )
  496. # define SPEW_THEMEWND_LEAKS(pwnd) (pwnd)->SpewLeaks()
  497. #endif // DEBUG
  498. #endif __NC_THEME_H__