-static const wxChar *TRACE_CLIPBOARD = _T("clipboard");
-
-void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
-{
-#if !TARGET_CARBON
- OSErr err = noErr ;
-#else
- OSStatus err = noErr ;
-#endif
- void * data = NULL ;
- Size byteCount;
-
- switch (dataFormat.GetType())
- {
- case wxDF_OEMTEXT:
- dataFormat = wxDF_TEXT;
- // fall through
-
- case wxDF_TEXT:
- break;
- case wxDF_UNICODETEXT:
- break;
- case wxDF_BITMAP :
- case wxDF_METAFILE :
- break ;
- default:
- {
- wxLogError(_("Unsupported clipboard format."));
- return NULL;
- }
- }
-
-#if TARGET_CARBON
- ScrapRef scrapRef;
-
- err = GetCurrentScrap( &scrapRef );
- if ( err != noTypeErr && err != memFullErr )
- {
- ScrapFlavorFlags flavorFlags;
-
- if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr)
- {
- if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == 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 )
- ((wxChar*)data)[byteCount/2] = 0 ;
- }
- else
- {
- delete[] ((char *)data) ;
- data = NULL ;
- }
- }
- }
- }
-
-#else
- long offset ;
- Handle datahandle = NewHandle(0) ;
- HLock( datahandle ) ;
- 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 ;
- if ( dataFormat.GetType() == wxDF_UNICODETEXT )
- ((wxChar*)data)[byteCount/2] = 0 ;
- *len = byteCount ;
- }
- DisposeHandle( datahandle ) ;
-#endif
- if ( err )
- {
- wxLogSysError(_("Failed to get clipboard data."));
-
- return NULL ;
- }
-
- if ( dataFormat.GetType() == wxDF_TEXT )
- {
- char * buf = (char*) data ;
- while( (buf=strchr(buf,0x0a)) != NULL )
- {
- *buf = 13 ;
- buf++ ;
- }
- }
-
- return data;
-}
-
-
-/*
- * Generalized clipboard implementation by Matthew Flatt
- */