client.c 15.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2005 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 20
#include <stdio.h>

21 22
#include "wine/debug.h"
#include "shdocvw.h"
23 24
#include "mshtmdid.h"
#include "idispids.h"
25 26 27

WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);

28
#define CLIENTSITE_THIS(iface) DEFINE_THIS(DocHost, OleClientSite, iface)
29 30 31

static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
{
32
    DocHost *This = CLIENTSITE_THIS(iface);
33 34 35 36 37 38 39 40 41

    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
        *ppv = CLIENTSITE(This);
    }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
        TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
        *ppv = CLIENTSITE(This);
42 43
    }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
        TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
44
        *ppv = INPLACESITE(This);
45 46
    }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
47
        *ppv = INPLACESITE(This);
48 49
    }else if(IsEqualGUID(&IID_IDocHostUIHandler, riid)) {
        TRACE("(%p)->(IID_IDocHostUIHandler %p)\n", This, ppv);
50
        *ppv = DOCHOSTUI(This);
51 52
    }else if(IsEqualGUID(&IID_IDocHostUIHandler2, riid)) {
        TRACE("(%p)->(IID_IDocHostUIHandler2 %p)\n", This, ppv);
53
        *ppv = DOCHOSTUI2(This);
54 55
    }else if(IsEqualGUID(&IID_IOleDocumentSite, riid)) {
        TRACE("(%p)->(IID_IOleDocumentSite %p)\n", This, ppv);
56
        *ppv = DOCSITE(This);
57 58
    }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
        TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
Jacek Caban's avatar
Jacek Caban committed
59
        *ppv = OLECMD(This);
60 61
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
62
        *ppv = CLDISP(This);
63 64
    }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
        TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
65
        *ppv = SERVPROV(This);
66 67 68
    }

    if(*ppv) {
69
        IOleClientSite_AddRef(CLIENTSITE(This));
70 71 72 73 74 75 76 77 78 79
        return S_OK;
    }

    WARN("Unsupported intrface %s\n", debugstr_guid(riid));

    return E_NOINTERFACE;
}

static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
{
80 81
    DocHost *This = CLIENTSITE_THIS(iface);
    return IDispatch_AddRef(This->disp);
82 83 84 85
}

static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
{
86 87
    DocHost *This = CLIENTSITE_THIS(iface);
    return IDispatch_Release(This->disp);
88 89 90 91
}

static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
{
92
    DocHost *This = CLIENTSITE_THIS(iface);
93 94 95 96 97 98 99
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
                                            DWORD dwWhichMoniker, IMoniker **ppmk)
{
100
    DocHost *This = CLIENTSITE_THIS(iface);
101
    FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
102 103 104 105 106
    return E_NOTIMPL;
}

static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
{
107
    DocHost *This = CLIENTSITE_THIS(iface);
108 109 110 111 112 113
    FIXME("(%p)->(%p)\n", This, ppContainer);
    return E_NOTIMPL;
}

