Fix typo in changelog
[TortoiseGit.git] / src / Utils / DropFiles.cpp
blobc9d10916b35b0e36e05692ec47f336a5b4356614
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013 - TortoiseGit
4 // Copyright (C) 2006, 2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "DropFiles.h"
23 CDropFiles::CDropFiles()
25 m_pBuffer = NULL;
26 m_nBufferSize = 0;
29 CDropFiles::~CDropFiles()
31 delete [] m_pBuffer;
34 void CDropFiles::AddFile(const CString &sFile)
36 m_arFiles.Add(sFile);
39 INT_PTR CDropFiles::GetCount() const
41 return m_arFiles.GetCount();
44 bool CDropFiles::IsEmpty() const
46 return m_arFiles.IsEmpty() == TRUE;
49 void CDropFiles::CreateBuffer()
51 ASSERT(m_pBuffer == NULL);
52 ASSERT(m_nBufferSize == 0);
53 ASSERT(!m_arFiles.IsEmpty());
55 int nLength = 0;
57 for(int i=0;i<m_arFiles.GetSize();i++)
59 nLength += m_arFiles[i].GetLength();
60 nLength += 1; // '\0' separator
63 m_nBufferSize = sizeof(DROPFILES) + (nLength+1)*sizeof(TCHAR);
64 m_pBuffer = new char[m_nBufferSize];
66 SecureZeroMemory(m_pBuffer, m_nBufferSize);
68 DROPFILES* df = (DROPFILES*)m_pBuffer;
69 df->pFiles = sizeof(DROPFILES);
70 df->fWide = 1;
72 TCHAR* pFilenames = (TCHAR*)(m_pBuffer + sizeof(DROPFILES));
73 TCHAR* pCurrentFilename = pFilenames;
75 for(int i=0;i<m_arFiles.GetSize();i++)
77 CString str = m_arFiles[i];
78 wcscpy_s(pCurrentFilename,str.GetLength()+1,str.GetBuffer());
79 pCurrentFilename += str.GetLength();
80 *pCurrentFilename = '\0'; // separator between file names
81 pCurrentFilename++;
83 *pCurrentFilename = '\0'; // terminate array
86 void* CDropFiles::GetBuffer() const
88 return (void*)m_pBuffer;
91 int CDropFiles::GetBufferSize() const
93 return m_nBufferSize;
96 void CDropFiles::CreateStructure()
98 CreateBuffer();
100 COleDataSource dropData;
101 HGLOBAL hMem = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE, GetBufferSize());
102 memcpy( ::GlobalLock(hMem), GetBuffer(), GetBufferSize() );
103 ::GlobalUnlock(hMem);
104 dropData.CacheGlobalData( CF_HDROP, hMem );
105 dropData.DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK,NULL);