ddraw: Forward the DDSCAPS2_TEXTUREMANAGE flag to wined3d.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  */
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "winuser.h"
33 #include "shlobj.h"
34 #include "shell32_main.h"
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
39
40 /***********************************************************************
41  * IFileSystemBindData implementation
42  */
43 typedef struct
44 {
45     const IFileSystemBindDataVtbl *lpVtbl;
46     LONG              ref;
47     WIN32_FIND_DATAW findFile;
48 } IFileSystemBindDataImpl;
49
50 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
51 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
52 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
53 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
54 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
55
56 static const IFileSystemBindDataVtbl sbvt =
57 {
58     IFileSystemBindData_fnQueryInterface,
59     IFileSystemBindData_fnAddRef,
60     IFileSystemBindData_fnRelease,
61     IFileSystemBindData_fnSetFindData,
62     IFileSystemBindData_fnGetFindData,
63 };
64
65 static const WCHAR wFileSystemBindData[] = {
66     'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
67
68 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
69 {
70     IFileSystemBindDataImpl *sb;
71     HRESULT ret = E_OUTOFMEMORY;
72
73     TRACE("%p, %p\n", pfd, ppV);
74
75     if (!ppV)
76        return E_INVALIDARG;
77
78     *ppV = NULL;
79
80     sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
81     if (!sb)
82         return ret;
83
84     sb->lpVtbl = &sbvt;
85     sb->ref = 1;
86     IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
87
88     ret = CreateBindCtx(0, ppV);
89     if (SUCCEEDED(ret))
90     {
91         BIND_OPTS bindOpts;
92
93         bindOpts.cbStruct = sizeof(BIND_OPTS);
94         bindOpts.grfFlags = 0;
95         bindOpts.grfMode = STGM_CREATE;
96         bindOpts.dwTickCountDeadline = 0;
97         IBindCtx_SetBindOptions(*ppV, &bindOpts);
98         IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
99
100         IFileSystemBindData_Release((IFileSystemBindData*)sb);
101     }
102     else
103         HeapFree(GetProcessHeap(), 0, sb);
104     return ret;
105 }
106
107 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
108 {
109     LPUNKNOWN pUnk;
110     IFileSystemBindData *pfsbd = NULL;
111     HRESULT ret;
112
113     TRACE("%p, %p\n", pbc, pfd);
114
115     if (!pfd)
116         return E_INVALIDARG;
117
118     ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
119     if (SUCCEEDED(ret))
120     {
121         ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
122         if (SUCCEEDED(ret))
123         {
124             ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
125             IFileSystemBindData_Release(pfsbd);
126         }
127         IUnknown_Release(pUnk);
128     }
129     return ret;
130 }
131
132 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
133 {
134     LPUNKNOWN pUnk;
135     IFileSystemBindData *pfsbd = NULL;
136     HRESULT ret;
137     
138     TRACE("%p, %p\n", pbc, pfd);
139
140     ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
141     if (SUCCEEDED(ret))
142     {
143         ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
144         if (SUCCEEDED(ret))
145         {
146             ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
147             IFileSystemBindData_Release(pfsbd);
148         }
149         IUnknown_Release(pUnk);
150     }
151     return ret;
152 }
153
154 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
155                 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
156 {
157     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
158     TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
159
160     *ppV = NULL;
161
162     if (IsEqualIID(riid, &IID_IUnknown))
163         *ppV = This;
164     else if (IsEqualIID(riid, &IID_IFileSystemBindData))
165         *ppV = (IFileSystemBindData*)This;
166
167     if (*ppV)
168     {
169         IUnknown_AddRef((IUnknown*)(*ppV));
170         TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
171         return S_OK;
172     }
173     TRACE("-- Interface: E_NOINTERFACE\n");
174     return E_NOINTERFACE;
175 }
176
177 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
178 {
179     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
180     ULONG refCount = InterlockedIncrement(&This->ref);
181
182     TRACE("(%p)->(count=%i)\n", This, refCount - 1);
183
184     return refCount;
185 }
186
187 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
188 {
189     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
190     ULONG refCount = InterlockedDecrement(&This->ref);
191     
192     TRACE("(%p)->(count=%i)\n", This, refCount + 1);
193
194     if (!refCount)
195     {
196         TRACE(" destroying ISFBindPidl(%p)\n",This);
197         HeapFree(GetProcessHeap(), 0, This);
198     }
199     return refCount;
200 }
201
202 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
203                IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
204 {
205     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
206     TRACE("(%p), %p\n", This, pfd);
207
208     if (!pfd)
209         return E_INVALIDARG;
210
211     memcpy(pfd, &This->findFile, sizeof(WIN32_FIND_DATAW));
212     return NOERROR;
213 }
214
215 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
216                IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
217 {
218     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
219     TRACE("(%p), %p\n", This, pfd);
220
221     if (pfd)
222         memcpy(&This->findFile, pfd, sizeof(WIN32_FIND_DATAW));
223     else
224         memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
225     return NOERROR;
226 }