413 414 private native void _toggleFullScreenMode(final long model); 415 416 public void toggleFullScreen() { 417 _toggleFullScreenMode(getNSWindowPtr()); 418 } 419 420 @Override // PlatformWindow 421 public void setMenuBar(MenuBar mb) { 422 final long nsWindowPtr = getNSWindowPtr(); 423 CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb); 424 if (mbPeer != null) { 425 nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel()); 426 } else { 427 nativeSetNSWindowMenuBar(nsWindowPtr, 0); 428 } 429 } 430 431 @Override // PlatformWindow 432 public void dispose() { 433 if (owner != null) { 434 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr()); 435 } 436 contentView.dispose(); 437 nativeDispose(getNSWindowPtr()); 438 CPlatformWindow.super.dispose(); 439 } 440 441 @Override // PlatformWindow 442 public FontMetrics getFontMetrics(Font f) { 443 // TODO: not implemented 444 (new RuntimeException("unimplemented")).printStackTrace(); 445 return null; 446 } 447 448 @Override // PlatformWindow 449 public Insets getInsets() { 450 return nativeGetNSWindowInsets(getNSWindowPtr()); 451 } 452 453 @Override // PlatformWindow 454 public Point getLocationOnScreen() { 455 return new Point(nativeBounds.x, nativeBounds.y); 510 } 511 if (!undecorated) { 512 CWrapper.NSWindow.zoom(getNSWindowPtr()); 513 } else { 514 deliverZoom(false); 515 516 Rectangle toBounds = this.normalBounds; 517 this.normalBounds = null; 518 setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height); 519 } 520 } 521 522 public boolean isVisible() { 523 return this.visible; 524 } 525 526 @Override // PlatformWindow 527 public void setVisible(boolean visible) { 528 final long nsWindowPtr = getNSWindowPtr(); 529 530 // Process parent-child relationship when hiding 531 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 532 if (!visible) { 533 // Unparent my children 534 for (Window w : target.getOwnedWindows()) { 535 WindowPeer p = acc.getPeer(w); 536 if (p instanceof LWWindowPeer) { 537 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow(); 538 if (pw != null && pw.isVisible()) { 539 CWrapper.NSWindow.removeChildWindow(nsWindowPtr, pw.getNSWindowPtr()); 540 } 541 } 542 } 543 544 // Unparent myself 545 if (owner != null && owner.isVisible()) { 546 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr); 547 } 548 } 549 550 // Configure stuff 551 updateIconImages(); 552 updateFocusabilityForAutoRequestFocus(false); 553 554 boolean wasMaximized = isMaximized(); 555 556 // Actually show or hide the window 557 LWWindowPeer blocker = (peer == null)? null : peer.getBlocker(); 558 if (blocker == null || !visible) { 559 // If it ain't blocked, or is being hidden, go regular way 560 if (visible) { 561 CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView()); 562 563 boolean isPopup = (target.getType() == Window.Type.POPUP); 564 if (isPopup) { 565 // Popups in applets don't activate applet's process 566 CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); 567 } else { 568 CWrapper.NSWindow.orderFront(nsWindowPtr); 569 } 602 case Frame.ICONIFIED: 603 CWrapper.NSWindow.miniaturize(nsWindowPtr); 604 break; 605 case Frame.MAXIMIZED_BOTH: 606 maximize(); 607 break; 608 default: // NORMAL 609 unmaximize(); // in case it was maximized, otherwise this is a no-op 610 break; 611 } 612 } 613 } 614 } 615 616 nativeSynthesizeMouseEnteredExitedEvents(); 617 618 // Configure stuff #2 619 updateFocusabilityForAutoRequestFocus(true); 620 621 // Manage parent-child relationship when showing 622 if (visible) { 623 // Add myself as a child 624 if (owner != null && owner.isVisible()) { 625 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove); 626 applyWindowLevel(target); 627 } 628 629 // Add my own children to myself 630 for (Window w : target.getOwnedWindows()) { 631 final Object p = acc.getPeer(w); 632 if (p instanceof LWWindowPeer) { 633 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow(); 634 if (pw != null && pw.isVisible()) { 635 CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove); 636 pw.applyWindowLevel(w); 637 } 638 } 639 } 640 } 641 642 // Deal with the blocker of the window being shown 643 if (blocker != null && visible) { 644 // Make sure the blocker is above its siblings 645 ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings(); 646 } 647 } 648 649 @Override // PlatformWindow 650 public void setTitle(String title) { 651 nativeSetNSWindowTitle(getNSWindowPtr(), title); 652 } 653 654 // Should be called on every window key property change. 655 @Override // PlatformWindow 1041 } 1042 1043 private void orderAboveSiblings() { 1044 if (owner == null) { 1045 return; 1046 } 1047 1048 // NOTE: the logic will fail if we have a hierarchy like: 1049 // visible root owner 1050 // invisible owner 1051 // visible dialog 1052 // However, this is an unlikely scenario for real life apps 1053 if (owner.isVisible()) { 1054 // Recursively pop up the windows from the very bottom so that only 1055 // the very top-most one becomes the main window 1056 owner.orderAboveSiblings(); 1057 1058 // Order the window to front of the stack of child windows 1059 final long nsWindowSelfPtr = getNSWindowPtr(); 1060 final long nsWindowOwnerPtr = owner.getNSWindowPtr(); 1061 CWrapper.NSWindow.removeChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr); 1062 CWrapper.NSWindow.addChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove); 1063 } 1064 1065 applyWindowLevel(target); 1066 } 1067 1068 protected void applyWindowLevel(Window target) { 1069 if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) { 1070 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel); 1071 } else if (target.getType() == Window.Type.POPUP) { 1072 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel); 1073 } 1074 } 1075 1076 // ---------------------------------------------------------------------- 1077 // NATIVE CALLBACKS 1078 // ---------------------------------------------------------------------- 1079 1080 private void windowDidBecomeMain() { 1081 if (checkBlockingAndOrder()) return; 1082 // If it's not blocked, make sure it's above its siblings | 413 414 private native void _toggleFullScreenMode(final long model); 415 416 public void toggleFullScreen() { 417 _toggleFullScreenMode(getNSWindowPtr()); 418 } 419 420 @Override // PlatformWindow 421 public void setMenuBar(MenuBar mb) { 422 final long nsWindowPtr = getNSWindowPtr(); 423 CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb); 424 if (mbPeer != null) { 425 nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel()); 426 } else { 427 nativeSetNSWindowMenuBar(nsWindowPtr, 0); 428 } 429 } 430 431 @Override // PlatformWindow 432 public void dispose() { 433 contentView.dispose(); 434 nativeDispose(getNSWindowPtr()); 435 CPlatformWindow.super.dispose(); 436 } 437 438 @Override // PlatformWindow 439 public FontMetrics getFontMetrics(Font f) { 440 // TODO: not implemented 441 (new RuntimeException("unimplemented")).printStackTrace(); 442 return null; 443 } 444 445 @Override // PlatformWindow 446 public Insets getInsets() { 447 return nativeGetNSWindowInsets(getNSWindowPtr()); 448 } 449 450 @Override // PlatformWindow 451 public Point getLocationOnScreen() { 452 return new Point(nativeBounds.x, nativeBounds.y); 507 } 508 if (!undecorated) { 509 CWrapper.NSWindow.zoom(getNSWindowPtr()); 510 } else { 511 deliverZoom(false); 512 513 Rectangle toBounds = this.normalBounds; 514 this.normalBounds = null; 515 setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height); 516 } 517 } 518 519 public boolean isVisible() { 520 return this.visible; 521 } 522 523 @Override // PlatformWindow 524 public void setVisible(boolean visible) { 525 final long nsWindowPtr = getNSWindowPtr(); 526 527 // Configure stuff 528 updateIconImages(); 529 updateFocusabilityForAutoRequestFocus(false); 530 531 boolean wasMaximized = isMaximized(); 532 533 // Actually show or hide the window 534 LWWindowPeer blocker = (peer == null)? null : peer.getBlocker(); 535 if (blocker == null || !visible) { 536 // If it ain't blocked, or is being hidden, go regular way 537 if (visible) { 538 CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView()); 539 540 boolean isPopup = (target.getType() == Window.Type.POPUP); 541 if (isPopup) { 542 // Popups in applets don't activate applet's process 543 CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); 544 } else { 545 CWrapper.NSWindow.orderFront(nsWindowPtr); 546 } 579 case Frame.ICONIFIED: 580 CWrapper.NSWindow.miniaturize(nsWindowPtr); 581 break; 582 case Frame.MAXIMIZED_BOTH: 583 maximize(); 584 break; 585 default: // NORMAL 586 unmaximize(); // in case it was maximized, otherwise this is a no-op 587 break; 588 } 589 } 590 } 591 } 592 593 nativeSynthesizeMouseEnteredExitedEvents(); 594 595 // Configure stuff #2 596 updateFocusabilityForAutoRequestFocus(true); 597 598 // Manage parent-child relationship when showing 599 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 600 601 if (visible) { 602 // Order myself above my parent 603 if (owner != null && owner.isVisible()) { 604 CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr()); 605 applyWindowLevel(target); 606 } 607 608 // Order my own children above myself 609 for (Window w : target.getOwnedWindows()) { 610 final Object p = acc.getPeer(w); 611 if (p instanceof LWWindowPeer) { 612 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow(); 613 if (pw != null && pw.isVisible()) { 614 CWrapper.NSWindow.orderWindow(pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr); 615 pw.applyWindowLevel(w); 616 } 617 } 618 } 619 } 620 621 // Deal with the blocker of the window being shown 622 if (blocker != null && visible) { 623 // Make sure the blocker is above its siblings 624 ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings(); 625 } 626 } 627 628 @Override // PlatformWindow 629 public void setTitle(String title) { 630 nativeSetNSWindowTitle(getNSWindowPtr(), title); 631 } 632 633 // Should be called on every window key property change. 634 @Override // PlatformWindow 1020 } 1021 1022 private void orderAboveSiblings() { 1023 if (owner == null) { 1024 return; 1025 } 1026 1027 // NOTE: the logic will fail if we have a hierarchy like: 1028 // visible root owner 1029 // invisible owner 1030 // visible dialog 1031 // However, this is an unlikely scenario for real life apps 1032 if (owner.isVisible()) { 1033 // Recursively pop up the windows from the very bottom so that only 1034 // the very top-most one becomes the main window 1035 owner.orderAboveSiblings(); 1036 1037 // Order the window to front of the stack of child windows 1038 final long nsWindowSelfPtr = getNSWindowPtr(); 1039 final long nsWindowOwnerPtr = owner.getNSWindowPtr(); 1040 CWrapper.NSWindow.orderFront(nsWindowOwnerPtr); 1041 CWrapper.NSWindow.orderWindow(nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove, nsWindowOwnerPtr); 1042 } 1043 1044 applyWindowLevel(target); 1045 } 1046 1047 protected void applyWindowLevel(Window target) { 1048 if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) { 1049 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel); 1050 } else if (target.getType() == Window.Type.POPUP) { 1051 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel); 1052 } 1053 } 1054 1055 // ---------------------------------------------------------------------- 1056 // NATIVE CALLBACKS 1057 // ---------------------------------------------------------------------- 1058 1059 private void windowDidBecomeMain() { 1060 if (checkBlockingAndOrder()) return; 1061 // If it's not blocked, make sure it's above its siblings |