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

Print this page




 213         [self.growBoxWindow setBackgroundColor:[NSColor clearColor]];
 214         [self.growBoxWindow setHasShadow:NO];
 215         [self.growBoxWindow setReleasedWhenClosed:NO];
 216 
 217         NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]];
 218         [imageView setEditable:NO];
 219         [imageView setAnimates:NO];
 220         [imageView setAllowsCutCopyPaste:NO];
 221         [self.growBoxWindow setContentView:imageView];
 222         [imageView setImage:growBoxImage];
 223         [growBoxImage release];
 224         [imageView release];
 225 
 226         [self addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
 227         [self adjustGrowBoxWindow];
 228     } else growBoxWindow = nil;
 229 
 230     return self;
 231 }
 232 



























































 233 - (void) dealloc {
 234 AWT_ASSERT_APPKIT_THREAD;
 235 
 236     JNIEnv *env = [ThreadUtilities getJNIEnv];
 237     [self.javaPlatformWindow setJObject:nil withEnv:env];
 238     self.growBoxWindow = nil;
 239 
 240     [super dealloc];
 241 }
 242 
 243 
 244 // NSWindow overrides
 245 - (BOOL) canBecomeKeyWindow {
 246 AWT_ASSERT_APPKIT_THREAD;
 247     return IS(self.styleBits, SHOULD_BECOME_KEY);
 248 }
 249 
 250 - (BOOL) canBecomeMainWindow {
 251 AWT_ASSERT_APPKIT_THREAD;
 252     return IS(self.styleBits, SHOULD_BECOME_MAIN);


 696 AWT_ASSERT_NOT_APPKIT_THREAD;
 697 
 698     NSRect jrect = NSMakeRect(originX, originY, width, height);
 699 
 700     // TODO: not sure we need displayIfNeeded message in our view
 701     AWTWindow *window = OBJC(windowPtr);
 702     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 703         AWT_ASSERT_APPKIT_THREAD;
 704 
 705         NSRect rect = ConvertNSScreenRect(NULL, jrect);
 706         [window setFrame:rect display:YES];
 707 
 708         // only start tracking events if pointer is above the toplevel
 709         // TODO: should post an Entered event if YES.
 710         NSPoint mLocation = [NSEvent mouseLocation];
 711         [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
 712 
 713         // ensure we repaint the whole window after the resize operation
 714         // (this will also re-enable screen updates, which were disabled above)
 715         // TODO: send PaintEvent


 716     }];
 717 
 718 JNF_COCOA_EXIT(env);
 719 }
 720 
 721 /*
 722  * Class:     sun_lwawt_macosx_CPlatformWindow
 723  * Method:    nativeSetNSWindowMinMax
 724  * Signature: (JDDDD)V
 725  */
 726 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
 727 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
 728 {
 729 JNF_COCOA_ENTER(env);
 730 AWT_ASSERT_NOT_APPKIT_THREAD;
 731 
 732     if (minW < 1) minW = 1;
 733     if (minH < 1) minH = 1;
 734     if (maxW < 1) maxW = 1;
 735     if (maxH < 1) maxH = 1;


 924 }
 925 
 926 /*
 927  * Class:     sun_lwawt_macosx_CPlatformWindow
 928  * Method:    nativeSetNSWindowSecurityWarningPositioning
 929  * Signature: (JDDFF)V
 930  */
 931 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning
 932 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY)
 933 {
 934 JNF_COCOA_ENTER(env);
 935 AWT_ASSERT_NOT_APPKIT_THREAD;
 936 
 937     [JNFException raise:env as:kRuntimeException reason:"unimplemented"];
 938 
 939 JNF_COCOA_EXIT(env);
 940 }
 941 
 942 /*
 943  * Class:     sun_lwawt_macosx_CPlatformWindow





















 944  * Method:    nativeGetScreenNSWindowIsOn_AppKitThread
 945  * Signature: (J)I
 946  */
 947 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread
 948 (JNIEnv *env, jclass clazz, jlong windowPtr)
 949 {
 950     jint index = -1;
 951 
 952 JNF_COCOA_ENTER(env);
 953 AWT_ASSERT_APPKIT_THREAD;
 954 
 955     AWTWindow *window = OBJC(windowPtr);
 956     NSScreen* screen = [window screen];
 957 
 958     //+++gdb NOTE: This is using a linear search of the screens. If it should
 959     //  prove to be a bottleneck, this can definitely be improved. However,
 960     //  many screens should prove to be the exception, rather than the rule.
 961     NSArray* screens = [NSScreen screens];
 962     NSUInteger i;
 963     for (i = 0; i < [screens count]; i++)




 213         [self.growBoxWindow setBackgroundColor:[NSColor clearColor]];
 214         [self.growBoxWindow setHasShadow:NO];
 215         [self.growBoxWindow setReleasedWhenClosed:NO];
 216 
 217         NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]];
 218         [imageView setEditable:NO];
 219         [imageView setAnimates:NO];
 220         [imageView setAllowsCutCopyPaste:NO];
 221         [self.growBoxWindow setContentView:imageView];
 222         [imageView setImage:growBoxImage];
 223         [growBoxImage release];
 224         [imageView release];
 225 
 226         [self addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
 227         [self adjustGrowBoxWindow];
 228     } else growBoxWindow = nil;
 229 
 230     return self;
 231 }
 232 
 233 - (BOOL) isTopmostWindowUnderMouse {
 234     
 235     int currentWinID = [self windowNumber]; 
 236     
 237     NSRect screenRect = [[NSScreen mainScreen] frame];    
 238     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 239     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);    
 240     
 241     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 242     
 243     
 244     for (NSDictionary *window in windows) {
 245         int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
 246         if (layer == 0) {
 247             int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];            
 248             CGRect rect;
 249             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 250             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 251                 return currentWinID == winID;
 252             } else if (currentWinID == winID) {
 253                 return NO;
 254             }
 255         }
 256     }
 257     return NO;
 258 }
 259 
 260 - (void) synthesizeMouseEnteredExitedEvents {
 261     
 262     int eventType = 0;
 263     BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
 264     BOOL mouseIsOver = [[self contentView] mouseIsOver];
 265     
 266     if (isUnderMouse && !mouseIsOver) {
 267         eventType = NSMouseEntered;
 268     } else if (!isUnderMouse && mouseIsOver) {
 269         eventType = NSMouseExited;        
 270     } else {
 271         return;
 272     }
 273     
 274     NSPoint screenLocation = [NSEvent mouseLocation];        
 275     NSPoint windowLocation = [self convertScreenToBase: screenLocation];        
 276     int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
 277     
 278     NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
 279                                                   location: windowLocation
 280                                              modifierFlags: modifierFlags
 281                                                  timestamp: 0
 282                                               windowNumber: [self windowNumber]
 283                                                    context: nil
 284                                                eventNumber: 0
 285                                             trackingNumber: 0
 286                                                   userData: nil
 287                             ];
 288     
 289     [[self contentView] deliverJavaMouseEvent: mouseEvent];
 290 }
 291 
 292 - (void) dealloc {
 293 AWT_ASSERT_APPKIT_THREAD;
 294 
 295     JNIEnv *env = [ThreadUtilities getJNIEnv];
 296     [self.javaPlatformWindow setJObject:nil withEnv:env];
 297     self.growBoxWindow = nil;
 298 
 299     [super dealloc];
 300 }
 301 
 302 
 303 // NSWindow overrides
 304 - (BOOL) canBecomeKeyWindow {
 305 AWT_ASSERT_APPKIT_THREAD;
 306     return IS(self.styleBits, SHOULD_BECOME_KEY);
 307 }
 308 
 309 - (BOOL) canBecomeMainWindow {
 310 AWT_ASSERT_APPKIT_THREAD;
 311     return IS(self.styleBits, SHOULD_BECOME_MAIN);


 755 AWT_ASSERT_NOT_APPKIT_THREAD;
 756 
 757     NSRect jrect = NSMakeRect(originX, originY, width, height);
 758 
 759     // TODO: not sure we need displayIfNeeded message in our view
 760     AWTWindow *window = OBJC(windowPtr);
 761     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 762         AWT_ASSERT_APPKIT_THREAD;
 763 
 764         NSRect rect = ConvertNSScreenRect(NULL, jrect);
 765         [window setFrame:rect display:YES];
 766 
 767         // only start tracking events if pointer is above the toplevel
 768         // TODO: should post an Entered event if YES.
 769         NSPoint mLocation = [NSEvent mouseLocation];
 770         [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
 771 
 772         // ensure we repaint the whole window after the resize operation
 773         // (this will also re-enable screen updates, which were disabled above)
 774         // TODO: send PaintEvent
 775         
 776         [window synthesizeMouseEnteredExitedEvents];
 777     }];
 778 
 779 JNF_COCOA_EXIT(env);
 780 }
 781 
 782 /*
 783  * Class:     sun_lwawt_macosx_CPlatformWindow
 784  * Method:    nativeSetNSWindowMinMax
 785  * Signature: (JDDDD)V
 786  */
 787 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
 788 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
 789 {
 790 JNF_COCOA_ENTER(env);
 791 AWT_ASSERT_NOT_APPKIT_THREAD;
 792 
 793     if (minW < 1) minW = 1;
 794     if (minH < 1) minH = 1;
 795     if (maxW < 1) maxW = 1;
 796     if (maxH < 1) maxH = 1;


 985 }
 986 
 987 /*
 988  * Class:     sun_lwawt_macosx_CPlatformWindow
 989  * Method:    nativeSetNSWindowSecurityWarningPositioning
 990  * Signature: (JDDFF)V
 991  */
 992 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning
 993 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY)
 994 {
 995 JNF_COCOA_ENTER(env);
 996 AWT_ASSERT_NOT_APPKIT_THREAD;
 997 
 998     [JNFException raise:env as:kRuntimeException reason:"unimplemented"];
 999 
1000 JNF_COCOA_EXIT(env);
1001 }
1002 
1003 /*
1004  * Class:     sun_lwawt_macosx_CPlatformWindow
1005  * Method:    nativeSynthesizeMouseEnteredExitedEvents
1006  * Signature: (J)V
1007  */
1008 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents
1009 (JNIEnv *env, jclass clazz, jlong windowPtr)
1010 {
1011     JNF_COCOA_ENTER(env);
1012     AWT_ASSERT_NOT_APPKIT_THREAD;
1013     
1014     AWTWindow *window = OBJC(windowPtr);
1015     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
1016         AWT_ASSERT_APPKIT_THREAD;
1017         
1018         [window synthesizeMouseEnteredExitedEvents];
1019     }];
1020     
1021     JNF_COCOA_EXIT(env);
1022 }
1023 
1024 /*
1025  * Class:     sun_lwawt_macosx_CPlatformWindow
1026  * Method:    nativeGetScreenNSWindowIsOn_AppKitThread
1027  * Signature: (J)I
1028  */
1029 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread
1030 (JNIEnv *env, jclass clazz, jlong windowPtr)
1031 {
1032     jint index = -1;
1033 
1034 JNF_COCOA_ENTER(env);
1035 AWT_ASSERT_APPKIT_THREAD;
1036 
1037     AWTWindow *window = OBJC(windowPtr);
1038     NSScreen* screen = [window screen];
1039 
1040     //+++gdb NOTE: This is using a linear search of the screens. If it should
1041     //  prove to be a bottleneck, this can definitely be improved. However,
1042     //  many screens should prove to be the exception, rather than the rule.
1043     NSArray* screens = [NSScreen screens];
1044     NSUInteger i;
1045     for (i = 0; i < [screens count]; i++)