static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
{
114
    DocHost *This = CLIENTSITE_THIS(iface);
115 116 117 118 119 120
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
{
121
    DocHost *This = CLIENTSITE_THIS(iface);
122 123 124 125 126 127
    FIXME("(%p)->(%x)\n", This, fShow);
    return E_NOTIMPL;
}

static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
{
128
    DocHost *This = CLIENTSITE_THIS(iface);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

#undef CLIENTSITE_THIS

static const IOleClientSiteVtbl OleClientSiteVtbl = {
    ClientSite_QueryInterface,
    ClientSite_AddRef,
    ClientSite_Release,
    ClientSite_SaveObject,
    ClientSite_GetMoniker,
    ClientSite_GetContainer,
    ClientSite_ShowObject,
    ClientSite_OnShowWindow,
    ClientSite_RequestNewObjectLayout
};

147
#define INPLACESITE_THIS(iface) DEFINE_THIS(DocHost, OleInPlaceSite, iface)
148 149 150

static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
{
151 152
    DocHost *This = INPLACESITE_THIS(iface);
    return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
153 154 155 156
}

static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
{
157 158
    DocHost *This = INPLACESITE_THIS(iface);
    return IOleClientSite_AddRef(CLIENTSITE(This));
159 160 161 162
}

static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
{
163 164
    DocHost *This = INPLACESITE_THIS(iface);
    return IOleClientSite_Release(CLIENTSITE(This));
165 166 167 168
}

static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
{
169
    DocHost *This = INPLACESITE_THIS(iface);
170 171 172

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

173
    *phwnd = This->hwnd;
174
    return S_OK;
175 176 177 178
}

static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
{
179
    DocHost *This = INPLACESITE_THIS(iface);
180 181 182 183 184 185
    FIXME("(%p)->(%x)\n", This, fEnterMode);
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
{
186
    DocHost *This = INPLACESITE_THIS(iface);
187 188 189 190 191

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

    /* Nothing to do here */
    return S_OK;
192 193 194 195
}

static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
{
196
    DocHost *This = INPLACESITE_THIS(iface);
197 198 199 200 201

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

    /* Nothing to do here */
    return S_OK;
202 203 204 205
}

static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
{
206
    DocHost *This = INPLACESITE_THIS(iface);
207 208 209 210 211 212 213 214
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
        IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
        LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
{
215
    DocHost *This = INPLACESITE_THIS(iface);
216 217

    TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect,
218
          lprcClipRect, lpFrameInfo);
219

220 221
    IOleInPlaceFrame_AddRef(INPLACEFRAME(This));
    *ppFrame = INPLACEFRAME(This);
222
    *ppDoc = NULL;
223

224
    GetClientRect(This->hwnd, lprcPosRect);
225
    *lprcClipRect = *lprcPosRect;
226 227 228

    lpFrameInfo->cb = sizeof(*lpFrameInfo);
    lpFrameInfo->fMDIApp = FALSE;
229
    lpFrameInfo->hwndFrame = This->frame_hwnd;
230 231 232 233
    lpFrameInfo->haccel = NULL;
    lpFrameInfo->cAccelEntries = 0; /* FIXME: should be 5 */

    return S_OK;
234 235 236 237
}

static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtent)
{
238
    DocHost *This = INPLACESITE_THIS(iface);
239
    FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
240 241 242 243 244
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
{
245
    DocHost *This = INPLACESITE_THIS(iface);
246 247 248 249 250 251
    FIXME("(%p)->(%x)\n", This, fUndoable);
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
{
252
    DocHost *This = INPLACESITE_THIS(iface);
253 254 255 256 257

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

    /* Nothing to do here */
    return S_OK;
258 259 260 261
}

static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
{
262
    DocHost *This = INPLACESITE_THIS(iface);
263 264 265 266 267 268
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
{
269
    DocHost *This = INPLACESITE_THIS(iface);
270 271 272 273 274 275 276
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface,
                                                  LPCRECT lprcPosRect)
{
277
    DocHost *This = INPLACESITE_THIS(iface);
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    FIXME("(%p)->(%p)\n", This, lprcPosRect);
    return E_NOTIMPL;
}

#undef INPLACESITE_THIS

static const IOleInPlaceSiteVtbl OleInPlaceSiteVtbl = {
    InPlaceSite_QueryInterface,
    InPlaceSite_AddRef,
    InPlaceSite_Release,
    InPlaceSite_GetWindow,
    InPlaceSite_ContextSensitiveHelp,
    InPlaceSite_CanInPlaceActivate,
    InPlaceSite_OnInPlaceActivate,
    InPlaceSite_OnUIActivate,
    InPlaceSite_GetWindowContext,
    InPlaceSite_Scroll,
    InPlaceSite_OnUIDeactivate,
    InPlaceSite_OnInPlaceDeactivate,
    InPlaceSite_DiscardUndoState,
    InPlaceSite_DeactivateAndUndo,
    InPlaceSite_OnPosRectChange
};

302
#define DOCSITE_THIS(iface) DEFINE_THIS(DocHost, OleDocumentSite, iface)
303 304 305 306

static HRESULT WINAPI OleDocumentSite_QueryInterface(IOleDocumentSite *iface,
                                                     REFIID riid, void **ppv)
{
307 308
    DocHost *This = DOCSITE_THIS(iface);
    return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
309 310 311 312
}

static ULONG WINAPI OleDocumentSite_AddRef(IOleDocumentSite *iface)
{
313 314
    DocHost *This = DOCSITE_THIS(iface);
    return IOleClientSite_AddRef(CLIENTSITE(This));
315 316 317 318
}

static ULONG WINAPI OleDocumentSite_Release(IOleDocumentSite *iface)
{
319 320
    DocHost *This = DOCSITE_THIS(iface);
    return IOleClientSite_Release(CLIENTSITE(This));
321 322 323 324 325
}

static HRESULT WINAPI OleDocumentSite_ActivateMe(IOleDocumentSite *iface,
                                                 IOleDocumentView *pViewToActivate)
{
326
    DocHost *This = DOCSITE_THIS(iface);
327 328 329 330 331 332 333 334 335 336
    IOleDocument *oledoc;
    RECT rect;
    HRESULT hres;

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

    hres = IUnknown_QueryInterface(This->document, &IID_IOleDocument, (void**)&oledoc);
    if(FAILED(hres))
        return hres;

337
    IOleDocument_CreateView(oledoc, INPLACESITE(This), NULL, 0, &This->view);
338 339
    IOleDocument_Release(oledoc);

340
    GetClientRect(This->hwnd, &rect);
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
    IOleDocumentView_SetRect(This->view, &rect);

    hres = IOleDocumentView_Show(This->view, TRUE);

    return hres;
}

#undef DOCSITE_THIS

static const IOleDocumentSiteVtbl OleDocumentSiteVtbl = {
    OleDocumentSite_QueryInterface,
    OleDocumentSite_AddRef,
    OleDocumentSite_Release,
    OleDocumentSite_ActivateMe
};

357
#define DISP_THIS(iface) DEFINE_THIS(DocHost, Dispatch, iface)
358 359 360

static HRESULT WINAPI ClDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
{
361 362
    DocHost *This = DISP_THIS(iface);
    return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
363 364 365 366
}

static ULONG WINAPI ClDispatch_AddRef(IDispatch *iface)
{
367 368
    DocHost *This = DISP_THIS(iface);
    return IOleClientSite_AddRef(CLIENTSITE(This));
369 370 371 372
}

static ULONG WINAPI ClDispatch_Release(IDispatch *iface)
{
373 374
    DocHost *This = DISP_THIS(iface);
    return IOleClientSite_Release(CLIENTSITE(This));
375 376 377 378
}

static HRESULT WINAPI ClDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
{
379
    DocHost *This = DISP_THIS(iface);
380 381 382

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

383 384 385 386
    return E_NOTIMPL;
}

static HRESULT WINAPI ClDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
387
                                             ITypeInfo **ppTInfo)
388
{
389
    DocHost *This = DISP_THIS(iface);
390

391
    TRACE("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
392

393 394 395 396
    return E_NOTIMPL;
}

static HRESULT WINAPI ClDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
397
                                               UINT cNames, LCID lcid, DISPID *rgDispId)
398
{
399
    DocHost *This = DISP_THIS(iface);
400

401
    TRACE("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
402
          lcid, rgDispId);
403

404 405 406
    return E_NOTIMPL;
}

407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
static const char *debugstr_dispid(DISPID dispid)
{
    static char buf[16];

#define CASE_DISPID(did) case did: return #did
    switch(dispid) {
        CASE_DISPID(DISPID_AMBIENT_USERMODE);
        CASE_DISPID(DISPID_AMBIENT_DLCONTROL);
        CASE_DISPID(DISPID_AMBIENT_USERAGENT);
        CASE_DISPID(DISPID_AMBIENT_PALETTE);
        CASE_DISPID(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
        CASE_DISPID(DISPID_AMBIENT_SILENT);
    }
#undef CASE_DISPID

    sprintf(buf, "%d", dispid);
    return buf;
}

426
static HRESULT WINAPI ClDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
427 428
                                        LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                                        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
429
{
430
    DocHost *This = DISP_THIS(iface);
431 432 433 434 435

    TRACE("(%p)->(%s %s %d %04x %p %p %p %p)\n", This, debugstr_dispid(dispIdMember),
          debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);

    switch(dispIdMember) {
436 437 438 439 440 441 442 443
    case DISPID_AMBIENT_USERMODE:
    case DISPID_AMBIENT_DLCONTROL:
    case DISPID_AMBIENT_USERAGENT:
    case DISPID_AMBIENT_PALETTE:
        if(!This->client_disp)
            return E_FAIL;
        return IDispatch_Invoke(This->client_disp, dispIdMember, riid, lcid, wFlags,
                                pDispParams, pVarResult, pExcepInfo, puArgErr);
444 445 446 447 448 449 450 451 452 453 454
    case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
        V_VT(pVarResult) = VT_BOOL;
        V_BOOL(pVarResult) = This->offline;
        return S_OK;
    case DISPID_AMBIENT_SILENT:
        V_VT(pVarResult) = VT_BOOL;
        V_BOOL(pVarResult) = This->offline;
        return S_OK;
    }

    FIXME("unhandled dispid %d\n", dispIdMember);
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
    return E_NOTIMPL;
}

#undef DISP_THIS

static const IDispatchVtbl DispatchVtbl = {
    ClDispatch_QueryInterface,
    ClDispatch_AddRef,
    ClDispatch_Release,
    ClDispatch_GetTypeInfoCount,
    ClDispatch_GetTypeInfo,
    ClDispatch_GetIDsOfNames,
    ClDispatch_Invoke
};

470
#define SERVPROV_THIS(iface) DEFINE_THIS(DocHost, ServiceProvider, iface)
471 472 473 474

static HRESULT WINAPI ClServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid,
                                                       void **ppv)
{
475 476
    DocHost *This = SERVPROV_THIS(iface);
    return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
477 478 479 480
}

static ULONG WINAPI ClServiceProvider_AddRef(IServiceProvider *iface)
{
481 482
    DocHost *This = SERVPROV_THIS(iface);
    return IOleClientSite_AddRef(CLIENTSITE(This));
483 484 485 486
}

static ULONG WINAPI ClServiceProvider_Release(IServiceProvider *iface)
{
487 488
    DocHost *This = SERVPROV_THIS(iface);
    return IOleClientSite_Release(CLIENTSITE(This));
489 490 491 492 493
}

static HRESULT WINAPI ClServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
                                                     REFIID riid, void **ppv)
{
494
    DocHost *This = SERVPROV_THIS(iface);
495 496 497

    if(IsEqualGUID(&IID_IHlinkFrame, guidService)) {
        TRACE("(%p)->(IID_IHlinkFrame %s %p)\n", This, debugstr_guid(riid), ppv);
498
        return IDispatch_QueryInterface(This->disp, riid, ppv);
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    }

    FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);

    return E_NOINTERFACE;
}

#undef SERVPROV_THIS

static const IServiceProviderVtbl ServiceProviderVtbl = {
    ClServiceProvider_QueryInterface,
    ClServiceProvider_AddRef,
    ClServiceProvider_Release,
    ClServiceProvider_QueryService
};

515
void DocHost_ClientSite_Init(DocHost *This)
516
{
517 518 519 520 521
    This->lpOleClientSiteVtbl   = &OleClientSiteVtbl;
    This->lpOleInPlaceSiteVtbl  = &OleInPlaceSiteVtbl;
    This->lpOleDocumentSiteVtbl = &OleDocumentSiteVtbl;
    This->lpDispatchVtbl        = &DispatchVtbl;
    This->lpServiceProviderVtbl = &ServiceProviderVtbl;
522

523
    This->view = NULL;
524 525
}

526
void DocHost_ClientSite_Release(DocHost *This)
527
{
528 529
    if(This->view)
        IOleDocumentView_Release(This->view);
530
}