From 444ad3a71961ee9b131bfc4a8f99d0c53fd79093 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 16 Aug 2001 23:46:56 +0000 Subject: [PATCH] added wxURLDataObject which unfortunately doesn't seem to work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11398 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataobj.h | 27 +++++++++++++++-------- include/wx/msw/ole/dataobj.h | 4 ++-- include/wx/msw/ole/dataobj2.h | 22 +++++++++++++++++++ samples/dnd/dnd.cpp | 36 +++++++++++++++++++++++++++++- src/msw/ole/dataobj.cpp | 41 +++++++++++++++++++++++++++++++++++ src/msw/ole/droptgt.cpp | 6 ++--- 6 files changed, 121 insertions(+), 15 deletions(-) diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index e7042d2b07..e1f345e2d9 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -445,14 +445,23 @@ private: #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_ diff --git a/include/wx/msw/ole/dataobj.h b/include/wx/msw/ole/dataobj.h index 41b013a9e8..9c036b330d 100644 --- a/include/wx/msw/ole/dataobj.h +++ b/include/wx/msw/ole/dataobj.h @@ -40,13 +40,13 @@ public: bool IsSupportedFormat(const wxDataFormat& format) const { return wxDataObjectBase::IsSupported(format, Get); } -#ifdef __WXDEBUG__ // 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 - #define wxGetFormatName(format) "" + #define wxGetFormatName(format) _T("") #endif // Debug/!Debug private: diff --git a/include/wx/msw/ole/dataobj2.h b/include/wx/msw/ole/dataobj2.h index af68898d3c..7fdfa70f97 100644 --- a/include/wx/msw/ole/dataobj2.h +++ b/include/wx/msw/ole/dataobj2.h @@ -78,4 +78,26 @@ public: 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 diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 96b14ad477..4f5f76d60e 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -80,6 +80,39 @@ private: 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 // ---------------------------------------------------------------------------- @@ -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); - // 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_ctrlLog->SetDropTarget(new URLDropTarget); wxLayoutConstraints *c; diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 7d55fcd05b..72776682a6 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -1035,6 +1035,47 @@ bool wxFileDataObject::GetDataHere(void *pData) const 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 // ---------------------------------------------------------------------------- diff --git a/src/msw/ole/droptgt.cpp b/src/msw/ole/droptgt.cpp index 8bc18646cd..20e505910c 100644 --- a/src/msw/ole/droptgt.cpp +++ b/src/msw/ole/droptgt.cpp @@ -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 - // debugging purposes + // debugging purposes, this is quite useful sometimes - please don't remove #if 0 IEnumFORMATETC *penumFmt; if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) ) @@ -402,11 +402,11 @@ bool wxDropTarget::GetData() rc = TRUE; } else { - wxLogLastError(wxT("IDataObject::SetData()")); + wxLogApiError(wxT("IDataObject::SetData()"), hr); } } else { - wxLogLastError(wxT("IDataObject::GetData()")); + wxLogApiError(wxT("IDataObject::GetData()"), hr); } return rc; -- 2.47.2