Windows: Remove special code for the help menu

This commit is contained in:
Henrik Rydgård
2025-09-01 09:34:27 +02:00
parent ee3b6b3dfc
commit 94b47498ab
5 changed files with 52 additions and 61 deletions
+17 -28
View File
@@ -126,7 +126,8 @@ namespace MainWindow
HWND hwndMain;
HWND hwndGameList;
TouchInputHandler touchHandler;
static HMENU menu;
static HMENU g_hMenu;
HINSTANCE hInst;
static int cursorCounter = 0;
@@ -293,7 +294,7 @@ namespace MainWindow
WINDOWPLACEMENT placement = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(hwndMain, &placement);
int oldWindowState = g_WindowState;
const int oldWindowState = g_WindowState;
inFullscreenResize = true;
g_IgnoreWM_SIZE = true;
@@ -322,8 +323,8 @@ namespace MainWindow
::SetWindowLong(hWnd, GWL_STYLE, dwStyle);
// Remove the menu bar. This can trigger WM_SIZE because the contents change size.
::SetMenu(hWnd, goingFullscreen || !g_Config.bShowMenuBar ? NULL : menu);
// Remove the menu bar if going fullscreen. This can trigger WM_SIZE because the contents change size.
::SetMenu(hWnd, goingFullscreen || !g_Config.bShowMenuBar ? NULL : g_hMenu);
if (g_Config.UseFullScreen() != goingFullscreen) {
g_Config.bFullScreen = goingFullscreen;
@@ -339,10 +340,10 @@ namespace MainWindow
if (g_Config.bFullScreenMulti) {
// Maximize isn't enough to display on all monitors.
// Remember that negative coordinates may be valid.
int totalX = GetSystemMetrics(SM_XVIRTUALSCREEN);
int totalY = GetSystemMetrics(SM_YVIRTUALSCREEN);
int totalWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int totalHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
const int totalX = GetSystemMetrics(SM_XVIRTUALSCREEN);
const int totalY = GetSystemMetrics(SM_YVIRTUALSCREEN);
const int totalWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
const int totalHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
MoveWindow(hwndMain, totalX, totalY, totalWidth, totalHeight, TRUE);
HandleSizeChange(oldWindowState);
ShowWindow(hwndMain, SW_SHOW);
@@ -468,7 +469,7 @@ namespace MainWindow
u32 style = WS_OVERLAPPEDWINDOW;
hwndMain = CreateWindowEx(0,szWindowClass, L"", style,
hwndMain = CreateWindowEx(0, szWindowClass, L"", style,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
if (!hwndMain)
return FALSE;
@@ -478,21 +479,9 @@ namespace MainWindow
const DWM_WINDOW_CORNER_PREFERENCE pref = DWMWCP_DONOTROUND;
DwmSetWindowAttribute(hwndMain, DWMWA_WINDOW_CORNER_PREFERENCE, &pref, sizeof(pref));
menu = GetMenu(hwndMain);
g_hMenu = GetMenu(hwndMain);
MENUINFO info;
ZeroMemory(&info,sizeof(MENUINFO));
info.cbSize = sizeof(MENUINFO);
info.cyMax = 0;
info.dwStyle = MNS_CHECKORBMP;
info.fMask = MIM_STYLE;
for (int i = 0; i < GetMenuItemCount(menu); i++) {
SetMenuInfo(GetSubMenu(menu,i), &info);
}
// Always translate first: translating resets the menu.
TranslateMenus(hwndMain, menu);
UpdateMenus();
MainMenuInit(hwndMain, g_hMenu);
// Accept dragged files.
DragAcceptFiles(hwndMain, TRUE);
@@ -955,9 +944,9 @@ namespace MainWindow
break;
case WM_USER_UPDATE_UI:
TranslateMenus(hwndMain, menu);
TranslateMenus(hwndMain, g_hMenu);
// Update checked status immediately for accelerators.
UpdateMenus();
UpdateMenus(nullptr);
break;
case WM_USER_WINDOW_TITLE_CHANGED:
@@ -983,7 +972,7 @@ namespace MainWindow
case WM_MENUSELECT:
// Called when a menu is opened. Also when an item is selected, but meh.
UpdateMenus(true);
UpdateMenus((HMENU)lParam);
WindowsRawInput::NotifyMenu();
trapMouse = false;
break;
@@ -1204,11 +1193,11 @@ namespace MainWindow
void ToggleDebugConsoleVisibility() {
if (!g_Config.bEnableLogging) {
g_logManager.GetConsoleListener()->Show(false);
EnableMenuItem(menu, ID_DEBUG_LOG, MF_GRAYED);
EnableMenuItem(g_hMenu, ID_DEBUG_LOG, MF_GRAYED);
}
else {
g_logManager.GetConsoleListener()->Show(true);
EnableMenuItem(menu, ID_DEBUG_LOG, MF_ENABLED);
EnableMenuItem(g_hMenu, ID_DEBUG_LOG, MF_ENABLED);
}
}
+1 -1
View File
@@ -66,7 +66,7 @@ namespace MainWindow
void CreateVFPUWindow();
void NotifyDebuggerMapLoaded();
void DestroyDebugWindows();
void UpdateMenus(bool isMenuSelect = false);
void UpdateMenus(HMENU menuSelected);
void UpdateCommands();
void UpdateSwitchUMD();
void SetWindowTitle(const wchar_t *title);
+26 -32
View File
@@ -63,13 +63,11 @@ extern bool g_TakeScreenshot;
namespace MainWindow {
extern HINSTANCE hInst;
extern bool noFocusPause;
static bool browsePauseAfter;
static std::unordered_map<int, std::string> initialMenuKeys;
static std::vector<std::string> availableShaders;
static std::string menuLanguageID = "";
static int menuKeymapGeneration = -1;
static bool menuShaderInfoLoaded = false;
std::vector<ShaderInfo> menuShaderInfo;
LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
@@ -162,30 +160,25 @@ namespace MainWindow {
return initialMenuKeys[menuID];
}
// TODO: Why isn't this just defined in the resoucre
void CreateHelpMenu(HMENU menu) {
auto des = GetI18NCategory(I18NCat::DESKTOPUI);
const std::wstring visitMainWebsite = ConvertUTF8ToWString(des->T("www.ppsspp.org"));
const std::wstring visitForum = ConvertUTF8ToWString(des->T("PPSSPP Forums"));
const std::wstring buyGold = ConvertUTF8ToWString(des->T("Buy PPSSPP Gold"));
const std::wstring gitHub = ConvertUTF8ToWString(des->T("GitHub"));
const std::wstring discord = ConvertUTF8ToWString(des->T("Discord"));
const std::wstring aboutPPSSPP = ConvertUTF8ToWString(des->T("About PPSSPP..."));
HMENU helpMenu = GetSubmenuById(menu, ID_HELP_MENU);
EmptySubMenu(helpMenu);
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENWEBSITE, visitMainWebsite.c_str());
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENFORUM, visitForum.c_str());
// Repeat the process for other languages, if necessary.
if (!System_GetPropertyBool(SYSPROP_APP_GOLD)) {
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_BUYGOLD, buyGold.c_str());
void MainMenuInit(HWND hwndMain, HMENU hMenu) {
MENUINFO info;
ZeroMemory(&info, sizeof(MENUINFO));
info.cbSize = sizeof(MENUINFO);
info.cyMax = 0;
info.dwStyle = MNS_CHECKORBMP;
info.fMask = MIM_STYLE;
for (int i = 0; i < GetMenuItemCount(hMenu); i++) {
SetMenuInfo(GetSubMenu(hMenu, i), &info);
}
// Always translate first: translating resets the menu.
TranslateMenus(hwndMain, hMenu);
// Don't need to update here, happens later.
HMENU helpMenu = GetSubmenuById(hMenu, ID_HELP_MENU);
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {
RemoveMenu(helpMenu, ID_HELP_BUYGOLD, MF_BYCOMMAND);
}
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_GITHUB, gitHub.c_str());
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_DISCORD, discord.c_str());
AppendMenu(helpMenu, MF_SEPARATOR, 0, 0);
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_ABOUT, aboutPPSSPP.c_str());
}
static void TranslateMenuItem(const HMENU hMenu, const int menuID, const std::wstring& accelerator = L"", const char *key = nullptr) {
@@ -321,7 +314,12 @@ namespace MainWindow {
TranslateMenuItem(menu, ID_EMULATION_CHAT, g_Config.bSystemControls ? L"\tCtrl+C" : L"");
// Help menu: it's translated in CreateHelpMenu.
CreateHelpMenu(menu);
TranslateMenuItem(menu, ID_HELP_OPENWEBSITE);
TranslateMenuItem(menu, ID_HELP_OPENFORUM);
TranslateMenuItem(menu, ID_HELP_BUYGOLD);
TranslateMenuItem(menu, ID_HELP_GITHUB);
TranslateMenuItem(menu, ID_HELP_DISCORD);
TranslateMenuItem(menu, ID_HELP_ABOUT);
}
void TranslateMenus(HWND hWnd, HMENU menu) {
@@ -342,7 +340,7 @@ namespace MainWindow {
void BrowseAndBootDone(std::string filename);
void BrowseAndBoot(RequesterToken token, std::string defaultPath, bool browseDirectory) {
browsePauseAfter = false;
bool browsePauseAfter = false;
if (GetUIState() == UISTATE_INGAME) {
browsePauseAfter = Core_IsStepping();
if (!browsePauseAfter)
@@ -990,11 +988,7 @@ namespace MainWindow {
vfpudlg->Show(false);
}
void UpdateMenus(bool isMenuSelect) {
if (isMenuSelect) {
menuShaderInfoLoaded = false;
}
void UpdateMenus(HMENU menuSelected) {
HMENU menu = GetMenu(GetHWND());
#define CHECKITEM(item,value) CheckMenuItem(menu,item,MF_BYCOMMAND | ((value) ? MF_CHECKED : MF_UNCHECKED));
CHECKITEM(ID_DEBUG_IGNOREILLEGALREADS, g_Config.bIgnoreBadMemAccess);
+1
View File
@@ -7,6 +7,7 @@
#include "Core/System.h"
namespace MainWindow {
void MainMenuInit(HWND hWndMain, HMENU hMenu);
void MainWindowMenu_Process(HWND hWnd, WPARAM wParam);
void TranslateMenus(HWND hWnd, HMENU menu);
void BrowseAndBoot(RequesterToken token, std::string defaultPath, bool browseDirectory = false);
+7
View File
@@ -688,7 +688,14 @@ BEGIN
POPUP "Help", ID_HELP_MENU
BEGIN
MENUITEM "www.ppsspp.org", ID_HELP_OPENWEBSITE
MENUITEM "PPSSPP Forums", ID_HELP_OPENFORUM
MENUITEM "Buy PPSSPP Gold", ID_HELP_BUYGOLD
MENUITEM "", 0, MFT_SEPARATOR
MENUITEM "GitHub", ID_HELP_GITHUB
MENUITEM "Discord", ID_HELP_DISCORD
MENUITEM "", 0, MFT_SEPARATOR
MENUITEM "About PPSSPP...", ID_HELP_ABOUT
END
END