]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxURLDataObject which unfortunately doesn't seem to work
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 Aug 2001 23:46:56 +0000 (23:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 Aug 2001 23:46:56 +0000 (23:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11398 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataobj.h
include/wx/msw/ole/dataobj.h
include/wx/msw/ole/dataobj2.h
samples/dnd/dnd.cpp
src/msw/ole/dataobj.cpp
src/msw/ole/droptgt.cpp

index e7042d2b07310580b918a6c197dfa27e74823991..e1f345e2d92fa98480bd3dd2581347f9b24c9bdc 100644 (file)
@@ -445,14 +445,23 @@ private:
 
 #if defined(__WXMSW__)
     #include "wx/msw/ole/dataobj2.h"
 
 #if defined(__WXMSW__)
     #include "wx/msw/ole/dataobj2.h"
-#elif defined(__WXMOTIF__)
-    // #include "wx/motif/dataobj2.h" -- not yet
-#elif defined(__WXGTK__)
-    #include "wx/gtk/dataobj2.h"
-#elif defined(__WXMAC__)
-    #include "wx/mac/dataobj2.h"
-#elif defined(__WXPM__)
-    #include "wx/os2/dataobj2.h"
-#endif
+
+    // wxURLDataObject defined in msw/ole/dataobj2.h
+#else // !__WXMSW__
+    #if defined(__WXGTK__)
+        #include "wx/gtk/dataobj2.h"
+    #elif defined(__WXMAC__)
+        #include "wx/mac/dataobj2.h"
+    #elif defined(__WXPM__)
+        #include "wx/os2/dataobj2.h"
+    #endif
+
+    // wxURLDataObject is simply wxTextDataObject with a different name
+    class WXDLLEXPORT wxURLDataObject : public wxTextDataObject
+    {
+    public:
+        wxString GetURL() const { return GetText(); }
+    };
+#endif // __WXMSW__/!__WXMSW__
 
 #endif // _WX_DATAOBJ_H_BASE_
 
 #endif // _WX_DATAOBJ_H_BASE_
index 41b013a9e8335f5cdd4821b8e5cd1e07d7abbb39..9c036b330d24a5dd0ae39469106cfff7e3816350 100644 (file)
@@ -40,13 +40,13 @@ public:
     bool IsSupportedFormat(const wxDataFormat& format) const
         { return wxDataObjectBase::IsSupported(format, Get); }
 
     bool IsSupportedFormat(const wxDataFormat& format) const
         { return wxDataObjectBase::IsSupported(format, Get); }
 
-#ifdef __WXDEBUG__
     // function to return symbolic name of clipboard format (for debug messages)
     // function to return symbolic name of clipboard format (for debug messages)
+#ifdef __WXDEBUG__
     static const wxChar *GetFormatName(wxDataFormat format);
 
     #define wxGetFormatName(format) wxDataObject::GetFormatName(format)
 #else // !Debug
     static const wxChar *GetFormatName(wxDataFormat format);
 
     #define wxGetFormatName(format) wxDataObject::GetFormatName(format)
 #else // !Debug
-    #define wxGetFormatName(format) ""
+    #define wxGetFormatName(format) _T("")
 #endif // Debug/!Debug
 
 private:
 #endif // Debug/!Debug
 
 private:
index af68898d3cd2d26d8f647ba7d31c771a4f2f69de..7fdfa70f97b75c8ef14ba1ec0131c61432e8ee5c 100644 (file)
@@ -78,4 +78,26 @@ public:
     virtual void AddFile(const wxString& file);
 };
 
     virtual void AddFile(const wxString& file);
 };
 
+// ----------------------------------------------------------------------------
+// wxURLDataObject: data object for URLs
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxURLDataObject : public wxDataObjectComposite
+{
+public:
+    wxURLDataObject();
+
+    // return the URL as string
+    wxString GetURL() const;
+
+    // override to set m_textFormat
+    virtual bool SetData(const wxDataFormat& format,
+                         size_t len,
+                         const void *buf);
+
+private:
+    // last data object we got data in
+    wxDataObjectSimple *m_dataObjectLast;
+};
+
 #endif // _WX_MSW_OLE_DATAOBJ2_H
 #endif // _WX_MSW_OLE_DATAOBJ2_H
index 96b14ad47786c19f77be79290dcc923360133013..4f5f76d60e970869f1e59b6e5ec8210676a34d1c 100644 (file)
@@ -80,6 +80,39 @@ private:
     wxListBox *m_pOwner;
 };
 
     wxListBox *m_pOwner;
 };
 
