dmime: Use the generic IPersistStream for DMParamControlTrack.
[wine.git] / dlls / msxml3 / nodemap.c
blob2ad6f120f28c36e424040c79d8009c509e917c39
1 /*
2 * Node map implementation
4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define COBJMACROS
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "ole2.h"
36 #include "msxml6.h"
37 #include "msxml2did.h"
39 #include "msxml_private.h"
41 #include "wine/debug.h"
43 #ifdef HAVE_LIBXML2
45 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
47 typedef struct
49 DispatchEx dispex;
50 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface;
51 ISupportErrorInfo ISupportErrorInfo_iface;
52 LONG ref;
54 xmlNodePtr node;
55 LONG iterator;
56 IEnumVARIANT *enumvariant;
58 const struct nodemap_funcs *funcs;
59 } xmlnodemap;
61 static HRESULT nodemap_get_item(IUnknown *iface, LONG index, VARIANT *item)
63 V_VT(item) = VT_DISPATCH;
64 return IXMLDOMNamedNodeMap_get_item((IXMLDOMNamedNodeMap*)iface, index, (IXMLDOMNode**)&V_DISPATCH(item));
67 static const struct enumvariant_funcs nodemap_enumvariant = {
68 nodemap_get_item,
69 NULL
72 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
74 return CONTAINING_RECORD(iface, xmlnodemap, IXMLDOMNamedNodeMap_iface);
77 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
79 return CONTAINING_RECORD(iface, xmlnodemap, ISupportErrorInfo_iface);
82 static HRESULT WINAPI xmlnodemap_QueryInterface(
83 IXMLDOMNamedNodeMap *iface,
84 REFIID riid, void** ppvObject )
86 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
87 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
89 if( IsEqualGUID( riid, &IID_IUnknown ) ||
90 IsEqualGUID( riid, &IID_IDispatch ) ||
91 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
93 *ppvObject = iface;
95 else if (IsEqualGUID( riid, &IID_IEnumVARIANT ))
97 if (!This->enumvariant)
99 HRESULT hr = create_enumvariant((IUnknown*)iface, FALSE, &nodemap_enumvariant, &This->enumvariant);
100 if (FAILED(hr)) return hr;
103 return IEnumVARIANT_QueryInterface(This->enumvariant, &IID_IEnumVARIANT, ppvObject);
105 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
107 return *ppvObject ? S_OK : E_NOINTERFACE;
109 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
111 *ppvObject = &This->ISupportErrorInfo_iface;
113 else
115 TRACE("interface %s not implemented\n", debugstr_guid(riid));
116 *ppvObject = NULL;
117 return E_NOINTERFACE;
120 IXMLDOMNamedNodeMap_AddRef( iface );
122 return S_OK;
125 static ULONG WINAPI xmlnodemap_AddRef(
126 IXMLDOMNamedNodeMap *iface )
128 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
129 ULONG ref = InterlockedIncrement( &This->ref );
130 TRACE("(%p)->(%d)\n", This, ref);
131 return ref;
134 static ULONG WINAPI xmlnodemap_Release(
135 IXMLDOMNamedNodeMap *iface )
137 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
138 ULONG ref = InterlockedDecrement( &This->ref );
140 TRACE("(%p)->(%d)\n", This, ref);
141 if ( ref == 0 )
143 xmldoc_release( This->node->doc );
144 if (This->enumvariant) IEnumVARIANT_Release(This->enumvariant);
145 heap_free( This );
148 return ref;
151 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
152 IXMLDOMNamedNodeMap *iface,
153 UINT* pctinfo )
155 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
156 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
159 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
160 IXMLDOMNamedNodeMap *iface,
161 UINT iTInfo, LCID lcid,
162 ITypeInfo** ppTInfo )
164 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
165 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
166 iTInfo, lcid, ppTInfo);
169 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
170 IXMLDOMNamedNodeMap *iface,
171 REFIID riid, LPOLESTR* rgszNames,
172 UINT cNames, LCID lcid, DISPID* rgDispId )
174 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
175 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
176 riid, rgszNames, cNames, lcid, rgDispId);
179 static HRESULT WINAPI xmlnodemap_Invoke(
180 IXMLDOMNamedNodeMap *iface,
181 DISPID dispIdMember, REFIID riid, LCID lcid,
182 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
183 EXCEPINFO* pExcepInfo, UINT* puArgErr )
185 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
186 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
187 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
190 static HRESULT WINAPI xmlnodemap_getNamedItem(
191 IXMLDOMNamedNodeMap *iface,
192 BSTR name,
193 IXMLDOMNode** item)
195 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
197 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), item );
199 return This->funcs->get_named_item(This->node, name, item);
202 static HRESULT WINAPI xmlnodemap_setNamedItem(
203 IXMLDOMNamedNodeMap *iface,
204 IXMLDOMNode* newItem,
205 IXMLDOMNode** namedItem)
207 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
209 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem );
211 return This->funcs->set_named_item(This->node, newItem, namedItem);
214 static HRESULT WINAPI xmlnodemap_removeNamedItem(
215 IXMLDOMNamedNodeMap *iface,
216 BSTR name,
217 IXMLDOMNode** namedItem)
219 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
221 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
223 return This->funcs->remove_named_item(This->node, name, namedItem);
226 static HRESULT WINAPI xmlnodemap_get_item(
227 IXMLDOMNamedNodeMap *iface,
228 LONG index,
229 IXMLDOMNode** item)
231 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
233 TRACE("(%p)->(%d %p)\n", This, index, item);
235 return This->funcs->get_item(This->node, index, item);
238 static HRESULT WINAPI xmlnodemap_get_length(
239 IXMLDOMNamedNodeMap *iface,
240 LONG *length)
242 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
244 TRACE("(%p)->(%p)\n", This, length);
246 return This->funcs->get_length(This->node, length);
249 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
250 IXMLDOMNamedNodeMap *iface,
251 BSTR baseName,
252 BSTR namespaceURI,
253 IXMLDOMNode** item)
255 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
257 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
259 return This->funcs->get_qualified_item(This->node, baseName, namespaceURI, item);
262 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
263 IXMLDOMNamedNodeMap *iface,
264 BSTR baseName,
265 BSTR namespaceURI,
266 IXMLDOMNode** item)
268 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
270 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
272 return This->funcs->remove_qualified_item(This->node, baseName, namespaceURI, item);
275 static HRESULT WINAPI xmlnodemap_nextNode(
276 IXMLDOMNamedNodeMap *iface,
277 IXMLDOMNode** nextItem)
279 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
281 TRACE("(%p)->(%p: %d)\n", This, nextItem, This->iterator);
283 return This->funcs->next_node(This->node, &This->iterator, nextItem);
286 static HRESULT WINAPI xmlnodemap_reset(
287 IXMLDOMNamedNodeMap *iface )
289 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
291 TRACE("(%p)->(%d)\n", This, This->iterator);
293 This->iterator = 0;
295 return S_OK;
298 static HRESULT WINAPI xmlnodemap__newEnum(
299 IXMLDOMNamedNodeMap *iface,
300 IUnknown** enumv)
302 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
303 TRACE("(%p)->(%p)\n", This, enumv);
304 return create_enumvariant((IUnknown*)iface, TRUE, &nodemap_enumvariant, (IEnumVARIANT**)enumv);
307 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl =
309 xmlnodemap_QueryInterface,
310 xmlnodemap_AddRef,
311 xmlnodemap_Release,
312 xmlnodemap_GetTypeInfoCount,
313 xmlnodemap_GetTypeInfo,
314 xmlnodemap_GetIDsOfNames,
315 xmlnodemap_Invoke,
316 xmlnodemap_getNamedItem,
317 xmlnodemap_setNamedItem,
318 xmlnodemap_removeNamedItem,
319 xmlnodemap_get_item,
320 xmlnodemap_get_length,
321 xmlnodemap_getQualifiedItem,
322 xmlnodemap_removeQualifiedItem,
323 xmlnodemap_nextNode,
324 xmlnodemap_reset,
325 xmlnodemap__newEnum,
328 static HRESULT WINAPI support_error_QueryInterface(
329 ISupportErrorInfo *iface,
330 REFIID riid, void** ppvObject )
332 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
333 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
334 return IXMLDOMNamedNodeMap_QueryInterface(&This->IXMLDOMNamedNodeMap_iface, riid, ppvObject);
337 static ULONG WINAPI support_error_AddRef(
338 ISupportErrorInfo *iface )
340 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
341 return IXMLDOMNamedNodeMap_AddRef(&This->IXMLDOMNamedNodeMap_iface);
344 static ULONG WINAPI support_error_Release(
345 ISupportErrorInfo *iface )
347 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
348 return IXMLDOMNamedNodeMap_Release(&This->IXMLDOMNamedNodeMap_iface);
351 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
352 ISupportErrorInfo *iface,
353 REFIID riid )
355 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
356 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
357 return IsEqualGUID(riid, &IID_IXMLDOMNamedNodeMap) ? S_OK : S_FALSE;
360 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl =
362 support_error_QueryInterface,
363 support_error_AddRef,
364 support_error_Release,
365 support_error_InterfaceSupportsErrorInfo
368 static HRESULT xmlnodemap_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
370 WCHAR *ptr;
371 int idx = 0;
373 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
374 idx = idx*10 + (*ptr-'0');
375 if(*ptr)
376 return DISP_E_UNKNOWNNAME;
378 *dispid = DISPID_DOM_COLLECTION_BASE + idx;
379 TRACE("ret %x\n", *dispid);
380 return S_OK;
383 static HRESULT xmlnodemap_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
384 VARIANT *res, EXCEPINFO *ei)
386 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap*)iface );
388 TRACE("(%p)->(%x %x %x %p %p %p)\n", This, id, lcid, flags, params, res, ei);
390 V_VT(res) = VT_DISPATCH;
391 V_DISPATCH(res) = NULL;
393 if (id < DISPID_DOM_COLLECTION_BASE || id > DISPID_DOM_COLLECTION_MAX)
394 return DISP_E_UNKNOWNNAME;
396 switch(flags)
398 case INVOKE_PROPERTYGET:
400 IXMLDOMNode *disp = NULL;
402 IXMLDOMNamedNodeMap_get_item(&This->IXMLDOMNamedNodeMap_iface, id - DISPID_DOM_COLLECTION_BASE, &disp);
403 V_DISPATCH(res) = (IDispatch*)disp;
404 break;
406 default:
408 FIXME("unimplemented flags %x\n", flags);
409 break;
413 TRACE("ret %p\n", V_DISPATCH(res));
415 return S_OK;
418 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl = {
419 xmlnodemap_get_dispid,
420 xmlnodemap_invoke
423 static const tid_t xmlnodemap_iface_tids[] = {
424 IXMLDOMNamedNodeMap_tid,
428 static dispex_static_data_t xmlnodemap_dispex = {
429 &xmlnodemap_dispex_vtbl,
430 IXMLDOMNamedNodeMap_tid,
431 NULL,
432 xmlnodemap_iface_tids
435 IXMLDOMNamedNodeMap *create_nodemap(xmlNodePtr node, const struct nodemap_funcs *funcs)
437 xmlnodemap *This;
439 This = heap_alloc( sizeof *This );
440 if ( !This )
441 return NULL;
443 This->IXMLDOMNamedNodeMap_iface.lpVtbl = &XMLDOMNamedNodeMapVtbl;
444 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
445 This->node = node;
446 This->ref = 1;
447 This->iterator = 0;
448 This->enumvariant = NULL;
449 This->funcs = funcs;
451 init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMNamedNodeMap_iface, &xmlnodemap_dispex);
453 xmldoc_add_ref(node->doc);
455 return &This->IXMLDOMNamedNodeMap_iface;
458 #endif