mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 11:58:12 +00:00
Windows trays: Fix ParentEntry & Enabling
The test/testtray program would crash on Windows when adding any item and then removing it, because a submenu's parent_entry field was not set. Additionally, I noticed that some extraneous code copied from the {G,S}etTrayEntryChecked made {G,S}etTrayEntryEnabled work only for checkboxes, which is not the desired behavior. Both issues were fixed in this commit.
This commit is contained in:
@@ -420,6 +420,7 @@ SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *la
|
|||||||
entry->submenu->hMenu = CreatePopupMenu();
|
entry->submenu->hMenu = CreatePopupMenu();
|
||||||
entry->submenu->nEntries = 0;
|
entry->submenu->nEntries = 0;
|
||||||
entry->submenu->entries = NULL;
|
entry->submenu->entries = NULL;
|
||||||
|
entry->submenu->parent_entry = entry;
|
||||||
|
|
||||||
entry->id = (UINT_PTR) entry->submenu->hMenu;
|
entry->id = (UINT_PTR) entry->submenu->hMenu;
|
||||||
} else {
|
} else {
|
||||||
@@ -528,21 +529,11 @@ bool SDL_GetTrayEntryChecked(SDL_TrayEntry *entry)
|
|||||||
|
|
||||||
void SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled)
|
void SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled)
|
||||||
{
|
{
|
||||||
if (!(entry->flags & SDL_TRAYENTRY_CHECKBOX)) {
|
|
||||||
SDL_SetError("Cannot update check for entry not created with SDL_TRAYENTRY_CHECKBOX");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnableMenuItem(entry->parent->hMenu, (UINT) entry->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
|
EnableMenuItem(entry->parent->hMenu, (UINT) entry->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry)
|
bool SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry)
|
||||||
{
|
{
|
||||||
if (!(entry->flags & SDL_TRAYENTRY_CHECKBOX)) {
|
|
||||||
SDL_SetError("Cannot fetch check for entry not created with SDL_TRAYENTRY_CHECKBOX");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MENUITEMINFOW mii;
|
MENUITEMINFOW mii;
|
||||||
mii.cbSize = sizeof(MENUITEMINFOW);
|
mii.cbSize = sizeof(MENUITEMINFOW);
|
||||||
mii.fMask = MIIM_STATE;
|
mii.fMask = MIIM_STATE;
|
||||||
|
Reference in New Issue
Block a user