diff --git a/docs/changes.txt b/docs/changes.txt index 7bcc054f41..5f300ce498 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -104,6 +104,7 @@ All (GUI): single-cell paragraphs. - Fixed wxHTML's line breaks handling in
blocks broken in 2.8.8 (#10120). - wxHTML: don't include extra whitespace in table cells. +- Implemented wxWindow::DragAcceptFiles() on all platforms. All (Unix): diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index cfd6427835..d8705ddb18 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -567,7 +567,9 @@ will not accept drop file events.} \wxheading{Remarks} -Windows only. +Windows only until version 2.8.9, available on all platforms since 2.8.10. +Cannot be used together with \helpref{SetDropTarget}{wxwindowsetdroptarget} on +non-Windows platforms. \membersection{wxWindow::Enable}\label{wxwindowenable} diff --git a/include/wx/arrstr.h b/include/wx/arrstr.h index 18d7651c4f..9ad3b4a445 100644 --- a/include/wx/arrstr.h +++ b/include/wx/arrstr.h @@ -364,6 +364,11 @@ public: m_strings[i] = m_array[i]; return m_strings; } + +#if wxABI_VERSION >= 20810 + wxString* Release(); +#endif // wxABI_VERSION >= 20810 + private: const wxArrayString& m_array; wxString* m_strings; diff --git a/include/wx/window.h b/include/wx/window.h index a6bdc327d4..5cf0b3abc0 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1027,6 +1027,14 @@ public: // NULL; it's owned by the window and will be deleted by it) virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0; virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; } + +#ifndef __WXMSW__ // MSW version is in msw/window.h +#if wxABI_VERSION >= 20810 + // Accept files for dragging + void DragAcceptFiles(bool accept); +#endif // wxABI_VERSION >= 20810 +#endif // !__WXMSW__ + #endif // wxUSE_DRAG_AND_DROP // constraints and sizers diff --git a/src/common/string.cpp b/src/common/string.cpp index 7556a54396..166769dd4b 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -2645,3 +2645,10 @@ int wxCMPFUNC_CONV wxStringSortDescending(wxString* s1, wxString* s2) { return -s1->Cmp(*s2); } + +wxString* wxCArrayString::Release() +{ + wxString *r = GetStrings(); + m_strings = NULL; + return r; +} diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 3f81a0af3f..295817c842 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2749,6 +2749,56 @@ void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move) return win ? win->GetMainWindowOfCompositeControl() : NULL; } +// ---------------------------------------------------------------------------- +// drag and drop +// ---------------------------------------------------------------------------- + +#if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) + +class wxDragAcceptFilesImplTarget : public wxFileDropTarget +{ +public: + wxDragAcceptFilesImplTarget(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->GetEventHandler()->ProcessEvent(event); + } + +private: + wxWindowBase * const m_win; + + DECLARE_NO_COPY_CLASS(wxDragAcceptFilesImplTarget) +}; + + +// 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(), + _T("cannot use DragAcceptFiles() and SetDropTarget() together") ); + SetDropTarget(new wxDragAcceptFilesImplTarget(this)); + } + else + { + SetDropTarget(NULL); + } +} + +#endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) + // ---------------------------------------------------------------------------- // global functions // ---------------------------------------------------------------------------- diff --git a/version-script.in b/version-script.in index c6323327f9..dbb63c669d 100644 --- a/version-script.in +++ b/version-script.in @@ -25,7 +25,9 @@ # public symbols added in 2.8.10 (please keep in alphabetical order): @WX_VERSION_TAG@.10 { + *wxCArrayString*Release*; *wxDCBase*GetFontPointSizeAdjustment*; + *wxWindowBase*DragAcceptFiles*; }; # public symbols added in 2.8.9 (please keep in alphabetical order):