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(long nsWindowPtr);
65 private static native void nativeDispose(long nsWindowPtr);
66
67 private static native int nativeGetNSWindowDisplayID_AppKitThread(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");
71 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
72
73 // for client properties
74 public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
75 public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
76
77 public static final String WINDOW_ALPHA = "Window.alpha";
78 public static final String WINDOW_SHADOW = "Window.shadow";
79
80 public static final String WINDOW_STYLE = "Window.style";
81 public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
82
83 public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
84 public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
85
571 this.visible = visible;
572
573 // Manage the extended state when showing
574 if (visible) {
575 // Apply the extended state as expected in shared code
576 if (target instanceof Frame) {
577 switch (((Frame)target).getExtendedState()) {
578 case Frame.ICONIFIED:
579 CWrapper.NSWindow.miniaturize(nsWindowPtr);
580 break;
581 case Frame.MAXIMIZED_BOTH:
582 maximize();
583 break;
584 default: // NORMAL
585 unmaximize(); // in case it was maximized, otherwise this is a no-op
586 break;
587 }
588 }
589 }
590
591 nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
592
593 // Configure stuff #2
594 updateFocusabilityForAutoRequestFocus(true);
595
596 // Manage parent-child relationship when showing
597 if (visible) {
598 // Add myself as a child
599 if (owner != null && owner.isVisible()) {
600 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
601 if (target.isAlwaysOnTop()) {
602 CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
603 }
604 }
605
606 // Add my own children to myself
607 for (Window w : target.getOwnedWindows()) {
608 WindowPeer p = (WindowPeer)w.getPeer();
609 if (p instanceof LWWindowPeer) {
610 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
611 if (pw != null && pw.isVisible()) {
717 return CWrapper.NSWindow.isKeyWindow(ptr);
718 }
719
720 @Override
721 public void updateFocusableWindowState() {
722 final boolean isFocusable = isNativelyFocusableWindow();
723 setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
724 }
725
726 @Override
727 public Graphics transformGraphics(Graphics g) {
728 // is this where we can inject a transform for HiDPI?
729 return g;
730 }
731
732 @Override
733 public void setAlwaysOnTop(boolean isAlwaysOnTop) {
734 setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
735 }
736
737 @Override
738 public void setOpacity(float opacity) {
739 CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
740 }
741
742 @Override
743 public void setOpaque(boolean isOpaque) {
744 CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
745 if (!isOpaque && !peer.isTextured()) {
746 long clearColor = CWrapper.NSColor.clearColor();
747 CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
748 }
749
750 //This is a temporary workaround. Looks like after 7124236 will be fixed
751 //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
752 SwingUtilities.invokeLater(new Runnable() {
753 @Override
754 public void run() {
755 invalidateShadow();
756 }
791 break;
792 case Frame.MAXIMIZED_BOTH:
793 if (prevWindowState == Frame.ICONIFIED) {
794 // let's return into the normal states first
795 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
796 }
797 maximize();
798 break;
799 case Frame.NORMAL:
800 if (prevWindowState == Frame.ICONIFIED) {
801 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
802 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
803 // the zoom call toggles between the normal and the max states
804 unmaximize();
805 }
806 break;
807 default:
808 throw new RuntimeException("Unknown window state: " + windowState);
809 }
810
811 nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
812
813 // NOTE: the SWP.windowState field gets updated to the newWindowState
814 // value when the native notification comes to us
815 }
816
817 @Override
818 public void setModalBlocked(boolean blocked) {
819 if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
820 return;
821 }
822
823 nativeSetEnabled(getNSWindowPtr(), !blocked);
824 }
825
826 public final void invalidateShadow(){
827 nativeRevalidateNSWindowShadow(getNSWindowPtr());
828 }
829
830 // ----------------------------------------------------------------------
831 // UTILITY METHODS
|
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 public static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
67
68 private static native int nativeGetNSWindowDisplayID_AppKitThread(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";
76 public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
77
78 public static final String WINDOW_ALPHA = "Window.alpha";
79 public static final String WINDOW_SHADOW = "Window.shadow";
80
81 public static final String WINDOW_STYLE = "Window.style";
82 public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
83
84 public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
85 public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
86
572 this.visible = visible;
573
574 // Manage the extended state when showing
575 if (visible) {
576 // Apply the extended state as expected in shared code
577 if (target instanceof Frame) {
578 switch (((Frame)target).getExtendedState()) {
579 case Frame.ICONIFIED:
580 CWrapper.NSWindow.miniaturize(nsWindowPtr);
581 break;
582 case Frame.MAXIMIZED_BOTH:
583 maximize();
584 break;
585 default: // NORMAL
586 unmaximize(); // in case it was maximized, otherwise this is a no-op
587 break;
588 }
589 }
590 }
591
592 nativeSynthesizeMouseEnteredExitedEvents();
593
594 // Configure stuff #2
595 updateFocusabilityForAutoRequestFocus(true);
596
597 // Manage parent-child relationship when showing
598 if (visible) {
599 // Add myself as a child
600 if (owner != null && owner.isVisible()) {
601 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
602 if (target.isAlwaysOnTop()) {
603 CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
604 }
605 }
606
607 // Add my own children to myself
608 for (Window w : target.getOwnedWindows()) {
609 WindowPeer p = (WindowPeer)w.getPeer();
610 if (p instanceof LWWindowPeer) {
611 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
612 if (pw != null && pw.isVisible()) {
718 return CWrapper.NSWindow.isKeyWindow(ptr);
719 }
720
721 @Override
722 public void updateFocusableWindowState() {
723 final boolean isFocusable = isNativelyFocusableWindow();
724 setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
725 }
726
727 @Override
728 public Graphics transformGraphics(Graphics g) {
729 // is this where we can inject a transform for HiDPI?
730 return g;
731 }
732
733 @Override
734 public void setAlwaysOnTop(boolean isAlwaysOnTop) {
735 setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
736 }
737
738 public PlatformWindow getTopmostPlatformWindowUnderMouse(){
739 return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
740 }
741
742 @Override
743 public void setOpacity(float opacity) {
744 CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
745 }
746
747 @Override
748 public void setOpaque(boolean isOpaque) {
749 CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
750 if (!isOpaque && !peer.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();
761 }
796 break;
797 case Frame.MAXIMIZED_BOTH:
798 if (prevWindowState == Frame.ICONIFIED) {
799 // let's return into the normal states first
800 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
801 }
802 maximize();
803 break;
804 case Frame.NORMAL:
805 if (prevWindowState == Frame.ICONIFIED) {
806 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
807 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
808 // the zoom call toggles between the normal and the max states
809 unmaximize();
810 }
811 break;
812 default:
813 throw new RuntimeException("Unknown window state: " + windowState);
814 }
815
816 nativeSynthesizeMouseEnteredExitedEvents();
817
818 // NOTE: the SWP.windowState field gets updated to the newWindowState
819 // value when the native notification comes to us
820 }
821
822 @Override
823 public void setModalBlocked(boolean blocked) {
824 if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
825 return;
826 }
827
828 nativeSetEnabled(getNSWindowPtr(), !blocked);
829 }
830
831 public final void invalidateShadow(){
832 nativeRevalidateNSWindowShadow(getNSWindowPtr());
833 }
834
835 // ----------------------------------------------------------------------
836 // UTILITY METHODS
|