htmlselect.c 21.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2006 Jacek Caban for CodeWeavers
 *
 * 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
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18 19
 */

#include <stdarg.h>
20
#include <assert.h>
21 22 23 24 25 26 27 28 29 30 31

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"

#include "wine/debug.h"

#include "mshtml_private.h"
32
#include "htmlevent.h"
33 34 35 36

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

typedef struct {
37 38
    HTMLElement element;

39
    IHTMLSelectElement IHTMLSelectElement_iface;
40 41 42 43

    nsIDOMHTMLSelectElement *nsselect;
} HTMLSelectElement;

44 45 46 47
static inline HTMLSelectElement *impl_from_IHTMLSelectElement(IHTMLSelectElement *iface)
{
    return CONTAINING_RECORD(iface, HTMLSelectElement, IHTMLSelectElement_iface);
}
48

49 50 51 52 53
static HRESULT htmlselect_item(HTMLSelectElement *This, int i, IDispatch **ret)
{
    nsIDOMHTMLOptionsCollection *nscol;
    nsIDOMNode *nsnode;
    nsresult nsres;
54
    HRESULT hres;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

    nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
    if(NS_FAILED(nsres)) {
        ERR("GetOptions failed: %08x\n", nsres);
        return E_FAIL;
    }

    nsres = nsIDOMHTMLOptionsCollection_Item(nscol, i, &nsnode);
    nsIDOMHTMLOptionsCollection_Release(nscol);
    if(NS_FAILED(nsres)) {
        ERR("Item failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nsnode) {
        HTMLDOMNode *node;

72
        hres = get_node(This->element.node.doc, nsnode, TRUE, &node);
73
        nsIDOMNode_Release(nsnode);
74 75
        if(FAILED(hres))
            return hres;
76

77
        *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
78 79 80 81 82 83
    }else {
        *ret = NULL;
    }
    return S_OK;
}

84 85 86
static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
                                                         REFIID riid, void **ppv)
{
87
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
88

89
    return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
90 91 92 93
}

static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
{
94
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
95

96
    return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
97 98 99 100
}

static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
{
101
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
102

103
    return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
104 105 106 107
}

static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
{
108
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
109

110
    return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
111 112 113 114 115
}

static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
                                              LCID lcid, ITypeInfo **ppTInfo)
{
116
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
117

118
    return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
119
            ppTInfo);
120 121 122 123 124 125
}

static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
126
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
127

128
    return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
129
            cNames, lcid, rgDispId);
130 131 132 133 134 135
}

static HRESULT WINAPI HTMLSelectElement_Invoke(IHTMLSelectElement *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
136
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
137

138
    return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
139
            lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
140 141
}

142
static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, LONG v)
143
{
144
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
145 146 147 148 149 150 151 152 153 154 155 156
    nsresult nsres;

    TRACE("(%p)->(%d)\n", This, v);
    if(v < 0)
        return CTL_E_INVALIDPROPERTYVALUE;

    nsres = nsIDOMHTMLSelectElement_SetSize(This->nsselect, v);
    if(NS_FAILED(nsres)) {
        ERR("SetSize failed: %08x\n", nsres);
        return E_FAIL;
    }
    return S_OK;
157 158
}

159
static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
160
{
161
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
162 163 164 165 166 167 168 169 170 171 172 173 174 175
    DWORD val;
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);
    if(!p)
        return E_INVALIDARG;

    nsres = nsIDOMHTMLSelectElement_GetSize(This->nsselect, &val);
    if(NS_FAILED(nsres)) {
        ERR("GetSize failed: %08x\n", nsres);
        return E_FAIL;
    }
    *p = val;
    return S_OK;
176 177 178 179
}

static HRESULT WINAPI HTMLSelectElement_put_multiple(IHTMLSelectElement *iface, VARIANT_BOOL v)
{
180
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
181 182 183 184 185 186 187
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_SetMultiple(This->nsselect, !!v);
    assert(nsres == NS_OK);
    return S_OK;
188 189 190 191
}

static HRESULT WINAPI HTMLSelectElement_get_multiple(IHTMLSelectElement *iface, VARIANT_BOOL *p)
{
192
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
193 194 195 196 197 198 199 200 201 202
    cpp_bool val;
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_GetMultiple(This->nsselect, &val);
    assert(nsres == NS_OK);

    *p = val ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
203 204 205 206
}

