]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/uma.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / uma.cpp
index 88b5771bddbf174085ab9d6b4d7eb8bb10fb4394..75132f7124fc2f81cd2917461813e206775b3003 100644 (file)
@@ -31,9 +31,7 @@
 #  endif
 #endif
 
-#ifndef __DARWIN__
-#  include <Scrap.h>
-#endif
+#include "wx/mac/uma.h"
 
 // since we have decided that we only support 8.6 upwards we are
 // checking for these minimum requirements in the startup code of
@@ -49,7 +47,8 @@ void UMACleanupToolbox()
 {
 }
 
-void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded )
+void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls),
+                     bool WXUNUSED(isEmbedded) )
 {
     ::InitCursor();
 
@@ -218,7 +217,7 @@ void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEn
             macKey = 0 ;
             glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
             if ( key >= WXK_F13 )
-                glyph += 13 ;
+                glyph += 12 ;
         }
         else
         {
@@ -755,22 +754,6 @@ wxMacPortStateHelper::~wxMacPortStateHelper()
 
 #endif
 
-OSStatus UMAPutScrap( Size size , OSType type , void *data )
-{
-    OSStatus err = noErr ;
-
-#if !TARGET_CARBON
-    err = PutScrap( size , type , data ) ;
-#else
-    ScrapRef    scrap;
-    err = GetCurrentScrap( &scrap );
-    if ( err == noErr )
-        err = PutScrapFlavor( scrap, type , 0, size, data );
-#endif
-
-    return err ;
-}
-
 Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
 {
     GetControlBounds( theControl , bounds ) ;
@@ -791,6 +774,72 @@ Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
     return bounds ;
 }
 
+size_t UMAPutBytesCFRefCallback( void *info, const void *bytes, size_t count )
+{
+    CFMutableDataRef data = (CFMutableDataRef) info;
+    if ( data )
+    {
+        CFDataAppendBytes( data, (const UInt8*) bytes, count );
+    }
+    return count;
+}
+
+void UMAReleaseCFDataProviderCallback( void *info, const void *data, size_t count )
+{
+    if ( info )
+        CFRelease( (CFDataRef) info );
+}
+
+void UMAReleaseCFDataConsumerCallback( void *info )
+{
+    if ( info )
+        CFRelease( (CFDataRef) info );
+}
+
+CGDataProviderRef UMACGDataProviderCreateWithCFData( CFDataRef data )
+{
+    if ( data == NULL )
+        return NULL;
+        
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+    if( &CGDataProviderCreateWithCFData != NULL )
+    {
+        return CGDataProviderCreateWithCFData( data );
+    }
+#endif
+
+    // make sure we keep it until done
+    CFRetain( data );
+    CGDataProviderRef provider = CGDataProviderCreateWithData( (void*) data , CFDataGetBytePtr( data ) ,
+        CFDataGetLength( data ), UMAReleaseCFDataProviderCallback );
+    // if provider couldn't be created, release the data again
+    if ( provider == NULL )
+        CFRelease( data );
+    return provider;
+}
+
+CGDataConsumerRef UMACGDataConsumerCreateWithCFData( CFMutableDataRef data )
+{
+    if ( data == NULL )
+        return NULL;
+        
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+    if( &CGDataConsumerCreateWithCFData != NULL )
+    {
+        return CGDataConsumerCreateWithCFData( data );
+    }
+#endif
+    // make sure we keep it until done
+    CFRetain( data );
+    CGDataConsumerCallbacks callbacks;
+    callbacks.putBytes = UMAPutBytesCFRefCallback;
+    callbacks.releaseConsumer = UMAReleaseCFDataConsumerCallback;
+    CGDataConsumerRef consumer = CGDataConsumerCreate( data , &callbacks );
+    // if consumer couldn't be created, release the data again
+    if ( consumer == NULL )
+        CFRelease( data );
+    return consumer;
+}
 #endif  // wxUSE_GUI
 
 #if wxUSE_BASE