Example #1
0
// Look up all extensions and mime types associated with a UTI
void wxMimeTypesManagerImpl::LoadTypeDataForUti(const wxString& uti)
{
    // Keys in to the UTI declaration plist
    const static wxCFStringRef tagsKey( "UTTypeTagSpecification" );
    const static wxCFStringRef extKey( "public.filename-extension" );
    const static wxCFStringRef mimeKey( "public.mime-type" );

    // Get the UTI as a CFString
    wxCFStringRef utiRef( uti );

    // Get a copy of the UTI declaration
    wxCFRef< CFDictionaryRef > utiDecl;
    utiDecl = wxCFRef< CFDictionaryRef >( UTTypeCopyDeclaration( utiRef ) );

    if( !utiDecl )
        return;

    // Get the tags spec (the section of a UTI declaration containing mappings to other type systems)
    CFTypeRef tagsData = CFDictionaryGetValue( utiDecl, tagsKey );

    if( CFGetTypeID( tagsData ) != CFDictionaryGetTypeID() )
        return;

    CFDictionaryRef tags = reinterpret_cast< CFDictionaryRef >( tagsData );

    // Read tags for extensions and mime types
    m_utiMap[ uti ].extensions = ReadStringListFromCFDict( tags, extKey );
    m_utiMap[ uti ].mimeTypes = ReadStringListFromCFDict( tags, mimeKey );
}
void ImageTargetFileQuartz::registerSelf()
{
	const int32_t PRIORITY = 2;
	
	ImageIoRegistrar::TargetCreationFunc func = ImageTargetFileQuartz::createRef;
	
	::CFArrayRef destTypes = ::CGImageDestinationCopyTypeIdentifiers();
	::CFIndex typeCount = ::CFArrayGetCount( destTypes );
	for( ::CFIndex dt = 0; dt < typeCount; ++dt ) {
		::CFStringRef uti = (::CFStringRef)::CFArrayGetValueAtIndex( destTypes, dt );
		if( ! uti )
			continue;
		std::string utiStr = cocoa::convertCfString( uti );
			

		::CFDictionaryRef dict = (CFDictionaryRef)UTTypeCopyDeclaration( uti );
		if( dict ) {
			::CFDictionaryRef tagSpecDict = (CFDictionaryRef)::CFDictionaryGetValue( dict, kUTTypeTagSpecificationKey );
			if( tagSpecDict ) {
				::CFTypeRef extensions = (CFTypeRef)::CFDictionaryGetValue( tagSpecDict, kUTTagClassFilenameExtension );
				if( extensions ) {
					::CFTypeID type = ::CFGetTypeID( extensions );
					if( type == ::CFStringGetTypeID() ) {		// single extension
						ImageIoRegistrar::registerTargetType( cocoa::convertCfString( (CFStringRef)extensions ), func, PRIORITY, utiStr );
					}
					else if( type == ::CFArrayGetTypeID() ) {	// array of extensions
						::CFArrayRef extensionsArr = ::CFArrayRef( extensions );
						CFIndex extCount = ::CFArrayGetCount( extensionsArr );
						for( CFIndex ext = 0; ext < extCount; ++ext ) {
							ImageIoRegistrar::registerTargetType( cocoa::convertCfString( (CFStringRef)::CFArrayGetValueAtIndex( extensionsArr, ext ) ), func, PRIORITY, utiStr );						
						}
					}			
				}
			}
			
			::CFRelease( dict );
		}
	}
	
	::CFRelease( destTypes );
}
///////////////////////////////////////////////////////////////////////////////
// Registrar
void ImageSourceFileQuartz::registerSelf()
{
	static const int32_t SOURCE_PRIORITY = 2;
	
	ImageIoRegistrar::SourceCreationFunc sourceFunc = ImageSourceFileQuartz::createRef;
	
	CFArrayRef sourceTypes = ::CGImageSourceCopyTypeIdentifiers();
	CFIndex sourceCount = ::CFArrayGetCount( sourceTypes );
	for( CFIndex st = 0; st < sourceCount; ++st ) {
		::CFStringRef uti = (::CFStringRef)::CFArrayGetValueAtIndex( sourceTypes, st );
		if( ! uti )
			continue;
		::CFDictionaryRef dict = (CFDictionaryRef)UTTypeCopyDeclaration( uti );
		if( dict ) {
			::CFDictionaryRef tagSpecDict = (CFDictionaryRef)::CFDictionaryGetValue( dict, kUTTypeTagSpecificationKey );
			if( tagSpecDict ) {
				::CFTypeRef extensions = (CFTypeRef)::CFDictionaryGetValue( tagSpecDict, kUTTagClassFilenameExtension );
				if( extensions ) {
					::CFTypeID type = ::CFGetTypeID( extensions );
					if( type == ::CFStringGetTypeID() ) {		// single extension
						ImageIoRegistrar::registerSourceType( cocoa::convertCfString( (CFStringRef)extensions ), sourceFunc, SOURCE_PRIORITY );
					}
					else if( type == ::CFArrayGetTypeID() ) {	// array of extensions
						::CFArrayRef extensionsArr = ::CFArrayRef( extensions );
						CFIndex extCount = ::CFArrayGetCount( extensionsArr );
						for( CFIndex ext = 0; ext < extCount; ++ext ) {
							ImageIoRegistrar::registerSourceType( cocoa::convertCfString( (CFStringRef)::CFArrayGetValueAtIndex( extensionsArr, ext ) ), sourceFunc, SOURCE_PRIORITY );
						}
					}			
				}
			}
			
			::CFRelease( dict );
		}
	}
	
	::CFRelease( sourceTypes );
	
	ImageIoRegistrar::registerSourceGeneric( ImageSourceFileQuartz::createRef, SOURCE_PRIORITY );
}