+#if defined(WXMAKINGDLL) && defined(__DARWIN__)
+ // close shared library resources from here since we don't have
+ // __wxterminate in Mach-O shared libraries
+ wxStAppResource::CloseSharedLibraryResource();
+#endif
+
+ UMACleanupToolbox() ;
+ if (s_macCursorRgn) {
+ ::DisposeRgn((RgnHandle)s_macCursorRgn);
+ }
+
+ #if 0
+ TerminateAE() ;
+ #endif
+}
+
+//----------------------------------------------------------------------
+// wxEntry
+//----------------------------------------------------------------------
+
+// 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);
+
+ // 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");
+
+ wxLogDebug( theResPath );
+
+ theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
+ if (theErr != noErr) {
+ // try in current directory (using name only)
+ theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
+ }
+
+ // free duplicated resource file path
+ free(theResPath);
+
+ // open the resource file
+ if (theErr == noErr) {
+ theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
+ &gSharedLibraryResource);
+ }
+ }
+ }
+#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__)
+
+// for shared libraries we have to manually get the correct resource
+// ref num upon initializing and releasing when terminating, therefore
+// the __wxinitialize and __wxterminate must be used
+
+extern "C" {
+ void __sinit(void); /* (generated by linker) */
+ pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
+ pascal void __terminate(void);
+}
+
+pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
+{
+ wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
+ return __initialize( theInitBlock ) ;
+}
+
+pascal void __wxterminate(void)
+{
+ wxStAppResource::CloseSharedLibraryResource() ;
+ __terminate() ;
+}
+
+#endif /* WXMAKINGDLL && !__DARWIN__ */
+
+int WXDLLEXPORT wxEntryStart( int argc, char *argv[] )
+{
+ return wxApp::Initialize();
+}
+
+int WXDLLEXPORT wxEntryInitGui()
+{
+ return wxTheApp->OnInitGui();
+}