diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-11-23 21:02:24 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-11-23 21:02:24 +0100 |
commit | 85c375cce7e56e9e5962e051adaf6d1afc4ed813 (patch) | |
tree | 8fb74bd650a8392a5779ed995a451b6fc31e6868 /src/libui_sdl/libui/windows | |
parent | aa4f427ed4aa6482172c1e26ddc368c0a74623ce (diff) |
* remember screen rotation/gap/etc settings
* fix menu cleanup to take submenus into account properly, so it doesn't crash when exiting
Diffstat (limited to 'src/libui_sdl/libui/windows')
-rw-r--r-- | src/libui_sdl/libui/windows/menu.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libui_sdl/libui/windows/menu.cpp b/src/libui_sdl/libui/windows/menu.cpp index 1f721b6..ccf5c9c 100644 --- a/src/libui_sdl/libui/windows/menu.cpp +++ b/src/libui_sdl/libui/windows/menu.cpp @@ -14,6 +14,7 @@ static BOOL hasAbout = FALSE; struct uiMenu { WCHAR *name; + HMENU handle; uiMenuItem **items; BOOL ischild; size_t len; @@ -292,6 +293,7 @@ static HMENU makeMenu(uiMenu *m) menu = CreatePopupMenu(); if (menu == NULL) logLastError(L"error creating menu"); + m->handle = menu; for (i = 0; i < m->len; i++) appendMenuItem(menu, m->items[i]); return menu; @@ -363,21 +365,28 @@ static void freeMenu(uiMenu *m, HMENU submenu) item->hmenus[j] = item->hmenus[j + 1]; item->hmenus[j] = NULL; item->len--; + + if (item->popupchild) + freeMenu(item->popupchild, item->popupchild->handle); } } void freeMenubar(HMENU menubar) { size_t i; + size_t j = 0; MENUITEMINFOW mi; - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) + { + if (menus[i]->ischild) continue; ZeroMemory(&mi, sizeof (MENUITEMINFOW)); mi.cbSize = sizeof (MENUITEMINFOW); mi.fMask = MIIM_SUBMENU; - if (GetMenuItemInfoW(menubar, i, TRUE, &mi) == 0) + if (GetMenuItemInfoW(menubar, j, TRUE, &mi) == 0) logLastError(L"error getting menu to delete item references from"); freeMenu(menus[i], mi.hSubMenu); + j++; } // no need to worry about destroying any menus; destruction of the window they're in will do it for us } @@ -396,7 +405,7 @@ void uninitMenus(void) if (item->len != 0) // LONGTERM userbug()? implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); - if (item->name != NULL) + if (item->type != typeSubmenu && item->name != NULL) uiFree(item->name); if (item->hmenus != NULL) uiFree(item->hmenus); |