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

Print this page




 303         [growBoxImage release];
 304         [imageView release];
 305 
 306         [self.nsWindow addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
 307         [self adjustGrowBoxWindow];
 308     } else growBoxWindow = nil;
 309 
 310     if (IS(self.styleBits, IS_POPUP)) {
 311         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 312     }
 313 
 314     return self;
 315 }
 316 
 317 + (BOOL) isAWTWindow:(NSWindow *)window {
 318     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 319 }
 320 
 321 // return id for the topmost window under mouse
 322 + (NSInteger) getTopmostWindowUnderMouseID {

 323 
 324     NSRect screenRect = [[NSScreen mainScreen] frame];
 325     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 326     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 327 
 328     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 329 
 330 
 331     for (NSDictionary *window in windows) {
 332         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 333         if (layer == 0) {
 334             CGRect rect;
 335             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 336             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 337                 return [[window objectForKey:(id)kCGWindowNumber] integerValue];

 338             }
 339         }
 340     }
 341     return -1;

 342 }
 343 
 344 // checks that this window is under the mouse cursor and this point is not overlapped by other windows
 345 - (BOOL) isTopmostWindowUnderMouse {
 346     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 347 }
 348 
 349 + (AWTWindow *) getTopmostWindowUnderMouse {
 350     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 351     NSWindow *window;
 352 
 353     NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
 354 
 355     while ((window = [windowEnumerator nextObject]) != nil) {
 356         if ([window windowNumber] == topmostWindowUnderMouseID) {
 357             BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
 358             return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
 359         }
 360     }
 361     return nil;




 303         [growBoxImage release];
 304         [imageView release];
 305 
 306         [self.nsWindow addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
 307         [self adjustGrowBoxWindow];
 308     } else growBoxWindow = nil;
 309 
 310     if (IS(self.styleBits, IS_POPUP)) {
 311         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 312     }
 313 
 314     return self;
 315 }
 316 
 317 + (BOOL) isAWTWindow:(NSWindow *)window {
 318     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 319 }
 320 
 321 // return id for the topmost window under mouse
 322 + (NSInteger) getTopmostWindowUnderMouseID {
 323     NSInteger result = -1;
 324     
 325     NSRect screenRect = [[NSScreen mainScreen] frame];
 326     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 327     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 328 
 329     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 330 
 331 
 332     for (NSDictionary *window in windows) {
 333         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 334         if (layer == 0) {
 335             CGRect rect;
 336             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 337             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 338                 result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
 339                 break;
 340             }
 341         }
 342     }
 343     [windows release];
 344     return result;
 345 }
 346 
 347 // checks that this window is under the mouse cursor and this point is not overlapped by other windows
 348 - (BOOL) isTopmostWindowUnderMouse {
 349     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 350 }
 351 
 352 + (AWTWindow *) getTopmostWindowUnderMouse {
 353     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 354     NSWindow *window;
 355 
 356     NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
 357 
 358     while ((window = [windowEnumerator nextObject]) != nil) {
 359         if ([window windowNumber] == topmostWindowUnderMouseID) {
 360             BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
 361             return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
 362         }
 363     }
 364     return nil;