#include "gdk/gdk.h"
-
//-------------------------------------------------------------------------
// global data
//-------------------------------------------------------------------------
void wxDataFormat::PrepareFormats()
{
- if (!g_textAtom)
+ if (!g_textAtom)
g_textAtom = gdk_atom_intern( "STRING", FALSE );
- if (!g_pngAtom)
+ if (!g_pngAtom)
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
- if (!g_fileAtom)
+ if (!g_fileAtom)
g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
}
// wxDataObject
//-------------------------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
-
wxDataObject::wxDataObject()
{
}
-wxDataObject::~wxDataObject()
+bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const
{
-}
-
-bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
-{
- size_t nFormatCount = GetFormatCount();
+ size_t nFormatCount = GetFormatCount(dir);
if ( nFormatCount == 1 ) {
return format == GetPreferredFormat();
}
else {
wxDataFormat *formats = new wxDataFormat[nFormatCount];
- GetAllFormats(formats);
+ GetAllFormats(formats,dir);
size_t n;
for ( n = 0; n < nFormatCount; n++ ) {
}
}
-
-// ----------------------------------------------------------------------------
-// wxTextDataObject
-// ----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
-
-wxTextDataObject::wxTextDataObject()
-{
-}
-
-wxTextDataObject::wxTextDataObject(const wxString& strText)
- : m_strText(strText)
-{
-}
-
-size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
-{
- return m_strText.Len() + 1; // +1 for trailing '\0'of course
-}
-
-bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
-{
- memcpy(buf, m_strText.c_str(), GetDataSize(format));
- return TRUE;
-}
-
-bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
-{
- m_strText = (const wxChar *)buf;
- return TRUE;
-}
-
// ----------------------------------------------------------------------------
// wxFileDataObject
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
-
-wxFileDataObject::wxFileDataObject()
-{
-}
-
-void wxFileDataObject::AddFile( const wxString &file )
+bool wxFileDataObject::GetDataHere(void *buf) const
{
- m_files += file;
- m_files += (wxChar)0;
-}
+ wxString filenames;
+
+ for (size_t i = 0; i < m_filenames.GetCount(); i++)
+ {
+ filenames += m_filenames[i];
+ filenames += (wxChar) 0;
+ }
+
+ memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 );
-wxString wxFileDataObject::GetFiles() const
-{
- return m_files;
+ return TRUE;
}
-bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+size_t wxFileDataObject::GetDataSize() const
{
- if (format == wxDF_FILENAME)
+ size_t res = 0;
+
+ for (size_t i = 0; i < m_filenames.GetCount(); i++)
{
- memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 );
- return TRUE;
+ res += m_filenames[i].Len();
+ res += 1;
}
- return FALSE;
+ return res + 1;
}
-size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const
+bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
{
- if (format != wxDF_FILENAME) return 0;
+ /* TODO */
- return m_files.Len() + 1;
+ wxString file( (const char *)buf ); /* char, not wxChar */
+
+ AddFile( file );
+
+ return TRUE;
}
-bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf)
+void wxFileDataObject::AddFile( const wxString &filename )
{
- if (format != wxDF_FILENAME)
- return FALSE;
-
- m_files = (char*)(buf); // this is so ugly, I cannot look at it
-
- return TRUE;
+ m_filenames.Add( filename );
}
// ----------------------------------------------------------------------------
// wxBitmapDataObject
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
-
wxBitmapDataObject::wxBitmapDataObject()
{
- m_pngData = (void*)NULL;
- m_pngSize = 0;
+ Init();
}
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
+ : wxBitmapDataObjectBase(bitmap)
{
- m_pngData = (void*)NULL;
- m_pngSize = 0;
- m_bitmap = bitmap;
+ Init();
+
DoConvertToPng();
}
wxBitmapDataObject::~wxBitmapDataObject()
{
- if (m_pngData)
- delete[] m_pngData;
+ Clear();
}
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
{
- if (m_pngData)
- delete[] m_pngData;
- m_pngData = (void*)NULL;
- m_pngSize = 0;
-
- m_bitmap = bitmap;
- DoConvertToPng();
-}
+ ClearAll();
-size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
-{
- if (format != wxDF_BITMAP) return 0;
-
- return m_pngSize;
+ wxBitmapDataObjectBase::SetBitmap(bitmap);
+
+ DoConvertToPng();
}
-bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+bool wxBitmapDataObject::GetDataHere(void *buf) const
{
- if (format != wxDF_BITMAP) return FALSE;
-
- if (m_pngSize > 0)
+ if ( !m_pngSize )
{
- memcpy(buf, m_pngData, m_pngSize);
- return TRUE;
+ wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") );
+
+ return FALSE;
}
-
- return FALSE;
-}
-bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
-{
- if (m_pngData) delete[] m_pngData;
- m_pngData = (void*) NULL;
- m_pngSize = 0;
- m_bitmap = wxNullBitmap;
-
- return FALSE;
+ memcpy(buf, m_pngData, m_pngSize);
+
+ return TRUE;
}
-void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
+bool wxBitmapDataObject::SetData(size_t size, const void *buf)
{
- if (m_pngData) delete[] m_pngData;
+ Clear();
+
m_pngSize = size;
- m_pngData = (void*) new char[m_pngSize];
-
+ m_pngData = malloc(m_pngSize);
+
memcpy( m_pngData, buf, m_pngSize );
-
+
wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
wxImage image;
wxPNGHandler handler;
- handler.LoadFile( &image, mstream );
+ if ( !handler.LoadFile( &image, mstream ) )
+ {
+ return FALSE;
+ }
+
m_bitmap = image.ConvertToBitmap();
+
+ return m_bitmap.Ok();
}
void wxBitmapDataObject::DoConvertToPng()
{
- if (!m_bitmap.Ok()) return;
-
+ if (!m_bitmap.Ok())
+ return;
+
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 = (void*) new char[m_pngSize];
-
+ m_pngData = malloc(m_pngSize);
+
wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
handler.SaveFile( &image, mstream );
}
-// ----------------------------------------------------------------------------
-// wxPrivateDataObject
-// ----------------------------------------------------------------------------
-
-IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
-
-void wxPrivateDataObject::Free()
-{
- if ( m_data )
- free(m_data);
-}
-
-wxPrivateDataObject::wxPrivateDataObject()
-{
- wxString id = wxT("application/");
- id += wxTheApp->GetAppName();
-
- m_format.SetId( id );
-
- m_size = 0;
- m_data = (void *)NULL;
-}
-
-void wxPrivateDataObject::SetData( const void *data, size_t size )
-{
- Free();
-
- m_size = size;
- m_data = malloc(size);
-
- memcpy( m_data, data, size );
-}
-
-void wxPrivateDataObject::WriteData( void *dest ) const
-{
- WriteData( m_data, dest );
-}
-
-size_t wxPrivateDataObject::GetSize() const
-{
- return m_size;
-}
-
-void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
-{
- memcpy( dest, data, GetSize() );
-}