From 632e5093093c6bcc8f791001e8d93436e712c1aa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2012 20:29:35 +0000 Subject: [PATCH] Improve check for OS X version in Cocoa wxFileDialog implementation. A library using wxWidgets linked with 10.6 SDK might be loaded into an application loading 10.5 version of AppKit in which case 10.6-specific functions shouldn't be used. Check for the AppKit version effectively in use instead of just checking for the system version. Closes #13831. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/filedlg.mm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index e026bc744e..0ab62f5bfa 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -38,6 +38,8 @@ #include "wx/osx/private.h" #include "wx/sysopt.h" +#include + // ============================================================================ // implementation // ============================================================================ @@ -49,6 +51,34 @@ // 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"); + } + if (version == -1) + { + return false; + } + 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]; @@ -586,7 +616,7 @@ int wxFileDialog::ShowModal() [oPanel setAllowsMultipleSelection: (HasFlag(wxFD_MULTIPLE) ? YES : NO )]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 - if ( UMAGetSystemVersion() >= 0x1060 ) + if ( UMAGetSystemVersion() >= 0x1060 && HasAppKit_10_6() ) { [oPanel setAllowedFileTypes: (m_delegate == nil ? types : nil)]; if ( !m_dir.IsEmpty() ) -- 2.45.2