- move CreateMyCompEnumList and CreateDesktopEnumList to their
[wine] / dlls / shell32 / shlfsbind.c
1 /*
2  * File System Bind Data object to use as parameter for the bind context to
3  * IShellFolder_ParseDisplayName
4  *
5  * Copyright 2003 Rolf Kalbermatter
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winuser.h"
31 #include "shlobj.h"
32 #include "shell32_main.h"
33
34 #include "debughlp.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38
39 /***********************************************************************
40  * IFileSystemBindData implementation
41  */
42 typedef struct
43 {
44         ICOM_VFIELD(IFileSystemBindData);
45         DWORD              ref;
46         WIN32_FIND_DATAW findFile;
47 } IFileSystemBindDataImpl;
48
49 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *iface, REFIID riid, LPVOID* ppvObj);
50 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface);
51 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface);
52 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd);
53 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd);
54
55 static struct ICOM_VTABLE(IFileSystemBindData) sbvt =
56 {
57     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
58     IFileSystemBindData_fnQueryInterface,
59     IFileSystemBindData_fnAddRef,
60     IFileSystemBindData_fnRelease,
61     IFileSystemBindData_fnGetFindData,
62     IFileSystemBindData_fnSetFindData,
63 };
64
65 static WCHAR wFileSystemBindData[] = {'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
66
67 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
68 {
69         IFileSystemBindDataImpl *sb;
70         HRESULT ret = E_OUTOFMEMORY;
71
72         TRACE("%p, %p\n", pfd, ppV);
73
74         if (!ppV)
75           return E_INVALIDARG;
76
77         *ppV = NULL;
78
79         sb = (IFileSystemBindDataImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
80         if (!sb)
81           return ret;
82
83         sb->lpVtbl = &sbvt;
84         sb->ref = 1;
85         IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
86
87         ret = CreateBindCtx(0, ppV);
88         if (SUCCEEDED(ret))
89         {
90           BIND_OPTS bindOpts;
91           bindOpts.cbStruct = sizeof(BIND_OPTS);
92           bindOpts.grfFlags = 0;
93           bindOpts.grfMode = STGM_CREATE;
94           bindOpts.dwTickCountDeadline = 0;
95           IBindCtx_SetBindOptions(*ppV, &bindOpts);
96           IBindCtx_RegisterObjectParam(*ppV, wFileSystemBindData, (LPUNKNOWN)sb);
97
98           IFileSystemBindData_Release((IFileSystemBindData*)sb);
99         }
100         else
101           HeapFree(GetProcessHeap(), 0, sb);
102         return ret;
103 }
104
105 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
106 {
107         LPUNKNOWN pUnk;
108         IFileSystemBindData *pfsbd = NULL;
109         HRESULT ret;
110
111         TRACE("%p, %p\n", pbc, pfd);
112
113         if (!pfd)
114           return E_INVALIDARG;
115
116         ret = IBindCtx_GetObjectParam(pbc, wFileSystemBindData, &pUnk);
117         if (SUCCEEDED(ret))
118         {
119           ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
120           if (SUCCEEDED(ret))
121           {
122             ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
123             IFileSystemBindData_Release(pfsbd);
124           }
125           IUnknown_Release(pUnk);
126         }
127         return ret;
128 }
129
130 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
131 {
132         LPUNKNOWN pUnk;
133         IFileSystemBindData *pfsbd = NULL;
134         HRESULT ret;
135         
136         TRACE("%p, %p\n", pbc, pfd);
137
138         ret = IBindCtx_GetObjectParam(pbc, wFileSystemBindData, &pUnk);
139         if (SUCCEEDED(ret))
140         {
141           ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
142           if (SUCCEEDED(ret))
143           {
144             ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
145             IFileSystemBindData_Release(pfsbd);
146           }
147           IUnknown_Release(pUnk);
148         }
149         return ret;}
150
151
152
153 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
154 {
155         ICOM_THIS(IFileSystemBindDataImpl, iface);
156         TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
157
158         *ppV = NULL;
159
160         if (IsEqualIID(riid, &IID_IUnknown))
161         {
162           *ppV = This;
163         }
164         else if (IsEqualIID(riid, &IID_IFileSystemBindData))
165         {
166           *ppV = (IFileSystemBindData*)This;
167         }
168
169         if (*ppV)
170         {
171           IUnknown_AddRef((IUnknown*)(*ppV));
172           TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
173           return S_OK;
174         }
175         TRACE("-- Interface: E_NOINTERFACE\n");
176         return E_NOINTERFACE;
177 }
178
179 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
180 {
181         ICOM_THIS(IFileSystemBindDataImpl, iface);
182         TRACE("(%p)\n", This);
183         return InterlockedIncrement(&This->ref);
184 }
185
186 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
187 {
188         ICOM_THIS(IFileSystemBindDataImpl, iface);
189         TRACE("(%p)\n", This);
190
191         if (!InterlockedDecrement(&This->ref))
192         {
193           TRACE(" destroying ISFBindPidl(%p)\n",This);
194           HeapFree(GetProcessHeap(), 0, This);
195           return 0;
196         }
197         return This->ref;
198 }
199
200 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
201 {
202         ICOM_THIS(IFileSystemBindDataImpl, iface);
203         TRACE("(%p), %p\n", This, pfd);
204
205         if (!pfd)
206           return E_INVALIDARG;
207
208         memcpy(pfd, &This->findFile, sizeof(WIN32_FIND_DATAW));
209         return NOERROR;
210 }
211
212 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
213 {
214         ICOM_THIS(IFileSystemBindDataImpl, iface);
215         TRACE("(%p), %p\n", This, pfd);
216
217         if (pfd)
218           memcpy(&This->findFile, pfd, sizeof(WIN32_FIND_DATAW));
219         else
220           memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
221         return NOERROR;
222 }