static HRESULT WINAPI HTMLSelectElement_put_name(IHTMLSelectElement *iface, BSTR v)
{
207
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
208 209 210 211 212 213 214 215 216 217 218 219 220
    nsAString str;
    nsresult nsres;

    TRACE("(%p)->(%s)\n", This, debugstr_w(v));
    nsAString_InitDepend(&str, v);
    nsres = nsIDOMHTMLSelectElement_SetName(This->nsselect, &str);
    nsAString_Finish(&str);

    if(NS_FAILED(nsres)) {
        ERR("SetName failed: %08x\n", nsres);
        return E_FAIL;
    }
    return S_OK;
221 222 223 224
}

static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
{
225
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
226 227 228 229 230 231 232
    nsAString name_str;
    nsresult nsres;

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

    nsAString_Init(&name_str, NULL);
    nsres = nsIDOMHTMLSelectElement_GetName(This->nsselect, &name_str);
233

234
    return return_nsstr(nsres, &name_str, p);
235 236 237 238
}

static HRESULT WINAPI HTMLSelectElement_get_options(IHTMLSelectElement *iface, IDispatch **p)
{
239
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
240 241 242

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

243
    *p = (IDispatch*)&This->IHTMLSelectElement_iface;
244 245
    IDispatch_AddRef(*p);
    return S_OK;
246 247 248 249
}

static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
{
250
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
251 252 253 254

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

    return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
255 256 257 258
}

static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
{
259
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
260 261 262 263
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

264
static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
265
{
266
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
267 268
    nsresult nsres;

269
    TRACE("(%p)->(%d)\n", This, v);
270 271 272 273 274 275

    nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
    if(NS_FAILED(nsres))
        ERR("SetSelectedIndex failed: %08x\n", nsres);

    return S_OK;
276 277
}

278
static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
279
{
280
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
281 282 283 284
    nsresult nsres;

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

285 286
    nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, p);
    if(NS_FAILED(nsres)) {
287
        ERR("GetSelectedIndex failed: %08x\n", nsres);
288 289
        return E_FAIL;
    }
290 291

    return S_OK;
292 293 294 295
}

static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
{
296
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
297 298 299 300 301 302 303
    nsAString type_str;
    nsresult nsres;

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

    nsAString_Init(&type_str, NULL);
    nsres = nsIDOMHTMLSelectElement_GetType(This->nsselect, &type_str);
304
    return return_nsstr(nsres, &type_str, p);
305 306 307 308
}

static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
{
309
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
310 311 312 313 314
    nsAString value_str;
    nsresult nsres;

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

315
    nsAString_InitDepend(&value_str, v);
316 317 318 319 320 321
    nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
    nsAString_Finish(&value_str);
    if(NS_FAILED(nsres))
        ERR("SetValue failed: %08x\n", nsres);

    return S_OK;
322 323 324 325
}

static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
{
326
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
327 328 329 330 331 332 333
    nsAString value_str;
    nsresult nsres;

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

    nsAString_Init(&value_str, NULL);
    nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
334
    return return_nsstr(nsres, &value_str, p);
335 336 337 338
}

static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
{
339
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
340 341 342 343 344 345 346 347 348 349 350
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_SetDisabled(This->nsselect, v != VARIANT_FALSE);
    if(NS_FAILED(nsres)) {
        ERR("SetDisabled failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
351 352 353 354
}

static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
{
355
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
356
    cpp_bool disabled = FALSE;
357 358 359 360 361 362 363 364 365 366 367 368
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_GetDisabled(This->nsselect, &disabled);
    if(NS_FAILED(nsres)) {
        ERR("GetDisabled failed: %08x\n", nsres);
        return E_FAIL;
    }

    *p = disabled ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
369 370 371 372
}

static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
{
373
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
    nsIDOMHTMLFormElement *nsform;
    nsIDOMNode *form_node;
    HTMLDOMNode *node;
    HRESULT hres;
    nsresult nsres;

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

    if(!p)
        return E_POINTER;

    nsres = nsIDOMHTMLSelectElement_GetForm(This->nsselect, &nsform);
    if (NS_FAILED(nsres)) {
        ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
        *p = NULL;
        return E_FAIL;
    }
    if (nsform == NULL) {
        TRACE("nsform not found\n");
        *p = NULL;
        return S_OK;
    }

    nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&form_node);
    nsIDOMHTMLFormElement_Release(nsform);
    assert(nsres == NS_OK);

    hres = get_node(This->element.node.doc, form_node, TRUE, &node);
    nsIDOMNode_Release(form_node);
    if (FAILED(hres))
        return hres;

    hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);

    node_release(node);
    return hres;
410 411 412 413 414
}

