X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6239ee05567eac71754f56c2a154222d10b57ff1..8064223b7b1b3657363b7a635c381b9269d95e55:/src/mac/carbon/dataobj.cpp diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index 5273411436..cdec68b05d 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/dataobj.cpp @@ -129,18 +129,10 @@ void wxDataFormat::SetType( wxDataFormatId dataType ) break; case wxDF_BITMAP: -#if wxMAC_USE_CORE_GRAPHICS m_format = (long) CFStringCreateCopy( NULL, CFSTR("public.tiff") ); -#else - m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.apple.pict") ); -#endif break; case wxDF_METAFILE: -#if wxMAC_USE_CORE_GRAPHICS m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.adobe.pdf") ); -#else - m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.apple.pict") ); -#endif break; case wxDF_FILENAME: @@ -155,10 +147,7 @@ void wxDataFormat::SetType( wxDataFormatId dataType ) wxString wxDataFormat::GetId() const { - wxCHECK_MSG( !IsStandard(), wxEmptyString, - wxT("name of predefined format cannot be retrieved") ); - - return m_id; + return wxCFStringRef(wxCFRetain((CFStringRef)m_format)).AsString(); } void wxDataFormat::SetId( NativeFormat format ) @@ -177,7 +166,6 @@ void wxDataFormat::SetId( NativeFormat format ) { m_type = wxDF_TEXT; } -#if wxMAC_USE_CORE_GRAPHICS else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.tiff") ) ) { m_type = wxDF_BITMAP; @@ -186,12 +174,6 @@ void wxDataFormat::SetId( NativeFormat format ) { m_type = wxDF_METAFILE; } -#else - else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("com.apple.pict") ) ) - { - m_type = wxDF_METAFILE; - } -#endif else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.file-url") ) ) { m_type = wxDF_FILENAME; @@ -199,7 +181,7 @@ void wxDataFormat::SetId( NativeFormat format ) else { m_type = wxDF_PRIVATE; - m_id = wxMacCFStringHolder( (CFStringRef) CFRetain((CFStringRef) format )).AsString(); + m_id = wxCFStringRef( (CFStringRef) CFRetain((CFStringRef) format )).AsString(); } } @@ -213,7 +195,7 @@ void wxDataFormat::SetId( const wxString& zId ) m_format = 0; } // since it is private, no need to conform to anything ... - m_format = (long) wxMacCFStringHolder(m_id).Detach(); + m_format = (long) wxCFRetain( (CFStringRef) wxCFStringRef(m_id) ); } bool wxDataFormat::operator==(const wxDataFormat& format) const @@ -438,7 +420,7 @@ bool wxDataObject::GetFromPasteboard( void * pb ) CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); CFRelease( cfString ); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); - wxString path = wxMacCFStringHolder(cfMutableString).AsString(); + wxString path = wxCFStringRef(cfMutableString).AsString(); if (!path.empty()) filenamesPassed += path + wxT("\n"); } @@ -647,12 +629,7 @@ wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap ) if (m_bitmap.Ok()) { -#if wxMAC_USE_CORE_GRAPHICS SetBitmap( rBitmap ); -#else - m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle(); - m_pictCreated = false; -#endif } } @@ -667,51 +644,24 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap ) wxBitmapDataObjectBase::SetBitmap( rBitmap ); if (m_bitmap.Ok()) { -#if wxMAC_USE_CORE_GRAPHICS - CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate(); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - if ( UMAGetSystemVersion() >= 0x1040 ) + CGImageRef cgImageRef = (CGImageRef) m_bitmap.CreateCGImage(); + + CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); + CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL ); + if ( destination ) { - CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); - CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL ); - if ( destination ) - { - CGImageDestinationAddImage( destination, cgImageRef, NULL ); - CGImageDestinationFinalize( destination ); - CFRelease( destination ); - } - m_pictHandle = NewHandle(CFDataGetLength(data)); - if ( m_pictHandle ) - { - memcpy( *(Handle)m_pictHandle, (const char *)CFDataGetBytePtr(data), CFDataGetLength(data) ); - } - CFRelease( data ); + CGImageDestinationAddImage( destination, cgImageRef, NULL ); + CGImageDestinationFinalize( destination ); + CFRelease( destination ); } - else -#endif -#ifndef __LP64__ + m_pictHandle = NewHandle(CFDataGetLength(data)); + if ( m_pictHandle ) { - // export as TIFF - GraphicsExportComponent exporter = 0; - OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &exporter); - if (noErr == err) - { - m_pictHandle = NewHandle(0); - if ( m_pictHandle ) - { - err = GraphicsExportSetInputCGImage( exporter, cgImageRef); - err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle); - err = GraphicsExportDoExport(exporter, NULL); - } - CloseComponent( exporter ); - } + memcpy( *(Handle)m_pictHandle, (const char *)CFDataGetBytePtr(data), CFDataGetLength(data) ); } -#endif + CFRelease( data ); + CGImageRelease(cgImageRef); -#else - m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle(); - m_pictCreated = false; -#endif } } @@ -725,12 +675,7 @@ void wxBitmapDataObject::Clear() { if (m_pictHandle != NULL) { -#if wxMAC_USE_CORE_GRAPHICS DisposeHandle( (Handle) m_pictHandle ); -#else - if (m_pictCreated) - KillPicture( (PicHandle)m_pictHandle ); -#endif m_pictHandle = NULL; } m_pictCreated = false; @@ -778,77 +723,29 @@ bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf ) if ((pBuf == NULL) || (nSize == 0)) return false; -#if wxMAC_USE_CORE_GRAPHICS Handle picHandle = NewHandle( nSize ); memcpy( *picHandle, pBuf, nSize ); m_pictHandle = picHandle; CGImageRef cgImageRef = 0; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - if ( UMAGetSystemVersion() >= 0x1040 ) - { - CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) pBuf, nSize, kCFAllocatorNull); - CGImageSourceRef source = CGImageSourceCreateWithData( data, NULL ); - if ( source ) - { - cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); - } - CFRelease( source ); - CFRelease( data ); - } - else -#endif -#ifndef __LP64__ + + CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) pBuf, nSize, kCFAllocatorNull); + CGImageSourceRef source = CGImageSourceCreateWithData( data, NULL ); + if ( source ) { - // import from TIFF - GraphicsImportComponent importer = 0; - OSStatus err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &importer); - if (noErr == err) - { - if ( picHandle ) - { - ComponentResult result = GraphicsImportSetDataHandle(importer, picHandle); - if ( result == noErr ) - { - Rect frame; - GraphicsImportGetNaturalBounds( importer, &frame ); - GraphicsImportCreateCGImage( importer, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings ); - } - } - CloseComponent( importer ); - } + cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); } -#endif + CFRelease( source ); + CFRelease( data ); + if ( cgImageRef ) { m_bitmap.Create( CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) ); CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) ); // since our context is upside down we dont use CGContextDrawImage - HIViewDrawCGImage( (CGContextRef) m_bitmap.GetHBITMAP() , &r, cgImageRef ) ; + wxMacDrawCGImage( (CGContextRef) m_bitmap.GetHBITMAP() , &r, cgImageRef ) ; CGImageRelease(cgImageRef); cgImageRef = NULL; } -#else - PicHandle picHandle = (PicHandle)NewHandle( nSize ); - memcpy( *picHandle, pBuf, nSize ); - m_pictHandle = picHandle; - // ownership is transferred to the bitmap - m_pictCreated = false; -#ifndef __LP64__ - Rect frame; - wxMacGetPictureBounds( picHandle, &frame ); -#if wxUSE_METAFILE - wxMetafile mf; - mf.SetHMETAFILE( (WXHMETAFILE)m_pictHandle ); -#endif - wxMemoryDC mdc; - m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top ); - mdc.SelectObject( m_bitmap ); -#if wxUSE_METAFILE - mf.Play( &mdc ); -#endif - mdc.SelectObject( wxNullBitmap ); -#endif -#endif return m_bitmap.Ok(); }