jdk/src/macosx/native/sun/awt/AWTWindow.m
changeset 12640 5ea775607d72
parent 12535 6d2ee83614e8
child 12648 00c38c393e11
equal deleted inserted replaced
12639:c1634bcec0a8 12640:5ea775607d72
    56 @synthesize javaPlatformWindow;
    56 @synthesize javaPlatformWindow;
    57 @synthesize javaMenuBar;
    57 @synthesize javaMenuBar;
    58 @synthesize javaMinSize;
    58 @synthesize javaMinSize;
    59 @synthesize javaMaxSize;
    59 @synthesize javaMaxSize;
    60 @synthesize styleBits;
    60 @synthesize styleBits;
       
    61 @synthesize isEnabled;
    61 
    62 
    62 - (void) updateMinMaxSize:(BOOL)resizable {
    63 - (void) updateMinMaxSize:(BOOL)resizable {
    63     if (resizable) {
    64     if (resizable) {
    64         [self setMinSize:self.javaMinSize];
    65         [self setMinSize:self.javaMinSize];
    65         [self setMaxSize:self.javaMaxSize];
    66         [self setMaxSize:self.javaMaxSize];
   155                               backing:NSBackingStoreBuffered
   156                               backing:NSBackingStoreBuffered
   156                                 defer:NO];
   157                                 defer:NO];
   157 
   158 
   158     if (self == nil) return nil; // no hope
   159     if (self == nil) return nil; // no hope
   159 
   160 
       
   161     self.isEnabled = YES;
   160     self.javaPlatformWindow = platformWindow;
   162     self.javaPlatformWindow = platformWindow;
   161     self.styleBits = bits;
   163     self.styleBits = bits;
   162     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
   164     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
   163 
   165 
   164     [self setDelegate:self];
   166     [self setDelegate:self];
   168     [self setPreservesContentDuringLiveResize:YES];
   170     [self setPreservesContentDuringLiveResize:YES];
   169 
   171 
   170     return self;
   172     return self;
   171 }
   173 }
   172 
   174 
   173 // checks that this window is under the mouse cursor and this point is not overlapped by others windows 
   175 // checks that this window is under the mouse cursor and this point is not overlapped by others windows
   174 - (BOOL) isTopmostWindowUnderMouse {
   176 - (BOOL) isTopmostWindowUnderMouse {
   175     
   177 
   176     int currentWinID = [self windowNumber]; 
   178     int currentWinID = [self windowNumber];
   177     
   179 
   178     NSRect screenRect = [[NSScreen mainScreen] frame];    
   180     NSRect screenRect = [[NSScreen mainScreen] frame];
   179     NSPoint nsMouseLocation = [NSEvent mouseLocation];
   181     NSPoint nsMouseLocation = [NSEvent mouseLocation];
   180     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);    
   182     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
   181     
   183 
   182     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
   184     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
   183     
   185 
   184     
   186 
   185     for (NSDictionary *window in windows) {
   187     for (NSDictionary *window in windows) {
   186         int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
   188         int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
   187         if (layer == 0) {
   189         if (layer == 0) {
   188             int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];            
   190             int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];
   189             CGRect rect;
   191             CGRect rect;
   190             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
   192             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
   191             if (CGRectContainsPoint(rect, cgMouseLocation)) {
   193             if (CGRectContainsPoint(rect, cgMouseLocation)) {
   192                 return currentWinID == winID;
   194                 return currentWinID == winID;
   193             } else if (currentWinID == winID) {
   195             } else if (currentWinID == winID) {
   197     }
   199     }
   198     return NO;
   200     return NO;
   199 }
   201 }
   200 
   202 
   201 - (void) synthesizeMouseEnteredExitedEvents {
   203 - (void) synthesizeMouseEnteredExitedEvents {
   202     
   204 
   203     int eventType = 0;
   205     int eventType = 0;
   204     BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
   206     BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
   205     BOOL mouseIsOver = [[self contentView] mouseIsOver];
   207     BOOL mouseIsOver = [[self contentView] mouseIsOver];
   206     
   208 
   207     if (isUnderMouse && !mouseIsOver) {
   209     if (isUnderMouse && !mouseIsOver) {
   208         eventType = NSMouseEntered;
   210         eventType = NSMouseEntered;
   209     } else if (!isUnderMouse && mouseIsOver) {
   211     } else if (!isUnderMouse && mouseIsOver) {
   210         eventType = NSMouseExited;        
   212         eventType = NSMouseExited;
   211     } else {
   213     } else {
   212         return;
   214         return;
   213     }
   215     }
   214     
   216 
   215     NSPoint screenLocation = [NSEvent mouseLocation];        
   217     NSPoint screenLocation = [NSEvent mouseLocation];
   216     NSPoint windowLocation = [self convertScreenToBase: screenLocation];        
   218     NSPoint windowLocation = [self convertScreenToBase: screenLocation];
   217     int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
   219     int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
   218     
   220 
   219     NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
   221     NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
   220                                                   location: windowLocation
   222                                                   location: windowLocation
   221                                              modifierFlags: modifierFlags
   223                                              modifierFlags: modifierFlags
   222                                                  timestamp: 0
   224                                                  timestamp: 0
   223                                               windowNumber: [self windowNumber]
   225                                               windowNumber: [self windowNumber]
   224                                                    context: nil
   226                                                    context: nil
   225                                                eventNumber: 0
   227                                                eventNumber: 0
   226                                             trackingNumber: 0
   228                                             trackingNumber: 0
   227                                                   userData: nil
   229                                                   userData: nil
   228                             ];
   230                             ];
   229     
   231 
   230     [[self contentView] deliverJavaMouseEvent: mouseEvent];
   232     [[self contentView] deliverJavaMouseEvent: mouseEvent];
   231 }
   233 }
   232 
   234 
   233 - (void) dealloc {
   235 - (void) dealloc {
   234 AWT_ASSERT_APPKIT_THREAD;
   236 AWT_ASSERT_APPKIT_THREAD;
   237     [self.javaPlatformWindow setJObject:nil withEnv:env];
   239     [self.javaPlatformWindow setJObject:nil withEnv:env];
   238 
   240 
   239     [super dealloc];
   241     [super dealloc];
   240 }
   242 }
   241 
   243 
   242 
       
   243 // NSWindow overrides
   244 // NSWindow overrides
   244 - (BOOL) canBecomeKeyWindow {
   245 - (BOOL) canBecomeKeyWindow {
   245 AWT_ASSERT_APPKIT_THREAD;
   246 AWT_ASSERT_APPKIT_THREAD;
   246     return IS(self.styleBits, SHOULD_BECOME_KEY);
   247     return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
   247 }
   248 }
   248 
   249 
   249 - (BOOL) canBecomeMainWindow {
   250 - (BOOL) canBecomeMainWindow {
   250 AWT_ASSERT_APPKIT_THREAD;
   251 AWT_ASSERT_APPKIT_THREAD;
   251     return IS(self.styleBits, SHOULD_BECOME_MAIN);
   252     return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
   252 }
   253 }
   253 
   254 
   254 - (BOOL) worksWhenModal {
   255 - (BOOL) worksWhenModal {
   255 AWT_ASSERT_APPKIT_THREAD;
   256 AWT_ASSERT_APPKIT_THREAD;
   256     return IS(self.styleBits, MODAL_EXCLUDED);
   257     return IS(self.styleBits, MODAL_EXCLUDED);
   560 
   561 
   561     size->width = MAX(size->width, minWidth);
   562     size->width = MAX(size->width, minWidth);
   562     size->height = MAX(size->height, minHeight);
   563     size->height = MAX(size->height, minHeight);
   563 }
   564 }
   564 
   565 
       
   566 - (void) setEnabled: (BOOL)flag {
       
   567     self.isEnabled = flag;
       
   568 
       
   569     if (IS(self.styleBits, CLOSEABLE)) {
       
   570         [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag];
       
   571     }
       
   572 
       
   573     if (IS(self.styleBits, MINIMIZABLE)) {
       
   574         [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
       
   575     }
       
   576 
       
   577     if (IS(self.styleBits, ZOOMABLE)) {
       
   578         [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag];
       
   579     }
       
   580 
       
   581     if (IS(self.styleBits, RESIZABLE)) {
       
   582         [self updateMinMaxSize:flag];
       
   583         [self setShowsResizeIndicator:flag];
       
   584     }
       
   585 }
       
   586 
   565 @end // AWTWindow
   587 @end // AWTWindow
   566 
   588 
   567 
   589 
   568 /*
   590 /*
   569  * Class:     sun_lwawt_macosx_CPlatformWindow
   591  * Class:     sun_lwawt_macosx_CPlatformWindow
   727         [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
   749         [window setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
   728 
   750 
   729         // ensure we repaint the whole window after the resize operation
   751         // ensure we repaint the whole window after the resize operation
   730         // (this will also re-enable screen updates, which were disabled above)
   752         // (this will also re-enable screen updates, which were disabled above)
   731         // TODO: send PaintEvent
   753         // TODO: send PaintEvent
   732         
   754 
   733         [window synthesizeMouseEnteredExitedEvents];
   755         [window synthesizeMouseEnteredExitedEvents];
   734     }];
   756     }];
   735 
   757 
   736 JNF_COCOA_EXIT(env);
   758 JNF_COCOA_EXIT(env);
   737 }
   759 }
   967 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents
   989 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents
   968 (JNIEnv *env, jclass clazz, jlong windowPtr)
   990 (JNIEnv *env, jclass clazz, jlong windowPtr)
   969 {
   991 {
   970     JNF_COCOA_ENTER(env);
   992     JNF_COCOA_ENTER(env);
   971     AWT_ASSERT_NOT_APPKIT_THREAD;
   993     AWT_ASSERT_NOT_APPKIT_THREAD;
   972     
   994 
   973     AWTWindow *window = OBJC(windowPtr);
   995     AWTWindow *window = OBJC(windowPtr);
   974     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
   996     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
   975         AWT_ASSERT_APPKIT_THREAD;
   997         AWT_ASSERT_APPKIT_THREAD;
   976         
   998 
   977         [window synthesizeMouseEnteredExitedEvents];
   999         [window synthesizeMouseEnteredExitedEvents];
   978     }];
  1000     }];
   979     
  1001 
   980     JNF_COCOA_EXIT(env);
  1002     JNF_COCOA_EXIT(env);
   981 }
  1003 }
   982 
  1004 
   983 /*
  1005 /*
   984  * Class:     sun_lwawt_macosx_CPlatformWindow
  1006  * Class:     sun_lwawt_macosx_CPlatformWindow
  1054 
  1076 
  1055 JNF_COCOA_EXIT(env);
  1077 JNF_COCOA_EXIT(env);
  1056 
  1078 
  1057     return underMouse;
  1079     return underMouse;
  1058 }
  1080 }
       
  1081 
       
  1082 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
       
  1083 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
       
  1084 {
       
  1085 JNF_COCOA_ENTER(env);
       
  1086 
       
  1087     AWTWindow *window = OBJC(windowPtr);
       
  1088     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
       
  1089         [window setEnabled: isEnabled];
       
  1090     }];
       
  1091 
       
  1092 JNF_COCOA_EXIT(env);
       
  1093 }
       
  1094