X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c309daf5d32560aa00278af578fad74b32f2cc51..bab3f3eac44fdc682febe918b3b50250e1991dec:/src/mac/carbon/dataobj.cpp diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index c2f75326c0..65401b5f33 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/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 /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,23 +17,27 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "dataobj.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#if wxUSE_DATAOBJ + #ifndef WX_PRECOMP #include "wx/intl.h" #endif -#include "wx/defs.h" #include "wx/log.h" #include "wx/dataobj.h" +#include "wx/dcmemory.h" #include "wx/mstream.h" #include "wx/image.h" +#include "wx/metafile.h" #include "wx/mac/private.h" +#include // ---------------------------------------------------------------------------- // functions @@ -73,40 +77,46 @@ void wxDataFormat::SetType( wxDataFormatId Type ) { m_type = Type; - if (m_type == wxDF_TEXT) - m_format = 'TEXT'; + 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 = 'PICT'; + m_format = kScrapFlavorTypePicture; else if (m_type == wxDF_FILENAME) m_format = kDragFlavorTypeHFS ; else { wxFAIL_MSG( wxT("invalid dataformat") ); - } -} -wxDataFormatId wxDataFormat::GetType() const -{ - return m_type; + // 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: to name of ( 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 format ) { m_format = format; - if (m_format == 'TEXT') + if (m_format == kScrapFlavorTypeText) m_type = wxDF_TEXT; - else - if (m_format == 'PICT') + else if (m_format == kScrapFlavorTypeUnicode ) + m_type = wxDF_UNICODETEXT; + else if (m_format == kScrapFlavorTypePicture) m_type = wxDF_BITMAP; - else - if (m_format == kDragFlavorTypeHFS ) + else if (m_format == kDragFlavorTypeHFS ) m_type = wxDF_FILENAME; else m_type = wxDF_PRIVATE; @@ -114,8 +124,6 @@ void wxDataFormat::SetId( NativeFormat format ) void wxDataFormat::SetId( const wxChar* zId ) { - wxString tmp(zId); - m_type = wxDF_PRIVATE; m_format = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); } @@ -141,7 +149,7 @@ bool wxDataObject::IsSupportedFormat( } else { - wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; + wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; GetAllFormats( pFormats ,vDir ); @@ -161,6 +169,19 @@ bool wxDataObject::IsSupportedFormat( } } +// ---------------------------------------------------------------------------- +// wxTextDataObject +// ---------------------------------------------------------------------------- + +#if wxUSE_UNICODE +void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const +{ + *formats++ = wxDataFormat( wxDF_TEXT ); + *formats = wxDataFormat( wxDF_UNICODETEXT ); +} + +#endif + // ---------------------------------------------------------------------------- // wxFileDataObject // ---------------------------------------------------------------------------- @@ -183,7 +204,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,9 +222,10 @@ bool wxFileDataObject::SetData( { m_filenames.Empty(); - wxString sFile( (const char *)pBuf); /* char, not wxChar */ - - AddFile(sFile); + // only add if this is not an empty string + // we can therefore clear the list by just setting an empty string + if ( (*(char*)pBuf) != 0 ) + AddFile(wxString::FromAscii((char*)pBuf)); return TRUE; } @@ -225,13 +247,16 @@ wxBitmapDataObject::wxBitmapDataObject() } wxBitmapDataObject::wxBitmapDataObject( - const wxBitmap& rBitmap + const wxBitmap& rBitmap ) : wxBitmapDataObjectBase(rBitmap) { Init(); - - DoConvertToPng(); + if ( m_bitmap.Ok() ) + { + m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; + m_pictCreated = false ; + } } wxBitmapDataObject::~wxBitmapDataObject() @@ -243,65 +268,70 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap ) { - ClearAll(); + Clear(); wxBitmapDataObjectBase::SetBitmap(rBitmap); - DoConvertToPng(); + if ( m_bitmap.Ok() ) + { + m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; + m_pictCreated = false ; + } +} + +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 ; + // ownership is transferred to the bitmap + m_pictCreated = false ; + Rect frame = (**picHandle).picFrame ; + + wxMetafile mf ; + mf.SetHMETAFILE( (WXHMETAFILE) m_pictHandle ) ; + wxMemoryDC mdc ; + m_bitmap.Create( frame.right - frame.left ,frame.bottom - frame.top ) ; + mdc.SelectObject(m_bitmap ) ; + mf.Play( &mdc ) ; + mdc.SelectObject( wxNullBitmap ) ; + 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); -} - +#endif \ No newline at end of file