1 /* 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #import <Cocoa/Cocoa.h> 27 #import <JavaNativeFoundation/JavaNativeFoundation.h> 28 #import <JavaRuntimeSupport/JavaRuntimeSupport.h> 29 30 #import "sun_lwawt_macosx_CPlatformWindow.h" 31 #import "com_apple_eawt_event_GestureHandler.h" 32 #import "com_apple_eawt_FullScreenHandler.h" 33 34 #import "AWTWindow.h" 35 #import "AWTView.h" 36 #import "CMenu.h" 37 #import "CMenuBar.h" 38 #import "LWCToolkit.h" 39 #import "GeomUtilities.h" 40 #import "ThreadUtilities.h" 41 #import "OSVersion.h" 42 43 static const float GROW_BOX_SIZE = 12.f; 44 45 #define MASK(KEY) \ 46 (sun_lwawt_macosx_CPlatformWindow_ ## KEY) 47 48 #define IS(BITS, KEY) \ 49 ((BITS & MASK(KEY)) != 0) 50 51 #define SET(BITS, KEY, VALUE) \ 52 BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) 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 [self.nsWindow release]; // the property retains the object already 270 271 self.isEnabled = YES; 272 self.javaPlatformWindow = platformWindow; 273 self.styleBits = bits; 274 [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; 275 276 if ([self shouldShowGrowBox]) { 277 NSImage *growBoxImage = [self createGrowBoxImage]; 278 growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; 279 [self.growBoxWindow setIgnoresMouseEvents:YES]; 280 [self.growBoxWindow setOpaque:NO]; 281 [self.growBoxWindow setBackgroundColor:[NSColor clearColor]]; 282 [self.growBoxWindow setHasShadow:NO]; 283 [self.growBoxWindow setReleasedWhenClosed:NO]; 284 285 NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]]; 286 [imageView setEditable:NO]; 287 [imageView setAnimates:NO]; 288 [imageView setAllowsCutCopyPaste:NO]; 289 [self.growBoxWindow setContentView:imageView]; 290 [imageView setImage:growBoxImage]; 291 [growBoxImage release]; 292 [imageView release]; 293 294 [self.nsWindow addChildWindow:self.growBoxWindow ordered:NSWindowAbove]; 295 [self adjustGrowBoxWindow]; 296 } else growBoxWindow = nil; 297 298 return self; 299 } 300 301 // checks that this window is under the mouse cursor and this point is not overlapped by others windows 302 - (BOOL) isTopmostWindowUnderMouse { 303 304 int currentWinID = [self.nsWindow windowNumber]; 305 306 NSRect screenRect = [[NSScreen mainScreen] frame]; 307 NSPoint nsMouseLocation = [NSEvent mouseLocation]; 308 CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y); 309 310 NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID); 311 312 313 for (NSDictionary *window in windows) { 314 int layer = [[window objectForKey:(id)kCGWindowLayer] intValue]; 315 if (layer == 0) { 316 int winID = [[window objectForKey:(id)kCGWindowNumber] intValue]; 317 CGRect rect; 318 CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect); 319 if (CGRectContainsPoint(rect, cgMouseLocation)) { 320 return currentWinID == winID; 321 } else if (currentWinID == winID) { 322 return NO; 323 } 324 } 325 } 326 return NO; 327 } 328 329 - (void) synthesizeMouseEnteredExitedEvents { 330 331 int eventType = 0; 332 BOOL isUnderMouse = [self isTopmostWindowUnderMouse]; 333 BOOL mouseIsOver = [[self.nsWindow contentView] mouseIsOver]; 334 335 if (isUnderMouse && !mouseIsOver) { 336 eventType = NSMouseEntered; 337 } else if (!isUnderMouse && mouseIsOver) { 338 eventType = NSMouseExited; 339 } else { 340 return; 341 } 342 343 NSPoint screenLocation = [NSEvent mouseLocation]; 344 NSPoint windowLocation = [self.nsWindow convertScreenToBase: screenLocation]; 345 int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask; 346 347 NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType 348 location: windowLocation 349 modifierFlags: modifierFlags 350 timestamp: 0 351 windowNumber: [self.nsWindow windowNumber] 352 context: nil 353 eventNumber: 0 354 trackingNumber: 0 355 userData: nil 356 ]; 357 358 [[self.nsWindow contentView] deliverJavaMouseEvent: mouseEvent]; 359 } 360 361 + (NSNumber *) getNSWindowDisplayID_AppKitThread:(NSWindow *)window { 362 AWT_ASSERT_APPKIT_THREAD; 363 NSScreen *screen = [window screen]; 364 NSDictionary *deviceDescription = [screen deviceDescription]; 365 return [deviceDescription objectForKey:@"NSScreenNumber"]; 366 } 367 368 - (void) dealloc { 369 AWT_ASSERT_APPKIT_THREAD; 370 371 JNIEnv *env = [ThreadUtilities getJNIEnv]; 372 [self.javaPlatformWindow setJObject:nil withEnv:env]; 373 self.growBoxWindow = nil; 374 375 self.nsWindow = nil; 376 377 [super dealloc]; 378 } 379 380 // NSWindow overrides 381 - (BOOL) canBecomeKeyWindow { 382 AWT_ASSERT_APPKIT_THREAD; 383 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY); 384 } 385 386 - (BOOL) canBecomeMainWindow { 387 AWT_ASSERT_APPKIT_THREAD; 388 return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN); 389 } 390 391 - (BOOL) worksWhenModal { 392 AWT_ASSERT_APPKIT_THREAD; 393 return IS(self.styleBits, MODAL_EXCLUDED); 394 } 395 396 397 // Gesture support 398 - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b { 399 AWT_ASSERT_APPKIT_THREAD; 400 401 JNIEnv *env = [ThreadUtilities getJNIEnv]; 402 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 403 if (platformWindow != NULL) { 404 // extract the target AWT Window object out of the CPlatformWindow 405 static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); 406 jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); 407 if (awtWindow != NULL) { 408 // translate the point into Java coordinates 409 NSPoint loc = [event locationInWindow]; 410 loc.y = [self.nsWindow frame].size.height - loc.y; 411 412 // send up to the GestureHandler to recursively dispatch on the AWT event thread 413 static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); 414 static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); 415 JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); 416 (*env)->DeleteLocalRef(env, awtWindow); 417 } 418 (*env)->DeleteLocalRef(env, platformWindow); 419 } 420 } 421 422 - (void)beginGestureWithEvent:(NSEvent *)event { 423 [self postGesture:event 424 as:com_apple_eawt_event_GestureHandler_PHASE 425 a:-1.0 426 b:0.0]; 427 } 428 429 - (void)endGestureWithEvent:(NSEvent *)event { 430 [self postGesture:event 431 as:com_apple_eawt_event_GestureHandler_PHASE 432 a:1.0 433 b:0.0]; 434 } 435 436 - (void)magnifyWithEvent:(NSEvent *)event { 437 [self postGesture:event 438 as:com_apple_eawt_event_GestureHandler_MAGNIFY 439 a:[event magnification] 440 b:0.0]; 441 } 442 443 - (void)rotateWithEvent:(NSEvent *)event { 444 [self postGesture:event 445 as:com_apple_eawt_event_GestureHandler_ROTATE 446 a:[event rotation] 447 b:0.0]; 448 } 449 450 - (void)swipeWithEvent:(NSEvent *)event { 451 [self postGesture:event 452 as:com_apple_eawt_event_GestureHandler_SWIPE 453 a:[event deltaX] 454 b:[event deltaY]]; 455 } 456 457 458 // NSWindowDelegate methods 459 460 - (void) adjustGrowBoxWindow { 461 if (self.growBoxWindow != nil) { 462 NSRect parentRect = [self.nsWindow frame]; 463 parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width); 464 [self.growBoxWindow setFrameOrigin:parentRect.origin]; 465 } 466 } 467 468 - (void) _deliverMoveResizeEvent { 469 AWT_ASSERT_APPKIT_THREAD; 470 471 // deliver the event if this is a user-initiated live resize or as a side-effect 472 // of a Java initiated resize, because AppKit can override the bounds and force 473 // the bounds of the window to avoid the Dock or remain on screen. 474 [AWTToolkit eventCountPlusPlus]; 475 JNIEnv *env = [ThreadUtilities getJNIEnv]; 476 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 477 if (platformWindow == NULL) { 478 // TODO: create generic AWT assert 479 } 480 481 [self adjustGrowBoxWindow]; 482 483 NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]); 484 485 static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); 486 JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, 487 (jint)frame.origin.x, 488 (jint)frame.origin.y, 489 (jint)frame.size.width, 490 (jint)frame.size.height); 491 (*env)->DeleteLocalRef(env, platformWindow); 492 } 493 494 - (void)windowDidMove:(NSNotification *)notification { 495 AWT_ASSERT_APPKIT_THREAD; 496 497 [self _deliverMoveResizeEvent]; 498 } 499 500 - (void)windowDidResize:(NSNotification *)notification { 501 AWT_ASSERT_APPKIT_THREAD; 502 503 [self _deliverMoveResizeEvent]; 504 } 505 506 - (void)windowDidExpose:(NSNotification *)notification { 507 AWT_ASSERT_APPKIT_THREAD; 508 509 [AWTToolkit eventCountPlusPlus]; 510 // TODO: don't see this callback invoked anytime so we track 511 // window exposing in _setVisible:(BOOL) 512 } 513 514 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)proposedFrame { 515 AWT_ASSERT_APPKIT_THREAD; 516 517 [AWTToolkit eventCountPlusPlus]; 518 JNIEnv *env = [ThreadUtilities getJNIEnv]; 519 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 520 if (platformWindow != NULL) { 521 static JNF_MEMBER_CACHE(jm_deliverZoom, jc_CPlatformWindow, "deliverZoom", "(Z)V"); 522 JNFCallVoidMethod(env, platformWindow, jm_deliverZoom, ![window isZoomed]); 523 (*env)->DeleteLocalRef(env, platformWindow); 524 } 525 return YES; 526 } 527 528 - (void) _deliverIconify:(BOOL)iconify { 529 AWT_ASSERT_APPKIT_THREAD; 530 531 [AWTToolkit eventCountPlusPlus]; 532 JNIEnv *env = [ThreadUtilities getJNIEnv]; 533 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 534 if (platformWindow != NULL) { 535 static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V"); 536 JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify); 537 (*env)->DeleteLocalRef(env, platformWindow); 538 } 539 } 540 541 - (void)windowDidMiniaturize:(NSNotification *)notification { 542 AWT_ASSERT_APPKIT_THREAD; 543 544 [self _deliverIconify:JNI_TRUE]; 545 } 546 547 - (void)windowDidDeminiaturize:(NSNotification *)notification { 548 AWT_ASSERT_APPKIT_THREAD; 549 550 [self _deliverIconify:JNI_FALSE]; 551 } 552 553 - (void) _deliverWindowFocusEvent:(BOOL)focused { 554 //AWT_ASSERT_APPKIT_THREAD; 555 556 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 557 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 558 if (platformWindow != NULL) { 559 static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(Z)V"); 560 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused); 561 (*env)->DeleteLocalRef(env, platformWindow); 562 } 563 } 564 565 566 - (void) windowDidBecomeKey: (NSNotification *) notification { 567 AWT_ASSERT_APPKIT_THREAD; 568 [AWTToolkit eventCountPlusPlus]; 569 [CMenuBar activate:self.javaMenuBar modallyDisabled:NO]; 570 [self _deliverWindowFocusEvent:YES]; 571 } 572 573 - (void) windowDidResignKey: (NSNotification *) notification { 574 // TODO: check why sometimes at start is invoked *not* on AppKit main thread. 575 AWT_ASSERT_APPKIT_THREAD; 576 [AWTToolkit eventCountPlusPlus]; 577 [self.javaMenuBar deactivate]; 578 [self _deliverWindowFocusEvent:NO]; 579 } 580 581 - (void) windowDidBecomeMain: (NSNotification *) notification { 582 AWT_ASSERT_APPKIT_THREAD; 583 [AWTToolkit eventCountPlusPlus]; 584 585 JNIEnv *env = [ThreadUtilities getJNIEnv]; 586 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 587 if (platformWindow != NULL) { 588 static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V"); 589 JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain); 590 (*env)->DeleteLocalRef(env, platformWindow); 591 } 592 } 593 594 - (BOOL)windowShouldClose:(id)sender { 595 AWT_ASSERT_APPKIT_THREAD; 596 [AWTToolkit eventCountPlusPlus]; 597 JNIEnv *env = [ThreadUtilities getJNIEnv]; 598 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 599 if (platformWindow != NULL) { 600 static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V"); 601 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent); 602 (*env)->DeleteLocalRef(env, platformWindow); 603 } 604 // The window will be closed (if allowed) as result of sending Java event 605 return NO; 606 } 607 608 609 - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env { 610 static JNF_CLASS_CACHE(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler"); 611 static JNF_STATIC_MEMBER_CACHE(jm_notifyFullScreenOperation, jc_FullScreenHandler, "handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V"); 612 static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); 613 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 614 if (platformWindow != NULL) { 615 jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); 616 if (awtWindow != NULL) { 617 JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op); 618 (*env)->DeleteLocalRef(env, awtWindow); 619 } 620 (*env)->DeleteLocalRef(env, platformWindow); 621 } 622 } 623 624 625 - (void)windowWillEnterFullScreen:(NSNotification *)notification { 626 static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V"); 627 JNIEnv *env = [ThreadUtilities getJNIEnv]; 628 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 629 if (platformWindow != NULL) { 630 JNFCallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen); 631 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env]; 632 (*env)->DeleteLocalRef(env, platformWindow); 633 } 634 } 635 636 - (void)windowDidEnterFullScreen:(NSNotification *)notification { 637 static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V"); 638 JNIEnv *env = [ThreadUtilities getJNIEnv]; 639 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 640 if (platformWindow != NULL) { 641 JNFCallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen); 642 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env]; 643 (*env)->DeleteLocalRef(env, platformWindow); 644 } 645 } 646 647 - (void)windowWillExitFullScreen:(NSNotification *)notification { 648 static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V"); 649 JNIEnv *env = [ThreadUtilities getJNIEnv]; 650 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 651 if (platformWindow != NULL) { 652 JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen); 653 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; 654 (*env)->DeleteLocalRef(env, platformWindow); 655 } 656 } 657 658 - (void)windowDidExitFullScreen:(NSNotification *)notification { 659 static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); 660 JNIEnv *env = [ThreadUtilities getJNIEnv]; 661 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 662 if (platformWindow != NULL) { 663 JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); 664 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; 665 (*env)->DeleteLocalRef(env, platformWindow); 666 } 667 } 668 669 - (void)sendEvent:(NSEvent *)event { 670 if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { 671 672 NSPoint p = [NSEvent mouseLocation]; 673 NSRect frame = [self.nsWindow frame]; 674 NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame]; 675 676 // Check if the click happened in the non-client area (title bar) 677 if (p.y >= (frame.origin.y + contentRect.size.height)) { 678 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 679 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 680 // Currently, no need to deliver the whole NSEvent. 681 static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); 682 JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); 683 } 684 } 685 } 686 687 - (void)constrainSize:(NSSize*)size { 688 float minWidth = 0.f, minHeight = 0.f; 689 690 if (IS(self.styleBits, DECORATED)) { 691 NSRect frame = [self.nsWindow frame]; 692 NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self.nsWindow styleMask]]; 693 694 float top = frame.size.height - contentRect.size.height; 695 float left = contentRect.origin.x - frame.origin.x; 696 float bottom = contentRect.origin.y - frame.origin.y; 697 float right = frame.size.width - (contentRect.size.width + left); 698 699 // Speculative estimation: 80 - enough for window decorations controls 700 minWidth += left + right + 80; 701 minHeight += top + bottom; 702 } 703 704 if ([self shouldShowGrowBox]) { 705 minWidth = MAX(minWidth, GROW_BOX_SIZE); 706 minHeight += GROW_BOX_SIZE; 707 } 708 709 minWidth = MAX(1.f, minWidth); 710 minHeight = MAX(1.f, minHeight); 711 712 size->width = MAX(size->width, minWidth); 713 size->height = MAX(size->height, minHeight); 714 } 715 716 - (void) setEnabled: (BOOL)flag { 717 self.isEnabled = flag; 718 719 if (IS(self.styleBits, CLOSEABLE)) { 720 [[self.nsWindow standardWindowButton:NSWindowCloseButton] setEnabled: flag]; 721 } 722 723 if (IS(self.styleBits, MINIMIZABLE)) { 724 [[self.nsWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag]; 725 } 726 727 if (IS(self.styleBits, ZOOMABLE)) { 728 [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled: flag]; 729 } 730 731 if (IS(self.styleBits, RESIZABLE)) { 732 [self updateMinMaxSize:flag]; 733 [self.nsWindow setShowsResizeIndicator:flag]; 734 } 735 } 736 737 @end // AWTWindow 738 739 740 /* 741 * Class: sun_lwawt_macosx_CPlatformWindow 742 * Method: nativeCreateNSWindow 743 * Signature: (JJIIII)J 744 */ 745 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow 746 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h) 747 { 748 __block AWTWindow *window = nil; 749 750 JNF_COCOA_ENTER(env); 751 AWT_ASSERT_NOT_APPKIT_THREAD; 752 753 JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; 754 NSView *contentView = OBJC(contentViewPtr); 755 NSRect frameRect = NSMakeRect(x, y, w, h); 756 757 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 758 AWT_ASSERT_APPKIT_THREAD; 759 760 window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow 761 styleBits:styleBits 762 frameRect:frameRect 763 contentView:contentView]; 764 // the window is released is CPlatformWindow.nativeDispose() 765 766 if (window) CFRetain(window.nsWindow); 767 }]; 768 769 JNF_COCOA_EXIT(env); 770 771 return ptr_to_jlong(window ? window.nsWindow : nil); 772 } 773 774 /* 775 * Class: sun_lwawt_macosx_CPlatformWindow 776 * Method: nativeSetNSWindowStyleBits 777 * Signature: (JII)V 778 */ 779 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits 780 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) 781 { 782 JNF_COCOA_ENTER(env); 783 AWT_ASSERT_NOT_APPKIT_THREAD; 784 785 NSWindow *nsWindow = OBJC(windowPtr); 786 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 787 AWT_ASSERT_APPKIT_THREAD; 788 789 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 790 791 // scans the bit field, and only updates the values requested by the mask 792 // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) 793 jint newBits = window.styleBits & ~mask | bits & mask; 794 795 // resets the NSWindow's style mask if the mask intersects any of those bits 796 if (mask & MASK(_STYLE_PROP_BITMASK)) { 797 [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; 798 } 799 800 // calls methods on NSWindow to change other properties, based on the mask 801 if (mask & MASK(_METHOD_PROP_BITMASK)) { 802 [window setPropertiesForStyleBits:bits mask:mask]; 803 } 804 805 window.styleBits = newBits; 806 }]; 807 808 JNF_COCOA_EXIT(env); 809 } 810 811 /* 812 * Class: sun_lwawt_macosx_CPlatformWindow 813 * Method: nativeSetNSWindowMenuBar 814 * Signature: (JJ)V 815 */ 816 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar 817 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) 818 { 819 JNF_COCOA_ENTER(env); 820 AWT_ASSERT_NOT_APPKIT_THREAD; 821 822 NSWindow *nsWindow = OBJC(windowPtr); 823 CMenuBar *menuBar = OBJC(menuBarPtr); 824 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 825 AWT_ASSERT_APPKIT_THREAD; 826 827 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 828 829 if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; 830 window.javaMenuBar = menuBar; 831 832 // if ([self isKeyWindow]) { 833 [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; 834 // } 835 }]; 836 837 JNF_COCOA_EXIT(env); 838 } 839 840 /* 841 * Class: sun_lwawt_macosx_CPlatformWindow 842 * Method: nativeGetNSWindowInsets 843 * Signature: (J)Ljava/awt/Insets; 844 */ 845 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets 846 (JNIEnv *env, jclass clazz, jlong windowPtr) 847 { 848 jobject ret = NULL; 849 850 JNF_COCOA_ENTER(env); 851 AWT_ASSERT_NOT_APPKIT_THREAD; 852 853 NSWindow *nsWindow = OBJC(windowPtr); 854 __block NSRect contentRect = NSZeroRect; 855 __block NSRect frame = NSZeroRect; 856 857 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 858 AWT_ASSERT_APPKIT_THREAD; 859 860 frame = [nsWindow frame]; 861 contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]]; 862 }]; 863 864 jint top = (jint)(frame.size.height - contentRect.size.height); 865 jint left = (jint)(contentRect.origin.x - frame.origin.x); 866 jint bottom = (jint)(contentRect.origin.y - frame.origin.y); 867 jint right = (jint)(frame.size.width - (contentRect.size.width + left)); 868 869 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); 870 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); 871 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); 872 873 JNF_COCOA_EXIT(env); 874 return ret; 875 } 876 877 /* 878 * Class: sun_lwawt_macosx_CPlatformWindow 879 * Method: nativeSetNSWindowBounds 880 * Signature: (JDDDD)V 881 */ 882 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds 883 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) 884 { 885 JNF_COCOA_ENTER(env); 886 AWT_ASSERT_NOT_APPKIT_THREAD; 887 888 NSRect jrect = NSMakeRect(originX, originY, width, height); 889 890 // TODO: not sure we need displayIfNeeded message in our view 891 NSWindow *nsWindow = OBJC(windowPtr); 892 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 893 AWT_ASSERT_APPKIT_THREAD; 894 895 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 896 897 NSRect rect = ConvertNSScreenRect(NULL, jrect); 898 [window constrainSize:&rect.size]; 899 900 [nsWindow setFrame:rect display:YES]; 901 902 // only start tracking events if pointer is above the toplevel 903 // TODO: should post an Entered event if YES. 904 NSPoint mLocation = [NSEvent mouseLocation]; 905 [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; 906 907 // ensure we repaint the whole window after the resize operation 908 // (this will also re-enable screen updates, which were disabled above) 909 // TODO: send PaintEvent 910 911 [window synthesizeMouseEnteredExitedEvents]; 912 }]; 913 914 JNF_COCOA_EXIT(env); 915 } 916 917 /* 918 * Class: sun_lwawt_macosx_CPlatformWindow 919 * Method: nativeSetNSWindowMinMax 920 * Signature: (JDDDD)V 921 */ 922 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 923 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 924 { 925 JNF_COCOA_ENTER(env); 926 AWT_ASSERT_NOT_APPKIT_THREAD; 927 928 if (minW < 1) minW = 1; 929 if (minH < 1) minH = 1; 930 if (maxW < 1) maxW = 1; 931 if (maxH < 1) maxH = 1; 932 933 NSWindow *nsWindow = OBJC(windowPtr); 934 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 935 AWT_ASSERT_APPKIT_THREAD; 936 937 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 938 939 NSSize min = { minW, minH }; 940 NSSize max = { maxW, maxH }; 941 942 [window constrainSize:&min]; 943 [window constrainSize:&max]; 944 945 window.javaMinSize = min; 946 window.javaMaxSize = max; 947 [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; 948 }]; 949 950 JNF_COCOA_EXIT(env); 951 } 952 953 /* 954 * Class: sun_lwawt_macosx_CPlatformWindow 955 * Method: nativePushNSWindowToBack 956 * Signature: (J)V 957 */ 958 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack 959 (JNIEnv *env, jclass clazz, jlong windowPtr) 960 { 961 JNF_COCOA_ENTER(env); 962 AWT_ASSERT_NOT_APPKIT_THREAD; 963 964 NSWindow *nsWindow = OBJC(windowPtr); 965 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 966 AWT_ASSERT_APPKIT_THREAD; 967 968 [nsWindow orderBack:nil]; 969 }]; 970 971 JNF_COCOA_EXIT(env); 972 } 973 974 /* 975 * Class: sun_lwawt_macosx_CPlatformWindow 976 * Method: nativePushNSWindowToFront 977 * Signature: (J)V 978 */ 979 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront 980 (JNIEnv *env, jclass clazz, jlong windowPtr) 981 { 982 JNF_COCOA_ENTER(env); 983 AWT_ASSERT_NOT_APPKIT_THREAD; 984 985 NSWindow *nsWindow = OBJC(windowPtr); 986 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 987 AWT_ASSERT_APPKIT_THREAD; 988 989 if (![nsWindow isKeyWindow]) { 990 [nsWindow makeKeyAndOrderFront:nsWindow]; 991 } else { 992 [nsWindow orderFront:nsWindow]; 993 } 994 }]; 995 996 JNF_COCOA_EXIT(env); 997 } 998 999 /* 1000 * Class: sun_lwawt_macosx_CPlatformWindow 1001 * Method: nativeSetNSWindowTitle 1002 * Signature: (JLjava/lang/String;)V 1003 */ 1004 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle 1005 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) 1006 { 1007 JNF_COCOA_ENTER(env); 1008 AWT_ASSERT_NOT_APPKIT_THREAD; 1009 1010 NSWindow *nsWindow = OBJC(windowPtr); 1011 [nsWindow performSelectorOnMainThread:@selector(setTitle:) 1012 withObject:JNFJavaToNSString(env, jtitle) 1013 waitUntilDone:NO]; 1014 1015 JNF_COCOA_EXIT(env); 1016 } 1017 1018 /* 1019 * Class: sun_lwawt_macosx_CPlatformWindow 1020 * Method: nativeRevalidateNSWindowShadow 1021 * Signature: (J)V 1022 */ 1023 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow 1024 (JNIEnv *env, jclass clazz, jlong windowPtr) 1025 { 1026 JNF_COCOA_ENTER(env); 1027 1028 NSWindow *nsWindow = OBJC(windowPtr); 1029 if ([NSThread isMainThread]) { 1030 [nsWindow invalidateShadow]; 1031 } else { 1032 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1033 AWT_ASSERT_APPKIT_THREAD; 1034 1035 [nsWindow invalidateShadow]; 1036 }]; 1037 } 1038 1039 JNF_COCOA_EXIT(env); 1040 } 1041 1042 /* 1043 * Class: sun_lwawt_macosx_CPlatformWindow 1044 * Method: nativeScreenOn_AppKitThread 1045 * Signature: (J)I 1046 */ 1047 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread 1048 (JNIEnv *env, jclass clazz, jlong windowPtr) 1049 { 1050 jint ret = 0; 1051 1052 JNF_COCOA_ENTER(env); 1053 AWT_ASSERT_APPKIT_THREAD; 1054 1055 NSWindow *nsWindow = OBJC(windowPtr); 1056 NSDictionary *props = [[nsWindow screen] deviceDescription]; 1057 ret = [[props objectForKey:@"NSScreenNumber"] intValue]; 1058 1059 JNF_COCOA_EXIT(env); 1060 1061 return ret; 1062 } 1063 1064 /* 1065 * Class: sun_lwawt_macosx_CPlatformWindow 1066 * Method: nativeSetNSWindowMinimizedIcon 1067 * Signature: (JJ)V 1068 */ 1069 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon 1070 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) 1071 { 1072 JNF_COCOA_ENTER(env); 1073 AWT_ASSERT_NOT_APPKIT_THREAD; 1074 1075 NSWindow *nsWindow = OBJC(windowPtr); 1076 NSImage *image = OBJC(nsImagePtr); 1077 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1078 AWT_ASSERT_APPKIT_THREAD; 1079 1080 [nsWindow setMiniwindowImage:image]; 1081 }]; 1082 1083 JNF_COCOA_EXIT(env); 1084 } 1085 1086 /* 1087 * Class: sun_lwawt_macosx_CPlatformWindow 1088 * Method: nativeSetNSWindowRepresentedFilename 1089 * Signature: (JLjava/lang/String;)V 1090 */ 1091 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename 1092 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) 1093 { 1094 JNF_COCOA_ENTER(env); 1095 AWT_ASSERT_NOT_APPKIT_THREAD; 1096 1097 NSWindow *nsWindow = OBJC(windowPtr); 1098 NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; 1099 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1100 AWT_ASSERT_APPKIT_THREAD; 1101 1102 [nsWindow setRepresentedURL:url]; 1103 }]; 1104 1105 JNF_COCOA_EXIT(env); 1106 } 1107 1108 /* 1109 * Class: sun_lwawt_macosx_CPlatformWindow 1110 * Method: nativeSetNSWindowSecurityWarningPositioning 1111 * Signature: (JDDFF)V 1112 */ 1113 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning 1114 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY) 1115 { 1116 JNF_COCOA_ENTER(env); 1117 AWT_ASSERT_NOT_APPKIT_THREAD; 1118 1119 [JNFException raise:env as:kRuntimeException reason:"unimplemented"]; 1120 1121 JNF_COCOA_EXIT(env); 1122 } 1123 1124 /* 1125 * Class: sun_lwawt_macosx_CPlatformWindow 1126 * Method: nativeSynthesizeMouseEnteredExitedEvents 1127 * Signature: (J)V 1128 */ 1129 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents 1130 (JNIEnv *env, jclass clazz, jlong windowPtr) 1131 { 1132 JNF_COCOA_ENTER(env); 1133 AWT_ASSERT_NOT_APPKIT_THREAD; 1134 1135 NSWindow *nsWindow = OBJC(windowPtr); 1136 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1137 AWT_ASSERT_APPKIT_THREAD; 1138 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1139 1140 [window synthesizeMouseEnteredExitedEvents]; 1141 }]; 1142 1143 JNF_COCOA_EXIT(env); 1144 } 1145 1146 /* 1147 * Class: sun_lwawt_macosx_CPlatformWindow 1148 * Method: _toggleFullScreenMode 1149 * Signature: (J)V 1150 */ 1151 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode 1152 (JNIEnv *env, jobject peer, jlong windowPtr) 1153 { 1154 JNF_COCOA_ENTER(env); 1155 1156 NSWindow *nsWindow = OBJC(windowPtr); 1157 SEL toggleFullScreenSelector = @selector(toggleFullScreen:); 1158 if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return; 1159 1160 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1161 [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; 1162 }]; 1163 1164 JNF_COCOA_EXIT(env); 1165 } 1166 1167 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled 1168 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) 1169 { 1170 JNF_COCOA_ENTER(env); 1171 1172 NSWindow *nsWindow = OBJC(windowPtr); 1173 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1174 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1175 1176 [window setEnabled: isEnabled]; 1177 }]; 1178 1179 JNF_COCOA_EXIT(env); 1180 } 1181 1182 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose 1183 (JNIEnv *env, jclass clazz, jlong windowPtr) 1184 { 1185 JNF_COCOA_ENTER(env); 1186 1187 NSWindow *nsWindow = OBJC(windowPtr); 1188 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1189 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1190 1191 // AWTWindow holds a reference to the NSWindow in its nsWindow 1192 // property. Unsetting the delegate allows it to be deallocated 1193 // which releases the reference. This, in turn, allows the window 1194 // itself be deallocated. 1195 [nsWindow setDelegate: nil]; 1196 1197 [window release]; 1198 }]; 1199 1200 JNF_COCOA_EXIT(env); 1201 } 1202