]> git.saurik.com Git - wxWidgets.git/commitdiff
wxFileDataObject supports GNOME file dnd now
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Nov 1999 17:58:56 +0000 (17:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Nov 1999 17:58:56 +0000 (17:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dnd/dnd.cpp
src/gtk/dataobj.cpp
src/gtk/dnd.cpp
src/gtk1/dataobj.cpp
src/gtk1/dnd.cpp

index f747e454a357452087aeac347e9b129faf152115..9e22d58e8a28db7c2001e21eba594745303f4c7a 100644 (file)
@@ -693,7 +693,7 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
     file_menu->Append(Menu_Quit, "E&xit");
 
     wxMenu *log_menu = new wxMenu;
     file_menu->Append(Menu_Quit, "E&xit");
 
     wxMenu *log_menu = new wxMenu;
-    log_menu->Append(Menu_Clear, "Clear\tDel");
+    log_menu->Append(Menu_Clear, "Clear\tCtrl-L");
 
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(Menu_Help, "&Help...");
 
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(Menu_Help, "&Help...");
@@ -869,6 +869,8 @@ void DnDFrame::OnHelp(wxCommandEvent& /* event */)
 void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
 {
     m_ctrlLog->Clear();
 void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
 {
     m_ctrlLog->Clear();
+    m_ctrlText->Clear();
+    m_ctrlFile->Clear();
 }
 
 void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
 }
 
 void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
@@ -879,16 +881,16 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
         wxTextDataObject textData(m_strText);
 /*
         wxFileDataObject textData;
         wxTextDataObject textData(m_strText);
 /*
         wxFileDataObject textData;
-       textData.AddFile( "/file1.txt" );
-       textData.AddFile( "/file2.txt" );
+        textData.AddFile( "/file1.txt" );
+        textData.AddFile( "/file2.txt" );
 */
         wxDropSource source(textData, this
 #ifdef __WXMSW__
 */
         wxDropSource source(textData, this
 #ifdef __WXMSW__
-                            ,wxCURSOR_PENCIL,            // for copy
+                            ,wxCURSOR_PENCIL,           // for copy
                             wxCURSOR_SPRAYCAN,          // for move
                             wxCURSOR_SPRAYCAN,          // for move
-                            wxCURSOR_QUESTION_ARROW   // for nothing
+                            wxCURSOR_QUESTION_ARROW     // for nothing
 #endif
 #endif
-                           );
+                            );
 
         const char *pc;
 
 
         const char *pc;
 
index fd40e35976ffad586af49c55929ac953bbeb10c5..41fd7843a1d426ff26c307ca21c549912767d92e 100644 (file)
@@ -126,12 +126,14 @@ void wxDataFormat::SetId( const wxChar *id )
 
 void wxDataFormat::PrepareFormats()
 {
 
 void wxDataFormat::PrepareFormats()
 {
+    // VZ: GNOME included in RedHat 6.1 uses the MIME types below and not the
+    //     atoms STRING and file:ALL as the old code was
     if (!g_textAtom)
     if (!g_textAtom)
-        g_textAtom = gdk_atom_intern( "STRING", FALSE );
+        g_textAtom = gdk_atom_intern( "text/plain", FALSE );
     if (!g_pngAtom)
         g_pngAtom = gdk_atom_intern( "image/png", FALSE );
     if (!g_fileAtom)
     if (!g_pngAtom)
         g_pngAtom = gdk_atom_intern( "image/png", FALSE );
     if (!g_fileAtom)
-        g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
+        g_fileAtom = gdk_atom_intern( "text/uri-list", FALSE );
 }
 
 //-------------------------------------------------------------------------
 }
 
 //-------------------------------------------------------------------------
@@ -199,21 +201,51 @@ size_t wxFileDataObject::GetDataSize() const
 
 bool wxFileDataObject::SetData(size_t size, const void *buf)
 {
 
 bool wxFileDataObject::SetData(size_t size, const void *buf)
 {
+    // VZ: old format
+#if 0
     // filenames are stores as a string with #0 as deliminators
     // filenames are stores as a string with #0 as deliminators
-
     const char *filenames = (const char*) buf;
     size_t pos = 0;
     for(;;)
     {
         if (filenames[0] == 0)
     const char *filenames = (const char*) buf;
     size_t pos = 0;
     for(;;)
     {
         if (filenames[0] == 0)
-           break;
-       if (pos >= size)
-           break;
+            break;
+        if (pos >= size)
+            break;
         wxString file( filenames );  // this returns the first file
         AddFile( file );
         wxString file( filenames );  // this returns the first file
         AddFile( file );
-       pos += file.Len()+1;
-       filenames += file.Len()+1;
+        pos += file.Len()+1;
+        filenames += file.Len()+1;
+    }
+#else // 1
+    m_filenames.Empty();
+
+    // the text/uri-list format is a sequence of URIs (filenames prefixed by
+    // "file:" as far as I see) delimited by "\r\n" of total length size
+    // (I wonder what happens if the file has '\n' in its filename??)
+    wxString filename;
+    for ( const char *p = (const char *)buf; *p; p++ )
+    {
+        if ( *p == '\r' && *(p+1) == '\n' )
+        {
+            static const int lenPrefix = 5; // strlen("file:")
+            if ( filename.Left(lenPrefix).MakeLower() == _T("file:") )
+            {
+                filename.erase(0, lenPrefix);
+            }
+
+            AddFile(filename);
+            filename.Empty();
+
+            // skip '\r'
+            p++;
+        }
+        else
+        {
+            filename += *p;
+        }
     }
     }
+#endif // 0/1
 
     return TRUE;
 }
 
     return TRUE;
 }
index 0b15ec204088fe7d088d241185bdcbca09c898c1..e8e4232a2a81fc456350d614a5345ef69bec9266 100644 (file)
@@ -359,7 +359,7 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
 
     // disable the debug message from GetMatchingPair() - there are too many
     // of them otherwise
 
     // disable the debug message from GetMatchingPair() - there are too many
     // of them otherwise
-#ifdef __WXDEBUG__
+#if 0 //def __WXDEBUG__
     wxLogNull noLog;
 #endif // Debug
 
     wxLogNull noLog;
 #endif // Debug
 
index fd40e35976ffad586af49c55929ac953bbeb10c5..41fd7843a1d426ff26c307ca21c549912767d92e 100644 (file)
@@ -126,12 +126,14 @@ void wxDataFormat::SetId( const wxChar *id )
 
 void wxDataFormat::PrepareFormats()
 {
 
 void wxDataFormat::PrepareFormats()
 {
+    // VZ: GNOME included in RedHat 6.1 uses the MIME types below and not the
+    //     atoms STRING and file:ALL as the old code was
     if (!g_textAtom)
     if (!g_textAtom)
-        g_textAtom = gdk_atom_intern( "STRING", FALSE );
+        g_textAtom = gdk_atom_intern( "text/plain", FALSE );
     if (!g_pngAtom)
         g_pngAtom = gdk_atom_intern( "image/png", FALSE );
     if (!g_fileAtom)
     if (!g_pngAtom)
         g_pngAtom = gdk_atom_intern( "image/png", FALSE );
     if (!g_fileAtom)
-        g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
+        g_fileAtom = gdk_atom_intern( "text/uri-list", FALSE );
 }
 
 //-------------------------------------------------------------------------
 }
 
 //-------------------------------------------------------------------------
@@ -199,21 +201,51 @@ size_t wxFileDataObject::GetDataSize() const
 
 bool wxFileDataObject::SetData(size_t size, const void *buf)
 {
 
 bool wxFileDataObject::SetData(size_t size, const void *buf)
 {
+    // VZ: old format
+#if 0
     // filenames are stores as a string with #0 as deliminators
     // filenames are stores as a string with #0 as deliminators
-
     const char *filenames = (const char*) buf;
     size_t pos = 0;
     for(;;)
     {
         if (filenames[0] == 0)
     const char *filenames = (const char*) buf;
     size_t pos = 0;
     for(;;)
     {
         if (filenames[0] == 0)
-           break;
-       if (pos >= size)
-           break;
+            break;
+        if (pos >= size)
+            break;
         wxString file( filenames );  // this returns the first file
         AddFile( file );
         wxString file( filenames );  // this returns the first file
         AddFile( file );
-       pos += file.Len()+1;
-       filenames += file.Len()+1;
+        pos += file.Len()+1;
+        filenames += file.Len()+1;
+    }
+#else // 1
+    m_filenames.Empty();
+
+    // the text/uri-list format is a sequence of URIs (filenames prefixed by
+    // "file:" as far as I see) delimited by "\r\n" of total length size
+    // (I wonder what happens if the file has '\n' in its filename??)
+    wxString filename;
+    for ( const char *p = (const char *)buf; *p; p++ )
+    {
+        if ( *p == '\r' && *(p+1) == '\n' )
+        {
+            static const int lenPrefix = 5; // strlen("file:")
+            if ( filename.Left(lenPrefix).MakeLower() == _T("file:") )
+            {
+                filename.erase(0, lenPrefix);
+            }
+
+            AddFile(filename);
+            filename.Empty();
+
+            // skip '\r'
+            p++;
+        }
+        else
+        {
+            filename += *p;
+        }
     }
     }
+#endif // 0/1
 
     return TRUE;
 }
 
     return TRUE;
 }
index 0b15ec204088fe7d088d241185bdcbca09c898c1..e8e4232a2a81fc456350d614a5345ef69bec9266 100644 (file)
@@ -359,7 +359,7 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
 
     // disable the debug message from GetMatchingPair() - there are too many
     // of them otherwise
 
     // disable the debug message from GetMatchingPair() - there are too many
     // of them otherwise
-#ifdef __WXDEBUG__
+#if 0 //def __WXDEBUG__
     wxLogNull noLog;
 #endif // Debug
 
     wxLogNull noLog;
 #endif // Debug