INT21_GetFreeDiskSpace(): The drive parameter is found in the DL
[wine] / dlls / dmusic / collection.c
1 /* IDirectMusicCollection Implementation
2  *
3  * Copyright (C) 2003 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27
28 #include "dmusic_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
31
32 /* IDirectMusicCollection IUnknown parts follow: */
33 HRESULT WINAPI IDirectMusicCollectionImpl_QueryInterface (LPDIRECTMUSICCOLLECTION iface, REFIID riid, LPVOID *ppobj)
34 {
35         ICOM_THIS(IDirectMusicCollectionImpl,iface);
36
37         if (IsEqualIID (riid, &IID_IUnknown) 
38                 || IsEqualIID (riid, &IID_IDirectMusicCollection)) {
39                 IDirectMusicCollectionImpl_AddRef(iface);
40                 *ppobj = This;
41                 return S_OK;
42         }
43
44         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
45         return E_NOINTERFACE;
46 }
47
48 ULONG WINAPI IDirectMusicCollectionImpl_AddRef (LPDIRECTMUSICCOLLECTION iface)
49 {
50         ICOM_THIS(IDirectMusicCollectionImpl,iface);
51         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52         return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirectMusicCollectionImpl_Release (LPDIRECTMUSICCOLLECTION iface)
56 {
57         ICOM_THIS(IDirectMusicCollectionImpl,iface);
58         ULONG ref = --This->ref;
59         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
60         if (ref == 0) {
61                 HeapFree(GetProcessHeap(), 0, This);
62         }
63         return ref;
64 }
65
66 /* IDirectMusicCollection Interface follow: */
67 HRESULT WINAPI IDirectMusicCollectionImpl_GetInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwPatch, IDirectMusicInstrument** ppInstrument)
68 {
69         ICOM_THIS(IDirectMusicCollectionImpl,iface);
70         int i;
71         
72         TRACE("(%p, %ld, %p)\n", This, dwPatch, ppInstrument);
73         for (i = 0; i < This->nrofinstruments; i++) {
74                 if (This->ppInstruments[i]->dwPatch == dwPatch) {
75                         *ppInstrument = (LPDIRECTMUSICINSTRUMENT)This->ppInstruments[i];
76                         return S_OK;
77                 }
78         }
79         
80         return DMUS_E_INVALIDPATCH;
81 }
82
83 HRESULT WINAPI IDirectMusicCollectionImpl_EnumInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwIndex, DWORD* pdwPatch, LPWSTR pwszName, DWORD dwNameLen)
84 {
85         ICOM_THIS(IDirectMusicCollectionImpl,iface);
86
87         TRACE("(%p, %ld, %p, %p, %ld)\n", This, dwIndex, pdwPatch, pwszName, dwNameLen);
88         if (dwIndex > This->nrofinstruments)
89                 return S_FALSE;
90         *pdwPatch = This->ppInstruments[dwIndex]->dwPatch;
91         if (pwszName != NULL) {
92                 /*
93                  *pwszName = (LPWSTR)This->ppInstruments[dwIndex]->pwszName;
94                  *dwNameLen = wcslen (This->ppInstruments[dwIndex]->pwszName);
95                  */
96         }
97         
98         return S_OK;
99 }
100
101 ICOM_VTABLE(IDirectMusicCollection) DirectMusicCollection_Vtbl =
102 {
103     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
104         IDirectMusicCollectionImpl_QueryInterface,
105         IDirectMusicCollectionImpl_AddRef,
106         IDirectMusicCollectionImpl_Release,
107         IDirectMusicCollectionImpl_GetInstrument,
108         IDirectMusicCollectionImpl_EnumInstrument
109 };
110
111 /* for ClassFactory */
112 HRESULT WINAPI DMUSIC_CreateDirectMusicCollection (LPCGUID lpcGUID, LPDIRECTMUSICCOLLECTION* ppDMColl, LPUNKNOWN pUnkOuter)
113 {
114         IDirectMusicCollectionImpl *collection;
115         
116         TRACE("(%p,%p,%p)\n", lpcGUID, ppDMColl, pUnkOuter);
117         if (IsEqualIID (lpcGUID, &IID_IDirectMusicCollection)) {
118                 collection = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCollectionImpl));
119                 if (NULL == collection) {
120                         *ppDMColl = (LPDIRECTMUSICCOLLECTION) NULL;
121                         return E_OUTOFMEMORY;
122                 }
123                 collection->lpVtbl = &DirectMusicCollection_Vtbl;
124                 collection->ref = 1;
125                 *ppDMColl = (LPDIRECTMUSICCOLLECTION) collection;
126                 return S_OK;
127         }
128
129         WARN("No interface found\n");   
130         return E_NOINTERFACE;
131 }
132
133
134 /*****************************************************************************
135  * IDirectMusicCollectionObject implementation
136  */
137 /* IDirectMusicCollectionObject IUnknown part: */
138 HRESULT WINAPI IDirectMusicCollectionObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj)
139 {
140         ICOM_THIS(IDirectMusicCollectionObject,iface);
141
142         if (IsEqualIID (riid, &IID_IUnknown) 
143                 || IsEqualIID (riid, &IID_IDirectMusicObject)) {
144                 IDirectMusicCollectionObject_AddRef(iface);
145                 *ppobj = This;
146                 return S_OK;
147         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
148                 IDirectMusicCollectionObjectStream_AddRef ((LPPERSISTSTREAM)This->pStream);
149                 *ppobj = This->pStream;
150                 return S_OK;
151         } else if (IsEqualIID (riid, &IID_IDirectMusicCollection)) {
152                 IDirectMusicCollectionImpl_AddRef ((LPDIRECTMUSICCOLLECTION)This->pCollection);
153                 *ppobj = This->pCollection;
154                 return S_OK;
155         }
156
157         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
158         return E_NOINTERFACE;
159 }
160
161 ULONG WINAPI IDirectMusicCollectionObject_AddRef (LPDIRECTMUSICOBJECT iface)
162 {
163         ICOM_THIS(IDirectMusicCollectionObject,iface);
164         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
165         return ++(This->ref);
166 }
167
168 ULONG WINAPI IDirectMusicCollectionObject_Release (LPDIRECTMUSICOBJECT iface)
169 {
170         ICOM_THIS(IDirectMusicCollectionObject,iface);
171         ULONG ref = --This->ref;
172         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
173         if (ref == 0) {
174                 HeapFree(GetProcessHeap(), 0, This);
175         }
176         return ref;
177 }
178
179 /* IDirectMusicCollectionObject IDirectMusicObject part: */
180 HRESULT WINAPI IDirectMusicCollectionObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
181 {
182         ICOM_THIS(IDirectMusicCollectionObject,iface);
183
184         TRACE("(%p, %p)\n", This, pDesc);
185         pDesc = This->pDesc;
186         
187         return S_OK;
188 }
189
190 HRESULT WINAPI IDirectMusicCollectionObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
191 {
192         ICOM_THIS(IDirectMusicCollectionObject,iface);
193
194         TRACE("(%p, %p)\n", This, pDesc);
195         This->pDesc = pDesc;
196
197         return S_OK;
198 }
199
200 HRESULT WINAPI IDirectMusicCollectionObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc)
201 {
202         ICOM_THIS(IDirectMusicCollectionObject,iface);
203
204         FIXME("(%p, %p, %p): stub\n", This, pStream, pDesc);
205
206         return S_OK;
207 }
208
209 ICOM_VTABLE(IDirectMusicObject) DirectMusicCollectionObject_Vtbl =
210 {
211     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
212         IDirectMusicCollectionObject_QueryInterface,
213         IDirectMusicCollectionObject_AddRef,
214         IDirectMusicCollectionObject_Release,
215         IDirectMusicCollectionObject_GetDescriptor,
216         IDirectMusicCollectionObject_SetDescriptor,
217         IDirectMusicCollectionObject_ParseDescriptor
218 };
219
220 /* for ClassFactory */
221 HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionObject (LPCGUID lpcGUID, LPDIRECTMUSICOBJECT* ppObject, LPUNKNOWN pUnkOuter)
222 {
223         IDirectMusicCollectionObject *obj;
224         
225         TRACE("(%p,%p,%p)\n", lpcGUID, ppObject, pUnkOuter);
226         if (IsEqualIID (lpcGUID, &IID_IDirectMusicObject)) {
227                 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCollectionObject));
228                 if (NULL == obj) {
229                         *ppObject = (LPDIRECTMUSICOBJECT) NULL;
230                         return E_OUTOFMEMORY;
231                 }
232                 obj->lpVtbl = &DirectMusicCollectionObject_Vtbl;
233                 obj->ref = 1;
234                 /* prepare IPersistStream */
235                 obj->pStream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCollectionObjectStream));
236                 obj->pStream->lpVtbl = &DirectMusicCollectionObjectStream_Vtbl;
237                 obj->pStream->ref = 1;
238                 obj->pStream->pParentObject = obj;
239                 /* prepare IDirectMusicCollection */
240                 DMUSIC_CreateDirectMusicCollection (&IID_IDirectMusicCollection, (LPDIRECTMUSICCOLLECTION*)&obj->pCollection, NULL);
241                 obj->pCollection->pObject = obj;
242                 *ppObject = (LPDIRECTMUSICOBJECT) obj;
243                 return S_OK;
244         }
245         WARN("No interface found\n");
246         
247         return E_NOINTERFACE;
248 }
249
250 /*****************************************************************************
251  * IDirectMusicCollectionObjectStream implementation
252  */
253 /* IDirectMusicCollectionObjectStream IUnknown part: */
254 HRESULT WINAPI IDirectMusicCollectionObjectStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj)
255 {
256         ICOM_THIS(IDirectMusicCollectionObjectStream,iface);
257
258         if (IsEqualIID (riid, &IID_IUnknown)
259                 || IsEqualIID (riid, &IID_IPersistStream)) {
260                 IDirectMusicCollectionObjectStream_AddRef (iface);
261                 *ppobj = This;
262                 return S_OK;
263         }
264
265         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
266         return E_NOINTERFACE;
267 }
268
269 ULONG WINAPI IDirectMusicCollectionObjectStream_AddRef (LPPERSISTSTREAM iface)
270 {
271         ICOM_THIS(IDirectMusicCollectionObjectStream,iface);
272         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
273         return ++(This->ref);
274 }
275
276 ULONG WINAPI IDirectMusicCollectionObjectStream_Release (LPPERSISTSTREAM iface)
277 {
278         ICOM_THIS(IDirectMusicCollectionObjectStream,iface);
279         ULONG ref = --This->ref;
280         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
281         if (ref == 0) {
282                 HeapFree(GetProcessHeap(), 0, This);
283         }
284         return ref;
285 }
286
287 /* IDirectMusicCollectionObjectStream IPersist part: */
288 HRESULT WINAPI IDirectMusicCollectionObjectStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID)
289 {
290         return E_NOTIMPL;
291 }
292
293 /* IDirectMusicCollectionObjectStream IPersistStream part: */
294 HRESULT WINAPI IDirectMusicCollectionObjectStream_IsDirty (LPPERSISTSTREAM iface)
295 {
296         return E_NOTIMPL;
297 }
298
299 HRESULT WINAPI IDirectMusicCollectionObjectStream_Load (LPPERSISTSTREAM iface, IStream* pStm)
300 {
301         FOURCC chunkID;
302         DWORD chunkSize;
303
304         IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
305         IStream_Read (pStm, &chunkSize, sizeof(FOURCC), NULL);
306         
307         if (chunkID == FOURCC_RIFF) {
308                 FIXME(": Loading not implemented yet\n");
309         } else {
310                 WARN("Not a RIFF file\n");
311                 return E_FAIL;
312         }
313         
314         return S_OK;
315 }
316
317 HRESULT WINAPI IDirectMusicCollectionObjectStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty)
318 {
319         return E_NOTIMPL;
320 }
321
322 HRESULT WINAPI IDirectMusicCollectionObjectStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize)
323 {
324         return E_NOTIMPL;
325 }
326
327 ICOM_VTABLE(IPersistStream) DirectMusicCollectionObjectStream_Vtbl =
328 {
329     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
330         IDirectMusicCollectionObjectStream_QueryInterface,
331         IDirectMusicCollectionObjectStream_AddRef,
332         IDirectMusicCollectionObjectStream_Release,
333         IDirectMusicCollectionObjectStream_GetClassID,
334         IDirectMusicCollectionObjectStream_IsDirty,
335         IDirectMusicCollectionObjectStream_Load,
336         IDirectMusicCollectionObjectStream_Save,
337         IDirectMusicCollectionObjectStream_GetSizeMax
338 };