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

Print this page




  29 import java.awt.Dialog.ModalityType;
  30 import java.awt.event.*;
  31 import java.awt.peer.WindowPeer;
  32 import java.beans.*;
  33 import java.lang.reflect.InvocationTargetException;
  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");


 225      */
 226     @Override // PlatformWindow
 227     public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
 228         initializeBase(_target, _peer, _owner, new CPlatformView());
 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;


 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 




  29 import java.awt.Dialog.ModalityType;
  30 import java.awt.event.*;
  31 import java.awt.peer.WindowPeer;
  32 import java.beans.*;
  33 import java.lang.reflect.InvocationTargetException;
  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,
  50             long styleBits, double x, double y, double w, double h, boolean zoomed);
  51     private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
  52     private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
  53     private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
  54     private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
  55     private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
  56     private static native void nativePushNSWindowToBack(long nsWindowPtr);
  57     private static native void nativePushNSWindowToFront(long nsWindowPtr);
  58     private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
  59     private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
  60     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
  61     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
  62     private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
  63     private static native void nativeSynthesizeMouseEnteredExitedEvents();
  64     private static native void nativeDispose(long nsWindowPtr);
  65     private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
  66     private static native void nativeEnterFullScreenMode(long nsWindowPtr);
  67     private static native void nativeExitFullScreenMode(long nsWindowPtr);
  68 
  69     // Loger to report issues happened during execution but that do not affect functionality
  70     private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");


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


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