diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2020-07-05 17:15:43 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-07-06 21:30:49 +1000 |
commit | e586152b76d62dbf38cd2882819e23eee2e0af7f (patch) | |
tree | 0f808be54beae359aca40a68050ffcbb7cb56b5e | |
parent | 3afdaa298c9bd341c04472a739f2b28ac8c577ca (diff) | |
download | wix-e586152b76d62dbf38cd2882819e23eee2e0af7f.tar.gz wix-e586152b76d62dbf38cd2882819e23eee2e0af7f.tar.bz2 wix-e586152b76d62dbf38cd2882819e23eee2e0af7f.zip |
Add ThemeCreateParentWindow so thmutil controls its window creation.
-rw-r--r-- | src/dutil/inc/thmutil.h | 22 | ||||
-rw-r--r-- | src/dutil/thmutil.cpp | 82 |
2 files changed, 90 insertions, 14 deletions
diff --git a/src/dutil/inc/thmutil.h b/src/dutil/inc/thmutil.h index 4d52fa69..e661a6cb 100644 --- a/src/dutil/inc/thmutil.h +++ b/src/dutil/inc/thmutil.h | |||
@@ -354,12 +354,30 @@ HRESULT DAPI ThemeRegisterVariableCallbacks( | |||
354 | ); | 354 | ); |
355 | 355 | ||
356 | /******************************************************************** | 356 | /******************************************************************** |
357 | ThemeLoadControls - creates the windows for all the theme controls. | 357 | ThemeCreateParentWindow - creates a parent window for the theme. |
358 | |||
359 | *******************************************************************/ | ||
360 | HRESULT DAPI ThemeCreateParentWindow( | ||
361 | __in THEME* pTheme, | ||
362 | __in DWORD dwExStyle, | ||
363 | __in LPCWSTR szClassName, | ||
364 | __in LPCWSTR szWindowName, | ||
365 | __in DWORD dwStyle, | ||
366 | __in int x, | ||
367 | __in int y, | ||
368 | __in_opt HWND hwndParent, | ||
369 | __in_opt HINSTANCE hInstance, | ||
370 | __in_opt LPVOID lpParam, | ||
371 | __out_opt HWND* phWnd | ||
372 | ); | ||
373 | |||
374 | /******************************************************************** | ||
375 | ThemeLoadControls - creates the windows for all the theme controls | ||
376 | using the window created in ThemeCreateParentWindow. | ||
358 | 377 | ||
359 | *******************************************************************/ | 378 | *******************************************************************/ |
360 | HRESULT DAPI ThemeLoadControls( | 379 | HRESULT DAPI ThemeLoadControls( |
361 | __in THEME* pTheme, | 380 | __in THEME* pTheme, |
362 | __in HWND hwndParent, | ||
363 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, | 381 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, |
364 | __in DWORD cAssignControlIds | 382 | __in DWORD cAssignControlIds |
365 | ); | 383 | ); |
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp index 1939c64d..2050b420 100644 --- a/src/dutil/thmutil.cpp +++ b/src/dutil/thmutil.cpp | |||
@@ -17,6 +17,7 @@ | |||
17 | #define ThmExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_THMUTIL, e, x, s, __VA_ARGS__) | 17 | #define ThmExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_THMUTIL, e, x, s, __VA_ARGS__) |
18 | #define ThmExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_THMUTIL, g, x, s, __VA_ARGS__) | 18 | #define ThmExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_THMUTIL, g, x, s, __VA_ARGS__) |
19 | 19 | ||
20 | // from CommCtrl.h | ||
20 | #ifndef BS_COMMANDLINK | 21 | #ifndef BS_COMMANDLINK |
21 | #define BS_COMMANDLINK 0x0000000EL | 22 | #define BS_COMMANDLINK 0x0000000EL |
22 | #endif | 23 | #endif |
@@ -184,7 +185,6 @@ static HRESULT FindImageList( | |||
184 | static HRESULT LoadControls( | 185 | static HRESULT LoadControls( |
185 | __in THEME* pTheme, | 186 | __in THEME* pTheme, |
186 | __in_opt THEME_CONTROL* pParentControl, | 187 | __in_opt THEME_CONTROL* pParentControl, |
187 | __in HWND hwndParent, | ||
188 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, | 188 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, |
189 | __in DWORD cAssignControlIds | 189 | __in DWORD cAssignControlIds |
190 | ); | 190 | ); |
@@ -287,6 +287,11 @@ static BOOL OnButtonClicked( | |||
287 | __in HWND hWnd, | 287 | __in HWND hWnd, |
288 | __in const THEME_CONTROL* pControl | 288 | __in const THEME_CONTROL* pControl |
289 | ); | 289 | ); |
290 | static void OnNcCreate( | ||
291 | __in THEME* pTheme, | ||
292 | __in HWND hWnd, | ||
293 | __in LPARAM lParam | ||
294 | ); | ||
290 | static HRESULT OnRichEditEnLink( | 295 | static HRESULT OnRichEditEnLink( |
291 | __in LPARAM lParam, | 296 | __in LPARAM lParam, |
292 | __in HWND hWndRichEdit, | 297 | __in HWND hWndRichEdit, |
@@ -553,14 +558,60 @@ LExit: | |||
553 | } | 558 | } |
554 | 559 | ||
555 | 560 | ||
561 | DAPI_(HRESULT) ThemeCreateParentWindow( | ||
562 | __in THEME* pTheme, | ||
563 | __in DWORD dwExStyle, | ||
564 | __in LPCWSTR szClassName, | ||
565 | __in LPCWSTR szWindowName, | ||
566 | __in DWORD dwStyle, | ||
567 | __in int x, | ||
568 | __in int y, | ||
569 | __in_opt HWND hwndParent, | ||
570 | __in_opt HINSTANCE hInstance, | ||
571 | __in_opt LPVOID lpParam, | ||
572 | __out_opt HWND* phWnd | ||
573 | ) | ||
574 | { | ||
575 | HRESULT hr = S_OK; | ||
576 | HWND hWnd = NULL; | ||
577 | |||
578 | if (pTheme->hwndParent) | ||
579 | { | ||
580 | ThmExitOnFailure(hr = E_INVALIDSTATE, "ThemeCreateParentWindow called after the theme was loaded."); | ||
581 | } | ||
582 | |||
583 | hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWidth, pTheme->nHeight, hwndParent, NULL, hInstance, lpParam); | ||
584 | ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window."); | ||
585 | ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE."); | ||
586 | AssertSz(hWnd == pTheme->hwndParent, "Theme parent window does not equal newly created window."); | ||
587 | |||
588 | if (phWnd) | ||
589 | { | ||
590 | *phWnd = hWnd; | ||
591 | } | ||
592 | |||
593 | LExit: | ||
594 | return hr; | ||
595 | } | ||
596 | |||
597 | |||
556 | DAPI_(HRESULT) ThemeLoadControls( | 598 | DAPI_(HRESULT) ThemeLoadControls( |
557 | __in THEME* pTheme, | 599 | __in THEME* pTheme, |
558 | __in HWND hwndParent, | ||
559 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, | 600 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, |
560 | __in DWORD cAssignControlIds | 601 | __in DWORD cAssignControlIds |
561 | ) | 602 | ) |
562 | { | 603 | { |
563 | return LoadControls(pTheme, NULL, hwndParent, rgAssignControlIds, cAssignControlIds); | 604 | HRESULT hr = S_OK; |
605 | |||
606 | if (!pTheme->hwndParent) | ||
607 | { | ||
608 | ThmExitOnFailure(hr = E_INVALIDSTATE, "ThemeLoadControls called before theme parent window created."); | ||
609 | } | ||
610 | |||
611 | hr = LoadControls(pTheme, NULL, rgAssignControlIds, cAssignControlIds); | ||
612 | |||
613 | LExit: | ||
614 | return hr; | ||
564 | } | 615 | } |
565 | 616 | ||
566 | 617 | ||
@@ -735,6 +786,10 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc( | |||
735 | { | 786 | { |
736 | switch (uMsg) | 787 | switch (uMsg) |
737 | { | 788 | { |
789 | case WM_NCCREATE: | ||
790 | OnNcCreate(pTheme, hWnd, lParam); | ||
791 | break; | ||
792 | |||
738 | case WM_NCHITTEST: | 793 | case WM_NCHITTEST: |
739 | if (pTheme->dwStyle & WS_POPUP) | 794 | if (pTheme->dwStyle & WS_POPUP) |
740 | { | 795 | { |
@@ -4107,6 +4162,15 @@ LExit: | |||
4107 | return fHandled; | 4162 | return fHandled; |
4108 | } | 4163 | } |
4109 | 4164 | ||
4165 | static void OnNcCreate( | ||
4166 | __in THEME* pTheme, | ||
4167 | __in HWND hWnd, | ||
4168 | __in LPARAM /*lParam*/ | ||
4169 | ) | ||
4170 | { | ||
4171 | pTheme->hwndParent = hWnd; | ||
4172 | } | ||
4173 | |||
4110 | static HRESULT OnRichEditEnLink( | 4174 | static HRESULT OnRichEditEnLink( |
4111 | __in LPARAM lParam, | 4175 | __in LPARAM lParam, |
4112 | __in HWND hWndRichEdit, | 4176 | __in HWND hWndRichEdit, |
@@ -4620,7 +4684,6 @@ static LRESULT CALLBACK PanelWndProc( | |||
4620 | static HRESULT LoadControls( | 4684 | static HRESULT LoadControls( |
4621 | __in THEME* pTheme, | 4685 | __in THEME* pTheme, |
4622 | __in_opt THEME_CONTROL* pParentControl, | 4686 | __in_opt THEME_CONTROL* pParentControl, |
4623 | __in HWND hwndParent, | ||
4624 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, | 4687 | __in_ecount_opt(cAssignControlIds) const THEME_ASSIGN_CONTROL_ID* rgAssignControlIds, |
4625 | __in DWORD cAssignControlIds | 4688 | __in DWORD cAssignControlIds |
4626 | ) | 4689 | ) |
@@ -4631,15 +4694,10 @@ static HRESULT LoadControls( | |||
4631 | BOOL fStartNewGroup = FALSE; | 4694 | BOOL fStartNewGroup = FALSE; |
4632 | DWORD cControls = 0; | 4695 | DWORD cControls = 0; |
4633 | THEME_CONTROL* rgControls = NULL; | 4696 | THEME_CONTROL* rgControls = NULL; |
4634 | 4697 | HWND hwndParent = pParentControl ? pParentControl->hWnd : pTheme->hwndParent; | |
4635 | if (!pParentControl) | ||
4636 | { | ||
4637 | AssertSz(!pTheme->hwndParent, "Theme already loaded controls because it has a parent window."); | ||
4638 | pTheme->hwndParent = hwndParent; | ||
4639 | } | ||
4640 | 4698 | ||
4641 | GetControls(pTheme, pParentControl, cControls, rgControls); | 4699 | GetControls(pTheme, pParentControl, cControls, rgControls); |
4642 | ::GetClientRect(pParentControl ? pParentControl->hWnd : pTheme->hwndParent, &rcParent); | 4700 | ::GetClientRect(hwndParent, &rcParent); |
4643 | 4701 | ||
4644 | for (DWORD i = 0; i < cControls; ++i) | 4702 | for (DWORD i = 0; i < cControls; ++i) |
4645 | { | 4703 | { |
@@ -4974,7 +5032,7 @@ static HRESULT LoadControls( | |||
4974 | 5032 | ||
4975 | if (pControl->cControls) | 5033 | if (pControl->cControls) |
4976 | { | 5034 | { |
4977 | hr = LoadControls(pTheme, pControl, pControl->hWnd, rgAssignControlIds, cAssignControlIds); | 5035 | hr = LoadControls(pTheme, pControl, rgAssignControlIds, cAssignControlIds); |
4978 | ThmExitOnFailure(hr, "Failed to load child controls."); | 5036 | ThmExitOnFailure(hr, "Failed to load child controls."); |
4979 | } | 5037 | } |
4980 | } | 5038 | } |