Skip to content

Commit

Permalink
PopupMenu: Fix click-through from submenu
Browse files Browse the repository at this point in the history
Previously it was possible to inadvertently activate a menu item by
clicking on a submenu item that was drawn on top of the parent menu.

The root cause was that hide() initiates an asynchronous mechanism
through exitModalState() that eventually destroys the MenuWindow, but
the MouseSourceState timer callbacks and event handlers sometimes still
had a chance to do a state update. Since the submenus have just been
destroyed the update could mistakenly conclude to activate one of the
items of the now lone parent.
  • Loading branch information
szarvas committed Feb 8, 2022
1 parent cdba8eb commit a1a8e13
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/juce_gui_basics/menus/juce_PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ struct MenuWindow : public Component
auto resultID = options.hasWatchedComponentBeenDeleted() ? 0 : getResultItemID (item);

exitModalState (resultID);
exitingModalState = true;

if (makeInvisible && deletionChecker != nullptr)
setVisible (false);
Expand Down Expand Up @@ -739,6 +740,9 @@ struct MenuWindow : public Component
if (! treeContains (currentlyModalWindow))
return false;

if (exitingModalState)
return false;

return true;
}

Expand Down Expand Up @@ -1323,6 +1327,7 @@ struct MenuWindow : public Component
uint32 windowCreationTime, lastFocusedTime, timeEnteredCurrentChildComp;
OwnedArray<MouseSourceState> mouseSourceStates;
float scaleFactor;
bool exitingModalState = false;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuWindow)
};
Expand Down

0 comments on commit a1a8e13

Please sign in to comment.