53 54 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); 55 56 @interface JavaResizeGrowBoxOverlayWindow : NSWindow { } 57 58 @end 59 60 @implementation JavaResizeGrowBoxOverlayWindow 61 62 - (BOOL) accessibilityIsIgnored 63 { 64 return YES; 65 } 66 67 - (NSArray *)accessibilityChildrenAttribute 68 { 69 return nil; 70 } 71 @end 72 73 @implementation AWTWindow 74 75 @synthesize javaPlatformWindow; 76 @synthesize javaMenuBar; 77 @synthesize growBoxWindow; 78 @synthesize javaMinSize; 79 @synthesize javaMaxSize; 80 @synthesize styleBits; 81 @synthesize isEnabled; 82 83 - (void) updateMinMaxSize:(BOOL)resizable { 84 if (resizable) { 85 [self setMinSize:self.javaMinSize]; 86 [self setMaxSize:self.javaMaxSize]; 87 } else { 88 NSRect currentFrame = [self frame]; 89 [self setMinSize:currentFrame.size]; 90 [self setMaxSize:currentFrame.size]; 91 } 92 } 93 94 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits 95 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits { 96 NSUInteger type = 0; 97 if (IS(styleBits, DECORATED)) { 98 type |= NSTitledWindowMask; 99 if (IS(styleBits, CLOSEABLE)) type |= NSClosableWindowMask; 100 if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask; 101 if (IS(styleBits, RESIZABLE)) type |= NSResizableWindowMask; 102 } else { 103 type |= NSBorderlessWindowMask; 104 } 105 106 if (IS(styleBits, TEXTURED)) type |= NSTexturedBackgroundWindowMask; 107 if (IS(styleBits, UNIFIED)) type |= NSUnifiedTitleAndToolbarWindowMask; 108 if (IS(styleBits, UTILITY)) type |= NSUtilityWindowMask; 109 if (IS(styleBits, HUD)) type |= NSHUDWindowMask; 110 if (IS(styleBits, SHEET)) type |= NSDocModalWindowMask; 111 if (IS(styleBits, NONACTIVATING)) type |= NSNonactivatingPanelMask; 112 113 return type; 114 } 115 116 // updates _METHOD_PROP_BITMASK based properties on the window 117 - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask { 118 if (IS(mask, RESIZABLE)) { 119 BOOL resizable = IS(bits, RESIZABLE); 120 [self updateMinMaxSize:resizable]; 121 [self setShowsResizeIndicator:resizable]; 122 } 123 124 if (IS(mask, HAS_SHADOW)) { 125 [self setHasShadow:IS(bits, HAS_SHADOW)]; 126 } 127 128 if (IS(mask, ZOOMABLE)) { 129 [[self standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)]; 130 } 131 132 if (IS(mask, ALWAYS_ON_TOP)) { 133 [self setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel]; 134 } 135 136 if (IS(mask, HIDES_ON_DEACTIVATE)) { 137 [self setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)]; 138 } 139 140 if (IS(mask, DRAGGABLE_BACKGROUND)) { 141 [self setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)]; 142 } 143 144 if (IS(mask, DOCUMENT_MODIFIED)) { 145 [self setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)]; 146 } 147 148 if ([self respondsToSelector:@selector(toggleFullScreen:)]) { 149 if (IS(mask, FULLSCREENABLE)) { 150 [self setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/]; 151 } else { 152 [self setCollectionBehavior:NSWindowCollectionBehaviorDefault]; 153 } 154 } 155 156 } 157 158 - (BOOL) shouldShowGrowBox { 159 return isSnowLeopardOrLower() && IS(self.styleBits, RESIZABLE); 160 } 161 162 - (NSImage *) createGrowBoxImage { 163 NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(GROW_BOX_SIZE, GROW_BOX_SIZE)]; 164 JRSUIControlRef growBoxWidget = JRSUIControlCreate(FALSE); 165 JRSUIControlSetWidget(growBoxWidget, kJRSUI_Widget_growBoxTextured); 166 JRSUIControlSetWindowType(growBoxWidget, kJRSUI_WindowType_utility); 167 JRSUIRendererRef renderer = JRSUIRendererCreate(); 168 [image lockFocus]; // sets current graphics context to that of the image 169 JRSUIControlDraw(renderer, growBoxWidget, [[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 1, GROW_BOX_SIZE - 1, GROW_BOX_SIZE - 1)); 170 [image unlockFocus]; 171 JRSUIRendererRelease(renderer); 172 JRSUIControlRelease(growBoxWidget); 173 return image; 174 } 175 176 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow 177 styleBits:(jint)bits 178 frameRect:(NSRect)rect 179 contentView:(NSView *)view 180 { 181 AWT_ASSERT_APPKIT_THREAD; 182 183 NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits]; 184 NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask]; 185 if (contentRect.size.width <= 0.0) { 186 contentRect.size.width = 1.0; 187 } 188 if (contentRect.size.height <= 0.0) { 189 contentRect.size.height = 1.0; 190 } 191 192 self = [super initWithContentRect:contentRect 193 styleMask:styleMask 194 backing:NSBackingStoreBuffered 195 defer:NO]; 196 197 if (self == nil) return nil; // no hope 198 199 self.isEnabled = YES; 200 self.javaPlatformWindow = platformWindow; 201 self.styleBits = bits; 202 [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; 203 204 [self setDelegate:self]; 205 [self setContentView:view]; 206 [self setInitialFirstResponder:view]; 207 [self setReleasedWhenClosed:NO]; 208 [self setPreservesContentDuringLiveResize:YES]; 209 210 if ([self shouldShowGrowBox]) { 211 NSImage *growBoxImage = [self createGrowBoxImage]; 212 growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; 213 [self.growBoxWindow setIgnoresMouseEvents:YES]; 214 [self.growBoxWindow setOpaque:NO]; 215 [self.growBoxWindow setBackgroundColor:[NSColor clearColor]]; 216 [self.growBoxWindow setHasShadow:NO]; 217 [self.growBoxWindow setReleasedWhenClosed:NO]; 218 219 NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]]; 220 [imageView setEditable:NO]; 221 [imageView setAnimates:NO]; 222 [imageView setAllowsCutCopyPaste:NO]; 223 [self.growBoxWindow setContentView:imageView]; 224 [imageView setImage:growBoxImage]; 225 [growBoxImage release]; 226 [imageView release]; 227 228 [self addChildWindow:self.growBoxWindow ordered:NSWindowAbove]; 229 [self adjustGrowBoxWindow]; 230 } else growBoxWindow = nil; 231 232 return self; 233 } 234 235 - (void) dealloc { 236 AWT_ASSERT_APPKIT_THREAD; 237 238 JNIEnv *env = [ThreadUtilities getJNIEnv]; 239 [self.javaPlatformWindow setJObject:nil withEnv:env]; 240 self.growBoxWindow = nil; 241 242 [super dealloc]; 243 } 244 245 // NSWindow overrides 246 - (BOOL) canBecomeKeyWindow { 247 AWT_ASSERT_APPKIT_THREAD; 248 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY); 249 } 250 251 - (BOOL) canBecomeMainWindow { 252 AWT_ASSERT_APPKIT_THREAD; 253 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN); 254 } 255 256 - (BOOL) worksWhenModal { 257 AWT_ASSERT_APPKIT_THREAD; 258 return IS(self.styleBits, MODAL_EXCLUDED); 259 } 260 261 262 // Gesture support 263 - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b { 264 AWT_ASSERT_APPKIT_THREAD; 265 266 JNIEnv *env = [ThreadUtilities getJNIEnv]; 267 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 268 if (platformWindow != NULL) { 269 // extract the target AWT Window object out of the CPlatformWindow 270 static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); 271 jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); 272 if (awtWindow != NULL) { 273 // translate the point into Java coordinates 274 NSPoint loc = [event locationInWindow]; 275 loc.y = [self frame].size.height - loc.y; 276 277 // send up to the GestureHandler to recursively dispatch on the AWT event thread 278 static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); 279 static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); 280 JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); 281 (*env)->DeleteLocalRef(env, awtWindow); 282 } 283 (*env)->DeleteLocalRef(env, platformWindow); 284 } 285 } 286 287 - (void)beginGestureWithEvent:(NSEvent *)event { 288 [self postGesture:event 289 as:com_apple_eawt_event_GestureHandler_PHASE 290 a:-1.0 291 b:0.0]; 292 } 293 294 - (void)endGestureWithEvent:(NSEvent *)event { 295 [self postGesture:event 307 308 - (void)rotateWithEvent:(NSEvent *)event { 309 [self postGesture:event 310 as:com_apple_eawt_event_GestureHandler_ROTATE 311 a:[event rotation] 312 b:0.0]; 313 } 314 315 - (void)swipeWithEvent:(NSEvent *)event { 316 [self postGesture:event 317 as:com_apple_eawt_event_GestureHandler_SWIPE 318 a:[event deltaX] 319 b:[event deltaY]]; 320 } 321 322 323 // NSWindowDelegate methods 324 325 - (void) adjustGrowBoxWindow { 326 if (self.growBoxWindow != nil) { 327 NSRect parentRect = [self frame]; 328 parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width); 329 [self.growBoxWindow setFrameOrigin:parentRect.origin]; 330 } 331 } 332 333 - (void) _deliverMoveResizeEvent { 334 AWT_ASSERT_APPKIT_THREAD; 335 336 // deliver the event if this is a user-initiated live resize or as a side-effect 337 // of a Java initiated resize, because AppKit can override the bounds and force 338 // the bounds of the window to avoid the Dock or remain on screen. 339 [AWTToolkit eventCountPlusPlus]; 340 JNIEnv *env = [ThreadUtilities getJNIEnv]; 341 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 342 if (platformWindow == NULL) { 343 // TODO: create generic AWT assert 344 } 345 346 [self adjustGrowBoxWindow]; 347 348 NSRect frame = ConvertNSScreenRect(env, [self frame]); 349 350 static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); 351 JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, 352 (jint)frame.origin.x, 353 (jint)frame.origin.y, 354 (jint)frame.size.width, 355 (jint)frame.size.height); 356 (*env)->DeleteLocalRef(env, platformWindow); 357 } 358 359 - (void)windowDidMove:(NSNotification *)notification { 360 AWT_ASSERT_APPKIT_THREAD; 361 362 [self _deliverMoveResizeEvent]; 363 } 364 365 - (void)windowDidResize:(NSNotification *)notification { 366 AWT_ASSERT_APPKIT_THREAD; 367 368 [self _deliverMoveResizeEvent]; 518 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; 519 (*env)->DeleteLocalRef(env, platformWindow); 520 } 521 } 522 523 - (void)windowDidExitFullScreen:(NSNotification *)notification { 524 static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); 525 JNIEnv *env = [ThreadUtilities getJNIEnv]; 526 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 527 if (platformWindow != NULL) { 528 JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); 529 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; 530 (*env)->DeleteLocalRef(env, platformWindow); 531 } 532 } 533 534 - (void)sendEvent:(NSEvent *)event { 535 if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { 536 537 NSPoint p = [NSEvent mouseLocation]; 538 NSRect frame = [self frame]; 539 NSRect contentRect = [self contentRectForFrameRect:frame]; 540 541 // Check if the click happened in the non-client area (title bar) 542 if (p.y >= (frame.origin.y + contentRect.size.height)) { 543 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 544 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 545 // Currently, no need to deliver the whole NSEvent. 546 static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); 547 JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); 548 } 549 } 550 [super sendEvent:event]; 551 } 552 553 - (void)constrainSize:(NSSize*)size { 554 float minWidth = 0.f, minHeight = 0.f; 555 556 if (IS(self.styleBits, DECORATED)) { 557 NSRect frame = [self frame]; 558 NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self styleMask]]; 559 560 float top = frame.size.height - contentRect.size.height; 561 float left = contentRect.origin.x - frame.origin.x; 562 float bottom = contentRect.origin.y - frame.origin.y; 563 float right = frame.size.width - (contentRect.size.width + left); 564 565 // Speculative estimation: 80 - enough for window decorations controls 566 minWidth += left + right + 80; 567 minHeight += top + bottom; 568 } 569 570 if ([self shouldShowGrowBox]) { 571 minWidth = MAX(minWidth, GROW_BOX_SIZE); 572 minHeight += GROW_BOX_SIZE; 573 } 574 575 minWidth = MAX(1.f, minWidth); 576 minHeight = MAX(1.f, minHeight); 577 578 size->width = MAX(size->width, minWidth); 579 size->height = MAX(size->height, minHeight); 580 } 581 582 - (void) setEnabled: (BOOL)flag { 583 self.isEnabled = flag; 584 585 if (IS(self.styleBits, CLOSEABLE)) { 586 [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag]; 587 } 588 589 if (IS(self.styleBits, MINIMIZABLE)) { 590 [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag]; 591 } 592 593 if (IS(self.styleBits, ZOOMABLE)) { 594 [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag]; 595 } 596 597 if (IS(self.styleBits, RESIZABLE)) { 598 [self updateMinMaxSize:flag]; 599 [self setShowsResizeIndicator:flag]; 600 } 601 } 602 603 @end // AWTWindow 604 605 606 /* 607 * Class: sun_lwawt_macosx_CPlatformWindow 608 * Method: nativeCreateNSWindow 609 * Signature: (JJIIII)J 610 */ 611 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow 612 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h) 613 { 614 __block AWTWindow *window = nil; 615 616 JNF_COCOA_ENTER(env); 617 AWT_ASSERT_NOT_APPKIT_THREAD; 618 619 JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; 620 NSView *contentView = OBJC(contentViewPtr); 621 NSRect frameRect = NSMakeRect(x, y, w, h); 622 623 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 624 AWT_ASSERT_APPKIT_THREAD; 625 626 window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow 627 styleBits:styleBits 628 frameRect:frameRect 629 contentView:contentView]; 630 631 if (window) CFRetain(window); 632 [window release]; // GC 633 }]; 634 635 JNF_COCOA_EXIT(env); 636 637 return ptr_to_jlong(window); 638 } 639 640 /* 641 * Class: sun_lwawt_macosx_CPlatformWindow 642 * Method: nativeSetNSWindowStyleBits 643 * Signature: (JII)V 644 */ 645 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits 646 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) 647 { 648 JNF_COCOA_ENTER(env); 649 AWT_ASSERT_NOT_APPKIT_THREAD; 650 651 AWTWindow *window = OBJC(windowPtr); 652 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 653 AWT_ASSERT_APPKIT_THREAD; 654 655 // scans the bit field, and only updates the values requested by the mask 656 // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) 657 jint newBits = window.styleBits & ~mask | bits & mask; 658 659 // resets the NSWindow's style mask if the mask intersects any of those bits 660 if (mask & MASK(_STYLE_PROP_BITMASK)) { 661 [window setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; 662 } 663 664 // calls methods on NSWindow to change other properties, based on the mask 665 if (mask & MASK(_METHOD_PROP_BITMASK)) { 666 [window setPropertiesForStyleBits:bits mask:mask]; 667 } 668 669 window.styleBits = newBits; 670 }]; 671 672 JNF_COCOA_EXIT(env); 673 } 674 675 /* 676 * Class: sun_lwawt_macosx_CPlatformWindow 677 * Method: nativeSetNSWindowMenuBar 678 * Signature: (JJ)V 679 */ 680 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar 681 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) 682 { 683 JNF_COCOA_ENTER(env); 684 AWT_ASSERT_NOT_APPKIT_THREAD; 685 686 AWTWindow *window = OBJC(windowPtr); 687 CMenuBar *menuBar = OBJC(menuBarPtr); 688 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 689 AWT_ASSERT_APPKIT_THREAD; 690 691 if ([window isKeyWindow]) [window.javaMenuBar deactivate]; 692 window.javaMenuBar = menuBar; 693 694 // if ([self isKeyWindow]) { 695 [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; 696 // } 697 }]; 698 699 JNF_COCOA_EXIT(env); 700 } 701 702 /* 703 * Class: sun_lwawt_macosx_CPlatformWindow 704 * Method: nativeGetNSWindowInsets 705 * Signature: (J)Ljava/awt/Insets; 706 */ 707 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets 708 (JNIEnv *env, jclass clazz, jlong windowPtr) 709 { 710 jobject ret = NULL; 711 712 JNF_COCOA_ENTER(env); 713 AWT_ASSERT_NOT_APPKIT_THREAD; 714 715 AWTWindow *window = OBJC(windowPtr); 716 __block NSRect contentRect = NSZeroRect; 717 __block NSRect frame = NSZeroRect; 718 719 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 720 AWT_ASSERT_APPKIT_THREAD; 721 722 frame = [window frame]; 723 contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]]; 724 }]; 725 726 jint top = (jint)(frame.size.height - contentRect.size.height); 727 jint left = (jint)(contentRect.origin.x - frame.origin.x); 728 jint bottom = (jint)(contentRect.origin.y - frame.origin.y); 729 jint right = (jint)(frame.size.width - (contentRect.size.width + left)); 730 731 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); 732 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); 733 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); 734 735 JNF_COCOA_EXIT(env); 736 return ret; 737 } 738 739 /* 740 * Class: sun_lwawt_macosx_CPlatformWindow 741 * Method: nativeSetNSWindowBounds 742 * Signature: (JDDDD)V 743 */ 744 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds 745 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) 746 { 747 JNF_COCOA_ENTER(env); 748 AWT_ASSERT_NOT_APPKIT_THREAD; 749 750 NSRect jrect = NSMakeRect(originX, originY, width, height); 751 752 // TODO: not sure we need displayIfNeeded message in our view 753 AWTWindow *window = OBJC(windowPtr); 754 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 755 AWT_ASSERT_APPKIT_THREAD; 756 757 NSRect rect = ConvertNSScreenRect(NULL, jrect); 758 [window constrainSize:&rect.size]; 759 760 [window setFrame:rect display:YES]; 761 762 // only start tracking events if pointer is above the toplevel 763 // TODO: should post an Entered event if YES. 764 NSPoint mLocation = [NSEvent mouseLocation]; 765 [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; 766 767 // ensure we repaint the whole window after the resize operation 768 // (this will also re-enable screen updates, which were disabled above) 769 // TODO: send PaintEvent 770 }]; 771 772 JNF_COCOA_EXIT(env); 773 } 774 775 /* 776 * Class: sun_lwawt_macosx_CPlatformWindow 777 * Method: nativeSetNSWindowMinMax 778 * Signature: (JDDDD)V 779 */ 780 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 781 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 782 { 783 JNF_COCOA_ENTER(env); 784 AWT_ASSERT_NOT_APPKIT_THREAD; 785 786 if (minW < 1) minW = 1; 787 if (minH < 1) minH = 1; 788 if (maxW < 1) maxW = 1; 789 if (maxH < 1) maxH = 1; 790 791 AWTWindow *window = OBJC(windowPtr); 792 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 793 AWT_ASSERT_APPKIT_THREAD; 794 795 NSSize min = { minW, minH }; 796 NSSize max = { maxW, maxH }; 797 798 [window constrainSize:&min]; 799 [window constrainSize:&max]; 800 801 window.javaMinSize = min; 802 window.javaMaxSize = max; 803 [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; 804 }]; 805 806 JNF_COCOA_EXIT(env); 807 } 808 809 /* 810 * Class: sun_lwawt_macosx_CPlatformWindow 811 * Method: nativePushNSWindowToBack 812 * Signature: (J)V 813 */ 814 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack 815 (JNIEnv *env, jclass clazz, jlong windowPtr) 816 { 817 JNF_COCOA_ENTER(env); 818 AWT_ASSERT_NOT_APPKIT_THREAD; 819 820 AWTWindow *window = OBJC(windowPtr); 821 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 822 AWT_ASSERT_APPKIT_THREAD; 823 824 [window orderBack:nil]; 825 }]; 826 827 JNF_COCOA_EXIT(env); 828 } 829 830 /* 831 * Class: sun_lwawt_macosx_CPlatformWindow 832 * Method: nativePushNSWindowToFront 833 * Signature: (J)V 834 */ 835 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront 836 (JNIEnv *env, jclass clazz, jlong windowPtr) 837 { 838 JNF_COCOA_ENTER(env); 839 AWT_ASSERT_NOT_APPKIT_THREAD; 840 841 AWTWindow *window = OBJC(windowPtr); 842 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 843 AWT_ASSERT_APPKIT_THREAD; 844 845 if (![window isKeyWindow]) { 846 [window makeKeyAndOrderFront:window]; 847 } else { 848 [window orderFront:window]; 849 } 850 }]; 851 852 JNF_COCOA_EXIT(env); 853 } 854 855 /* 856 * Class: sun_lwawt_macosx_CPlatformWindow 857 * Method: nativeSetNSWindowTitle 858 * Signature: (JLjava/lang/String;)V 859 */ 860 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle 861 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) 862 { 863 JNF_COCOA_ENTER(env); 864 AWT_ASSERT_NOT_APPKIT_THREAD; 865 866 AWTWindow *window = OBJC(windowPtr); 867 [window performSelectorOnMainThread:@selector(setTitle:) 868 withObject:JNFJavaToNSString(env, jtitle) 869 waitUntilDone:NO]; 870 871 JNF_COCOA_EXIT(env); 872 } 873 874 /* 875 * Class: sun_lwawt_macosx_CPlatformWindow 876 * Method: nativeSetNSWindowAlpha 877 * Signature: (JF)V 878 */ 879 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowAlpha 880 (JNIEnv *env, jclass clazz, jlong windowPtr, jfloat alpha) 881 { 882 JNF_COCOA_ENTER(env); 883 AWT_ASSERT_NOT_APPKIT_THREAD; 884 885 AWTWindow *window = OBJC(windowPtr); 886 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 887 AWT_ASSERT_APPKIT_THREAD; 888 889 [window setAlphaValue:alpha]; 890 [window.growBoxWindow setAlphaValue:alpha]; 891 }]; 892 893 JNF_COCOA_EXIT(env); 894 } 895 896 /* 897 * Class: sun_lwawt_macosx_CPlatformWindow 898 * Method: nativeRevalidateNSWindowShadow 899 * Signature: (J)V 900 */ 901 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow 902 (JNIEnv *env, jclass clazz, jlong windowPtr) 903 { 904 JNF_COCOA_ENTER(env); 905 AWT_ASSERT_NOT_APPKIT_THREAD; 906 907 AWTWindow *window = OBJC(windowPtr); 908 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 909 AWT_ASSERT_APPKIT_THREAD; 910 911 [window invalidateShadow]; 912 }]; 913 914 JNF_COCOA_EXIT(env); 915 } 916 917 /* 918 * Class: sun_lwawt_macosx_CPlatformWindow 919 * Method: nativeScreenOn_AppKitThread 920 * Signature: (J)I 921 */ 922 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread 923 (JNIEnv *env, jclass clazz, jlong windowPtr) 924 { 925 jint ret = 0; 926 927 JNF_COCOA_ENTER(env); 928 AWT_ASSERT_APPKIT_THREAD; 929 930 AWTWindow *window = OBJC(windowPtr); 931 NSDictionary *props = [[window screen] deviceDescription]; 932 ret = [[props objectForKey:@"NSScreenNumber"] intValue]; 933 934 JNF_COCOA_EXIT(env); 935 936 return ret; 937 } 938 939 /* 940 * Class: sun_lwawt_macosx_CPlatformWindow 941 * Method: nativeSetNSWindowMinimizedIcon 942 * Signature: (JJ)V 943 */ 944 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon 945 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) 946 { 947 JNF_COCOA_ENTER(env); 948 AWT_ASSERT_NOT_APPKIT_THREAD; 949 950 AWTWindow *window = OBJC(windowPtr); 951 NSImage *image = OBJC(nsImagePtr); 952 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 953 AWT_ASSERT_APPKIT_THREAD; 954 955 [window setMiniwindowImage:image]; 956 }]; 957 958 JNF_COCOA_EXIT(env); 959 } 960 961 /* 962 * Class: sun_lwawt_macosx_CPlatformWindow 963 * Method: nativeSetNSWindowRepresentedFilename 964 * Signature: (JLjava/lang/String;)V 965 */ 966 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename 967 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) 968 { 969 JNF_COCOA_ENTER(env); 970 AWT_ASSERT_NOT_APPKIT_THREAD; 971 972 AWTWindow *window = OBJC(windowPtr); 973 NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; 974 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 975 AWT_ASSERT_APPKIT_THREAD; 976 977 [window setRepresentedURL:url]; 978 }]; 979 980 JNF_COCOA_EXIT(env); 981 } 982 983 /* 984 * Class: sun_lwawt_macosx_CPlatformWindow 985 * Method: nativeSetNSWindowSecurityWarningPositioning 986 * Signature: (JDDFF)V 987 */ 988 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning 989 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY) 990 { 991 JNF_COCOA_ENTER(env); 992 AWT_ASSERT_NOT_APPKIT_THREAD; 993 994 [JNFException raise:env as:kRuntimeException reason:"unimplemented"]; 995 996 JNF_COCOA_EXIT(env); 997 } 998 999 /* 1000 * Class: sun_lwawt_macosx_CPlatformWindow 1001 * Method: nativeGetScreenNSWindowIsOn_AppKitThread 1002 * Signature: (J)I 1003 */ 1004 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread 1005 (JNIEnv *env, jclass clazz, jlong windowPtr) 1006 { 1007 jint index = -1; 1008 1009 JNF_COCOA_ENTER(env); 1010 AWT_ASSERT_APPKIT_THREAD; 1011 1012 AWTWindow *window = OBJC(windowPtr); 1013 NSScreen* screen = [window screen]; 1014 1015 //+++gdb NOTE: This is using a linear search of the screens. If it should 1016 // prove to be a bottleneck, this can definitely be improved. However, 1017 // many screens should prove to be the exception, rather than the rule. 1018 NSArray* screens = [NSScreen screens]; 1019 NSUInteger i; 1020 for (i = 0; i < [screens count]; i++) 1021 { 1022 if ([[screens objectAtIndex:i] isEqualTo:screen]) 1023 { 1024 index = i; 1025 break; 1026 } 1027 } 1028 1029 JNF_COCOA_EXIT(env); 1030 return 1; 1031 } 1032 1033 1034 /* 1035 * Class: sun_lwawt_macosx_CPlatformWindow 1036 * Method: _toggleFullScreenMode 1037 * Signature: (J)V 1038 */ 1039 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode 1040 (JNIEnv *env, jobject peer, jlong windowPtr) 1041 { 1042 JNF_COCOA_ENTER(env); 1043 1044 AWTWindow *window = OBJC(windowPtr); 1045 SEL toggleFullScreenSelector = @selector(toggleFullScreen:); 1046 if (![window respondsToSelector:toggleFullScreenSelector]) return; 1047 1048 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1049 [window performSelector:toggleFullScreenSelector withObject:nil]; 1050 }]; 1051 1052 JNF_COCOA_EXIT(env); 1053 } 1054 1055 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse 1056 (JNIEnv *env, jclass clazz, jlong windowPtr) 1057 { 1058 __block jboolean underMouse = JNI_FALSE; 1059 1060 JNF_COCOA_ENTER(env); 1061 AWT_ASSERT_NOT_APPKIT_THREAD; 1062 1063 AWTWindow *aWindow = OBJC(windowPtr); 1064 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() { 1065 AWT_ASSERT_APPKIT_THREAD; 1066 1067 NSPoint pt = [aWindow mouseLocationOutsideOfEventStream]; 1068 underMouse = [[aWindow contentView] hitTest:pt] != nil; 1069 }]; 1070 1071 JNF_COCOA_EXIT(env); 1072 1073 return underMouse; 1074 } 1075 1076 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled 1077 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) 1078 { 1079 JNF_COCOA_ENTER(env); 1080 1081 AWTWindow *window = OBJC(windowPtr); 1082 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1083 [window setEnabled: isEnabled]; 1084 }]; 1085 1086 JNF_COCOA_EXIT(env); 1087 } 1088 | 53 54 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); 55 56 @interface JavaResizeGrowBoxOverlayWindow : NSWindow { } 57 58 @end 59 60 @implementation JavaResizeGrowBoxOverlayWindow 61 62 - (BOOL) accessibilityIsIgnored 63 { 64 return YES; 65 } 66 67 - (NSArray *)accessibilityChildrenAttribute 68 { 69 return nil; 70 } 71 @end 72 73 // -------------------------------------------------------------- 74 // NSWindow/NSPanel descendants implementation 75 #define AWT_NS_WINDOW_IMPLEMENTATION \ 76 - (id) initWithDelegate:(AWTWindow *)delegate \ 77 frameRect:(NSRect)contectRect \ 78 styleMask:(NSUInteger)styleMask \ 79 contentView:(NSView *)view \ 80 { \ 81 self = [super initWithContentRect:contectRect \ 82 styleMask:styleMask \ 83 backing:NSBackingStoreBuffered \ 84 defer:NO]; \ 85 \ 86 if (self == nil) return nil; \ 87 \ 88 [self setDelegate:delegate]; \ 89 [self setContentView:view]; \ 90 [self setInitialFirstResponder:view]; \ 91 [self setReleasedWhenClosed:NO]; \ 92 [self setPreservesContentDuringLiveResize:YES]; \ 93 \ 94 return self; \ 95 } \ 96 \ 97 /* NSWindow overrides */ \ 98 - (BOOL) canBecomeKeyWindow { \ 99 return [(AWTWindow*)[self delegate] canBecomeKeyWindow]; \ 100 } \ 101 \ 102 - (BOOL) canBecomeMainWindow { \ 103 return [(AWTWindow*)[self delegate] canBecomeMainWindow]; \ 104 } \ 105 \ 106 - (BOOL) worksWhenModal { \ 107 return [(AWTWindow*)[self delegate] worksWhenModal]; \ 108 } \ 109 \ 110 - (void)sendEvent:(NSEvent *)event { \ 111 [(AWTWindow*)[self delegate] sendEvent:event]; \ 112 [super sendEvent:event]; \ 113 } 114 115 @implementation AWTWindow_Normal 116 AWT_NS_WINDOW_IMPLEMENTATION 117 @end 118 @implementation AWTWindow_Panel 119 AWT_NS_WINDOW_IMPLEMENTATION 120 @end 121 // END of NSWindow/NSPanel descendants implementation 122 // -------------------------------------------------------------- 123 124 125 @implementation AWTWindow 126 127 @synthesize nsWindow; 128 @synthesize javaPlatformWindow; 129 @synthesize javaMenuBar; 130 @synthesize growBoxWindow; 131 @synthesize javaMinSize; 132 @synthesize javaMaxSize; 133 @synthesize styleBits; 134 @synthesize isEnabled; 135 136 - (void) updateMinMaxSize:(BOOL)resizable { 137 if (resizable) { 138 [self.nsWindow setMinSize:self.javaMinSize]; 139 [self.nsWindow setMaxSize:self.javaMaxSize]; 140 } else { 141 NSRect currentFrame = [self.nsWindow frame]; 142 [self.nsWindow setMinSize:currentFrame.size]; 143 [self.nsWindow setMaxSize:currentFrame.size]; 144 } 145 } 146 147 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits 148 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits { 149 NSUInteger type = 0; 150 if (IS(styleBits, DECORATED)) { 151 type |= NSTitledWindowMask; 152 if (IS(styleBits, CLOSEABLE)) type |= NSClosableWindowMask; 153 if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask; 154 if (IS(styleBits, RESIZABLE)) type |= NSResizableWindowMask; 155 } else { 156 type |= NSBorderlessWindowMask; 157 } 158 159 if (IS(styleBits, TEXTURED)) type |= NSTexturedBackgroundWindowMask; 160 if (IS(styleBits, UNIFIED)) type |= NSUnifiedTitleAndToolbarWindowMask; 161 if (IS(styleBits, UTILITY)) type |= NSUtilityWindowMask; 162 if (IS(styleBits, HUD)) type |= NSHUDWindowMask; 163 if (IS(styleBits, SHEET)) type |= NSDocModalWindowMask; 164 if (IS(styleBits, NONACTIVATING)) type |= NSNonactivatingPanelMask; 165 166 return type; 167 } 168 169 // updates _METHOD_PROP_BITMASK based properties on the window 170 - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask { 171 if (IS(mask, RESIZABLE)) { 172 BOOL resizable = IS(bits, RESIZABLE); 173 [self updateMinMaxSize:resizable]; 174 [self.nsWindow setShowsResizeIndicator:resizable]; 175 } 176 177 if (IS(mask, HAS_SHADOW)) { 178 [self.nsWindow setHasShadow:IS(bits, HAS_SHADOW)]; 179 } 180 181 if (IS(mask, ZOOMABLE)) { 182 [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)]; 183 } 184 185 if (IS(mask, ALWAYS_ON_TOP)) { 186 [self.nsWindow setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel]; 187 } 188 189 if (IS(mask, HIDES_ON_DEACTIVATE)) { 190 [self.nsWindow setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)]; 191 } 192 193 if (IS(mask, DRAGGABLE_BACKGROUND)) { 194 [self.nsWindow setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)]; 195 } 196 197 if (IS(mask, DOCUMENT_MODIFIED)) { 198 [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)]; 199 } 200 201 if ([self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) { 202 if (IS(mask, FULLSCREENABLE)) { 203 [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/]; 204 } else { 205 [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault]; 206 } 207 } 208 209 } 210 211 - (BOOL) shouldShowGrowBox { 212 return isSnowLeopardOrLower() && IS(self.styleBits, RESIZABLE); 213 } 214 215 - (NSImage *) createGrowBoxImage { 216 NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(GROW_BOX_SIZE, GROW_BOX_SIZE)]; 217 JRSUIControlRef growBoxWidget = JRSUIControlCreate(FALSE); 218 JRSUIControlSetWidget(growBoxWidget, kJRSUI_Widget_growBoxTextured); 219 JRSUIControlSetWindowType(growBoxWidget, kJRSUI_WindowType_utility); 220 JRSUIRendererRef renderer = JRSUIRendererCreate(); 221 [image lockFocus]; // sets current graphics context to that of the image 222 JRSUIControlDraw(renderer, growBoxWidget, [[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 1, GROW_BOX_SIZE - 1, GROW_BOX_SIZE - 1)); 223 [image unlockFocus]; 224 JRSUIRendererRelease(renderer); 225 JRSUIControlRelease(growBoxWidget); 226 return image; 227 } 228 229 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow 230 styleBits:(jint)bits 231 frameRect:(NSRect)rect 232 contentView:(NSView *)view 233 { 234 AWT_ASSERT_APPKIT_THREAD; 235 236 NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits]; 237 NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask]; 238 if (contentRect.size.width <= 0.0) { 239 contentRect.size.width = 1.0; 240 } 241 if (contentRect.size.height <= 0.0) { 242 contentRect.size.height = 1.0; 243 } 244 245 self = [super init]; 246 247 if (self == nil) return nil; // no hope 248 249 if (IS(bits, UTILITY) || 250 IS(bits, NONACTIVATING) || 251 IS(bits, HUD) || 252 IS(bits, HIDES_ON_DEACTIVATE)) 253 { 254 self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self 255 frameRect:contentRect 256 styleMask:styleMask 257 contentView:view]; 258 } 259 else 260 { 261 // These windows will appear in the window list in the dock icon menu 262 self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self 263 frameRect:contentRect 264 styleMask:styleMask 265 contentView:view]; 266 } 267 268 if (self.nsWindow == nil) return nil; // no hope either 269 270 self.isEnabled = YES; 271 self.javaPlatformWindow = platformWindow; 272 self.styleBits = bits; 273 [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; 274 275 if ([self shouldShowGrowBox]) { 276 NSImage *growBoxImage = [self createGrowBoxImage]; 277 growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; 278 [self.growBoxWindow setIgnoresMouseEvents:YES]; 279 [self.growBoxWindow setOpaque:NO]; 280 [self.growBoxWindow setBackgroundColor:[NSColor clearColor]]; 281 [self.growBoxWindow setHasShadow:NO]; 282 [self.growBoxWindow setReleasedWhenClosed:NO]; 283 284 NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]]; 285 [imageView setEditable:NO]; 286 [imageView setAnimates:NO]; 287 [imageView setAllowsCutCopyPaste:NO]; 288 [self.growBoxWindow setContentView:imageView]; 289 [imageView setImage:growBoxImage]; 290 [growBoxImage release]; 291 [imageView release]; 292 293 [self.nsWindow addChildWindow:self.growBoxWindow ordered:NSWindowAbove]; 294 [self adjustGrowBoxWindow]; 295 } else growBoxWindow = nil; 296 297 return self; 298 } 299 300 - (void) dealloc { 301 AWT_ASSERT_APPKIT_THREAD; 302 303 JNIEnv *env = [ThreadUtilities getJNIEnv]; 304 [self.javaPlatformWindow setJObject:nil withEnv:env]; 305 self.growBoxWindow = nil; 306 307 self.nsWindow = nil; 308 309 [super dealloc]; 310 } 311 312 // NSWindow overrides 313 - (BOOL) canBecomeKeyWindow { 314 AWT_ASSERT_APPKIT_THREAD; 315 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY); 316 } 317 318 - (BOOL) canBecomeMainWindow { 319 AWT_ASSERT_APPKIT_THREAD; 320 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN); 321 } 322 323 - (BOOL) worksWhenModal { 324 AWT_ASSERT_APPKIT_THREAD; 325 return IS(self.styleBits, MODAL_EXCLUDED); 326 } 327 328 329 // Gesture support 330 - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b { 331 AWT_ASSERT_APPKIT_THREAD; 332 333 JNIEnv *env = [ThreadUtilities getJNIEnv]; 334 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 335 if (platformWindow != NULL) { 336 // extract the target AWT Window object out of the CPlatformWindow 337 static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); 338 jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); 339 if (awtWindow != NULL) { 340 // translate the point into Java coordinates 341 NSPoint loc = [event locationInWindow]; 342 loc.y = [self.nsWindow frame].size.height - loc.y; 343 344 // send up to the GestureHandler to recursively dispatch on the AWT event thread 345 static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); 346 static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); 347 JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); 348 (*env)->DeleteLocalRef(env, awtWindow); 349 } 350 (*env)->DeleteLocalRef(env, platformWindow); 351 } 352 } 353 354 - (void)beginGestureWithEvent:(NSEvent *)event { 355 [self postGesture:event 356 as:com_apple_eawt_event_GestureHandler_PHASE 357 a:-1.0 358 b:0.0]; 359 } 360 361 - (void)endGestureWithEvent:(NSEvent *)event { 362 [self postGesture:event 374 375 - (void)rotateWithEvent:(NSEvent *)event { 376 [self postGesture:event 377 as:com_apple_eawt_event_GestureHandler_ROTATE 378 a:[event rotation] 379 b:0.0]; 380 } 381 382 - (void)swipeWithEvent:(NSEvent *)event { 383 [self postGesture:event 384 as:com_apple_eawt_event_GestureHandler_SWIPE 385 a:[event deltaX] 386 b:[event deltaY]]; 387 } 388 389 390 // NSWindowDelegate methods 391 392 - (void) adjustGrowBoxWindow { 393 if (self.growBoxWindow != nil) { 394 NSRect parentRect = [self.nsWindow frame]; 395 parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width); 396 [self.growBoxWindow setFrameOrigin:parentRect.origin]; 397 } 398 } 399 400 - (void) _deliverMoveResizeEvent { 401 AWT_ASSERT_APPKIT_THREAD; 402 403 // deliver the event if this is a user-initiated live resize or as a side-effect 404 // of a Java initiated resize, because AppKit can override the bounds and force 405 // the bounds of the window to avoid the Dock or remain on screen. 406 [AWTToolkit eventCountPlusPlus]; 407 JNIEnv *env = [ThreadUtilities getJNIEnv]; 408 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 409 if (platformWindow == NULL) { 410 // TODO: create generic AWT assert 411 } 412 413 [self adjustGrowBoxWindow]; 414 415 NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]); 416 417 static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); 418 JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, 419 (jint)frame.origin.x, 420 (jint)frame.origin.y, 421 (jint)frame.size.width, 422 (jint)frame.size.height); 423 (*env)->DeleteLocalRef(env, platformWindow); 424 } 425 426 - (void)windowDidMove:(NSNotification *)notification { 427 AWT_ASSERT_APPKIT_THREAD; 428 429 [self _deliverMoveResizeEvent]; 430 } 431 432 - (void)windowDidResize:(NSNotification *)notification { 433 AWT_ASSERT_APPKIT_THREAD; 434 435 [self _deliverMoveResizeEvent]; 585 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; 586 (*env)->DeleteLocalRef(env, platformWindow); 587 } 588 } 589 590 - (void)windowDidExitFullScreen:(NSNotification *)notification { 591 static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); 592 JNIEnv *env = [ThreadUtilities getJNIEnv]; 593 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 594 if (platformWindow != NULL) { 595 JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); 596 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; 597 (*env)->DeleteLocalRef(env, platformWindow); 598 } 599 } 600 601 - (void)sendEvent:(NSEvent *)event { 602 if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { 603 604 NSPoint p = [NSEvent mouseLocation]; 605 NSRect frame = [self.nsWindow frame]; 606 NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame]; 607 608 // Check if the click happened in the non-client area (title bar) 609 if (p.y >= (frame.origin.y + contentRect.size.height)) { 610 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 611 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 612 // Currently, no need to deliver the whole NSEvent. 613 static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); 614 JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); 615 } 616 } 617 } 618 619 - (void)constrainSize:(NSSize*)size { 620 float minWidth = 0.f, minHeight = 0.f; 621 622 if (IS(self.styleBits, DECORATED)) { 623 NSRect frame = [self.nsWindow frame]; 624 NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self.nsWindow styleMask]]; 625 626 float top = frame.size.height - contentRect.size.height; 627 float left = contentRect.origin.x - frame.origin.x; 628 float bottom = contentRect.origin.y - frame.origin.y; 629 float right = frame.size.width - (contentRect.size.width + left); 630 631 // Speculative estimation: 80 - enough for window decorations controls 632 minWidth += left + right + 80; 633 minHeight += top + bottom; 634 } 635 636 if ([self shouldShowGrowBox]) { 637 minWidth = MAX(minWidth, GROW_BOX_SIZE); 638 minHeight += GROW_BOX_SIZE; 639 } 640 641 minWidth = MAX(1.f, minWidth); 642 minHeight = MAX(1.f, minHeight); 643 644 size->width = MAX(size->width, minWidth); 645 size->height = MAX(size->height, minHeight); 646 } 647 648 - (void) setEnabled: (BOOL)flag { 649 self.isEnabled = flag; 650 651 if (IS(self.styleBits, CLOSEABLE)) { 652 [[self.nsWindow standardWindowButton:NSWindowCloseButton] setEnabled: flag]; 653 } 654 655 if (IS(self.styleBits, MINIMIZABLE)) { 656 [[self.nsWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag]; 657 } 658 659 if (IS(self.styleBits, ZOOMABLE)) { 660 [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled: flag]; 661 } 662 663 if (IS(self.styleBits, RESIZABLE)) { 664 [self updateMinMaxSize:flag]; 665 [self.nsWindow setShowsResizeIndicator:flag]; 666 } 667 } 668 669 @end // AWTWindow 670 671 672 /* 673 * Class: sun_lwawt_macosx_CPlatformWindow 674 * Method: nativeCreateNSWindow 675 * Signature: (JJIIII)J 676 */ 677 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow 678 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h) 679 { 680 __block AWTWindow *window = nil; 681 682 JNF_COCOA_ENTER(env); 683 AWT_ASSERT_NOT_APPKIT_THREAD; 684 685 JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; 686 NSView *contentView = OBJC(contentViewPtr); 687 NSRect frameRect = NSMakeRect(x, y, w, h); 688 689 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 690 AWT_ASSERT_APPKIT_THREAD; 691 692 window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow 693 styleBits:styleBits 694 frameRect:frameRect 695 contentView:contentView]; 696 697 if (window) CFRetain(window); 698 [window release]; // GC 699 }]; 700 701 JNF_COCOA_EXIT(env); 702 703 return ptr_to_jlong(window ? window.nsWindow : nil); 704 } 705 706 /* 707 * Class: sun_lwawt_macosx_CPlatformWindow 708 * Method: nativeSetNSWindowStyleBits 709 * Signature: (JII)V 710 */ 711 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits 712 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) 713 { 714 JNF_COCOA_ENTER(env); 715 AWT_ASSERT_NOT_APPKIT_THREAD; 716 717 NSWindow *nsWindow = OBJC(windowPtr); 718 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 719 AWT_ASSERT_APPKIT_THREAD; 720 721 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 722 723 // scans the bit field, and only updates the values requested by the mask 724 // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) 725 jint newBits = window.styleBits & ~mask | bits & mask; 726 727 // resets the NSWindow's style mask if the mask intersects any of those bits 728 if (mask & MASK(_STYLE_PROP_BITMASK)) { 729 [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; 730 } 731 732 // calls methods on NSWindow to change other properties, based on the mask 733 if (mask & MASK(_METHOD_PROP_BITMASK)) { 734 [window setPropertiesForStyleBits:bits mask:mask]; 735 } 736 737 window.styleBits = newBits; 738 }]; 739 740 JNF_COCOA_EXIT(env); 741 } 742 743 /* 744 * Class: sun_lwawt_macosx_CPlatformWindow 745 * Method: nativeSetNSWindowMenuBar 746 * Signature: (JJ)V 747 */ 748 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar 749 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) 750 { 751 JNF_COCOA_ENTER(env); 752 AWT_ASSERT_NOT_APPKIT_THREAD; 753 754 NSWindow *nsWindow = OBJC(windowPtr); 755 CMenuBar *menuBar = OBJC(menuBarPtr); 756 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 757 AWT_ASSERT_APPKIT_THREAD; 758 759 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 760 761 if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; 762 window.javaMenuBar = menuBar; 763 764 // if ([self isKeyWindow]) { 765 [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; 766 // } 767 }]; 768 769 JNF_COCOA_EXIT(env); 770 } 771 772 /* 773 * Class: sun_lwawt_macosx_CPlatformWindow 774 * Method: nativeGetNSWindowInsets 775 * Signature: (J)Ljava/awt/Insets; 776 */ 777 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets 778 (JNIEnv *env, jclass clazz, jlong windowPtr) 779 { 780 jobject ret = NULL; 781 782 JNF_COCOA_ENTER(env); 783 AWT_ASSERT_NOT_APPKIT_THREAD; 784 785 NSWindow *nsWindow = OBJC(windowPtr); 786 __block NSRect contentRect = NSZeroRect; 787 __block NSRect frame = NSZeroRect; 788 789 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 790 AWT_ASSERT_APPKIT_THREAD; 791 792 frame = [nsWindow frame]; 793 contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]]; 794 }]; 795 796 jint top = (jint)(frame.size.height - contentRect.size.height); 797 jint left = (jint)(contentRect.origin.x - frame.origin.x); 798 jint bottom = (jint)(contentRect.origin.y - frame.origin.y); 799 jint right = (jint)(frame.size.width - (contentRect.size.width + left)); 800 801 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); 802 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); 803 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); 804 805 JNF_COCOA_EXIT(env); 806 return ret; 807 } 808 809 /* 810 * Class: sun_lwawt_macosx_CPlatformWindow 811 * Method: nativeSetNSWindowBounds 812 * Signature: (JDDDD)V 813 */ 814 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds 815 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) 816 { 817 JNF_COCOA_ENTER(env); 818 AWT_ASSERT_NOT_APPKIT_THREAD; 819 820 NSRect jrect = NSMakeRect(originX, originY, width, height); 821 822 // TODO: not sure we need displayIfNeeded message in our view 823 NSWindow *nsWindow = OBJC(windowPtr); 824 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 825 AWT_ASSERT_APPKIT_THREAD; 826 827 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 828 829 NSRect rect = ConvertNSScreenRect(NULL, jrect); 830 [window constrainSize:&rect.size]; 831 832 [nsWindow setFrame:rect display:YES]; 833 834 // only start tracking events if pointer is above the toplevel 835 // TODO: should post an Entered event if YES. 836 NSPoint mLocation = [NSEvent mouseLocation]; 837 [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; 838 839 // ensure we repaint the whole window after the resize operation 840 // (this will also re-enable screen updates, which were disabled above) 841 // TODO: send PaintEvent 842 }]; 843 844 JNF_COCOA_EXIT(env); 845 } 846 847 /* 848 * Class: sun_lwawt_macosx_CPlatformWindow 849 * Method: nativeSetNSWindowMinMax 850 * Signature: (JDDDD)V 851 */ 852 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 853 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 854 { 855 JNF_COCOA_ENTER(env); 856 AWT_ASSERT_NOT_APPKIT_THREAD; 857 858 if (minW < 1) minW = 1; 859 if (minH < 1) minH = 1; 860 if (maxW < 1) maxW = 1; 861 if (maxH < 1) maxH = 1; 862 863 NSWindow *nsWindow = OBJC(windowPtr); 864 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 865 AWT_ASSERT_APPKIT_THREAD; 866 867 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 868 869 NSSize min = { minW, minH }; 870 NSSize max = { maxW, maxH }; 871 872 [window constrainSize:&min]; 873 [window constrainSize:&max]; 874 875 window.javaMinSize = min; 876 window.javaMaxSize = max; 877 [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; 878 }]; 879 880 JNF_COCOA_EXIT(env); 881 } 882 883 /* 884 * Class: sun_lwawt_macosx_CPlatformWindow 885 * Method: nativePushNSWindowToBack 886 * Signature: (J)V 887 */ 888 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack 889 (JNIEnv *env, jclass clazz, jlong windowPtr) 890 { 891 JNF_COCOA_ENTER(env); 892 AWT_ASSERT_NOT_APPKIT_THREAD; 893 894 NSWindow *nsWindow = OBJC(windowPtr); 895 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 896 AWT_ASSERT_APPKIT_THREAD; 897 898 [nsWindow orderBack:nil]; 899 }]; 900 901 JNF_COCOA_EXIT(env); 902 } 903 904 /* 905 * Class: sun_lwawt_macosx_CPlatformWindow 906 * Method: nativePushNSWindowToFront 907 * Signature: (J)V 908 */ 909 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront 910 (JNIEnv *env, jclass clazz, jlong windowPtr) 911 { 912 JNF_COCOA_ENTER(env); 913 AWT_ASSERT_NOT_APPKIT_THREAD; 914 915 NSWindow *nsWindow = OBJC(windowPtr); 916 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 917 AWT_ASSERT_APPKIT_THREAD; 918 919 if (![nsWindow isKeyWindow]) { 920 [nsWindow makeKeyAndOrderFront:nsWindow]; 921 } else { 922 [nsWindow orderFront:nsWindow]; 923 } 924 }]; 925 926 JNF_COCOA_EXIT(env); 927 } 928 929 /* 930 * Class: sun_lwawt_macosx_CPlatformWindow 931 * Method: nativeSetNSWindowTitle 932 * Signature: (JLjava/lang/String;)V 933 */ 934 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle 935 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) 936 { 937 JNF_COCOA_ENTER(env); 938 AWT_ASSERT_NOT_APPKIT_THREAD; 939 940 NSWindow *nsWindow = OBJC(windowPtr); 941 [nsWindow performSelectorOnMainThread:@selector(setTitle:) 942 withObject:JNFJavaToNSString(env, jtitle) 943 waitUntilDone:NO]; 944 945 JNF_COCOA_EXIT(env); 946 } 947 948 /* 949 * Class: sun_lwawt_macosx_CPlatformWindow 950 * Method: nativeSetNSWindowAlpha 951 * Signature: (JF)V 952 */ 953 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowAlpha 954 (JNIEnv *env, jclass clazz, jlong windowPtr, jfloat alpha) 955 { 956 JNF_COCOA_ENTER(env); 957 AWT_ASSERT_NOT_APPKIT_THREAD; 958 959 NSWindow *nsWindow = OBJC(windowPtr); 960 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 961 AWT_ASSERT_APPKIT_THREAD; 962 963 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 964 [nsWindow setAlphaValue:alpha]; 965 [window.growBoxWindow setAlphaValue:alpha]; 966 }]; 967 968 JNF_COCOA_EXIT(env); 969 } 970 971 /* 972 * Class: sun_lwawt_macosx_CPlatformWindow 973 * Method: nativeRevalidateNSWindowShadow 974 * Signature: (J)V 975 */ 976 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow 977 (JNIEnv *env, jclass clazz, jlong windowPtr) 978 { 979 JNF_COCOA_ENTER(env); 980 AWT_ASSERT_NOT_APPKIT_THREAD; 981 982 NSWindow *nsWindow = OBJC(windowPtr); 983 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 984 AWT_ASSERT_APPKIT_THREAD; 985 986 [nsWindow invalidateShadow]; 987 }]; 988 989 JNF_COCOA_EXIT(env); 990 } 991 992 /* 993 * Class: sun_lwawt_macosx_CPlatformWindow 994 * Method: nativeScreenOn_AppKitThread 995 * Signature: (J)I 996 */ 997 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread 998 (JNIEnv *env, jclass clazz, jlong windowPtr) 999 { 1000 jint ret = 0; 1001 1002 JNF_COCOA_ENTER(env); 1003 AWT_ASSERT_APPKIT_THREAD; 1004 1005 NSWindow *nsWindow = OBJC(windowPtr); 1006 NSDictionary *props = [[nsWindow screen] deviceDescription]; 1007 ret = [[props objectForKey:@"NSScreenNumber"] intValue]; 1008 1009 JNF_COCOA_EXIT(env); 1010 1011 return ret; 1012 } 1013 1014 /* 1015 * Class: sun_lwawt_macosx_CPlatformWindow 1016 * Method: nativeSetNSWindowMinimizedIcon 1017 * Signature: (JJ)V 1018 */ 1019 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon 1020 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) 1021 { 1022 JNF_COCOA_ENTER(env); 1023 AWT_ASSERT_NOT_APPKIT_THREAD; 1024 1025 NSWindow *nsWindow = OBJC(windowPtr); 1026 NSImage *image = OBJC(nsImagePtr); 1027 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1028 AWT_ASSERT_APPKIT_THREAD; 1029 1030 [nsWindow setMiniwindowImage:image]; 1031 }]; 1032 1033 JNF_COCOA_EXIT(env); 1034 } 1035 1036 /* 1037 * Class: sun_lwawt_macosx_CPlatformWindow 1038 * Method: nativeSetNSWindowRepresentedFilename 1039 * Signature: (JLjava/lang/String;)V 1040 */ 1041 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename 1042 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) 1043 { 1044 JNF_COCOA_ENTER(env); 1045 AWT_ASSERT_NOT_APPKIT_THREAD; 1046 1047 NSWindow *nsWindow = OBJC(windowPtr); 1048 NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; 1049 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1050 AWT_ASSERT_APPKIT_THREAD; 1051 1052 [nsWindow setRepresentedURL:url]; 1053 }]; 1054 1055 JNF_COCOA_EXIT(env); 1056 } 1057 1058 /* 1059 * Class: sun_lwawt_macosx_CPlatformWindow 1060 * Method: nativeSetNSWindowSecurityWarningPositioning 1061 * Signature: (JDDFF)V 1062 */ 1063 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning 1064 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY) 1065 { 1066 JNF_COCOA_ENTER(env); 1067 AWT_ASSERT_NOT_APPKIT_THREAD; 1068 1069 [JNFException raise:env as:kRuntimeException reason:"unimplemented"]; 1070 1071 JNF_COCOA_EXIT(env); 1072 } 1073 1074 /* 1075 * Class: sun_lwawt_macosx_CPlatformWindow 1076 * Method: nativeGetScreenNSWindowIsOn_AppKitThread 1077 * Signature: (J)I 1078 */ 1079 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread 1080 (JNIEnv *env, jclass clazz, jlong windowPtr) 1081 { 1082 jint index = -1; 1083 1084 JNF_COCOA_ENTER(env); 1085 AWT_ASSERT_APPKIT_THREAD; 1086 1087 NSWindow *nsWindow = OBJC(windowPtr); 1088 NSScreen* screen = [nsWindow screen]; 1089 1090 //+++gdb NOTE: This is using a linear search of the screens. If it should 1091 // prove to be a bottleneck, this can definitely be improved. However, 1092 // many screens should prove to be the exception, rather than the rule. 1093 NSArray* screens = [NSScreen screens]; 1094 NSUInteger i; 1095 for (i = 0; i < [screens count]; i++) 1096 { 1097 if ([[screens objectAtIndex:i] isEqualTo:screen]) 1098 { 1099 index = i; 1100 break; 1101 } 1102 } 1103 1104 JNF_COCOA_EXIT(env); 1105 return 1; 1106 } 1107 1108 1109 /* 1110 * Class: sun_lwawt_macosx_CPlatformWindow 1111 * Method: _toggleFullScreenMode 1112 * Signature: (J)V 1113 */ 1114 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode 1115 (JNIEnv *env, jobject peer, jlong windowPtr) 1116 { 1117 JNF_COCOA_ENTER(env); 1118 1119 NSWindow *nsWindow = OBJC(windowPtr); 1120 SEL toggleFullScreenSelector = @selector(toggleFullScreen:); 1121 if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return; 1122 1123 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1124 [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; 1125 }]; 1126 1127 JNF_COCOA_EXIT(env); 1128 } 1129 1130 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse 1131 (JNIEnv *env, jclass clazz, jlong windowPtr) 1132 { 1133 __block jboolean underMouse = JNI_FALSE; 1134 1135 JNF_COCOA_ENTER(env); 1136 AWT_ASSERT_NOT_APPKIT_THREAD; 1137 1138 NSWindow *nsWindow = OBJC(windowPtr); 1139 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() { 1140 AWT_ASSERT_APPKIT_THREAD; 1141 1142 NSPoint pt = [nsWindow mouseLocationOutsideOfEventStream]; 1143 underMouse = [[nsWindow contentView] hitTest:pt] != nil; 1144 }]; 1145 1146 JNF_COCOA_EXIT(env); 1147 1148 return underMouse; 1149 } 1150 1151 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled 1152 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) 1153 { 1154 JNF_COCOA_ENTER(env); 1155 1156 NSWindow *nsWindow = OBJC(windowPtr); 1157 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1158 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1159 1160 [window setEnabled: isEnabled]; 1161 }]; 1162 1163 JNF_COCOA_EXIT(env); 1164 } 1165 |