attempt to tame composite data objects

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25954 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2004-02-26 17:02:00 +00:00
parent 53ac3021de
commit 634bafa9eb
2 changed files with 78 additions and 104 deletions

View File

@ -205,6 +205,11 @@ bool wxClipboard::IsOpened() const
bool wxClipboard::SetData( wxDataObject *data ) bool wxClipboard::SetData( wxDataObject *data )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
Clear();
// as we can only store one wxDataObject, this is the same in this // as we can only store one wxDataObject, this is the same in this
// implementation // implementation
return AddData( data ); return AddData( data );
@ -236,58 +241,38 @@ bool wxClipboard::AddData( wxDataObject *data )
#else #else
OSStatus err = noErr ; OSStatus err = noErr ;
#endif #endif
size_t sz = data->GetDataSize( array[i] ) ;
switch ( array[i].GetType() ) void* buf = malloc( sz + 1 ) ;
{ if ( buf )
case wxDF_TEXT: {
case wxDF_OEMTEXT: data->GetDataHere( array[i] , buf ) ;
{ OSType mactype = 0 ;
wxTextDataObject* textDataObject = (wxTextDataObject*) data; switch ( array[i].GetType() )
wxCharBuffer buf = textDataObject->GetText().mb_str() ; {
err = UMAPutScrap( strlen(buf) , kScrapFlavorTypeText , (void*) buf.data() ) ; case wxDF_TEXT:
} case wxDF_OEMTEXT:
break ; mactype = kScrapFlavorTypeText ;
#if wxUSE_UNICODE break ;
case wxDF_UNICODETEXT : #if wxUSE_UNICODE
{ case wxDF_UNICODETEXT :
wxTextDataObject* textDataObject = (wxTextDataObject*) data; mactype = kScrapFlavorTypeUnicode ;
wxString str(textDataObject->GetText()); break ;
err = UMAPutScrap( str.Length() * sizeof(wxChar) , kScrapFlavorTypeUnicode , (void*) str.wc_str() ) ; #endif
} #if wxUSE_DRAG_AND_DROP
break ; case wxDF_METAFILE:
#endif mactype = kScrapFlavorTypePicture ;
#if wxUSE_DRAG_AND_DROP break ;
case wxDF_METAFILE: #endif
{ case wxDF_BITMAP:
wxMetafileDataObject* metaFileDataObject = case wxDF_DIB:
(wxMetafileDataObject*) data; mactype = kScrapFlavorTypePicture ;
wxMetafile metaFile = metaFileDataObject->GetMetafile(); break ;
PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; default:
HLock( (Handle) pict ) ; break ;
err = UMAPutScrap( GetHandleSize( (Handle) pict ) , kScrapFlavorTypePicture , *pict ) ; }
HUnlock( (Handle) pict ) ; UMAPutScrap( sz , mactype , buf ) ;
} free( buf ) ;
break ; }
#endif
case wxDF_BITMAP:
case wxDF_DIB:
{
bool created = false ;
PicHandle pict = NULL ;
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data ;
pict = (PicHandle) bitmapDataObject->GetBitmap().GetPict( &created ) ;
HLock( (Handle) pict ) ;
err = UMAPutScrap( GetHandleSize( (Handle) pict ) , kScrapFlavorTypePicture , *pict ) ;
HUnlock( (Handle) pict ) ;
if ( created )
KillPicture( pict ) ;
}
default:
break ;
}
} }
delete[] array; delete[] array;
@ -297,6 +282,8 @@ bool wxClipboard::AddData( wxDataObject *data )
void wxClipboard::Close() void wxClipboard::Close()
{ {
wxCHECK_RET( m_open, wxT("clipboard not open") );
m_open = false ; m_open = false ;
// Get rid of cached object. If this is not done copying from another application will // Get rid of cached object. If this is not done copying from another application will

View File

@ -205,6 +205,11 @@ bool wxClipboard::IsOpened() const
bool wxClipboard::SetData( wxDataObject *data ) bool wxClipboard::SetData( wxDataObject *data )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
Clear();
// as we can only store one wxDataObject, this is the same in this // as we can only store one wxDataObject, this is the same in this
// implementation // implementation
return AddData( data ); return AddData( data );
@ -236,58 +241,38 @@ bool wxClipboard::AddData( wxDataObject *data )
#else #else
OSStatus err = noErr ; OSStatus err = noErr ;
#endif #endif
size_t sz = data->GetDataSize( array[i] ) ;
switch ( array[i].GetType() ) void* buf = malloc( sz + 1 ) ;
{ if ( buf )
case wxDF_TEXT: {
case wxDF_OEMTEXT: data->GetDataHere( array[i] , buf ) ;
{ OSType mactype = 0 ;
wxTextDataObject* textDataObject = (wxTextDataObject*) data; switch ( array[i].GetType() )
wxCharBuffer buf = textDataObject->GetText().mb_str() ; {
err = UMAPutScrap( strlen(buf) , kScrapFlavorTypeText , (void*) buf.data() ) ; case wxDF_TEXT:
} case wxDF_OEMTEXT:
break ; mactype = kScrapFlavorTypeText ;
#if wxUSE_UNICODE break ;
case wxDF_UNICODETEXT : #if wxUSE_UNICODE
{ case wxDF_UNICODETEXT :
wxTextDataObject* textDataObject = (wxTextDataObject*) data; mactype = kScrapFlavorTypeUnicode ;
wxString str(textDataObject->GetText()); break ;
err = UMAPutScrap( str.Length() * sizeof(wxChar) , kScrapFlavorTypeUnicode , (void*) str.wc_str() ) ; #endif
} #if wxUSE_DRAG_AND_DROP
break ; case wxDF_METAFILE:
#endif mactype = kScrapFlavorTypePicture ;
#if wxUSE_DRAG_AND_DROP break ;
case wxDF_METAFILE: #endif
{ case wxDF_BITMAP:
wxMetafileDataObject* metaFileDataObject = case wxDF_DIB:
(wxMetafileDataObject*) data; mactype = kScrapFlavorTypePicture ;
wxMetafile metaFile = metaFileDataObject->GetMetafile(); break ;
PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; default:
HLock( (Handle) pict ) ; break ;
err = UMAPutScrap( GetHandleSize( (Handle) pict ) , kScrapFlavorTypePicture , *pict ) ; }
HUnlock( (Handle) pict ) ; UMAPutScrap( sz , mactype , buf ) ;
} free( buf ) ;
break ; }
#endif
case wxDF_BITMAP:
case wxDF_DIB:
{
bool created = false ;
PicHandle pict = NULL ;
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data ;
pict = (PicHandle) bitmapDataObject->GetBitmap().GetPict( &created ) ;
HLock( (Handle) pict ) ;
err = UMAPutScrap( GetHandleSize( (Handle) pict ) , kScrapFlavorTypePicture , *pict ) ;
HUnlock( (Handle) pict ) ;
if ( created )
KillPicture( pict ) ;
}
default:
break ;
}
} }
delete[] array; delete[] array;
@ -297,6 +282,8 @@ bool wxClipboard::AddData( wxDataObject *data )
void wxClipboard::Close() void wxClipboard::Close()
{ {
wxCHECK_RET( m_open, wxT("clipboard not open") );
m_open = false ; m_open = false ;
// Get rid of cached object. If this is not done copying from another application will // Get rid of cached object. If this is not done copying from another application will