oleobj.c 22.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2005 Jacek Caban
 *
 * 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 20 21 22 23 24 25 26 27 28 29
 */

#include "config.h"

#include <stdarg.h>
#include <stdio.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
30
#include "shlguid.h"
31 32
#include "mshtmdid.h"
#include "idispids.h"
33 34 35 36 37 38 39 40 41 42 43

#include "wine/debug.h"

#include "mshtml_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

/**********************************************************
 * IOleObject implementation
 */

Jacek Caban's avatar
Jacek Caban committed
44
#define OLEOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, OleObject, iface)
45 46 47

static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppvObject)
{
48
    HTMLDocument *This = OLEOBJ_THIS(iface);
49 50 51 52 53
    return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
}

static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
{
54
    HTMLDocument *This = OLEOBJ_THIS(iface);
55 56 57 58 59
    return IHTMLDocument2_AddRef(HTMLDOC(This));
}

static ULONG WINAPI OleObject_Release(IOleObject *iface)
{
60
    HTMLDocument *This = OLEOBJ_THIS(iface);
61 62 63 64 65
    return IHTMLDocument2_Release(HTMLDOC(This));
}

static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
{
66
    HTMLDocument *This = OLEOBJ_THIS(iface);
67
    IDocHostUIHandler *pDocHostUIHandler = NULL;
68
    IOleCommandTarget *cmdtrg = NULL;
69
    VARIANT silent;
70 71
    HRESULT hres;

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

74 75 76
    if(pClientSite == This->client)
        return S_OK;

77
    if(This->client) {
78
        IOleClientSite_Release(This->client);
79
        This->client = NULL;
80
        This->usermode = UNKNOWN_USERMODE;
81
    }
82

83
    if(This->hostui) {
84
        IDocHostUIHandler_Release(This->hostui);
85 86
        This->hostui = NULL;
    }
87

88 89
    memset(&This->hostinfo, 0, sizeof(DOCHOSTUIINFO));

90
    if(!pClientSite)
91 92 93 94 95 96 97 98 99 100 101
        return S_OK;

    hres = IOleObject_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&pDocHostUIHandler);
    if(SUCCEEDED(hres)) {
        DOCHOSTUIINFO hostinfo;
        LPOLESTR key_path = NULL, override_key_path = NULL;
        IDocHostUIHandler2 *pDocHostUIHandler2;

        memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
        hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
        hres = IDocHostUIHandler_GetHostInfo(pDocHostUIHandler, &hostinfo);
102
        if(SUCCEEDED(hres)) {
103
            TRACE("hostinfo = {%u %08x %08x %s %s}\n",
104 105
                    hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
                    debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
106 107
            memcpy(&This->hostinfo, &hostinfo, sizeof(DOCHOSTUIINFO));
        }
108

Jacek Caban's avatar
Jacek Caban committed
109 110 111 112 113 114 115 116 117
        if(!This->has_key_path) {
            hres = IDocHostUIHandler_GetOptionKeyPath(pDocHostUIHandler, &key_path, 0);
            if(hres == S_OK && key_path) {
                if(key_path[0]) {
                    /* FIXME: use key_path */
                    TRACE("key_path = %s\n", debugstr_w(key_path));
                }
                CoTaskMemFree(key_path);
            }
118

Jacek Caban's avatar
Jacek Caban committed
119 120 121 122 123 124 125 126 127 128 129
            hres = IDocHostUIHandler_QueryInterface(pDocHostUIHandler, &IID_IDocHostUIHandler2,
                    (void**)&pDocHostUIHandler2);
            if(SUCCEEDED(hres)) {
                hres = IDocHostUIHandler2_GetOverrideKeyPath(pDocHostUIHandler2, &override_key_path, 0);
                if(hres == S_OK && override_key_path && override_key_path[0]) {
                    if(override_key_path[0]) {
                        /*FIXME: use override_key_path */
                        TRACE("override_key_path = %s\n", debugstr_w(override_key_path));
                    }
                    CoTaskMemFree(override_key_path);
                }
130
                IDocHostUIHandler2_Release(pDocHostUIHandler2);
Jacek Caban's avatar
Jacek Caban committed
131 132 133
            }

            This->has_key_path = TRUE;
134 135 136
        }
    }

Jacek Caban's avatar
Jacek Caban committed
137 138 139 140 141 142 143 144 145 146 147 148 149
    /* Native calls here GetWindow. What is it for?
     * We don't have anything to do with it here (yet). */
    if(pClientSite) {
        IOleWindow *pOleWindow = NULL;
        HWND hwnd;

        hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&pOleWindow);
        if(SUCCEEDED(hres)) {
            IOleWindow_GetWindow(pOleWindow, &hwnd);
            IOleWindow_Release(pOleWindow);
        }
    }

