The LVN_GETDISPINFO notify message should point to the same iSubItem
[wine] / dlls / dmime / graph.c
1 /* IDirectMusicGraph
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 "dmime_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
31
32 /* IDirectMusicGraph IUnknown part: */
33 HRESULT WINAPI IDirectMusicGraphImpl_QueryInterface (LPDIRECTMUSICGRAPH iface, REFIID riid, LPVOID *ppobj)
34 {
35         ICOM_THIS(IDirectMusicGraphImpl,iface);
36
37         if (IsEqualIID (riid, &IID_IUnknown) || 
38             IsEqualIID (riid, &IID_IDirectMusicGraph)) {
39                 IDirectMusicGraphImpl_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 IDirectMusicGraphImpl_AddRef (LPDIRECTMUSICGRAPH iface)
49 {
50         ICOM_THIS(IDirectMusicGraphImpl,iface);
51         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52         return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirectMusicGraphImpl_Release (LPDIRECTMUSICGRAPH iface)
56 {
57         ICOM_THIS(IDirectMusicGraphImpl,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 /* IDirectMusicGraph IDirectMusicGraph part: */
67 HRESULT WINAPI IDirectMusicGraphImpl_StampPMsg (LPDIRECTMUSICGRAPH iface, DMUS_PMSG* pPMSG)
68 {
69         ICOM_THIS(IDirectMusicGraphImpl,iface);
70
71         FIXME("(%p, %p): stub\n", This, pPMSG);
72
73         return S_OK;
74 }
75
76 HRESULT WINAPI IDirectMusicGraphImpl_InsertTool (LPDIRECTMUSICGRAPH iface, IDirectMusicTool* pTool, DWORD* pdwPChannels, DWORD cPChannels, LONG lIndex)
77 {
78     int i;
79         IDirectMusicTool8Impl* p;
80         IDirectMusicTool8Impl* toAdd = (IDirectMusicTool8Impl*) pTool;
81     ICOM_THIS(IDirectMusicGraphImpl,iface);
82
83         FIXME("(%p, %p, %p, %ld, %li): use of pdwPChannels\n", This, pTool, pdwPChannels, cPChannels, lIndex);
84
85         if (0 == This->num_tools) {
86           This->pFirst = This->pLast = toAdd;
87           toAdd->pPrev = toAdd->pNext = NULL;
88         } else if (lIndex == 0 || lIndex <= -This->num_tools) {
89           This->pFirst->pPrev = toAdd;
90           toAdd->pNext = This->pFirst;
91           toAdd->pPrev = NULL;
92           This->pFirst = toAdd;
93         } else if (lIndex < 0) {
94           p = This->pLast;
95           for (i = 0; i < -lIndex; ++i) {
96             p = p->pPrev;
97           }
98           toAdd->pNext = p->pNext;
99           if (p->pNext) p->pNext->pPrev = toAdd;
100           p->pNext = toAdd;
101           toAdd->pPrev = p;
102         } else if (lIndex >= This->num_tools) {
103           This->pLast->pNext = toAdd;
104           toAdd->pPrev = This->pLast;
105           toAdd->pNext = NULL;
106           This->pLast = toAdd;
107         } else if (lIndex > 0) {
108           p = This->pFirst;
109           for (i = 0; i < lIndex; ++i) {
110             p = p->pNext;
111           }
112           toAdd->pPrev = p->pPrev;
113           if (p->pPrev) p->pPrev->pNext = toAdd;
114           p->pPrev = toAdd;
115           toAdd->pNext = p;
116         }
117         ++This->num_tools;
118         return DS_OK;
119 }
120
121 HRESULT WINAPI IDirectMusicGraphImpl_GetTool (LPDIRECTMUSICGRAPH iface, DWORD dwIndex, IDirectMusicTool** ppTool)
122 {
123         int i;
124         IDirectMusicTool8Impl* p = NULL;
125         ICOM_THIS(IDirectMusicGraphImpl,iface);
126         
127         FIXME("(%p, %ld, %p): stub\n", This, dwIndex, ppTool);
128
129         p = This->pFirst;
130         for (i = 0; i < dwIndex && i < This->num_tools; ++i) {
131           p = p->pNext;
132         }
133         *ppTool = (IDirectMusicTool*) p;
134         if (NULL != *ppTool) {
135           IDirectMusicTool8Impl_AddRef((LPDIRECTMUSICTOOL8) *ppTool);
136         }
137         return DS_OK;
138 }
139
140 HRESULT WINAPI IDirectMusicGraphImpl_RemoveTool (LPDIRECTMUSICGRAPH iface, IDirectMusicTool* pTool)
141 {
142         ICOM_THIS(IDirectMusicGraphImpl,iface);
143
144         FIXME("(%p, %p): stub\n", This, pTool);
145
146         return S_OK;
147 }
148
149 ICOM_VTABLE(IDirectMusicGraph) DirectMusicGraph_Vtbl =
150 {
151     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
152         IDirectMusicGraphImpl_QueryInterface,
153         IDirectMusicGraphImpl_AddRef,
154         IDirectMusicGraphImpl_Release,
155         IDirectMusicGraphImpl_StampPMsg,
156         IDirectMusicGraphImpl_InsertTool,
157         IDirectMusicGraphImpl_GetTool,
158         IDirectMusicGraphImpl_RemoveTool
159 };
160
161 /* for ClassFactory */
162 HRESULT WINAPI DMUSIC_CreateDirectMusicGraph (LPCGUID lpcGUID, LPDIRECTMUSICGRAPH *ppDMGrph, LPUNKNOWN pUnkOuter)
163 {
164         IDirectMusicGraphImpl* dmgraph;
165         
166         if (IsEqualIID (lpcGUID, &IID_IDirectMusicGraph)) {
167                 dmgraph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicGraphImpl));
168                 if (NULL == dmgraph) {
169                         *ppDMGrph = (LPDIRECTMUSICGRAPH) NULL;
170                         return E_OUTOFMEMORY;
171                 }
172                 dmgraph->lpVtbl = &DirectMusicGraph_Vtbl;
173                 dmgraph->ref = 1;
174                 *ppDMGrph = (LPDIRECTMUSICGRAPH) dmgraph;
175                 return S_OK;
176         }
177         WARN("No interface found\n");
178         
179         return E_NOINTERFACE;   
180 }
181
182 /*****************************************************************************
183  * IDirectMusicGraphObject implementation
184  */
185 /* IDirectMusicGraphObject IUnknown part: */
186 HRESULT WINAPI IDirectMusicGraphObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj)
187 {
188         ICOM_THIS(IDirectMusicGraphObject,iface);
189
190         if (IsEqualIID (riid, &IID_IUnknown) 
191                 || IsEqualIID (riid, &IID_IDirectMusicObject)) {
192                 IDirectMusicGraphObject_AddRef(iface);
193                 *ppobj = This;
194                 return S_OK;
195         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
196                 IPersistStream_AddRef ((LPPERSISTSTREAM)This->pStream);
197                 *ppobj = (LPPERSISTSTREAM)This->pStream;
198                 return S_OK;
199         } else if (IsEqualIID (riid, &IID_IDirectMusicGraph)) {
200                 IDirectMusicGraph_AddRef ((LPDIRECTMUSICGRAPH)This->pGraph);
201                 *ppobj = (LPDIRECTMUSICGRAPH)This->pGraph;
202                 return S_OK;
203         }
204         
205         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
206         return E_NOINTERFACE;
207 }
208
209 ULONG WINAPI IDirectMusicGraphObject_AddRef (LPDIRECTMUSICOBJECT iface)
210 {
211         ICOM_THIS(IDirectMusicGraphObject,iface);
212         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
213         return ++(This->ref);
214 }
215
216 ULONG WINAPI IDirectMusicGraphObject_Release (LPDIRECTMUSICOBJECT iface)
217 {
218         ICOM_THIS(IDirectMusicGraphObject,iface);
219         ULONG ref = --This->ref;
220         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
221         if (ref == 0) {
222                 HeapFree(GetProcessHeap(), 0, This);
223         }
224         return ref;
225 }
226
227 /* IDirectMusicGraphObject IDirectMusicObject part: */
228 HRESULT WINAPI IDirectMusicGraphObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
229 {
230         ICOM_THIS(IDirectMusicGraphObject,iface);
231
232         TRACE("(%p, %p)\n", This, pDesc);
233         pDesc = This->pDesc;
234         
235         return S_OK;
236 }
237
238 HRESULT WINAPI IDirectMusicGraphObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
239 {
240         ICOM_THIS(IDirectMusicGraphObject,iface);
241
242         TRACE("(%p, %p)\n", This, pDesc);
243         This->pDesc = pDesc;
244
245         return S_OK;
246 }
247
248 HRESULT WINAPI IDirectMusicGraphObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc)
249 {
250         ICOM_THIS(IDirectMusicGraphObject,iface);
251
252         FIXME("(%p, %p, %p): stub\n", This, pStream, pDesc);
253
254         return S_OK;
255 }
256
257 ICOM_VTABLE(IDirectMusicObject) DirectMusicGraphObject_Vtbl =
258 {
259     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
260         IDirectMusicGraphObject_QueryInterface,
261         IDirectMusicGraphObject_AddRef,
262         IDirectMusicGraphObject_Release,
263         IDirectMusicGraphObject_GetDescriptor,
264         IDirectMusicGraphObject_SetDescriptor,
265         IDirectMusicGraphObject_ParseDescriptor
266 };
267
268 /* for ClassFactory */
269 HRESULT WINAPI DMUSIC_CreateDirectMusicGraphObject (LPCGUID lpcGUID, LPDIRECTMUSICOBJECT* ppObject, LPUNKNOWN pUnkOuter)
270 {
271         IDirectMusicGraphObject *obj;
272         
273         TRACE("(%p,%p,%p)\n", lpcGUID, ppObject, pUnkOuter);
274         if (IsEqualIID (lpcGUID, &IID_IDirectMusicObject)) {
275                 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicGraphObject));
276                 if (NULL == obj) {
277                         *ppObject = (LPDIRECTMUSICOBJECT) NULL;
278                         return E_OUTOFMEMORY;
279                 }
280                 obj->lpVtbl = &DirectMusicGraphObject_Vtbl;
281                 obj->ref = 1;
282                 /* prepare IPersistStream */
283                 obj->pStream = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicGraphObjectStream));
284                 obj->pStream->lpVtbl = &DirectMusicGraphObjectStream_Vtbl;
285                 obj->pStream->ref = 1;  
286                 obj->pStream->pParentObject = obj;
287                 /* prepare IDirectMusicGraph */
288                 DMUSIC_CreateDirectMusicGraph (&IID_IDirectMusicGraph, (LPDIRECTMUSICGRAPH*)&obj->pGraph, NULL);
289                 obj->pGraph->pObject = obj;
290                 *ppObject = (LPDIRECTMUSICOBJECT) obj;
291                 return S_OK;
292         }
293         WARN("No interface found\n");
294         
295         return E_NOINTERFACE;
296 }
297         
298 /*****************************************************************************
299  * IDirectMusicGraphObjectStream implementation
300  */
301 /* IDirectMusicGraphObjectStream IUnknown part: */
302 HRESULT WINAPI IDirectMusicGraphObjectStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj)
303 {
304         ICOM_THIS(IDirectMusicGraphObjectStream,iface);
305
306         if (IsEqualIID (riid, &IID_IUnknown)
307                 || IsEqualIID (riid, &IID_IPersistStream)) {
308                 IDirectMusicGraphObjectStream_AddRef(iface);
309                 *ppobj = This;
310                 return S_OK;
311         }
312         
313         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
314         return E_NOINTERFACE;
315 }
316
317 ULONG WINAPI IDirectMusicGraphObjectStream_AddRef (LPPERSISTSTREAM iface)
318 {
319         ICOM_THIS(IDirectMusicGraphObjectStream,iface);
320         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
321         return ++(This->ref);
322 }
323
324 ULONG WINAPI IDirectMusicGraphObjectStream_Release (LPPERSISTSTREAM iface)
325 {
326         ICOM_THIS(IDirectMusicGraphObjectStream,iface);
327         ULONG ref = --This->ref;
328         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
329         if (ref == 0) {
330                 HeapFree(GetProcessHeap(), 0, This);
331         }
332         return ref;
333 }
334
335 /* IDirectMusicGraphObjectStream IPersist part: */
336 HRESULT WINAPI IDirectMusicGraphObjectStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID)
337 {
338         return E_NOTIMPL;
339 }
340
341 /* IDirectMusicGraphObjectStream IPersistStream part: */
342 HRESULT WINAPI IDirectMusicGraphObjectStream_IsDirty (LPPERSISTSTREAM iface)
343 {
344         return E_NOTIMPL;
345 }
346
347 HRESULT WINAPI IDirectMusicGraphObjectStream_Load (LPPERSISTSTREAM iface, IStream* pStm)
348 {
349         FIXME(": Loading not implemented yet\n");
350         return S_OK;
351 }
352
353 HRESULT WINAPI IDirectMusicGraphObjectStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty)
354 {
355         return E_NOTIMPL;
356 }
357
358 HRESULT WINAPI IDirectMusicGraphObjectStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize)
359 {
360         return E_NOTIMPL;
361 }
362
363 ICOM_VTABLE(IPersistStream) DirectMusicGraphObjectStream_Vtbl =
364 {
365     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
366         IDirectMusicGraphObjectStream_QueryInterface,
367         IDirectMusicGraphObjectStream_AddRef,
368         IDirectMusicGraphObjectStream_Release,
369         IDirectMusicGraphObjectStream_GetClassID,
370         IDirectMusicGraphObjectStream_IsDirty,
371         IDirectMusicGraphObjectStream_Load,
372         IDirectMusicGraphObjectStream_Save,
373         IDirectMusicGraphObjectStream_GetSizeMax
374 };