< prev index next >

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

Print this page




 361         if (isNativelyFocusableWindow()) {
 362             styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
 363             styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
 364         }
 365 
 366         final boolean isFrame = (target instanceof Frame);
 367         final boolean isDialog = (target instanceof Dialog);
 368         final boolean isPopup = (target.getType() == Window.Type.POPUP);
 369         if (isDialog) {
 370             styleBits = SET(styleBits, MINIMIZABLE, false);
 371         }
 372 
 373         // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
 374         {
 375             this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
 376             if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
 377         }
 378 
 379         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
 380         {
 381             final boolean resizable = isTargetResizable() && isNativelyFocusableWindow();
 382             styleBits = SET(styleBits, RESIZABLE, resizable);
 383             if (!resizable) {
 384                 styleBits = SET(styleBits, ZOOMABLE, false);
 385             }
 386         }
 387 
 388         if (target.isAlwaysOnTop()) {
 389             styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
 390         }
 391 
 392         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 393             styleBits = SET(styleBits, MODAL_EXCLUDED, true);
 394         }
 395 
 396         // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
 397         if (isPopup) {
 398             styleBits = SET(styleBits, TEXTURED, false);
 399             // Popups in applets don't activate applet's process
 400             styleBits = SET(styleBits, NONACTIVATING, true);
 401             styleBits = SET(styleBits, IS_POPUP, true);


 671             }
 672         } else {
 673             // otherwise, put it in a proper z-order
 674             CPlatformWindow bw
 675                     = (CPlatformWindow) blocker.getPlatformWindow();
 676             bw.execute(blockerPtr -> {
 677                 execute(ptr -> {
 678                     CWrapper.NSWindow.orderWindow(ptr,
 679                                                   CWrapper.NSWindow.NSWindowBelow,
 680                                                   blockerPtr);
 681                 });
 682             });
 683         }
 684         this.visible = visible;
 685 
 686         // Manage the extended state when showing
 687         if (visible) {
 688             /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
 689             Frame or Dialog is resizable and focusable.
 690             **/
 691             final boolean resizable = isTargetResizable() && isNativelyFocusableWindow();
 692             if (resizable) {
 693                 setCanFullscreen(true);
 694             }
 695 
 696             // Apply the extended state as expected in shared code
 697             if (target instanceof Frame) {
 698                 if (!wasMaximized && isMaximized()) {
 699                     // setVisible could have changed the native maximized state
 700                     deliverZoom(true);
 701                 } else {
 702                     int frameState = ((Frame)target).getExtendedState();
 703                     if ((frameState & Frame.ICONIFIED) != 0) {
 704                         // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
 705                         frameState = Frame.ICONIFIED;
 706                     }
 707                     switch (frameState) {
 708                         case Frame.ICONIFIED:
 709                             execute(CWrapper.NSWindow::miniaturize);
 710                             break;
 711                         case Frame.MAXIMIZED_BOTH:


 806         execute(CPlatformWindow::nativePushNSWindowToFront);
 807         updateFocusabilityForAutoRequestFocus(true);
 808     }
 809 
 810     private void setCanFullscreen(final boolean canFullScreen) {
 811         if (target instanceof RootPaneContainer
 812                 && getPeer().getPeerType() == PeerType.FRAME) {
 813 
 814             if (isInFullScreen && !canFullScreen) {
 815                 toggleFullScreen();
 816             }
 817 
 818             final RootPaneContainer rpc = (RootPaneContainer) target;
 819             rpc.getRootPane().putClientProperty(
 820                     CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen);
 821         }
 822     }
 823 
 824     @Override
 825     public void setResizable(final boolean resizable) {
 826         final boolean windowResizable = resizable && isNativelyFocusableWindow();
 827         setCanFullscreen(windowResizable);
 828         setStyleBits(RESIZABLE, windowResizable);
 829         setStyleBits(ZOOMABLE, windowResizable);
 830     }
 831 
 832     @Override
 833     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
 834         execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
 835     }
 836 
 837     @Override
 838     public boolean rejectFocusRequest(FocusEvent.Cause cause) {
 839         // Cross-app activation requests are not allowed.
 840         if (cause != FocusEvent.Cause.MOUSE_EVENT &&
 841             !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
 842         {
 843             focusLogger.fine("the app is inactive, so the request is rejected");
 844             return true;
 845         }
 846         return false;
 847     }
 848 
 849     @Override


 851         execute(ptr -> {
 852             if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
 853                 CWrapper.NSWindow.makeMainWindow(ptr);
 854             }
 855             CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
 856         });
 857         return true;
 858     }
 859 
 860     @Override
 861     public boolean isActive() {
 862         AtomicBoolean ref = new AtomicBoolean();
 863         execute(ptr -> {
 864             ref.set(CWrapper.NSWindow.isKeyWindow(ptr));
 865         });
 866         return ref.get();
 867     }
 868 
 869     @Override
 870     public void updateFocusableWindowState() {
 871         setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | RESIZABLE,
 872                 (isNativelyFocusableWindow() && isTargetResizable()));
 873     }
 874 
 875     @Override
 876     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 877         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 878     }
 879 
 880     @Override
 881     public void setOpacity(float opacity) {
 882         execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
 883     }
 884 
 885     @Override
 886     public void setOpaque(boolean isOpaque) {
 887         execute(ptr -> CWrapper.NSWindow.setOpaque(ptr, isOpaque));
 888         boolean isTextured = (peer == null) ? false : peer.isTextured();
 889         if (!isTextured) {
 890             if (!isOpaque) {
 891                 execute(ptr -> CWrapper.NSWindow.setBackgroundColor(ptr, 0));
 892             } else if (peer != null) {




 361         if (isNativelyFocusableWindow()) {
 362             styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
 363             styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
 364         }
 365 
 366         final boolean isFrame = (target instanceof Frame);
 367         final boolean isDialog = (target instanceof Dialog);
 368         final boolean isPopup = (target.getType() == Window.Type.POPUP);
 369         if (isDialog) {
 370             styleBits = SET(styleBits, MINIMIZABLE, false);
 371         }
 372 
 373         // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
 374         {
 375             this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
 376             if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
 377         }
 378 
 379         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
 380         {
 381             final boolean resizable = isTargetResizable();
 382             styleBits = SET(styleBits, RESIZABLE, resizable);
 383             if (!resizable) {
 384                 styleBits = SET(styleBits, ZOOMABLE, false);
 385             }
 386         }
 387 
 388         if (target.isAlwaysOnTop()) {
 389             styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
 390         }
 391 
 392         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 393             styleBits = SET(styleBits, MODAL_EXCLUDED, true);
 394         }
 395 
 396         // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
 397         if (isPopup) {
 398             styleBits = SET(styleBits, TEXTURED, false);
 399             // Popups in applets don't activate applet's process
 400             styleBits = SET(styleBits, NONACTIVATING, true);
 401             styleBits = SET(styleBits, IS_POPUP, true);


 671             }
 672         } else {
 673             // otherwise, put it in a proper z-order
 674             CPlatformWindow bw
 675                     = (CPlatformWindow) blocker.getPlatformWindow();
 676             bw.execute(blockerPtr -> {
 677                 execute(ptr -> {
 678                     CWrapper.NSWindow.orderWindow(ptr,
 679                                                   CWrapper.NSWindow.NSWindowBelow,
 680                                                   blockerPtr);
 681                 });
 682             });
 683         }
 684         this.visible = visible;
 685 
 686         // Manage the extended state when showing
 687         if (visible) {
 688             /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
 689             Frame or Dialog is resizable and focusable.
 690             **/
 691             final boolean resizable = isTargetResizable();
 692             if (resizable) {
 693                 setCanFullscreen(true);
 694             }
 695 
 696             // Apply the extended state as expected in shared code
 697             if (target instanceof Frame) {
 698                 if (!wasMaximized && isMaximized()) {
 699                     // setVisible could have changed the native maximized state
 700                     deliverZoom(true);
 701                 } else {
 702                     int frameState = ((Frame)target).getExtendedState();
 703                     if ((frameState & Frame.ICONIFIED) != 0) {
 704                         // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
 705                         frameState = Frame.ICONIFIED;
 706                     }
 707                     switch (frameState) {
 708                         case Frame.ICONIFIED:
 709                             execute(CWrapper.NSWindow::miniaturize);
 710                             break;
 711                         case Frame.MAXIMIZED_BOTH:


 806         execute(CPlatformWindow::nativePushNSWindowToFront);
 807         updateFocusabilityForAutoRequestFocus(true);
 808     }
 809 
 810     private void setCanFullscreen(final boolean canFullScreen) {
 811         if (target instanceof RootPaneContainer
 812                 && getPeer().getPeerType() == PeerType.FRAME) {
 813 
 814             if (isInFullScreen && !canFullScreen) {
 815                 toggleFullScreen();
 816             }
 817 
 818             final RootPaneContainer rpc = (RootPaneContainer) target;
 819             rpc.getRootPane().putClientProperty(
 820                     CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen);
 821         }
 822     }
 823 
 824     @Override
 825     public void setResizable(final boolean resizable) {
 826         setCanFullscreen(resizable);
 827         setStyleBits(RESIZABLE, resizable);
 828         setStyleBits(ZOOMABLE, resizable);

 829     }
 830 
 831     @Override
 832     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
 833         execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
 834     }
 835 
 836     @Override
 837     public boolean rejectFocusRequest(FocusEvent.Cause cause) {
 838         // Cross-app activation requests are not allowed.
 839         if (cause != FocusEvent.Cause.MOUSE_EVENT &&
 840             !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
 841         {
 842             focusLogger.fine("the app is inactive, so the request is rejected");
 843             return true;
 844         }
 845         return false;
 846     }
 847 
 848     @Override


 850         execute(ptr -> {
 851             if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
 852                 CWrapper.NSWindow.makeMainWindow(ptr);
 853             }
 854             CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
 855         });
 856         return true;
 857     }
 858 
 859     @Override
 860     public boolean isActive() {
 861         AtomicBoolean ref = new AtomicBoolean();
 862         execute(ptr -> {
 863             ref.set(CWrapper.NSWindow.isKeyWindow(ptr));
 864         });
 865         return ref.get();
 866     }
 867 
 868     @Override
 869     public void updateFocusableWindowState() {
 870         final boolean isFocusable = isNativelyFocusableWindow();
 871         setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable);
 872     }
 873 
 874     @Override
 875     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
 876         setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
 877     }
 878 
 879     @Override
 880     public void setOpacity(float opacity) {
 881         execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
 882     }
 883 
 884     @Override
 885     public void setOpaque(boolean isOpaque) {
 886         execute(ptr -> CWrapper.NSWindow.setOpaque(ptr, isOpaque));
 887         boolean isTextured = (peer == null) ? false : peer.isTextured();
 888         if (!isTextured) {
 889             if (!isOpaque) {
 890                 execute(ptr -> CWrapper.NSWindow.setBackgroundColor(ptr, 0));
 891             } else if (peer != null) {


< prev index next >