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 
CExeDropHandler()25 CExeDropHandler::CExeDropHandler()
26 {
27     pclsid = (CLSID *)&CLSID_ExeDropHandler;
28 }
29 
~CExeDropHandler()30 CExeDropHandler::~CExeDropHandler()
31 {
32 
33 }
34 
35 // IDropTarget
DragEnter(IDataObject * pDataObject,DWORD dwKeyState,POINTL pt,DWORD * pdwEffect)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 
DragOver(DWORD dwKeyState,POINTL pt,DWORD * pdwEffect)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 
DragLeave()53 HRESULT WINAPI CExeDropHandler::DragLeave()
54 {
55     TRACE ("(%p)\n", this);
56     return S_OK;
57 }
58 
Drop(IDataObject * pDataObject,DWORD dwKeyState,POINTL pt,DWORD * pdwEffect)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             ReleaseStgMedium(&medium);
76             return E_FAIL;
77         }
78         pszSrcList = (LPWSTR) (((byte*) lpdf) + lpdf->pFiles);
79         while (*pszSrcList)
80         {
81             if (StrChrW(pszSrcList, L' ') && cchRemaining > 3)
82                 StringCchPrintfExW(pszEnd, cchRemaining, &pszEnd, &cchRemaining, 0, L"\"%ls\" ", pszSrcList);
83             else
84                 StringCchPrintfExW(pszEnd, cchRemaining, &pszEnd, &cchRemaining, 0, L"%ls ", pszSrcList);
85 
86             pszSrcList += wcslen(pszSrcList) + 1;
87         }
88 
89         GlobalUnlock(medium.hGlobal);
90         ReleaseStgMedium(&medium);
91     }
92 
93     ShellExecuteW(NULL, L"open", sPathTarget, wszBuf, NULL,SW_SHOWNORMAL);
94 
95     return S_OK;
96 }
97 
98 
99 // IPersistFile
GetCurFile(LPOLESTR * ppszFileName)100 HRESULT WINAPI CExeDropHandler::GetCurFile(LPOLESTR *ppszFileName)
101 {
102     FIXME ("(%p)\n", this);
103     return E_NOTIMPL;
104 }
105 
IsDirty()106 HRESULT WINAPI CExeDropHandler::IsDirty()
107 {
108     FIXME ("(%p)\n", this);
109     return E_NOTIMPL;
110 }
111 
Load(LPCOLESTR pszFileName,DWORD dwMode)112 HRESULT WINAPI CExeDropHandler::Load(LPCOLESTR pszFileName, DWORD dwMode)
113 {
114     UINT len = strlenW(pszFileName);
115     sPathTarget = (WCHAR *)SHAlloc((len + 1) * sizeof(WCHAR));
116     memcpy(sPathTarget, pszFileName, (len + 1) * sizeof(WCHAR));
117     return S_OK;
118 }
119 
Save(LPCOLESTR pszFileName,BOOL fRemember)120 HRESULT WINAPI CExeDropHandler::Save(LPCOLESTR pszFileName, BOOL fRemember)
121 {
122     FIXME ("(%p)\n", this);
123     return E_NOTIMPL;
124 }
125 
SaveCompleted(LPCOLESTR pszFileName)126 HRESULT WINAPI CExeDropHandler::SaveCompleted(LPCOLESTR pszFileName)
127 {
128     FIXME ("(%p)\n", this);
129     return E_NOTIMPL;
130 }
131 
132 /************************************************************************
133  * CFSFolder::GetClassID
134  */
GetClassID(CLSID * lpClassId)135 HRESULT WINAPI CExeDropHandler::GetClassID(CLSID * lpClassId)
136 {
137     TRACE ("(%p)\n", this);
138 
139     if (!lpClassId)
140         return E_POINTER;
141 
142     *lpClassId = *pclsid;
143 
144     return S_OK;
145 }
146