static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
                                            VARIANT before)
{
415
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
416 417 418 419 420
    nsIWritableVariant *nsvariant;
    HTMLElement *element_obj;
    nsresult nsres;

    TRACE("(%p)->(%p %s)\n", This, element, debugstr_variant(&before));
421

422 423 424 425 426 427 428 429 430
    element_obj = unsafe_impl_from_IHTMLElement(element);
    if(!element_obj) {
        FIXME("External IHTMLElement implementation?\n");
        return E_INVALIDARG;
    }

    nsvariant = create_nsvariant();
    if(!nsvariant)
        return E_FAIL;
431

432 433
    switch(V_VT(&before)) {
    case VT_EMPTY:
434
    case VT_ERROR:
435 436 437 438 439 440
        nsres = nsIWritableVariant_SetAsEmpty(nsvariant);
        break;
    case VT_I2:
        nsres = nsIWritableVariant_SetAsInt16(nsvariant, V_I2(&before));
        break;
    default:
441
        FIXME("unhandled before %s\n", debugstr_variant(&before));
442
        nsIWritableVariant_Release(nsvariant);
443 444 445
        return E_NOTIMPL;
    }

446 447 448 449 450 451 452
    if(NS_SUCCEEDED(nsres))
        nsres = nsIDOMHTMLSelectElement_Add(This->nsselect, element_obj->nselem, (nsIVariant*)nsvariant);
    nsIWritableVariant_Release(nsvariant);
    if(NS_FAILED(nsres)) {
        ERR("Add failed: %08x\n", nsres);
        return E_FAIL;
    }
453

454
    return S_OK;
455 456
}

457
static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
458
{
459
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
460 461
    nsresult nsres;
    TRACE("(%p)->(%d)\n", This, index);
462 463 464
    if(index < 0)
        return E_INVALIDARG;

465 466 467 468 469 470
    nsres = nsIDOMHTMLSelectElement_select_Remove(This->nsselect, index);
    if(NS_FAILED(nsres)) {
        ERR("Remove failed: %08x\n", nsres);
        return E_FAIL;
    }
    return S_OK;
471 472
}

473
static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
474
{
475
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
476 477 478 479 480 481 482 483 484
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
    if(NS_FAILED(nsres))
        ERR("SetLength failed: %08x\n", nsres);

    return S_OK;
485 486
}

487
static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
488
{
489
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
490
    UINT32 length = 0;
491 492 493 494 495 496 497 498 499 500
    nsresult nsres;

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

    nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
    if(NS_FAILED(nsres))
        ERR("GetLength failed: %08x\n", nsres);

    *p = length;

501
    TRACE("ret %d\n", *p);
502
    return S_OK;
503 504 505 506
}

static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
{
507
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
508 509 510 511 512 513 514
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
                                             VARIANT index, IDispatch **pdisp)
{
515
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
516 517 518 519 520 521 522 523 524 525 526 527 528 529

    TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);

    if(!pdisp)
        return E_POINTER;
    *pdisp = NULL;

    if(V_VT(&name) == VT_I4) {
        if(V_I4(&name) < 0)
            return E_INVALIDARG;
        return htmlselect_item(This, V_I4(&name), pdisp);
    }

    FIXME("Unsupported args\n");
530 531 532 533 534 535
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
                                             IDispatch **pdisp)
{
536
    HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
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
    FIXME("(%p)->(v %p)\n", This, pdisp);
    return E_NOTIMPL;
}

static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
    HTMLSelectElement_QueryInterface,
    HTMLSelectElement_AddRef,
    HTMLSelectElement_Release,
    HTMLSelectElement_GetTypeInfoCount,
    HTMLSelectElement_GetTypeInfo,
    HTMLSelectElement_GetIDsOfNames,
    HTMLSelectElement_Invoke,
    HTMLSelectElement_put_size,
    HTMLSelectElement_get_size,
    HTMLSelectElement_put_multiple,
    HTMLSelectElement_get_multiple,
    HTMLSelectElement_put_name,
    HTMLSelectElement_get_name,
    HTMLSelectElement_get_options,
    HTMLSelectElement_put_onchange,
    HTMLSelectElement_get_onchange,
    HTMLSelectElement_put_selectedIndex,
    HTMLSelectElement_get_selectedIndex,
    HTMLSelectElement_get_type,
    HTMLSelectElement_put_value,
    HTMLSelectElement_get_value,
    HTMLSelectElement_put_disabled,
    HTMLSelectElement_get_disabled,
    HTMLSelectElement_get_form,
    HTMLSelectElement_add,
    HTMLSelectElement_remove,
    HTMLSelectElement_put_length,
    HTMLSelectElement_get_length,
    HTMLSelectElement_get__newEnum,
    HTMLSelectElement_item,
    HTMLSelectElement_tags
};

