X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/172da31f537534fd531f05abede196aefa60d6b7..888dde65f43d5f57e8fb2028b27191cca1741403:/src/mac/carbon/mimetmac.cpp?ds=sidebyside diff --git a/src/mac/carbon/mimetmac.cpp b/src/mac/carbon/mimetmac.cpp index 67d3371823..ab3508000b 100644 --- a/src/mac/carbon/mimetmac.cpp +++ b/src/mac/carbon/mimetmac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: mac/mimetype.cpp +// Name: src/mac/carbon/mimetype.cpp // Purpose: Mac Carbon implementation for wx MIME-related classes // Author: Ryan Norton // Modified by: @@ -27,27 +27,27 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/string.h" - - #if wxUSE_GUI - #include "wx/icon.h" - #endif -#endif +#if wxUSE_MIMETYPE +#include "wx/mac/mimetype.h" -#if wxUSE_MIMETYPE +#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/dynarray.h" #include "wx/confbase.h" -#include "wx/mac/mimetype.h" #include "wx/mac/private.h" // other standard headers @@ -55,9 +55,10 @@ #ifndef __DARWIN__ #include + #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 @@ -414,7 +414,7 @@ wxString wxFileTypeImpl::GetCommand(const wxString& verb) const m_lIndex, &entry); wxString sCurrentExtension = wxMacMakeStringFromPascal(entry.extension); - sCurrentExtension = sCurrentExtension.Right(sCurrentExtension.Length()-1 ); + sCurrentExtension = sCurrentExtension.Right(sCurrentExtension.length()-1 ); //type, creator, ext, roles, outapp (FSRef), outappurl CFURLRef cfurlAppPath; @@ -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") ); @@ -546,7 +479,7 @@ bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) //entry has period in it wxString sCurrentExtension = wxMacMakeStringFromPascal( entry.extension ); - extensions.Add( sCurrentExtension.Right( sCurrentExtension.Length() - 1 ) ); + extensions.Add( sCurrentExtension.Right( sCurrentExtension.length() - 1 ) ); return true; } @@ -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; @@ -716,7 +649,7 @@ wxFileType* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e) if (status == noErr) { wxString sCurrentExtension = wxMacMakeStringFromPascal(entry.extension); - if ( sCurrentExtension.Right(sCurrentExtension.Length() - 1) == e ) // entry has period in it + if ( sCurrentExtension.Right(sCurrentExtension.length() - 1) == e ) // entry has period in it { wxFileType* pFileType = new wxFileType(); pFileType->m_impl->Init((wxMimeTypesManagerImpl*)this, pos); @@ -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 @@ -1311,7 +1245,6 @@ private: // ---------------------------------------------------------------------------- #define wxCFDATA_RELEASEBUFFER 1 -#define wxCFDATA_RETAINBUFFER 0 class wxCFData { @@ -1591,7 +1524,7 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) //'*' for unrestricted if (ftInfo.GetExtensionsCount() != 0) { - for (size_t iExtension = 0; iExtension < (size_t)ftInfo.GetExtensionsCount(); ++iExtension) + for (size_t iExtension = 0; iExtension < ftInfo.GetExtensionsCount(); ++iExtension) { cfaExtensions.Add( wxCFString( asExtensions[iExtension] ) ); } @@ -1679,10 +1612,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 +1625,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) { @@ -1749,7 +1690,7 @@ wxFileType* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) wxMacStringToPascal(ftInfo.GetDescription(), psDescription); Str255 psPostCreatorName; - wxMacStringToPascal(wxT(""), psPostCreatorName); + wxMacStringToPascal(wxEmptyString, psPostCreatorName); //add the entry to the database ICMapEntry entry; @@ -1979,10 +1920,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