jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java
changeset 14753 a56a685d137f
parent 14647 bacc2d4f4b27
child 15331 410070becfef
equal deleted inserted replaced
14659:cda39b3e7f15 14753:a56a685d137f
    24  */
    24  */
    25 
    25 
    26 package sun.lwawt.macosx;
    26 package sun.lwawt.macosx;
    27 
    27 
    28 import java.awt.*;
    28 import java.awt.*;
       
    29 import java.awt.geom.Rectangle2D;
       
    30 import java.awt.image.VolatileImage;
    29 
    31 
    30 import sun.awt.CGraphicsConfig;
    32 import sun.awt.CGraphicsConfig;
       
    33 import sun.awt.CGraphicsEnvironment;
    31 import sun.lwawt.LWWindowPeer;
    34 import sun.lwawt.LWWindowPeer;
    32 import sun.lwawt.macosx.event.NSEvent;
    35 import sun.lwawt.macosx.event.NSEvent;
    33 
    36 
    34 import sun.java2d.SurfaceData;
    37 import sun.java2d.SurfaceData;
    35 import sun.java2d.opengl.CGLLayer;
    38 import sun.java2d.opengl.CGLLayer;
    36 import sun.java2d.opengl.CGLSurfaceData;
    39 import sun.java2d.opengl.CGLSurfaceData;
    37 
    40 
    38 public class CPlatformView extends CFRetainedResource {
    41 public class CPlatformView extends CFRetainedResource {
    39     private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
    42     private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
       
    43     private static native void nativeSetAutoResizable(long awtView, boolean toResize);
       
    44     private static native int nativeGetNSViewDisplayID(long awtView);
       
    45     private static native Rectangle2D nativeGetLocationOnScreen(long awtView);
       
    46     private static native boolean nativeIsViewUnderMouse(long ptr);
    40 
    47 
    41     private LWWindowPeer peer;
    48     private LWWindowPeer peer;
    42     private SurfaceData surfaceData;
    49     private SurfaceData surfaceData;
    43     private CGLLayer windowLayer;
    50     private CGLLayer windowLayer;
    44     private CPlatformResponder responder;
    51     private CPlatformResponder responder;
    57         setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
    64         setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
    58     }
    65     }
    59 
    66 
    60     public long getAWTView() {
    67     public long getAWTView() {
    61         return ptr;
    68         return ptr;
    62     }
    69         }
    63 
    70 
    64     public boolean isOpaque() {
    71     public boolean isOpaque() {
    65         return !peer.isTranslucent();
    72         return !peer.isTranslucent();
    66     }
    73     }
    67 
    74 
   156         } else {
   163         } else {
   157             return 0;
   164             return 0;
   158         }
   165         }
   159     }
   166     }
   160 
   167 
       
   168     public void setAutoResizable(boolean toResize) {
       
   169         nativeSetAutoResizable(this.getAWTView(), toResize);
       
   170     }
       
   171 
       
   172     public boolean isUnderMouse() {
       
   173         return nativeIsViewUnderMouse(getAWTView());
       
   174     }
       
   175 
       
   176     public GraphicsDevice getGraphicsDevice() {
       
   177         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
       
   178         CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
       
   179         int displayID = nativeGetNSViewDisplayID(getAWTView());
       
   180         GraphicsDevice gd = cge.getScreenDevice(displayID);
       
   181         if (gd == null) {
       
   182             // this could possibly happen during device removal
       
   183             // use the default screen device in this case
       
   184             gd = ge.getDefaultScreenDevice();
       
   185         }
       
   186         return gd;
       
   187     }
       
   188 
       
   189     public Point getLocationOnScreen() {
       
   190         Rectangle r = nativeGetLocationOnScreen(this.getAWTView()).getBounds();
       
   191         return new Point(r.x, r.y);
       
   192     }
       
   193 
   161     // ----------------------------------------------------------------------
   194     // ----------------------------------------------------------------------
   162     // NATIVE CALLBACKS
   195     // NATIVE CALLBACKS
   163     // ----------------------------------------------------------------------
   196     // ----------------------------------------------------------------------
       
   197 
       
   198     /*
       
   199      * The callback is called only in the embedded case when the view is
       
   200      * automatically resized by the superview.
       
   201      * In normal mode this method is never called.
       
   202      */
       
   203     private void deliverResize(int x, int y, int w, int h) {
       
   204         peer.notifyReshape(x, y, w, h);
       
   205     }
       
   206 
   164 
   207 
   165     private void deliverMouseEvent(NSEvent event) {
   208     private void deliverMouseEvent(NSEvent event) {
   166         int x = event.getX();
   209         int x = event.getX();
   167         int y = getBounds().height - event.getY();
   210         int y = getBounds().height - event.getY();
   168 
   211