mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 22:04:55 +02:00
Fix Dark Mode Menu Bar cluttered issue
Use correct enums for dark mode menubar Fix #14910, fix #10130, close #14911
This commit is contained in:
parent
60034edf37
commit
243112d04d
@ -41,6 +41,10 @@
|
|||||||
#define WINAPI_LAMBDA
|
#define WINAPI_LAMBDA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WM_DPICHANGED
|
||||||
|
#define WM_DPICHANGED 0x02E0
|
||||||
|
#endif
|
||||||
|
|
||||||
// already added in project files
|
// already added in project files
|
||||||
// keep for plugin authors
|
// keep for plugin authors
|
||||||
//#ifdef _MSC_VER
|
//#ifdef _MSC_VER
|
||||||
@ -770,16 +774,15 @@ namespace NppDarkMode
|
|||||||
|
|
||||||
// processes messages related to UAH / custom menubar drawing.
|
// processes messages related to UAH / custom menubar drawing.
|
||||||
// return true if handled, false to continue with normal processing in your wndproc
|
// return true if handled, false to continue with normal processing in your wndproc
|
||||||
bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr)
|
bool runUAHWndProc(HWND hWnd, UINT message, WPARAM /*wParam*/, LPARAM lParam, LRESULT* lr)
|
||||||
{
|
{
|
||||||
static HTHEME g_menuTheme = nullptr;
|
static HTHEME g_menuTheme = nullptr;
|
||||||
|
|
||||||
UNREFERENCED_PARAMETER(wParam);
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_UAHDRAWMENU:
|
case WM_UAHDRAWMENU:
|
||||||
{
|
{
|
||||||
UAHMENU* pUDM = (UAHMENU*)lParam;
|
auto pUDM = reinterpret_cast<UAHMENU*>(lParam);
|
||||||
RECT rc{};
|
RECT rc{};
|
||||||
|
|
||||||
// get the menubar rect
|
// get the menubar rect
|
||||||
@ -804,9 +807,10 @@ namespace NppDarkMode
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_UAHDRAWMENUITEM:
|
case WM_UAHDRAWMENUITEM:
|
||||||
{
|
{
|
||||||
UAHDRAWMENUITEM* pUDMI = (UAHDRAWMENUITEM*)lParam;
|
auto pUDMI = reinterpret_cast<UAHDRAWMENUITEM*>(lParam);
|
||||||
|
|
||||||
// get the menu item string
|
// get the menu item string
|
||||||
wchar_t menuString[256] = { '\0' };
|
wchar_t menuString[256] = { '\0' };
|
||||||
@ -824,32 +828,32 @@ namespace NppDarkMode
|
|||||||
|
|
||||||
DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
|
DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
|
||||||
|
|
||||||
int iTextStateID = MPI_NORMAL;
|
int iTextStateID = MBI_NORMAL;
|
||||||
int iBackgroundStateID = MPI_NORMAL;
|
int iBackgroundStateID = MBI_NORMAL;
|
||||||
{
|
{
|
||||||
if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT))
|
if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT))
|
||||||
{
|
{
|
||||||
// normal display
|
// normal display
|
||||||
iTextStateID = MPI_NORMAL;
|
iTextStateID = MBI_NORMAL;
|
||||||
iBackgroundStateID = MPI_NORMAL;
|
iBackgroundStateID = MBI_NORMAL;
|
||||||
}
|
}
|
||||||
if (pUDMI->dis.itemState & ODS_HOTLIGHT)
|
if (pUDMI->dis.itemState & ODS_HOTLIGHT)
|
||||||
{
|
{
|
||||||
// hot tracking
|
// hot tracking
|
||||||
iTextStateID = MPI_HOT;
|
iTextStateID = MBI_HOT;
|
||||||
iBackgroundStateID = MPI_HOT;
|
iBackgroundStateID = MBI_HOT;
|
||||||
}
|
}
|
||||||
if (pUDMI->dis.itemState & ODS_SELECTED)
|
if (pUDMI->dis.itemState & ODS_SELECTED)
|
||||||
{
|
{
|
||||||
// clicked -- MENU_POPUPITEM has no state for this, though MENU_BARITEM does
|
// clicked
|
||||||
iTextStateID = MPI_HOT;
|
iTextStateID = MBI_PUSHED;
|
||||||
iBackgroundStateID = MPI_HOT;
|
iBackgroundStateID = MBI_PUSHED;
|
||||||
}
|
}
|
||||||
if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED))
|
if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED))
|
||||||
{
|
{
|
||||||
// disabled / grey text
|
// disabled / grey text
|
||||||
iTextStateID = MPI_DISABLED;
|
iTextStateID = MBI_DISABLED;
|
||||||
iBackgroundStateID = MPI_DISABLED;
|
iBackgroundStateID = MBI_DISABLED;
|
||||||
}
|
}
|
||||||
if (pUDMI->dis.itemState & ODS_NOACCEL)
|
if (pUDMI->dis.itemState & ODS_NOACCEL)
|
||||||
{
|
{
|
||||||
@ -862,31 +866,57 @@ namespace NppDarkMode
|
|||||||
g_menuTheme = OpenThemeData(hWnd, L"Menu");
|
g_menuTheme = OpenThemeData(hWnd, L"Menu");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iBackgroundStateID == MPI_NORMAL || iBackgroundStateID == MPI_DISABLED)
|
switch (iBackgroundStateID)
|
||||||
{
|
{
|
||||||
FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getDarkerBackgroundBrush());
|
case MBI_NORMAL:
|
||||||
}
|
case MBI_DISABLED:
|
||||||
else if (iBackgroundStateID == MPI_HOT || iBackgroundStateID == MPI_DISABLEDHOT)
|
{
|
||||||
{
|
::FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getDarkerBackgroundBrush());
|
||||||
FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getHotBackgroundBrush());
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
case MBI_HOT:
|
||||||
DrawThemeBackground(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iBackgroundStateID, &pUDMI->dis.rcItem, nullptr);
|
case MBI_DISABLEDHOT:
|
||||||
|
{
|
||||||
|
::FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getHotBackgroundBrush());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case MBI_PUSHED:
|
||||||
|
case MBI_DISABLEDPUSHED:
|
||||||
|
{
|
||||||
|
::FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getSofterBackgroundBrush());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
::DrawThemeBackground(g_menuTheme, pUDMI->um.hdc, MENU_BARITEM, iBackgroundStateID, &pUDMI->dis.rcItem, nullptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DTTOPTS dttopts{};
|
DTTOPTS dttopts{};
|
||||||
dttopts.dwSize = sizeof(DTTOPTS);
|
dttopts.dwSize = sizeof(DTTOPTS);
|
||||||
if (iTextStateID == MPI_NORMAL || iTextStateID == MPI_HOT)
|
if (iTextStateID == MBI_NORMAL || iTextStateID == MBI_HOT || iTextStateID == MBI_PUSHED)
|
||||||
{
|
{
|
||||||
dttopts.dwFlags |= DTT_TEXTCOLOR;
|
dttopts.dwFlags |= DTT_TEXTCOLOR;
|
||||||
dttopts.crText = NppDarkMode::getTextColor();
|
dttopts.crText = NppDarkMode::getTextColor();
|
||||||
}
|
}
|
||||||
DrawThemeTextEx(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iTextStateID, menuString, mii.cch, dwFlags, &pUDMI->dis.rcItem, &dttopts);
|
else if (iTextStateID == MBI_DISABLED || iTextStateID == MBI_DISABLEDHOT || iTextStateID == MBI_DISABLEDPUSHED)
|
||||||
|
{
|
||||||
|
dttopts.dwFlags |= DTT_TEXTCOLOR;
|
||||||
|
dttopts.crText = NppDarkMode::getDisabledTextColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
::DrawThemeTextEx(g_menuTheme, pUDMI->um.hdc, MENU_BARITEM, iTextStateID, menuString, mii.cch, dwFlags, &pUDMI->dis.rcItem, &dttopts);
|
||||||
|
|
||||||
*lr = 0;
|
*lr = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WM_DPICHANGED:
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
{
|
{
|
||||||
if (g_menuTheme)
|
if (g_menuTheme)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user