]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed wxDropFilesEvent dtor, added copy ctor and implemented Clone() for it
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 21 Nov 2001 23:48:49 +0000 (23:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 21 Nov 2001 23:48:49 +0000 (23:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12570 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/event.h
src/msw/window.cpp

index 92f0ef19b1bce45f8867e6eee9cb7611b8b7f3b9..b96e4458be3fc4d61290c4460d83a8f0f1474218 100644 (file)
@@ -1284,18 +1284,35 @@ class WXDLLEXPORT wxDropFilesEvent : public wxEvent
 public:
     int       m_noFiles;
     wxPoint   m_pos;
-    wxString* m_files;        // Memory (de)allocated by code calling ProcessEvent
+    wxString* m_files;
 
     wxDropFilesEvent(wxEventType type = wxEVT_NULL,
                      int noFiles = 0,
                      wxString *files = (wxString *) NULL)
         { m_eventType = type; m_noFiles = noFiles; m_files = files; }
 
+    // we need a copy ctor to avoid deleting m_files pointer twice
+    wxDropFilesEvent(const wxDropFilesEvent& other)
+        : m_pos(other.m_pos)
+    {
+        m_noFiles = other.m_noFiles;
+        m_files = new wxString[m_noFiles];
+        for ( int n = 0; n < m_noFiles; n++ )
+        {
+            m_files[n] = other.m_files[n];
+        }
+    }
+
+    virtual ~wxDropFilesEvent()
+    {
+        delete [] m_files;
+    }
+
     wxPoint GetPosition() const { return m_pos; }
     int GetNumberOfFiles() const { return m_noFiles; }
     wxString *GetFiles() const { return m_files; }
 
-    virtual wxEvent *Clone() const { wxFAIL_MSG("error"); return NULL; }
+    virtual wxEvent *Clone() const { return new wxDropFilesEvent(*this); }
 
 private:
     DECLARE_DYNAMIC_CLASS(wxDropFilesEvent)
index fa407353a86094345c0d453e57a4aafb67cc5542..10d88547e1da44228fb3beaf2eaaa90ef0305d1d 100644 (file)
@@ -3063,11 +3063,9 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
 {
 #ifndef __WXMICROWIN__
     HDROP hFilesInfo = (HDROP) wParam;
-    POINT dropPoint;
-    DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
 
     // Get the total number of files dropped
-    WORD gwFilesDropped = (WORD)::DragQueryFile
+    UINT gwFilesDropped = ::DragQueryFile
                             (
                                 (HDROP)hFilesInfo,
                                 (UINT)-1,
@@ -3076,24 +3074,28 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
                             );
 
     wxString *files = new wxString[gwFilesDropped];
-    int wIndex;
-    for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
+    for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ )
     {
-        DragQueryFile (hFilesInfo, wIndex, (LPTSTR) wxBuffer, 1000);
-        files[wIndex] = wxBuffer;
+        // first get the needed buffer length (+1 for terminating NUL)
+        size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1;
+
+        // and now get the file name
+        ::DragQueryFile(hFilesInfo, wIndex,
+                        files[wIndex].GetWriteBuf(len), len);
+
+        files[wIndex].UngetWriteBuf();
     }
     DragFinish (hFilesInfo);
 
     wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
     event.m_eventObject = this;
+
+    POINT dropPoint;
+    DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
     event.m_pos.x = dropPoint.x;
     event.m_pos.y = dropPoint.y;
 
-    bool rc = GetEventHandler()->ProcessEvent(event);
-
-    delete[] files;
-
-    return rc;
+    return GetEventHandler()->ProcessEvent(event);
 #else // __WXMICROWIN__
     return FALSE;
 #endif