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

Print this page




  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 nativeSetNSWindowAlpha(long nsWindowPtr, float alpha);
  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 nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);

  64 
  65     private static native int nativeGetScreenNSWindowIsOn_AppKitThread(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 


 565             CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
 566                     ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
 567         }
 568         this.visible = visible;
 569 
 570         // 5. Manage the extended state when showing
 571         if (visible) {
 572             // Re-apply the extended state as expected in shared code
 573             if (target instanceof Frame) {
 574                 switch (((Frame)target).getExtendedState()) {
 575                     case Frame.ICONIFIED:
 576                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
 577                         break;
 578                     case Frame.MAXIMIZED_BOTH:
 579                         zoom();
 580                         break;
 581                 }
 582             }
 583         }
 584 


 585         // 6. Configure stuff #2
 586         updateFocusabilityForAutoRequestFocus(true);
 587 
 588         // 7. Manage parent-child relationship when showing
 589         if (visible) {
 590             // 7a. Add myself as a child
 591             if (owner != null && owner.isVisible()) {
 592                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 593                 if (target.isAlwaysOnTop()) {
 594                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 595                 }
 596             }
 597 
 598             // 7b. Add my own children to myself
 599             for (Window w : target.getOwnedWindows()) {
 600                 WindowPeer p = (WindowPeer)w.getPeer();
 601                 if (p instanceof LWWindowPeer) {
 602                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 603                     if (pw != null && pw.isVisible()) {
 604                         CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);


 766                 break;
 767             case Frame.MAXIMIZED_BOTH:
 768                 if (prevWindowState == Frame.ICONIFIED) {
 769                     // let's return into the normal states first
 770                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 771                 }
 772                 zoom();
 773                 break;
 774             case Frame.NORMAL:
 775                 if (prevWindowState == Frame.ICONIFIED) {
 776                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 777                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 778                     // the zoom call toggles between the normal and the max states
 779                     zoom();
 780                 }
 781                 break;
 782             default:
 783                 throw new RuntimeException("Unknown window state: " + windowState);
 784         }
 785 


 786         // NOTE: the SWP.windowState field gets updated to the newWindowState
 787         //       value when the native notification comes to us
 788     }
 789 
 790     // ----------------------------------------------------------------------
 791     //                          UTILITY METHODS
 792     // ----------------------------------------------------------------------
 793 
 794     /*
 795      * Find image to install into Title or into Application icon.
 796      * First try icons installed for toplevel. If there is no icon
 797      * use default Duke image.
 798      * This method shouldn't return null.
 799      */
 800     private CImage getImageForTarget() {
 801         List<Image> icons = target.getIconImages();
 802         if (icons == null || icons.size() == 0) {
 803             return null;
 804         }
 805 




  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 nativeSetNSWindowAlpha(long nsWindowPtr, float alpha);
  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 nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
  64     private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
  65 
  66     private static native int nativeGetScreenNSWindowIsOn_AppKitThread(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");
  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 


 566             CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
 567                     ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
 568         }
 569         this.visible = visible;
 570 
 571         // 5. Manage the extended state when showing
 572         if (visible) {
 573             // Re-apply the extended state as expected in shared code
 574             if (target instanceof Frame) {
 575                 switch (((Frame)target).getExtendedState()) {
 576                     case Frame.ICONIFIED:
 577                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
 578                         break;
 579                     case Frame.MAXIMIZED_BOTH:
 580                         zoom();
 581                         break;
 582                 }
 583             }
 584         }
 585 
 586         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 587 
 588         // 6. Configure stuff #2
 589         updateFocusabilityForAutoRequestFocus(true);
 590 
 591         // 7. Manage parent-child relationship when showing
 592         if (visible) {
 593             // 7a. Add myself as a child
 594             if (owner != null && owner.isVisible()) {
 595                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 596                 if (target.isAlwaysOnTop()) {
 597                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 598                 }
 599             }
 600 
 601             // 7b. Add my own children to myself
 602             for (Window w : target.getOwnedWindows()) {
 603                 WindowPeer p = (WindowPeer)w.getPeer();
 604                 if (p instanceof LWWindowPeer) {
 605                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 606                     if (pw != null && pw.isVisible()) {
 607                         CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);


 769                 break;
 770             case Frame.MAXIMIZED_BOTH:
 771                 if (prevWindowState == Frame.ICONIFIED) {
 772                     // let's return into the normal states first
 773                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 774                 }
 775                 zoom();
 776                 break;
 777             case Frame.NORMAL:
 778                 if (prevWindowState == Frame.ICONIFIED) {
 779                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 780                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 781                     // the zoom call toggles between the normal and the max states
 782                     zoom();
 783                 }
 784                 break;
 785             default:
 786                 throw new RuntimeException("Unknown window state: " + windowState);
 787         }
 788 
 789         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 790 
 791         // NOTE: the SWP.windowState field gets updated to the newWindowState
 792         //       value when the native notification comes to us
 793     }
 794 
 795     // ----------------------------------------------------------------------
 796     //                          UTILITY METHODS
 797     // ----------------------------------------------------------------------
 798 
 799     /*
 800      * Find image to install into Title or into Application icon.
 801      * First try icons installed for toplevel. If there is no icon
 802      * use default Duke image.
 803      * This method shouldn't return null.
 804      */
 805     private CImage getImageForTarget() {
 806         List<Image> icons = target.getIconImages();
 807         if (icons == null || icons.size() == 0) {
 808             return null;
 809         }
 810