src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page

        

*** 36,45 **** --- 36,46 ---- import sun.awt.*; import sun.java2d.*; import sun.java2d.loops.Blit; import sun.java2d.loops.CompositeType; import sun.java2d.pipe.Region; + import sun.lwawt.macosx.CPlatformWindow; import sun.util.logging.PlatformLogger; public class LWWindowPeer extends LWContainerPeer<Window, JComponent> implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
*** 680,742 **** (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null; LWWindowPeer curWindowPeer = (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null; if (id == MouseEvent.MOUSE_EXITED) { ! // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched ! // to a peer from another window. So we must first check if this peer is ! // the same as lastWindowPeer ! if (lastWindowPeer == this) { ! if (isEnabled()) { Point lp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer); postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), MouseEvent.MOUSE_EXITED, when, modifiers, lp.x, lp.y, screenX, screenY, clickCount, popupTrigger, button)); } lastMouseEventPeer = null; } ! } else { ! if (targetPeer != lastMouseEventPeer) { ! ! if (id != MouseEvent.MOUSE_DRAGGED || lastMouseEventPeer == null) { ! // lastMouseEventPeer may be null if mouse was out of Java windows ! if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) { ! // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit ! // later), in which case lastWindowPeer is another window ! if (lastWindowPeer != this) { ! Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer); ! // Additionally translate from this to lastWindowPeer coordinates ! Rectangle lr = lastWindowPeer.getBounds(); ! oldp.x += r.x - lr.x; ! oldp.y += r.y - lr.y; ! postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), ! MouseEvent.MOUSE_EXITED, ! when, modifiers, ! oldp.x, oldp.y, screenX, screenY, ! clickCount, popupTrigger, button)); ! } else { ! Point oldp = lastMouseEventPeer.windowToLocal(x, y, this); ! postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), ! MouseEvent.MOUSE_EXITED, ! when, modifiers, ! oldp.x, oldp.y, screenX, screenY, ! clickCount, popupTrigger, button)); } } ! if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) { ! Point newp = targetPeer.windowToLocal(x, y, curWindowPeer); ! postEvent(new MouseEvent(targetPeer.getTarget(), ! MouseEvent.MOUSE_ENTERED, ! when, modifiers, ! newp.x, newp.y, screenX, screenY, ! clickCount, popupTrigger, button)); } } - lastMouseEventPeer = targetPeer; } // TODO: fill "bdata" member of AWTEvent int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0; int otherButtonsPressed = modifiers & ~eventButtonMask; --- 681,737 ---- (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null; LWWindowPeer curWindowPeer = (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null; if (id == MouseEvent.MOUSE_EXITED) { ! // We always send the MOUSE_EXITED event to the lastWindowPeer ! if (lastWindowPeer != null) { ! if (lastWindowPeer.isEnabled()) { Point lp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer); postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), MouseEvent.MOUSE_EXITED, when, modifiers, lp.x, lp.y, screenX, screenY, clickCount, popupTrigger, button)); } lastMouseEventPeer = null; } ! } else if(id == MouseEvent.MOUSE_ENTERED) { ! if (targetPeer != null) { ! if (targetPeer.isEnabled()) { ! Point lp = targetPeer.windowToLocal(x, y, curWindowPeer); ! postEvent(new MouseEvent(targetPeer.getTarget(), ! MouseEvent.MOUSE_ENTERED, when, ! modifiers, lp.x, lp.y, screenX, ! screenY, clickCount, popupTrigger, ! button)); } + lastMouseEventPeer = targetPeer; } ! } else { ! CPlatformWindow topmostPlatforWindow = ! CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse(); ! LWWindowPeer topmostWindowPeer = ! topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null; ! ! if (topmostWindowPeer == curWindowPeer) { ! // current window is the topmost window under mouse ! if (targetPeer != lastMouseEventPeer) { ! generateMouseEnterExitEventsForComponents(when, button, x, y, ! screenX, screenY, modifiers, clickCount, popupTrigger, ! lastWindowPeer, curWindowPeer, targetPeer); } + } else { + // the topmost window under mouse is differ from the current window + LWComponentPeer topmostTargetPeer = + topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null; + if (topmostTargetPeer != lastMouseEventPeer) { + generateMouseEnterExitEventsForComponents(when, button, x, y, + screenX, screenY, modifiers, clickCount, popupTrigger, + lastWindowPeer, topmostWindowPeer, topmostTargetPeer); } } // TODO: fill "bdata" member of AWTEvent int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0; int otherButtonsPressed = modifiers & ~eventButtonMask;
*** 819,828 **** --- 814,866 ---- } } notifyUpdateCursor(); } + private void generateMouseEnterExitEventsForComponents(long when, + int button, int x, int y, int screenX, int screenY, + int modifiers, int clickCount, boolean popupTrigger, + LWWindowPeer lastWindowPeer, + LWWindowPeer targetWindowPeer, LWComponentPeer targetPeer) { + + // Generate Mouse Exit for components + if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) { + // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit + // later), in which case lastWindowPeer is another window + if (lastWindowPeer != targetWindowPeer) { + Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer); + // Additionally translate from this to lastWindowPeer coordinates + Rectangle r = getBounds(); + Rectangle lr = lastWindowPeer.getBounds(); + oldp.x += r.x - lr.x; + oldp.y += r.y - lr.y; + postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), + MouseEvent.MOUSE_EXITED, + when, modifiers, + oldp.x, oldp.y, screenX, screenY, + clickCount, popupTrigger, button)); + } else { + Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer); + postEvent(new MouseEvent(lastMouseEventPeer.getTarget(), + MouseEvent.MOUSE_EXITED, + when, modifiers, + oldp.x, oldp.y, screenX, screenY, + clickCount, popupTrigger, button)); + } + } + lastMouseEventPeer = targetPeer; + // Generate Mouse Enter for components + if (targetPeer != null && targetPeer.isEnabled()) { + Point newp = targetPeer.windowToLocal(x, y, targetWindowPeer); + postEvent(new MouseEvent(targetPeer.getTarget(), + MouseEvent.MOUSE_ENTERED, + when, modifiers, + newp.x, newp.y, screenX, screenY, + clickCount, popupTrigger, button)); + } + } + public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers, int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation, byte[] bdata) {