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;


 748 
 749 JNF_COCOA_EXIT(env);
 750 }
 751 
 752 /*
 753  * Class:     sun_lwawt_macosx_CPlatformWindow
 754  * Method:    nativePushNSWindowToBack
 755  * Signature: (J)V
 756  */
 757 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
 758 (JNIEnv *env, jclass clazz, jlong windowPtr)
 759 {
 760 JNF_COCOA_ENTER(env);
 761 AWT_ASSERT_NOT_APPKIT_THREAD;
 762 
 763     AWTWindow *window = OBJC(windowPtr);
 764     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 765         AWT_ASSERT_APPKIT_THREAD;
 766 
 767         [window orderBack:nil];

 768     }];
 769 
 770 JNF_COCOA_EXIT(env);
 771 }
 772 
 773 /*
 774  * Class:     sun_lwawt_macosx_CPlatformWindow
 775  * Method:    nativePushNSWindowToFront
 776  * Signature: (J)V
 777  */
 778 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
 779 (JNIEnv *env, jclass clazz, jlong windowPtr)
 780 {
 781 JNF_COCOA_ENTER(env);
 782 AWT_ASSERT_NOT_APPKIT_THREAD;
 783 
 784     AWTWindow *window = OBJC(windowPtr);
 785     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 786         AWT_ASSERT_APPKIT_THREAD;
 787 
 788         if (![window isKeyWindow]) {
 789             [window makeKeyAndOrderFront:window];
 790         } else {
 791             [window orderFront:window];
 792         }


 793     }];
 794 
 795 JNF_COCOA_EXIT(env);
 796 }
 797 
 798 /*
 799  * Class:     sun_lwawt_macosx_CPlatformWindow
 800  * Method:    nativeSetNSWindowTitle
 801  * Signature: (JLjava/lang/String;)V
 802  */
 803 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
 804 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
 805 {
 806 JNF_COCOA_ENTER(env);
 807 AWT_ASSERT_NOT_APPKIT_THREAD;
 808 
 809     AWTWindow *window = OBJC(windowPtr);
 810     [window performSelectorOnMainThread:@selector(setTitle:)
 811                               withObject:JNFJavaToNSString(env, jtitle)
 812                            waitUntilDone:NO];




 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 
 279                             enterExitEventWithType: eventType
 280                             location: windowLocation
 281                             modifierFlags: modifierFlags
 282                             timestamp: 0
 283                             windowNumber: [self windowNumber]
 284                             context: nil
 285                             eventNumber: 0
 286                             trackingNumber: 0
 287                             userData: nil
 288                             ];
 289     
 290     [[self contentView] deliverJavaMouseEvent: mouseEvent];
 291 }
 292 
 293 - (void) dealloc {
 294 AWT_ASSERT_APPKIT_THREAD;
 295 
 296     JNIEnv *env = [ThreadUtilities getJNIEnv];
 297     [self.javaPlatformWindow setJObject:nil withEnv:env];
 298     self.growBoxWindow = nil;
 299 
 300     [super dealloc];
 301 }
 302 
 303 
 304 // NSWindow overrides
 305 - (BOOL) canBecomeKeyWindow {
 306 AWT_ASSERT_APPKIT_THREAD;
 307     return IS(self.styleBits, SHOULD_BECOME_KEY);
 308 }
 309 
 310 - (BOOL) canBecomeMainWindow {
 311 AWT_ASSERT_APPKIT_THREAD;
 312     return IS(self.styleBits, SHOULD_BECOME_MAIN);


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


 810 
 811 JNF_COCOA_EXIT(env);
 812 }
 813 
 814 /*
 815  * Class:     sun_lwawt_macosx_CPlatformWindow
 816  * Method:    nativePushNSWindowToBack
 817  * Signature: (J)V
 818  */
 819 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
 820 (JNIEnv *env, jclass clazz, jlong windowPtr)
 821 {
 822 JNF_COCOA_ENTER(env);
 823 AWT_ASSERT_NOT_APPKIT_THREAD;
 824 
 825     AWTWindow *window = OBJC(windowPtr);
 826     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 827         AWT_ASSERT_APPKIT_THREAD;
 828 
 829         [window orderBack:nil];
 830         [window synthesizeMouseEnteredExitedEvents];
 831     }];
 832 
 833 JNF_COCOA_EXIT(env);
 834 }
 835 
 836 /*
 837  * Class:     sun_lwawt_macosx_CPlatformWindow
 838  * Method:    nativePushNSWindowToFront
 839  * Signature: (J)V
 840  */
 841 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
 842 (JNIEnv *env, jclass clazz, jlong windowPtr)
 843 {
 844 JNF_COCOA_ENTER(env);
 845 AWT_ASSERT_NOT_APPKIT_THREAD;
 846 
 847     AWTWindow *window = OBJC(windowPtr);
 848     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 849         AWT_ASSERT_APPKIT_THREAD;
 850 
 851         if (![window isKeyWindow]) {
 852             [window makeKeyAndOrderFront:window];
 853         } else {
 854             [window orderFront:window];
 855         }
 856         
 857         [window synthesizeMouseEnteredExitedEvents];
 858     }];
 859 
 860 JNF_COCOA_EXIT(env);
 861 }
 862 
 863 /*
 864  * Class:     sun_lwawt_macosx_CPlatformWindow
 865  * Method:    nativeSetNSWindowTitle
 866  * Signature: (JLjava/lang/String;)V
 867  */
 868 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
 869 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
 870 {
 871 JNF_COCOA_ENTER(env);
 872 AWT_ASSERT_NOT_APPKIT_THREAD;
 873 
 874     AWTWindow *window = OBJC(windowPtr);
 875     [window performSelectorOnMainThread:@selector(setTitle:)
 876                               withObject:JNFJavaToNSString(env, jtitle)
 877                            waitUntilDone:NO];