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