CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/W32Util/UAHMenuBar.cpp
Views: 1401
#include "Common/CommonWindows.h"12#include <Uxtheme.h>3#include <vsstyle.h>45#include "Windows/W32Util/UAHMenuBar.h"6#include "Windows/W32Util/DarkMode.h"78static HTHEME g_menuTheme = nullptr;910// processes messages related to UAH / custom menubar drawing.11// return true if handled, false to continue with normal processing in your wndproc12bool UAHDarkModeWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *lr)13{14if (!IsDarkModeEnabled() && message != WM_THEMECHANGED) {15return false;16}1718switch (message)19{20case WM_UAHDRAWMENU:21{22UAHMENU *pUDM = (UAHMENU *)lParam;23RECT rc = { 0 };2425// get the menubar rect26{27MENUBARINFO mbi = { sizeof(mbi) };28GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);2930RECT rcWindow;31GetWindowRect(hWnd, &rcWindow);3233// the rcBar is offset by the window rect34rc = mbi.rcBar;35OffsetRect(&rc, -rcWindow.left, -rcWindow.top);3637rc.top -= 1;38}3940if (!g_menuTheme) {41g_menuTheme = OpenThemeData(hWnd, L"Menu");42}4344DrawThemeBackground(g_menuTheme, pUDM->hdc, MENU_POPUPITEM, MPI_NORMAL, &rc, nullptr);45return true;46}47case WM_UAHDRAWMENUITEM:48{49UAHDRAWMENUITEM *pUDMI = (UAHDRAWMENUITEM *)lParam;5051// get the menu item string52wchar_t menuString[256] = { 0 };53MENUITEMINFO mii = { sizeof(mii), MIIM_STRING };54{55mii.dwTypeData = menuString;56mii.cch = (sizeof(menuString) / 2) - 1;5758GetMenuItemInfo(pUDMI->um.hmenu, pUDMI->umi.iPosition, TRUE, &mii);59}6061// get the item state for drawing6263DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;6465int iTextStateID = 0;66int iBackgroundStateID = 0;67{68if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT)) {69// normal display70iTextStateID = MPI_NORMAL;71iBackgroundStateID = MPI_NORMAL;72}73if (pUDMI->dis.itemState & ODS_HOTLIGHT) {74// hot tracking75iTextStateID = MPI_HOT;76iBackgroundStateID = MPI_HOT;77}78if (pUDMI->dis.itemState & ODS_SELECTED) {79// clicked -- MENU_POPUPITEM has no state for this, though MENU_BARITEM does80iTextStateID = MPI_HOT;81iBackgroundStateID = MPI_HOT;82}83if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED)) {84// disabled / grey text85iTextStateID = MPI_DISABLED;86iBackgroundStateID = MPI_DISABLED;87}88if (pUDMI->dis.itemState & ODS_NOACCEL) {89dwFlags |= DT_HIDEPREFIX;90}91}9293if (!g_menuTheme) {94g_menuTheme = OpenThemeData(hWnd, L"Menu");95}9697DrawThemeBackground(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iBackgroundStateID, &pUDMI->dis.rcItem, nullptr);98DrawThemeText(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iTextStateID, menuString, mii.cch, dwFlags, 0, &pUDMI->dis.rcItem);99100return true;101}102case WM_THEMECHANGED:103{104if (g_menuTheme) {105CloseThemeData(g_menuTheme);106g_menuTheme = nullptr;107}108// continue processing in main wndproc109return false;110}111default:112return false;113}114}115116117