+ err = GetCurrentScrap( &scrapRef );
+ if ( err != noTypeErr && err != memFullErr )
+ {
+ ScrapFlavorFlags flavorFlags;
+
+ err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags );
+ if (err == noErr)
+ {
+ err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount );
+ if (err == noErr)
+ {
+ Size allocSize = byteCount;
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ allocSize += 1;
+ else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ allocSize += 2;
+
+ data = new char[ allocSize ];
+
+ if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr )
+ {
+ *len = allocSize;
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ ((char*)data)[ byteCount ] = 0;
+ if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ {
+ // "data" format is UTF16, so 2 bytes = one character
+ // wxChar size depends on platform, so just clear last 2 bytes
+ ((char*)data)[ byteCount + 0 ] =
+ ((char*)data)[ byteCount + 1 ] = 0;
+ }
+ }
+ else
+ {
+ delete [] (char*)data;
+ data = NULL;
+ }
+ }
+ }
+ }
+
+#else
+ long offset;
+ Handle datahandle = NewHandle( 0 );
+ HLock( datahandle );
+ err = (OSStatus)GetScrap( datahandle, dataFormat.GetFormatId(), &offset );
+ HUnlock( datahandle );
+ if ( GetHandleSize( datahandle ) > 0 )
+ {
+ byteCount = GetHandleSize( datahandle );
+ Size allocSize = byteCount;
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ allocSize += 1;
+ else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ allocSize += 2;
+
+ data = new char[ allocSize ];
+
+ memcpy( (char*) data, (char*) *datahandle, byteCount );
+ if ( dataFormat.GetType() == wxDF_TEXT )
+ ((char*)data)[ byteCount ] = 0;
+ else if ( dataFormat.GetType() == wxDF_UNICODETEXT )
+ ((wxChar*)data)[ byteCount / 2 ] = 0;
+ *len = byteCount;
+ }
+
+ DisposeHandle( datahandle );
+#endif
+
+ if (err != noErr)
+ {
+ wxLogSysError(wxT("Failed to get clipboard data."));
+
+ return NULL;
+ }
+
+ if (dataFormat.GetType() == wxDF_TEXT)
+ wxMacConvertNewlines10To13( (char*)data );
+
+ return data;