]> git.saurik.com Git - wxWidgets.git/commitdiff
implement wxWindow::DragAcceptFiles() on all platforms
authorVáclav Slavík <vslavik@fastmail.fm>
Thu, 13 Nov 2008 22:30:40 +0000 (22:30 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Thu, 13 Nov 2008 22:30:40 +0000 (22:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/arrstr.h
include/wx/window.h
interface/wx/window.h
src/common/wincmn.cpp

index 95b9506fdc82a3a1a066728a7cff7f737a056ad2..6da3cb2a326bb478194720031eb6b024478d6e38 100644 (file)
@@ -355,6 +355,14 @@ public:
             m_strings[i] = m_array[i];
         return m_strings;
     }
+
+    wxString* Release()
+    {
+        wxString *r = GetStrings();
+        m_strings = NULL;
+        return r;
+    }
+
 private:
     const wxArrayString& m_array;
     wxString* m_strings;
index 268fee782e4f6bae95c8df159c55f1d3cc294398..fb66bf004eea193d9d4246be7c643d347674c38a 100644 (file)
@@ -1230,6 +1230,16 @@ 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; }
+
+    // Accept files for dragging
+    virtual void DragAcceptFiles(bool accept)
+#ifdef __WXMSW__
+    // it does have common implementation but not for MSW which has its own
+    // native version of it
+    = 0
+#endif // __WXMSW__
+    ;
+
 #endif // wxUSE_DRAG_AND_DROP
 
     // constraints and sizers
index bc0f7c33f5208c544f795138836f6d4776ddaf03..cbb1e4e8d09b7925a1d8fe5023f2742ff4fca5aa 100644 (file)
@@ -600,7 +600,11 @@ public:
             If @true, the window is eligible for drop file events.
             If @false, the window will not accept drop file events.
 
-        @remarks Windows only.
+        @remarks Windows only until version 2.8.9, available on all platforms
+                 since 2.8.10. Cannot be used together with SetDropTarget() on
+                 non-Windows platforms.
+
+        @see SetDropTarget()
     */
     virtual void DragAcceptFiles(bool accept);
 
index 531c674c3945a08f436c9d21938ef672942baba5..6eac63e1a929196e12349ec74dd2c74baf0694c0 100644 (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
 // ----------------------------------------------------------------------------