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

Print this page




 192             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 193             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 194         }
 195     };
 196 
 197     // Bounds of the native widget but in the Java coordinate system.
 198     // In order to keep it up-to-date we will update them on
 199     // 1) setting native bounds via nativeSetBounds() call
 200     // 2) getting notification from the native level via deliverMoveResizeEvent()
 201     private Rectangle nativeBounds;
 202     private volatile boolean isFullScreenMode = false;
 203 
 204     private Window target;
 205     private LWWindowPeer peer;
 206     private CPlatformView contentView;
 207     private CPlatformWindow owner;
 208     private boolean visible = false; // visibility status from native perspective
 209     private boolean undecorated; // initialized in getInitialStyleBits()
 210     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
 211     private CPlatformResponder responder;

 212 
 213     public CPlatformWindow(final PeerType peerType) {
 214         super(0, true);
 215         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 216     }
 217 
 218     /*
 219      * Delegate initialization (create native window and all the
 220      * related resources).
 221      */
 222     @Override // PlatformWindow
 223     public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
 224         this.peer = _peer;
 225         this.target = _target;
 226         if (_owner instanceof CPlatformWindow) {
 227             this.owner = (CPlatformWindow)_owner;
 228         }
 229 
 230         final int styleBits = getInitialStyleBits();
 231 


 450         return gd;
 451     }
 452 
 453     @Override // PlatformWindow
 454     public SurfaceData getScreenSurface() {
 455         // TODO: not implemented
 456         return null;
 457     }
 458 
 459     @Override // PlatformWindow
 460     public SurfaceData replaceSurfaceData() {
 461         return contentView.replaceSurfaceData();
 462     }
 463 
 464     @Override // PlatformWindow
 465     public void setBounds(int x, int y, int w, int h) {
 466 //        assert CThreading.assertEventQueue();
 467         nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
 468     }
 469 
 470     private void zoom() {







 471         if (!undecorated) {

 472             CWrapper.NSWindow.zoom(getNSWindowPtr());
 473         } else {
 474             // OS X handles -zoom incorrectly for undecorated windows
 475             final boolean isZoomed = this.normalBounds == null;
 476             deliverZoom(isZoomed);
 477 
 478             Rectangle toBounds;
 479             if (isZoomed) {
 480                 this.normalBounds = peer.getBounds();
 481                 long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
 482                 toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
 483                 // Flip the y coordinate
 484                 Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
 485                 toBounds.y = frame.height - toBounds.y - toBounds.height;











 486             } else {
 487                 toBounds = normalBounds;


 488                 this.normalBounds = null;
 489             }
 490             setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
 491         }
 492     }
 493 
 494     private boolean isVisible() {
 495         return this.visible;
 496     }
 497 
 498     @Override // PlatformWindow
 499     public void setVisible(boolean visible) {
 500         final long nsWindowPtr = getNSWindowPtr();
 501 
 502         // 1. Process parent-child relationship when hiding
 503         if (!visible) {
 504             // 1a. Unparent my children
 505             for (Window w : target.getOwnedWindows()) {
 506                 WindowPeer p = (WindowPeer)w.getPeer();
 507                 if (p instanceof LWWindowPeer) {
 508                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 509                     if (pw != null && pw.isVisible()) {
 510                         CWrapper.NSWindow.removeChildWindow(nsWindowPtr, pw.getNSWindowPtr());
 511                     }
 512                 }
 513             }
 514 
 515             // 1b. Unparent myself
 516             if (owner != null && owner.isVisible()) {
 517                 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
 518             }
 519         }
 520 
 521         // 2. Configure stuff
 522         updateIconImages();
 523         updateFocusabilityForAutoRequestFocus(false);
 524 
 525         // 3. Manage the extended state when hiding
 526         if (!visible) {
 527             // Cancel out the current native state of the window
 528             switch (peer.getState()) {
 529                 case Frame.ICONIFIED:
 530                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 531                     break;
 532                 case Frame.MAXIMIZED_BOTH:
 533                     zoom();
 534                     break;
 535             }
 536         }
 537 
 538         // 4. Actually show or hide the window
 539         LWWindowPeer blocker = peer.getBlocker();
 540         if (blocker == null || !visible) {
 541             // If it ain't blocked, or is being hidden, go regular way
 542             if (visible) {
 543                 CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
 544 
 545                 boolean isPopup = (target.getType() == Window.Type.POPUP);
 546                 if (isPopup) {
 547                     // Popups in applets don't activate applet's process
 548                     CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
 549                 } else {
 550                     CWrapper.NSWindow.orderFront(nsWindowPtr);
 551                 }
 552 
 553                 boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
 554                 if (!isKeyWindow) {
 555                     CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
 556                 }
 557             } else {
 558                 CWrapper.NSWindow.orderOut(nsWindowPtr);
 559             }
 560         } else {
 561             // otherwise, put it in a proper z-order
 562             CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
 563                     ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
 564         }
 565         this.visible = visible;
 566 
 567         // 5. Manage the extended state when showing
 568         if (visible) {
 569             // Re-apply the extended state as expected in shared code
 570             if (target instanceof Frame) {
 571                 switch (((Frame)target).getExtendedState()) {
 572                     case Frame.ICONIFIED:
 573                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
 574                         break;
 575                     case Frame.MAXIMIZED_BOTH:
 576                         zoom();



 577                         break;
 578                 }
 579             }
 580         }
 581 
 582         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 583 
 584         // 6. Configure stuff #2
 585         updateFocusabilityForAutoRequestFocus(true);
 586 
 587         // 7. Manage parent-child relationship when showing
 588         if (visible) {
 589             // 7a. Add myself as a child
 590             if (owner != null && owner.isVisible()) {
 591                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 592                 if (target.isAlwaysOnTop()) {
 593                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 594                 }
 595             }
 596 
 597             // 7b. Add my own children to myself
 598             for (Window w : target.getOwnedWindows()) {
 599                 WindowPeer p = (WindowPeer)w.getPeer();
 600                 if (p instanceof LWWindowPeer) {
 601                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 602                     if (pw != null && pw.isVisible()) {
 603                         CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
 604                         if (w.isAlwaysOnTop()) {
 605                             CWrapper.NSWindow.setLevel(pw.getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
 606                         }
 607                     }
 608                 }
 609             }
 610         }
 611 
 612         // 8. Deal with the blocker of the window being shown
 613         if (blocker != null && visible) {
 614             // Make sure the blocker is above its siblings
 615             ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
 616         }
 617     }
 618 
 619     @Override // PlatformWindow
 620     public void setTitle(String title) {
 621         nativeSetNSWindowTitle(getNSWindowPtr(), title);
 622     }
 623 
 624     // Should be called on every window key property change.
 625     @Override // PlatformWindow
 626     public void updateIconImages() {
 627         final long nsWindowPtr = getNSWindowPtr();
 628         final CImage cImage = getImageForTarget();
 629         nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
 630     }
 631 
 632     public long getNSWindowPtr() {


 750         contentView.exitFullScreenMode();
 751         isFullScreenMode = false;
 752     }
 753 
 754     @Override
 755     public void setWindowState(int windowState) {
 756         if (!peer.isVisible()) {
 757             // setVisible() applies the state
 758             return;
 759         }
 760 
 761         int prevWindowState = peer.getState();
 762         if (prevWindowState == windowState) return;
 763 
 764         final long nsWindowPtr = getNSWindowPtr();
 765         switch (windowState) {
 766             case Frame.ICONIFIED:
 767                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 768                     // let's return into the normal states first
 769                     // the zoom call toggles between the normal and the max states
 770                     zoom();
 771                 }
 772                 CWrapper.NSWindow.miniaturize(nsWindowPtr);
 773                 break;
 774             case Frame.MAXIMIZED_BOTH:
 775                 if (prevWindowState == Frame.ICONIFIED) {
 776                     // let's return into the normal states first
 777                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 778                 }
 779                 zoom();
 780                 break;
 781             case Frame.NORMAL:
 782                 if (prevWindowState == Frame.ICONIFIED) {
 783                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 784                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 785                     // the zoom call toggles between the normal and the max states
 786                     zoom();
 787                 }
 788                 break;
 789             default:
 790                 throw new RuntimeException("Unknown window state: " + windowState);
 791         }
 792 
 793         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 794 
 795         // NOTE: the SWP.windowState field gets updated to the newWindowState
 796         //       value when the native notification comes to us
 797     }
 798 
 799     @Override
 800     public void setModalBlocked(boolean blocked) {
 801         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 802             return;
 803         }
 804 
 805         nativeSetEnabled(getNSWindowPtr(), !blocked);
 806     }




 192             if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
 193             return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
 194         }
 195     };
 196 
 197     // Bounds of the native widget but in the Java coordinate system.
 198     // In order to keep it up-to-date we will update them on
 199     // 1) setting native bounds via nativeSetBounds() call
 200     // 2) getting notification from the native level via deliverMoveResizeEvent()
 201     private Rectangle nativeBounds;
 202     private volatile boolean isFullScreenMode = false;
 203 
 204     private Window target;
 205     private LWWindowPeer peer;
 206     private CPlatformView contentView;
 207     private CPlatformWindow owner;
 208     private boolean visible = false; // visibility status from native perspective
 209     private boolean undecorated; // initialized in getInitialStyleBits()
 210     private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
 211     private CPlatformResponder responder;
 212     private volatile boolean zoomed = false; // from native perspective
 213 
 214     public CPlatformWindow(final PeerType peerType) {
 215         super(0, true);
 216         assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 217     }
 218 
 219     /*
 220      * Delegate initialization (create native window and all the
 221      * related resources).
 222      */
 223     @Override // PlatformWindow
 224     public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
 225         this.peer = _peer;
 226         this.target = _target;
 227         if (_owner instanceof CPlatformWindow) {
 228             this.owner = (CPlatformWindow)_owner;
 229         }
 230 
 231         final int styleBits = getInitialStyleBits();
 232 


 451         return gd;
 452     }
 453 
 454     @Override // PlatformWindow
 455     public SurfaceData getScreenSurface() {
 456         // TODO: not implemented
 457         return null;
 458     }
 459 
 460     @Override // PlatformWindow
 461     public SurfaceData replaceSurfaceData() {
 462         return contentView.replaceSurfaceData();
 463     }
 464 
 465     @Override // PlatformWindow
 466     public void setBounds(int x, int y, int w, int h) {
 467 //        assert CThreading.assertEventQueue();
 468         nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
 469     }
 470 
 471     private boolean isMaximized() {
 472         return undecorated ? this.normalBounds != null : zoomed;
 473     }
 474 
 475     private void maximize() {
 476         if (isMaximized()) {
 477             return;
 478         }
 479         if (!undecorated) {
 480             zoomed = true;
 481             CWrapper.NSWindow.zoom(getNSWindowPtr());
 482         } else {
 483             deliverZoom(true);


 484 


 485             this.normalBounds = peer.getBounds();
 486             long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
 487             Rectangle toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
 488             // Flip the y coordinate
 489             Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
 490             toBounds.y = frame.height - toBounds.y - toBounds.height;
 491             setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
 492         }
 493     }
 494 
 495     private void unmaximize() {
 496         if (!isMaximized()) {
 497             return;
 498         }
 499         if (!undecorated) {
 500             zoomed = false;
 501             CWrapper.NSWindow.zoom(getNSWindowPtr());
 502         } else {
 503             deliverZoom(false);
 504 
 505             Rectangle toBounds = this.normalBounds;
 506             this.normalBounds = null;

 507             setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
 508         }
 509     }
 510 
 511     private boolean isVisible() {
 512         return this.visible;
 513     }
 514 
 515     @Override // PlatformWindow
 516     public void setVisible(boolean visible) {
 517         final long nsWindowPtr = getNSWindowPtr();
 518 
 519         // Process parent-child relationship when hiding
 520         if (!visible) {
 521             // Unparent my children
 522             for (Window w : target.getOwnedWindows()) {
 523                 WindowPeer p = (WindowPeer)w.getPeer();
 524                 if (p instanceof LWWindowPeer) {
 525                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 526                     if (pw != null && pw.isVisible()) {
 527                         CWrapper.NSWindow.removeChildWindow(nsWindowPtr, pw.getNSWindowPtr());
 528                     }
 529                 }
 530             }
 531 
 532             // Unparent myself
 533             if (owner != null && owner.isVisible()) {
 534                 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
 535             }
 536         }
 537 
 538         // Configure stuff
 539         updateIconImages();
 540         updateFocusabilityForAutoRequestFocus(false);
 541 
 542         // Actually show or hide the window













 543         LWWindowPeer blocker = peer.getBlocker();
 544         if (blocker == null || !visible) {
 545             // If it ain't blocked, or is being hidden, go regular way
 546             if (visible) {
 547                 CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
 548 
 549                 boolean isPopup = (target.getType() == Window.Type.POPUP);
 550                 if (isPopup) {
 551                     // Popups in applets don't activate applet's process
 552                     CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
 553                 } else {
 554                     CWrapper.NSWindow.orderFront(nsWindowPtr);
 555                 }
 556 
 557                 boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
 558                 if (!isKeyWindow) {
 559                     CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
 560                 }
 561             } else {
 562                 CWrapper.NSWindow.orderOut(nsWindowPtr);
 563             }
 564         } else {
 565             // otherwise, put it in a proper z-order
 566             CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
 567                     ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
 568         }
 569         this.visible = visible;
 570 
 571         // Manage the extended state when showing
 572         if (visible) {
 573             // 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                         maximize();
 581                         break;
 582                     default: // NORMAL
 583                         unmaximize(); // in case it was maximized, otherwise this is a no-op
 584                         break;
 585                 }
 586             }
 587         }
 588 
 589         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 590 
 591         // Configure stuff #2
 592         updateFocusabilityForAutoRequestFocus(true);
 593 
 594         // Manage parent-child relationship when showing
 595         if (visible) {
 596             // Add myself as a child
 597             if (owner != null && owner.isVisible()) {
 598                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
 599                 if (target.isAlwaysOnTop()) {
 600                     CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
 601                 }
 602             }
 603 
 604             // Add my own children to myself
 605             for (Window w : target.getOwnedWindows()) {
 606                 WindowPeer p = (WindowPeer)w.getPeer();
 607                 if (p instanceof LWWindowPeer) {
 608                     CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
 609                     if (pw != null && pw.isVisible()) {
 610                         CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
 611                         if (w.isAlwaysOnTop()) {
 612                             CWrapper.NSWindow.setLevel(pw.getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
 613                         }
 614                     }
 615                 }
 616             }
 617         }
 618 
 619         // Deal with the blocker of the window being shown
 620         if (blocker != null && visible) {
 621             // Make sure the blocker is above its siblings
 622             ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
 623         }
 624     }
 625 
 626     @Override // PlatformWindow
 627     public void setTitle(String title) {
 628         nativeSetNSWindowTitle(getNSWindowPtr(), title);
 629     }
 630 
 631     // Should be called on every window key property change.
 632     @Override // PlatformWindow
 633     public void updateIconImages() {
 634         final long nsWindowPtr = getNSWindowPtr();
 635         final CImage cImage = getImageForTarget();
 636         nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
 637     }
 638 
 639     public long getNSWindowPtr() {


 757         contentView.exitFullScreenMode();
 758         isFullScreenMode = false;
 759     }
 760 
 761     @Override
 762     public void setWindowState(int windowState) {
 763         if (!peer.isVisible()) {
 764             // setVisible() applies the state
 765             return;
 766         }
 767 
 768         int prevWindowState = peer.getState();
 769         if (prevWindowState == windowState) return;
 770 
 771         final long nsWindowPtr = getNSWindowPtr();
 772         switch (windowState) {
 773             case Frame.ICONIFIED:
 774                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 775                     // let's return into the normal states first
 776                     // the zoom call toggles between the normal and the max states
 777                     unmaximize();
 778                 }
 779                 CWrapper.NSWindow.miniaturize(nsWindowPtr);
 780                 break;
 781             case Frame.MAXIMIZED_BOTH:
 782                 if (prevWindowState == Frame.ICONIFIED) {
 783                     // let's return into the normal states first
 784                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 785                 }
 786                 maximize();
 787                 break;
 788             case Frame.NORMAL:
 789                 if (prevWindowState == Frame.ICONIFIED) {
 790                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
 791                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
 792                     // the zoom call toggles between the normal and the max states
 793                     unmaximize();
 794                 }
 795                 break;
 796             default:
 797                 throw new RuntimeException("Unknown window state: " + windowState);
 798         }
 799 
 800         nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr);
 801 
 802         // NOTE: the SWP.windowState field gets updated to the newWindowState
 803         //       value when the native notification comes to us
 804     }
 805 
 806     @Override
 807     public void setModalBlocked(boolean blocked) {
 808         if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
 809             return;
 810         }
 811 
 812         nativeSetEnabled(getNSWindowPtr(), !blocked);
 813     }