Leaked source code of windows server 2003
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.

584 lines
28 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. HRESULT AcquireNcThemeMetrics();
  195. BOOL IsValidNcThemeMetrics( NCTHEMEMET* pnctm );
  196. BOOL ThemeNcAdjustWindowRect( NCTHEMEMET* pnctm, LPCRECT prcSrc, LPCRECT prcDest, BOOL fWantClientRect );
  197. void InitNcThemeMetrics( NCTHEMEMET* pnctm = NULL );
  198. void ClearNcThemeMetrics( NCTHEMEMET* pnctm = NULL );
  199. //---------------------------------------------------------------------------
  200. typedef struct _NCPAINTOVERIDE
  201. {
  202. NCWNDMET* pncwm;
  203. NCTHEMEMET nctm;
  204. } NCPAINTOVERIDE, *PNCPAINTOVERIDE;
  205. //---------------------------------------------------------------------------
  206. class CMdiBtns;
  207. //---------------------------------------------------------------------------
  208. // Hook state flags
  209. #define HOOKSTATE_IN_DWP 0x00000001 // prevents Post-wndproc OWP from deleting the themewnd
  210. #define HOOKSTATE_DETACH_WINDOWDESTROY 0x00000002 // tags themewnd for detach on window death
  211. #define HOOKSTATE_DETACH_THEMEDESTROY 0x00000004 // tags themewnd for detach on theme death
  212. //---------------------------------------------------------------------------
  213. class CThemeWnd
  214. //---------------------------------------------------------------------------
  215. {
  216. public:
  217. // ref counting
  218. LONG AddRef();
  219. LONG Release();
  220. // access operators
  221. operator HWND() { return _hwnd; }
  222. operator HTHEME() { return _hTheme; }
  223. // theme object attach/detach methods
  224. static ULONG EvaluateWindowStyle( HWND hwnd );
  225. static ULONG EvaluateStyle( DWORD dwStyle, DWORD dwExStyle );
  226. static CThemeWnd* Attach( HWND hwnd, IN OUT OPTIONAL NCEVALUATE* pnce = NULL ); // attaches CThemeWnd instance from window
  227. static CThemeWnd* FromHwnd( HWND hwnd ); // Retrieves CThemeWnd instance from window
  228. static CThemeWnd* FromHdc( HDC hdc, int cScanAncestors = 0 ); // maximum number of ancestor windows to grock.
  229. static void Detach( HWND hwnd, DWORD dwDisposition ); // detaches CThemeWnd instance from window
  230. static void DetachAll( DWORD dwDisposition ); // detaches all CThemeWnd instances in the current process
  231. static void RemoveWindowProperties(HWND hwnd, BOOL fDestroying);
  232. static BOOL Reject( HWND hwnd, BOOL fExile );
  233. static BOOL Fail( HWND hwnd );
  234. BOOL Revoke(); // revokes theming on a themed window
  235. BOOL TestCF( ULONG fClassFlag ) const
  236. { return (_fClassFlags & fClassFlag) != 0; }
  237. // Theme state
  238. BOOL IsNcThemed();
  239. BOOL IsFrameThemed();
  240. // set/remove/change theme
  241. void SetFrameTheme( ULONG dwFlags, IN OPTIONAL WINDOWINFO* pwi );
  242. void RemoveFrameTheme( ULONG dwFlags );
  243. void ChangeTheme( THEME_MSG* ptm );
  244. #define FTF_CREATE 0x00000001 // 'soft' theme the window during creation sequence.
  245. #define FTF_REDRAW 0x00000010 // force frame redraw.
  246. #define FTF_NOMODIFYRGN 0x00000040 // don't touch window region.
  247. #define FTF_NOMODIFYPLACEMENT 0x00000080 // don't move the window
  248. // Theme revocation
  249. #define RF_NORMAL 0x00000001
  250. #define RF_REGION 0x00000002
  251. #define RF_TYPEMASK 0x0000FFFF
  252. #define RF_DEFER 0x00010000 // defer revocation until next WM_WINDOWPOSCHANGED
  253. #define RF_INREVOKE 0x00020000
  254. void SetRevokeFlags( ULONG dwFlags ) {_dwRevokeFlags = dwFlags;}
  255. DWORD GetRevokeFlags() const {return _dwRevokeFlags;}
  256. DWORD IsRevoked( IN OPTIONAL ULONG dwFlags = 0 ) const
  257. {return dwFlags ? TESTFLAG(_dwRevokeFlags, dwFlags) :
  258. TESTFLAG(_dwRevokeFlags, RF_TYPEMASK);}
  259. void EnterRevoke() {AddRef(); _dwRevokeFlags |= RF_INREVOKE;}
  260. void LeaveRevoke() {_dwRevokeFlags &= ~RF_INREVOKE; Release();}
  261. // NCPaint hooking:
  262. BOOL InNcPaint() const { return _cNcPaint != 0; }
  263. void EnterNcPaint() { _cNcPaint++; }
  264. void LeaveNcPaint() { _cNcPaint--; }
  265. BOOL InNcThemePaint() const { return _cNcThemePaint != 0; }
  266. void EnterNcThemePaint() { _cNcThemePaint++; }
  267. void LeaveNcThemePaint() { _cNcThemePaint--; }
  268. // window region state
  269. void SetDirtyFrameRgn( BOOL fDirty, BOOL fFrameChanged = FALSE );
  270. BOOL DirtyFrameRgn() const { return _fDirtyFrameRgn; }
  271. BOOL AssigningFrameRgn() const { return _fAssigningFrameRgn; }
  272. BOOL AssignedFrameRgn() const { return _fAssignedFrameRgn; }
  273. // window region management
  274. void AssignFrameRgn( BOOL fAssign, DWORD dwFlags );
  275. HRGN CreateCompositeRgn( IN const NCWNDMET* pncwm,
  276. OUT HRGN rghrgnParts[],
  277. OUT HRGN rghrgnTemplates[] /* arrays presumed cFRAMEPARTS in length */);
  278. // metrics/layout/state helpers.
  279. BOOL GetNcWindowMetrics( IN OPTIONAL LPCRECT prcWnd,
  280. OUT OPTIONAL NCWNDMET** ppncwm,
  281. OUT OPTIONAL NCTHEMEMET* pnctm,
  282. IN DWORD dwOptions );
  283. #define NCWMF_RECOMPUTE 0x00000001 // recompute values
  284. #define NCWMF_PREVIEW 0x00000002 // Only used for the preview forces recalculating of NCTHEMEMET
  285. BOOL InThemeSettingChange() const {return _fInThemeSettingChange;}
  286. void EnterThemeSettingChange() {_fInThemeSettingChange = TRUE;}
  287. void LeaveThemeSettingChange() {_fInThemeSettingChange = FALSE;}
  288. UINT NcCalcMenuBar( int, int, int ); // user32!CalcMenuBar wrap
  289. void ScreenToWindow( LPPOINT prgPts, UINT cPts );
  290. void ScreenToWindowRect( LPRECT prc );
  291. // MDI frame state.
  292. void UpdateMDIFrameStuff( HWND hwndMDIClient, BOOL fSetMenu = FALSE );
  293. void ThemeMDIMenuButtons( BOOL fTheme, BOOL fRedraw );
  294. void ModifyMDIMenubar( BOOL fTheme, BOOL fRedraw );
  295. // hit testing and mouse tracking
  296. WORD NcBackgroundHitTest( POINT ptHit, LPCRECT prcWnd, DWORD dwStyle, DWORD dwExStyle, FRAMESTATES fs,
  297. const WINDOWPARTS rgiParts[],
  298. const WINDOWPARTS rgiTemplates[],
  299. const RECT rgrcParts[] /* all arrays presumed cFRAMEPARTS in length */);
  300. // determines whether the indicated button should be tracked on mouse events.
  301. BOOL ShouldTrackFrameButton( UINT uHitcode );
  302. // Track mouse on NC frame button; copies back appropriate syscmd (SC_) code and target window,
  303. // returns TRUE if tracking was handled, otherwise FALSE if default tracking is required.
  304. BOOL TrackFrameButton( IN HWND hwnd, IN INT uHitCode, OUT OPTIONAL WPARAM* puSysCmd,
  305. BOOL fHottrack = FALSE );
  306. // hot NC hittest identifier accessors
  307. int GetNcHotItem() { return _htHot; }
  308. void SetNcHotItem(int htHot) { _htHot = htHot; }
  309. // style change handling
  310. void StyleChanged( UINT iGWL, DWORD dwOld, DWORD dwNew );
  311. BOOL SuppressingStyleMsgs() { return _fSuppressStyleMsgs; }
  312. void SuppressStyleMsgs() { _fSuppressStyleMsgs = TRUE; }
  313. void AllowStyleMsgs() { _fSuppressStyleMsgs = FALSE; }
  314. // App icon management
  315. HICON AcquireFrameIcon( DWORD dwStyle, DWORD dwExStyle, BOOL fWinIniChange );
  316. void SetFrameIcon(HICON hIcon) { _hAppIcon = hIcon; }
  317. // non-client painting
  318. void NcPaint( IN OPTIONAL HDC hdc,
  319. IN ULONG dwFlags,
  320. IN OPTIONAL HRGN hrgnUpdate,
  321. IN OPTIONAL PNCPAINTOVERIDE pncpo );
  322. #define NCPF_DEFAULT 0x00000000
  323. #define NCPF_ACTIVEFRAME 0x00000001
  324. #define NCPF_INACTIVEFRAME 0x00000002
  325. #define DC_BACKGROUND 0x00010000
  326. #define DC_ENTIRECAPTION 0xFFFFFFFF
  327. void NcPaintCaption( IN HDC hdcOut,
  328. IN NCWNDMET* pncwm,
  329. IN BOOL fBuffered,
  330. IN OPTIONAL DWORD dwCaptionFlags = DC_ENTIRECAPTION,
  331. IN DTBGOPTS *pdtbopts = NULL );
  332. #define RNCF_CAPTION 0x00000001
  333. #define RNCF_SCROLLBAR 0x00000002
  334. #define RNCF_FRAME 0x00000004
  335. #define RNCF_ALL 0xFFFFFFFF
  336. BOOL HasRenderedNcPart( DWORD dwField ) const { return TESTFLAG(_dwRenderedNcParts, dwField); }
  337. void SetRenderedNcPart( DWORD dwField ) { _dwRenderedNcParts |= dwField; }
  338. void ClearRenderedNcPart( DWORD dwField ) { _dwRenderedNcParts &= ~dwField; }
  339. void LockRedraw( BOOL bLock ) { _cLockRedraw += (bLock ? 1 : -1); }
  340. BOOL HasProcessedEraseBk() { return _fProcessedEraseBk; }
  341. void ProcessedEraseBk(BOOL fProcessed) { _fProcessedEraseBk = fProcessed; }
  342. // Maxed MDI child button ownerdraw implementation
  343. HWND GetMDIClient() const { return _hwndMDIClient; }
  344. CMdiBtns* LoadMdiBtns( IN OPTIONAL HDC hdc, IN OPTIONAL UINT uSysCmd = 0 );
  345. void UnloadMdiBtns( IN OPTIONAL UINT uSysCmd = 0 );
  346. // resource management
  347. void InitWindowMetrics();
  348. // lame button support
  349. #ifdef LAME_BUTTON
  350. // ExStyles not defined by user
  351. #define WS_EX_LAMEBUTTONON 0x00000800L
  352. #define WS_EX_LAMEBUTTON 0x00008000L
  353. void ClearLameResources();
  354. void InitLameResources();
  355. void DrawLameButton(HDC hdc, IN const NCWNDMET* pncwm);
  356. void GetLameButtonMetrics( NCWNDMET* pncwm, const SIZE* psizeCaption );
  357. #else
  358. # define ClearLameResources()
  359. # define InitLameResources()
  360. # define DrawLameButton(hdc, pncwm)
  361. # define GetLameButtonMetrics(pncwm, psize)
  362. #endif // LAME_BUTTON
  363. // Debugging:
  364. #ifdef DEBUG
  365. void Spew( DWORD dwSpewFlags, LPCTSTR pszFmt, LPCTSTR pszWndClassList = NULL );
  366. static void SpewAll( DWORD dwSpewFlags, LPCTSTR pszFmt, LPCTSTR pszWndClassList = NULL );
  367. static void SpewLeaks();
  368. #endif DEBUG
  369. // CThemeWnd object-window association
  370. private:
  371. static ULONG _Evaluate( HWND hwnd, NCEVALUATE* pnce );
  372. static ULONG _EvaluateExclusions( HWND hwnd, NCEVALUATE* pnce );
  373. BOOL _AttachInstance( HWND hwnd, HTHEME hTheme, ULONG fTargetFlags, PVOID pvWndCompat );
  374. BOOL _DetachInstance( DWORD dwDisposition );
  375. void _CloseTheme();
  376. static BOOL CALLBACK _DetachDesktopWindowsCB( HWND hwnd, LPARAM dwProcessId );
  377. // Ctor, Dtor
  378. private: // auto-instantiated and deleted through friends
  379. CThemeWnd();
  380. ~CThemeWnd();
  381. // Misc private methods
  382. private:
  383. static BOOL _PostWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  384. static BOOL _PostDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  385. static BOOL _PreDefWindowProc( HWND, UINT, WPARAM, LPARAM, LRESULT* );
  386. static HTHEME _AcquireThemeHandle( HWND hwnd, IN OUT ULONG *pfClassFlags );
  387. void _AssignRgn( HRGN hrgn, DWORD dwFlags );
  388. void _FreeRegionHandles();
  389. // Private data
  390. private:
  391. CHAR _szHead[9]; // header signature used for object validation
  392. HWND _hwnd;
  393. LONG _cRef; // ref count.
  394. HTHEME _hTheme; // theme handle
  395. DWORD _dwRenderedNcParts; // mask of the NC elements we've drawn, to decide if we should track them
  396. ULONG _dwRevokeFlags; // theme revoke flags
  397. ULONG _fClassFlags; // theming class flag bits
  398. NCWNDMET _ncwm; // per-window metrics
  399. HICON _hAppIcon; // application's icon
  400. HRGN _hrgnWnd; // cached window region.
  401. HRGN _rghrgnParts[cFRAMEPARTS]; // cached nc component subregions.
  402. HRGN _rghrgnSizingTemplates[cFRAMEPARTS]; // cached nc frame resizing hittest template subregions.
  403. BOOL _fDirtyFrameRgn; // State flag: window region needs updating.
  404. BOOL _fFrameThemed; // SetFrameTheme() has been invoked on a valid frame window
  405. BOOL _fAssigningFrameRgn;// SetWindowRgn state flag.
  406. BOOL _fAssignedFrameRgn; // Region state flag
  407. BOOL _fSuppressStyleMsgs; // Suppress style change messages to arrive at the WndProc
  408. BOOL _fProcessedEraseBk;
  409. BOOL _fInThemeSettingChange; // window is being sent a theme setting change message.
  410. BOOL _fDetached; // Detached object; leave it alone!
  411. BOOL _fThemedMDIBtns; // MDI menubar buttons have been themed-rendered.
  412. HWND _hwndMDIClient; // MDICLIENT child window.
  413. int _cLockRedraw; // paint lock reference count.
  414. int _cNcPaint; // NCPAINT message ref count
  415. int _cNcThemePaint; // Indicator: we're painting the nonclient area.
  416. SIZE _sizeRgn; // window rgn size.
  417. int _htHot; // hittest code of the current hot NC element
  418. CMdiBtns* _pMdiBtns;
  419. CRITICAL_SECTION _cswm; // serializes access to _ncwm.
  420. #ifdef LAME_BUTTON
  421. HFONT _hFontLame; // font used to draw the lame button text
  422. SIZE _sizeLame; // the text extent of the lame text
  423. #endif // LAME_BUTTON
  424. static LONG _cObj; // instance count
  425. #ifdef DEBUG
  426. public:
  427. TCHAR _szCaption[MAX_PATH];
  428. TCHAR _szWndClass[MAX_PATH];
  429. #endif DEBUG
  430. CHAR _szTail[4]; // tail signature used for object validation
  431. // Message tracking
  432. public:
  433. // Friends
  434. friend LRESULT _ThemeDefWindowProc( HWND, UINT, WPARAM, LPARAM, BOOL );
  435. friend BOOL ThemePreWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  436. friend BOOL ThemePostWndProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  437. friend BOOL ThemePreDefDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  438. friend BOOL ThemePrePostDlgProc( HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID** );
  439. friend BOOL ThemePostDefDlgProc(HWND, UINT, WPARAM, LPARAM, LRESULT*, VOID**);
  440. };
  441. //-------------------------------------------------------------------------//
  442. // public variables.
  443. extern CRITICAL_SECTION _csThemeMet; // protects access to _nctmCurrent in nctheme.cpp
  444. extern CRITICAL_SECTION _csNcSysMet; // protects access to _ncmCurrent in nctheme.cpp
  445. extern CRITICAL_SECTION _csNcPaint; // protects thread-in-NCPAINT collection
  446. //-------------------------------------------------------------------------//
  447. // forwards:
  448. // Internal sysmet wrappers. These functions can be more efficient than
  449. // calling through USER32, and support theme preview functionality.
  450. int NcGetSystemMetrics(int);
  451. BOOL NcGetNonclientMetrics( OUT OPTIONAL NONCLIENTMETRICS* pncm, BOOL fRefresh = FALSE );
  452. void NcClearNonclientMetrics();
  453. HFONT NcGetCaptionFont( BOOL fSmallCaption );
  454. HWND NcPaintWindow_Find(); // retrieves window in current thread that is processing NCPAINT
  455. //
  456. void PrintClientNotHandled(HWND hwnd);
  457. // hook function workers
  458. int _InternalGetSystemMetrics( int, BOOL& fHandled );
  459. BOOL _InternalSystemParametersInfo( UINT, UINT, PVOID, UINT, BOOL fUnicode, BOOL& fHandled );
  460. //------------------------------------------ -------------------------------//
  461. /// debug spew
  462. #define NCTF_THEMEWND 0x00000001
  463. #define NCTF_AWR 0x00000002 // ThemeAdjustWindowRectEx vs Calcsize
  464. #define NCTF_SETFRAMETHEME 0x00000004 //
  465. #define NCTF_CALCWNDPOS 0x00000008 // WM_NCCALCSIZE, WM_WINDOWPOSCHANGED.
  466. #define NCTF_RGNWND 0x00000010 // region window debugging
  467. #define NCTF_MDIBUTTONS 0x00000020 // region window debugging
  468. #define NCTF_NCPAINT 0x00000040 // debug painting
  469. #define NCTF_SYSMETS 0x00000080 // system metrics calls
  470. #define NCTF_ALWAYS 0xFFFFFFFF // always trace
  471. #ifdef DEBUG
  472. void CDECL _NcTraceMsg( ULONG uFlags, LPCTSTR pszFmt, ...);
  473. void INIT_THEMEWND_DBG( CThemeWnd* pwnd );
  474. void SPEW_RECT( ULONG ulTrace, LPCTSTR pszMsg, LPCRECT prc );
  475. void SPEW_MARGINS( ULONG ulTrace, LPCTSTR pszMsg, LPCRECT prcParent, LPCRECT prcChild );
  476. void SPEW_RGNRECT( ULONG ulTrace, LPCTSTR pszMsg, HRGN hrgn, int iPartID );
  477. void SPEW_WINDOWINFO( ULONG ulTrace, WINDOWINFO* );
  478. void SPEW_NCWNDMET( ULONG ulTrace, LPCTSTR, NCWNDMET* );
  479. void SPEW_SCROLLINFO( ULONG ulTrace, LPCTSTR pszMsg, HWND hwnd, LPCSCROLLINFO psi );
  480. void SPEW_THEMEMSG( ULONG ulTrace, LPCTSTR pszMsg, THEME_MSG* ptm );
  481. # define SPEW_THEMEWND(pwnd,dwFlags,txt,classlist) (pwnd)->Spew( dwFlags, txt, classlist )
  482. # define SPEW_THEMEWND_LEAKS(pwnd) (pwnd)->SpewLeaks()
  483. #else // DEBUG
  484. inline void CDECL _NcTraceMsg( ULONG uFlags, LPCTSTR pszFmt, ...) {}
  485. # define INIT_THEMEWND_DBG( pwnd );
  486. # define SPEW_RECT( ulTrace, pszMsg, prc )
  487. # define SPEW_MARGINS( ulTrace, pszMsg, prcParent, prcChild )
  488. # define SPEW_RGNRECT( ulTrace, pszMsg, hrgn, iPartID )
  489. # define SPEW_WINDOWINFO( ulTrace, pwi )
  490. # define SPEW_NCWNDMET( ulTrace, pszMsg, pncwm )
  491. # define SPEW_SCROLLINFO( ulTrace, pszMsg, hwnd, psi )
  492. # define SPEW_THEMEMSG( ulTrace, pszMsg, ptm )
  493. # define SPEW_THEMEWND(pwnd,dwFlags,txt,classlist) (pwnd)->Spew( dwFlags, txt, classlist )
  494. # define SPEW_THEMEWND_LEAKS(pwnd) (pwnd)->SpewLeaks()
  495. #endif // DEBUG
  496. #endif __NC_THEME_H__