1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-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
21 #include "../DragDropImpl.h"
\r
22 #include "../UnicodeUtils.h"
\r
26 * helper class to turn a control into a file drop target
\r
28 class CFileDropTarget : public CIDropTarget
\r
31 CFileDropTarget(HWND hTargetWnd):CIDropTarget(hTargetWnd){}
\r
32 virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL /*pt*/)
\r
34 if(pFmtEtc->cfFormat == CF_TEXT && medium.tymed == TYMED_ISTREAM)
\r
36 if(medium.pstm != NULL)
\r
38 const int BUF_SIZE = 10000;
\r
39 char buff[BUF_SIZE+1];
\r
41 HRESULT hr = medium.pstm->Read(buff, BUF_SIZE, &cbRead);
\r
42 if( SUCCEEDED(hr) && cbRead > 0 && cbRead < BUF_SIZE)
\r
45 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
46 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
47 std::wstring str = CUnicodeUtils::StdGetUnicode(std::string(buff));
\r
48 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)str.c_str());
\r
51 for(;(hr==S_OK && cbRead >0) && SUCCEEDED(hr) ;)
\r
54 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
55 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
56 std::wstring str = CUnicodeUtils::StdGetUnicode(std::string(buff));
\r
57 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)str.c_str());
\r
59 hr = medium.pstm->Read(buff, BUF_SIZE, &cbRead);
\r
63 if(pFmtEtc->cfFormat == CF_UNICODETEXT && medium.tymed == TYMED_ISTREAM)
\r
65 if(medium.pstm != NULL)
\r
67 const int BUF_SIZE = 10000;
\r
68 TCHAR buff[BUF_SIZE+1];
\r
70 HRESULT hr = medium.pstm->Read(buff, BUF_SIZE, &cbRead);
\r
71 if( SUCCEEDED(hr) && cbRead > 0 && cbRead < BUF_SIZE)
\r
74 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
75 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
76 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)buff);
\r
79 for(;(hr==S_OK && cbRead >0) && SUCCEEDED(hr) ;)
\r
82 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
83 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
84 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)buff);
\r
86 hr = medium.pstm->Read(buff, BUF_SIZE, &cbRead);
\r
90 if(pFmtEtc->cfFormat == CF_TEXT && medium.tymed == TYMED_HGLOBAL)
\r
92 char* pStr = (char*)GlobalLock(medium.hGlobal);
\r
95 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
96 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
97 std::wstring str = CUnicodeUtils::StdGetUnicode(std::string(pStr));
\r
98 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)str.c_str());
\r
100 GlobalUnlock(medium.hGlobal);
\r
102 if(pFmtEtc->cfFormat == CF_UNICODETEXT && medium.tymed == TYMED_HGLOBAL)
\r
104 WCHAR* pStr = (WCHAR*)GlobalLock(medium.hGlobal);
\r
107 LRESULT nLen = ::SendMessage(m_hTargetWnd, WM_GETTEXTLENGTH, 0, 0);
\r
108 ::SendMessage(m_hTargetWnd, EM_SETSEL, nLen, -1);
\r
109 ::SendMessage(m_hTargetWnd, EM_REPLACESEL, TRUE, (LPARAM)pStr);
\r
111 GlobalUnlock(medium.hGlobal);
\r
113 if(pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
\r
115 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
\r
118 TCHAR szFileName[MAX_PATH];
\r
120 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
121 for(UINT i = 0; i < cFiles; ++i)
\r
123 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
124 ::SendMessage(m_hTargetWnd, WM_SETTEXT, 0, (LPARAM)szFileName);
\r
126 //DragFinish(hDrop); // base class calls ReleaseStgMedium
\r
128 GlobalUnlock(medium.hGlobal);
\r
130 return true; //let base free the medium
\r
138 * Enhancement for a CEdit control which allows the edit control to have files
\r
139 * dropped onto it and fill in the path of that dropped file.
\r
141 class CFileDropEdit : public CEdit
\r
143 DECLARE_DYNAMIC(CFileDropEdit)
\r
147 virtual ~CFileDropEdit();
\r
150 DECLARE_MESSAGE_MAP()
\r
152 CFileDropTarget * m_pDropTarget;
\r
153 virtual void PreSubclassWindow();
\r