]> git.saurik.com Git - wxWidgets.git/commitdiff
additions for wxFileDataObject from Ricky Gonzales <gonzales@pyramid3.net>
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 1999 16:20:40 +0000 (16:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 2 Nov 1999 16:20:40 +0000 (16:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4306 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/ole/dataobj2.h
src/msw/ole/dataobj.cpp

index 5bb231f9f0773533494bdfbd4496e26f5ad37954..af68898d3cd2d26d8f647ba7d31c771a4f2f69de 100644 (file)
@@ -73,6 +73,9 @@ class WXDLLEXPORT wxFileDataObject : public wxFileDataObjectBase
 public:
     // implement base class pure virtuals
     virtual bool SetData(size_t len, const void *buf);
 public:
     // implement base class pure virtuals
     virtual bool SetData(size_t len, const void *buf);
+    virtual size_t GetDataSize() const;
+    virtual bool GetDataHere(void *pData) const;
+    virtual void AddFile(const wxString& file);
 };
 
 #endif // _WX_MSW_OLE_DATAOBJ2_H
 };
 
 #endif // _WX_MSW_OLE_DATAOBJ2_H
index ded97ac472f39dc9bf5b29cb7dea346bdde41a1c..90e8ab88cb4f61276bd13548804b2bed1e1ac9ed 100644 (file)
@@ -48,6 +48,8 @@
   #include <olestd.h>
 #endif
 
   #include <olestd.h>
 #endif
 
+#include <shlobj.h>
+
 #include  "wx/msw/ole/oleutils.h"
 
 // ----------------------------------------------------------------------------
 #include  "wx/msw/ole/oleutils.h"
 
 // ----------------------------------------------------------------------------
@@ -946,6 +948,68 @@ bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *pData)
     return TRUE;
 }
 
     return TRUE;
 }
 
+void wxFileDataObject::AddFile(const wxString& file)
+{
+    // just add file to filenames array
+    // all useful data (such as DROPFILES struct) will be
+    // created later as necessary
+    m_filenames.Add(file);
+}
+
+size_t wxFileDataObject::GetDataSize() const
+{
+    // size returned will be the size of the DROPFILES structure,
+    // plus the list of filesnames (null byte separated), plus
+    // a double null at the end
+
+    // if no filenames in list, size is 0
+    if (m_filenames.GetCount() == 0) return 0;
+
+    // inital size of DROPFILES struct + null byte
+    size_t sz = sizeof(DROPFILES) + 1;
+
+    int i;
+    for (i=0; i<m_filenames.GetCount(); ++i)
+    {
+        // add filename length plus null byte
+        sz += m_filenames[i].Len() + 1;
+    }
+    return sz;
+}
+
+bool wxFileDataObject::GetDataHere(void *pData) const
+{
+    // pData points to an externally allocated memory block
+    // created using the size returned by GetDataSize()
+
+    // if pData is NULL, or there are no files, return
+    if (!pData || m_filenames.GetCount() == 0) return FALSE;
+
+    // convert data pointer to a DROPFILES struct pointer
+    LPDROPFILES pDrop = (LPDROPFILES) pData;
+
+    // initialize DROPFILES struct
+    pDrop->pFiles = sizeof(DROPFILES);
+    pDrop->fNC = FALSE;
+    pDrop->fWide = FALSE;
+
+    // set start of filenames list (null separated)
+    char *pbuf = (char*)pDrop + sizeof(DROPFILES);
+
+    size_t i;
+    for (i=0; i<m_filenames.GetCount(); ++i)
+    {
+        // copy filename to pbuf and add null terminator
+        size_t len = m_filenames[i].Len();
+        memcpy(pbuf, m_filenames[i], len);
+        pbuf += len;
+        *pbuf++ = '\0';
+    }
+    *pbuf = '\0';      // add final null terminator
+
+    return TRUE;
+}
+
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------