docfrag.c 16.2 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 24 25
/*
 *    DOM Document Fragment 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 "config.h"

#include <stdarg.h>
26 27 28 29 30
#ifdef HAVE_LIBXML2
# include <libxml/parser.h>
# include <libxml/xmlerror.h>
#endif

31 32 33 34
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
35
#include "msxml6.h"
36 37 38 39 40 41 42

#include "msxml_private.h"

#include "wine/debug.h"

#ifdef HAVE_LIBXML2

43 44
WINE_DEFAULT_DEBUG_CHANNEL(msxml);

45 46
typedef struct _domfrag
{
47
    xmlnode node;
48
    IXMLDOMDocumentFragment IXMLDOMDocumentFragment_iface;
49 50 51
    LONG ref;
} domfrag;

52 53 54
static const tid_t domfrag_se_tids[] = {
    IXMLDOMNode_tid,
    IXMLDOMDocumentFragment_tid,
55
    NULL_tid
56 57
};

58 59
static inline domfrag *impl_from_IXMLDOMDocumentFragment( IXMLDOMDocumentFragment *iface )
{
60
    return CONTAINING_RECORD(iface, domfrag, IXMLDOMDocumentFragment_iface);
61 62 63 64 65 66 67 68
}

static HRESULT WINAPI domfrag_QueryInterface(
    IXMLDOMDocumentFragment *iface,
    REFIID riid,
    void** ppvObject )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
69
    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
70 71

    if ( IsEqualGUID( riid, &IID_IXMLDOMDocumentFragment ) ||
72
         IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
73
         IsEqualGUID( riid, &IID_IDispatch ) ||
74 75 76 77
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
78 79 80 81
    else if(node_query_interface(&This->node, riid, ppvObject))
    {
        return *ppvObject ? S_OK : E_NOINTERFACE;
    }
82 83 84 85
    else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
    {
        return node_create_supporterrorinfo(domfrag_se_tids, ppvObject);
    }
86 87
    else
    {
88
        TRACE("Unsupported interface %s\n", debugstr_guid(riid));
89
        *ppvObject = NULL;
90 91 92
        return E_NOINTERFACE;
    }

93
    IXMLDOMDocumentFragment_AddRef(iface);
94 95 96 97 98 99 100
    return S_OK;
}

static ULONG WINAPI domfrag_AddRef(
    IXMLDOMDocumentFragment *iface )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
101 102 103
    ULONG ref = InterlockedIncrement( &This->ref );
    TRACE("(%p)->(%d)\n", This, ref);
    return ref;
104 105 106 107 108 109
}

static ULONG WINAPI domfrag_Release(
    IXMLDOMDocumentFragment *iface )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
110
    ULONG ref = InterlockedDecrement( &This->ref );
111

112
    TRACE("(%p)->(%d)\n", This, ref);
113 114
    if ( ref == 0 )
    {
115
        destroy_xmlnode(&This->node);
116
        heap_free( This );
117 118 119 120 121 122 123 124 125
    }

    return ref;
}

static HRESULT WINAPI domfrag_GetTypeInfoCount(
    IXMLDOMDocumentFragment *iface,
    UINT* pctinfo )
{
126
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
127
    return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
128 129 130 131 132 133 134
}

static HRESULT WINAPI domfrag_GetTypeInfo(
    IXMLDOMDocumentFragment *iface,
    UINT iTInfo, LCID lcid,
    ITypeInfo** ppTInfo )
{
135
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
136 137
    return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
        iTInfo, lcid, ppTInfo);
138 139 140 141 142 143 144
}

static HRESULT WINAPI domfrag_GetIDsOfNames(
    IXMLDOMDocumentFragment *iface,
    REFIID riid, LPOLESTR* rgszNames,
    UINT cNames, LCID lcid, DISPID* rgDispId )
{
145
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
146 147
    return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
        riid, rgszNames, cNames, lcid, rgDispId);
148 149 150 151 152 153 154 155
}

static HRESULT WINAPI domfrag_Invoke(
    IXMLDOMDocumentFragment *iface,
    DISPID dispIdMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
    EXCEPINFO* pExcepInfo, UINT* puArgErr )
{
156
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
157 158
    return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
        dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
159 160 161 162 163 164 165
}

static HRESULT WINAPI domfrag_get_nodeName(
    IXMLDOMDocumentFragment *iface,
    BSTR* p )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
166 167 168 169 170 171 172

    static const WCHAR document_fragmentW[] =
        {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0};

    TRACE("(%p)->(%p)\n", This, p);

    return return_bstr(document_fragmentW, p);
173 174 175 176
}

static HRESULT WINAPI domfrag_get_nodeValue(
    IXMLDOMDocumentFragment *iface,
177
    VARIANT* value)
178 179
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
180 181
    TRACE("(%p)->(%p)\n", This, value);
    return return_null_var(value);
182 183 184 185
}

static HRESULT WINAPI domfrag_put_nodeValue(
    IXMLDOMDocumentFragment *iface,
186
    VARIANT value)
187 188
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
189
    TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
190
    return E_FAIL;
191 192 193 194 195 196 197
}

static HRESULT WINAPI domfrag_get_nodeType(
    IXMLDOMDocumentFragment *iface,
    DOMNodeType* domNodeType )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
198 199 200 201 202

    TRACE("(%p)->(%p)\n", This, domNodeType);

    *domNodeType = NODE_DOCUMENT_FRAGMENT;
    return S_OK;
203 204 205 206 207 208 209
}

static HRESULT WINAPI domfrag_get_parentNode(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode** parent )
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
210 211 212 213

    TRACE("(%p)->(%p)\n", This, parent);

    return node_get_parent(&This->node, parent);
214 215 216 217 218 219 220
}

static HRESULT WINAPI domfrag_get_childNodes(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNodeList** outList)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
221 222 223 224

    TRACE("(%p)->(%p)\n", This, outList);

    return node_get_child_nodes(&This->node, outList);
225 226 227 228 229 230 231
}

static HRESULT WINAPI domfrag_get_firstChild(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode** domNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
232 233 234 235

    TRACE("(%p)->(%p)\n", This, domNode);

    return node_get_first_child(&This->node, domNode);
236 237 238 239 240 241 242
}

static HRESULT WINAPI domfrag_get_lastChild(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode** domNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
243 244 245

    TRACE("(%p)->(%p)\n", This, domNode);

246
    return node_get_last_child(&This->node, domNode);
247 248 249 250 251 252 253
}

static HRESULT WINAPI domfrag_get_previousSibling(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode** domNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
254 255 256 257

    TRACE("(%p)->(%p)\n", This, domNode);

    return return_null_node(domNode);
258 259 260 261 262 263 264
}

static HRESULT WINAPI domfrag_get_nextSibling(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode** domNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
265 266 267 268

    TRACE("(%p)->(%p)\n", This, domNode);

    return return_null_node(domNode);
269 270 271 272 273 274 275
}

static HRESULT WINAPI domfrag_get_attributes(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNamedNodeMap** attributeMap)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
276 277 278 279

    TRACE("(%p)->(%p)\n", This, attributeMap);

    return return_null_ptr((void**)attributeMap);
280 281 282 283
}

static HRESULT WINAPI domfrag_insertBefore(
    IXMLDOMDocumentFragment *iface,
284
    IXMLDOMNode* newNode, VARIANT refChild,
285 286 287
    IXMLDOMNode** outOldNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
288

289
    TRACE("(%p)->(%p %s %p)\n", This, newNode, debugstr_variant(&refChild), outOldNode);
290 291 292

    /* TODO: test */
    return node_insert_before(&This->node, newNode, &refChild, outOldNode);
