X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad9835c97c10c0d7de345e3a7a7c0fc2776eb2cb..1f1d2182ffe4feb82a1e674266f47d172ed3cb3c:/src/mac/carbon/mimetmac.cpp?ds=sidebyside diff --git a/src/mac/carbon/mimetmac.cpp b/src/mac/carbon/mimetmac.cpp index f0bc491790..5f1593ea05 100644 --- a/src/mac/carbon/mimetmac.cpp +++ b/src/mac/carbon/mimetmac.cpp @@ -32,21 +32,22 @@ #if wxUSE_MIMETYPE +#include "wx/mac/mimetype.h" + #ifndef WX_PRECOMP #include "wx/dynarray.h" #include "wx/string.h" + #include "wx/intl.h" + #include "wx/log.h" #if wxUSE_GUI #include "wx/icon.h" #endif #endif -#include "wx/log.h" #include "wx/file.h" -#include "wx/intl.h" #include "wx/confbase.h" -#include "wx/mac/mimetype.h" #include "wx/mac/private.h" // other standard headers @@ -57,7 +58,7 @@ #include #endif - +#ifndef __LP64__ // START CODE SAMPLE FROM TECHNOTE 1002 (http://developer.apple.com/technotes/tn/tn1002.html) // IsRemoteVolume can be used to find out if the @@ -319,7 +320,7 @@ pascal OSErr FSpGetFullPath( const FSSpec *spec, return result; } - +#endif // LP64 // // On the mac there are two ways to open a file - one is through apple events and the // finder, another is through mime types. @@ -340,22 +341,22 @@ pascal OSErr FSpGetFullPath( const FSSpec *spec, // // debug helper -inline void wxLogMimeDebug(const wxChar* szMsg, OSStatus status) +inline void wxLogMimeDebug(const wxChar* WXUNUSED_UNLESS_DEBUG(szMsg), OSStatus WXUNUSED_UNLESS_DEBUG(status)) { wxLogDebug(wxString::Format(wxT("%s LINE:%i OSERROR:%i"), szMsg, __LINE__, (int)status)); } // in case we're compiling in non-GUI mode -class WXDLLEXPORT wxIcon; +class WXDLLIMPEXP_FWD_CORE wxIcon; -bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt) +bool wxFileTypeImpl::SetCommand(const wxString& WXUNUSED(cmd), const wxString& WXUNUSED(verb), bool WXUNUSED(overwriteprompt)) { wxASSERT_MSG( m_manager != NULL , wxT("Bad wxFileType") ); return false; } -bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon, int index) +bool wxFileTypeImpl::SetDefaultIcon(const wxString& WXUNUSED(strIcon), int WXUNUSED(index)) { wxASSERT_MSG( m_manager != NULL , wxT("Bad wxFileType") ); @@ -397,9 +398,8 @@ wxFileTypeImpl::GetPrintCommand( // we need to go straight to launch services // -#if defined(__DARWIN__) - //on darwin, use launch services + #include wxString wxFileTypeImpl::GetCommand(const wxString& verb) const @@ -420,7 +420,7 @@ wxString wxFileTypeImpl::GetCommand(const wxString& verb) const CFURLRef cfurlAppPath; OSStatus status = LSGetApplicationForInfo( kLSUnknownType, kLSUnknownCreator, - wxMacCFStringHolder(sCurrentExtension, wxLocale::GetSystemEncoding()), + wxCFStringRef(sCurrentExtension, wxLocale::GetSystemEncoding()), kLSRolesAll, NULL, &cfurlAppPath ); @@ -438,7 +438,7 @@ wxString wxFileTypeImpl::GetCommand(const wxString& verb) const resultStr = wxString(wxT("'")) - + wxMacCFStringHolder(cfsUnixPath).AsString(wxLocale::GetSystemEncoding()) + + wxCFStringRef(cfsUnixPath).AsString(wxLocale::GetSystemEncoding()) + wxString(wxT("'")); return resultStr; @@ -456,73 +456,6 @@ wxString wxFileTypeImpl::GetCommand(const wxString& verb) const return wxEmptyString; } -#else //carbon/classic implementation - -wxString wxFileTypeImpl::GetCommand(const wxString& verb) const -{ - wxASSERT_MSG( m_manager != NULL , wxT("Bad wxFileType") ); - - if (verb == wxT("open")) - { - ICMapEntry entry; - ICGetMapEntry( (ICInstance) m_manager->m_hIC, - (Handle) m_manager->m_hDatabase, - m_lIndex, &entry); - - //The entry in the mimetype database only contains the app - //that's registered - it may not exist... we need to remap the creator - //type and find the right application - - // THIS IS REALLY COMPLICATED :\. - // There are a lot of conversions going on here. - Str255 outName; - FSSpec outSpec; - OSErr err = FindApplication( entry.fileCreator, false, outName, &outSpec ); - if (err != noErr) - return wxEmptyString; - - Handle outPathHandle; - short outPathSize; - err = FSpGetFullPath( &outSpec, &outPathSize, &outPathHandle ); - if (err == noErr) - { - char* szPath = *outPathHandle; - wxString sClassicPath(szPath, wxConvLocal, outPathSize); - -#if defined(__DARWIN__) - // Classic Path --> Unix (OSX) Path - CFURLRef finalURL = CFURLCreateWithFileSystemPath( - kCFAllocatorDefault, - wxMacCFStringHolder(sClassicPath, wxLocale::GetSystemEncoding()), - kCFURLHFSPathStyle, - false ); //false == not a directory - - //clean up memory from the classic path handle - DisposeHandle( outPathHandle ); - - if (finalURL) - { - CFStringRef cfsUnixPath = CFURLCopyFileSystemPath(finalURL, kCFURLPOSIXPathStyle); - CFRelease(finalURL); - - // PHEW! Success! - if (cfsUnixPath) - return wxMacCFStringHolder(cfsUnixPath).AsString(wxLocale::GetSystemEncoding()); - } -#else //classic HFS path acceptable - return sClassicPath; -#endif - } - else - { - wxLogMimeDebug(wxT("FSpGetFullPath failed."), (OSStatus)err); - } - } - - return wxEmptyString; -} -#endif //!DARWIN - bool wxFileTypeImpl::GetDescription(wxString *desc) const { wxASSERT_MSG( m_manager != NULL , wxT("Bad wxFileType") ); @@ -606,7 +539,7 @@ size_t wxFileTypeImpl::GetAllCommands(wxArrayString * verbs, return ulCount; } -void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& extraDir) +void wxMimeTypesManagerImpl::Initialize(int WXUNUSED(mailcapStyles), const wxString& WXUNUSED(extraDir)) { wxASSERT_MSG(m_hIC == NULL, wxT("Already initialized wxMimeTypesManager!")); @@ -629,7 +562,7 @@ void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& extra if (status != noErr) { wxLogDebug(wxT("Could not initialize wxMimeTypesManager!")); - wxASSERT( false ); + wxFAIL; m_hIC = NULL; return; @@ -788,7 +721,9 @@ pascal OSStatus MoreProcGetProcessTypeSignature( infoRec.processInfoLength = sizeof(ProcessInfoRec); infoRec.processName = NULL; +#ifndef __LP64__ infoRec.processAppSpec = NULL; +#endif if ( pPSN == NULL ) { @@ -818,7 +753,6 @@ pascal OSStatus MoreProcGetProcessTypeSignature( // #include "wx/mac/corefoundation/cfstring.h" -#include "wx/intl.h" //wxLocale for wxCFString #define wxCF_RELEASE true #define wxCF_RETAIN false @@ -830,11 +764,9 @@ pascal OSStatus MoreProcGetProcessTypeSignature( class wxCFDictionary { public: - wxCFDictionary(CFTypeRef ref, bool bRetain = wxCF_RELEASE) + wxCFDictionary(CFTypeRef ref) { m_cfmdRef = (CFMutableDictionaryRef) ref; - if (bRetain == wxCF_RETAIN && ref) - CFRetain(ref); } wxCFDictionary(CFIndex cfiSize = 0) @@ -961,8 +893,8 @@ public: for (CFIndex i = 0; i < cfiCount; ++i) { - wxString sKey = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID(pKeys[i]))).AsString(); - wxString sValue = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID(pValues[i]))).AsString(); + wxString sKey = wxCFStringRef(CFCopyTypeIDDescription(CFGetTypeID(pKeys[i]))).AsString(); + wxString sValue = wxCFStringRef(CFCopyTypeIDDescription(CFGetTypeID(pValues[i]))).AsString(); sMessage << wxString::Format(wxT("[{#%d} Key : %s]"), (int) i, @@ -987,7 +919,7 @@ public: { for (CFIndex i = 0; i < CFArrayGetCount(cfaRef); ++i) { - wxString sValue = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID( + wxString sValue = wxCFStringRef(CFCopyTypeIDDescription(CFGetTypeID( CFArrayGetValueAtIndex(cfaRef, i) ))).AsString(); @@ -1005,7 +937,7 @@ public: if (sValue == wxT("CFString")) { - sMessage << wxMacCFStringHolder((CFStringRef)cfRef, false).AsString(); + sMessage << wxCFStringRef(wxCFRetain((CFStringRef)cfRef)).AsString(); } else if (sValue == wxT("CFNumber")) { @@ -1027,7 +959,7 @@ public: } else if (sValue == wxT("CFURL")) { - sMessage << wxMacCFStringHolder(CFURLCopyPath((CFURLRef) cfRef)).AsString(); + sMessage << wxCFStringRef(CFURLCopyPath((CFURLRef) cfRef)).AsString(); } else { @@ -1058,7 +990,7 @@ public: if (cfsError) { if (pErrorMsg) - *pErrorMsg = wxMacCFStringHolder(cfsError).AsString(); + *pErrorMsg = wxCFStringRef(cfsError).AsString(); else CFRelease(cfsError); } @@ -1077,11 +1009,9 @@ private: class wxCFArray { public: - wxCFArray(CFTypeRef ref, bool bRetain = wxCF_RELEASE) + wxCFArray(CFTypeRef ref) { m_cfmaRef = (CFMutableArrayRef)ref; - if (bRetain == wxCF_RETAIN && ref) - CFRetain(ref); } wxCFArray(CFIndex cfiSize = 0) : m_cfmaRef(NULL) @@ -1186,37 +1116,6 @@ private: CFMutableArrayRef m_cfmaRef; }; -// ---------------------------------------------------------------------------- -// wxCFString -// ---------------------------------------------------------------------------- - -class wxCFString -{ -public: - wxCFString(CFTypeRef ref, bool bRetain = wxCF_RELEASE) : m_Holder((CFStringRef)ref, bRetain == wxCF_RELEASE) - {} - - wxCFString(const wxChar* szString) : m_Holder(wxString(szString), wxLocale::GetSystemEncoding()) - {} - - wxCFString(const wxString& sString) : m_Holder(sString, wxLocale::GetSystemEncoding()) - {} - - virtual ~wxCFString() {} - - operator CFTypeRef() const - { return (CFTypeRef) ((CFStringRef) m_Holder); } - - bool IsOk() - { return ((CFTypeRef)(*this)) != NULL; } - - wxString BuildWXString() - { return m_Holder.AsString(); } - -private: - wxMacCFStringHolder m_Holder; -}; - // ---------------------------------------------------------------------------- // wxCFNumber // ---------------------------------------------------------------------------- @@ -1229,10 +1128,8 @@ public: m_cfnRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &nValue); } - wxCFNumber(CFTypeRef ref, bool bRetain = wxCF_RELEASE) : m_cfnRef((CFNumberRef)ref) + wxCFNumber(CFTypeRef ref) : m_cfnRef((CFNumberRef)ref) { - if (bRetain == wxCF_RETAIN && ref) - CFRetain(ref); } virtual ~wxCFNumber() @@ -1266,18 +1163,16 @@ private: class wxCFURL { public: - wxCFURL(CFTypeRef ref = NULL, bool bRetain = wxCF_RELEASE) : m_cfurlRef((CFURLRef)ref) + wxCFURL(CFTypeRef ref = NULL) : m_cfurlRef((CFURLRef)ref) { - if (bRetain == wxCF_RETAIN && ref) - CFRetain(ref); } - wxCFURL(const wxCFString& URLString, CFTypeRef BaseURL = NULL) + wxCFURL(const wxCFStringRef& URLString, CFTypeRef BaseURL = NULL) { Create(URLString, BaseURL); } - void Create(const wxCFString& URLString, CFTypeRef BaseURL = NULL) + void Create(const wxCFStringRef& URLString, CFTypeRef BaseURL = NULL) { m_cfurlRef = CFURLCreateWithString( kCFAllocatorDefault, @@ -1293,7 +1188,7 @@ public: wxString BuildWXString() { - return wxCFString(CFURLCopyPath(m_cfurlRef)).BuildWXString(); + return wxCFStringRef(CFURLCopyPath(m_cfurlRef)).AsString(); } operator CFTypeRef() const @@ -1311,15 +1206,12 @@ private: // ---------------------------------------------------------------------------- #define wxCFDATA_RELEASEBUFFER 1 -#define wxCFDATA_RETAINBUFFER 0 class wxCFData { public: - wxCFData(CFTypeRef ref, bool bRetain = wxCF_RELEASE) : m_cfdaRef((CFDataRef)ref) + wxCFData(CFTypeRef ref) : m_cfdaRef((CFDataRef)ref) { - if (bRetain == wxCF_RETAIN && ref) - CFRetain(ref); } wxCFData(const UInt8* pBytes, CFIndex len, bool bKeep = wxCFDATA_RELEASEBUFFER) @@ -1520,7 +1412,7 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) { cfdInfo.MakeMutable( cfdInfo.GetCount() + 1 ); - wxCFArray cfaDocTypes( cfdInfo[ wxCFString(wxT("CFBundleDocumentTypes")) ], wxCF_RETAIN ); + wxCFArray cfaDocTypes( wxCFRetain( cfdInfo[ wxCFStringRef(wxT("CFBundleDocumentTypes")) ] ) ); bool bAddDocTypesArrayToDictionary = !cfaDocTypes.IsOk(); if (bAddDocTypesArrayToDictionary) @@ -1534,12 +1426,11 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) CFIndex i; for (i = 0; i < cfaDocTypes.GetCount(); ++i) { - wxCFDictionary cfdDocTypeEntry( cfaDocTypes[i], wxCF_RETAIN ); + wxCFDictionary cfdDocTypeEntry( wxCFRetain( cfaDocTypes[i] ) ); // A lot of apps don't support MIME types for some reason // so we go by extensions only - wxCFArray cfaExtensions( cfdDocTypeEntry[ wxCFString(wxT("CFBundleTypeExtensions")) ], - wxCF_RETAIN ); + wxCFArray cfaExtensions( wxCFRetain( cfdDocTypeEntry[ wxCFStringRef(wxT("CFBundleTypeExtensions")) ] ) ); if (!cfaExtensions.IsOk()) continue; @@ -1549,7 +1440,7 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) for (size_t iWXExt = 0; iWXExt < asExtensions.GetCount(); ++iWXExt) { if (asExtensions[iWXExt] == - wxCFString(cfaExtensions[iExt], wxCF_RETAIN).BuildWXString()) + wxCFStringRef( wxCFRetain( (CFStringRef) cfaExtensions[iExt] ) ).AsString()) { bEntryFound = true; dwFoundIndex = iWXExt; @@ -1570,14 +1461,14 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) if (!ftInfo.GetDescription().empty()) { - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeName")), - wxCFString(ftInfo.GetDescription()) ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeName")), + wxCFStringRef(ftInfo.GetDescription()) ); } if (!ftInfo.GetIconFile().empty()) { - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeIconFile")), - wxCFString(ftInfo.GetIconFile()) ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeIconFile")), + wxCFStringRef(ftInfo.GetIconFile()) ); } wxCFArray cfaOSTypes; @@ -1585,33 +1476,33 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) wxCFArray cfaMimeTypes; //OSTypes is a cfarray of four-char-codes - '****' for unrestricted - cfaOSTypes.Add( wxCFString(wxT("****")) ); - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeOSTypes")), cfaOSTypes ); + cfaOSTypes.Add( wxCFStringRef(wxT("****")) ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeOSTypes")), cfaOSTypes ); //'*' for unrestricted if (ftInfo.GetExtensionsCount() != 0) { for (size_t iExtension = 0; iExtension < ftInfo.GetExtensionsCount(); ++iExtension) { - cfaExtensions.Add( wxCFString( asExtensions[iExtension] ) ); + cfaExtensions.Add( wxCFStringRef( asExtensions[iExtension] ) ); } - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeExtensions")), cfaExtensions ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeExtensions")), cfaExtensions ); } if (!ftInfo.GetMimeType().empty()) { - cfaMimeTypes.Add( wxCFString(ftInfo.GetMimeType()) ); - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeMIMETypes")), cfaMimeTypes ); + cfaMimeTypes.Add( wxCFStringRef(ftInfo.GetMimeType()) ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeMIMETypes")), cfaMimeTypes ); } // Editor - can perform all actions // Viewer - all actions except manipulation/saving // None - can perform no actions - cfdNewEntry.Add( wxCFString(wxT("CFBundleTypeRole")), wxCFString(wxT("Editor")) ); + cfdNewEntry.Add( wxCFStringRef(wxT("CFBundleTypeRole")), wxCFStringRef(wxT("Editor")) ); // Is application bundled? - cfdNewEntry.Add( wxCFString(wxT("LSTypeIsPackage")), kCFBooleanTrue ); + cfdNewEntry.Add( wxCFStringRef(wxT("LSTypeIsPackage")), kCFBooleanTrue ); if (bEntryFound) cfaDocTypes.Set(i, cfdNewEntry); @@ -1620,9 +1511,9 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) // set the doc types array in the muted dictionary if (bAddDocTypesArrayToDictionary) - cfdInfo.Add(wxCFString(wxT("CFBundleDocumentTypes")), cfaDocTypes); + cfdInfo.Add(wxCFStringRef(wxT("CFBundleDocumentTypes")), cfaDocTypes); else - cfdInfo.Set(wxCFString(wxT("CFBundleDocumentTypes")), cfaDocTypes); + cfdInfo.Set(wxCFStringRef(wxT("CFBundleDocumentTypes")), cfaDocTypes); cfdInfo.MakeValidXML(); @@ -1679,10 +1570,8 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) wxLogDebug(wxT("No main bundle")); } -#if defined(__DARWIN__) if (!bInfoSuccess) return NULL; -#endif // on mac you have to embed it into the mac's file reference resource ('FREF' I believe) // or, alternately, you could just add an entry to m_hDatabase, but you'd need to get @@ -1694,8 +1583,18 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) if (status == noErr) { Str255 psCreatorName; +#ifndef __LP64__ FSSpec dummySpec; status = FindApplication(creator, false, psCreatorName, &dummySpec); +#else + FSRef fsref; + status = LSFindApplicationForInfo( creator, NULL, NULL, &fsref ,NULL); + HFSUniStr255 name; + status = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, &name, NULL, NULL); + CFStringRef str = FSCreateStringFromHFSUniStr( 0 , &name ); + CFStringGetPascalString(str, psCreatorName, 256, CFStringGetSystemEncoding()); + CFRelease( str ); +#endif if (status == noErr) { @@ -1861,7 +1760,7 @@ wxMimeTypesManagerImpl::Unassociate(wxFileType *pFileType) { cfdInfo.MakeMutable( cfdInfo.GetCount() + 1 ); - wxCFArray cfaDocTypes( cfdInfo[ wxCFString(wxT("CFBundleDocumentTypes")) ], wxCF_RETAIN ); + wxCFArray cfaDocTypes( wxCFRetain( cfdInfo[ wxCFStringRef(wxT("CFBundleDocumentTypes")) ] ) ); if (cfaDocTypes.IsOk()) { @@ -1871,12 +1770,11 @@ wxMimeTypesManagerImpl::Unassociate(wxFileType *pFileType) CFIndex i; for (i = 0; i < cfaDocTypes.GetCount(); ++i) { - wxCFDictionary cfdDocTypeEntry( cfaDocTypes[i], wxCF_RETAIN ); + wxCFDictionary cfdDocTypeEntry( wxCFRetain( cfaDocTypes[i] ) ); //A lot of apps dont do to mime types for some reason //so we go by extensions only - wxCFArray cfaExtensions( cfdDocTypeEntry[ wxCFString(wxT("CFBundleTypeExtensions")) ], - wxCF_RETAIN ); + wxCFArray cfaExtensions( wxCFRetain( cfdDocTypeEntry[ wxCFStringRef(wxT("CFBundleTypeExtensions")) ]) ); if (!cfaExtensions.IsOk()) continue; @@ -1886,11 +1784,11 @@ wxMimeTypesManagerImpl::Unassociate(wxFileType *pFileType) for (size_t iWXExt = 0; iWXExt < asExtensions.GetCount(); ++iWXExt) { if (asExtensions[iWXExt] == - wxCFString(cfaExtensions[iExt], wxCF_RETAIN).BuildWXString()) + wxCFStringRef( wxCFRetain( (CFStringRef) cfaExtensions[iExt] ) ).AsString()) { bEntryFound = true; cfaDocTypes.Remove(i); - cfdInfo.Set( wxCFString(wxT("CFBundleDocumentTypes")) , cfaDocTypes ); + cfdInfo.Set( wxCFStringRef(wxT("CFBundleDocumentTypes")) , cfaDocTypes ); break; } } //end of wxstring array @@ -1979,10 +1877,8 @@ wxMimeTypesManagerImpl::Unassociate(wxFileType *pFileType) wxLogDebug(wxT("No main bundle")); } -#if defined(__DARWIN__) if (!bInfoSuccess) return false; -#endif // this should be as easy as removing the entry from the database // and then saving the database @@ -2033,7 +1929,7 @@ wxMimeTypesManagerImpl::Unassociate(wxFileType *pFileType) &cfsError); if (cfsError && cfiWritten == 0) { - wxLogDebug(wxCFString(cfsError).BuildWXString()); + wxLogDebug(wxCFStringRef(cfsError).BuildWXString()); wxString sMessage; cfdInfo.PrintOut(sMessage); wxLogDebug(sMessage);