This commit is contained in:
Max833 2024-11-06 02:16:08 +01:00 committed by GitHub
commit 9c2c0c8813
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

View file

@ -3,6 +3,7 @@
namespace hiro {
static auto Application_keyboardProc(HWND, UINT, WPARAM, LPARAM) -> bool;
static auto Application_processDeferred() -> void;
static auto Application_processDialogMessage(MSG&) -> void;
static auto CALLBACK Window_windowProc(HWND, UINT, WPARAM, LPARAM) -> LRESULT;
@ -44,6 +45,14 @@ auto pApplication::processEvents() -> void {
Application_processDialogMessage(msg);
}
}
Application_processDeferred();
}
auto Application_processDeferred() -> void {
for (auto menu : pApplication::state().staleMenus) {
menu->_updateDeferred();
}
pApplication::state().staleMenus.reset();
}
auto Application_processDialogMessage(MSG& msg) -> void {

View file

@ -17,6 +17,7 @@ struct pApplication {
int modalCount = 0; //number of modal loops
Timer modalTimer; //to run Application during modal events
pToolTip* toolTip = nullptr; //active toolTip
vector<pMenuBar*> staleMenus; //menubars to update
};
static auto state() -> State&;
};

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();

View file

@ -13,7 +13,8 @@ struct pMenuBar : pObject {
auto _parent() -> maybe<pWindow&>;
auto _update() -> void;
auto _updateDeferred() -> void;
HMENU hmenu = 0;
vector<wObject> objects;
};