Hi all,
I’ve spotted a mouse-event related bug when using modal windows, where the mouseExit() method isn’t being called on a Component when dismissing a modal window (e.g. PopupMenu).
The code below shows the problem of a Button::Listener::buttonClicked callback being used to trigger a PopupMenu, and whenever that menu window is dismissed by clicking outside of the trigger Button’s bounds (or selecting a menu item) the mouseExit call to the trigger Button is lost. Also, moving the mouse back in to the Button will trigger a second mouseEnter call, still without a mouseExit.
I’m pretty sure this behaviour is a side-effect of the fix discussed in this topic: Missing mouseEnter callback, but I can’t see a way of getting the mouseExit call back to the original Component from where that fix is.
class MainContentComponent : public Component
, private Button::Listener
{
public:
MainContentComponent()
{
addAndMakeVisible (button);
button.addListener (this);
setSize (600, 400);
}
void paint (Graphics& g) override
{
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
}
void resized() override
{
button.setBounds (getLocalBounds().withSizeKeepingCentre (200, 200));
}
private:
void MainContentComponent::buttonClicked (Button* buttonClicked) override
{
PopupMenu menu;
menu.addItem (1, "My Menu Item");
PopupMenu::Options options;
int result = menu.showAt (buttonClicked);
ignoreUnused (result);
}
class EnterExitButton : public TextButton
{
public:
EnterExitButton()
{ }
protected:
void mouseEnter (const MouseEvent&) override
{
DBG ("Entering " + getName());
}
void mouseExit (const MouseEvent&) override
{
DBG ("Exiting " + getName());
}
};
EnterExitButton button;
};