]> git.saurik.com Git - wxWidgets.git/commitdiff
Use text/uri-list instead of x-moz-url in wxGTK wxURLDataObject.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jul 2012 11:55:00 +0000 (11:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jul 2012 11:55:00 +0000 (11:55 +0000)
The standard exchange format for URLs is text/uri-list and not the deprecated
and Firefox-specific x-moz-url, support for which was moreover implemented
incorrectly anyhow.

Also add an example of copying URLs to the dnd sample.

See https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types for more
information.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72159 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
samples/dnd/dnd.cpp
src/gtk/dataobj.cpp

index 003df61d6dda198c7412a610c4d79f3b26668642..9fda726f5e2b603072174fb8d97b30548d7836fd 100644 (file)
@@ -535,6 +535,7 @@ All (GUI):
 wxGTK:
 
 - Allow building wxGTK3 with Broadway backend (Kolya Kosenko).
+- Improve drag-and-drop of URLs.
 
 wxMSW:
 
index 62b65b9d9e4fd029878207e80d7d68f6ea7bd392..90662218120584f4b57dcde6ee6e8f25b9c7ed47 100644 (file)
@@ -227,6 +227,7 @@ public:
 #endif // wxUSE_METAFILE
 
     void OnCopyFiles(wxCommandEvent& event);
+    void OnCopyURL(wxCommandEvent& event);
 
     void OnUsePrimary(wxCommandEvent& event);
 
@@ -816,6 +817,7 @@ enum
     Menu_PasteBitmap,
     Menu_PasteMFile,
     Menu_CopyFiles,
+    Menu_CopyURL,
     Menu_UsePrimary,
     Menu_Shape_New = 500,
     Menu_Shape_Edit,
@@ -844,6 +846,7 @@ BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
     EVT_MENU(Menu_PasteMFile, DnDFrame::OnPasteMetafile)
 #endif // wxUSE_METAFILE
     EVT_MENU(Menu_CopyFiles,  DnDFrame::OnCopyFiles)
+    EVT_MENU(Menu_CopyURL,    DnDFrame::OnCopyURL)
     EVT_MENU(Menu_UsePrimary, DnDFrame::OnUsePrimary)
 
     EVT_UPDATE_UI(Menu_DragMoveDef, DnDFrame::OnUpdateUIMoveByDefault)
@@ -974,6 +977,7 @@ DnDFrame::DnDFrame()
 #endif // wxUSE_METAFILE
     clip_menu->AppendSeparator();
     clip_menu->Append(Menu_CopyFiles, wxT("Copy &files\tCtrl-F"));
+    clip_menu->Append(Menu_CopyURL, wxT("Copy &URL\tCtrl-U"));
     clip_menu->AppendSeparator();
     clip_menu->AppendCheckItem(Menu_UsePrimary, wxT("Use &primary selection\tCtrl-P"));
 
@@ -1485,6 +1489,27 @@ void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event))
 #endif // MSW/!MSW
 }
 
+void DnDFrame::OnCopyURL(wxCommandEvent& WXUNUSED(event))
+{
+    // Just hard code it for now, we could ask the user but the point here is
+    // to test copying URLs, it doesn't really matter what it is.
+    const wxString url("http://www.wxwidgets.org/");
+
+    wxClipboardLocker locker;
+    if ( !!locker && wxTheClipboard->AddData(new wxURLDataObject(url)) )
+    {
+        wxLogStatus(this, "Copied URL \"%s\" to %s.",
+                    url,
+                    GetMenuBar()->IsChecked(Menu_UsePrimary)
+                        ? "primary selection"
+                        : "clipboard");
+    }
+    else
+    {
+        wxLogError("Failed to copy URL.");
+    }
+}
+
 // ---------------------------------------------------------------------------
 // text clipboard
 // ---------------------------------------------------------------------------
index c742b77f156bf2ce5fe1c9caaa35809b1aecf1f2..55c81cfc77e19b8dd6ecebf35109645e854a400d 100644 (file)
@@ -421,45 +421,26 @@ void wxBitmapDataObject::DoConvertToPng()
 // ----------------------------------------------------------------------------
 
 wxURLDataObject::wxURLDataObject(const wxString& url) :
-   wxDataObjectSimple( wxDataFormat( gdk_atom_intern("text/x-moz-url",FALSE) ) )
+   wxDataObjectSimple( wxDataFormat( g_fileAtom ) )
 {
    m_url = url;
 }
 
 size_t wxURLDataObject::GetDataSize() const
 {
-    if (m_url.empty())
-        return 0;
-
-    return 2*m_url.Len()+2;
+    return strlen(m_url.utf8_str()) + 1;
 }
 
 bool wxURLDataObject::GetDataHere(void *buf) const
 {
-    if (m_url.empty())
-        return false;
-
-    wxCSConv conv( "UCS2" );
-    conv.FromWChar( (char*) buf, 2*m_url.Len()+2, m_url.wc_str() );
+    strcpy(static_cast<char*>(buf), m_url.utf8_str());
 
     return true;
 }
 
-    // copy data from buffer to our data
 bool wxURLDataObject::SetData(size_t len, const void *buf)
 {
-    if (len == 0)
-    {
-        m_url = wxEmptyString;
-        return false;
-    }
-
-    wxCSConv conv( "UCS2" );
-    wxWCharBuffer res = conv.cMB2WC( (const char*) buf );
-    m_url = res;
-    int pos = m_url.Find( '\n' );
-    if (pos != wxNOT_FOUND)
-        m_url.Remove( pos, m_url.Len() - pos );
+    m_url = wxString::FromUTF8(static_cast<const char*>(buf), len);
 
     return true;
 }