293 294 295 296 297 298 299 300 301
}

static HRESULT WINAPI domfrag_replaceChild(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode* newNode,
    IXMLDOMNode* oldNode,
    IXMLDOMNode** outOldNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
302 303 304 305 306

    TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);

    /* TODO: test */
    return node_replace_child(&This->node, newNode, oldNode, outOldNode);
307 308 309 310
}

static HRESULT WINAPI domfrag_removeChild(
    IXMLDOMDocumentFragment *iface,
311
    IXMLDOMNode *child, IXMLDOMNode **oldChild)
312 313
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
314 315
    TRACE("(%p)->(%p %p)\n", This, child, oldChild);
    return node_remove_child(&This->node, child, oldChild);
316 317 318 319
}

static HRESULT WINAPI domfrag_appendChild(
    IXMLDOMDocumentFragment *iface,
320
    IXMLDOMNode *child, IXMLDOMNode **outChild)
321 322
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
323 324
    TRACE("(%p)->(%p %p)\n", This, child, outChild);
    return node_append_child(&This->node, child, outChild);
325 326 327 328
}

static HRESULT WINAPI domfrag_hasChildNodes(
    IXMLDOMDocumentFragment *iface,
329
    VARIANT_BOOL *ret)
330 331
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
332 333
    TRACE("(%p)->(%p)\n", This, ret);
    return node_has_childnodes(&This->node, ret);
