src/macosx/native/sun/awt/AWTWindow.m

Print this page

        

*** 49,75 **** #define SET(BITS, KEY, VALUE) \ BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); @implementation AWTWindow @synthesize javaPlatformWindow; @synthesize javaMenuBar; @synthesize javaMinSize; @synthesize javaMaxSize; @synthesize styleBits; @synthesize isEnabled; - (void) updateMinMaxSize:(BOOL)resizable { if (resizable) { ! [self setMinSize:self.javaMinSize]; ! [self setMaxSize:self.javaMaxSize]; } else { ! NSRect currentFrame = [self frame]; ! [self setMinSize:currentFrame.size]; ! [self setMaxSize:currentFrame.size]; } } // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits + (NSUInteger) styleMaskForStyleBits:(jint)styleBits { --- 49,128 ---- #define SET(BITS, KEY, VALUE) \ BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); + // -------------------------------------------------------------- + // NSWindow/NSPanel descendants implementation + #define AWT_NS_WINDOW_IMPLEMENTATION \ + - (id) initWithDelegate:(AWTWindow *)delegate \ + frameRect:(NSRect)contectRect \ + styleMask:(NSUInteger)styleMask \ + contentView:(NSView *)view \ + { \ + self = [super initWithContentRect:contectRect \ + styleMask:styleMask \ + backing:NSBackingStoreBuffered \ + defer:NO]; \ + \ + if (self == nil) return nil; \ + \ + [self setDelegate:delegate]; \ + [self setContentView:view]; \ + [self setInitialFirstResponder:view]; \ + [self setReleasedWhenClosed:NO]; \ + [self setPreservesContentDuringLiveResize:YES]; \ + \ + return self; \ + } \ + \ + /* NSWindow overrides */ \ + - (BOOL) canBecomeKeyWindow { \ + return [(AWTWindow*)[self delegate] canBecomeKeyWindow]; \ + } \ + \ + - (BOOL) canBecomeMainWindow { \ + return [(AWTWindow*)[self delegate] canBecomeMainWindow]; \ + } \ + \ + - (BOOL) worksWhenModal { \ + return [(AWTWindow*)[self delegate] worksWhenModal]; \ + } \ + \ + - (void)sendEvent:(NSEvent *)event { \ + [(AWTWindow*)[self delegate] sendEvent:event]; \ + [super sendEvent:event]; \ + } + + @implementation AWTWindow_Normal + AWT_NS_WINDOW_IMPLEMENTATION + @end + @implementation AWTWindow_Panel + AWT_NS_WINDOW_IMPLEMENTATION + @end + // END of NSWindow/NSPanel descendants implementation + // -------------------------------------------------------------- + + @implementation AWTWindow + @synthesize nsWindow; @synthesize javaPlatformWindow; @synthesize javaMenuBar; @synthesize javaMinSize; @synthesize javaMaxSize; @synthesize styleBits; @synthesize isEnabled; - (void) updateMinMaxSize:(BOOL)resizable { if (resizable) { ! [self.nsWindow setMinSize:self.javaMinSize]; ! [self.nsWindow setMaxSize:self.javaMaxSize]; } else { ! NSRect currentFrame = [self.nsWindow frame]; ! [self.nsWindow setMinSize:currentFrame.size]; ! [self.nsWindow setMaxSize:currentFrame.size]; } } // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
*** 96,137 **** // updates _METHOD_PROP_BITMASK based properties on the window - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask { if (IS(mask, RESIZABLE)) { BOOL resizable = IS(bits, RESIZABLE); [self updateMinMaxSize:resizable]; ! [self setShowsResizeIndicator:resizable]; } if (IS(mask, HAS_SHADOW)) { ! [self setHasShadow:IS(bits, HAS_SHADOW)]; } if (IS(mask, ZOOMABLE)) { ! [[self standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)]; } if (IS(mask, ALWAYS_ON_TOP)) { ! [self setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel]; } if (IS(mask, HIDES_ON_DEACTIVATE)) { ! [self setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)]; } if (IS(mask, DRAGGABLE_BACKGROUND)) { ! [self setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)]; } if (IS(mask, DOCUMENT_MODIFIED)) { ! [self setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)]; } ! if ([self respondsToSelector:@selector(toggleFullScreen:)]) { if (IS(mask, FULLSCREENABLE)) { ! [self setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/]; } else { ! [self setCollectionBehavior:NSWindowCollectionBehaviorDefault]; } } } --- 149,190 ---- // updates _METHOD_PROP_BITMASK based properties on the window - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask { if (IS(mask, RESIZABLE)) { BOOL resizable = IS(bits, RESIZABLE); [self updateMinMaxSize:resizable]; ! [self.nsWindow setShowsResizeIndicator:resizable]; } if (IS(mask, HAS_SHADOW)) { ! [self.nsWindow setHasShadow:IS(bits, HAS_SHADOW)]; } if (IS(mask, ZOOMABLE)) { ! [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)]; } if (IS(mask, ALWAYS_ON_TOP)) { ! [self.nsWindow setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel]; } if (IS(mask, HIDES_ON_DEACTIVATE)) { ! [self.nsWindow setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)]; } if (IS(mask, DRAGGABLE_BACKGROUND)) { ! [self.nsWindow setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)]; } if (IS(mask, DOCUMENT_MODIFIED)) { ! [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)]; } ! if ([self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) { if (IS(mask, FULLSCREENABLE)) { ! [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/]; } else { ! [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault]; } } }
*** 149,183 **** } if (contentRect.size.height <= 0.0) { contentRect.size.height = 1.0; } ! self = [super initWithContentRect:contentRect ! styleMask:styleMask ! backing:NSBackingStoreBuffered ! defer:NO]; if (self == nil) return nil; // no hope self.isEnabled = YES; self.javaPlatformWindow = platformWindow; self.styleBits = bits; [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; - [self setDelegate:self]; - [self setContentView:view]; - [self setInitialFirstResponder:view]; - [self setReleasedWhenClosed:NO]; - [self setPreservesContentDuringLiveResize:YES]; - return self; } // checks that this window is under the mouse cursor and this point is not overlapped by others windows - (BOOL) isTopmostWindowUnderMouse { ! int currentWinID = [self windowNumber]; NSRect screenRect = [[NSScreen mainScreen] frame]; NSPoint nsMouseLocation = [NSEvent mouseLocation]; CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y); --- 202,248 ---- } if (contentRect.size.height <= 0.0) { contentRect.size.height = 1.0; } ! self = [super init]; if (self == nil) return nil; // no hope + if (IS(bits, UTILITY) || + IS(bits, NONACTIVATING) || + IS(bits, HUD) || + IS(bits, HIDES_ON_DEACTIVATE)) + { + self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self + frameRect:contentRect + styleMask:styleMask + contentView:view]; + } + else + { + // These windows will appear in the window list in the dock icon menu + self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self + frameRect:contentRect + styleMask:styleMask + contentView:view]; + } + + if (self.nsWindow == nil) return nil; // no hope either + self.isEnabled = YES; self.javaPlatformWindow = platformWindow; self.styleBits = bits; [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; return self; } // checks that this window is under the mouse cursor and this point is not overlapped by others windows - (BOOL) isTopmostWindowUnderMouse { ! int currentWinID = [self.nsWindow windowNumber]; NSRect screenRect = [[NSScreen mainScreen] frame]; NSPoint nsMouseLocation = [NSEvent mouseLocation]; CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
*** 202,245 **** - (void) synthesizeMouseEnteredExitedEvents { int eventType = 0; BOOL isUnderMouse = [self isTopmostWindowUnderMouse]; ! BOOL mouseIsOver = [[self contentView] mouseIsOver]; if (isUnderMouse && !mouseIsOver) { eventType = NSMouseEntered; } else if (!isUnderMouse && mouseIsOver) { eventType = NSMouseExited; } else { return; } NSPoint screenLocation = [NSEvent mouseLocation]; ! NSPoint windowLocation = [self convertScreenToBase: screenLocation]; int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask; NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType location: windowLocation modifierFlags: modifierFlags timestamp: 0 ! windowNumber: [self windowNumber] context: nil eventNumber: 0 trackingNumber: 0 userData: nil ]; ! [[self contentView] deliverJavaMouseEvent: mouseEvent]; } - (void) dealloc { AWT_ASSERT_APPKIT_THREAD; JNIEnv *env = [ThreadUtilities getJNIEnv]; [self.javaPlatformWindow setJObject:nil withEnv:env]; [super dealloc]; } // NSWindow overrides - (BOOL) canBecomeKeyWindow { --- 267,312 ---- - (void) synthesizeMouseEnteredExitedEvents { int eventType = 0; BOOL isUnderMouse = [self isTopmostWindowUnderMouse]; ! BOOL mouseIsOver = [[self.nsWindow contentView] mouseIsOver]; if (isUnderMouse && !mouseIsOver) { eventType = NSMouseEntered; } else if (!isUnderMouse && mouseIsOver) { eventType = NSMouseExited; } else { return; } NSPoint screenLocation = [NSEvent mouseLocation]; ! NSPoint windowLocation = [self.nsWindow convertScreenToBase: screenLocation]; int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask; NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType location: windowLocation modifierFlags: modifierFlags timestamp: 0 ! windowNumber: [self.nsWindow windowNumber] context: nil eventNumber: 0 trackingNumber: 0 userData: nil ]; ! [[self.nsWindow contentView] deliverJavaMouseEvent: mouseEvent]; } - (void) dealloc { AWT_ASSERT_APPKIT_THREAD; JNIEnv *env = [ThreadUtilities getJNIEnv]; [self.javaPlatformWindow setJObject:nil withEnv:env]; + self.nsWindow = nil; + [super dealloc]; } // NSWindow overrides - (BOOL) canBecomeKeyWindow {
*** 269,279 **** static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); if (awtWindow != NULL) { // translate the point into Java coordinates NSPoint loc = [event locationInWindow]; ! loc.y = [self frame].size.height - loc.y; // send up to the GestureHandler to recursively dispatch on the AWT event thread static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); --- 336,346 ---- static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); if (awtWindow != NULL) { // translate the point into Java coordinates NSPoint loc = [event locationInWindow]; ! loc.y = [self.nsWindow frame].size.height - loc.y; // send up to the GestureHandler to recursively dispatch on the AWT event thread static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b);
*** 332,342 **** jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow == NULL) { // TODO: create generic AWT assert } ! NSRect frame = ConvertNSScreenRect(env, [self frame]); static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, (jint)frame.origin.x, (jint)frame.origin.y, --- 399,409 ---- jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow == NULL) { // TODO: create generic AWT assert } ! NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]); static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, (jint)frame.origin.x, (jint)frame.origin.y,
*** 522,552 **** - (void)sendEvent:(NSEvent *)event { if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { NSPoint p = [NSEvent mouseLocation]; ! NSRect frame = [self frame]; ! NSRect contentRect = [self contentRectForFrameRect:frame]; // Check if the click happened in the non-client area (title bar) if (p.y >= (frame.origin.y + contentRect.size.height)) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; // Currently, no need to deliver the whole NSEvent. static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); } } - [super sendEvent:event]; } - (void)constrainSize:(NSSize*)size { float minWidth = 0.f, minHeight = 0.f; if (IS(self.styleBits, DECORATED)) { ! NSRect frame = [self frame]; ! NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self styleMask]]; float top = frame.size.height - contentRect.size.height; float left = contentRect.origin.x - frame.origin.x; float bottom = contentRect.origin.y - frame.origin.y; float right = frame.size.width - (contentRect.size.width + left); --- 589,618 ---- - (void)sendEvent:(NSEvent *)event { if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { NSPoint p = [NSEvent mouseLocation]; ! NSRect frame = [self.nsWindow frame]; ! NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame]; // Check if the click happened in the non-client area (title bar) if (p.y >= (frame.origin.y + contentRect.size.height)) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; // Currently, no need to deliver the whole NSEvent. static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); } } } - (void)constrainSize:(NSSize*)size { float minWidth = 0.f, minHeight = 0.f; if (IS(self.styleBits, DECORATED)) { ! NSRect frame = [self.nsWindow frame]; ! NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self.nsWindow styleMask]]; float top = frame.size.height - contentRect.size.height; float left = contentRect.origin.x - frame.origin.x; float bottom = contentRect.origin.y - frame.origin.y; float right = frame.size.width - (contentRect.size.width + left);
*** 565,588 **** - (void) setEnabled: (BOOL)flag { self.isEnabled = flag; if (IS(self.styleBits, CLOSEABLE)) { ! [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag]; } if (IS(self.styleBits, MINIMIZABLE)) { ! [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag]; } if (IS(self.styleBits, ZOOMABLE)) { ! [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag]; } if (IS(self.styleBits, RESIZABLE)) { [self updateMinMaxSize:flag]; ! [self setShowsResizeIndicator:flag]; } } @end // AWTWindow --- 631,654 ---- - (void) setEnabled: (BOOL)flag { self.isEnabled = flag; if (IS(self.styleBits, CLOSEABLE)) { ! [[self.nsWindow standardWindowButton:NSWindowCloseButton] setEnabled: flag]; } if (IS(self.styleBits, MINIMIZABLE)) { ! [[self.nsWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag]; } if (IS(self.styleBits, ZOOMABLE)) { ! [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled: flag]; } if (IS(self.styleBits, RESIZABLE)) { [self updateMinMaxSize:flag]; ! [self.nsWindow setShowsResizeIndicator:flag]; } } @end // AWTWindow
*** 616,626 **** [window release]; // GC }]; JNF_COCOA_EXIT(env); ! return ptr_to_jlong(window); } /* * Class: sun_lwawt_macosx_CPlatformWindow * Method: nativeSetNSWindowStyleBits --- 682,692 ---- [window release]; // GC }]; JNF_COCOA_EXIT(env); ! return ptr_to_jlong(window ? window.nsWindow : nil); } /* * Class: sun_lwawt_macosx_CPlatformWindow * Method: nativeSetNSWindowStyleBits
*** 630,650 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; // scans the bit field, and only updates the values requested by the mask // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) jint newBits = window.styleBits & ~mask | bits & mask; // resets the NSWindow's style mask if the mask intersects any of those bits if (mask & MASK(_STYLE_PROP_BITMASK)) { ! [window setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; } // calls methods on NSWindow to change other properties, based on the mask if (mask & MASK(_METHOD_PROP_BITMASK)) { [window setPropertiesForStyleBits:bits mask:mask]; --- 696,718 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + // scans the bit field, and only updates the values requested by the mask // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) jint newBits = window.styleBits & ~mask | bits & mask; // resets the NSWindow's style mask if the mask intersects any of those bits if (mask & MASK(_STYLE_PROP_BITMASK)) { ! [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; } // calls methods on NSWindow to change other properties, based on the mask if (mask & MASK(_METHOD_PROP_BITMASK)) { [window setPropertiesForStyleBits:bits mask:mask];
*** 665,680 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); CMenuBar *menuBar = OBJC(menuBarPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! if ([window isKeyWindow]) [window.javaMenuBar deactivate]; window.javaMenuBar = menuBar; // if ([self isKeyWindow]) { [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; // } --- 733,750 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); CMenuBar *menuBar = OBJC(menuBarPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! AWTWindow *window = (AWTWindow*)[nsWindow delegate]; ! ! if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; window.javaMenuBar = menuBar; // if ([self isKeyWindow]) { [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; // }
*** 694,712 **** jobject ret = NULL; JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); __block NSRect contentRect = NSZeroRect; __block NSRect frame = NSZeroRect; [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! frame = [window frame]; ! contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[window styleMask]]; }]; jint top = (jint)(frame.size.height - contentRect.size.height); jint left = (jint)(contentRect.origin.x - frame.origin.x); jint bottom = (jint)(contentRect.origin.y - frame.origin.y); --- 764,782 ---- jobject ret = NULL; JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); __block NSRect contentRect = NSZeroRect; __block NSRect frame = NSZeroRect; [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! frame = [nsWindow frame]; ! contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]]; }]; jint top = (jint)(frame.size.height - contentRect.size.height); jint left = (jint)(contentRect.origin.x - frame.origin.x); jint bottom = (jint)(contentRect.origin.y - frame.origin.y);
*** 732,754 **** AWT_ASSERT_NOT_APPKIT_THREAD; NSRect jrect = NSMakeRect(originX, originY, width, height); // TODO: not sure we need displayIfNeeded message in our view ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; NSRect rect = ConvertNSScreenRect(NULL, jrect); [window constrainSize:&rect.size]; ! [window setFrame:rect display:YES]; // only start tracking events if pointer is above the toplevel // TODO: should post an Entered event if YES. NSPoint mLocation = [NSEvent mouseLocation]; ! [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; // ensure we repaint the whole window after the resize operation // (this will also re-enable screen updates, which were disabled above) // TODO: send PaintEvent --- 802,826 ---- AWT_ASSERT_NOT_APPKIT_THREAD; NSRect jrect = NSMakeRect(originX, originY, width, height); // TODO: not sure we need displayIfNeeded message in our view ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + NSRect rect = ConvertNSScreenRect(NULL, jrect); [window constrainSize:&rect.size]; ! [nsWindow setFrame:rect display:YES]; // only start tracking events if pointer is above the toplevel // TODO: should post an Entered event if YES. NSPoint mLocation = [NSEvent mouseLocation]; ! [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; // ensure we repaint the whole window after the resize operation // (this will also re-enable screen updates, which were disabled above) // TODO: send PaintEvent
*** 772,785 **** if (minW < 1) minW = 1; if (minH < 1) minH = 1; if (maxW < 1) maxW = 1; if (maxH < 1) maxH = 1; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; NSSize min = { minW, minH }; NSSize max = { maxW, maxH }; [window constrainSize:&min]; [window constrainSize:&max]; --- 844,859 ---- if (minW < 1) minW = 1; if (minH < 1) minH = 1; if (maxW < 1) maxW = 1; if (maxH < 1) maxH = 1; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + NSSize min = { minW, minH }; NSSize max = { maxW, maxH }; [window constrainSize:&min]; [window constrainSize:&max];
*** 801,815 **** (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [window orderBack:nil]; }]; JNF_COCOA_EXIT(env); } --- 875,889 ---- (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [nsWindow orderBack:nil]; }]; JNF_COCOA_EXIT(env); }
*** 822,839 **** (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! if (![window isKeyWindow]) { ! [window makeKeyAndOrderFront:window]; } else { ! [window orderFront:window]; } }]; JNF_COCOA_EXIT(env); } --- 896,913 ---- (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! if (![nsWindow isKeyWindow]) { ! [nsWindow makeKeyAndOrderFront:nsWindow]; } else { ! [nsWindow orderFront:nsWindow]; } }]; JNF_COCOA_EXIT(env); }
*** 847,858 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); ! [window performSelectorOnMainThread:@selector(setTitle:) withObject:JNFJavaToNSString(env, jtitle) waitUntilDone:NO]; JNF_COCOA_EXIT(env); } --- 921,932 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); ! [nsWindow performSelectorOnMainThread:@selector(setTitle:) withObject:JNFJavaToNSString(env, jtitle) waitUntilDone:NO]; JNF_COCOA_EXIT(env); }
*** 866,880 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jfloat alpha) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [window setAlphaValue:alpha]; }]; JNF_COCOA_EXIT(env); } --- 940,954 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jfloat alpha) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [nsWindow setAlphaValue:alpha]; }]; JNF_COCOA_EXIT(env); }
*** 887,901 **** (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [window invalidateShadow]; }]; JNF_COCOA_EXIT(env); } --- 961,975 ---- (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [nsWindow invalidateShadow]; }]; JNF_COCOA_EXIT(env); }
*** 910,921 **** jint ret = 0; JNF_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); ! NSDictionary *props = [[window screen] deviceDescription]; ret = [[props objectForKey:@"NSScreenNumber"] intValue]; JNF_COCOA_EXIT(env); return ret; --- 984,995 ---- jint ret = 0; JNF_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); ! NSDictionary *props = [[nsWindow screen] deviceDescription]; ret = [[props objectForKey:@"NSScreenNumber"] intValue]; JNF_COCOA_EXIT(env); return ret;
*** 930,945 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); NSImage *image = OBJC(nsImagePtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [window setMiniwindowImage:image]; }]; JNF_COCOA_EXIT(env); } --- 1004,1019 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); NSImage *image = OBJC(nsImagePtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [nsWindow setMiniwindowImage:image]; }]; JNF_COCOA_EXIT(env); }
*** 952,967 **** (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [window setRepresentedURL:url]; }]; JNF_COCOA_EXIT(env); } --- 1026,1041 ---- (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; ! [nsWindow setRepresentedURL:url]; }]; JNF_COCOA_EXIT(env); }
*** 990,1003 **** (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; [window synthesizeMouseEnteredExitedEvents]; }]; JNF_COCOA_EXIT(env); } --- 1064,1079 ---- (JNIEnv *env, jclass clazz, jlong windowPtr) { JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ AWT_ASSERT_APPKIT_THREAD; + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + [window synthesizeMouseEnteredExitedEvents]; }]; JNF_COCOA_EXIT(env); }
*** 1013,1024 **** jint index = -1; JNF_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; ! AWTWindow *window = OBJC(windowPtr); ! NSScreen* screen = [window screen]; //+++gdb NOTE: This is using a linear search of the screens. If it should // prove to be a bottleneck, this can definitely be improved. However, // many screens should prove to be the exception, rather than the rule. NSArray* screens = [NSScreen screens]; --- 1089,1100 ---- jint index = -1; JNF_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); ! NSScreen* screen = [nsWindow screen]; //+++gdb NOTE: This is using a linear search of the screens. If it should // prove to be a bottleneck, this can definitely be improved. However, // many screens should prove to be the exception, rather than the rule. NSArray* screens = [NSScreen screens];
*** 1045,1060 **** JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode (JNIEnv *env, jobject peer, jlong windowPtr) { JNF_COCOA_ENTER(env); ! AWTWindow *window = OBJC(windowPtr); SEL toggleFullScreenSelector = @selector(toggleFullScreen:); ! if (![window respondsToSelector:toggleFullScreenSelector]) return; [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ ! [window performSelector:toggleFullScreenSelector withObject:nil]; }]; JNF_COCOA_EXIT(env); } --- 1121,1136 ---- JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode (JNIEnv *env, jobject peer, jlong windowPtr) { JNF_COCOA_ENTER(env); ! NSWindow *nsWindow = OBJC(windowPtr); SEL toggleFullScreenSelector = @selector(toggleFullScreen:); ! if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return; [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ ! [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; }]; JNF_COCOA_EXIT(env); }
*** 1064,1079 **** __block jboolean underMouse = JNI_FALSE; JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! AWTWindow *aWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() { AWT_ASSERT_APPKIT_THREAD; ! NSPoint pt = [aWindow mouseLocationOutsideOfEventStream]; ! underMouse = [[aWindow contentView] hitTest:pt] != nil; }]; JNF_COCOA_EXIT(env); return underMouse; --- 1140,1155 ---- __block jboolean underMouse = JNI_FALSE; JNF_COCOA_ENTER(env); AWT_ASSERT_NOT_APPKIT_THREAD; ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() { AWT_ASSERT_APPKIT_THREAD; ! NSPoint pt = [nsWindow mouseLocationOutsideOfEventStream]; ! underMouse = [[nsWindow contentView] hitTest:pt] != nil; }]; JNF_COCOA_EXIT(env); return underMouse;
*** 1082,1093 **** JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) { JNF_COCOA_ENTER(env); ! AWTWindow *window = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ [window setEnabled: isEnabled]; }]; JNF_COCOA_EXIT(env); } --- 1158,1171 ---- JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) { JNF_COCOA_ENTER(env); ! NSWindow *nsWindow = OBJC(windowPtr); [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + [window setEnabled: isEnabled]; }]; JNF_COCOA_EXIT(env); }