src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java

Print this page




  34 
  35 import javax.swing.*;
  36 
  37 import sun.awt.*;
  38 import sun.awt.AWTAccessor.ComponentAccessor;
  39 import sun.java2d.SurfaceData;
  40 import sun.java2d.opengl.CGLSurfaceData;
  41 import sun.lwawt.*;
  42 import sun.util.logging.PlatformLogger;
  43 
  44 import com.apple.laf.*;
  45 import com.apple.laf.ClientPropertyApplicator.Property;
  46 import com.sun.awt.AWTUtilities;
  47 
  48 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  49     private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
  50     private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
  51     private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
  52     private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
  53     private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);


  54     private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
  55     private static native void nativePushNSWindowToBack(long nsWindowPtr);
  56     private static native void nativePushNSWindowToFront(long nsWindowPtr);
  57     private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
  58     private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
  59     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
  60     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
  61     private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
  62     private static native void nativeSynthesizeMouseEnteredExitedEvents();
  63     private static native void nativeDispose(long nsWindowPtr);
  64     private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
  65     private static native void nativeEnterFullScreenMode(long nsWindowPtr);
  66     private static native void nativeExitFullScreenMode(long nsWindowPtr);
  67 
  68     // Loger to report issues happened during execution but that do not affect functionality
  69     private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
  70     private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
  71 
  72     // for client properties
  73     public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";


 229 
 230         final int styleBits = getInitialStyleBits();
 231 
 232         responder = createPlatformResponder();
 233         contentView = createContentView();
 234         contentView.initialize(peer, responder);
 235 
 236         final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
 237         Rectangle bounds;
 238         if (!IS(DECORATED, styleBits)) {
 239             // For undecorated frames the move/resize event does not come if the frame is centered on the screen
 240             // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
 241             bounds = new Rectangle(0, 0, 1, 1);
 242         } else {
 243             bounds = _peer.constrainBounds(_target.getBounds());
 244         }
 245         final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
 246                 ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
 247         setPtr(nativeWindowPtr);
 248 








 249         if (target instanceof javax.swing.RootPaneContainer) {
 250             final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
 251             if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
 252                 public void propertyChange(final PropertyChangeEvent evt) {
 253                     CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
 254                     rootpane.removePropertyChangeListener("ancestor", this);
 255                 }
 256             });
 257         }
 258 
 259         validateSurface();
 260     }
 261 
 262     protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
 263         this.peer = peer;
 264         this.target = target;
 265         if (owner instanceof CPlatformWindow) {
 266             this.owner = (CPlatformWindow)owner;
 267         }
 268         this.contentView = view;


 457     public GraphicsDevice getGraphicsDevice() {
 458         return contentView.getGraphicsDevice();
 459     }
 460 
 461     @Override // PlatformWindow
 462     public SurfaceData getScreenSurface() {
 463         // TODO: not implemented
 464         return null;
 465     }
 466 
 467     @Override // PlatformWindow
 468     public SurfaceData replaceSurfaceData() {
 469         return contentView.replaceSurfaceData();
 470     }
 471 
 472     @Override // PlatformWindow
 473     public void setBounds(int x, int y, int w, int h) {
 474         nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
 475     }
 476 




 477     private boolean isMaximized() {
 478         return undecorated ? this.normalBounds != null
 479                 : CWrapper.NSWindow.isZoomed(getNSWindowPtr());
 480     }
 481 
 482     private void maximize() {
 483         if (peer == null || isMaximized()) {
 484             return;
 485         }
 486         if (!undecorated) {
 487             CWrapper.NSWindow.zoom(getNSWindowPtr());
 488         } else {
 489             deliverZoom(true);
 490 
 491             // We need an up to date size of the peer, so we flush the native events
 492             // to be sure that there are no setBounds requests in the queue.
 493             LWCToolkit.flushNativeSelectors();
 494             this.normalBounds = peer.getBounds();
 495 
 496             GraphicsConfiguration config = getPeer().getGraphicsConfiguration();


 966 
 967     private void deliverWindowClosingEvent() {
 968         if (peer != null && peer.getBlocker() == null) {
 969             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 970         }
 971     }
 972 
 973     private void deliverIconify(final boolean iconify) {
 974         if (peer != null) {
 975             peer.notifyIconify(iconify);
 976         }
 977     }
 978 
 979     private void deliverZoom(final boolean isZoomed) {
 980         if (peer != null) {
 981             peer.notifyZoom(isZoomed);
 982         }
 983     }
 984 
 985     private void checkZoom() {
 986         if (target instanceof Frame && isVisible()) {
 987             Frame targetFrame = (Frame)target;
 988             if (targetFrame.getExtendedState() != Frame.MAXIMIZED_BOTH && isMaximized()) {
 989                 deliverZoom(true);
 990             } else if (targetFrame.getExtendedState() == Frame.MAXIMIZED_BOTH && !isMaximized()) {
 991                 deliverZoom(false);
 992             }
 993         }
 994     }
 995 
 996     private void deliverNCMouseDown() {
 997         if (peer != null) {
 998             peer.notifyNCMouseDown();
 999         }
1000     }
1001 
1002     /*
1003      * Our focus model is synthetic and only non-simple window
1004      * may become natively focusable window.
1005      */
1006     private boolean isNativelyFocusableWindow() {
1007         if (peer == null) {
1008             return false;
1009         }
1010 
1011         return !peer.isSimpleWindow() && target.getFocusableWindowState();
1012     }
1013 
1014     /*




  34 
  35 import javax.swing.*;
  36 
  37 import sun.awt.*;
  38 import sun.awt.AWTAccessor.ComponentAccessor;
  39 import sun.java2d.SurfaceData;
  40 import sun.java2d.opengl.CGLSurfaceData;
  41 import sun.lwawt.*;
  42 import sun.util.logging.PlatformLogger;
  43 
  44 import com.apple.laf.*;
  45 import com.apple.laf.ClientPropertyApplicator.Property;
  46 import com.sun.awt.AWTUtilities;
  47 
  48 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  49     private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
  50     private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
  51     private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
  52     private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
  53     private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
  54     private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
  55             double x, double y, double w, double h);
  56     private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
  57     private static native void nativePushNSWindowToBack(long nsWindowPtr);
  58     private static native void nativePushNSWindowToFront(long nsWindowPtr);
  59     private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
  60     private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
  61     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
  62     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
  63     private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
  64     private static native void nativeSynthesizeMouseEnteredExitedEvents();
  65     private static native void nativeDispose(long nsWindowPtr);
  66     private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
  67     private static native void nativeEnterFullScreenMode(long nsWindowPtr);
  68     private static native void nativeExitFullScreenMode(long nsWindowPtr);
  69 
  70     // Loger to report issues happened during execution but that do not affect functionality
  71     private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
  72     private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
  73 
  74     // for client properties
  75     public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";


 231 
 232         final int styleBits = getInitialStyleBits();
 233 
 234         responder = createPlatformResponder();
 235         contentView = createContentView();
 236         contentView.initialize(peer, responder);
 237 
 238         final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
 239         Rectangle bounds;
 240         if (!IS(DECORATED, styleBits)) {
 241             // For undecorated frames the move/resize event does not come if the frame is centered on the screen
 242             // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
 243             bounds = new Rectangle(0, 0, 1, 1);
 244         } else {
 245             bounds = _peer.constrainBounds(_target.getBounds());
 246         }
 247         final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
 248                 ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
 249         setPtr(nativeWindowPtr);
 250 
 251         _peer.setMaximizedBounds(_peer.getMaximizedBounds());
 252         if (_target instanceof Frame) {
 253             Frame frame = (Frame) _target;
 254             if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
 255                 maximize();
 256             }
 257         }
 258 
 259         if (target instanceof javax.swing.RootPaneContainer) {
 260             final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
 261             if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
 262                 public void propertyChange(final PropertyChangeEvent evt) {
 263                     CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
 264                     rootpane.removePropertyChangeListener("ancestor", this);
 265                 }
 266             });
 267         }
 268 
 269         validateSurface();
 270     }
 271 
 272     protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
 273         this.peer = peer;
 274         this.target = target;
 275         if (owner instanceof CPlatformWindow) {
 276             this.owner = (CPlatformWindow)owner;
 277         }
 278         this.contentView = view;


 467     public GraphicsDevice getGraphicsDevice() {
 468         return contentView.getGraphicsDevice();
 469     }
 470 
 471     @Override // PlatformWindow
 472     public SurfaceData getScreenSurface() {
 473         // TODO: not implemented
 474         return null;
 475     }
 476 
 477     @Override // PlatformWindow
 478     public SurfaceData replaceSurfaceData() {
 479         return contentView.replaceSurfaceData();
 480     }
 481 
 482     @Override // PlatformWindow
 483     public void setBounds(int x, int y, int w, int h) {
 484         nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
 485     }
 486 
 487     public void setMaximizedBounds(int x, int y, int w, int h) {
 488         nativeSetNSWindowStandardFrame(getNSWindowPtr(), x, y, w, h);
 489     }
 490 
 491     private boolean isMaximized() {
 492         return undecorated ? this.normalBounds != null
 493                 : CWrapper.NSWindow.isZoomed(getNSWindowPtr());
 494     }
 495 
 496     private void maximize() {
 497         if (peer == null || isMaximized()) {
 498             return;
 499         }
 500         if (!undecorated) {
 501             CWrapper.NSWindow.zoom(getNSWindowPtr());
 502         } else {
 503             deliverZoom(true);
 504 
 505             // We need an up to date size of the peer, so we flush the native events
 506             // to be sure that there are no setBounds requests in the queue.
 507             LWCToolkit.flushNativeSelectors();
 508             this.normalBounds = peer.getBounds();
 509 
 510             GraphicsConfiguration config = getPeer().getGraphicsConfiguration();


 980 
 981     private void deliverWindowClosingEvent() {
 982         if (peer != null && peer.getBlocker() == null) {
 983             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 984         }
 985     }
 986 
 987     private void deliverIconify(final boolean iconify) {
 988         if (peer != null) {
 989             peer.notifyIconify(iconify);
 990         }
 991     }
 992 
 993     private void deliverZoom(final boolean isZoomed) {
 994         if (peer != null) {
 995             peer.notifyZoom(isZoomed);
 996         }
 997     }
 998 
 999     private void checkZoom() {
1000         int state = peer.getState();
1001         if (state != Frame.MAXIMIZED_BOTH && isMaximized()) {

1002             deliverZoom(true);
1003         } else if (state == Frame.MAXIMIZED_BOTH && !isMaximized()) {
1004             deliverZoom(false);
1005         }
1006     }

1007 
1008     private void deliverNCMouseDown() {
1009         if (peer != null) {
1010             peer.notifyNCMouseDown();
1011         }
1012     }
1013 
1014     /*
1015      * Our focus model is synthetic and only non-simple window
1016      * may become natively focusable window.
1017      */
1018     private boolean isNativelyFocusableWindow() {
1019         if (peer == null) {
1020             return false;
1021         }
1022 
1023         return !peer.isSimpleWindow() && target.getFocusableWindowState();
1024     }
1025 
1026     /*