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

Print this page




 175         new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
 176             nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
 177         }},
 178         new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
 179             if (value == null || !(value instanceof java.io.File)) {
 180                 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
 181                 return;
 182             }
 183 
 184             final String filename = ((java.io.File)value).getAbsolutePath();
 185             nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
 186         }}
 187     }) {
 188         public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
 189             Component root = SwingUtilities.getRoot(p);
 190             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 191             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 192         }
 193     };
 194 


 195     // Bounds of the native widget but in the Java coordinate system.
 196     // In order to keep it up-to-date we will update them on
 197     // 1) setting native bounds via nativeSetBounds() call
 198     // 2) getting notification from the native level via deliverMoveResizeEvent()
 199     private Rectangle nativeBounds;
 200     private volatile boolean isFullScreenMode = false;

 201 
 202     private Window target;
 203     private LWWindowPeer peer;
 204     private CPlatformView contentView;
 205     private CPlatformWindow owner;
 206 
 207     public CPlatformWindow(final PeerType peerType) {
 208         super(0, true);
 209         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 210     }
 211 
 212     /*
 213      * Delegate initialization (create native window and all the
 214      * related resources).
 215      */
 216     @Override // PlatformWindow
 217     public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
 218         this.peer = _peer;
 219         this.target = _target;
 220         if (_owner instanceof CPlatformWindow) {


 637 
 638     @Override
 639     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 640         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 641     }
 642 
 643     @Override
 644     public void setOpacity(float opacity) {
 645         CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
 646     }
 647 
 648     @Override
 649     public void setOpaque(boolean isOpaque) {
 650         CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
 651         if (!isOpaque) {
 652             long clearColor = CWrapper.NSColor.clearColor();
 653             CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
 654         }
 655     }
 656 
















 657     @Override
 658     public void enterFullScreenMode() {


 659         isFullScreenMode = true;
 660         contentView.enterFullScreenMode(getNSWindowPtr());



 661     }
 662 
 663     @Override
 664     public void exitFullScreenMode() {
 665         contentView.exitFullScreenMode();



 666         isFullScreenMode = false;
 667     }


 668 
 669     @Override
 670     public void setWindowState(int windowState) {
 671         if (!peer.isVisible()) {
 672             // setVisible() applies the state
 673             return;
 674         }
 675 
 676         int prevWindowState = peer.getState();
 677         if (prevWindowState == windowState) return;
 678 
 679         final long nsWindowPtr = getNSWindowPtr();
 680         switch (windowState) {
 681             case Frame.ICONIFIED:
 682                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 683                     // let's return into the normal states first
 684                     // the zoom call toggles between the normal and the max states
 685                     CWrapper.NSWindow.zoom(nsWindowPtr);
 686                 }
 687                 CWrapper.NSWindow.miniaturize(nsWindowPtr);


 746     @Override
 747     public long getLayerPtr() {
 748         return contentView.getWindowLayerPtr();
 749     }
 750 
 751     private void validateSurface() {
 752         SurfaceData surfaceData = getSurfaceData();
 753         if (surfaceData instanceof CGLSurfaceData) {
 754             ((CGLSurfaceData)surfaceData).validate();
 755         }
 756     }
 757 
 758     /*************************************************************
 759      * Callbacks from the AWTWindow and AWTView objc classes.
 760      *************************************************************/
 761     private void deliverWindowFocusEvent(boolean gained){
 762         peer.notifyActivation(gained);
 763     }
 764 
 765     private void deliverMoveResizeEvent(int x, int y, int width, int height) {
 766         // when the content view enters the full-screen mode, the native
 767         // move/resize notifications contain a bounds smaller than
 768         // the whole screen and therefore we ignore the native notifications
 769         // and the content view itself creates correct synthetic notifications
 770         if (isFullScreenMode) return;
 771 
 772         nativeBounds = new Rectangle(x, y, width, height);
 773         peer.notifyReshape(x, y, width, height);
 774         //TODO validateSurface already called from notifyReshape
 775         validateSurface();
 776     }
 777 
 778     private void deliverWindowClosingEvent() {
 779         if (peer.getBlocker() == null)  {
 780             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 781         }
 782     }
 783 
 784     private void deliverIconify(final boolean iconify) {
 785         peer.notifyIconify(iconify);
 786     }
 787 
 788     private void deliverZoom(final boolean isZoomed) {
 789         peer.notifyZoom(isZoomed);
 790     }
 791 




 175         new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
 176             nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
 177         }},
 178         new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
 179             if (value == null || !(value instanceof java.io.File)) {
 180                 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
 181                 return;
 182             }
 183 
 184             final String filename = ((java.io.File)value).getAbsolutePath();
 185             nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
 186         }}
 187     }) {
 188         public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
 189             Component root = SwingUtilities.getRoot(p);
 190             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 191             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 192         }
 193     };
 194 
 195     private final Object LOCK = new Object(){};
 196 
 197     // Bounds of the native widget but in the Java coordinate system.
 198     // In order to keep it up-to-date we will update them on
 199     // 1) setting native bounds via nativeSetBounds() call
 200     // 2) getting notification from the native level via deliverMoveResizeEvent()
 201     private Rectangle nativeBounds;
 202 
 203     private boolean isFullScreenMode = false; // synchronized on the LOCK
 204 
 205     private Window target;
 206     private LWWindowPeer peer;
 207     private CPlatformView contentView;
 208     private CPlatformWindow owner;
 209 
 210     public CPlatformWindow(final PeerType peerType) {
 211         super(0, true);
 212         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 213     }
 214 
 215     /*
 216      * Delegate initialization (create native window and all the
 217      * related resources).
 218      */
 219     @Override // PlatformWindow
 220     public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
 221         this.peer = _peer;
 222         this.target = _target;
 223         if (_owner instanceof CPlatformWindow) {


 640 
 641     @Override
 642     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 643         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 644     }
 645 
 646     @Override
 647     public void setOpacity(float opacity) {
 648         CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
 649     }
 650 
 651     @Override
 652     public void setOpaque(boolean isOpaque) {
 653         CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
 654         if (!isOpaque) {
 655             long clearColor = CWrapper.NSColor.clearColor();
 656             CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
 657         }
 658     }
 659 
 660     private void setMenuBarVisibleIfOnPrimaryScreen(boolean visible) {
 661         long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
 662         try {
 663             long primaryScreen = CWrapper.NSScreen.screens_0();
 664             try {
 665                 if (primaryScreen == screen) {
 666                     CWrapper.NSMenu.setMenuBarVisible(visible);
 667                 }
 668             } finally {
 669                 CWrapper.NSObject.release(primaryScreen);
 670             }
 671         } finally {
 672             CWrapper.NSObject.release(screen);
 673         }
 674     }
 675 
 676     @Override
 677     public void enterFullScreenMode() {
 678         synchronized (LOCK) {
 679             if (!isFullScreenMode) {
 680                 isFullScreenMode = true;
 681                 setMenuBarVisibleIfOnPrimaryScreen(false);
 682                 CWrapper.NSWindow.toggleFullScreen(getNSWindowPtr(), 0L);
 683             }
 684         }
 685     }
 686 
 687     @Override
 688     public void exitFullScreenMode() {
 689         synchronized (LOCK) {
 690             if (isFullScreenMode) {
 691                 CWrapper.NSWindow.toggleFullScreen(getNSWindowPtr(), 0L);
 692                 setMenuBarVisibleIfOnPrimaryScreen(true);
 693                 isFullScreenMode = false;
 694             }
 695         }
 696     }
 697 
 698     @Override
 699     public void setWindowState(int windowState) {
 700         if (!peer.isVisible()) {
 701             // setVisible() applies the state
 702             return;
 703         }
 704 
 705         int prevWindowState = peer.getState();
 706         if (prevWindowState == windowState) return;
 707 
 708         final long nsWindowPtr = getNSWindowPtr();
 709         switch (windowState) {
 710             case Frame.ICONIFIED:
 711                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 712                     // let's return into the normal states first
 713                     // the zoom call toggles between the normal and the max states
 714                     CWrapper.NSWindow.zoom(nsWindowPtr);
 715                 }
 716                 CWrapper.NSWindow.miniaturize(nsWindowPtr);


 775     @Override
 776     public long getLayerPtr() {
 777         return contentView.getWindowLayerPtr();
 778     }
 779 
 780     private void validateSurface() {
 781         SurfaceData surfaceData = getSurfaceData();
 782         if (surfaceData instanceof CGLSurfaceData) {
 783             ((CGLSurfaceData)surfaceData).validate();
 784         }
 785     }
 786 
 787     /*************************************************************
 788      * Callbacks from the AWTWindow and AWTView objc classes.
 789      *************************************************************/
 790     private void deliverWindowFocusEvent(boolean gained){
 791         peer.notifyActivation(gained);
 792     }
 793 
 794     private void deliverMoveResizeEvent(int x, int y, int width, int height) {






 795         nativeBounds = new Rectangle(x, y, width, height);
 796         peer.notifyReshape(x, y, width, height);
 797         //TODO validateSurface already called from notifyReshape
 798         validateSurface();
 799     }
 800 
 801     private void deliverWindowClosingEvent() {
 802         if (peer.getBlocker() == null)  {
 803             peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
 804         }
 805     }
 806 
 807     private void deliverIconify(final boolean iconify) {
 808         peer.notifyIconify(iconify);
 809     }
 810 
 811     private void deliverZoom(final boolean isZoomed) {
 812         peer.notifyZoom(isZoomed);
 813     }
 814