Split up ThemeDefWindowProc so that the right message handling code is shared with PanelWndProc.
Sean Hall committed
Jul 6, 2020 at 19:43 UTC
171b886bc5652da63b5ed549c755aa3fa3337eab
1 file changed
+132
-103
src/dutil/thmutil.cpp
+132
-103
@@ -334,6 +334,13 @@ static void GetControlDimensions(
334
static HRESULT SizeListViewColumns(
335
__inout THEME_CONTROL* pControl
336
);
337
+static LRESULT CALLBACK ControlGroupDefWindowProc(
338
+ __in_opt THEME* pTheme,
339
+ __in HWND hWnd,
340
+ __in UINT uMsg,
341
+ __in WPARAM wParam,
342
+ __in LPARAM lParam
343
+ );
344
static LRESULT CALLBACK PanelWndProc(
345
__in HWND hWnd,
346
__in UINT uMsg,
@@ -860,7 +867,14 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc(
867
switch (uMsg)
868
{
869
case WM_NCCREATE:
863
- OnNcCreate(pTheme, hWnd, lParam);
870
+ if (pTheme->hwndParent)
871
+ {
872
+ AssertSz(FALSE, "WM_NCCREATE called multiple times");
873
+ }
874
+ else
875
+ {
876
+ OnNcCreate(pTheme, hWnd, lParam);
877
+ }
878
break;
879
880
case WM_NCHITTEST:
@@ -877,41 +891,6 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc(
891
}
892
break;
893
880
- case WM_DRAWITEM:
881
- ThemeDrawControl(pTheme, reinterpret_cast<LPDRAWITEMSTRUCT>(lParam));
882
- return TRUE;
883
-
884
- case WM_CTLCOLORBTN: __fallthrough;
885
- case WM_CTLCOLORSTATIC:
886
- {
887
- HBRUSH hBrush = NULL;
888
- if (ThemeSetControlColor(pTheme, reinterpret_cast<HDC>(wParam), reinterpret_cast<HWND>(lParam), &hBrush))
889
- {
890
- return reinterpret_cast<LRESULT>(hBrush);
891
- }
892
- }
893
- break;
894
-
895
- case WM_SETCURSOR:
896
- if (ThemeHoverControl(pTheme, hWnd, reinterpret_cast<HWND>(wParam)))
897
- {
898
- return TRUE;
899
- }
900
- break;
901
-
902
- case WM_PAINT:
903
- if (::GetUpdateRect(hWnd, NULL, FALSE))
904
- {
905
- PAINTSTRUCT ps;
906
- ::BeginPaint(hWnd, &ps);
907
- if (hWnd == pTheme->hwndParent)
908
- {
909
- ThemeDrawBackground(pTheme, &ps);
910
- }
911
- ::EndPaint(hWnd, &ps);
912
- }
913
- return 0;
914
-
894
case WM_SIZING:
895
if (pTheme->fAutoResize)
896
{
@@ -952,70 +931,10 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc(
931
return 0;
932
}
933
break;
955
-
956
- case WM_TIMER:
957
- OnBillboardTimer(pTheme, hWnd, wParam);
958
- break;
959
-
960
- case WM_NOTIFY:
961
- if (lParam)
962
- {
963
- LPNMHDR pnmhdr = reinterpret_cast<LPNMHDR>(lParam);
964
- switch (pnmhdr->code)
965
- {
966
- // Tab/Shift+Tab support for rich-edit control.
967
- case EN_MSGFILTER:
968
- {
969
- MSGFILTER* msgFilter = reinterpret_cast<MSGFILTER*>(lParam);
970
- if (WM_KEYDOWN == msgFilter->msg && VK_TAB == msgFilter->wParam)
971
- {
972
- BOOL fShift = 0x8000 & ::GetKeyState(VK_SHIFT);
973
- HWND hwndFocus = ::GetNextDlgTabItem(hWnd, msgFilter->nmhdr.hwndFrom, fShift);
974
- ::SetFocus(hwndFocus);
975
- return 1;
976
- }
977
- break;
978
- }
979
-
980
- // Hyperlink clicks from rich-edit control.
981
- case EN_LINK:
982
- return SUCCEEDED(OnRichEditEnLink(lParam, pnmhdr->hwndFrom, hWnd));
983
-
984
- // Clicks on a hypertext/syslink control.
985
- case NM_CLICK: __fallthrough;
986
- case NM_RETURN:
987
- if (ControlIsType(pTheme, static_cast<DWORD>(pnmhdr->idFrom), THEME_CONTROL_TYPE_HYPERTEXT))
988
- {
989
- PNMLINK pnmlink = reinterpret_cast<PNMLINK>(lParam);
990
- LITEM litem = pnmlink->item;
991
- ShelExec(litem.szUrl, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL);
992
- return 1;
993
- }
994
-
995
- return 0;
996
- }
997
- }
998
- break;
999
-
1000
- case WM_COMMAND:
1001
- switch (HIWORD(wParam))
1002
- {
1003
- case BN_CLICKED:
1004
- if (lParam)
1005
- {
1006
- const THEME_CONTROL* pControl = FindControlFromHWnd(pTheme, (HWND)lParam);
1007
- if (pControl && OnButtonClicked(pTheme, hWnd, pControl))
1008
- {
1009
- return 0;
1010
- }
1011
- }
1012
- break;
1013
- }
1014
- break;
934
}
935
}
936
1018
- return ::DefWindowProcW(hWnd, uMsg, wParam, lParam);
937
+ return ControlGroupDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam);
938
}
939
940
@@ -4846,6 +4765,119 @@ LExit:
4765
}
4766
4767
4768
+static LRESULT CALLBACK ControlGroupDefWindowProc(
4769
+ __in_opt THEME* pTheme,
4770
+ __in HWND hWnd,
4771
+ __in UINT uMsg,
4772
+ __in WPARAM wParam,
4773
+ __in LPARAM lParam
4774
+ )
4775
+{
4776
+ if (pTheme)
4777
+ {
4778
+ switch (uMsg)
4779
+ {
4780
+ case WM_DRAWITEM:
4781
+ ThemeDrawControl(pTheme, reinterpret_cast<LPDRAWITEMSTRUCT>(lParam));
4782
+ return TRUE;
4783
+
4784
+ case WM_CTLCOLORBTN: __fallthrough;
4785
+ case WM_CTLCOLORSTATIC:
4786
+ {
4787
+ HBRUSH hBrush = NULL;
4788
+ if (ThemeSetControlColor(pTheme, reinterpret_cast<HDC>(wParam), reinterpret_cast<HWND>(lParam), &hBrush))
4789
+ {
4790
+ return reinterpret_cast<LRESULT>(hBrush);
4791
+ }
4792
+ }
4793
+ break;
4794
+
4795
+ case WM_SETCURSOR:
4796
+ if (ThemeHoverControl(pTheme, hWnd, reinterpret_cast<HWND>(wParam)))
4797
+ {
4798
+ return TRUE;
4799
+ }
4800
+ break;
4801
+
4802
+ case WM_PAINT:
4803
+ if (::GetUpdateRect(hWnd, NULL, FALSE))
4804
+ {
4805
+ PAINTSTRUCT ps;
4806
+ ::BeginPaint(hWnd, &ps);
4807
+ if (hWnd == pTheme->hwndParent)
4808
+ {
4809
+ ThemeDrawBackground(pTheme, &ps);
4810
+ }
4811
+ ::EndPaint(hWnd, &ps);
4812
+ }
4813
+ return 0;
4814
+
4815
+ case WM_TIMER:
4816
+ OnBillboardTimer(pTheme, hWnd, wParam);
4817
+ break;
4818
+
4819
+ case WM_NOTIFY:
4820
+ if (lParam)
4821
+ {
4822
+ LPNMHDR pnmhdr = reinterpret_cast<LPNMHDR>(lParam);
4823
+ switch (pnmhdr->code)
4824
+ {
4825
+ // Tab/Shift+Tab support for rich-edit control.
4826
+ case EN_MSGFILTER:
4827
+ {
4828
+ MSGFILTER* msgFilter = reinterpret_cast<MSGFILTER*>(lParam);
4829
+ if (WM_KEYDOWN == msgFilter->msg && VK_TAB == msgFilter->wParam)
4830
+ {
4831
+ BOOL fShift = 0x8000 & ::GetKeyState(VK_SHIFT);
4832
+ HWND hwndFocus = ::GetNextDlgTabItem(hWnd, msgFilter->nmhdr.hwndFrom, fShift);
4833
+ ::SetFocus(hwndFocus);
4834
+ return 1;
4835
+ }
4836
+ break;
4837
+ }
4838
+
4839
+ // Hyperlink clicks from rich-edit control.
4840
+ case EN_LINK:
4841
+ return SUCCEEDED(OnRichEditEnLink(lParam, pnmhdr->hwndFrom, hWnd));
4842
+
4843
+ // Clicks on a hypertext/syslink control.
4844
+ case NM_CLICK: __fallthrough;
4845
+ case NM_RETURN:
4846
+ if (ControlIsType(pTheme, static_cast<DWORD>(pnmhdr->idFrom), THEME_CONTROL_TYPE_HYPERTEXT))
4847
+ {
4848
+ PNMLINK pnmlink = reinterpret_cast<PNMLINK>(lParam);
4849
+ LITEM litem = pnmlink->item;
4850
+ ShelExec(litem.szUrl, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL);
4851
+ return 1;
4852
+ }
4853
+
4854
+ return 0;
4855
+ }
4856
+ }
4857
+ break;
4858
+
4859
+ case WM_COMMAND:
4860
+ switch (HIWORD(wParam))
4861
+ {
4862
+ case BN_CLICKED:
4863
+ if (lParam)
4864
+ {
4865
+ const THEME_CONTROL* pControl = FindControlFromHWnd(pTheme, (HWND)lParam);
4866
+ if (pControl && OnButtonClicked(pTheme, hWnd, pControl))
4867
+ {
4868
+ return 0;
4869
+ }
4870
+ }
4871
+ break;
4872
+ }
4873
+ break;
4874
+ }
4875
+ }
4876
+
4877
+ return ::DefWindowProcW(hWnd, uMsg, wParam, lParam);
4878
+}
4879
+
4880
+
4881
static LRESULT CALLBACK PanelWndProc(
4882
__in HWND hWnd,
4883
__in UINT uMsg,
@@ -4861,7 +4893,8 @@ static LRESULT CALLBACK PanelWndProc(
4893
case WM_NCCREATE:
4894
{
4895
LPCREATESTRUCTW lpcs = reinterpret_cast<LPCREATESTRUCTW>(lParam);
4864
- ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(lpcs->lpCreateParams));
4896
+ pTheme = reinterpret_cast<THEME*>(lpcs->lpCreateParams);
4897
+ ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pTheme));
4898
}
4899
break;
4900
@@ -4873,13 +4906,9 @@ static LRESULT CALLBACK PanelWndProc(
4906
case WM_NCHITTEST:
4907
return HTCLIENT;
4908
break;
4876
-
4877
- case WM_DRAWITEM:
4878
- ThemeDrawControl(pTheme, reinterpret_cast<LPDRAWITEMSTRUCT>(lParam));
4879
- return TRUE;
4909
}
4910
4882
- return ThemeDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam);
4911
+ return ControlGroupDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam);
4912
}
4913
4914