X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72e7876ba5ad16a1b03bb2449ea7886ec648854a..fb2e90c1745beb2c1db7bba7cf35587be392c819:/src/mac/dataobj.cpp diff --git a/src/mac/dataobj.cpp b/src/mac/dataobj.cpp index fbaf93061d..ebf1f0dbed 100644 --- a/src/mac/dataobj.cpp +++ b/src/mac/dataobj.cpp @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: os2/dataobj.cpp -// Purpose: implementation of wx[I]DataObject class -// Author: David Webster +// Name: mac/dataobj.cpp +// Purpose: implementation of wxDataObject class +// Author: Stefan Csomor // Modified by: // Created: 10/21/99 // RCS-ID: $Id$ -// Copyright: (c) 1999 David Webster -// Licence: wxWindows license +// Copyright: (c) 1999 Stefan Csomor +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -33,6 +33,8 @@ #include "wx/dataobj.h" #include "wx/mstream.h" #include "wx/image.h" +#include "wx/mac/private.h" +#include "Scrap.h" // ---------------------------------------------------------------------------- // functions @@ -44,114 +46,83 @@ wxDataFormat::wxDataFormat() { - m_vType = wxDF_INVALID; - m_vFormat = 0; + m_type = wxDF_INVALID; + m_format = 0; } -wxDataFormat::wxDataFormat( - wxDataFormatId vType -) +wxDataFormat::wxDataFormat( wxDataFormatId vType ) { - PrepareFormats(); SetType(vType); } -wxDataFormat::wxDataFormat( - const wxChar* zId -) +wxDataFormat::wxDataFormat( const wxChar* zId) { - PrepareFormats(); SetId(zId); } -wxDataFormat::wxDataFormat( - const wxString& rId -) +wxDataFormat::wxDataFormat( const wxString& rId) { - PrepareFormats(); SetId(rId); } -wxDataFormat::wxDataFormat( - NativeFormat vFormat -) +wxDataFormat::wxDataFormat( NativeFormat vFormat) { - PrepareFormats(); SetId(vFormat); } -void wxDataFormat::SetType( - wxDataFormatId vType -) +void wxDataFormat::SetType( wxDataFormatId Type ) { - m_vType = vType; - - if (m_vType == wxDF_TEXT) - m_vFormat = 0; - else - if (m_vType == wxDF_BITMAP) - m_vFormat = 0; - else - if (m_vType == wxDF_FILENAME) - m_vFormat = 0; + m_type = Type; + + if (m_type == wxDF_TEXT ) + m_format = kScrapFlavorTypeText; + else if (m_type == wxDF_UNICODETEXT ) + m_format = kScrapFlavorTypeUnicode ; + else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE ) + m_format = kScrapFlavorTypePicture; + else if (m_type == wxDF_FILENAME) + m_format = kDragFlavorTypeHFS ; else { wxFAIL_MSG( wxT("invalid dataformat") ); - } -} -wxDataFormatId wxDataFormat::GetType() const -{ - return m_vType; + // this is '????' but it can't be used in the code because ??' is + // parsed as a trigraph! + m_format = 0x3f3f3f3f; + } } wxString wxDataFormat::GetId() const { - wxString sRet(""); // TODO: gdk_atom_name( m_format ) ); - return sRet; + // note that m_format is not a pointer to string, it *is* itself a 4 + // character string + char text[5] ; + strncpy( text , (char*) &m_format , 4 ) ; + text[4] = 0 ; + + return wxString::FromAscii( text ) ; } -void wxDataFormat::SetId( - NativeFormat vFormat -) +void wxDataFormat::SetId( NativeFormat format ) { - m_vFormat = vFormat; -// TODO: -/* - if (m_format == g_textAtom) + m_format = format; + + if (m_format == kScrapFlavorTypeText) m_type = wxDF_TEXT; - else - if (m_format == g_pngAtom) + else if (m_format == kScrapFlavorTypeUnicode ) + m_type = wxDF_UNICODETEXT; + else if (m_format == kScrapFlavorTypePicture) m_type = wxDF_BITMAP; - else - if (m_format == g_fileAtom) + else if (m_format == kDragFlavorTypeHFS ) m_type = wxDF_FILENAME; else m_type = wxDF_PRIVATE; -*/ -} - -void wxDataFormat::SetId( - const wxChar* zId -) -{ - wxString tmp(zId); - - m_vType = wxDF_PRIVATE; - m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); } -void wxDataFormat::PrepareFormats() +void wxDataFormat::SetId( const wxChar* zId ) { -// TODO: -/* - if (!g_textAtom) - g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) - g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) - g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); -*/ + m_type = wxDF_PRIVATE; + m_format = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); } //------------------------------------------------------------------------- @@ -175,7 +146,7 @@ bool wxDataObject::IsSupportedFormat( } else { - wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; + wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; GetAllFormats( pFormats ,vDir ); @@ -217,7 +188,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++) { @@ -233,11 +204,9 @@ bool wxFileDataObject::SetData( , const void* pBuf ) { - /* TODO */ - - wxString sFile( (const char *)pBuf); /* char, not wxChar */ + m_filenames.Empty(); - AddFile(sFile); + AddFile(wxString::FromAscii((char*)pBuf)); return TRUE; } @@ -259,13 +228,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() @@ -277,64 +248,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 = vImage.ConvertToBitmap(); + 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; - - wxImage vImage(m_bitmap); - wxPNGHandler vHandler; - wxCountingOutputStream vCount; - - vHandler.SaveFile(&vImage, vCount); - - m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ??? - m_pngData = malloc(m_pngSize); - - wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize); - - vHandler.SaveFile(&vImage, vMstream ); -} -