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

Print this page




 309     [self.nsWindow release]; // the property retains the object already
 310 
 311     self.isEnabled = YES;
 312     self.isMinimizing = NO;
 313     self.javaPlatformWindow = platformWindow;
 314     self.styleBits = bits;
 315     self.ownerWindow = owner;
 316     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 317 
 318     if (IS(self.styleBits, IS_POPUP)) {
 319         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 320     }
 321 
 322     return self;
 323 }
 324 
 325 + (BOOL) isAWTWindow:(NSWindow *)window {
 326     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 327 }
 328 




















 329 // returns id for the topmost window under mouse
 330 + (NSInteger) getTopmostWindowUnderMouseID {
 331     NSInteger result = -1;
 332     














 333     NSRect screenRect = [[NSScreen mainScreen] frame];
 334     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 335     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 336 
 337     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 338 
 339     for (NSDictionary *window in windows) {
 340         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 341         if (layer == 0) {
 342             CGRect rect;
 343             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 344             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 345                 result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
 346                 break;
 347             }
 348         }
 349     }
 350     [windows release];
 351     return result;
 352 }
 353 
 354 // checks that this window is under the mouse cursor and this point is not overlapped by others windows
 355 - (BOOL) isTopmostWindowUnderMouse {
 356     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 357 }
 358 
 359 + (AWTWindow *) getTopmostWindowUnderMouse {
 360     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 361     NSWindow *window;




 309     [self.nsWindow release]; // the property retains the object already
 310 
 311     self.isEnabled = YES;
 312     self.isMinimizing = NO;
 313     self.javaPlatformWindow = platformWindow;
 314     self.styleBits = bits;
 315     self.ownerWindow = owner;
 316     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 317 
 318     if (IS(self.styleBits, IS_POPUP)) {
 319         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 320     }
 321 
 322     return self;
 323 }
 324 
 325 + (BOOL) isAWTWindow:(NSWindow *)window {
 326     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 327 }
 328 
 329 // Retrieves the list of possible window layers (levels)
 330 + (NSArray*) getWindowLayers {
 331     static NSArray *windowLayers;
 332     static dispatch_once_t token;
 333  
 334     // Initialize the list of possible window layers
 335     dispatch_once(&token, ^{
 336         // The layers are ordered from front to back, (i.e. the toppest one is the first)
 337         windowLayers = [NSArray arrayWithObjects:
 338                             [NSNumber numberWithInt:CGWindowLevelForKey(kCGPopUpMenuWindowLevelKey)],
 339                             [NSNumber numberWithInt:CGWindowLevelForKey(kCGFloatingWindowLevelKey)],
 340                             [NSNumber numberWithInt:CGWindowLevelForKey(kCGNormalWindowLevelKey)],
 341                             nil
 342                        ];
 343         [windowLayers retain];
 344     });
 345     return windowLayers;
 346 }
 347 
 348 
 349 // returns id for the topmost window under mouse
 350 + (NSInteger) getTopmostWindowUnderMouseID {
 351     NSInteger result = -1;
 352 
 353     NSArray *windowLayers = [AWTWindow getWindowLayers];
 354     // Looking for the window under mouse starting from the toppest layer
 355     for (NSNumber *layer in windowLayers) {
 356         result = [AWTWindow getTopmostWindowUnderMouseIDImpl:[layer integerValue]];
 357         if (result != -1) {
 358             break;
 359         }
 360     }
 361     return result;
 362 }
 363 
 364 + (NSInteger) getTopmostWindowUnderMouseIDImpl:(NSInteger)windowLayer {
 365     NSInteger result = -1;    
 366 
 367     NSRect screenRect = [[NSScreen mainScreen] frame];
 368     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 369     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 370 
 371     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 372 
 373     for (NSDictionary *window in windows) {
 374         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 375         if (layer == windowLayer) {
 376             CGRect rect;
 377             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 378             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 379                 result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
 380                 break;
 381             }
 382         }
 383     }
 384     [windows release];
 385     return result;
 386 }
 387 
 388 // checks that this window is under the mouse cursor and this point is not overlapped by others windows
 389 - (BOOL) isTopmostWindowUnderMouse {
 390     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 391 }
 392 
 393 + (AWTWindow *) getTopmostWindowUnderMouse {
 394     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 395     NSWindow *window;