diff options
| author | Manolo Gouy <Manolo> | 2013-04-30 08:56:28 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2013-04-30 08:56:28 +0000 |
| commit | a2d821cc2e089c3872e881db046efe8ae1c44253 (patch) | |
| tree | bb56522d20a14a78a572a2c9f142c96bf76a72c1 /src | |
| parent | dc21195952cfd2eff01a3befffa6b940b118d433 (diff) | |
Use the [NSimage initWithCGImage:size:] message when possible.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9907 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_cocoa.mm | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 6b1d31764..3e104eabe 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2960,19 +2960,30 @@ void Fl_X::collapse() { static NSImage *CGBitmapContextToNSImage(CGContextRef c) // the returned NSImage is autoreleased { - unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c); - NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata - pixelsWide:CGBitmapContextGetWidth(c) - pixelsHigh:CGBitmapContextGetHeight(c) - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:CGBitmapContextGetBytesPerRow(c) - bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)]; - NSImage* image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]]; - [imagerep release]; + NSImage* image; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + if (fl_mac_os_version >= 100600) { + CGImageRef cgimg = CGBitmapContextCreateImage(c); // requires 10.4 + image = [[NSImage alloc] initWithCGImage:cgimg size:NSZeroSize]; // requires 10.6 + CFRelease(cgimg); + } + else +#endif + { + unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c); + NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata + pixelsWide:CGBitmapContextGetWidth(c) + pixelsHigh:CGBitmapContextGetHeight(c) + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:CGBitmapContextGetBytesPerRow(c) + bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)]; + image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]]; + [imagerep release]; + } return [image autorelease]; } @@ -3275,12 +3286,7 @@ int Fl::dnd(void) [mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"]; CFRelease(text); Fl_Widget *w = Fl::pushed(); - Fl_Window *win = w->window(); - if (win == NULL) { - win = (Fl_Window*)w; - } else { - while(win->window()) win = win->window(); - } + Fl_Window *win = w->top_window(); NSView *myview = [Fl_X::i(win)->xid contentView]; NSEvent *theEvent = [NSApp currentEvent]; |
