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
This commit is contained in:
Vadim Zeitlin
2001-08-16 23:46:56 +00:00
parent 2b260bc3e2
commit 444ad3a719
6 changed files with 121 additions and 15 deletions

View File

@@ -445,14 +445,23 @@ private:
#if defined(__WXMSW__) #if defined(__WXMSW__)
#include "wx/msw/ole/dataobj2.h" #include "wx/msw/ole/dataobj2.h"
#elif defined(__WXMOTIF__)
// #include "wx/motif/dataobj2.h" -- not yet // wxURLDataObject defined in msw/ole/dataobj2.h
#elif defined(__WXGTK__) #else // !__WXMSW__
#include "wx/gtk/dataobj2.h" #if defined(__WXGTK__)
#elif defined(__WXMAC__) #include "wx/gtk/dataobj2.h"
#include "wx/mac/dataobj2.h" #elif defined(__WXMAC__)
#elif defined(__WXPM__) #include "wx/mac/dataobj2.h"
#include "wx/os2/dataobj2.h" #elif defined(__WXPM__)
#endif #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_

View File

@@ -40,13 +40,13 @@ public:
bool IsSupportedFormat(const wxDataFormat& format) const bool IsSupportedFormat(const wxDataFormat& format) const
{ return wxDataObjectBase::IsSupported(format, Get); } { 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); static const wxChar *GetFormatName(wxDataFormat format);
#define wxGetFormatName(format) wxDataObject::GetFormatName(format) #define wxGetFormatName(format) wxDataObject::GetFormatName(format)
#else // !Debug #else // !Debug
#define wxGetFormatName(format) "" #define wxGetFormatName(format) _T("")
#endif // Debug/!Debug #endif // Debug/!Debug
private: private:

View 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

View 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_pLog = new wxLogTextCtrl(m_ctrlLog);
m_pLogPrev = wxLog::SetActiveTarget(m_pLog); 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_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
m_ctrlText->SetDropTarget(new DnDText(m_ctrlText)); m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
m_ctrlLog->SetDropTarget(new URLDropTarget);
wxLayoutConstraints *c; wxLayoutConstraints *c;

View 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
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -148,7 +148,7 @@ STDMETHODIMP wxIDropTarget::DragEnter(IDataObject *pIDataSource,
_T("drop target must have data object") ); _T("drop target must have data object") );
// show the list of formats supported by the source data object for the // 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 #if 0
IEnumFORMATETC *penumFmt; IEnumFORMATETC *penumFmt;
if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) ) if ( SUCCEEDED(pIDataSource->EnumFormatEtc(DATADIR_GET, &penumFmt)) )
@@ -402,11 +402,11 @@ bool wxDropTarget::GetData()
rc = TRUE; rc = TRUE;
} }
else { 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;