domimpl.c 5.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 *    DOM Document Implementation implementation
 *
 * Copyright 2007 Alistair Leslie-Hughes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#define COBJMACROS

#include <stdarg.h>
24

25 26 27 28
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
29
#include "msxml6.h"
30

31
#include "msxml_dispex.h"
32 33 34

#include "wine/debug.h"

35 36
WINE_DEFAULT_DEBUG_CHANNEL(msxml);

37 38
typedef struct _domimpl
{
39
    DispatchEx dispex;
40
    IXMLDOMImplementation IXMLDOMImplementation_iface;
41 42 43 44 45
    LONG ref;
} domimpl;

static inline domimpl *impl_from_IXMLDOMImplementation( IXMLDOMImplementation *iface )
{
46
    return CONTAINING_RECORD(iface, domimpl, IXMLDOMImplementation_iface);
47 48
}

49
static HRESULT WINAPI domimpl_QueryInterface(
50 51 52 53 54
    IXMLDOMImplementation *iface,
    REFIID riid,
    void** ppvObject )
{
    domimpl *This = impl_from_IXMLDOMImplementation( iface );
55
    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
56 57 58 59 60 61 62

    if ( IsEqualGUID( riid, &IID_IXMLDOMImplementation ) ||
         IsEqualGUID( riid, &IID_IDispatch ) ||
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
63 64 65 66
    else if (dispex_query_interface(&This->dispex, riid, ppvObject))
    {
        return *ppvObject ? S_OK : E_NOINTERFACE;
    }
67 68
    else
    {
69
        TRACE("Unsupported interface %s\n", debugstr_guid(riid));
70
        *ppvObject = NULL;
71 72 73 74 75 76 77 78
        return E_NOINTERFACE;
    }

    IXMLDOMImplementation_AddRef( iface );

    return S_OK;
}

79
static ULONG WINAPI domimpl_AddRef(IXMLDOMImplementation *iface)
80
{
81 82 83
    domimpl *domimpl = impl_from_IXMLDOMImplementation(iface);
    ULONG ref = InterlockedIncrement(&domimpl->ref);
    TRACE("%p, refcount %lu.\n", iface, ref);
84
    return ref;
85 86
}

87
static ULONG WINAPI domimpl_Release(IXMLDOMImplementation *iface)
88
{
89 90 91 92
    domimpl *domimpl = impl_from_IXMLDOMImplementation(iface);
    ULONG ref = InterlockedDecrement(&domimpl->ref);

    TRACE("%p, refcount %lu.\n", iface, ref);
93

94 95
    if (!ref)
        heap_free(domimpl);
96 97 98 99

    return ref;
}

100
static HRESULT WINAPI domimpl_GetTypeInfoCount(
101 102 103
    IXMLDOMImplementation *iface,
    UINT* pctinfo )
{
104
    domimpl *This = impl_from_IXMLDOMImplementation( iface );
105
    return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
106 107
}

108
static HRESULT WINAPI domimpl_GetTypeInfo(
109 110 111 112
    IXMLDOMImplementation *iface,
    UINT iTInfo, LCID lcid,
    ITypeInfo** ppTInfo )
{
113
    domimpl *This = impl_from_IXMLDOMImplementation( iface );
114 115
    return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
        iTInfo, lcid, ppTInfo);
116 117
}

118
static HRESULT WINAPI domimpl_GetIDsOfNames(
119 120 121 122
    IXMLDOMImplementation *iface,
    REFIID riid, LPOLESTR* rgszNames,
    UINT cNames, LCID lcid, DISPID* rgDispId )
{
123
    domimpl *This = impl_from_IXMLDOMImplementation( iface );
124 125
    return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
        riid, rgszNames, cNames, lcid, rgDispId);
126 127
}

128
static HRESULT WINAPI domimpl_Invoke(
129 130 131 132 133
    IXMLDOMImplementation *iface,
    DISPID dispIdMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
    EXCEPINFO* pExcepInfo, UINT* puArgErr )
{
134
    domimpl *This = impl_from_IXMLDOMImplementation( iface );
135 136
    return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
        dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
137 138
}

139
static HRESULT WINAPI domimpl_hasFeature(IXMLDOMImplementation* This, BSTR feature, BSTR version, VARIANT_BOOL *hasFeature)
140
{
141 142 143 144
    static const WCHAR bVersion[] = {'1','.','0',0};
    static const WCHAR bXML[] = {'X','M','L',0};
    static const WCHAR bDOM[] = {'D','O','M',0};
    static const WCHAR bMSDOM[] = {'M','S','-','D','O','M',0};
145 146 147
    BOOL bValidFeature = FALSE;
    BOOL bValidVersion = FALSE;

148
    TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(feature), debugstr_w(version), hasFeature);
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

    if(!feature || !hasFeature)
        return E_INVALIDARG;

    *hasFeature = VARIANT_FALSE;

    if(!version || lstrcmpiW(version, bVersion) == 0)
        bValidVersion = TRUE;

    if(lstrcmpiW(feature, bXML) == 0 || lstrcmpiW(feature, bDOM) == 0 || lstrcmpiW(feature, bMSDOM) == 0)
        bValidFeature = TRUE;

    if(bValidVersion && bValidFeature)
        *hasFeature = VARIANT_TRUE;

    return S_OK;
}

167
static const struct IXMLDOMImplementationVtbl domimpl_vtbl =
168
{
169 170 171 172 173 174 175 176
    domimpl_QueryInterface,
    domimpl_AddRef,
    domimpl_Release,
    domimpl_GetTypeInfoCount,
    domimpl_GetTypeInfo,
    domimpl_GetIDsOfNames,
    domimpl_Invoke,
    domimpl_hasFeature
177 178
};

179 180
static const tid_t domimpl_iface_tids[] =
{
181 182 183 184
    IXMLDOMImplementation_tid,
    0
};

185 186
static dispex_static_data_t domimpl_dispex =
{
187 188 189
    NULL,
    IXMLDOMImplementation_tid,
    NULL,
190
    domimpl_iface_tids
191 192
};

193
HRESULT create_dom_implementation(IXMLDOMImplementation **ret)
194
{
195
    domimpl *object;
196

197 198
    if (!(object = heap_alloc(sizeof(*object))))
        return E_OUTOFMEMORY;
199

200
    object->IXMLDOMImplementation_iface.lpVtbl = &domimpl_vtbl;
201
    object->ref = 1;
202
    init_dispex(&object->dispex, (IUnknown *)&object->IXMLDOMImplementation_iface, &domimpl_dispex);
203

204 205 206
    *ret = &object->IXMLDOMImplementation_iface;

    return S_OK;
207
}