X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/427ff66291af2d8dd34ff5ee68c81436997144a1..37d0bfa8756716ac456879bd64c57ec27fe20be5:/src/mac/carbon/dataobj.cpp?ds=sidebyside diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index 5949c6300b..65401b5f33 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/dataobj.cpp @@ -17,24 +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 "Scrap.h" +#include // ---------------------------------------------------------------------------- // functions @@ -85,19 +88,21 @@ void wxDataFormat::SetType( wxDataFormatId Type ) 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 { - char text[5] ; - strncpy( text , (char*) m_format , 4 ) ; - text[4] = 0 ; + // 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 ) ; } @@ -107,14 +112,11 @@ void wxDataFormat::SetId( NativeFormat format ) if (m_format == kScrapFlavorTypeText) m_type = wxDF_TEXT; - else - if (m_format == kScrapFlavorTypeUnicode ) + else if (m_format == kScrapFlavorTypeUnicode ) m_type = wxDF_UNICODETEXT; - else - if (m_format == kScrapFlavorTypePicture) + 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; @@ -122,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 ); } @@ -169,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 // ---------------------------------------------------------------------------- @@ -209,7 +222,10 @@ bool wxFileDataObject::SetData( { m_filenames.Empty(); - AddFile(wxString::FromAscii((char*)pBuf)); + // 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; } @@ -238,7 +254,8 @@ wxBitmapDataObject::wxBitmapDataObject( Init(); if ( m_bitmap.Ok() ) { - m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ; + m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; + m_pictCreated = false ; } } @@ -255,7 +272,8 @@ void wxBitmapDataObject::SetBitmap( wxBitmapDataObjectBase::SetBitmap(rBitmap); if ( m_bitmap.Ok() ) { - m_pictHandle = m_bitmap.GetPict( &m_pictCreated ) ; + m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; + m_pictCreated = false ; } } @@ -301,11 +319,19 @@ bool wxBitmapDataObject::SetData( 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 ; - m_bitmap.SetPict( picHandle ) ; - m_bitmap.SetWidth( frame.right - frame.left ) ; - m_bitmap.SetHeight( frame.bottom - frame.top ) ; + 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(); } + +#endif \ No newline at end of file