user32: Move unpack_message call to User32CallWindowProc.
[wine.git] / dlls / msxml3 / nodemap.c
blobc90d46136a826623edb648189d83261e6e670158
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 #define COBJMACROS
23 #include <stdarg.h>
24 #include <libxml/parser.h>
25 #include <libxml/xmlerror.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "msxml6.h"
33 #include "msxml2did.h"
35 #include "msxml_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41 typedef struct
43 DispatchEx dispex;
44 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface;
45 ISupportErrorInfo ISupportErrorInfo_iface;
46 LONG ref;
48 xmlNodePtr node;
49 LONG iterator;
50 IEnumVARIANT *enumvariant;
52 const struct nodemap_funcs *funcs;
53 } xmlnodemap;
55 static HRESULT nodemap_get_item(IUnknown *iface, LONG index, VARIANT *item)
57 V_VT(item) = VT_DISPATCH;
58 return IXMLDOMNamedNodeMap_get_item((IXMLDOMNamedNodeMap*)iface, index, (IXMLDOMNode**)&V_DISPATCH(item));
61 static const struct enumvariant_funcs nodemap_enumvariant = {
62 nodemap_get_item,
63 NULL
66 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
68 return CONTAINING_RECORD(iface, xmlnodemap, IXMLDOMNamedNodeMap_iface);
71 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
73 return CONTAINING_RECORD(iface, xmlnodemap, ISupportErrorInfo_iface);
76 static HRESULT WINAPI xmlnodemap_QueryInterface(
77 IXMLDOMNamedNodeMap *iface,
78 REFIID riid, void** ppvObject )
80 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
81 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
83 if( IsEqualGUID( riid, &IID_IUnknown ) ||
84 IsEqualGUID( riid, &IID_IDispatch ) ||
85 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
87 *ppvObject = iface;
89 else if (IsEqualGUID( riid, &IID_IEnumVARIANT ))
91 if (!This->enumvariant)
93 HRESULT hr = create_enumvariant((IUnknown*)iface, FALSE, &nodemap_enumvariant, &This->enumvariant);
94 if (FAILED(hr)) return hr;
97 return IEnumVARIANT_QueryInterface(This->enumvariant, &IID_IEnumVARIANT, ppvObject);
99 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
101 return *ppvObject ? S_OK : E_NOINTERFACE;
103 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
105 *ppvObject = &This->ISupportErrorInfo_iface;
107 else
109 TRACE("interface %s not implemented\n", debugstr_guid(riid));
110 *ppvObject = NULL;
111 return E_NOINTERFACE;
114 IXMLDOMNamedNodeMap_AddRef( iface );
116 return S_OK;
119 static ULONG WINAPI xmlnodemap_AddRef(
120 IXMLDOMNamedNodeMap *iface )
122 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
123 ULONG ref = InterlockedIncrement( &This->ref );
124 TRACE("%p, refcount %lu.\n", iface, ref);
125 return ref;
128 static ULONG WINAPI xmlnodemap_Release(
129 IXMLDOMNamedNodeMap *iface )
131 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
132 ULONG ref = InterlockedDecrement( &This->ref );
134 TRACE("%p, refcount %lu.\n", iface, ref);
136 if (!ref)
138 xmlnode_release( This->node );
139 xmldoc_release( This->node->doc );
140 if (This->enumvariant) IEnumVARIANT_Release(This->enumvariant);
141 heap_free( This );
144 return ref;
147 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
148 IXMLDOMNamedNodeMap *iface,
149 UINT* pctinfo )
151 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
152 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
155 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
156 IXMLDOMNamedNodeMap *iface,
157 UINT iTInfo, LCID lcid,
158 ITypeInfo** ppTInfo )
160 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
161 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
162 iTInfo, lcid, ppTInfo);
165 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
166 IXMLDOMNamedNodeMap *iface,
167 REFIID riid, LPOLESTR* rgszNames,
168 UINT cNames, LCID lcid, DISPID* rgDispId )
170 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
171 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
172 riid, rgszNames, cNames, lcid, rgDispId);
175 static HRESULT WINAPI xmlnodemap_Invoke(
176 IXMLDOMNamedNodeMap *iface,
177 DISPID dispIdMember, REFIID riid, LCID lcid,
178 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
179 EXCEPINFO* pExcepInfo, UINT* puArgErr )
181 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
182 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
183 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
186 static HRESULT WINAPI xmlnodemap_getNamedItem(
187 IXMLDOMNamedNodeMap *iface,
188 BSTR name,
189 IXMLDOMNode** item)
191 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
193 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), item );
195 return This->funcs->get_named_item(This->node, name, item);
198 static HRESULT WINAPI xmlnodemap_setNamedItem(
199 IXMLDOMNamedNodeMap *iface,
200 IXMLDOMNode* newItem,
201 IXMLDOMNode** namedItem)
203 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
205 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem );
207 return This->funcs->set_named_item(This->node, newItem, namedItem);
210 static HRESULT WINAPI xmlnodemap_removeNamedItem(
211 IXMLDOMNamedNodeMap *iface,
212 BSTR name,
213 IXMLDOMNode** namedItem)
215 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
217 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
219 return This->funcs->remove_named_item(This->node, name, namedItem);
222 static HRESULT WINAPI xmlnodemap_get_item(
223 IXMLDOMNamedNodeMap *iface,
224 LONG index,
225 IXMLDOMNode** item)
227 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
229 TRACE("%p, %ld, %p.\n", iface, index, item);
231 return This->funcs->get_item(This->node, index, item);
234 static HRESULT WINAPI xmlnodemap_get_length(
235 IXMLDOMNamedNodeMap *iface,
236 LONG *length)
238 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
240 TRACE("(%p)->(%p)\n", This, length);
242 return This->funcs->get_length(This->node, length);
245 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
246 IXMLDOMNamedNodeMap *iface,
247 BSTR baseName,
248 BSTR namespaceURI,
249 IXMLDOMNode** item)
251 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
253 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
255 return This->funcs->get_qualified_item(This->node, baseName, namespaceURI, item);
258 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
259 IXMLDOMNamedNodeMap *iface,
260 BSTR baseName,
261 BSTR namespaceURI,
262 IXMLDOMNode** item)
264 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
266 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
268 return This->funcs->remove_qualified_item(This->node, baseName, namespaceURI, item);
271 static HRESULT WINAPI xmlnodemap_nextNode(
272 IXMLDOMNamedNodeMap *iface,
273 IXMLDOMNode** nextItem)
275 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
277 TRACE("%p, %p, %ld.\n", iface, nextItem, This->iterator);
279 return This->funcs->next_node(This->node, &This->iterator, nextItem);
282 static HRESULT WINAPI xmlnodemap_reset(
283 IXMLDOMNamedNodeMap *iface )
285 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
287 TRACE("%p, %ld.\n", iface, This->iterator);
289 This->iterator = 0;
291 return S_OK;
294 static HRESULT WINAPI xmlnodemap__newEnum(
295 IXMLDOMNamedNodeMap *iface,
296 IUnknown** enumv)
298 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
299 TRACE("(%p)->(%p)\n", This, enumv);
300 return create_enumvariant((IUnknown*)iface, TRUE, &nodemap_enumvariant, (IEnumVARIANT**)enumv);
303 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl =
305 xmlnodemap_QueryInterface,
306 xmlnodemap_AddRef,
307 xmlnodemap_Release,
308 xmlnodemap_GetTypeInfoCount,
309 xmlnodemap_GetTypeInfo,
310 xmlnodemap_GetIDsOfNames,
311 xmlnodemap_Invoke,
312 xmlnodemap_getNamedItem,
313 xmlnodemap_setNamedItem,
314 xmlnodemap_removeNamedItem,
315 xmlnodemap_get_item,
316 xmlnodemap_get_length,
317 xmlnodemap_getQualifiedItem,
318 xmlnodemap_removeQualifiedItem,
319 xmlnodemap_nextNode,
320 xmlnodemap_reset,
321 xmlnodemap__newEnum,
324 static HRESULT WINAPI support_error_QueryInterface(
325 ISupportErrorInfo *iface,
326 REFIID riid, void** ppvObject )
328 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
329 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
330 return IXMLDOMNamedNodeMap_QueryInterface(&This->IXMLDOMNamedNodeMap_iface, riid, ppvObject);
333 static ULONG WINAPI support_error_AddRef(
334 ISupportErrorInfo *iface )
336 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
337 return IXMLDOMNamedNodeMap_AddRef(&This->IXMLDOMNamedNodeMap_iface);
340 static ULONG WINAPI support_error_Release(
341 ISupportErrorInfo *iface )
343 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
344 return IXMLDOMNamedNodeMap_Release(&This->IXMLDOMNamedNodeMap_iface);
347 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
348 ISupportErrorInfo *iface,
349 REFIID riid )
351 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
352 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
353 return IsEqualGUID(riid, &IID_IXMLDOMNamedNodeMap) ? S_OK : S_FALSE;
356 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl =
358 support_error_QueryInterface,
359 support_error_AddRef,
360 support_error_Release,
361 support_error_InterfaceSupportsErrorInfo
364 static HRESULT xmlnodemap_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
366 WCHAR *ptr;
367 int idx = 0;
369 for(ptr = name; *ptr >= '0' && *ptr <= '9'; ptr++)
370 idx = idx*10 + (*ptr-'0');
371 if(*ptr)
372 return DISP_E_UNKNOWNNAME;
374 *dispid = DISPID_DOM_COLLECTION_BASE + idx;
375 TRACE("ret %lx\n", *dispid);
376 return S_OK;
379 static HRESULT xmlnodemap_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
380 VARIANT *res, EXCEPINFO *ei)
382 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap*)iface );
384 TRACE("%p, %ld, %lx, %x, %p, %p, %p.\n", iface, id, lcid, flags, params, res, ei);
386 V_VT(res) = VT_DISPATCH;
387 V_DISPATCH(res) = NULL;
389 if (id < DISPID_DOM_COLLECTION_BASE || id > DISPID_DOM_COLLECTION_MAX)
390 return DISP_E_UNKNOWNNAME;
392 switch(flags)
394 case INVOKE_PROPERTYGET:
396 IXMLDOMNode *disp = NULL;
398 IXMLDOMNamedNodeMap_get_item(&This->IXMLDOMNamedNodeMap_iface, id - DISPID_DOM_COLLECTION_BASE, &disp);
399 V_DISPATCH(res) = (IDispatch*)disp;
400 break;
402 default:
404 FIXME("unimplemented flags %x\n", flags);
405 break;
409 TRACE("ret %p\n", V_DISPATCH(res));
411 return S_OK;
414 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl = {
415 xmlnodemap_get_dispid,
416 xmlnodemap_invoke
419 static const tid_t xmlnodemap_iface_tids[] = {
420 IXMLDOMNamedNodeMap_tid,
424 static dispex_static_data_t xmlnodemap_dispex = {
425 &xmlnodemap_dispex_vtbl,
426 IXMLDOMNamedNodeMap_tid,
427 NULL,
428 xmlnodemap_iface_tids
431 IXMLDOMNamedNodeMap *create_nodemap(xmlNodePtr node, const struct nodemap_funcs *funcs)
433 xmlnodemap *This;
435 This = heap_alloc( sizeof *This );
436 if ( !This )
437 return NULL;
439 This->IXMLDOMNamedNodeMap_iface.lpVtbl = &XMLDOMNamedNodeMapVtbl;
440 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
441 This->node = node;
442 This->ref = 1;
443 This->iterator = 0;
444 This->enumvariant = NULL;
445 This->funcs = funcs;
447 init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMNamedNodeMap_iface, &xmlnodemap_dispex);
449 xmlnode_add_ref(node);
450 xmldoc_add_ref(node->doc);
452 return &This->IXMLDOMNamedNodeMap_iface;