From e9e0826d10ac38ab162c0407ee618d1edf93069d Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 20 Jan 2007 15:28:11 +0000 Subject: Made resource fork on OS X obsolete. We still do add it just in case, but should the data be lost during a copy process through a different file system, the app will still put itself in the foreground if using a GUI (STR #1453) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5627 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_mac.cxx | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index dc3782944..452d98774 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -1264,8 +1264,16 @@ void fl_open_callback(void (*cb)(const char *)) { /** - * initialize the Mac toolboxes and set the default menubar + * initialize the Mac toolboxes, dock status, and set the default menubar */ + +#ifndef MAC_OS_X_VERSION_10_3 +extern "C" { +extern OSErr CPSEnableForegroundOperation(ProcessSerialNumber *psn, UInt32 _arg2, + UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +} +#endif + void fl_open_display() { static char beenHereDoneThat = 0; if ( !beenHereDoneThat ) { @@ -1284,6 +1292,42 @@ void fl_open_display() { ClearMenuBar(); AppendResMenu( GetMenuHandle( 1 ), 'DRVR' ); DrawMenuBar(); + + // bring the application into foreground without a 'CARB' resource + Boolean same_psn; + ProcessSerialNumber cur_psn, front_psn; + if( !GetCurrentProcess( &cur_psn ) && !GetFrontProcess( &front_psn ) && + !SameProcess( &front_psn, &cur_psn, &same_psn ) && !same_psn ) + { + // only transform the application type for unbundled apps + CFBundleRef bundle = CFBundleGetMainBundle(); + if( bundle ) + { + FSRef execFs; + CFURLRef execUrl = CFBundleCopyExecutableURL( bundle ); + CFURLGetFSRef( execUrl, &execFs ); + + FSRef bundleFs; + GetProcessBundleLocation( &cur_psn, &bundleFs ); + + if( !FSCompareFSRefs( &execFs, &bundleFs ) ) + bundle = NULL; + + CFRelease(execUrl); + } + + if( !bundle ) + { +#ifdef MAC_OS_X_VERSION_10_3 + // newer supported API + if( !TransformProcessType( &cur_psn, kProcessTransformToForegroundApplication ) ) +#else + // undocumented API + if( !CPSEnableForegroundOperation( &cur_psn, 0x03, 0x3C, 0x2C, 0x1103 ) ) +#endif + SetFrontProcess( &cur_psn ); + } + } } } -- cgit v1.2.3