diff options
author | Aaron M. Ucko <ucko@debian.org> | 2013-02-06 22:07:34 -0500 |
---|---|---|
committer | Aaron M. Ucko <ucko@debian.org> | 2013-02-06 22:07:34 -0500 |
commit | 786f49e9d19180e6bf1c7d0fe0d9da89f953a330 (patch) | |
tree | 6ac2189363049445e3ef9cc57a7eaefec13b5438 /src/Fl_cocoa.mm | |
parent | f3358bb14bc1644f895e7f72344c29906c5ac6d1 (diff) |
Imported Upstream version 1.3.2
Diffstat (limited to 'src/Fl_cocoa.mm')
-rw-r--r-- | src/Fl_cocoa.mm | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 0206fcb..a361f29 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1,5 +1,5 @@ // -// "$Id: Fl_cocoa.mm 9688 2012-09-28 08:07:47Z manolo $" +// "$Id: Fl_cocoa.mm 9734 2012-11-30 18:20:36Z manolo $" // // MacOS-Cocoa specific code for the Fast Light Tool Kit (FLTK). // @@ -982,6 +982,7 @@ void fl_open_callback(void (*cb)(const char *)) { <NSWindowDelegate, NSApplicationDelegate> #endif { + BOOL seen_open_file; } - (void)windowDidMove:(NSNotification *)notif; - (void)windowDidResize:(NSNotification *)notif; @@ -1000,6 +1001,7 @@ void fl_open_callback(void (*cb)(const char *)) { - (void)applicationWillUnhide:(NSNotification *)notify; - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client; - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification; @end @implementation FLDelegate - (void)windowDidMove:(NSNotification *)notif @@ -1255,6 +1257,7 @@ void fl_open_callback(void (*cb)(const char *)) { } - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { + seen_open_file = YES; if (open_cb) { fl_lock_function(); (*open_cb)([filename UTF8String]); @@ -1263,6 +1266,12 @@ void fl_open_callback(void (*cb)(const char *)) { } return NO; } +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification +{ + // without this, the opening of the 1st window is delayed by several seconds + // under Mac OS 10.8 when a file is dragged on the application icon + if (fl_mac_os_version >= 100800 && seen_open_file) [[NSApp mainWindow] orderFront:self]; +} @end @implementation FLApplication @@ -1334,9 +1343,10 @@ void fl_open_display() { // only transform the application type for unbundled apps NSBundle *bundle = [NSBundle mainBundle]; if (bundle) { - NSString *exe = [bundle executablePath]; + NSString *exe = [[bundle executablePath] stringByStandardizingPath]; NSString *bpath = [bundle bundlePath]; - if ([bpath isEqualToString:exe]) bundle = nil; + NSString *exe_dir = [exe stringByDeletingLastPathComponent]; + if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) bundle = nil; } if ( !bundle ) @@ -3317,7 +3327,7 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, win = win->window(); } CGFloat epsilon = 0; - if (fl_mac_os_version >= 100600) epsilon = 0.001; + if (fl_mac_os_version >= 100600) epsilon = 0.5; // STR #2887 // The epsilon offset is absolutely necessary under 10.6. Without it, the top pixel row and // left pixel column are not read, and bitmap is read shifted by one pixel in both directions. // Under 10.5, we want no offset. @@ -3326,7 +3336,12 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, } unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel) -// delete[] the returned pointer after use +/* Returns a capture of a rectangle of a mapped window as a pre-multiplied RGBA array of bytes. + Alpha values are always 1 (except for the angles of a window title bar) + so pre-multiplication can be ignored. + *bytesPerPixel is always set to the value 4 upon return. + delete[] the returned pointer after use + */ { NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h); *bytesPerPixel = [bitmap bitsPerPixel]/8; @@ -3371,7 +3386,7 @@ CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, i CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB(); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData); img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut, - bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaLast, + bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast, provider, NULL, false, kCGRenderingIntentDefault); CGColorSpaceRelease(lut); CGDataProviderRelease(provider); @@ -3425,14 +3440,14 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset) Fl::check(); win->make_current(); this->set_current(); // back to the Fl_Paged_Device - int bpp; - // capture the window title bar as an RGBA image - unsigned char *top_image = Fl_X::bitmap_from_window_rect(win, 0, -bt, win->w(), bt, &bpp); - Fl_RGB_Image* rgba = new Fl_RGB_Image(top_image, win->w(), bt, bpp); + // capture the window title bar + CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt); // and print it - rgba->draw(x_offset, y_offset); - delete rgba; - delete[] top_image; + CGRect rect = { { x_offset, y_offset }, { win->w(), bt } }; + Fl_X::q_begin_image(rect, 0, 0, win->w(), bt); + CGContextDrawImage(fl_gc, rect, img); + Fl_X::q_end_image(); + CFRelease(img); this->print_widget(win, x_offset, y_offset + bt); // print the window inner part } @@ -3471,5 +3486,5 @@ static int calc_mac_os_version() { #endif // __APPLE__ // -// End of "$Id: Fl_cocoa.mm 9688 2012-09-28 08:07:47Z manolo $". +// End of "$Id: Fl_cocoa.mm 9734 2012-11-30 18:20:36Z manolo $". // |