I'm trying to programmatically create a borderless NSWindow close to the mouse cursor and with the size of the image it should display. However I always get a much larger window (each side is about three times the size it should be)! I double-checked that my imageObj has the correct size and that all the NSSize and NSRect structures are created with correct values. The commented-out line doesn't work either (however which would be correct?)
I already searched through this site but I couldn't find any similar issue... What am I doing wrong? Here is my code:
NSString* imageName = [[NSBundle mainBundle] pathForResource:@"os_unknown" ofType:@"icns"];
NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];
[view setImage:imageObj];
NSSize s = [imageObj size];
NSPoint p = [NSEvent mouseLocation];
NSRect r = [NSWindow frameRectForContentRect:NSMakeRect(p.x, p.y, s.width, s.height)
styleMask:NSBorderlessWindowMask];
//NSRect r = {p, s};
if (win) [win release];
win = [[NSWindow alloc] initWithContentRect:r
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:false];
[win setLevel:kCGUtilityWindowLevel];
[view setBounds:NSMakeRect(0, 0, s.width, s.height)];
[[win contentView] addSubview:view];
[win orderFront:sender];
Here *win is an NSWindow and *view is an NSImageView. Both are declared on top of my source file. I'm running Snow Leopard so any strictly >10.6.8 code won't work (already tried something).
Thank you in advance for any help.