-// extern variable for shared library resource id
-// need to be able to find it with NSLookupAndBindSymbol
-short gSharedLibraryResource = kResFileNotOpened ;
-
-#if defined(WXMAKINGDLL) && defined(__DARWIN__)
-CFBundleRef gSharedLibraryBundle = NULL;
-#endif /* WXMAKINGDLL && __DARWIN__ */
-
-wxStAppResource::wxStAppResource()
-{
- m_currentRefNum = CurResFile() ;
- if ( gSharedLibraryResource != kResFileNotOpened )
- {
- UseResFile( gSharedLibraryResource ) ;
- }
-}
-
-wxStAppResource::~wxStAppResource()
-{
- if ( m_currentRefNum != kResFileNotOpened )
- {
- UseResFile( m_currentRefNum ) ;
- }
-}
-
-void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
-{
- gSharedLibraryResource = kResFileNotOpened;
-
-#ifdef WXMAKINGDLL
- if ( initBlock != NULL ) {
- const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
- FSSpec *fileSpec = NULL;
-
- if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
- fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
- }
- else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
- fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
- }
-
- if (fileSpec != NULL) {
- gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
- }
- }
- else {
-#ifdef __DARWIN__
- // Open the shared library resource file if it is not yet open
- NSSymbol theSymbol;
- NSModule theModule;
- const char *theLibPath;
-
- gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
- if (gSharedLibraryBundle != NULL) {
- // wxWindows has been bundled into a framework
- // load the framework resources
-
- gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
- }
- else {
- // wxWindows is a simple dynamic shared library
- // load the resources from the data fork of a separate resource file
- char *theResPath;
- char *theName;
- char *theExt;
- FSRef theResRef;
- OSErr theErr = noErr;
-
- // get the library path
- theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
- theModule = NSModuleForSymbol(theSymbol);
- theLibPath = NSLibraryNameForModule(theModule);
-
- // if we call wxLogDebug from here then, as wxTheApp hasn't been
- // created yet when we're called from wxApp::Initialize(), wxLog
- // is going to create a default stderr-based log target instead of
- // the expected normal GUI one -- don't do it, if we really want
- // to see this message just use fprintf() here
-#if 0
- wxLogDebug( wxT("wxMac library installation name is '%s'"),
- theLibPath );
-#endif
-
- // allocate copy to replace .dylib.* extension with .rsrc
- theResPath = strdup(theLibPath);
- if (theResPath != NULL) {
- theName = strrchr(theResPath, '/');
- if (theName == NULL) {
- // no directory elements in path
- theName = theResPath;
- }
- // find ".dylib" shared library extension
- theExt = strstr(theName, ".dylib");
- // overwrite extension with ".rsrc"
- strcpy(theExt, ".rsrc");
-
-#if 0
- wxLogDebug( wxT("wxMac resources file name is '%s'"),
- theResPath );
-#endif
-
- theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
- if (theErr != noErr) {
- // try in current directory (using name only)
- theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
- }
-
- // open the resource file
- if (theErr == noErr) {
- theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
- &gSharedLibraryResource);
- }
- if (theErr != noErr) {
-#ifdef __WXDEBUG__
- fprintf(stderr,
- wxT("unable to open wxMac resource file '%s'\n"),
- theResPath );
-#endif // __WXDEBUG__
- }
-
- // free duplicated resource file path
- free(theResPath);
- }
- }
-#endif /* __DARWIN__ */
- }
-#endif /* WXMAKINGDLL */
-}
-
-void wxStAppResource::CloseSharedLibraryResource()
-{
-#ifdef WXMAKINGDLL
- // Close the shared library resource file
- if (gSharedLibraryResource != kResFileNotOpened) {
-#ifdef __DARWIN__
- if (gSharedLibraryBundle != NULL) {
- CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
- gSharedLibraryResource);
- gSharedLibraryBundle = NULL;
- }
- else
-#endif /* __DARWIN__ */
- {
- CloseResFile(gSharedLibraryResource);
- }
- gSharedLibraryResource = kResFileNotOpened;
- }
-#endif /* WXMAKINGDLL */
-}
-
-#if defined(WXMAKINGDLL) && !defined(__DARWIN__)