150 151 152 153 154 155 156 157 158
    hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleCommandTarget, (void**)&cmdtrg);
    if(SUCCEEDED(hres)) {
        VARIANT var;
        OLECMD cmd = {OLECMDID_SETPROGRESSTEXT, 0};

        IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &cmd, NULL);

        V_VT(&var) = VT_I4;
        V_I4(&var) = 0;
159 160 161 162
        IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
                OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
        IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 
                OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
163 164 165 166

        IOleCommandTarget_Release(cmdtrg);
    }

167
    IOleClientSite_AddRef(pClientSite);
168
    This->client = pClientSite;
169
    This->hostui = pDocHostUIHandler;
170

171 172 173
    if(This->usermode == UNKNOWN_USERMODE)
        IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERMODE);

174
    IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_OFFLINEIFNOTCONNECTED); 
175 176 177 178 179 180 181 182 183

    hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
    if(SUCCEEDED(hres)) {
        if(V_VT(&silent) != VT_BOOL)
            WARN("V_VT(silent) = %d\n", V_VT(&silent));
        else if(V_BOOL(&silent))
            FIXME("silent == true\n");
    }

184 185 186
    IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERAGENT);
    IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_PALETTE);

187 188 189 190 191
    return S_OK;
}

static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
{
192 193
    HTMLDocument *This = OLEOBJ_THIS(iface);

194 195 196 197 198 199 200 201 202 203 204 205 206 207
    TRACE("(%p)->(%p)\n", This, ppClientSite);

    if(!ppClientSite)
        return E_INVALIDARG;

    if(This->client)
        IOleClientSite_AddRef(This->client);
    *ppClientSite = This->client;

    return S_OK;
}

