bool wxApp::Initialize(int& argc, wxChar **argv) { // Mac-specific #if wxDEBUG_LEVEL && wxOSX_USE_COCOA_OR_CARBON InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); #endif /* Cocoa supports -Key value options which set the user defaults key "Key" to the value "value" Some of them are very handy for debugging like -NSShowAllViews YES. Cocoa picks these up from the real argv so our removal of them from the wx copy of it does not affect Cocoa's ability to see them. We basically just assume that any "-NS" option and its following argument needs to be removed from argv. We hope that user code does not expect to see -NS options and indeed it's probably a safe bet since most user code accepting options is probably using the double-dash GNU-style syntax. */ for(int i=1; i < argc; ++i) { static const wxChar *ARG_NS = wxT("-NS"); if( wxStrncmp(argv[i], ARG_NS, wxStrlen(ARG_NS)) == 0 ) { // Only eat this option if it has an argument if( (i + 1) < argc ) { memmove(argv + i, argv + i + 2, (argc-i-1)*sizeof(wxChar*)); argc -= 2; // drop back one position so the next run through the loop // reprocesses the argument at our current index. --i; } } } if ( !wxAppBase::Initialize(argc, argv) ) return false; #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif // these might be the startup dirs, set them to the 'usual' dir containing the app bundle wxString startupCwd = wxGetCwd() ; if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") ) { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ; CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ; CFRelease( url ) ; CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ; CFRelease( urlParent ) ; wxString cwd = wxCFStringRef(path).AsString(wxLocale::GetSystemEncoding()); wxSetWorkingDirectory( cwd ) ; } return true; }
bool wxApp::Initialize(int& argc, wxChar **argv) { // Mac-specific #if wxDEBUG_LEVEL && wxOSX_USE_COCOA_OR_CARBON InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); #endif // Mac OS X passes a process serial number command line argument when // the application is launched from the Finder. This argument must be // removed from the command line arguments before being handled by the // application (otherwise applications would need to handle it) if ( argc > 1 ) { static const wxChar *ARG_PSN = wxT("-psn_"); if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 ) { // remove this argument --argc; memmove(argv + 1, argv + 2, argc * sizeof(char *)); } } if ( !wxAppBase::Initialize(argc, argv) ) return false; #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif // these might be the startup dirs, set them to the 'usual' dir containing the app bundle wxString startupCwd = wxGetCwd() ; if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") ) { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ; CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ; CFRelease( url ) ; CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ; CFRelease( urlParent ) ; wxString cwd = wxCFStringRef(path).AsString(wxLocale::GetSystemEncoding()); wxSetWorkingDirectory( cwd ) ; } return true; }
bool wxApp::Initialize(int& argc, wxChar **argv) { // Mac-specific #if __WXDEBUG__ InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); #endif UMAInitToolbox( 4, sm_isEmbedded ) ; SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; #ifndef __DARWIN__ # if __option(profile) ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ; # endif #endif #ifndef __DARWIN__ // now avoid exceptions thrown for new (bad_alloc) // FIXME CS for some changes outside wxMac does not compile anymore #if 0 std::__throws_bad_alloc = 0 ; #endif #endif s_macCursorRgn = ::NewRgn() ; // Mac OS X passes a process serial number command line argument when // the application is launched from the Finder. This argument must be // removed from the command line arguments before being handled by the // application (otherwise applications would need to handle it) if ( argc > 1 ) { static const wxChar *ARG_PSN = _T("-psn_"); if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 ) { // remove this argument --argc; memmove(argv + 1, argv + 2, argc * sizeof(char *)); } } if ( !wxAppBase::Initialize(argc, argv) ) return false; #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif #if TARGET_API_MAC_OSX // these might be the startup dirs, set them to the 'usual' dir containing the app bundle wxString startupCwd = wxGetCwd() ; if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") ) { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ; CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ; CFRelease( url ) ; CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ; CFRelease( urlParent ) ; wxString cwd = wxMacCFStringHolder(path).AsString(wxLocale::GetSystemEncoding()); wxSetWorkingDirectory( cwd ) ; } #endif wxMacCreateNotifierTable() ; #ifdef __WXMAC_OSX__ /* connect posted events to common-mode run loop so that wxPostEvent events are handled even while we're in the menu or on a scrollbar */ CFRunLoopSourceContext event_posted_context = {0}; event_posted_context.perform = macPostedEventCallback; m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context); CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); #endif UMAShowArrowCursor() ; return true; }