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

Print this page


   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  44 import sun.util.logging.PlatformLogger;
  45 
  46 import com.apple.laf.*;
  47 import com.apple.laf.ClientPropertyApplicator.Property;
  48 import com.sun.awt.AWTUtilities;
  49 
  50 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  51     private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
  52     private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
  53     private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
  54     private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
  55     private static native void nativeSetNSWindowBounds(long nsWindowPtr, 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(long nsWindowPtr);
  65     private static native void nativeDispose(long nsWindowPtr);

  66 
  67     // Loger to report issues happened during execution but that do not affect functionality
  68     private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
  69     private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
  70 
  71     // for client properties
  72     public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
  73     public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
  74 
  75     public static final String WINDOW_ALPHA = "Window.alpha";
  76     public static final String WINDOW_SHADOW = "Window.shadow";
  77 
  78     public static final String WINDOW_STYLE = "Window.style";
  79     public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
  80 
  81     public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
  82     public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
  83 
  84     public static final String WINDOW_CLOSEABLE = "Window.closeable";
  85     public static final String WINDOW_MINIMIZABLE = "Window.minimizable";


 576         this.visible = visible;
 577 
 578         // Manage the extended state when showing
 579         if (visible) {
 580             // Apply the extended state as expected in shared code
 581             if (target instanceof Frame) {
 582                 switch (((Frame)target).getExtendedState()) {
 583                     case Frame.ICONIFIED:
 584                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
 585                         break;
 586                     case Frame.MAXIMIZED_BOTH:
 587                         maximize();
 588                         break;
 589                     default: // NORMAL
 590                         unmaximize(); // in case it was maximized, otherwise this is a no-op
 591                         break;
 592                 }
 593             }
 594         }
 595 
 596         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 597 
 598         // Configure stuff #2
 599         updateFocusabilityForAutoRequestFocus(true);
 600 
 601         // Manage parent-child relationship when showing
 602         if (visible) {
 603             // Add myself as a child
 604             if (owner != null && owner.isVisible()) {
 605                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 606                 if (target.isAlwaysOnTop()) {
 607                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 608                 }
 609             }
 610 
 611             // Add my own children to myself
 612             for (Window w : target.getOwnedWindows()) {
 613                 WindowPeer p = (WindowPeer)w.getPeer();
 614                 if (p instanceof LWWindowPeer) {
 615                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 616                     if (pw != null && pw.isVisible()) {


 721         return CWrapper.NSWindow.isKeyWindow(ptr);
 722     }
 723 
 724     @Override
 725     public void updateFocusableWindowState() {
 726         final boolean isFocusable = isNativelyFocusableWindow();
 727         setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
 728     }
 729 
 730     @Override
 731     public Graphics transformGraphics(Graphics g) {
 732         // is this where we can inject a transform for HiDPI?
 733         return g;
 734     }
 735 
 736     @Override
 737     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 738         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 739     }
 740 



 741     @Override
 742     public void setOpacity(float opacity) {
 743         CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
 744     }
 745 
 746     @Override
 747     public void setOpaque(boolean isOpaque) {
 748         CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
 749         boolean isTextured = (peer == null)? false : peer.isTextured();
 750         if (!isOpaque && !isTextured) {
 751             long clearColor = CWrapper.NSColor.clearColor();
 752             CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
 753         }
 754 
 755         //This is a temporary workaround. Looks like after 7124236 will be fixed
 756         //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
 757         SwingUtilities.invokeLater(new Runnable() {
 758             @Override
 759             public void run() {
 760                 invalidateShadow();


 813                 break;
 814             case Frame.MAXIMIZED_BOTH:
 815                 if (prevWindowState == Frame.ICONIFIED) {
 816                     // let's return into the normal states first
 817                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 818                 }
 819                 maximize();
 820                 break;
 821             case Frame.NORMAL:
 822                 if (prevWindowState == Frame.ICONIFIED) {
 823                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 824                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 825                     // the zoom call toggles between the normal and the max states
 826                     unmaximize();
 827                 }
 828                 break;
 829             default:
 830                 throw new RuntimeException("Unknown window state: " + windowState);
 831         }
 832 
 833         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 834 
 835         // NOTE: the SWP.windowState field gets updated to the newWindowState
 836         //       value when the native notification comes to us
 837     }
 838 
 839     @Override
 840     public void setModalBlocked(boolean blocked) {
 841         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 842             return;
 843         }
 844 
 845         nativeSetEnabled(getNSWindowPtr(), !blocked);
 846     }
 847 
 848 
 849     public final void invalidateShadow(){
 850         nativeRevalidateNSWindowShadow(getNSWindowPtr());
 851     }
 852 
 853     // ----------------------------------------------------------------------


   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  44 import sun.util.logging.PlatformLogger;
  45 
  46 import com.apple.laf.*;
  47 import com.apple.laf.ClientPropertyApplicator.Property;
  48 import com.sun.awt.AWTUtilities;
  49 
  50 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
  51     private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
  52     private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
  53     private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
  54     private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
  55     private static native void nativeSetNSWindowBounds(long nsWindowPtr, 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 
  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";
  74     public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
  75 
  76     public static final String WINDOW_ALPHA = "Window.alpha";
  77     public static final String WINDOW_SHADOW = "Window.shadow";
  78 
  79     public static final String WINDOW_STYLE = "Window.style";
  80     public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
  81 
  82     public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
  83     public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
  84 
  85     public static final String WINDOW_CLOSEABLE = "Window.closeable";
  86     public static final String WINDOW_MINIMIZABLE = "Window.minimizable";


 577         this.visible = visible;
 578 
 579         // Manage the extended state when showing
 580         if (visible) {
 581             // Apply the extended state as expected in shared code
 582             if (target instanceof Frame) {
 583                 switch (((Frame)target).getExtendedState()) {
 584                     case Frame.ICONIFIED:
 585                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
 586                         break;
 587                     case Frame.MAXIMIZED_BOTH:
 588                         maximize();
 589                         break;
 590                     default: // NORMAL
 591                         unmaximize(); // in case it was maximized, otherwise this is a no-op
 592                         break;
 593                 }
 594             }
 595         }
 596 
 597         nativeSynthesizeMouseEnteredExitedEvents();
 598 
 599         // Configure stuff #2
 600         updateFocusabilityForAutoRequestFocus(true);
 601 
 602         // Manage parent-child relationship when showing
 603         if (visible) {
 604             // Add myself as a child
 605             if (owner != null && owner.isVisible()) {
 606                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 607                 if (target.isAlwaysOnTop()) {
 608                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 609                 }
 610             }
 611 
 612             // Add my own children to myself
 613             for (Window w : target.getOwnedWindows()) {
 614                 WindowPeer p = (WindowPeer)w.getPeer();
 615                 if (p instanceof LWWindowPeer) {
 616                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 617                     if (pw != null && pw.isVisible()) {


 722         return CWrapper.NSWindow.isKeyWindow(ptr);
 723     }
 724 
 725     @Override
 726     public void updateFocusableWindowState() {
 727         final boolean isFocusable = isNativelyFocusableWindow();
 728         setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
 729     }
 730 
 731     @Override
 732     public Graphics transformGraphics(Graphics g) {
 733         // is this where we can inject a transform for HiDPI?
 734         return g;
 735     }
 736 
 737     @Override
 738     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 739         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 740     }
 741 
 742     public PlatformWindow getTopmostPlatformWindowUnderMouse() {
 743         return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
 744     }
 745     @Override
 746     public void setOpacity(float opacity) {
 747         CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
 748     }
 749 
 750     @Override
 751     public void setOpaque(boolean isOpaque) {
 752         CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
 753         boolean isTextured = (peer == null)? false : peer.isTextured();
 754         if (!isOpaque && !isTextured) {
 755             long clearColor = CWrapper.NSColor.clearColor();
 756             CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
 757         }
 758 
 759         //This is a temporary workaround. Looks like after 7124236 will be fixed
 760         //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
 761         SwingUtilities.invokeLater(new Runnable() {
 762             @Override
 763             public void run() {
 764                 invalidateShadow();


 817                 break;
 818             case Frame.MAXIMIZED_BOTH:
 819                 if (prevWindowState == Frame.ICONIFIED) {
 820                     // let's return into the normal states first
 821                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 822                 }
 823                 maximize();
 824                 break;
 825             case Frame.NORMAL:
 826                 if (prevWindowState == Frame.ICONIFIED) {
 827                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 828                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 829                     // the zoom call toggles between the normal and the max states
 830                     unmaximize();
 831                 }
 832                 break;
 833             default:
 834                 throw new RuntimeException("Unknown window state: " + windowState);
 835         }
 836 
 837         nativeSynthesizeMouseEnteredExitedEvents();
 838 
 839         // NOTE: the SWP.windowState field gets updated to the newWindowState
 840         //       value when the native notification comes to us
 841     }
 842 
 843     @Override
 844     public void setModalBlocked(boolean blocked) {
 845         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 846             return;
 847         }
 848 
 849         nativeSetEnabled(getNSWindowPtr(), !blocked);
 850     }
 851 
 852 
 853     public final void invalidateShadow(){
 854         nativeRevalidateNSWindowShadow(getNSWindowPtr());
 855     }
 856 
 857     // ----------------------------------------------------------------------