Handle deprecation with Mac OS 10.9 of SetFrontProcess(), GetCurrentProcess(), GetFrontProcess(), SameProcess().

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10288 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2014-09-07 20:30:46 +00:00
parent 2031e30069
commit 3e0bb410f8

View File

@ -1413,29 +1413,36 @@ void fl_open_display() {
while (ign_event); while (ign_event);
// bring the application into foreground without a 'CARB' resource // bring the application into foreground without a 'CARB' resource
Boolean same_psn; bool i_am_in_front;
ProcessSerialNumber cur_psn, front_psn; ProcessSerialNumber cur_psn = { 0, kCurrentProcess };
if ( !GetCurrentProcess( &cur_psn ) && !GetFrontProcess( &front_psn ) && #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
!SameProcess( &front_psn, &cur_psn, &same_psn ) && !same_psn ) { if (fl_mac_os_version >= 100600) {
i_am_in_front = [[NSRunningApplication currentApplication] isActive];
}
else
#endif
{
Boolean same_psn;
ProcessSerialNumber front_psn;
i_am_in_front = (!GetFrontProcess( &front_psn ) &&
!SameProcess( &front_psn, &cur_psn, &same_psn ) && same_psn );
}
if (!i_am_in_front) {
// only transform the application type for unbundled apps // only transform the application type for unbundled apps
NSBundle *bundle = [NSBundle mainBundle]; NSBundle *bundle = [NSBundle mainBundle];
if (bundle) { if (bundle) {
NSString *exe = [[bundle executablePath] stringByStandardizingPath]; NSString *exe = [[bundle executablePath] stringByStandardizingPath];
NSString *bpath = [bundle bundlePath]; NSString *bpath = [bundle bundlePath];
NSString *exe_dir = [exe stringByDeletingLastPathComponent]; NSString *exe_dir = [exe stringByDeletingLastPathComponent];
if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) bundle = nil; if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) bundle = nil;
} }
if ( !bundle ) if ( !bundle ) {
{ TransformProcessType(&cur_psn, kProcessTransformToForegroundApplication); // needs Mac OS 10.3
OSErr err; /* support of Mac OS 10.2 or earlier used this undocumented call instead
err = TransformProcessType(&cur_psn, kProcessTransformToForegroundApplication); // needs Mac OS 10.3 err = CPSEnableForegroundOperation(&cur_psn, 0x03, 0x3C, 0x2C, 0x1103);
/* support of Mac OS 10.2 or earlier used this undocumented call instead */
err = CPSEnableForegroundOperation(&cur_psn, 0x03, 0x3C, 0x2C, 0x1103); [NSApp activateIgnoringOtherApps:YES];
*/
if (err == noErr) {
SetFrontProcess( &cur_psn );
}
} }
} }
if (![NSApp servicesMenu]) createAppleMenu(); if (![NSApp servicesMenu]) createAppleMenu();
@ -2550,8 +2557,7 @@ void Fl_X::make(Fl_Window* w)
[myview registerForDraggedTypes:[NSArray arrayWithObjects:utf8_format, NSFilenamesPboardType, nil]]; [myview registerForDraggedTypes:[NSArray arrayWithObjects:utf8_format, NSFilenamesPboardType, nil]];
if ( ! Fl_X::first->next ) { if ( ! Fl_X::first->next ) {
// if this is the first window, we need to bring the application to the front // if this is the first window, we need to bring the application to the front
ProcessSerialNumber psn = { 0, kCurrentProcess }; [NSApp activateIgnoringOtherApps:YES];
SetFrontProcess( &psn );
} }
if (w->size_range_set) w->size_range_(); if (w->size_range_set) w->size_range_();