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

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;
  40 import sun.java2d.pipe.Region;

  41 import sun.util.logging.PlatformLogger;
  42 
  43 public class LWWindowPeer
  44     extends LWContainerPeer<Window, JComponent>
  45     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  46 {
  47     public static enum PeerType {
  48         SIMPLEWINDOW,
  49         FRAME,
  50         DIALOG,
  51         EMBEDDEDFRAME
  52     }
  53 
  54     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  55 
  56     private PlatformWindow platformWindow;
  57 
  58     // Window bounds reported by the native system (as opposed to
  59     // regular bounds inherited from LWComponentPeer which are
  60     // requested by user and may haven't been applied yet because


 665     /*
 666      * Called by the delegate to dispatch the event to Java. Event
 667      * coordinates are relative to non-client window are, i.e. the top-left
 668      * point of the client area is (insets.top, insets.left).
 669      */
 670     public void dispatchMouseEvent(int id, long when, int button,
 671                                    int x, int y, int screenX, int screenY,
 672                                    int modifiers, int clickCount, boolean popupTrigger,
 673                                    byte[] bdata)
 674     {
 675         // TODO: fill "bdata" member of AWTEvent
 676         Rectangle r = getBounds();
 677         // findPeerAt() expects parent coordinates
 678         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 679         LWWindowPeer lastWindowPeer =
 680             (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
 681         LWWindowPeer curWindowPeer =
 682             (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
 683 
 684         if (id == MouseEvent.MOUSE_EXITED) {
 685             // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
 686             // to a peer from another window. So we must first check if this peer is
 687             // the same as lastWindowPeer
 688             if (lastWindowPeer == this) {
 689                 if (isEnabled()) {
 690                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 691                                                                 lastWindowPeer);
 692                     postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 693                                              MouseEvent.MOUSE_EXITED, when,
 694                                              modifiers, lp.x, lp.y, screenX,
 695                                              screenY, clickCount, popupTrigger,
 696                                              button));
 697                 }
 698                 lastMouseEventPeer = null;
 699             }
 700         } else {
 701             if (targetPeer != lastMouseEventPeer) {
 702 
 703                 if (id != MouseEvent.MOUSE_DRAGGED || lastMouseEventPeer == null) {
 704                     // lastMouseEventPeer may be null if mouse was out of Java windows
 705                     if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 706                         // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
 707                         // later), in which case lastWindowPeer is another window
 708                         if (lastWindowPeer != this) {
 709                             Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
 710                             // Additionally translate from this to lastWindowPeer coordinates
 711                             Rectangle lr = lastWindowPeer.getBounds();
 712                             oldp.x += r.x - lr.x;
 713                             oldp.y += r.y - lr.y;
 714                             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 715                                                      MouseEvent.MOUSE_EXITED,
 716                                                      when, modifiers,
 717                                                      oldp.x, oldp.y, screenX, screenY,
 718                                                      clickCount, popupTrigger, button));
 719                         } else {
 720                             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 721                             postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 722                                                      MouseEvent.MOUSE_EXITED,
 723                                                      when, modifiers,
 724                                                      oldp.x, oldp.y, screenX, screenY,
 725                                                      clickCount, popupTrigger, button));
 726                         }

 727                     }
 728                     if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
 729                         Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
 730                         postEvent(new MouseEvent(targetPeer.getTarget(),
 731                                                  MouseEvent.MOUSE_ENTERED,
 732                                                  when, modifiers,
 733                                                  newp.x, newp.y, screenX, screenY,
 734                                                  clickCount, popupTrigger, button));





 735                     }








 736                 }
 737                 lastMouseEventPeer = targetPeer;
 738             }
 739             // TODO: fill "bdata" member of AWTEvent
 740 
 741             int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
 742             int otherButtonsPressed = modifiers & ~eventButtonMask;
 743 
 744             // For pressed/dragged/released events OS X treats other
 745             // mouse buttons as if they were BUTTON2, so we do the same
 746             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 747 
 748             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 749             // mouse even when dragging. That's why we first update lastMouseEventPeer
 750             // based on initial targetPeer value and only then recalculate targetPeer
 751             // for MOUSE_DRAGGED/RELEASED events
 752             if (id == MouseEvent.MOUSE_PRESSED) {
 753 
 754                 // Ungrab only if this window is not an owned window of the grabbing one.
 755                 if (!isGrabbing() && grabbingWindow != null &&
 756                     grabbingWindow != getOwnerFrameDialog(this))
 757                 {


 804                                                   screenX, screenY, clickCount,
 805                                                   popupTrigger, button);
 806                 postEvent(event);
 807             }
 808 
 809             if (id == MouseEvent.MOUSE_RELEASED) {
 810                 if ((mouseClickButtons & eventButtonMask) != 0
 811                     && targetPeer.isEnabled()) {
 812                     postEvent(new MouseEvent(targetPeer.getTarget(),
 813                                              MouseEvent.MOUSE_CLICKED,
 814                                              when, modifiers,
 815                                              lp.x, lp.y, screenX, screenY,
 816                                              clickCount, popupTrigger, button));
 817                 }
 818                 mouseClickButtons &= ~eventButtonMask;
 819             }
 820         }
 821         notifyUpdateCursor();
 822     }
 823 











































 824     public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
 825                                         int scrollType, int scrollAmount,
 826                                         int wheelRotation, double preciseWheelRotation,
 827                                         byte[] bdata)
 828     {
 829         // TODO: could we just use the last mouse event target here?
 830         Rectangle r = getBounds();
 831         // findPeerAt() expects parent coordinates
 832         final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 833         if (targetPeer == null || !targetPeer.isEnabled()) {
 834             return;
 835         }
 836 
 837         Point lp = targetPeer.windowToLocal(x, y, this);
 838         // TODO: fill "bdata" member of AWTEvent
 839         // TODO: screenX/screenY
 840         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 841                                       MouseEvent.MOUSE_WHEEL,
 842                                       when, modifiers,
 843                                       lp.x, lp.y,




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;
  40 import sun.java2d.pipe.Region;
  41 import sun.lwawt.macosx.CPlatformWindow;
  42 import sun.util.logging.PlatformLogger;
  43 
  44 public class LWWindowPeer
  45     extends LWContainerPeer<Window, JComponent>
  46     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  47 {
  48     public static enum PeerType {
  49         SIMPLEWINDOW,
  50         FRAME,
  51         DIALOG,
  52         EMBEDDEDFRAME
  53     }
  54 
  55     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  56 
  57     private PlatformWindow platformWindow;
  58 
  59     // Window bounds reported by the native system (as opposed to
  60     // regular bounds inherited from LWComponentPeer which are
  61     // requested by user and may haven't been applied yet because


 666     /*
 667      * Called by the delegate to dispatch the event to Java. Event
 668      * coordinates are relative to non-client window are, i.e. the top-left
 669      * point of the client area is (insets.top, insets.left).
 670      */
 671     public void dispatchMouseEvent(int id, long when, int button,
 672                                    int x, int y, int screenX, int screenY,
 673                                    int modifiers, int clickCount, boolean popupTrigger,
 674                                    byte[] bdata)
 675     {
 676         // TODO: fill "bdata" member of AWTEvent
 677         Rectangle r = getBounds();
 678         // findPeerAt() expects parent coordinates
 679         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 680         LWWindowPeer lastWindowPeer =
 681             (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
 682         LWWindowPeer curWindowPeer =
 683             (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
 684 
 685         if (id == MouseEvent.MOUSE_EXITED) {
 686             // We always send the MOUSE_EXITED event to the lastWindowPeer
 687             if (lastWindowPeer != null) {
 688                 if (lastWindowPeer.isEnabled()) {


 689                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 690                             lastWindowPeer);
 691                     postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 692                             MouseEvent.MOUSE_EXITED, when,
 693                             modifiers, lp.x, lp.y, screenX,
 694                             screenY, clickCount, popupTrigger,
 695                             button));
 696                 }
 697                 lastMouseEventPeer = null;
 698             }
 699         } else if(id == MouseEvent.MOUSE_ENTERED) {
 700             if (targetPeer != null) {
 701                 if (targetPeer.isEnabled()) {
 702                     Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
 703                     postEvent(new MouseEvent(targetPeer.getTarget(),
 704                             MouseEvent.MOUSE_ENTERED, when,
 705                             modifiers, lp.x, lp.y, screenX,
 706                             screenY, clickCount, popupTrigger,
 707                             button));

















 708                 }
 709                 lastMouseEventPeer = targetPeer;
 710             }
 711         } else {
 712             CPlatformWindow topmostPlatforWindow =
 713                     CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
 714             LWWindowPeer topmostWindowPeer =
 715                     topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 716 
 717             if (topmostWindowPeer == curWindowPeer) {
 718                 // current window is the topmost window under mouse
 719                 if (targetPeer != lastMouseEventPeer) {
 720                     generateMouseEnterExitEventsForComponents(when, button, x, y,
 721                             screenX, screenY, modifiers, clickCount, popupTrigger,
 722                             lastWindowPeer, curWindowPeer, targetPeer);
 723                 }
 724             } else {
 725                 // the topmost window under mouse is differ from the current window
 726                 LWComponentPeer topmostTargetPeer =
 727                         topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
 728                 if (topmostTargetPeer != lastMouseEventPeer) {
 729                     generateMouseEnterExitEventsForComponents(when, button, x, y,
 730                             screenX, screenY, modifiers, clickCount, popupTrigger,
 731                             lastWindowPeer, topmostWindowPeer, topmostTargetPeer);
 732                 }

 733             }
 734             // TODO: fill "bdata" member of AWTEvent
 735 
 736             int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
 737             int otherButtonsPressed = modifiers & ~eventButtonMask;
 738 
 739             // For pressed/dragged/released events OS X treats other
 740             // mouse buttons as if they were BUTTON2, so we do the same
 741             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 742 
 743             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 744             // mouse even when dragging. That's why we first update lastMouseEventPeer
 745             // based on initial targetPeer value and only then recalculate targetPeer
 746             // for MOUSE_DRAGGED/RELEASED events
 747             if (id == MouseEvent.MOUSE_PRESSED) {
 748 
 749                 // Ungrab only if this window is not an owned window of the grabbing one.
 750                 if (!isGrabbing() && grabbingWindow != null &&
 751                     grabbingWindow != getOwnerFrameDialog(this))
 752                 {


 799                                                   screenX, screenY, clickCount,
 800                                                   popupTrigger, button);
 801                 postEvent(event);
 802             }
 803 
 804             if (id == MouseEvent.MOUSE_RELEASED) {
 805                 if ((mouseClickButtons & eventButtonMask) != 0
 806                     && targetPeer.isEnabled()) {
 807                     postEvent(new MouseEvent(targetPeer.getTarget(),
 808                                              MouseEvent.MOUSE_CLICKED,
 809                                              when, modifiers,
 810                                              lp.x, lp.y, screenX, screenY,
 811                                              clickCount, popupTrigger, button));
 812                 }
 813                 mouseClickButtons &= ~eventButtonMask;
 814             }
 815         }
 816         notifyUpdateCursor();
 817     }
 818 
 819     private void generateMouseEnterExitEventsForComponents(long when,
 820             int button, int x, int y, int screenX, int screenY,
 821             int modifiers, int clickCount, boolean popupTrigger,
 822             LWWindowPeer lastWindowPeer,
 823             LWWindowPeer targetWindowPeer, LWComponentPeer targetPeer) {
 824 
 825         // Generate Mouse Exit for components
 826         if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 827             // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
 828             // later), in which case lastWindowPeer is another window
 829             if (lastWindowPeer != targetWindowPeer) {
 830                 Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
 831                 // Additionally translate from this to lastWindowPeer coordinates
 832                 Rectangle r = getBounds();
 833                 Rectangle lr = lastWindowPeer.getBounds();
 834                 oldp.x += r.x - lr.x;
 835                 oldp.y += r.y - lr.y;
 836                 postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 837                         MouseEvent.MOUSE_EXITED,
 838                         when, modifiers,
 839                         oldp.x, oldp.y, screenX, screenY,
 840                         clickCount, popupTrigger, button));
 841             } else {
 842                 Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
 843                 postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
 844                         MouseEvent.MOUSE_EXITED,
 845                         when, modifiers,
 846                         oldp.x, oldp.y, screenX, screenY,
 847                         clickCount, popupTrigger, button));
 848             }
 849         }
 850         lastMouseEventPeer = targetPeer;
 851         // Generate Mouse Enter for components
 852         if (targetPeer != null && targetPeer.isEnabled()) {
 853             Point newp = targetPeer.windowToLocal(x, y, targetWindowPeer);
 854             postEvent(new MouseEvent(targetPeer.getTarget(),
 855                     MouseEvent.MOUSE_ENTERED,
 856                     when, modifiers,
 857                     newp.x, newp.y, screenX, screenY,
 858                     clickCount, popupTrigger, button));
 859         }
 860     }
 861 
 862     public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
 863                                         int scrollType, int scrollAmount,
 864                                         int wheelRotation, double preciseWheelRotation,
 865                                         byte[] bdata)
 866     {
 867         // TODO: could we just use the last mouse event target here?
 868         Rectangle r = getBounds();
 869         // findPeerAt() expects parent coordinates
 870         final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 871         if (targetPeer == null || !targetPeer.isEnabled()) {
 872             return;
 873         }
 874 
 875         Point lp = targetPeer.windowToLocal(x, y, this);
 876         // TODO: fill "bdata" member of AWTEvent
 877         // TODO: screenX/screenY
 878         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 879                                       MouseEvent.MOUSE_WHEEL,
 880                                       when, modifiers,
 881                                       lp.x, lp.y,