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