Modal state causing unrelated mouseExit() in mouse listeners


#1

Steps:

  1. Attach a MouseListener to a Component in the hierarchy of a TopLevelWindow
  2. Put the application into the modal state, calling enterModalState() on a new unrelated TopLevelWindow.

Result:

The MouseListener will receive mouseExit messages without corresponding mouseEnter messages when the mouse goes in and out of the associated Component.

Resolution:

Either the mouseExit should never be sent (preferred if mouse clicks are disabled in the modal state), or both mouseEnter and mouseExit should be sent (preferred if mouse clicks pass through unrelated TopLevelWindow in the modal state).


#2

Ok, how about this…

void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time) { if (isCurrentlyBlockedByAnotherModalComponent() && source.getComponentUnderMouse() != this) return;


#3

That works!