1 /* 2 * Copyright 2004, 2005 Martin Fuchs 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 20 // 21 // Explorer clone 22 // 23 // webchild.h 24 // 25 // Martin Fuchs, 08.02.2004 26 // 27 28 29 #ifndef _MSC_VER 30 #include <exdisp.h> // for IConnectionPointContainer 31 #include <exdispid.h> // for DWebBrowserEvents2 IDs 32 #endif 33 34 #ifndef DISPID_BEFORENAVIGATE // missing in MinGW (as of 07.02.2004) 35 #define DISPID_BEFORENAVIGATE 100 36 #define DISPID_NAVIGATECOMPLETE 101 37 #define DISPID_STATUSTEXTCHANGE 102 38 #define DISPID_QUIT 103 39 #define DISPID_DOWNLOADCOMPLETE 104 40 #define DISPID_COMMANDSTATECHANGE 105 41 #define DISPID_DOWNLOADBEGIN 106 42 #define DISPID_NEWWINDOW 107 43 #define DISPID_PROGRESSCHANGE 108 44 #define DISPID_WINDOWMOVE 109 45 #define DISPID_WINDOWRESIZE 110 46 #define DISPID_WINDOWACTIVATE 111 47 #define DISPID_PROPERTYCHANGE 112 48 #define DISPID_TITLECHANGE 113 49 #define DISPID_TITLEICONCHANGE 114 50 #define DISPID_FRAMEBEFORENAVIGATE 200 51 #define DISPID_FRAMENAVIGATECOMPLETE 201 52 #define DISPID_FRAMENEWWINDOW 204 53 54 #define DISPID_NAVIGATECOMPLETE2 252 55 #define DISPID_ONQUIT 253 56 #define DISPID_ONVISIBLE 254 57 #define DISPID_ONTOOLBAR 255 58 #define DISPID_ONMENUBAR 256 59 #define DISPID_ONSTATUSBAR 257 60 #define DISPID_ONFULLSCREEN 258 61 #define DISPID_DOCUMENTCOMPLETE 259 62 #define DISPID_ONTHEATERMODE 260 63 #define DISPID_ONADDRESSBAR 261 64 #define DISPID_WINDOWSETRESIZABLE 262 65 #define DISPID_WINDOWCLOSING 263 66 #define DISPID_WINDOWSETLEFT 264 67 #define DISPID_WINDOWSETTOP 265 68 #define DISPID_WINDOWSETWIDTH 266 69 #define DISPID_WINDOWSETHEIGHT 267 70 #define DISPID_CLIENTTOHOSTWINDOW 268 71 #define DISPID_SETSECURELOCKICON 269 72 #define DISPID_FILEDOWNLOAD 270 73 #define DISPID_NAVIGATEERROR 271 74 #define DISPID_PRIVACYIMPACTEDSTATECHANGE 272 75 #endif 76 77 #ifndef V_INT // missing in MinGW (as of 07.02.2004) 78 #define V_INT(x) V_UNION(x, intVal) 79 #endif 80 81 #ifdef _MSC_VER 82 #pragma warning(disable: 4355) // use of 'this' for initialization of _connector 83 #endif 84 85 86 template<typename T> struct ConnectionPoint : public SIfacePtr<T> 87 { ConnectionPointConnectionPoint88 ConnectionPoint(IConnectionPointContainer* pCPC, REFIID riid) 89 { 90 CheckError(pCPC->FindConnectionPoint(riid, &this->_p)); 91 } 92 }; 93 94 struct EventConnection 95 { EventConnectionEventConnection96 EventConnection(IConnectionPoint* connectionpoint, IUnknown* sink) 97 { 98 CheckError(connectionpoint->Advise(sink, &_cookie)); 99 _connectionpoint = connectionpoint; 100 } 101 EventConnectionEventConnection102 template<typename T> EventConnection(T& connectionpoint, IUnknown* sink) 103 { 104 CheckError(connectionpoint->Advise(sink, &_cookie)); 105 _connectionpoint = connectionpoint; 106 } 107 108 /* template<typename T> EventConnection(SIfacePtr<T>& connectionpoint, IUnknown* sink) 109 { 110 CheckError(connectionpoint->Advise(sink, &_cookie)); 111 _connectionpoint = connectionpoint.GetPtr(); 112 } */ 113 114 /* template<typename T> EventConnection(T& connectionpoint, IUnknown* sink) 115 { 116 CheckError(connectionpoint->Advise(sink, &_cookie)); 117 _connectionpoint = connectionpoint; 118 } */ 119 ~EventConnectionEventConnection120 ~EventConnection() 121 { 122 if (_connectionpoint) 123 _connectionpoint->Unadvise(_cookie); 124 } 125 126 protected: 127 SIfacePtr<IConnectionPoint> _connectionpoint; 128 DWORD _cookie; 129 }; 130 131 struct EventConnector : public EventConnection 132 { EventConnectorEventConnector133 EventConnector(IUnknown* unknown, REFIID riid, IUnknown* sink) 134 : EventConnection(ConnectionPoint<IConnectionPoint>( 135 SIfacePtr<IConnectionPointContainer>(unknown, IID_IConnectionPointContainer), riid), sink) 136 { 137 } 138 }; 139 140 141 struct OleInPlaceClient : public SimpleComObject, 142 public IOleClientSite, 143 public IOleInPlaceSite 144 { 145 protected: 146 HWND _hwnd; 147 148 public: 149 OleInPlaceClient(HWND hwnd=0) _hwndOleInPlaceClient150 : _hwnd(hwnd) 151 { 152 } 153 attachOleInPlaceClient154 void attach(HWND hwnd) 155 { 156 _hwnd = hwnd; 157 } 158 159 HRESULT attach_control(IOleObject* ole_obj, LONG iVerb=OLEIVERB_INPLACEACTIVATE, HWND hwndParent=0, LPCRECT pRect=NULL) 160 { 161 HRESULT hr = ole_obj->SetClientSite(this); 162 if (FAILED(hr)) 163 return hr; 164 165 // hr = ole_obj->SetHostNames(app, doc)); 166 167 hr = ole_obj->DoVerb(iVerb, NULL, this, 0, 0/*hwnd*/, NULL/*&rcPos*/); 168 169 return hr; 170 } 171 172 HRESULT detach(IOleObject* ole_obj, DWORD dwSaveOption=OLECLOSE_SAVEIFDIRTY) 173 { 174 HRESULT hr = ole_obj->Close(dwSaveOption); 175 176 _hwnd = 0; 177 178 return hr; 179 } 180 QueryInterfaceOleInPlaceClient181 STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppv) 182 { 183 if (IsEqualIID(riid, IID_IOleClientSite)) 184 {*ppv=static_cast<IOleClientSite*>(this); IncRef(); return S_OK;} 185 186 if (IsEqualIID(riid, IID_IOleInPlaceSite)) 187 {*ppv=static_cast<IOleInPlaceSite*>(this); IncRef(); return S_OK;} 188 189 if (IsEqualIID(riid, IID_IUnknown)) 190 {*ppv=static_cast<IOleClientSite/*oder auch IOleInPlaceSite*/*>(this); IncRef(); return S_OK;} 191 192 return E_NOINTERFACE; 193 } 194 AddRefOleInPlaceClient195 STDMETHODIMP_(ULONG) AddRef() {return IncRef();} ReleaseOleInPlaceClient196 STDMETHODIMP_(ULONG) Release() {return DecRef();} 197 198 199 // IOleWindow: 200 GetWindowOleInPlaceClient201 virtual /* [input_sync] */ HRESULT STDMETHODCALLTYPE GetWindow(/* [out] */ HWND __RPC_FAR *phwnd) 202 { 203 *phwnd = _hwnd; 204 return S_OK; 205 } 206 ContextSensitiveHelpOleInPlaceClient207 virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(/* [in] */ BOOL fEnterMode) 208 { 209 return E_NOTIMPL; 210 } 211 212 213 // IOleClientSite: 214 SaveObjectOleInPlaceClient215 virtual HRESULT STDMETHODCALLTYPE SaveObject() 216 { 217 return E_NOTIMPL; 218 } 219 GetMonikerOleInPlaceClient220 virtual HRESULT STDMETHODCALLTYPE GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker __RPC_FAR *__RPC_FAR *ppmk) 221 { 222 return E_NOTIMPL; 223 } 224 GetContainerOleInPlaceClient225 virtual HRESULT STDMETHODCALLTYPE GetContainer(IOleContainer __RPC_FAR *__RPC_FAR *ppContainer) 226 { 227 ppContainer = 0; 228 return E_NOINTERFACE; 229 } 230 ShowObjectOleInPlaceClient231 virtual HRESULT STDMETHODCALLTYPE ShowObject() 232 { 233 return S_OK; 234 } 235 OnShowWindowOleInPlaceClient236 virtual HRESULT STDMETHODCALLTYPE OnShowWindow(BOOL fShow) 237 { 238 return S_OK; 239 } 240 RequestNewObjectLayoutOleInPlaceClient241 virtual HRESULT STDMETHODCALLTYPE RequestNewObjectLayout() 242 { 243 return S_OK; 244 } 245 246 247 // IOleInPlaceSite: 248 CanInPlaceActivateOleInPlaceClient249 virtual HRESULT STDMETHODCALLTYPE CanInPlaceActivate() 250 { 251 return S_OK; 252 } 253 OnInPlaceActivateOleInPlaceClient254 virtual HRESULT STDMETHODCALLTYPE OnInPlaceActivate() 255 { 256 return S_OK; 257 } 258 OnUIActivateOleInPlaceClient259 virtual HRESULT STDMETHODCALLTYPE OnUIActivate() 260 { 261 return S_OK; 262 } 263 GetWindowContextOleInPlaceClient264 virtual HRESULT STDMETHODCALLTYPE GetWindowContext( 265 /* [out] */ IOleInPlaceFrame __RPC_FAR *__RPC_FAR *ppFrame, 266 /* [out] */ IOleInPlaceUIWindow __RPC_FAR *__RPC_FAR *ppDoc, 267 /* [out] */ LPRECT lprcPosRect, 268 /* [out] */ LPRECT lprcClipRect, 269 /* [out][in] */ LPOLEINPLACEFRAMEINFO lpFrameInfo) 270 { 271 ClientRect rect(_hwnd); 272 273 ppFrame = 0; 274 ppDoc = 0; 275 *lprcPosRect = rect; 276 *lprcClipRect = rect; 277 278 assert(lpFrameInfo->cb>=sizeof(OLEINPLACEFRAMEINFO)); 279 lpFrameInfo->fMDIApp = FALSE; //@@ 280 lpFrameInfo->hwndFrame = 0; 281 lpFrameInfo->haccel = 0; 282 lpFrameInfo->cAccelEntries = 0; 283 284 return S_OK; 285 } 286 ScrollOleInPlaceClient287 virtual HRESULT STDMETHODCALLTYPE Scroll(/* [in] */ SIZE scrollExtant) 288 { 289 return S_OK; 290 } 291 OnUIDeactivateOleInPlaceClient292 virtual HRESULT STDMETHODCALLTYPE OnUIDeactivate(/* [in] */ BOOL fUndoable) 293 { 294 return S_OK; 295 } 296 OnInPlaceDeactivateOleInPlaceClient297 virtual HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate() 298 { 299 return S_OK; 300 } 301 DiscardUndoStateOleInPlaceClient302 virtual HRESULT STDMETHODCALLTYPE DiscardUndoState() 303 { 304 return S_OK; 305 } 306 DeactivateAndUndoOleInPlaceClient307 virtual HRESULT STDMETHODCALLTYPE DeactivateAndUndo() 308 { 309 return S_OK; 310 } 311 OnPosRectChangeOleInPlaceClient312 virtual HRESULT STDMETHODCALLTYPE OnPosRectChange(/* [in] */ LPCRECT lprcPosRect) 313 { 314 return S_OK; 315 } 316 }; 317 318 319 // window with in place activates Active-X Control 320 321 template<typename BASE, typename SMARTPTR> struct IPCtrlWindow : public BASE 322 { 323 typedef BASE super; 324 IPCtrlWindowIPCtrlWindow325 IPCtrlWindow(HWND hwnd) 326 : super(hwnd) 327 { 328 } 329 IPCtrlWindowIPCtrlWindow330 template<typename T> IPCtrlWindow(HWND hwnd, T& info) 331 : super(hwnd, info) 332 { 333 } 334 create_controlIPCtrlWindow335 HRESULT create_control(HWND hwnd, REFIID clsid, REFIID riid) 336 { 337 // Erzeugen einer Instanz des Controls 338 HRESULT hr = _control.CreateInstance(clsid, riid); 339 if (FAILED(hr)) 340 return hr; 341 342 _client_side.attach(hwnd); 343 344 hr = _client_side.attach_control(SIfacePtr<IOleObject>(_control, IID_IOleObject)/*, OLEIVERB_INPLACEACTIVATE, 345 hwnd, &Rect(10, 10, 500, 500)*/); 346 if (FAILED(hr)) 347 return hr; 348 349 // try to get a IOleInPlaceObject interface for window resizing 350 return _control.QueryInterface(IID_IOleInPlaceObject, &_in_place_object); // _in_place_object = _control 351 } 352 353 protected: WndProcIPCtrlWindow354 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) 355 { 356 if (nmsg == WM_SIZE) { 357 if (_in_place_object) { 358 RECT rect = {0, 0, LOWORD(lparam), HIWORD(lparam)}; 359 360 _in_place_object->SetObjectRects(&rect, &rect); 361 } 362 } else if (nmsg == WM_CLOSE) { 363 _in_place_object = NULL; 364 365 if (_control) { 366 _client_side.detach(SIfacePtr<IOleObject>(_control, IID_IOleObject), OLECLOSE_NOSAVE); 367 _control = NULL; 368 } 369 } 370 371 return super::WndProc(nmsg, wparam, lparam); 372 } 373 374 ComInit _usingCOM; 375 SMARTPTR _control; 376 OleInPlaceClient _client_side; 377 SIfacePtr<IOleInPlaceObject> _in_place_object; 378 }; 379 380 381 382 #include "exdispid.h" 383 384 385 struct DWebBrowserEvents2IF 386 { ~DWebBrowserEvents2IFDWebBrowserEvents2IF387 virtual ~DWebBrowserEvents2IF() {} 388 StatusTextChangeDWebBrowserEvents2IF389 virtual void StatusTextChange(const BStr& text) 390 {} 391 ProgressChangeDWebBrowserEvents2IF392 virtual void ProgressChange(long progress, long progressMax) 393 {} 394 WindowMoveDWebBrowserEvents2IF395 virtual void WindowMove() 396 {} 397 WindowResizeDWebBrowserEvents2IF398 virtual void WindowResize() 399 {} 400 WindowActivateDWebBrowserEvents2IF401 virtual void WindowActivate() 402 {} 403 PropertyChangeDWebBrowserEvents2IF404 virtual void PropertyChange(const BStr& property) 405 {} 406 DownloadCompleteDWebBrowserEvents2IF407 virtual void DownloadComplete() 408 {} 409 CommandStateChangeDWebBrowserEvents2IF410 virtual void CommandStateChange(long command, bool enable) 411 {} 412 DownloadBeginDWebBrowserEvents2IF413 virtual void DownloadBegin() 414 {} 415 NewWindow2DWebBrowserEvents2IF416 virtual void NewWindow2(IDispatch** ppDisp, VARIANT_BOOL& cancel) 417 {} 418 TitleChangeDWebBrowserEvents2IF419 virtual void TitleChange(const BStr& text) 420 {} 421 TitleIconChangeDWebBrowserEvents2IF422 virtual void TitleIconChange(const BStr& text) 423 {} 424 FrameBeforeNavigateDWebBrowserEvents2IF425 virtual void FrameBeforeNavigate(const BStr& url, long flags, const BStr& targetFrameName, VARIANT* postData, const BStr& headers, VARIANT_BOOL& cancel) 426 {} 427 FrameNavigateCompleteDWebBrowserEvents2IF428 virtual void FrameNavigateComplete(const BStr& url) 429 {} 430 FrameNewWindowDWebBrowserEvents2IF431 virtual void FrameNewWindow(const BStr&url, long flags, const BStr& targetFrameName, VARIANT* postData, const BStr& headers, VARIANT_BOOL& processed) 432 {} 433 BeforeNavigate2DWebBrowserEvents2IF434 virtual void BeforeNavigate2(IDispatch* pDisp, const Variant& url, const Variant& flags, 435 const Variant& targetFrameName, const Variant& postData, 436 const Variant& headers, VARIANT_BOOL& cancel) 437 {} 438 NavigateComplete2DWebBrowserEvents2IF439 virtual void NavigateComplete2(IDispatch* pDisp, const Variant& url) 440 {} 441 OnQuitDWebBrowserEvents2IF442 virtual void OnQuit() 443 {} 444 OnVisibleDWebBrowserEvents2IF445 virtual void OnVisible(bool Visible) 446 {} 447 OnToolbarDWebBrowserEvents2IF448 virtual void OnToolbar(bool Visible) 449 {} 450 OnMenubarDWebBrowserEvents2IF451 virtual void OnMenubar(bool Visible) 452 {} 453 OnStatusbarDWebBrowserEvents2IF454 virtual void OnStatusbar(bool Visible) 455 {} 456 OnFullscreenDWebBrowserEvents2IF457 virtual void OnFullscreen(bool Visible) 458 {} 459 DocumentCompleteDWebBrowserEvents2IF460 virtual void DocumentComplete() 461 {} 462 OnTheatermodeDWebBrowserEvents2IF463 virtual void OnTheatermode(bool Visible) 464 {} 465 OnAddressbarDWebBrowserEvents2IF466 virtual void OnAddressbar(bool Visible) 467 {} 468 WindowSetResizableDWebBrowserEvents2IF469 virtual void WindowSetResizable(bool Visible) 470 {} 471 WindowClosingDWebBrowserEvents2IF472 virtual void WindowClosing(VARIANT_BOOL IsChildWindow, VARIANT_BOOL& cancel) 473 {} 474 WindowSetLeftDWebBrowserEvents2IF475 virtual void WindowSetLeft(long Left) 476 {} 477 WindowSetTopDWebBrowserEvents2IF478 virtual void WindowSetTop(long Top) 479 {} 480 WindowSetWidthDWebBrowserEvents2IF481 virtual void WindowSetWidth(long Width) 482 {} 483 WindowSetHeightDWebBrowserEvents2IF484 virtual void WindowSetHeight(long Height) 485 {} 486 ClientToHostWindowDWebBrowserEvents2IF487 virtual void ClientToHostWindow(long& CX, long& CY) 488 {} 489 SetSecureLockIconDWebBrowserEvents2IF490 virtual void SetSecureLockIcon(long SecureLockIcon) 491 {} 492 FileDownloadDWebBrowserEvents2IF493 virtual void FileDownload(Variant& cancel) 494 {} 495 NavigateErrorDWebBrowserEvents2IF496 virtual void NavigateError(IDispatch* pDisp, const Variant& url, const Variant& Frame, const Variant& StatusCode, VARIANT_BOOL& cancel) 497 {} 498 PrivacyImpactedStateChangeDWebBrowserEvents2IF499 virtual void PrivacyImpactedStateChange(bool bImpacted) 500 {} 501 }; 502 503 504 // The web browser control has to be initialized completely before being able, 505 // to display a page, that does not access internet. 506 struct ANSUNC BrowserNavigator 507 { 508 BrowserNavigator(); 509 510 void attach(IWebBrowser* browser); 511 void goto_url(LPCTSTR url); 512 void set_html_page(const String& html_txt); 513 void navigated(LPCTSTR url); 514 get_browserBrowserNavigator515 IWebBrowser* get_browser() {return _browser.get();} 516 517 protected: 518 SIfacePtr<IWebBrowser> _browser; 519 String _new_url; 520 String _new_html_txt; 521 bool _browser_initialized; 522 }; 523 524 525 // MinGW defines a wrong FixedDWebBrowserEvents2 interface with virtual functions for DISPID calls, so we use our own, corrected version: 526 interface FixedDWebBrowserEvents2 : public IDispatch 527 { 528 #ifdef __GNUC__ ~FixedDWebBrowserEvents2()529 virtual ~FixedDWebBrowserEvents2() {} 530 #endif 531 }; 532 533 struct ANSUNC DWebBrowserEvents2Impl 534 : public IComSrvBase<FixedDWebBrowserEvents2, DWebBrowserEvents2Impl>, public SimpleComObject, 535 public DWebBrowserEvents2IF 536 { 537 typedef IComSrvBase<FixedDWebBrowserEvents2, DWebBrowserEvents2Impl> super; 538 539 540 DWebBrowserEvents2IF* _callback; 541 542 DWebBrowserEvents2ImplDWebBrowserEvents2Impl543 DWebBrowserEvents2Impl(BrowserNavigator& navigator) 544 : super(DIID_DWebBrowserEvents2), 545 _navigator(navigator) 546 { 547 _callback = this; 548 } 549 550 551 /* // IUnknown 552 STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv) 553 { 554 *ppv = NULL; 555 556 if (SUCCEEDED(super::QueryInterface(riid, ppv))) 557 return S_OK; 558 559 return E_NOINTERFACE; 560 } */ 561 562 563 // IDispatch STDMETHODDWebBrowserEvents2Impl564 STDMETHOD(GetTypeInfoCount)(UINT* pctinfo) 565 {return E_NOTIMPL;} 566 STDMETHODDWebBrowserEvents2Impl567 STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) 568 {return E_NOTIMPL;} 569 STDMETHODDWebBrowserEvents2Impl570 STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) 571 {return E_NOTIMPL;} 572 STDMETHODDWebBrowserEvents2Impl573 STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, 574 DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr) 575 { 576 switch(dispIdMember) { 577 case DISPID_STATUSTEXTCHANGE: 578 _callback->StatusTextChange((BStr)Variant(pDispParams->rgvarg[0])); 579 break; 580 581 case DISPID_COMMANDSTATECHANGE: 582 _callback->CommandStateChange(Variant(pDispParams->rgvarg[1]), Variant(pDispParams->rgvarg[0])); 583 break; 584 585 case DISPID_DOWNLOADBEGIN: 586 _callback->DownloadBegin(); 587 break; 588 589 case DISPID_PROGRESSCHANGE: // sent when download progress is updated 590 _callback->ProgressChange(Variant(pDispParams->rgvarg[1]), Variant(pDispParams->rgvarg[0])); 591 break; 592 593 case DISPID_WINDOWMOVE: // sent when main window has been moved 594 _callback->WindowMove(); 595 break; 596 597 case DISPID_WINDOWRESIZE: // sent when main window has been sized 598 _callback->WindowResize(); 599 break; 600 601 case DISPID_WINDOWACTIVATE: // sent when main window has been activated 602 _callback->WindowActivate(); 603 break; 604 605 case DISPID_PROPERTYCHANGE: // sent when the PutProperty method is called 606 _callback->PropertyChange((BStr)Variant(pDispParams->rgvarg[0])); 607 break; 608 609 case DISPID_TITLECHANGE: // sent when the document title changes 610 _callback->TitleChange((BStr)Variant(pDispParams->rgvarg[0])); 611 break; 612 613 case DISPID_TITLEICONCHANGE: // sent when the top level window icon may have changed. 614 _callback->TitleIconChange((BStr)Variant(pDispParams->rgvarg[0])); 615 break; 616 617 618 // anything below here is not present in DWebBrowserEvents, only in DWebBrowserEvents2: -> 619 620 case DISPID_FRAMEBEFORENAVIGATE: 621 if (pDispParams->cArgs != 6) 622 return E_INVALIDARG; 623 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 624 return E_INVALIDARG; 625 _callback->FrameBeforeNavigate( 626 (BStr)Variant(&pDispParams->rgvarg[5]), Variant(&pDispParams->rgvarg[4]), 627 (BStr)Variant(&pDispParams->rgvarg[3]), &pDispParams->rgvarg[2], 628 (BStr)Variant(&pDispParams->rgvarg[1]), *V_BOOLREF(&pDispParams->rgvarg[0])); 629 break; 630 631 case DISPID_FRAMENAVIGATECOMPLETE: 632 if (pDispParams->cArgs != 1) 633 return E_INVALIDARG; 634 _callback->FrameNavigateComplete((BStr)Variant(pDispParams->rgvarg[0])); 635 break; 636 637 case DISPID_FRAMENEWWINDOW: 638 if (pDispParams->cArgs != 6) 639 return E_INVALIDARG; 640 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 641 return E_INVALIDARG; 642 _callback->FrameNewWindow((BStr)Variant(&pDispParams->rgvarg[5]), Variant(&pDispParams->rgvarg[4]), 643 (BStr)Variant(&pDispParams->rgvarg[3]), &pDispParams->rgvarg[2], 644 (BStr)Variant(&pDispParams->rgvarg[1]), *V_BOOLREF(&pDispParams->rgvarg[0])); 645 break; 646 647 case DISPID_BEFORENAVIGATE2: // hyperlink clicked on 648 if (pDispParams->cArgs != 7) 649 return E_INVALIDARG; 650 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 651 return E_INVALIDARG; 652 _callback->BeforeNavigate2(Variant(pDispParams->rgvarg[6]), 653 pDispParams->rgvarg[5], &pDispParams->rgvarg[4], 654 pDispParams->rgvarg[3], &pDispParams->rgvarg[2], 655 pDispParams->rgvarg[1], *V_BOOLREF(&pDispParams->rgvarg[0])); 656 break; 657 658 case DISPID_NEWWINDOW2: // sent when a new window should be created 659 if (pDispParams->cArgs != 2) 660 return E_INVALIDARG; 661 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 662 return E_INVALIDARG; 663 if (V_VT(&pDispParams->rgvarg[1]) != (VT_DISPATCH|VT_BYREF)) 664 return E_INVALIDARG; 665 _callback->NewWindow2(V_DISPATCHREF(&pDispParams->rgvarg[1]), *V_BOOLREF(&pDispParams->rgvarg[0])); 666 break; 667 668 case DISPID_NAVIGATECOMPLETE2:// UIActivate new document 669 if (pDispParams->cArgs != 2) 670 return E_INVALIDARG; 671 672 // notify the navigator 673 NavigateComplete2(Variant(pDispParams->rgvarg[1]), Variant(pDispParams->rgvarg[0])); 674 675 _callback->NavigateComplete2(Variant(pDispParams->rgvarg[1]), Variant(pDispParams->rgvarg[0])); 676 break; 677 678 case DISPID_ONQUIT: 679 _callback->OnQuit(); 680 break; 681 682 case DISPID_ONVISIBLE: // sent when the window goes visible/hidden 683 if (pDispParams->cArgs != 1) 684 return E_INVALIDARG; 685 _callback->OnVisible(Variant(pDispParams->rgvarg[0])); 686 break; 687 688 case DISPID_ONTOOLBAR: // sent when the toolbar should be shown/hidden 689 if (pDispParams->cArgs != 1) 690 return E_INVALIDARG; 691 _callback->OnToolbar(Variant(pDispParams->rgvarg[0])); 692 break; 693 694 case DISPID_ONMENUBAR: // sent when the menubar should be shown/hidden 695 if (pDispParams->cArgs != 1) 696 return E_INVALIDARG; 697 _callback->OnMenubar(Variant(pDispParams->rgvarg[0])); 698 break; 699 700 case DISPID_ONSTATUSBAR: // sent when the statusbar should be shown/hidden 701 if (pDispParams->cArgs != 1) 702 return E_INVALIDARG; 703 _callback->OnStatusbar(Variant(pDispParams->rgvarg[0])); 704 break; 705 706 case DISPID_ONFULLSCREEN: // sent when kiosk mode should be on/off 707 if (pDispParams->cArgs != 1) 708 return E_INVALIDARG; 709 _callback->OnFullscreen(Variant(pDispParams->rgvarg[0])); 710 break; 711 712 case DISPID_DOCUMENTCOMPLETE:// new document goes ReadyState_Complete 713 _callback->DocumentComplete(); 714 break; 715 716 case DISPID_DOWNLOADCOMPLETE: 717 _callback->DownloadComplete(); 718 break; 719 720 case DISPID_ONTHEATERMODE: // sent when theater mode should be on/off 721 if (pDispParams->cArgs != 1) 722 return E_INVALIDARG; 723 _callback->OnTheatermode(Variant(pDispParams->rgvarg[0])); 724 break; 725 726 case DISPID_ONADDRESSBAR: // sent when the address bar should be shown/hidden 727 if (pDispParams->cArgs != 1) 728 return E_INVALIDARG; 729 _callback->OnAddressbar(Variant(pDispParams->rgvarg[0])); 730 break; 731 732 case DISPID_WINDOWSETRESIZABLE:// sent to set the style of the host window frame 733 if (pDispParams->cArgs != 1) 734 return E_INVALIDARG; 735 _callback->WindowSetResizable(Variant(pDispParams->rgvarg[0])); 736 break; 737 738 case DISPID_WINDOWCLOSING: // sent before script window.close closes the window 739 if (pDispParams->cArgs != 2) 740 return E_INVALIDARG; 741 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 742 return E_INVALIDARG; 743 _callback->WindowClosing(Variant(pDispParams->rgvarg[1]), *V_BOOLREF(&pDispParams->rgvarg[0])); 744 break; 745 746 case DISPID_WINDOWSETLEFT: // sent when the put_left method is called on the WebOC 747 if (pDispParams->cArgs != 1) 748 return E_INVALIDARG; 749 _callback->WindowSetLeft(Variant(pDispParams->rgvarg[0])); 750 break; 751 752 case DISPID_WINDOWSETTOP: // sent when the put_top method is called on the WebOC 753 if (pDispParams->cArgs != 1) 754 return E_INVALIDARG; 755 _callback->WindowSetTop(Variant(pDispParams->rgvarg[0])); 756 break; 757 758 case DISPID_WINDOWSETWIDTH: // sent when the put_width method is called on the WebOC 759 if (pDispParams->cArgs != 1) 760 return E_INVALIDARG; 761 _callback->WindowSetWidth(Variant(pDispParams->rgvarg[0])); 762 break; 763 764 case DISPID_WINDOWSETHEIGHT: // sent when the put_height method is called on the WebOC 765 if (pDispParams->cArgs != 1) 766 return E_INVALIDARG; 767 _callback->WindowSetHeight(Variant(pDispParams->rgvarg[0])); 768 break; 769 770 case DISPID_CLIENTTOHOSTWINDOW:// sent during window.open to request conversion of dimensions 771 { 772 long cx, cy; 773 if (pDispParams->cArgs != 2) 774 return E_INVALIDARG; 775 if (V_VT(&pDispParams->rgvarg[0]) != (VT_I4|VT_BYREF)) 776 return E_INVALIDARG; 777 if (V_VT(&pDispParams->rgvarg[1]) != (VT_I4|VT_BYREF)) 778 return E_INVALIDARG; 779 cx = *V_I4REF(&pDispParams->rgvarg[1]); 780 cy = *V_I4REF(&pDispParams->rgvarg[0]); 781 _callback->ClientToHostWindow(cx, cy); 782 break; 783 } 784 785 case DISPID_SETSECURELOCKICON:// sent to suggest the appropriate security icon to show 786 if (pDispParams->cArgs != 1) 787 return E_INVALIDARG; 788 _callback->SetSecureLockIcon(Variant(pDispParams->rgvarg[0])); 789 break; 790 791 case DISPID_FILEDOWNLOAD: { // Fired to indicate the File Download dialog is opening 792 if (pDispParams->cArgs != 1) //@@ every time 2 ?! 793 return E_INVALIDARG; 794 Variant var(pDispParams->rgvarg[0]); 795 _callback->FileDownload(var);} 796 break; 797 798 case DISPID_NAVIGATEERROR: // Fired to indicate the a binding error has occured 799 if (pDispParams->cArgs != 5) 800 return E_INVALIDARG; 801 if (V_VT(&pDispParams->rgvarg[0]) != (VT_BOOL|VT_BYREF)) 802 return E_INVALIDARG; 803 _callback->NavigateError(Variant(pDispParams->rgvarg[4]), Variant(pDispParams->rgvarg[3]), 804 Variant(pDispParams->rgvarg[2]), Variant(pDispParams->rgvarg[1]), 805 *V_BOOLREF(&pDispParams->rgvarg[0])); 806 break; 807 808 case DISPID_PRIVACYIMPACTEDSTATECHANGE:// Fired when the user's browsing experience is impacted 809 if (pDispParams->cArgs != 1) 810 return E_INVALIDARG; 811 _callback->PrivacyImpactedStateChange(Variant(pDispParams->rgvarg[0])); 812 break; 813 814 default: 815 return NOERROR; 816 } 817 818 return S_OK; 819 } 820 821 protected: 822 BrowserNavigator& _navigator; 823 NavigateComplete2DWebBrowserEvents2Impl824 void NavigateComplete2(IDispatch* pDisp, const Variant& url) 825 { 826 String adr = (BStr)url; 827 828 _navigator.navigated(adr); 829 } 830 }; 831 832 833 /// encapsulation of Web control in MDI child windows 834 struct WebChildWindow : public IPCtrlWindow<ChildWindow, SIfacePtr<IWebBrowser2> >, 835 public DWebBrowserEvents2Impl 836 { 837 typedef IPCtrlWindow<ChildWindow, SIfacePtr<IWebBrowser2> > super; 838 typedef DWebBrowserEvents2Impl web_super; 839 840 WebChildWindow(HWND hwnd, const WebChildWndInfo& info); 841 createWebChildWindow842 static WebChildWindow* create(const FileChildWndInfo& info) 843 { 844 ChildWindow* child = ChildWindow::create(info, info._pos.rcNormalPosition, 845 WINDOW_CREATOR_INFO(WebChildWindow,WebChildWndInfo), CLASSNAME_CHILDWND, NULL, info._pos.showCmd==SW_SHOWMAXIMIZED? WS_MAXIMIZE: 0); 846 847 return static_cast<WebChildWindow*>(child); 848 } 849 850 851 // DWebBrowserEvents2Impl overides -> 852 BeforeNavigate2WebChildWindow853 void BeforeNavigate2(IDispatch* pDisp, const Variant& url, const Variant& flags, 854 const Variant& targetFrameName, const Variant& postData, 855 const Variant& headers, VARIANT_BOOL& cancel) 856 { 857 //String adr = (BStr)url; 858 } 859 NavigateComplete2WebChildWindow860 void NavigateComplete2(IDispatch* pDisp, const Variant& url) 861 { 862 web_super::NavigateComplete2(pDisp, url); 863 864 set_url(String(BStr(url))); 865 } 866 StatusTextChangeWebChildWindow867 void StatusTextChange(const BStr& text) 868 { 869 _statusText = text; 870 SendMessage(_hwndFrame, PM_SETSTATUSTEXT, 0, (LPARAM)_statusText.c_str()); 871 } 872 ProgressChangeWebChildWindow873 void ProgressChange(long Progress, long ProgressMax) 874 { 875 } 876 WindowMoveWebChildWindow877 void WindowMove() 878 { 879 } 880 WindowResizeWebChildWindow881 void WindowResize() 882 { 883 } 884 WindowActivateWebChildWindow885 void WindowActivate() 886 { 887 } 888 PropertyChangeWebChildWindow889 void PropertyChange(const BStr& Property) 890 { 891 Variant value; 892 _control->GetProperty(Property, &value); 893 } 894 CommandStateChangeWebChildWindow895 void CommandStateChange(long command/*CSC_NAVIGATEFORWARD, CSC_NAVIGATEBACK*/, bool enable) 896 { 897 } 898 DownloadBeginWebChildWindow899 void DownloadBegin() 900 { 901 } 902 NewWindow2WebChildWindow903 void NewWindow2(IDispatch** ppDisp, VARIANT_BOOL& cancel) 904 { 905 //*ppDisp = ; 906 //cancel = TRUE; 907 } 908 TitleChangeWebChildWindow909 void TitleChange(const BStr& text) 910 { 911 SetWindowText(_hwnd, String(text)); 912 } 913 TitleIconChangeWebChildWindow914 void TitleIconChange(const BStr& text) 915 { 916 } 917 FrameBeforeNavigateWebChildWindow918 void FrameBeforeNavigate(const BStr& url, long flags, const BStr& targetFrameName, VARIANT* postData, const BStr& headers, VARIANT_BOOL& cancel) 919 { 920 } 921 FrameNavigateCompleteWebChildWindow922 void FrameNavigateComplete(const BStr& url) 923 { 924 } 925 FrameNewWindowWebChildWindow926 void FrameNewWindow(const BStr& url, long flags, const BStr& targetFrameName, VARIANT* postData, const BStr& headers, VARIANT_BOOL& processed) 927 { 928 } 929 OnQuitWebChildWindow930 void OnQuit() 931 { 932 } 933 OnVisibleWebChildWindow934 void OnVisible(bool Visible) 935 { 936 } 937 OnToolbarWebChildWindow938 void OnToolbar(bool Visible) 939 { 940 } 941 OnMenubarWebChildWindow942 void OnMenubar(bool Visible) 943 { 944 } 945 OnStatusbarWebChildWindow946 void OnStatusbar(bool Visible) 947 { 948 } 949 OnFullscreenWebChildWindow950 void OnFullscreen(bool Visible) 951 { 952 } 953 DocumentCompleteWebChildWindow954 void DocumentComplete() 955 { 956 } 957 OnTheatermodeWebChildWindow958 void OnTheatermode(bool Visible) 959 { 960 } 961 OnAddressbarWebChildWindow962 void OnAddressbar(bool Visible) 963 { 964 } 965 WindowSetResizableWebChildWindow966 void WindowSetResizable(bool Visible) 967 { 968 } 969 WindowClosingWebChildWindow970 void WindowClosing(VARIANT_BOOL IsChildWindow, VARIANT_BOOL& cancel) 971 { 972 } 973 WindowSetLeftWebChildWindow974 void WindowSetLeft(long Left) 975 { 976 } 977 WindowSetTopWebChildWindow978 void WindowSetTop(long Top) 979 { 980 } 981 WindowSetWidthWebChildWindow982 void WindowSetWidth(long Width) 983 { 984 } 985 WindowSetHeightWebChildWindow986 void WindowSetHeight(long Height) 987 { 988 } 989 ClientToHostWindowWebChildWindow990 void ClientToHostWindow(long& CX, long& CY) 991 { 992 } 993 SetSecureLockIconWebChildWindow994 void SetSecureLockIcon(long SecureLockIcon) 995 { 996 } 997 FileDownloadWebChildWindow998 void FileDownload(Variant& cancel) 999 { 1000 } 1001 NavigateErrorWebChildWindow1002 void NavigateError(IDispatch* pDisp, const Variant& url, const Variant& Frame, const Variant& StatusCode, VARIANT_BOOL& cancel) 1003 { 1004 } 1005 PrivacyImpactedStateChangeWebChildWindow1006 void PrivacyImpactedStateChange(bool bImpacted) 1007 { 1008 } 1009 1010 1011 protected: 1012 BrowserNavigator _navigator; 1013 auto_ptr<EventConnector> _connector; 1014 1015 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); 1016 1017 virtual String jump_to_int(LPCTSTR url); 1018 }; 1019