X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e822cd8d0bdf04cd2c7a3dddff61dcc211f7439..2cf3a6d7bef6f20bea35062dd3d4dbf0aec9efb5:/src/mac/carbon/clipbrd.cpp diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index cea52d1990..d0ea791e8b 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -2,7 +2,7 @@ // Name: src/mac/carbon/clipbrd.cpp // Purpose: Clipboard functionality // Author: Stefan Csomor; -// Generalized clipboard implementation by Matthew Flatt +// Generalized clipboard implementation by Matthew Flatt // Modified by: // Created: 1998-01-01 // RCS-ID: $Id$ @@ -14,14 +14,18 @@ #if wxUSE_CLIPBOARD -#include "wx/app.h" -#include "wx/frame.h" -#include "wx/bitmap.h" -#include "wx/utils.h" -#include "wx/metafile.h" #include "wx/clipbrd.h" -#include "wx/intl.h" -#include "wx/log.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/frame.h" + #include "wx/bitmap.h" +#endif + +#include "wx/metafile.h" #ifndef __DARWIN__ #include @@ -144,7 +148,7 @@ void * wxGetClipboardData( wxDataFormat dataFormat, long *len ) return NULL; } - if ( dataFormat.GetType() == wxDF_TEXT ) + if (dataFormat.GetType() == wxDF_TEXT) wxMacConvertNewlines10To13( (char*)data ); return data; @@ -160,19 +164,19 @@ wxClipboard::wxClipboard() wxClipboard::~wxClipboard() { - if (m_data) + if (m_data != NULL) { delete m_data; - m_data = (wxDataObject*)NULL; + m_data = NULL; } } void wxClipboard::Clear() { - if (m_data) + if (m_data != NULL) { delete m_data; - m_data = (wxDataObject*)NULL; + m_data = NULL; } #if TARGET_CARBON @@ -236,17 +240,26 @@ bool wxClipboard::AddData( wxDataObject *data ) for (size_t i = 0; i < m_data->GetFormatCount(); i++) { - wxLogTrace( TRACE_CLIPBOARD, - wxT("wxClipboard now supports atom %s"), - array[i].GetId().c_str() ); + if (array[i].IsStandard()) + { + wxLogTrace( TRACE_CLIPBOARD, + wxT("wxClipboard now supports standard atom type %d"), + array[i].GetType() ); + } + else + { + wxLogTrace( TRACE_CLIPBOARD, + wxT("wxClipboard now supports atom %s"), + array[i].GetId().c_str() ); + } size_t sz = data->GetDataSize( array[ i ] ); void* buf = malloc( sz + 1 ); - if ( buf ) + if ( buf != NULL ) { // empty the buffer because in some case GetDataHere does not fill buf - memset(buf, 0, sz + 1); - data->GetDataHere( array[ i ] , buf ); + memset( buf, 0, sz + 1 ); + data->GetDataHere( array[ i ], buf ); OSType mactype = 0; switch ( array[i].GetType() ) { @@ -275,7 +288,7 @@ bool wxClipboard::AddData( wxDataObject *data ) break; default: - mactype = (OSType)(array[i].GetFormatId()); + mactype = (OSType)(array[ i ].GetFormatId()); break; } @@ -310,6 +323,8 @@ bool wxClipboard::IsSupported( const wxDataFormat &dataFormat ) if ( m_data ) return m_data->IsSupported( dataFormat ); + bool hasData = false; + #if TARGET_CARBON OSStatus err = noErr; ScrapRef scrapRef; @@ -325,23 +340,32 @@ bool wxClipboard::IsSupported( const wxDataFormat &dataFormat ) { err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount ); if (err == noErr) - return true; + hasData = true; + } + else if ( dataFormat.GetType() == wxDF_UNICODETEXT ) + { + err = GetScrapFlavorFlags( scrapRef, 'TEXT', &flavorFlags ); + if (err == noErr) + { + err = GetScrapFlavorSize( scrapRef, 'TEXT', &byteCount ); + if (err == noErr) + hasData = true; + } } } - return false; - #else - long offset; + + long offset = 0; Handle datahandle = NewHandle( 0 ); HLock( datahandle ); GetScrap( datahandle, dataFormat.GetFormatId(), &offset ); HUnlock( datahandle ); - bool hasData = GetHandleSize( datahandle ) > 0; + hasData = GetHandleSize( datahandle ) > 0; DisposeHandle( datahandle ); +#endif return hasData; -#endif } bool wxClipboard::GetData( wxDataObject& data ) @@ -372,7 +396,7 @@ bool wxClipboard::GetData( wxDataObject& data ) else { char *d = new char[ dataSize ]; - m_data->GetDataHere( format, (void*) d ); + m_data->GetDataHere( format, (void*)d ); data.SetData( format, dataSize, d ); delete [] d; } @@ -413,6 +437,7 @@ bool wxClipboard::GetData( wxDataObject& data ) } delete [] array; + return transferred; }