+// ----------------------------------------------------------------------------
+// Define a custom dtop target accepting URLs
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT URLDropTarget : public wxDropTarget
+{
+public:
+    URLDropTarget() { SetDataObject(new wxURLDataObject); }
+
+    void OnDropURL(wxCoord x, wxCoord y, const wxString& text)
+    {
+        // of course, a real program would do something more useful here...
+        wxMessageBox(text, _T("wxDnD sample: got URL"),
+                     wxICON_INFORMATION | wxOK);
+    }
+
+    // URLs can't be moved, only copied
+    virtual wxDragResult OnDragOver(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
+                                    wxDragResult def)
+        { return def == wxDragMove ? wxDragCopy : def; }
+
+    // translate this to calls to OnDropURL() just for convenience
+    virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
+    {
+        if ( !GetData() )
+            return wxDragNone;
+
+        OnDropURL(x, y, ((wxURLDataObject *)m_dataObject)->GetURL());
+
+        return def;
+    }
+};
+
 // ----------------------------------------------------------------------------
 // Define a new application type
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Define a new application type
 // ----------------------------------------------------------------------------
@@ -921,9 +954,10 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
     m_pLog = new wxLogTextCtrl(m_ctrlLog);
     m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
 
     m_pLog = new wxLogTextCtrl(m_ctrlLog);
     m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
 
-    // associate drop targets with 2 text controls
+    // associate drop targets with the controls
     m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
     m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
     m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
     m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
+    m_ctrlLog->SetDropTarget(new URLDropTarget);
 
     wxLayoutConstraints *c;
 
 
     wxLayoutConstraints *c;
 
index 7d55fcd05bd0faab0a1213d55b7a921241b1fccf..72776682a698e47047f10c43403f3f5c90975dba 100644 (file)
@@ -1035,6 +1035,47 @@ bool wxFileDataObject::GetDataHere(void *pData) const
     return TRUE;
 }
 
     return TRUE;
 }
 
+// ----------------------------------------------------------------------------
+// wxURLDataObject
+// ----------------------------------------------------------------------------
+
+wxURLDataObject::wxURLDataObject()
+{
+    // we support CF_TEXT and CFSTR_SHELLURL formats which are basicly the same
+    // but it seems that some browsers only provideo ne of them so we have to
+    // support both
+    Add(new wxCustomDataObject(CFSTR_SHELLURL));
+    Add(new wxTextDataObject);
+
+    // we don't have any data yet
+    m_dataObjectLast = NULL;
+}
+
+bool wxURLDataObject::SetData(const wxDataFormat& format,
+                              size_t len,
+                              const void *buf)
+{
+    m_dataObjectLast = GetObject(format);
+
+    wxCHECK_MSG( m_dataObjectLast, FALSE,
+                 wxT("unsupported format in wxURLDataObject"));
+
+    return m_dataObjectLast->SetData(len, buf);
+}
+
+wxString wxURLDataObject::GetURL() const
+{
+    wxString url;
+    wxCHECK_MSG( m_dataObjectLast, url, _T("no data in wxURLDataObject") );
+
+    size_t len = m_dataObjectLast->GetDataSize();
+
+    m_dataObjectLast->GetDataHere(url.GetWriteBuf(len + 1));
+    url.UngetWriteBuf();
+
+    return url;
+}
+
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
index 8bc18646cdaf746ee8c2315e99ed65632639f754..20e505910c03fc6587291d93392d6bc0aac74b88 100644 (file)
@@ -148,7 +148,7 @@ STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource,
                   _T("drop target must have data object") );
 
     // show the list of formats supported by the source data object for the
                   _T("drop target must have data object") );
 
     // show the list of formats supported by the source data object for the
-    // debugging purposes
+    // debugging purposes, this is quite useful sometimes - please don't remove
 #if 0
     IEnumFORMATETC *penumFmt;
     if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) )
 #if 0
     IEnumFORMATETC *penumFmt;
     if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) )
@@ -402,11 +402,11 @@ bool wxDropTarget::GetData()
             rc = TRUE;
         }
         else {
             rc = TRUE;
         }
         else {
-            wxLogLastError(wxT("IDataObject::SetData()"));
+            wxLogApiError(wxT("IDataObject::SetData()"), hr);
         }
     }
     else {
         }
     }
     else {
-        wxLogLastError(wxT("IDataObject::GetData()"));
+        wxLogApiError(wxT("IDataObject::GetData()"), hr);
     }
 
     return rc;
     }
 
     return rc;