1 /*
2  * executable drop target handler
3  *
4  * Copyright 2014              Huw Campbell
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <precomp.h>
22 
23 WINE_DEFAULT_DEBUG_CHANNEL (shell);
24 
25 CExeDropHandler::CExeDropHandler()
26 {
27     pclsid = (CLSID *)&CLSID_ExeDropHandler;
28 }
29 
30 CExeDropHandler::~CExeDropHandler()
31 {
32 
33 }
34 
35 // IDropTarget
36 HRESULT WINAPI CExeDropHandler::DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
37 {
38     TRACE ("(%p)\n", this);
39     if (*pdwEffect == DROPEFFECT_NONE)
40         return S_OK;
41 
42     *pdwEffect = DROPEFFECT_COPY;
43     return S_OK;
44 }
45 
46 HRESULT WINAPI CExeDropHandler::DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
47 {
48     TRACE ("(%p)\n", this);
49     *pdwEffect = DROPEFFECT_COPY;
50     return S_OK;
51 }
52 
53 HRESULT WINAPI CExeDropHandler::DragLeave()
54 {
55     TRACE ("(%p)\n", this);
56     return S_OK;
57 }
58 
59 HRESULT WINAPI CExeDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
60 {
61     TRACE ("(%p)\n", this);
62     FORMATETC fmt;
63     STGMEDIUM medium;
64     LPWSTR pszSrcList;
65     InitFormatEtc (fmt, CF_HDROP, TYMED_HGLOBAL);
66     WCHAR wszBuf[MAX_PATH * 2 + 8], *pszEnd = wszBuf;
67     size_t cchRemaining = _countof(wszBuf);
68 
69     if (SUCCEEDED(pDataObject->GetData(&fmt, &medium)) /* && SUCCEEDED(pDataObject->GetData(&fmt2, &medium))*/)
70     {
71         LPDROPFILES lpdf = (LPDROPFILES) GlobalLock(medium.hGlobal);
72         if (!lpdf)
73         {
74             ERR("Error locking global\n");
75             return E_FAIL;
76         }
77         pszSrcList = (LPWSTR) (((byte*) lpdf) + lpdf->pFiles);
78         while (*pszSrcList)
79         {
80             if (StrChrW(pszSrcList, L' ') && cchRemaining > 3)
81                 StringCchPrintfExW(pszEnd, cchRemaining, &pszEnd, &cchRemaining, 0, L"\"%ls\" ", pszSrcList);
82             else
83                 StringCchPrintfExW(pszEnd, cchRemaining, &pszEnd, &cchRemaining, 0, L"%ls ", pszSrcList);
84 
85             pszSrcList += wcslen(pszSrcList) + 1;
86         }
87     }
88 
89     ShellExecuteW(NULL, L"open", sPathTarget, wszBuf, NULL,SW_SHOWNORMAL);
90 
91     return S_OK;
92 }
93 
94 
95 // IPersistFile
96 HRESULT WINAPI CExeDropHandler::GetCurFile(LPOLESTR *ppszFileName)
97 {
98     FIXME ("(%p)\n", this);
99     return E_NOTIMPL;
100 }
101 
102 HRESULT WINAPI CExeDropHandler::IsDirty()
103 {
104     FIXME ("(%p)\n", this);
105     return E_NOTIMPL;
106 }
107 
108 HRESULT WINAPI CExeDropHandler::Load(LPCOLESTR pszFileName, DWORD dwMode)
109 {
110     UINT len = strlenW(pszFileName);
111     sPathTarget = (WCHAR *)SHAlloc((len + 1) * sizeof(WCHAR));
112     memcpy(sPathTarget, pszFileName, (len + 1) * sizeof(WCHAR));
113     return S_OK;
114 }
115 
116 HRESULT WINAPI CExeDropHandler::Save(LPCOLESTR pszFileName, BOOL fRemember)
117 {
118     FIXME ("(%p)\n", this);
119     return E_NOTIMPL;
120 }
121 
122 HRESULT WINAPI CExeDropHandler::SaveCompleted(LPCOLESTR pszFileName)
123 {
124     FIXME ("(%p)\n", this);
125     return E_NOTIMPL;
126 }
127 
128 /************************************************************************
129  * CFSFolder::GetClassID
130  */
131 HRESULT WINAPI CExeDropHandler::GetClassID(CLSID * lpClassId)
132 {
133     TRACE ("(%p)\n", this);
134 
135     if (!lpClassId)
136         return E_POINTER;
137 
138     *lpClassId = *pclsid;
139 
140     return S_OK;
141 }