static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
{
208
    HTMLDocument *This = OLEOBJ_THIS(iface);
209 210 211 212 213 214
    FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
{
215
    HTMLDocument *This = OLEOBJ_THIS(iface);
Jacek Caban's avatar
Jacek Caban committed
216

217
    TRACE("(%p)->(%08x)\n", This, dwSaveOption);
218 219 220 221 222 223

    if(dwSaveOption == OLECLOSE_PROMPTSAVE)
        FIXME("OLECLOSE_PROMPTSAVE not implemented\n");

    if(This->in_place_active)
        IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
Jacek Caban's avatar
Jacek Caban committed
224

225
    HTMLDocument_LockContainer(This, FALSE);
Jacek Caban's avatar
Jacek Caban committed
226 227
    
    return S_OK;
228 229 230 231
}

static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
{
232
    HTMLDocument *This = OLEOBJ_THIS(iface);
233
    FIXME("(%p %d %p)->()\n", This, dwWhichMoniker, pmk);
234 235 236 237 238
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
{
239
    HTMLDocument *This = OLEOBJ_THIS(iface);
240
    FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
241 242 243 244 245 246
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
                                        DWORD dwReserved)
{
247
    HTMLDocument *This = OLEOBJ_THIS(iface);
248
    FIXME("(%p)->(%p %x %d)\n", This, pDataObject, fCreation, dwReserved);
249 250 251 252 253
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
{
254
    HTMLDocument *This = OLEOBJ_THIS(iface);
255
    FIXME("(%p)->(%d %p)\n", This, dwReserved, ppDataObject);
256 257 258 259 260 261
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
                                        LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
{
262
    HTMLDocument *This = OLEOBJ_THIS(iface);
263 264 265
    IOleDocumentSite *pDocSite;
    HRESULT hres;

266
    TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
267

268
    if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) { 
269
        FIXME("iVerb = %d not supported\n", iVerb);
270 271 272 273 274 275 276 277
        return E_NOTIMPL;
    }

    if(!pActiveSite)
        pActiveSite = This->client;

    hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
    if(SUCCEEDED(hres)) {
278 279
        HTMLDocument_LockContainer(This, TRUE);

280 281
        /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
        hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
282 283 284 285 286 287 288 289 290 291 292 293 294 295
        IOleDocumentSite_Release(pDocSite);
    }else {
        hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
        if(SUCCEEDED(hres)) {
            if(lprcPosRect) {
                RECT rect; /* We need to pass rect as not const pointer */
                memcpy(&rect, lprcPosRect, sizeof(RECT));
                IOleDocumentView_SetRect(DOCVIEW(This), &rect);
            }
            IOleDocumentView_Show(DOCVIEW(This), TRUE);
        }
    }

    return hres;
296 297 298 299
}

static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
{
300
    HTMLDocument *This = OLEOBJ_THIS(iface);
301 302 303 304 305 306
    FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_Update(IOleObject *iface)
{
307
    HTMLDocument *This = OLEOBJ_THIS(iface);
308 309 310 311 312 313
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
{
314
    HTMLDocument *This = OLEOBJ_THIS(iface);
315 316 317 318 319 320
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
{
321 322
    HTMLDocument *This = OLEOBJ_THIS(iface);

323 324 325 326 327 328 329 330 331 332 333
    TRACE("(%p)->(%p)\n", This, pClsid);

    if(!pClsid)
        return E_INVALIDARG;

    memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
    return S_OK;
}

static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
{
334
    HTMLDocument *This = OLEOBJ_THIS(iface);
335
    FIXME("(%p)->(%d %p)\n", This, dwFormOfType, pszUserType);
336 337 338 339 340
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
{
341
    HTMLDocument *This = OLEOBJ_THIS(iface);
342
    FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
343 344 345 346 347
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
{
348
    HTMLDocument *This = OLEOBJ_THIS(iface);
349
    FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
350 351 352 353 354
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
{
355
    HTMLDocument *This = OLEOBJ_THIS(iface);
356 357 358 359 360 361
    FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
{
362
    HTMLDocument *This = OLEOBJ_THIS(iface);
363
    FIXME("(%p)->(%d)\n", This, dwConnection);
364 365 366 367 368
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
{
369
    HTMLDocument *This = OLEOBJ_THIS(iface);
370 371 372 373 374 375
    FIXME("(%p)->(%p)\n", This, ppenumAdvise);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
{
376
    HTMLDocument *This = OLEOBJ_THIS(iface);
377
    FIXME("(%p)->(%d %p)\n", This, dwAspect, pdwStatus);
378 379 380 381 382
    return E_NOTIMPL;
}

static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
{
383
    HTMLDocument *This = OLEOBJ_THIS(iface);
384 385 386 387
    FIXME("(%p)->(%p)\n", This, pLogpal);
    return E_NOTIMPL;
}

388 389
#undef OLEPBJ_THIS

390
static const IOleObjectVtbl OleObjectVtbl = {
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
    OleObject_QueryInterface,
    OleObject_AddRef,
    OleObject_Release,
    OleObject_SetClientSite,
    OleObject_GetClientSite,
    OleObject_SetHostNames,
    OleObject_Close,
    OleObject_SetMoniker,
    OleObject_GetMoniker,
    OleObject_InitFromData,
    OleObject_GetClipboardData,
    OleObject_DoVerb,
    OleObject_EnumVerbs,
    OleObject_Update,
    OleObject_IsUpToDate,
    OleObject_GetUserClassID,
    OleObject_GetUserType,
    OleObject_SetExtent,
    OleObject_GetExtent,
    OleObject_Advise,
    OleObject_Unadvise,
    OleObject_EnumAdvise,
    OleObject_GetMiscStatus,
    OleObject_SetColorScheme
};

/**********************************************************
 * IOleDocument implementation
 */

Jacek Caban's avatar
Jacek Caban committed
421
#define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
422 423 424

static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
{
425
    HTMLDocument *This = OLEDOC_THIS(iface);
426 427 428 429 430
    return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
}

static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
{
431
    HTMLDocument *This = OLEDOC_THIS(iface);
432 433 434 435 436
    return IHTMLDocument2_AddRef(HTMLDOC(This));
}

static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
{
437
    HTMLDocument *This = OLEDOC_THIS(iface);
438 439 440 441 442 443
    return IHTMLDocument2_Release(HTMLDOC(This));
}

static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
                                   DWORD dwReserved, IOleDocumentView **ppView)
{
444
    HTMLDocument *This = OLEDOC_THIS(iface);
445 446
    HRESULT hres;

447
    TRACE("(%p)->(%p %p %d %p)\n", This, pIPSite, pstm, dwReserved, ppView);
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470

    if(!ppView)
        return E_INVALIDARG;

    /* FIXME:
     * Windows implementation creates new IOleDocumentView when function is called for the
     * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
     * if the application uses returned interfaces, passed to ActivateMe or returned by
     * QueryInterface, so there is no reason to create new interface. This needs more testing.
     */

    if(pIPSite) {
        hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
        if(FAILED(hres))
            return hres;
    }

    if(pstm)
        FIXME("pstm is not supported\n");

    IOleDocumentView_AddRef(DOCVIEW(This));
    *ppView = DOCVIEW(This);
    return S_OK;
471 472 473 474
}

static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
{
475
    HTMLDocument *This = OLEDOC_THIS(iface);
476 477 478 479 480 481 482
    FIXME("(%p)->(%p)\n", This, pdwStatus);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
                                   IOleDocumentView **ppView)
{
483
    HTMLDocument *This = OLEDOC_THIS(iface);
484 485 486 487
    FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
    return E_NOTIMPL;
}

488 489
#undef OLEDOC_THIS

490
static const IOleDocumentVtbl OleDocumentVtbl = {
491 492 493 494 495 496 497 498
    OleDocument_QueryInterface,
    OleDocument_AddRef,
    OleDocument_Release,
    OleDocument_CreateView,
    OleDocument_GetDocMiscStatus,
    OleDocument_EnumViews
};

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
/**********************************************************
 * IOleControl implementation
 */

#define CONTROL_THIS(iface) DEFINE_THIS(HTMLDocument, OleControl, iface)

static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
}

static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    return IHTMLDocument2_AddRef(HTMLDOC(This));
}

static ULONG WINAPI OleControl_Release(IOleControl *iface)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    return IHTMLDocument_Release(HTMLDOC(This));
}

static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pCI);
    return E_NOTIMPL;
}

static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pMsg);
    return E_NOTIMPL;
}

537
HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
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
{
    IDispatch *disp = NULL;
    DISPPARAMS dispparams = {NULL, 0};
    UINT err;
    HRESULT hres;

    hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
    if(FAILED(hres)) {
        TRACE("Could not get IDispatch\n");
        return hres;
    }

    VariantInit(res);

    hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
            DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);

    IDispatch_Release(disp);

    return hres;
}

static HRESULT on_change_dlcontrol(HTMLDocument *This)
{
    VARIANT res;
    HRESULT hres;
    
565
    hres = get_client_disp_property(This->client, DISPID_AMBIENT_DLCONTROL, &res);
566
    if(SUCCEEDED(hres))
567
        FIXME("unsupported dlcontrol %08x\n", V_I4(&res));
568 569 570 571

    return S_OK;
}

572 573 574
static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
{
    HTMLDocument *This = CONTROL_THIS(iface);
575 576 577 578 579 580 581 582 583 584 585
    VARIANT res;
    HRESULT hres;

    if(!This->client) {
        TRACE("This->client = NULL\n");
        return S_OK;
    }

    switch(dispID) {
    case DISPID_AMBIENT_USERMODE:
        TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
586
        hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERMODE, &res);
587 588 589 590
        if(FAILED(hres))
            return S_OK;

        if(V_VT(&res) == VT_BOOL) {
591 592 593
            if(V_BOOL(&res)) {
                This->usermode = BROWSEMODE;
            }else {
594
                FIXME("edit mode is not supported\n");
595
                This->usermode = EDITMODE;
596 597 598 599 600 601 602 603 604 605 606
            }
        }else {
            FIXME("V_VT(res)=%d\n", V_VT(&res));
        }
        return S_OK;
    case DISPID_AMBIENT_DLCONTROL:
        TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
        return on_change_dlcontrol(This);
    case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
        TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
        on_change_dlcontrol(This);
607
        hres = get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
        if(FAILED(hres))
            return S_OK;

        if(V_VT(&res) == VT_BOOL) {
            if(V_BOOL(&res)) {
                FIXME("offline connection is not supported\n");
                hres = E_FAIL;
            }
        }else {
            FIXME("V_VT(res)=%d\n", V_VT(&res));
        }
        return S_OK;
    case DISPID_AMBIENT_SILENT:
        TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
        on_change_dlcontrol(This);
623
        hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &res);
624 625 626 627 628 629 630 631 632 633 634 635 636 637
        if(FAILED(hres))
            return S_OK;

        if(V_VT(&res) == VT_BOOL) {
            if(V_BOOL(&res)) {
                FIXME("silent mode is not supported\n");
                hres = E_FAIL;
            }
        }else {
            FIXME("V_VT(res)=%d\n", V_VT(&res));
        }
        return S_OK;
    case DISPID_AMBIENT_USERAGENT:
        TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
638
        hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERAGENT, &res);
639 640 641 642 643 644 645 646
        if(FAILED(hres))
            return S_OK;

        FIXME("not supported AMBIENT_USERAGENT\n");
        hres = E_FAIL;
        return S_OK;
    case DISPID_AMBIENT_PALETTE:
        TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
647
        hres = get_client_disp_property(This->client, DISPID_AMBIENT_PALETTE, &res);
648 649 650 651 652 653 654 655
        if(FAILED(hres))
            return S_OK;

        FIXME("not supported AMBIENT_PALETTE\n");
        hres = E_FAIL;
        return S_OK;
    }

656
    FIXME("(%p) unsupported dispID=%d\n", This, dispID);
657
    return E_FAIL;
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
}

