Update menu-bar.cpp

This commit is contained in:
Max833 2021-07-11 17:48:22 +02:00 committed by GitHub
parent 9105d412d9
commit 22767c9cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,7 @@ auto pMenuBar::construct() -> void {
}
auto pMenuBar::destruct() -> void {
pApplication::state().staleMenus.removeByValue(this);
if(hmenu) { DestroyMenu(hmenu); hmenu = nullptr; }
if(auto parent = _parent()) {
SetMenu(parent->hwnd, nullptr);
@ -44,6 +45,20 @@ auto pMenuBar::_parent() -> maybe<pWindow&> {
}
auto pMenuBar::_update() -> void {
bool updateNow = false;
if(auto parent = _parent()) {
updateNow = GetMenu(parent->hwnd) == nullptr;
}
if (updateNow) {
_updateDeferred();
} else {
pApplication::state().staleMenus.removeByValue(this);
pApplication::state().staleMenus.append(this);
}
}
auto pMenuBar::_updateDeferred() -> void {
if(hmenu) DestroyMenu(hmenu);
hmenu = CreateMenu();