src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
changeset 53358 659b004b6a1b
parent 52967 5adeed0d6311
child 53360 58e25974ede4
equal deleted inserted replaced
53357:c52a37f40324 53358:659b004b6a1b
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   293     protected boolean visible = false; // visibility status from native perspective
   293     protected boolean visible = false; // visibility status from native perspective
   294     private boolean undecorated; // initialized in getInitialStyleBits()
   294     private boolean undecorated; // initialized in getInitialStyleBits()
   295     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
   295     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
   296     private CPlatformResponder responder;
   296     private CPlatformResponder responder;
   297     private long lastBecomeMainTime; // this is necessary to preserve right siblings order
   297     private long lastBecomeMainTime; // this is necessary to preserve right siblings order
   298     private boolean maximizedBothState = false;
       
   299     private boolean frameResizibilityChanged = false;
       
   300 
   298 
   301     public CPlatformWindow() {
   299     public CPlatformWindow() {
   302         super(0, true);
   300         super(0, true);
   303     }
   301     }
   304 
   302 
   397             if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
   395             if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
   398         }
   396         }
   399 
   397 
   400         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
   398         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
   401         {
   399         {
   402             final boolean resizable = isTargetResizable();
   400             final boolean resizable = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
   403             styleBits = SET(styleBits, RESIZABLE, resizable);
   401             styleBits = SET(styleBits, RESIZABLE, resizable);
   404             if (!resizable) {
   402             if (!resizable) {
   405                 styleBits = SET(styleBits, ZOOMABLE, false);
   403                 styleBits = SET(styleBits, ZOOMABLE, false);
   406             }
   404             }
   407         }
   405         }
   609             this.normalBounds = peer.getBounds();
   607             this.normalBounds = peer.getBounds();
   610             Rectangle maximizedBounds = peer.getMaximizedBounds();
   608             Rectangle maximizedBounds = peer.getMaximizedBounds();
   611             setBounds(maximizedBounds.x, maximizedBounds.y,
   609             setBounds(maximizedBounds.x, maximizedBounds.y,
   612                     maximizedBounds.width, maximizedBounds.height);
   610                     maximizedBounds.width, maximizedBounds.height);
   613         }
   611         }
   614         setFrameResizibilityChanged(true);
       
   615         updateResizableAndMaximizeState(true);
       
   616     }
   612     }
   617 
   613 
   618     private void unmaximize() {
   614     private void unmaximize() {
   619         if (!isMaximized()) {
   615         if (!isMaximized()) {
   620             return;
   616             return;
   707         this.visible = visible;
   703         this.visible = visible;
   708 
   704 
   709         // Manage the extended state when showing
   705         // Manage the extended state when showing
   710         if (visible) {
   706         if (visible) {
   711             /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
   707             /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
   712             Frame resizable and Frame state is not MAXIMIZED_BOTH or Dialog is resizable.
   708             Frame or Dialog is resizable.
   713             **/
   709             **/
   714             if (isTargetResizable()) {
   710             final boolean resizable = (target instanceof Frame) ? ((Frame)target).isResizable() :
       
   711             ((target instanceof Dialog) ? ((Dialog)target).isResizable() : false);
       
   712             if (resizable) {
   715                 setCanFullscreen(true);
   713                 setCanFullscreen(true);
   716             }
   714             }
   717 
   715 
   718             // Apply the extended state as expected in shared code
   716             // Apply the extended state as expected in shared code
   719             if (target instanceof Frame) {
   717             if (target instanceof Frame) {
   723                 } else {
   721                 } else {
   724                     int frameState = ((Frame)target).getExtendedState();
   722                     int frameState = ((Frame)target).getExtendedState();
   725                     if ((frameState & Frame.ICONIFIED) != 0) {
   723                     if ((frameState & Frame.ICONIFIED) != 0) {
   726                         // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
   724                         // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
   727                         frameState = Frame.ICONIFIED;
   725                         frameState = Frame.ICONIFIED;
   728                     }
       
   729 
       
   730                     if (isFrameResizibilityChanged()) {
       
   731                         updateResizableAndMaximizeState(false);
       
   732                         setFrameResizibilityChanged(false);
       
   733                     }
   726                     }
   734 
   727 
   735                     switch (frameState) {
   728                     switch (frameState) {
   736                         case Frame.ICONIFIED:
   729                         case Frame.ICONIFIED:
   737                             execute(CWrapper.NSWindow::miniaturize);
   730                             execute(CWrapper.NSWindow::miniaturize);
   849         }
   842         }
   850     }
   843     }
   851 
   844 
   852     @Override
   845     @Override
   853     public void setResizable(final boolean resizable) {
   846     public void setResizable(final boolean resizable) {
   854         boolean windowResizable = resizable && !isMaximizedBoth();
   847         setCanFullscreen(resizable);
   855         setCanFullscreen(windowResizable);
   848         setStyleBits(RESIZABLE, resizable);
   856         setStyleBits(RESIZABLE, windowResizable);
   849         setStyleBits(ZOOMABLE, resizable);
   857         setStyleBits(ZOOMABLE, windowResizable);
       
   858     }
   850     }
   859 
   851 
   860     @Override
   852     @Override
   861     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
   853     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
   862         execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
   854         execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
   959         if (prevWindowState == windowState) return;
   951         if (prevWindowState == windowState) return;
   960 
   952 
   961         if ((windowState & Frame.ICONIFIED) != 0) {
   953         if ((windowState & Frame.ICONIFIED) != 0) {
   962             // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
   954             // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
   963             windowState = Frame.ICONIFIED;
   955             windowState = Frame.ICONIFIED;
   964         }
       
   965 
       
   966         if (isFrameResizibilityChanged()) {
       
   967             updateResizableAndMaximizeState(false);
       
   968             setFrameResizibilityChanged(false);
       
   969         }
   956         }
   970 
   957 
   971         switch (windowState) {
   958         switch (windowState) {
   972             case Frame.ICONIFIED:
   959             case Frame.ICONIFIED:
   973                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
   960                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
  1165     }
  1152     }
  1166 
  1153 
  1167     private void deliverNCMouseDown() {
  1154     private void deliverNCMouseDown() {
  1168         if (peer != null) {
  1155         if (peer != null) {
  1169             peer.notifyNCMouseDown();
  1156             peer.notifyNCMouseDown();
  1170         }
       
  1171     }
       
  1172 
       
  1173     /*
       
  1174      * Resizibility of frame with state MAXIMIZED_BOTH is set to true to zoom
       
  1175      * the frame on double click on title bar and set to false later. This is
       
  1176      * required as frame won't zoom if resizibility of frame is false.
       
  1177      */
       
  1178     private void deliverDoubleClickOnTitlebar() {
       
  1179         if ((peer != null) && (target instanceof Frame)) {
       
  1180             if (isMaximizedBoth()) {
       
  1181                 updateResizableAndMaximizeState(false);
       
  1182                 execute(CWrapper.NSWindow::zoom);
       
  1183                 updateResizableAndMaximizeState(true);
       
  1184             }
       
  1185         }
  1157         }
  1186     }
  1158     }
  1187 
  1159 
  1188     /*
  1160     /*
  1189      * Our focus model is synthetic and only non-simple window
  1161      * Our focus model is synthetic and only non-simple window
  1348         if (peer != null && peer.isSimpleWindow()) {
  1320         if (peer != null && peer.isSimpleWindow()) {
  1349             return (getOwnerFrameOrDialog(target) instanceof CEmbeddedFrame);
  1321             return (getOwnerFrameOrDialog(target) instanceof CEmbeddedFrame);
  1350         }
  1322         }
  1351         return false;
  1323         return false;
  1352     }
  1324     }
  1353 
       
  1354     private boolean isTargetResizable() {
       
  1355         if (target instanceof Frame) {
       
  1356             return ((Frame)target).isResizable() && !isMaximizedBoth();
       
  1357         } else if (target instanceof Dialog) {
       
  1358             return ((Dialog)target).isResizable();
       
  1359         }
       
  1360         return false;
       
  1361     }
       
  1362 
       
  1363     private void updateResizableAndMaximizeState(boolean maximizeState) {
       
  1364         maximizedBothState = maximizeState;
       
  1365         setResizable(!maximizeState);
       
  1366     }
       
  1367 
       
  1368     private boolean isMaximizedBoth() {
       
  1369         return maximizedBothState;
       
  1370     }
       
  1371 
       
  1372     private void setFrameResizibilityChanged(boolean resize) {
       
  1373         frameResizibilityChanged = resize;
       
  1374     }
       
  1375 
       
  1376     private boolean isFrameResizibilityChanged() {
       
  1377         return frameResizibilityChanged;
       
  1378     }
       
  1379 
       
  1380     // ----------------------------------------------------------------------
  1325     // ----------------------------------------------------------------------
  1381     //                          NATIVE CALLBACKS
  1326     //                          NATIVE CALLBACKS
  1382     // ----------------------------------------------------------------------
  1327     // ----------------------------------------------------------------------
  1383 
  1328 
  1384     private void windowWillMiniaturize() {
  1329     private void windowWillMiniaturize() {