OSDN Git Service

Using cherry Pick implement combine commits to avoid the rebase start by command...
[tortoisegit/TortoiseGitJp.git] / src / Utils / DropFiles.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2006, 2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "stdafx.h"\r
20 #include "DropFiles.h"\r
21 \r
22 CDropFiles::CDropFiles()\r
23 {\r
24         m_pBuffer = NULL;\r
25         m_nBufferSize = 0;\r
26 }\r
27 \r
28 CDropFiles::~CDropFiles()\r
29 {\r
30         delete [] m_pBuffer;\r
31 }\r
32 \r
33 void CDropFiles::AddFile(const CString &sFile)\r
34 {\r
35         m_arFiles.Add(sFile);\r
36 }\r
37 \r
38 INT_PTR CDropFiles::GetCount()\r
39 {\r
40         return m_arFiles.GetCount();\r
41 }\r
42 \r
43 void CDropFiles::CreateBuffer()\r
44 {\r
45         ASSERT(m_pBuffer == NULL);\r
46         ASSERT(m_nBufferSize == 0);\r
47         ASSERT(m_arFiles.GetCount()>0);\r
48 \r
49         int nLength = 0;\r
50 \r
51         for(int i=0;i<m_arFiles.GetSize();i++)\r
52         {\r
53                 nLength += m_arFiles[i].GetLength();\r
54                 nLength += 1; // '\0' separator\r
55         }\r
56 \r
57         m_nBufferSize = sizeof(DROPFILES) + (nLength+1)*sizeof(TCHAR);\r
58         m_pBuffer = new char[m_nBufferSize];\r
59         \r
60         SecureZeroMemory(m_pBuffer, m_nBufferSize);\r
61 \r
62         DROPFILES* df = (DROPFILES*)m_pBuffer;\r
63         df->pFiles = sizeof(DROPFILES);\r
64         df->fWide = 1;\r
65 \r
66         TCHAR* pFilenames = (TCHAR*)(m_pBuffer + sizeof(DROPFILES));\r
67         TCHAR* pCurrentFilename = pFilenames;\r
68 \r
69         for(int i=0;i<m_arFiles.GetSize();i++)\r
70         {\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
75                 pCurrentFilename++;\r
76         }\r
77         *pCurrentFilename = '\0'; // terminate array\r
78 }\r
79 \r
80 void* CDropFiles::GetBuffer() const\r
81 {\r
82         return (void*)m_pBuffer;\r
83 }\r
84 \r
85 int     CDropFiles::GetBufferSize() const\r
86 {\r
87         return m_nBufferSize;\r
88 }\r
89 \r
90 void CDropFiles::CreateStructure()\r
91 {\r
92         CreateBuffer();\r
93         \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
100 }\r