1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2006, 2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "DropFiles.h"
\r
22 CDropFiles::CDropFiles()
\r
28 CDropFiles::~CDropFiles()
\r
30 delete [] m_pBuffer;
\r
33 void CDropFiles::AddFile(const CString &sFile)
\r
35 m_arFiles.Add(sFile);
\r
38 INT_PTR CDropFiles::GetCount()
\r
40 return m_arFiles.GetCount();
\r
43 void CDropFiles::CreateBuffer()
\r
45 ASSERT(m_pBuffer == NULL);
\r
46 ASSERT(m_nBufferSize == 0);
\r
47 ASSERT(m_arFiles.GetCount()>0);
\r
51 for(int i=0;i<m_arFiles.GetSize();i++)
\r
53 nLength += m_arFiles[i].GetLength();
\r
54 nLength += 1; // '\0' separator
\r
57 m_nBufferSize = sizeof(DROPFILES) + (nLength+1)*sizeof(TCHAR);
\r
58 m_pBuffer = new char[m_nBufferSize];
\r
60 SecureZeroMemory(m_pBuffer, m_nBufferSize);
\r
62 DROPFILES* df = (DROPFILES*)m_pBuffer;
\r
63 df->pFiles = sizeof(DROPFILES);
\r
66 TCHAR* pFilenames = (TCHAR*)(m_pBuffer + sizeof(DROPFILES));
\r
67 TCHAR* pCurrentFilename = pFilenames;
\r
69 for(int i=0;i<m_arFiles.GetSize();i++)
\r
71 CString str = m_arFiles[i];
\r
72 wcscpy_s(pCurrentFilename,str.GetLength()+1,str.GetBuffer());
\r
73 pCurrentFilename += str.GetLength();
\r
74 *pCurrentFilename = '\0'; // separator between file names
\r
77 *pCurrentFilename = '\0'; // terminate array
\r
80 void* CDropFiles::GetBuffer() const
\r
82 return (void*)m_pBuffer;
\r
85 int CDropFiles::GetBufferSize() const
\r
87 return m_nBufferSize;
\r
90 void CDropFiles::CreateStructure()
\r
94 COleDataSource dropData;
\r
95 HGLOBAL hMem = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE, GetBufferSize());
\r
96 memcpy( ::GlobalLock(hMem), GetBuffer(), GetBufferSize() );
\r
97 ::GlobalUnlock(hMem);
\r
98 dropData.CacheGlobalData( CF_HDROP, hMem );
\r
99 dropData.DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK,NULL);
\r