implement wxWindow::DragAcceptFiles() on all platforms

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2008-11-13 22:30:40 +00:00
parent 11e3af6e7e
commit 4f24cbbd3d
4 changed files with 78 additions and 1 deletions

View File

@@ -2897,6 +2897,61 @@ bool wxWindowBase::HasFocus() const
win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl();
}
// ----------------------------------------------------------------------------
// drag and drop
// ----------------------------------------------------------------------------
#if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
namespace
{
class DragAcceptFilesTarget : public wxFileDropTarget
{
public:
DragAcceptFilesTarget(wxWindowBase *win) : m_win(win) {}
virtual bool OnDropFiles(wxCoord x, wxCoord y,
const wxArrayString& filenames)
{
wxDropFilesEvent event(wxEVT_DROP_FILES,
filenames.size(),
wxCArrayString(filenames).Release());
event.SetEventObject(m_win);
event.m_pos.x = x;
event.m_pos.y = y;
return m_win->HandleWindowEvent(event);
}
private:
wxWindowBase * const m_win;
DECLARE_NO_COPY_CLASS(DragAcceptFilesTarget)
};
} // anonymous namespace
// Generic version of DragAcceptFiles(). It works by installing a simple
// wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
// together with explicit SetDropTarget() calls.
void wxWindowBase::DragAcceptFiles(bool accept)
{
if ( accept )
{
wxASSERT_MSG( !GetDropTarget(),
"cannot use DragAcceptFiles() and SetDropTarget() together" );
SetDropTarget(new DragAcceptFilesTarget(this));
}
else
{
SetDropTarget(NULL);
}
}
#endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
// ----------------------------------------------------------------------------
// global functions
// ----------------------------------------------------------------------------