static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
{
    HTMLDocument *This = CONTROL_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bFreeze);
    return E_NOTIMPL;
}

#undef CONTROL_THIS

static const IOleControlVtbl OleControlVtbl = {
    OleControl_QueryInterface,
    OleControl_AddRef,
    OleControl_Release,
    OleControl_GetControlInfo,
    OleControl_OnMnemonic,
    OleControl_OnAmbientPropertyChange,
    OleControl_FreezeEvents
};

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
/**********************************************************
 * ICustomDoc implementation
 */

#define CUSTOMDOC_THIS(iface) DEFINE_THIS(HTMLDocument, CustomDoc, iface)

static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = CUSTOMDOC_THIS(iface);
    return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
}

static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
{
    HTMLDocument *This = CUSTOMDOC_THIS(iface);
    return IHTMLDocument2_AddRef(HTMLDOC(This));
}

static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
{
    HTMLDocument *This = CUSTOMDOC_THIS(iface);
    return IHTMLDocument_Release(HTMLDOC(This));
}

static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
{
    HTMLDocument *This = CUSTOMDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pUIHandler);
    return E_NOTIMPL;
}

#undef CUSTOMDOC_THIS

static const ICustomDocVtbl CustomDocVtbl = {
    CustomDoc_QueryInterface,
    CustomDoc_AddRef,
    CustomDoc_Release,
    CustomDoc_SetUIHandler
};

719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
void HTMLDocument_LockContainer(HTMLDocument *This, BOOL fLock)
{
    IOleContainer *container;
    HRESULT hres;

    if(!This->client || This->container_locked == fLock)
        return;

    hres = IOleClientSite_GetContainer(This->client, &container);
    if(SUCCEEDED(hres)) {
        IOleContainer_LockContainer(container, fLock);
        This->container_locked = fLock;
        IOleContainer_Release(container);
    }
}

735 736 737 738
void HTMLDocument_OleObj_Init(HTMLDocument *This)
{
    This->lpOleObjectVtbl = &OleObjectVtbl;
    This->lpOleDocumentVtbl = &OleDocumentVtbl;
739
    This->lpOleControlVtbl = &OleControlVtbl;
740
    This->lpCustomDocVtbl = &CustomDocVtbl;
741

742 743
    This->usermode = UNKNOWN_USERMODE;

744
    This->client = NULL;
745
    This->hostui = NULL;
Jacek Caban's avatar
Jacek Caban committed
746 747

    This->has_key_path = FALSE;
748
    This->container_locked = FALSE;
749 750

    memset(&This->hostinfo, 0, sizeof(DOCHOSTUIINFO));
751
}