575 576 577 578
static inline HTMLSelectElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLSelectElement, element.node);
}
579

580 581
static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
582
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
583 584 585 586 587

    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
588
        *ppv = &This->IHTMLSelectElement_iface;
589 590
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
591
        *ppv = &This->IHTMLSelectElement_iface;
592 593
    }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
        TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
594
        *ppv = &This->IHTMLSelectElement_iface;
595 596 597 598 599 600 601 602 603 604
    }

    if(*ppv) {
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
    }

    return HTMLElement_QI(&This->element.node, riid, ppv);
}

605 606
static HRESULT HTMLSelectElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
{
607
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
608
    return IHTMLSelectElement_put_disabled(&This->IHTMLSelectElement_iface, v);
609 610 611 612
}

static HRESULT HTMLSelectElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
{
613
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
614
    return IHTMLSelectElement_get_disabled(&This->IHTMLSelectElement_iface, p);
615 616
}

617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
#define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN

static HRESULT HTMLSelectElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD flags, DISPID *dispid)
{
    const WCHAR *ptr;
    DWORD idx = 0;

    for(ptr = name; *ptr && isdigitW(*ptr); ptr++) {
        idx = idx*10 + (*ptr-'0');
        if(idx > MSHTML_CUSTOM_DISPID_CNT) {
            WARN("too big idx\n");
            return DISP_E_UNKNOWNNAME;
        }
    }
    if(*ptr)
        return DISP_E_UNKNOWNNAME;

    *dispid = DISPID_OPTIONCOL_0 + idx;
    return S_OK;
}

static HRESULT HTMLSelectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
        VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
{
641
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
642 643 644 645 646

    TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);

    switch(flags) {
    case DISPATCH_PROPERTYGET: {
647 648
        IDispatch *ret;
        HRESULT hres;
649

650 651 652
        hres = htmlselect_item(This, id-DISPID_OPTIONCOL_0, &ret);
        if(FAILED(hres))
            return hres;
653

654
        if(ret) {
655
            V_VT(res) = VT_DISPATCH;
656
            V_DISPATCH(res) = ret;
657 658 659 660 661 662 663 664 665 666 667 668 669 670
        }else {
            V_VT(res) = VT_NULL;
        }
        break;
    }

    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }

    return S_OK;
}

671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
static void HTMLSelectElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
{
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);

    if(This->nsselect)
        note_cc_edge((nsISupports*)This->nsselect, "This->nsselect", cb);
}

static void HTMLSelectElement_unlink(HTMLDOMNode *iface)
{
    HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);

    if(This->nsselect) {
        nsIDOMHTMLSelectElement *nsselect = This->nsselect;

        This->nsselect = NULL;
        nsIDOMHTMLSelectElement_Release(nsselect);
    }
}

691
static const NodeImplVtbl HTMLSelectElementImplVtbl = {
692
    HTMLSelectElement_QI,
693
    HTMLElement_destructor,
694
    HTMLElement_cpc,
695
    HTMLElement_clone,
696
    HTMLElement_handle_event,
697
    HTMLElement_get_attr_col,
698
    NULL,
699
    NULL,
700
    HTMLSelectElementImpl_put_disabled,
701 702 703 704
    HTMLSelectElementImpl_get_disabled,
    NULL,
    NULL,
    HTMLSelectElement_get_dispid,
705 706 707 708
    HTMLSelectElement_invoke,
    NULL,
    HTMLSelectElement_traverse,
    HTMLSelectElement_unlink
709 710
};

711
static const tid_t HTMLSelectElement_tids[] = {
712
    HTMLELEMENT_TIDS,
713 714 715 716 717 718 719 720 721 722 723
    IHTMLSelectElement_tid,
    0
};

static dispex_static_data_t HTMLSelectElement_dispex = {
    NULL,
    DispHTMLSelectElement_tid,
    NULL,
    HTMLSelectElement_tids
};

724
HRESULT HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
725
{
726
    HTMLSelectElement *ret;
727 728
    nsresult nsres;

729 730 731 732
    ret = heap_alloc_zero(sizeof(HTMLSelectElement));
    if(!ret)
        return E_OUTOFMEMORY;

733
    ret->IHTMLSelectElement_iface.lpVtbl = &HTMLSelectElementVtbl;
734
    ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
735

736 737
    HTMLElement_Init(&ret->element, doc, nselem, &HTMLSelectElement_dispex);

738
    nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement,
739
                                             (void**)&ret->nsselect);
740
    assert(nsres == NS_OK);
741 742 743

    *elem = &ret->element;
    return S_OK;
744
}