X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c309daf5d32560aa00278af578fad74b32f2cc51..474df218777eae7dade89c094e50e032eb2feeea:/src/mac/carbon/dataobj.cpp?ds=inline diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index c2f75326c0..c1a443a7e5 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/dataobj.cpp @@ -6,7 +6,7 @@ // Created: 10/21/99 // RCS-ID: $Id$ // Copyright: (c) 1999 David Webster -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -141,7 +141,7 @@ bool wxDataObject::IsSupportedFormat( } else { - wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; + wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; GetAllFormats( pFormats ,vDir ); @@ -183,7 +183,7 @@ bool wxFileDataObject::GetDataHere( size_t wxFileDataObject::GetDataSize() const { - size_t nRes = 0; + size_t nRes = 0; for (size_t i = 0; i < m_filenames.GetCount(); i++) { @@ -201,7 +201,7 @@ bool wxFileDataObject::SetData( { m_filenames.Empty(); - wxString sFile( (const char *)pBuf); /* char, not wxChar */ + wxString sFile( (const char *)pBuf); /* char, not wxChar */ AddFile(sFile); @@ -225,13 +225,15 @@ wxBitmapDataObject::wxBitmapDataObject() } wxBitmapDataObject::wxBitmapDataObject( - const wxBitmap& rBitmap + const wxBitmap& rBitmap ) : wxBitmapDataObjectBase(rBitmap) { Init(); - - DoConvertToPng(); + if ( m_bitmap.Ok() ) + { + m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ; + } } wxBitmapDataObject::~wxBitmapDataObject() @@ -243,65 +245,61 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap ) { - ClearAll(); + Clear(); wxBitmapDataObjectBase::SetBitmap(rBitmap); - DoConvertToPng(); + if ( m_bitmap.Ok() ) + { + m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ; + } +} + +void wxBitmapDataObject::Init() +{ + m_pictHandle = NULL ; + m_pictCreated = false ; +} + +void wxBitmapDataObject::Clear() +{ + if ( m_pictCreated && m_pictHandle ) + { + KillPicture( (PicHandle) m_pictHandle ) ; + } + m_pictHandle = NULL ; } bool wxBitmapDataObject::GetDataHere( void* pBuf ) const { - if (!m_pngSize) + if (!m_pictHandle) { wxFAIL_MSG(wxT("attempt to copy empty bitmap failed")); return FALSE; } - memcpy(pBuf, m_pngData, m_pngSize); + memcpy(pBuf, *(Handle)m_pictHandle, GetHandleSize((Handle)m_pictHandle)); return TRUE; } +size_t wxBitmapDataObject::GetDataSize() const +{ + return GetHandleSize((Handle)m_pictHandle) ; +} + bool wxBitmapDataObject::SetData( size_t nSize , const void* pBuf ) { Clear(); - m_pngSize = nSize; - m_pngData = malloc(m_pngSize); - - memcpy(m_pngData, pBuf, m_pngSize); - - wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize); - wxImage vImage; - wxPNGHandler vHandler; - - if (!vHandler.LoadFile(&vImage, vMstream)) - { - return FALSE; - } - - m_bitmap = wxBitmap( vImage ) ; + PicHandle picHandle = (PicHandle) NewHandle( nSize ) ; + memcpy( *picHandle , pBuf , nSize ) ; + m_pictHandle = picHandle ; + m_pictCreated = false ; + Rect frame = (**picHandle).picFrame ; + + m_bitmap.SetPict( picHandle ) ; + m_bitmap.SetWidth( frame.right - frame.left ) ; + m_bitmap.SetHeight( frame.bottom - frame.top ) ; return m_bitmap.Ok(); } - -void wxBitmapDataObject::DoConvertToPng() -{ - if (!m_bitmap.Ok()) - return; - - wxCHECK_RET( wxImage::FindHandler(wxBITMAP_TYPE_PNG) != NULL, - wxT("You must call wxImage::AddHandler(new wxPNGHandler); to be able to use clipboard with bitmaps!") ); - - wxImage image = m_bitmap.ConvertToImage(); - - wxCountingOutputStream count; - image.SaveFile(count, wxBITMAP_TYPE_PNG); - - m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? - m_pngData = malloc(m_pngSize); - - wxMemoryOutputStream mstream((char*) m_pngData, m_pngSize); - image.SaveFile(mstream, wxBITMAP_TYPE_PNG); -} -