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

Print this page




 244     }
 245 
 246     if (self.nsWindow == nil) return nil; // no hope either
 247     [self.nsWindow release]; // the property retains the object already
 248 
 249     self.isEnabled = YES;
 250     self.javaPlatformWindow = platformWindow;
 251     self.styleBits = bits;
 252     self.ownerWindow = owner;
 253     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 254 
 255     return self;
 256 }
 257 
 258 + (BOOL) isAWTWindow:(NSWindow *)window {
 259     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 260 }
 261 
 262 // returns id for the topmost window under mouse
 263 + (NSInteger) getTopmostWindowUnderMouseID {

 264 
 265     NSRect screenRect = [[NSScreen mainScreen] frame];
 266     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 267     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 268 
 269     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 270 
 271     for (NSDictionary *window in windows) {
 272         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 273         if (layer == 0) {
 274             CGRect rect;
 275             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 276             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 277                 return [[window objectForKey:(id)kCGWindowNumber] integerValue];

 278             }
 279         }
 280     }
 281     return -1;

 282 }
 283 
 284 // checks that this window is under the mouse cursor and this point is not overlapped by others windows
 285 - (BOOL) isTopmostWindowUnderMouse {
 286     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 287 }
 288 
 289 + (AWTWindow *) getTopmostWindowUnderMouse {
 290     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 291     NSWindow *window;
 292 
 293     NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
 294 
 295     while ((window = [windowEnumerator nextObject]) != nil) {
 296         if ([window windowNumber] == topmostWindowUnderMouseID) {
 297             BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
 298             return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
 299         }
 300     }
 301     return nil;




 244     }
 245 
 246     if (self.nsWindow == nil) return nil; // no hope either
 247     [self.nsWindow release]; // the property retains the object already
 248 
 249     self.isEnabled = YES;
 250     self.javaPlatformWindow = platformWindow;
 251     self.styleBits = bits;
 252     self.ownerWindow = owner;
 253     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 254 
 255     return self;
 256 }
 257 
 258 + (BOOL) isAWTWindow:(NSWindow *)window {
 259     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 260 }
 261 
 262 // returns id for the topmost window under mouse
 263 + (NSInteger) getTopmostWindowUnderMouseID {
 264     NSInteger result = -1;
 265     
 266     NSRect screenRect = [[NSScreen mainScreen] frame];
 267     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 268     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 269 
 270     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 271 
 272     for (NSDictionary *window in windows) {
 273         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 274         if (layer == 0) {
 275             CGRect rect;
 276             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
 277             if (CGRectContainsPoint(rect, cgMouseLocation)) {
 278                 result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
 279                 break;
 280             }
 281         }
 282     }
 283     [windows release];
 284     return result;
 285 }
 286 
 287 // checks that this window is under the mouse cursor and this point is not overlapped by others windows
 288 - (BOOL) isTopmostWindowUnderMouse {
 289     return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
 290 }
 291 
 292 + (AWTWindow *) getTopmostWindowUnderMouse {
 293     NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
 294     NSWindow *window;
 295 
 296     NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
 297 
 298     while ((window = [windowEnumerator nextObject]) != nil) {
 299         if ([window windowNumber] == topmostWindowUnderMouseID) {
 300             BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
 301             return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
 302         }
 303     }
 304     return nil;