Fix the case of product and company names.
[wine] / dlls / quartz / enummoniker.c
1 /*
2  * IEnumMoniker implementation
3  *
4  * Copyright 2003 Robert Shearman
5  *
6  * This file contains the (internal) driver registration functions,
7  * driver enumeration APIs and DirectDraw creation functions.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #define COM_NO_WINDOWS_H
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ole2.h"
30 #include "strmif.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
35
36 typedef struct EnumMonikerImpl
37 {
38     ICOM_VFIELD(IEnumMoniker);
39     ULONG ref;
40     IMoniker ** ppMoniker;
41     ULONG nMonikerCount;
42     ULONG index;
43 } EnumMonikerImpl;
44
45 static struct ICOM_VTABLE(IEnumMoniker) EnumMonikerImpl_Vtbl;
46
47 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface);
48
49 HRESULT EnumMonikerImpl_Create(IMoniker ** ppMoniker, ULONG nMonikerCount, IEnumMoniker ** ppEnum)
50 {
51     /* NOTE: assumes that array of IMonikers has already been AddRef'd
52      * I.e. this function does not AddRef the array of incoming
53      * IMonikers */
54     EnumMonikerImpl * pemi = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
55
56     TRACE("(%p, %ld, %p)\n", ppMoniker, nMonikerCount, ppEnum);
57
58     *ppEnum = NULL;
59
60     if (!pemi)
61         return E_OUTOFMEMORY;
62
63     pemi->lpVtbl = &EnumMonikerImpl_Vtbl;
64     pemi->ref = 1;
65     pemi->ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker*));
66     memcpy(pemi->ppMoniker, ppMoniker, nMonikerCount*sizeof(IMoniker*));
67     pemi->nMonikerCount = nMonikerCount;
68     pemi->index = 0;
69
70     *ppEnum = (IEnumMoniker *)pemi;
71
72     return S_OK;
73 }
74
75 /**********************************************************************
76  * IEnumMoniker_QueryInterface (also IUnknown)
77  */
78 static HRESULT WINAPI EnumMonikerImpl_QueryInterface(
79     LPENUMMONIKER iface,
80     REFIID riid,
81     LPVOID *ppvObj)
82 {
83     ICOM_THIS(EnumMonikerImpl, iface);
84     TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
85
86     if (This == NULL || ppvObj == NULL) return E_POINTER;
87
88     if (IsEqualGUID(riid, &IID_IUnknown) ||
89         IsEqualGUID(riid, &IID_IEnumMoniker))
90     {
91         *ppvObj = (LPVOID)iface;
92         EnumMonikerImpl_AddRef(iface);
93         return S_OK;
94     }
95
96     FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
97     return E_NOINTERFACE;
98 }
99
100 /**********************************************************************
101  * IEnumMoniker_AddRef (also IUnknown)
102  */
103 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface)
104 {
105     ICOM_THIS(EnumMonikerImpl, iface);
106
107     TRACE("\n");
108
109     if (This == NULL) return E_POINTER;
110
111     return InterlockedIncrement(&This->ref);
112 }
113
114 /**********************************************************************
115  * IEnumMoniker_Release (also IUnknown)
116  */
117 static ULONG WINAPI EnumMonikerImpl_Release(LPENUMMONIKER iface)
118 {
119     ICOM_THIS(EnumMonikerImpl, iface);
120
121     TRACE("\n");
122
123     if (!InterlockedDecrement(&This->ref))
124     {
125         CoTaskMemFree(This->ppMoniker);
126         This->ppMoniker = NULL;
127         CoTaskMemFree(This);
128         return 0;
129     }
130     return This->ref;
131 }
132
133 static HRESULT WINAPI EnumMonikerImpl_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
134 {
135     ULONG fetched;
136     ICOM_THIS(EnumMonikerImpl, iface);
137
138     TRACE("(%ld, %p, %p)\n", celt, rgelt, pceltFetched);
139
140     for (fetched = 0; (This->index + fetched < This->nMonikerCount) && (fetched < celt); fetched++)
141     {
142         rgelt[fetched] = This->ppMoniker[This->index + fetched];
143         IMoniker_AddRef(rgelt[fetched]);
144     }
145
146     This->index += fetched;
147
148     if (pceltFetched)
149         *pceltFetched = fetched;
150
151     if (fetched != celt)
152         return S_FALSE;
153     else
154         return S_OK;
155 }
156
157 static HRESULT WINAPI EnumMonikerImpl_Skip(LPENUMMONIKER iface, ULONG celt)
158 {
159     ICOM_THIS(EnumMonikerImpl, iface);
160
161     TRACE("(%ld)\n", celt);
162
163     This->index += celt;
164
165     return S_OK;
166 }
167
168 static HRESULT WINAPI EnumMonikerImpl_Reset(LPENUMMONIKER iface)
169 {
170     ICOM_THIS(EnumMonikerImpl, iface);
171
172     TRACE("()\n");
173
174     This->index = 0;
175
176     return S_OK;
177 }
178
179 static HRESULT WINAPI EnumMonikerImpl_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
180 {
181     FIXME("(%p): stub\n", ppenum);
182
183     return E_NOTIMPL;
184 }
185
186 /**********************************************************************
187  * IEnumMoniker_Vtbl
188  */
189 static ICOM_VTABLE(IEnumMoniker) EnumMonikerImpl_Vtbl =
190 {
191     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
192     EnumMonikerImpl_QueryInterface,
193     EnumMonikerImpl_AddRef,
194     EnumMonikerImpl_Release,
195     EnumMonikerImpl_Next,
196     EnumMonikerImpl_Skip,
197     EnumMonikerImpl_Reset,
198     EnumMonikerImpl_Clone
199 };