334 335 336 337
}

static HRESULT WINAPI domfrag_get_ownerDocument(
    IXMLDOMDocumentFragment *iface,
338
    IXMLDOMDocument **doc)
339 340
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
341 342
    TRACE("(%p)->(%p)\n", This, doc);
    return node_get_owner_doc(&This->node, doc);
343 344 345 346
}

static HRESULT WINAPI domfrag_cloneNode(
    IXMLDOMDocumentFragment *iface,
347
    VARIANT_BOOL deep, IXMLDOMNode** outNode)
348 349
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
350 351
    TRACE("(%p)->(%d %p)\n", This, deep, outNode);
    return node_clone( &This->node, deep, outNode );
352 353 354 355 356 357 358
}

static HRESULT WINAPI domfrag_get_nodeTypeString(
    IXMLDOMDocumentFragment *iface,
    BSTR* p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
359 360 361 362 363
    static const WCHAR documentfragmentW[] = {'d','o','c','u','m','e','n','t','f','r','a','g','m','e','n','t',0};

    TRACE("(%p)->(%p)\n", This, p);

    return return_bstr(documentfragmentW, p);
364 365 366 367 368 369 370
}

static HRESULT WINAPI domfrag_get_text(
    IXMLDOMDocumentFragment *iface,
    BSTR* p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
371 372
    TRACE("(%p)->(%p)\n", This, p);
    return node_get_text(&This->node, p);
373 374 375 376 377 378 379
}

static HRESULT WINAPI domfrag_put_text(
    IXMLDOMDocumentFragment *iface,
    BSTR p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
380 381
    TRACE("(%p)->(%s)\n", This, debugstr_w(p));
    return node_put_text( &This->node, p );
382 383 384 385
}

static HRESULT WINAPI domfrag_get_specified(
    IXMLDOMDocumentFragment *iface,
386
    VARIANT_BOOL* isSpecified)
387 388
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
389 390 391
    FIXME("(%p)->(%p) stub!\n", This, isSpecified);
    *isSpecified = VARIANT_TRUE;
    return S_OK;
392 393 394 395
}

static HRESULT WINAPI domfrag_get_definition(
    IXMLDOMDocumentFragment *iface,
396
    IXMLDOMNode** definitionNode)
397 398
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
399 400
    FIXME("(%p)->(%p)\n", This, definitionNode);
    return E_NOTIMPL;
401 402 403 404
}

static HRESULT WINAPI domfrag_get_nodeTypedValue(
    IXMLDOMDocumentFragment *iface,
405
    VARIANT *v)
406 407
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
408 409
    TRACE("(%p)->(%p)\n", This, v);
    return return_null_var(v);
410 411 412 413
}

static HRESULT WINAPI domfrag_put_nodeTypedValue(
    IXMLDOMDocumentFragment *iface,
414
    VARIANT typedValue)
415 416
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
417 418
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
    return E_NOTIMPL;
419 420 421 422
}

static HRESULT WINAPI domfrag_get_dataType(
    IXMLDOMDocumentFragment *iface,
423
    VARIANT* typename)
424 425
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
426 427
    TRACE("(%p)->(%p)\n", This, typename);
    return return_null_var( typename );
428 429 430 431 432 433 434
}

static HRESULT WINAPI domfrag_put_dataType(
    IXMLDOMDocumentFragment *iface,
    BSTR p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
435

436
    TRACE("(%p)->(%s)\n", This, debugstr_w(p));
437 438 439 440 441

    if(!p)
        return E_INVALIDARG;

    return E_FAIL;
442 443 444 445 446 447 448
}

static HRESULT WINAPI domfrag_get_xml(
    IXMLDOMDocumentFragment *iface,
    BSTR* p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
449 450 451

    TRACE("(%p)->(%p)\n", This, p);

452
    return node_get_xml(&This->node, FALSE, p);
453 454 455 456
}

static HRESULT WINAPI domfrag_transformNode(
    IXMLDOMDocumentFragment *iface,
457
    IXMLDOMNode *node, BSTR *p)
458 459
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
460 461
    TRACE("(%p)->(%p %p)\n", This, node, p);
    return node_transform_node(&This->node, node, p);
462 463 464 465 466 467 468
}

static HRESULT WINAPI domfrag_selectNodes(
    IXMLDOMDocumentFragment *iface,
    BSTR p, IXMLDOMNodeList** outList)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
