X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be9abe3fd0edec7215fa00aa158f7581da4df2fe..d1b15f03b8e614c83541ca3487f847f61122b514:/src/gtk1/dataobj.cpp diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index bb9e817c05..d1668eb212 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -14,6 +14,8 @@ #include "wx/dataobj.h" #include "wx/app.h" #include "wx/debug.h" +#include "wx/mstream.h" +#include "wx/image.h" #include "gdk/gdk.h" @@ -23,6 +25,7 @@ //------------------------------------------------------------------------- GdkAtom g_textAtom = 0; +GdkAtom g_pngAtom = 0; //------------------------------------------------------------------------- // wxDataFormat @@ -32,7 +35,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject) wxDataFormat::wxDataFormat() { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = wxDF_INVALID; m_hasAtom = FALSE; m_atom = (GdkAtom) 0; @@ -40,25 +43,25 @@ wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat( wxDataFormatId type ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetType( type ); } wxDataFormat::wxDataFormat( const wxChar *id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxString &id ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); SetId( id ); } wxDataFormat::wxDataFormat( const wxDataFormat &format ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_type = format.GetType(); m_id = format.GetId(); m_hasAtom = TRUE; @@ -67,7 +70,7 @@ wxDataFormat::wxDataFormat( const wxDataFormat &format ) wxDataFormat::wxDataFormat( const GdkAtom atom ) { - if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + PrepareFormats(); m_hasAtom = TRUE; m_atom = atom; @@ -84,7 +87,7 @@ wxDataFormat::wxDataFormat( const GdkAtom atom ) m_type = wxDF_PRIVATE; m_id = gdk_atom_name( m_atom ); - if (m_id == _T("file:ALL")) + if (m_id == wxT("file:ALL")) { m_type = wxDF_FILENAME; } @@ -97,21 +100,21 @@ void wxDataFormat::SetType( wxDataFormatId type ) if (m_type == wxDF_TEXT) { - m_id = _T("STRING"); + m_id = wxT("STRING"); } else if (m_type == wxDF_BITMAP) { - m_id = _T("BITMAP"); + m_id = wxT("image/png"); } else if (m_type == wxDF_FILENAME) { - m_id = _T("file:ALL"); + m_id = wxT("file:ALL"); } else { - wxFAIL_MSG( _T("invalid dataformat") ); + wxFAIL_MSG( wxT("invalid dataformat") ); } m_hasAtom = FALSE; @@ -152,7 +155,7 @@ GdkAtom wxDataFormat::GetAtom() else if (m_type == wxDF_PRIVATE) { - m_atom = gdk_atom_intern( MBSTRINGCAST m_id.mbc_str(), FALSE ); + m_atom = gdk_atom_intern( wxMBSTRINGCAST m_id.mbc_str(), FALSE ); } else if (m_type == wxDF_FILENAME) @@ -169,6 +172,12 @@ GdkAtom wxDataFormat::GetAtom() return m_atom; } +void wxDataFormat::PrepareFormats() +{ + if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); + if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); +} + //------------------------------------------------------------------------- // wxDataBroker //------------------------------------------------------------------------- @@ -385,18 +394,28 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) wxBitmapDataObject::wxBitmapDataObject() { m_format.SetType( wxDF_BITMAP ); + m_pngData = (char*)NULL; + m_pngSize = 0; } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) { m_format.SetType( wxDF_BITMAP ); - + m_pngData = (char*)NULL; + m_pngSize = 0; m_bitmap = bitmap; + DoConvertToPng(); +} + +wxBitmapDataObject::~wxBitmapDataObject() +{ + if (m_pngData) delete[] m_pngData; } void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) { m_bitmap = bitmap; + DoConvertToPng(); } wxBitmap wxBitmapDataObject::GetBitmap() const @@ -411,12 +430,44 @@ void wxBitmapDataObject::WriteData( void *dest ) const size_t wxBitmapDataObject::GetSize() const { - return 0; + return m_pngSize; +} + +void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const +{ +// if (m_bitmap == bitmap) + memcpy( dest, m_pngData, m_pngSize ); +} + +void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize ) +{ + if (m_pngData) delete[] m_pngData; + m_pngData = (char*) NULL; + m_pngSize = pngSize; + m_pngData = new char[m_pngSize]; + memcpy( m_pngData, pngData, m_pngSize ); + + wxMemoryInputStream mstream( pngData, pngSize ); + wxImage image; + wxPNGHandler handler; + handler.LoadFile( &image, mstream ); + m_bitmap = image.ConvertToBitmap(); } -void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const +void wxBitmapDataObject::DoConvertToPng() { - memcpy( dest, m_bitmap.GetPixmap(), GetSize() ); + if (m_pngData) delete[] m_pngData; + + wxImage image( m_bitmap ); + wxPNGHandler handler; + + wxCountingOutputStream count; + handler.SaveFile( &image, count ); + m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? + m_pngData = new char[m_pngSize]; + + wxMemoryOutputStream mstream( m_pngData, m_pngSize ); + handler.SaveFile( &image, mstream ); } // ---------------------------------------------------------------------------- @@ -433,7 +484,7 @@ void wxPrivateDataObject::Free() wxPrivateDataObject::wxPrivateDataObject() { - wxString id = _T("application/"); + wxString id = wxT("application/"); id += wxTheApp->GetAppName(); m_format.SetId( id );