< 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);


 465             }
 466 
 467             prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
 468             if (prop != null) {
 469                 styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
 470             }
 471         }
 472 
 473         if (isDialog) {
 474             styleBits = SET(styleBits, IS_DIALOG, true);
 475             if (((Dialog) target).isModal()) {
 476                 styleBits = SET(styleBits, IS_MODAL, true);
 477             }
 478         }
 479 
 480         peer.setTextured(IS(TEXTURED, styleBits));
 481 
 482         return styleBits;
 483     }
 484 
 485     private boolean isTargetResizable() {
 486         if (target instanceof Frame) {
 487             return ((Frame)target).isResizable();
 488         } else if (target instanceof Dialog) {
 489             return ((Dialog)target).isResizable();
 490         }
 491 
 492         return false;
 493     }
 494 
 495     // this is the counter-point to -[CWindow _nativeSetStyleBit:]
 496     private void setStyleBits(final int mask, final boolean value) {
 497         execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
 498     }
 499 
 500     private native void _toggleFullScreenMode(final long model);
 501 
 502     public void toggleFullScreen() {
 503         execute(this::_toggleFullScreenMode);
 504     }
 505 
 506     @Override // PlatformWindow
 507     public void setMenuBar(MenuBar mb) {
 508         CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
 509         execute(nsWindowPtr->{
 510             if (mbPeer != null) {
 511                 mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
 512             } else {
 513                 nativeSetNSWindowMenuBar(nsWindowPtr, 0);
 514             }


 669                     CWrapper.NSWindow.close(ptr);
 670                 });
 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 = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
 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);


 465             }
 466 
 467             prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
 468             if (prop != null) {
 469                 styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
 470             }
 471         }
 472 
 473         if (isDialog) {
 474             styleBits = SET(styleBits, IS_DIALOG, true);
 475             if (((Dialog) target).isModal()) {
 476                 styleBits = SET(styleBits, IS_MODAL, true);
 477             }
 478         }
 479 
 480         peer.setTextured(IS(TEXTURED, styleBits));
 481 
 482         return styleBits;
 483     }
 484 










 485     // this is the counter-point to -[CWindow _nativeSetStyleBit:]
 486     private void setStyleBits(final int mask, final boolean value) {
 487         execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
 488     }
 489 
 490     private native void _toggleFullScreenMode(final long model);
 491 
 492     public void toggleFullScreen() {
 493         execute(this::_toggleFullScreenMode);
 494     }
 495 
 496     @Override // PlatformWindow
 497     public void setMenuBar(MenuBar mb) {
 498         CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
 499         execute(nsWindowPtr->{
 500             if (mbPeer != null) {
 501                 mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
 502             } else {
 503                 nativeSetNSWindowMenuBar(nsWindowPtr, 0);
 504             }


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


 797         execute(CPlatformWindow::nativePushNSWindowToFront);
 798         updateFocusabilityForAutoRequestFocus(true);
 799     }
 800 
 801     private void setCanFullscreen(final boolean canFullScreen) {
 802         if (target instanceof RootPaneContainer
 803                 && getPeer().getPeerType() == PeerType.FRAME) {
 804 
 805             if (isInFullScreen && !canFullScreen) {
 806                 toggleFullScreen();
 807             }
 808 
 809             final RootPaneContainer rpc = (RootPaneContainer) target;
 810             rpc.getRootPane().putClientProperty(
 811                     CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen);
 812         }
 813     }
 814 
 815     @Override
 816     public void setResizable(final boolean resizable) {
 817         setCanFullscreen(resizable);
 818         setStyleBits(RESIZABLE, resizable);
 819         setStyleBits(ZOOMABLE, resizable);

 820     }
 821 
 822     @Override
 823     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
 824         execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
 825     }
 826 
 827     @Override
 828     public boolean rejectFocusRequest(FocusEvent.Cause cause) {
 829         // Cross-app activation requests are not allowed.
 830         if (cause != FocusEvent.Cause.MOUSE_EVENT &&
 831             !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
 832         {
 833             focusLogger.fine("the app is inactive, so the request is rejected");
 834             return true;
 835         }
 836         return false;
 837     }
 838 
 839     @Override


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


< prev index next >