X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/906c935a80b10d53cecf57f71ab5f3f4f1d529ec..a51e79e87db3512823258d487849bb7e7947b700:/src/osx/cocoa/filedlg.mm?ds=sidebyside diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index a1c79b7fc5..6e4e5c4f2c 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -34,9 +34,13 @@ #include "wx/filename.h" #include "wx/tokenzr.h" +#include "wx/evtloop.h" #include "wx/osx/private.h" #include "wx/sysopt.h" +#include "wx/testing.h" + +#include // ============================================================================ // implementation @@ -49,6 +53,32 @@ // then the delegate method - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename will have to // be implemented +namespace +{ + +bool HasAppKit_10_6() +{ + // Even if we require 10.6, we might be loaded by an application that + // was linked against 10.5. setAllowedFileTypes will still be ignored + // in this case. From NSSavePanel.h: + // NSOpenPanel: On versions less than 10.6, this property is ignored. + // For applications that link against 10.6 and higher, this property will + // determine which files should be enabled in the open panel. + int32_t version = NSVersionOfLinkTimeLibrary("AppKit"); + if (version == -1) + { + // If we're loaded by an application that doesn't link against AppKit, + // use the runtime version instead. This check will not work for the + // case above. + version = NSVersionOfRunTimeLibrary("AppKit"); + } + + // Notice that this still works correctly even if version is -1. + return version >= 0x40e2400 /* version of 10.6 AppKit */; +} + +} // anonymous namespace + @interface wxOpenPanelDelegate : NSObject wxOSX_10_6_AND_LATER() { wxFileDialog* _dialog; @@ -436,7 +466,7 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow) accView = m_filterPanel->GetHandle(); if( HasFlag(wxFD_OPEN) ) { - if ( UMAGetSystemVersion() < 0x1060 ) + if ( UMAGetSystemVersion() < 0x1060 || !HasAppKit_10_6() ) { wxOpenPanelDelegate* del = [[wxOpenPanelDelegate alloc]init]; [del setFileDialog:this]; @@ -466,6 +496,10 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow) int wxFileDialog::ShowModal() { + WX_TESTING_SHOW_MODAL_HOOK(); + + wxCFEventLoopPauseIdleEvents pause; + wxMacAutoreleasePool autoreleasepool; wxCFStringRef cf( m_message ); @@ -585,20 +619,22 @@ int wxFileDialog::ShowModal() [oPanel setMessage:cf.AsNSString()]; [oPanel setAllowsMultipleSelection: (HasFlag(wxFD_MULTIPLE) ? YES : NO )]; - if ( UMAGetSystemVersion() < 0x1060 ) - { - returnCode = [oPanel runModalForDirectory:m_dir.IsEmpty() ? nil : dir.AsNSString() - file:file.AsNSString() types:(m_delegate == nil ? types : nil)]; - } - else +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + if ( UMAGetSystemVersion() >= 0x1060 && HasAppKit_10_6() ) { [oPanel setAllowedFileTypes: (m_delegate == nil ? types : nil)]; if ( !m_dir.IsEmpty() ) [oPanel setDirectoryURL:[NSURL fileURLWithPath:dir.AsNSString() - isDirectory:YES]]; + isDirectory:YES]]; returnCode = [oPanel runModal]; } - + else +#endif + { + returnCode = [oPanel runModalForDirectory:m_dir.IsEmpty() ? nil : dir.AsNSString() + file:file.AsNSString() types:(m_delegate == nil ? types : nil)]; + } + ModalFinishedCallback(oPanel, returnCode); }