]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/dataobj.cpp
Corrected small mistake (set static variable)
[wxWidgets.git] / src / gtk1 / dataobj.cpp
index dc7effd7477fb4abcebe67a95b4533294cab031c..c7d29816cb8230bb373043204240b7ddf25eaeba 100644 (file)
@@ -33,7 +33,14 @@ GdkAtom  g_fileAtom        = 0;
 
 wxDataFormat::wxDataFormat()
 {
-    PrepareFormats();
+    // do *not* call PrepareFormats() from here for 2 reasons:
+    //
+    // 1. we will have time to do it later because some other Set function
+    //    must be called before we really need them
+    //
+    // 2. doing so prevents us from declaring global wxDataFormats because
+    //    calling PrepareFormats (and thus gdk_atom_intern) before GDK is
+    //    initialised will result in a crash
     m_type = wxDF_INVALID;
     m_format = (GdkAtom) 0;
 }
@@ -64,6 +71,7 @@ wxDataFormat::wxDataFormat( NativeFormat format )
 
 void wxDataFormat::SetType( wxDataFormatId type )
 {
+    PrepareFormats();
     m_type = type;
 
     if (m_type == wxDF_TEXT)
@@ -93,6 +101,7 @@ wxString wxDataFormat::GetId() const
 
 void wxDataFormat::SetId( NativeFormat format )
 {
+    PrepareFormats();
     m_format = format;
 
     if (m_format == g_textAtom)
@@ -109,6 +118,7 @@ void wxDataFormat::SetId( NativeFormat format )
 
 void wxDataFormat::SetId( const wxChar *id )
 {
+    PrepareFormats();
     m_type = wxDF_PRIVATE;
     wxString tmp( id );
     m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );  // what is the string cast for?
@@ -128,25 +138,19 @@ void wxDataFormat::PrepareFormats()
 // wxDataObject
 //-------------------------------------------------------------------------
 
-IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
-
 wxDataObject::wxDataObject()
 {
 }
 
-wxDataObject::~wxDataObject()
-{
-}
-
-bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
+bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) 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++ ) {
@@ -167,7 +171,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
 
 bool wxFileDataObject::GetDataHere(void *buf) const
 {
-    const wxString& filenames = GetFilenames();
+    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 );
 
     return TRUE;
@@ -175,16 +186,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const
 
 size_t wxFileDataObject::GetDataSize() const
 {
-    return GetFilenames().Len() + 1;
+    size_t res = 0;
+
+    for (size_t i = 0; i < m_filenames.GetCount(); i++)
+    {
+        res += m_filenames[i].Len();
+        res += 1;
+    }
+
+    return res + 1;
 }
 
-bool wxFileDataObject::SetData(const void *buf)
+bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
 {
-    SetFilenames((const wxChar *)buf);
+    /* TODO */
+
+    wxString file( (const char *)buf );  /* char, not wxChar */
+
+    AddFile( file );
 
     return TRUE;
 }
 
+void wxFileDataObject::AddFile( const wxString &filename )
+{
+   m_filenames.Add( filename );
+}
+
 // ----------------------------------------------------------------------------
 // wxBitmapDataObject
 // ----------------------------------------------------------------------------
@@ -248,6 +276,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf)
     }
 
     m_bitmap = image.ConvertToBitmap();
+
+    return m_bitmap.Ok();
 }
 
 void wxBitmapDataObject::DoConvertToPng()
@@ -268,51 +298,4 @@ void wxBitmapDataObject::DoConvertToPng()
     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() );
-}