X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/43790a0d0386ba63c967545cea7487df2db6e966..a2fe01c96d43777db58041ec470e8aaa27f1e3b2:/src/mac/carbon/app.cpp diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index dd66fb10e4..f610756a2a 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -304,11 +304,37 @@ void wxApp::MacNewFile() void wxApp::MacReopenApp() { - // eventually check for open docs, if none, call MacNewFile - wxTopLevelWindowMac* topLevelWindow = wxDynamicCast(GetTopWindow(), wxTopLevelWindowMac); - - if (topLevelWindow && topLevelWindow->IsIconized()) - topLevelWindow->Iconize(false); + // HIG says : + // if there is no open window -> create a new one + // if all windows are hidden -> show the first + // if some windows are not hidden -> do nothing + + wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); + if ( node == NULL ) + { + MacNewFile() ; + } + else + { + wxTopLevelWindow* firstIconized = NULL ; + while (node) + { + wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData(); + if ( win->IsIconized() == false ) + { + firstIconized = NULL ; + break ; + } + else + { + if ( firstIconized == NULL ) + firstIconized = win ; + } + node = node->GetNext(); + } + if ( firstIconized ) + firstIconized->Iconize( false ) ; + } } //---------------------------------------------------------------------- @@ -340,11 +366,7 @@ static const EventTypeSpec eventList[] = static pascal OSStatus wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; - EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; - wxTheApp->MacSetCurrentEvent( event , handler ) ; - +{ wxMacCarbonEvent cEvent( event ) ; MenuRef menuRef = cEvent.GetParameter(kEventParamDirectObject) ; wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ; @@ -390,8 +412,6 @@ wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *d } } - wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; - return eventNotHandledErr; } @@ -476,6 +496,10 @@ static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef hand pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { + EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; + EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; + wxTheApp->MacSetCurrentEvent( event , handler ) ; + OSStatus result = eventNotHandledErr ; switch( GetEventClass( event ) ) { @@ -502,6 +526,8 @@ pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef eve break ; } + wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; + return result ; } @@ -604,6 +630,20 @@ bool wxApp::Initialize(int& argc, wxChar **argv) 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() ;