469 470
    TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
    return node_select_nodes(&This->node, p, outList);
471 472 473 474 475 476 477
}

static HRESULT WINAPI domfrag_selectSingleNode(
    IXMLDOMDocumentFragment *iface,
    BSTR p, IXMLDOMNode** outNode)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
478 479
    TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
    return node_select_singlenode(&This->node, p, outNode);
480 481 482 483
}

static HRESULT WINAPI domfrag_get_parsed(
    IXMLDOMDocumentFragment *iface,
484
    VARIANT_BOOL* isParsed)
485 486
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
487 488 489
    FIXME("(%p)->(%p) stub!\n", This, isParsed);
    *isParsed = VARIANT_TRUE;
    return S_OK;
490 491 492 493 494 495 496
}

static HRESULT WINAPI domfrag_get_namespaceURI(
    IXMLDOMDocumentFragment *iface,
    BSTR* p)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
497 498
    TRACE("(%p)->(%p)\n", This, p);
    return node_get_namespaceURI(&This->node, p);
499 500 501 502
}

static HRESULT WINAPI domfrag_get_prefix(
    IXMLDOMDocumentFragment *iface,
503
    BSTR* prefix)
504 505
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
506 507
    TRACE("(%p)->(%p)\n", This, prefix);
    return return_null_bstr( prefix );
508 509 510 511
}

static HRESULT WINAPI domfrag_get_baseName(
    IXMLDOMDocumentFragment *iface,
512
    BSTR* name)
513 514
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
515 516
    FIXME("(%p)->(%p): needs test\n", This, name);
    return return_null_bstr( name );
517 518 519 520 521 522 523
}

static HRESULT WINAPI domfrag_transformNodeToObject(
    IXMLDOMDocumentFragment *iface,
    IXMLDOMNode* domNode, VARIANT var1)
{
    domfrag *This = impl_from_IXMLDOMDocumentFragment( iface );
524 525
    FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
    return E_NOTIMPL;
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
}

static const struct IXMLDOMDocumentFragmentVtbl domfrag_vtbl =
{
    domfrag_QueryInterface,
    domfrag_AddRef,
    domfrag_Release,
    domfrag_GetTypeInfoCount,
    domfrag_GetTypeInfo,
    domfrag_GetIDsOfNames,
    domfrag_Invoke,
    domfrag_get_nodeName,
    domfrag_get_nodeValue,
    domfrag_put_nodeValue,
    domfrag_get_nodeType,
    domfrag_get_parentNode,
    domfrag_get_childNodes,
    domfrag_get_firstChild,
    domfrag_get_lastChild,
    domfrag_get_previousSibling,
    domfrag_get_nextSibling,
    domfrag_get_attributes,
    domfrag_insertBefore,
    domfrag_replaceChild,
    domfrag_removeChild,
    domfrag_appendChild,
    domfrag_hasChildNodes,
    domfrag_get_ownerDocument,
    domfrag_cloneNode,
    domfrag_get_nodeTypeString,
    domfrag_get_text,
    domfrag_put_text,
    domfrag_get_specified,
    domfrag_get_definition,
    domfrag_get_nodeTypedValue,
    domfrag_put_nodeTypedValue,
    domfrag_get_dataType,
    domfrag_put_dataType,
    domfrag_get_xml,
    domfrag_transformNode,
    domfrag_selectNodes,
    domfrag_selectSingleNode,
    domfrag_get_parsed,
    domfrag_get_namespaceURI,
    domfrag_get_prefix,
    domfrag_get_baseName,
    domfrag_transformNodeToObject
};

575 576 577 578 579 580 581 582 583 584 585 586
static const tid_t domfrag_iface_tids[] = {
    IXMLDOMDocumentFragment_tid,
    0
};

static dispex_static_data_t domfrag_dispex = {
    NULL,
    IXMLDOMDocumentFragment_tid,
    NULL,
    domfrag_iface_tids
};

587 588 589 590
IUnknown* create_doc_fragment( xmlNodePtr fragment )
{
    domfrag *This;

591
    This = heap_alloc( sizeof *This );
592 593 594
    if ( !This )
        return NULL;

595
    This->IXMLDOMDocumentFragment_iface.lpVtbl = &domfrag_vtbl;
596 597
    This->ref = 1;

598
    init_xmlnode(&This->node, fragment, (IXMLDOMNode*)&This->IXMLDOMDocumentFragment_iface, &domfrag_dispex);
599

600
    return (IUnknown*)&This->IXMLDOMDocumentFragment_iface;
601 602 603
}

#endif