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

Print this page




  29 import java.awt.*;
  30 import java.awt.Dialog.ModalityType;
  31 import java.awt.event.*;
  32 import java.awt.peer.WindowPeer;
  33 import java.beans.*;
  34 import java.util.List;
  35 
  36 import javax.swing.*;
  37 
  38 import sun.awt.*;
  39 import sun.java2d.SurfaceData;
  40 import sun.java2d.opengl.CGLSurfaceData;
  41 import sun.lwawt.*;
  42 import sun.lwawt.LWWindowPeer.PeerType;
  43 import sun.util.logging.PlatformLogger;
  44 
  45 import com.apple.laf.*;
  46 import com.apple.laf.ClientPropertyApplicator.Property;
  47 import com.sun.awt.AWTUtilities;
  48 
  49 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  50     private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
  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 nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
  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 
  68     private static native int nativeGetNSWindowDisplayID(long nsWindowPtr);
  69 


 182             if (value == null || !(value instanceof java.io.File)) {
 183                 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
 184                 return;
 185             }
 186 
 187             final String filename = ((java.io.File)value).getAbsolutePath();
 188             nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
 189         }}
 190     }) {
 191         public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
 192             Component root = SwingUtilities.getRoot(p);
 193             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 194             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 195         }
 196     };
 197 
 198     // Bounds of the native widget but in the Java coordinate system.
 199     // In order to keep it up-to-date we will update them on
 200     // 1) setting native bounds via nativeSetBounds() call
 201     // 2) getting notification from the native level via deliverMoveResizeEvent()
 202     private Rectangle nativeBounds;
 203     private volatile boolean isFullScreenMode = false;
 204 
 205     private Window target;
 206     private LWWindowPeer peer;
 207     private CPlatformView contentView;
 208     private CPlatformWindow owner;
 209     private boolean visible = false; // visibility status from native perspective
 210     private boolean undecorated; // initialized in getInitialStyleBits()
 211     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
 212     private CPlatformResponder responder;
 213     private volatile boolean zoomed = false; // from native perspective
 214 
 215     public CPlatformWindow(final PeerType peerType) {
 216         super(0, true);
 217         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 218     }
 219 
 220     /*
 221      * Delegate initialization (create native window and all the
 222      * related resources).


 852     public LWWindowPeer getPeer() {
 853         return peer;
 854     }
 855 
 856     public CPlatformView getContentView() {
 857         return contentView;
 858     }
 859 
 860     @Override
 861     public long getLayerPtr() {
 862         return contentView.getWindowLayerPtr();
 863     }
 864 
 865     private void validateSurface() {
 866         SurfaceData surfaceData = getSurfaceData();
 867         if (surfaceData instanceof CGLSurfaceData) {
 868             ((CGLSurfaceData)surfaceData).validate();
 869         }
 870     }
 871 






 872     /*************************************************************
 873      * Callbacks from the AWTWindow and AWTView objc classes.
 874      *************************************************************/
 875     private void deliverWindowFocusEvent(boolean gained){
 876         // Fix for 7150349: ingore "gained" notifications when the app is inactive.
 877         if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
 878             focusLogger.fine("the app is inactive, so the notification is ignored");
 879             return;
 880         }
 881         responder.handleWindowFocusEvent(gained);
 882     }
 883 
 884     private void deliverMoveResizeEvent(int x, int y, int width, int height) {
 885         // when the content view enters the full-screen mode, the native
 886         // move/resize notifications contain a bounds smaller than
 887         // the whole screen and therefore we ignore the native notifications
 888         // and the content view itself creates correct synthetic notifications
 889         if (isFullScreenMode) return;


 890 

 891         nativeBounds = new Rectangle(x, y, width, height);
 892         peer.notifyReshape(x, y, width, height);



 893         //TODO validateSurface already called from notifyReshape
 894         validateSurface();
 895     }
 896 
 897     private void deliverWindowClosingEvent() {
 898         if (peer.getBlocker() == null)  {
 899             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 900         }
 901     }
 902 
 903     private void deliverIconify(final boolean iconify) {
 904         peer.notifyIconify(iconify);
 905     }
 906 
 907     private void deliverZoom(final boolean isZoomed) {
 908         peer.notifyZoom(isZoomed);
 909     }
 910 
 911     private void deliverNCMouseDown() {
 912         peer.notifyNCMouseDown();




  29 import java.awt.*;
  30 import java.awt.Dialog.ModalityType;
  31 import java.awt.event.*;
  32 import java.awt.peer.WindowPeer;
  33 import java.beans.*;
  34 import java.util.List;
  35 
  36 import javax.swing.*;
  37 
  38 import sun.awt.*;
  39 import sun.java2d.SurfaceData;
  40 import sun.java2d.opengl.CGLSurfaceData;
  41 import sun.lwawt.*;
  42 import sun.lwawt.LWWindowPeer.PeerType;
  43 import sun.util.logging.PlatformLogger;
  44 
  45 import com.apple.laf.*;
  46 import com.apple.laf.ClientPropertyApplicator.Property;
  47 import com.sun.awt.AWTUtilities;
  48 
  49 public final class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  50     private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
  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 nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
  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 
  68     private static native int nativeGetNSWindowDisplayID(long nsWindowPtr);
  69 


 182             if (value == null || !(value instanceof java.io.File)) {
 183                 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
 184                 return;
 185             }
 186 
 187             final String filename = ((java.io.File)value).getAbsolutePath();
 188             nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
 189         }}
 190     }) {
 191         public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
 192             Component root = SwingUtilities.getRoot(p);
 193             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 194             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 195         }
 196     };
 197 
 198     // Bounds of the native widget but in the Java coordinate system.
 199     // In order to keep it up-to-date we will update them on
 200     // 1) setting native bounds via nativeSetBounds() call
 201     // 2) getting notification from the native level via deliverMoveResizeEvent()
 202     private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
 203     private volatile boolean isFullScreenMode = false;
 204 
 205     private Window target;
 206     private LWWindowPeer peer;
 207     private CPlatformView contentView;
 208     private CPlatformWindow owner;
 209     private boolean visible = false; // visibility status from native perspective
 210     private boolean undecorated; // initialized in getInitialStyleBits()
 211     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
 212     private CPlatformResponder responder;
 213     private volatile boolean zoomed = false; // from native perspective
 214 
 215     public CPlatformWindow(final PeerType peerType) {
 216         super(0, true);
 217         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 218     }
 219 
 220     /*
 221      * Delegate initialization (create native window and all the
 222      * related resources).


 852     public LWWindowPeer getPeer() {
 853         return peer;
 854     }
 855 
 856     public CPlatformView getContentView() {
 857         return contentView;
 858     }
 859 
 860     @Override
 861     public long getLayerPtr() {
 862         return contentView.getWindowLayerPtr();
 863     }
 864 
 865     private void validateSurface() {
 866         SurfaceData surfaceData = getSurfaceData();
 867         if (surfaceData instanceof CGLSurfaceData) {
 868             ((CGLSurfaceData)surfaceData).validate();
 869         }
 870     }
 871 
 872     private void flushBuffers() {
 873         if (isVisible() && !nativeBounds.isEmpty()) {
 874             LWCToolkit.getLWCToolkit().flushPendingEventsOnAppkit(target);
 875         }
 876     }
 877 
 878     /*************************************************************
 879      * Callbacks from the AWTWindow and AWTView objc classes.
 880      *************************************************************/
 881     private void deliverWindowFocusEvent(boolean gained){
 882         // Fix for 7150349: ingore "gained" notifications when the app is inactive.
 883         if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
 884             focusLogger.fine("the app is inactive, so the notification is ignored");
 885             return;
 886         }
 887         responder.handleWindowFocusEvent(gained);
 888     }
 889 
 890     private void deliverMoveResizeEvent(int x, int y, int width, int height) {
 891         // when the content view enters the full-screen mode, the native
 892         // move/resize notifications contain a bounds smaller than
 893         // the whole screen and therefore we ignore the native notifications
 894         // and the content view itself creates correct synthetic notifications
 895         if (isFullScreenMode) {
 896             return;
 897         }
 898 
 899         final Rectangle oldB = nativeBounds;
 900         nativeBounds = new Rectangle(x, y, width, height);
 901         peer.notifyReshape(x, y, width, height);
 902         if (!oldB.getSize().equals(nativeBounds.getSize()) ) {
 903             flushBuffers();
 904         }
 905         //TODO validateSurface already called from notifyReshape
 906         validateSurface();
 907     }
 908 
 909     private void deliverWindowClosingEvent() {
 910         if (peer.getBlocker() == null)  {
 911             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 912         }
 913     }
 914 
 915     private void deliverIconify(final boolean iconify) {
 916         peer.notifyIconify(iconify);
 917     }
 918 
 919     private void deliverZoom(final boolean isZoomed) {
 920         peer.notifyZoom(isZoomed);
 921     }
 922 
 923     private void deliverNCMouseDown() {
 924         peer.notifyNCMouseDown();