CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/W32Util/UAHMenuBar.cpp
Views: 1401
1
#include "Common/CommonWindows.h"
2
3
#include <Uxtheme.h>
4
#include <vsstyle.h>
5
6
#include "Windows/W32Util/UAHMenuBar.h"
7
#include "Windows/W32Util/DarkMode.h"
8
9
static HTHEME g_menuTheme = nullptr;
10
11
// processes messages related to UAH / custom menubar drawing.
12
// return true if handled, false to continue with normal processing in your wndproc
13
bool UAHDarkModeWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *lr)
14
{
15
if (!IsDarkModeEnabled() && message != WM_THEMECHANGED) {
16
return false;
17
}
18
19
switch (message)
20
{
21
case WM_UAHDRAWMENU:
22
{
23
UAHMENU *pUDM = (UAHMENU *)lParam;
24
RECT rc = { 0 };
25
26
// get the menubar rect
27
{
28
MENUBARINFO mbi = { sizeof(mbi) };
29
GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
30
31
RECT rcWindow;
32
GetWindowRect(hWnd, &rcWindow);
33
34
// the rcBar is offset by the window rect
35
rc = mbi.rcBar;
36
OffsetRect(&rc, -rcWindow.left, -rcWindow.top);
37
38
rc.top -= 1;
39
}
40
41
if (!g_menuTheme) {
42
g_menuTheme = OpenThemeData(hWnd, L"Menu");
43
}
44
45
DrawThemeBackground(g_menuTheme, pUDM->hdc, MENU_POPUPITEM, MPI_NORMAL, &rc, nullptr);
46
return true;
47
}
48
case WM_UAHDRAWMENUITEM:
49
{
50
UAHDRAWMENUITEM *pUDMI = (UAHDRAWMENUITEM *)lParam;
51
52
// get the menu item string
53
wchar_t menuString[256] = { 0 };
54
MENUITEMINFO mii = { sizeof(mii), MIIM_STRING };
55
{
56
mii.dwTypeData = menuString;
57
mii.cch = (sizeof(menuString) / 2) - 1;
58
59
GetMenuItemInfo(pUDMI->um.hmenu, pUDMI->umi.iPosition, TRUE, &mii);
60
}
61
62
// get the item state for drawing
63
64
DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
65
66
int iTextStateID = 0;
67
int iBackgroundStateID = 0;
68
{
69
if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT)) {
70
// normal display
71
iTextStateID = MPI_NORMAL;
72
iBackgroundStateID = MPI_NORMAL;
73
}
74
if (pUDMI->dis.itemState & ODS_HOTLIGHT) {
75
// hot tracking
76
iTextStateID = MPI_HOT;
77
iBackgroundStateID = MPI_HOT;
78
}
79
if (pUDMI->dis.itemState & ODS_SELECTED) {
80
// clicked -- MENU_POPUPITEM has no state for this, though MENU_BARITEM does
81
iTextStateID = MPI_HOT;
82
iBackgroundStateID = MPI_HOT;
83
}
84
if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED)) {
85
// disabled / grey text
86
iTextStateID = MPI_DISABLED;
87
iBackgroundStateID = MPI_DISABLED;
88
}
89
if (pUDMI->dis.itemState & ODS_NOACCEL) {
90
dwFlags |= DT_HIDEPREFIX;
91
}
92
}
93
94
if (!g_menuTheme) {
95
g_menuTheme = OpenThemeData(hWnd, L"Menu");
96
}
97
98
DrawThemeBackground(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iBackgroundStateID, &pUDMI->dis.rcItem, nullptr);
99
DrawThemeText(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iTextStateID, menuString, mii.cch, dwFlags, 0, &pUDMI->dis.rcItem);
100
101
return true;
102
}
103
case WM_THEMECHANGED:
104
{
105
if (g_menuTheme) {
106
CloseThemeData(g_menuTheme);
107
g_menuTheme = nullptr;
108
}
109
// continue processing in main wndproc
110
return false;
111
}
112
default:
113
return false;
114
}
115
}
116
117