Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1381 lines
42 KiB

  1. //**********************************************************************
  2. // File name: SITE.CPP
  3. //
  4. // Implementation file for COleSite
  5. //
  6. // Functions:
  7. //
  8. // See SITE.H for class definition
  9. //
  10. // Copyright (c) 1992 - 1996 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. extern BOOL CopyBitmapRectToFile
  14. (
  15. HBITMAP hbm,
  16. LPRECT lpRect,
  17. LPTSTR lpszFileName
  18. );
  19. #include "exdispid.h"
  20. #define SETDefFormatEtc(fe, cf, med) \
  21. {\
  22. (fe).cfFormat=cf;\
  23. (fe).dwAspect=DVASPECT_CONTENT;\
  24. (fe).ptd=NULL;\
  25. (fe).tymed=med;\
  26. (fe).lindex=-1;\
  27. };
  28. #define MAX_DISP_NAME 50
  29. #define DISPID_RunIcwTutorApp 12345
  30. typedef struct dispatchList_tag
  31. {
  32. WCHAR szName[MAX_DISP_NAME];
  33. int cName;
  34. DWORD dwDispID;
  35. } DISPATCHLIST;
  36. DISPATCHLIST ExternalInterface[] =
  37. {
  38. {L"RunIcwTutorApplication", 22, DISPID_RunIcwTutorApp }
  39. };
  40. const TCHAR cszOLSNewText[] = TEXT("g_spnOlsNewText");
  41. const TCHAR cszOLSOldText[] = TEXT("g_spnOlsOldText");
  42. //**********************************************************************
  43. //
  44. // OleFree
  45. //
  46. // Purpose:
  47. //
  48. // free memory using the currently active IMalloc* allocator
  49. //
  50. // Parameters:
  51. //
  52. // LPVOID pmem - pointer to memory allocated using IMalloc
  53. //
  54. // Return Value:
  55. //
  56. // None
  57. //
  58. // Comments:
  59. //
  60. //********************************************************************
  61. void OleFree(LPVOID pmem)
  62. {
  63. LPMALLOC pmalloc;
  64. if (pmem == NULL)
  65. return;
  66. if (FAILED(CoGetMalloc(MEMCTX_TASK, &pmalloc)))
  67. return;
  68. pmalloc->Free(pmem);
  69. pmalloc->Release();
  70. }
  71. //**********************************************************************
  72. //
  73. // COleSite::COleSite
  74. //
  75. // Purpose:
  76. //
  77. // Constructor for COleSite
  78. //
  79. // Parameters:
  80. //
  81. //
  82. // Return Value:
  83. //
  84. // None
  85. //
  86. // Function Calls:
  87. // Function Location
  88. //
  89. // Comments:
  90. //
  91. //********************************************************************
  92. #pragma warning(disable : 4355) // turn off this warning. This warning
  93. // tells us that we are passing this in
  94. // an initializer, before "this" is through
  95. // initializing. This is ok, because
  96. // we just store the ptr in the other
  97. // constructors
  98. COleSite::COleSite (void) : m_OleClientSite(this) ,
  99. m_OleInPlaceSite(this),
  100. m_OleInPlaceFrame(this)
  101. #pragma warning (default : 4355) // Turn the warning back on
  102. {
  103. TCHAR szTempPath[MAX_PATH];
  104. // Init member vars
  105. m_lpInPlaceObject = NULL;
  106. m_lpOleObject = NULL;
  107. m_hwndIPObj = NULL;
  108. m_hWnd = NULL;
  109. m_fInPlaceActive = FALSE;
  110. m_dwHtmPageType = 0;
  111. m_hbmBkGrnd = NULL;
  112. lstrcpyn(m_szForeGrndColor, HTML_DEFAULT_COLOR, MAX_COLOR_NAME);
  113. lstrcpyn(m_szBkGrndColor, HTML_DEFAULT_BGCOLOR, MAX_COLOR_NAME);
  114. m_bUseBkGndBitmap = FALSE;
  115. m_dwDrawAspect = DVASPECT_CONTENT; // clear the reference count
  116. m_cRef = 0; // Init the ref count
  117. // Create a temp file for storing the background bitmap
  118. if (GetTempPath(sizeof(szTempPath)/sizeof(TCHAR), szTempPath))
  119. {
  120. GetTempFileName(szTempPath, TEXT("ICW"), 0, m_szBkGndBitmapFile);
  121. }
  122. // Create a storage file for creating/embedding an OLE oject into this site
  123. StgCreateDocfile (NULL,
  124. STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE,
  125. 0,
  126. &m_lpStorage);
  127. }
  128. //**********************************************************************
  129. //
  130. // COleSite::~COleSite
  131. //
  132. // Purpose:
  133. //
  134. // Destructor for COleSite
  135. //
  136. // Parameters:
  137. //
  138. // None
  139. //
  140. // Return Value:
  141. //
  142. // None
  143. //
  144. // Function Calls:
  145. // Function Location
  146. //
  147. // IOleObject::Release Object
  148. // IStorage::Release OLE API
  149. //
  150. // Comments:
  151. //
  152. //********************************************************************
  153. COleSite::~COleSite ()
  154. {
  155. TraceMsg(TF_GENERAL, "In COleSite's Destructor \r\n");
  156. ASSERT( m_cRef == 0 );
  157. if (m_lpOleObject)
  158. m_lpOleObject->Release();
  159. if (m_lpWebBrowser)
  160. m_lpWebBrowser->Release();
  161. if (m_lpStorage)
  162. {
  163. m_lpStorage->Release();
  164. m_lpStorage = NULL;
  165. }
  166. DeleteFile(m_szBkGndBitmapFile);
  167. }
  168. //**********************************************************************
  169. //
  170. // COleSite::CloseOleObject
  171. //
  172. // Purpose:
  173. //
  174. // Call IOleObject::Close on the object of the COleSite
  175. //
  176. // Parameters:
  177. //
  178. // None
  179. //
  180. // Return Value:
  181. //
  182. // None
  183. //
  184. // Function Calls:
  185. // Function Location
  186. //
  187. // IOleObject::QueryInterface Object
  188. // IOleObject::Close Object
  189. // IOleInPlaceObject::UIDeactivate Object
  190. // IOleInPlaceObject::InPlaceDeactivate Object
  191. // IOleInPlaceObject::Release Object
  192. //
  193. // Comments:
  194. //
  195. //********************************************************************
  196. void COleSite::CloseOleObject (void)
  197. {
  198. TraceMsg(TF_GENERAL, "In COleSite::CloseOleObject \r\n");
  199. if (m_lpOleObject)
  200. {
  201. if (m_fInPlaceActive)
  202. {
  203. LPOLEINPLACEOBJECT lpObject;
  204. LPVIEWOBJECT lpViewObject = NULL;
  205. m_lpOleObject->QueryInterface(IID_IOleInPlaceObject, (LPVOID FAR *)&lpObject);
  206. lpObject->UIDeactivate();
  207. // don't need to worry about inside-out because the object
  208. // is going away.
  209. lpObject->InPlaceDeactivate();
  210. lpObject->Release();
  211. }
  212. m_lpOleObject->Close(OLECLOSE_NOSAVE);
  213. m_hWnd = NULL;
  214. }
  215. }
  216. //**********************************************************************
  217. //
  218. // COleSite::UnloadOleObject
  219. //
  220. // Purpose:
  221. //
  222. // Close and release all pointers to the object of the COleSite
  223. //
  224. // Parameters:
  225. //
  226. // None
  227. //
  228. // Return Value:
  229. //
  230. // None
  231. //
  232. // Function Calls:
  233. // Function Location
  234. //
  235. // COleSite::CloseOleObject SITE.CPP
  236. // IOleObject::QueryInterface Object
  237. // IViewObject::SetAdvise Object
  238. // IViewObject::Release Object
  239. // IStorage::Release OLE API
  240. //
  241. // Comments:
  242. //
  243. //********************************************************************
  244. void COleSite::UnloadOleObject (void)
  245. {
  246. TraceMsg(TF_GENERAL, "In COleSite::UnloadOleObject \r\n");
  247. if (m_lpOleObject)
  248. {
  249. LPVIEWOBJECT lpViewObject;
  250. CloseOleObject(); // ensure object is closed; NOP if already closed
  251. m_lpOleObject->QueryInterface(IID_IViewObject, (LPVOID FAR *)&lpViewObject);
  252. if (lpViewObject)
  253. {
  254. // Remove the view advise
  255. lpViewObject->SetAdvise(m_dwDrawAspect, 0, NULL);
  256. lpViewObject->Release();
  257. }
  258. m_lpOleObject->Release();
  259. m_lpOleObject = NULL;
  260. }
  261. }
  262. //**********************************************************************
  263. //
  264. // COleSite::QueryInterface
  265. //
  266. // Purpose:
  267. //
  268. // Used for interface negotiation of the container Site.
  269. //
  270. // Parameters:
  271. //
  272. // REFIID riid - A reference to the interface that is
  273. // being queried.
  274. //
  275. // LPVOID FAR* ppvObj - An out parameter to return a pointer to
  276. // the interface.
  277. //
  278. // Return Value:
  279. //
  280. // S_OK - The interface is supported.
  281. // S_FALSE - The interface is not supported
  282. //
  283. // Function Calls:
  284. // Function Location
  285. //
  286. // IsEqualIID OLE API
  287. // ResultFromScode OLE API
  288. // COleSite::AddRef OBJ.CPP
  289. // COleClientSite::AddRef IOCS.CPP
  290. // CAdviseSink::AddRef IAS.CPP
  291. //
  292. // Comments:
  293. //
  294. //
  295. //********************************************************************
  296. STDMETHODIMP COleSite::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  297. {
  298. TraceMsg(TF_GENERAL, "In COleSite::QueryInterface\r\n");
  299. *ppvObj = NULL; // must set out pointer parameters to NULL
  300. if ( riid == IID_IDocHostUIHandler)
  301. {
  302. AddRef();
  303. *ppvObj = this;
  304. return ResultFromScode(S_OK);
  305. }
  306. if ( riid == IID_IUnknown)
  307. {
  308. AddRef();
  309. *ppvObj = this;
  310. return ResultFromScode(S_OK);
  311. }
  312. if ( riid == IID_IOleClientSite)
  313. {
  314. m_OleClientSite.AddRef();
  315. *ppvObj = &m_OleClientSite;
  316. return ResultFromScode(S_OK);
  317. }
  318. if ( riid == IID_IOleInPlaceSite)
  319. {
  320. m_OleInPlaceSite.AddRef();
  321. *ppvObj = &m_OleInPlaceSite;
  322. return ResultFromScode(S_OK);
  323. }
  324. if( (riid == DIID_DWebBrowserEvents) ||
  325. (riid == IID_IDispatch))
  326. {
  327. AddRef();
  328. *ppvObj = (LPVOID)(IUnknown*)(DWebBrowserEvents*)this;
  329. return ResultFromScode(S_OK);
  330. }
  331. // Not a supported interface
  332. return ResultFromScode(E_NOINTERFACE);
  333. }
  334. //**********************************************************************
  335. //
  336. // COleSite::AddRef
  337. //
  338. // Purpose:
  339. //
  340. // Increments the reference count of the container Site.
  341. //
  342. // Parameters:
  343. //
  344. // None
  345. //
  346. // Return Value:
  347. //
  348. // ULONG - The new reference count of the site.
  349. //
  350. // Function Calls:
  351. // Function Location
  352. //
  353. //
  354. // Comments:
  355. //
  356. //********************************************************************
  357. STDMETHODIMP_(ULONG) COleSite::AddRef()
  358. {
  359. TraceMsg(TF_GENERAL, "In COleSite::AddRef\r\n");
  360. return ++m_cRef;
  361. }
  362. //**********************************************************************
  363. //
  364. // COleSite::Release
  365. //
  366. // Purpose:
  367. //
  368. // Decrements the reference count of the container Site
  369. //
  370. // Parameters:
  371. //
  372. // None
  373. //
  374. // Return Value:
  375. //
  376. // ULONG - The new reference count of the Site.
  377. //
  378. // Function Calls:
  379. // Function Location
  380. //
  381. //
  382. // Comments:
  383. //
  384. //********************************************************************
  385. STDMETHODIMP_(ULONG) COleSite::Release()
  386. {
  387. TraceMsg(TF_GENERAL, "In COleSite::Release\r\n");
  388. return --m_cRef;
  389. }
  390. //**********************************************************************
  391. //
  392. // COleSite::CreateBrowserObject
  393. //
  394. // Purpose:
  395. //
  396. // Used to Create a new WebBrowser object (can't be done in the
  397. // constructor).
  398. //
  399. // Parameters:
  400. //
  401. // Return Value:
  402. //
  403. // None
  404. //
  405. // Function Calls:
  406. //
  407. // Comments:
  408. //
  409. //********************************************************************
  410. void COleSite::CreateBrowserObject()
  411. {
  412. HRESULT hr;
  413. SETDefFormatEtc(m_fe, 0, TYMED_NULL);
  414. hr = OleCreate(CLSID_WebBrowser,
  415. IID_IWebBrowser2,
  416. OLERENDER_DRAW,
  417. &m_fe,
  418. &m_OleClientSite,
  419. m_lpStorage,
  420. (LPVOID FAR *)&m_lpWebBrowser);
  421. if (SUCCEEDED(hr))
  422. InitBrowserObject();
  423. IUnknown *pOleSite;
  424. // Get an IUnknow pointer to the site, so I can attach an event sink
  425. QueryInterface(IID_IUnknown, (LPVOID *)&pOleSite);
  426. // Setup to get WebBrowserEvents
  427. ConnectToConnectionPoint(pOleSite,
  428. DIID_DWebBrowserEvents,
  429. TRUE,
  430. (IUnknown *)m_lpWebBrowser,
  431. &m_dwcpCookie,
  432. NULL);
  433. // We can release this instance now, since we have attached the event sink
  434. pOleSite->Release();
  435. }
  436. void COleSite::DestroyBrowserObject()
  437. {
  438. UnloadOleObject();
  439. if (m_lpWebBrowser)
  440. {
  441. m_lpWebBrowser->Release();
  442. m_lpWebBrowser = NULL;
  443. }
  444. }
  445. //**********************************************************************
  446. //
  447. // COleSite::InitBrowserObject
  448. //
  449. // Purpose:
  450. //
  451. // Used to initialize a newly create object (can't be done in the
  452. // constructor).
  453. //
  454. // Parameters:
  455. //
  456. // Return Value:
  457. //
  458. // None
  459. //
  460. // Function Calls:
  461. // Function Location
  462. //
  463. // IOleObject::SetHostNames Object
  464. // IOleObject::QueryInterface Object
  465. // IViewObject2::GetExtent Object
  466. // IOleObject::DoVerb Object
  467. // IViewObject::SetAdvise Object
  468. // IViewObject::Release Object
  469. // GetClientRect Windows API
  470. // OleSetContainedObject OLE API
  471. //
  472. // Comments:
  473. //
  474. //********************************************************************
  475. void COleSite::InitBrowserObject()
  476. {
  477. // If we don't have a WebBrowser object to initialize, then bail
  478. if (!m_lpWebBrowser)
  479. return;
  480. // Get An OleObject from the WebBrowser Interface
  481. m_lpWebBrowser->QueryInterface(IID_IOleObject, (LPVOID FAR *)&m_lpOleObject);
  482. // inform object handler/DLL object that it is used in the embedding container's context
  483. OleSetContainedObject(m_lpOleObject, TRUE);
  484. // setup the client setup
  485. m_lpOleObject->SetClientSite(&m_OleClientSite);
  486. }
  487. void COleSite::ConnectBrowserObjectToWindow
  488. (
  489. HWND hWnd,
  490. DWORD dwHtmPageType,
  491. BOOL bUseBkGndBitmap,
  492. HBITMAP hbmBkGrnd,
  493. LPRECT lprcBkGrnd,
  494. LPTSTR lpszclrBkGrnd,
  495. LPTSTR lpszclrForeGrnd
  496. )
  497. {
  498. if (m_hWnd)
  499. {
  500. // Close the OLE Object, which will deactivate it, so we can then reactivate it
  501. // with the new window
  502. CloseOleObject();
  503. }
  504. // Remeber this window handle for later
  505. m_hWnd = hWnd;
  506. m_dwHtmPageType = dwHtmPageType;
  507. m_bUseBkGndBitmap = bUseBkGndBitmap;
  508. m_hbmBkGrnd = hbmBkGrnd;
  509. if (NULL != lpszclrForeGrnd)
  510. lstrcpyn(m_szForeGrndColor, lpszclrForeGrnd, MAX_COLOR_NAME);
  511. if (NULL != lpszclrBkGrnd)
  512. lstrcpyn(m_szBkGrndColor, lpszclrBkGrnd, MAX_COLOR_NAME);
  513. CopyRect(&m_rcBkGrnd, lprcBkGrnd);
  514. InPlaceActivate();
  515. }
  516. void COleSite::ShowHTML()
  517. {
  518. RECT rect;
  519. // we only want to DoVerb(SHOW) if this is an InsertNew object.
  520. // we should NOT DoVerb(SHOW) if the object is created FromFile.
  521. m_lpOleObject->DoVerb( OLEIVERB_SHOW,
  522. NULL,
  523. &m_OleClientSite,
  524. -1,
  525. m_hWnd,
  526. &rect);
  527. }
  528. void COleSite::InPlaceActivate()
  529. {
  530. RECT rect;
  531. m_lpOleObject->DoVerb( OLEIVERB_INPLACEACTIVATE,
  532. NULL,
  533. &m_OleClientSite,
  534. -1,
  535. m_hWnd,
  536. &rect);
  537. }
  538. void COleSite::UIActivate()
  539. {
  540. RECT rect;
  541. m_lpOleObject->DoVerb( OLEIVERB_UIACTIVATE,
  542. NULL,
  543. &m_OleClientSite,
  544. -1,
  545. m_hWnd,
  546. &rect);
  547. }
  548. HRESULT COleSite::TweakHTML( TCHAR* pszFontFace,
  549. TCHAR* pszFontSize,
  550. TCHAR* pszBgColor,
  551. TCHAR* pszForeColor)
  552. {
  553. ASSERT(m_lpWebBrowser);
  554. IWebBrowser2* pwb = m_lpWebBrowser;
  555. HRESULT hr = E_FAIL;
  556. IDispatch* pDisp = NULL;
  557. hr = pwb->get_Document(&pDisp);
  558. // Call might succeed but that dosen't guarantee a valid ptr
  559. if (SUCCEEDED(hr) && pDisp)
  560. {
  561. IHTMLDocument2* pDoc = NULL;
  562. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  563. if (SUCCEEDED(hr) && pDoc)
  564. {
  565. VARIANT var;
  566. VariantInit(&var);
  567. V_VT(&var) = VT_BSTR;
  568. if (m_bUseBkGndBitmap)
  569. {
  570. // Use A background bitmap
  571. SetHTMLBackground(pDoc, m_hbmBkGrnd, &m_rcBkGrnd);
  572. }
  573. else
  574. {
  575. //Setup the background solid color
  576. var.bstrVal = A2W(pszBgColor);
  577. pDoc->put_bgColor(var);
  578. }
  579. //Setup the Foreground (text) color
  580. var.bstrVal = A2W(pszForeColor);
  581. pDoc->put_fgColor(var);
  582. //now we'll try for the font-face/size
  583. if((NULL != pszFontFace))
  584. {
  585. IHTMLElement* pBody;
  586. //Get the <BODY> from the document
  587. hr = pDoc->get_body(&pBody);
  588. if((SUCCEEDED(hr)) && pBody)
  589. {
  590. IHTMLStyle* pStyle = NULL;
  591. //Cool, now the inline style sheet
  592. hr = pBody->get_style(&pStyle);
  593. if (SUCCEEDED(hr) && pStyle)
  594. {
  595. //Great, now the font-family
  596. hr = pStyle->put_fontFamily(A2W(pszFontFace));
  597. if(SUCCEEDED(hr))
  598. {
  599. //Setup for the font-size
  600. var.bstrVal = A2W(pszFontSize);
  601. //And finally the font-size
  602. hr = pStyle->put_fontSize(var);
  603. }
  604. pStyle->Release();
  605. }
  606. pBody->Release();
  607. }
  608. }
  609. pDoc->Release();
  610. }
  611. pDisp->Release();
  612. }
  613. else
  614. hr = E_FAIL;
  615. return hr;
  616. }
  617. HRESULT COleSite::SetHTMLBackground
  618. (
  619. IHTMLDocument2 *pDoc,
  620. HBITMAP hbm,
  621. LPRECT lpRC
  622. )
  623. {
  624. HRESULT hr = E_FAIL;
  625. IDispatch* pDisp = NULL;
  626. TCHAR szBmpURL[MAX_PATH+10];
  627. // Get the portion of the Bitmap we are interested into a file
  628. if (CopyBitmapRectToFile(hbm, lpRC, m_szBkGndBitmapFile))
  629. {
  630. wsprintf (szBmpURL, TEXT("file://%s"), m_szBkGndBitmapFile);
  631. IHTMLElement* pBody;
  632. //Get the <BODY> from the document
  633. hr = pDoc->get_body(&pBody);
  634. if((SUCCEEDED(hr)) && pBody)
  635. {
  636. IHTMLBodyElement* pBodyElt = NULL;
  637. pBody->QueryInterface(IID_IHTMLBodyElement, (void**)&pBodyElt);
  638. // Set the Background bitmap
  639. hr = pBodyElt->put_background(A2W(szBmpURL));
  640. pBodyElt->Release();
  641. }
  642. }
  643. return (hr);
  644. }
  645. //**********************************************************************
  646. //
  647. // COleSite::GetObjRect
  648. //
  649. // Purpose:
  650. //
  651. // Retrieves the rect of the object in pixels
  652. //
  653. // Parameters:
  654. //
  655. // LPRECT lpRect - Rect structure filled with object's rect in pixels
  656. //
  657. //********************************************************************
  658. void COleSite::GetObjRect(LPRECT lpRect)
  659. {
  660. GetClientRect(m_hWnd, lpRect);
  661. }
  662. // * CConWizSite::GetHostInfo
  663. // *
  664. // * Purpose: Called at initialisation of every instance of Trident.
  665. // *
  666. HRESULT COleSite::GetHostInfo( DOCHOSTUIINFO* pInfo )
  667. {
  668. BSTR wbLoc = NULL;
  669. pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
  670. // Adjust the HTML properties to our liking based on the offer type
  671. // pagetype defs in appdefs.h
  672. switch(m_dwHtmPageType)
  673. {
  674. //YES 3D
  675. case PAGETYPE_BILLING:
  676. case PAGETYPE_ISP_TOS:
  677. case PAGETYPE_MARKETING:
  678. case PAGETYPE_CUSTOMPAY:
  679. {
  680. pInfo->dwFlags = DOCHOSTUIFLAG_DIALOG | DOCHOSTUIFLAG_DISABLE_HELP_MENU;
  681. break;
  682. }
  683. //NO 3D
  684. case PAGETYPE_BRANDED:
  685. case PAGETYPE_ISP_NORMAL:
  686. case PAGETYPE_NOOFFERS:
  687. case PAGETYPE_ISP_FINISH:
  688. case PAGETYPE_ISP_CUSTOMFINISH:
  689. case PAGETYPE_OLS_FINISH:
  690. default:
  691. {
  692. pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_DIALOG | DOCHOSTUIFLAG_SCROLL_NO |
  693. DOCHOSTUIFLAG_DISABLE_HELP_MENU;
  694. break;
  695. }
  696. }
  697. return S_OK;
  698. }
  699. // * CConWizSite::ShowUI
  700. // *
  701. // * Purpose: Called when MSHTML.DLL shows its UI
  702. // *
  703. HRESULT COleSite::ShowUI
  704. (
  705. DWORD dwID,
  706. IOleInPlaceActiveObject * /*pActiveObject*/,
  707. IOleCommandTarget * pCommandTarget,
  708. IOleInPlaceFrame * /*pFrame*/,
  709. IOleInPlaceUIWindow * /*pDoc*/
  710. )
  711. {
  712. // We've already got our own UI in place so just return S_OK
  713. return S_OK;
  714. }
  715. // * CConWizSite::HideUI
  716. // *
  717. // * Purpose: Called when MSHTML.DLL hides its UI
  718. // *
  719. HRESULT COleSite::HideUI(void)
  720. {
  721. return S_OK;
  722. }
  723. // * CConWizSite::UpdateUI
  724. // *
  725. // * Purpose: Called when MSHTML.DLL updates its UI
  726. // *
  727. HRESULT COleSite::UpdateUI(void)
  728. {
  729. return S_OK;
  730. }
  731. // * CConWizSite::EnableModeless
  732. // *
  733. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::EnableModeless
  734. // *
  735. HRESULT COleSite::EnableModeless(BOOL /*fEnable*/)
  736. {
  737. return E_NOTIMPL;
  738. }
  739. // * CConWizSite::OnDocWindowActivate
  740. // *
  741. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnDocWindowActivate
  742. // *
  743. HRESULT COleSite::OnDocWindowActivate(BOOL /*fActivate*/)
  744. {
  745. return E_NOTIMPL;
  746. }
  747. // * CConWizSite::OnFrameWindowActivate
  748. // *
  749. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnFrameWindowActivate
  750. // *
  751. HRESULT COleSite::OnFrameWindowActivate(BOOL /*fActivate*/)
  752. {
  753. return E_NOTIMPL;
  754. }
  755. // * CConWizSite::ResizeBorder
  756. // *
  757. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::ResizeBorder
  758. // *
  759. HRESULT COleSite::ResizeBorder(
  760. LPCRECT /*prcBorder*/,
  761. IOleInPlaceUIWindow* /*pUIWindow*/,
  762. BOOL /*fRameWindow*/)
  763. {
  764. return E_NOTIMPL;
  765. }
  766. // * CConWizSite::ShowContextMenu
  767. // *
  768. // * Purpose: Called when MSHTML.DLL would normally display its context menu
  769. // *
  770. HRESULT COleSite::ShowContextMenu(
  771. DWORD /*dwID*/,
  772. POINT* /*pptPosition*/,
  773. IUnknown* /*pCommandTarget*/,
  774. IDispatch* /*pDispatchObjectHit*/)
  775. {
  776. return S_OK; // We've shown our own context menu. MSHTML.DLL will no longer try to show its own.
  777. }
  778. // * CConWizSite::TranslateAccelerator
  779. // *
  780. // * Purpose: Called from MSHTML.DLL's TranslateAccelerator routines
  781. // *
  782. HRESULT COleSite::TranslateAccelerator(LPMSG lpMsg,
  783. /* [in] */ const GUID __RPC_FAR *pguidCmdGroup,
  784. /* [in] */ DWORD nCmdID)
  785. {
  786. return ResultFromScode(S_FALSE);
  787. }
  788. // * CConWizSite::GetOptionKeyPath
  789. // *
  790. // * Purpose: Called by MSHTML.DLL to find where the host wishes to store
  791. // * its options in the registry
  792. // *
  793. HRESULT COleSite::GetOptionKeyPath(BSTR* pbstrKey, DWORD)
  794. {
  795. return E_NOTIMPL;
  796. }
  797. STDMETHODIMP COleSite::GetDropTarget(
  798. /* [in] */ IDropTarget __RPC_FAR *pDropTarget,
  799. /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)
  800. {
  801. return E_NOTIMPL;
  802. }
  803. STDMETHODIMP COleSite::GetExternal(
  804. /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
  805. {
  806. // return the IDispatch we have for extending the object Model
  807. ASSERT(this);
  808. *ppDispatch = (IDispatch*)this;
  809. return S_OK;
  810. }
  811. STDMETHODIMP COleSite::GetIDsOfNames(
  812. /* [in] */ REFIID riid,
  813. /* [size_is][in] */ OLECHAR** rgszNames,
  814. /* [in] */ UINT cNames,
  815. /* [in] */ LCID lcid,
  816. /* [size_is][out] */ DISPID* rgDispId)
  817. {
  818. HRESULT hr = ResultFromScode(DISP_E_UNKNOWNNAME);
  819. rgDispId[0] = DISPID_UNKNOWN;
  820. for (int iX = 0; iX < sizeof(ExternalInterface)/sizeof(DISPATCHLIST); iX++)
  821. {
  822. if ( 2 == CompareString( lcid,
  823. NORM_IGNORECASE | NORM_IGNOREWIDTH,
  824. (LPCTSTR)ExternalInterface[iX].szName,
  825. ExternalInterface[iX].cName,
  826. (LPCTSTR)rgszNames[0],
  827. wcslen(rgszNames[0])))
  828. {
  829. rgDispId[0] = ExternalInterface[iX].dwDispID;
  830. hr = NOERROR;
  831. break;
  832. }
  833. }
  834. // Set the disid's for the parameters
  835. if (cNames > 1)
  836. {
  837. // Set a DISPID for function parameters
  838. for (UINT i = 1; i < cNames ; i++)
  839. rgDispId[i] = DISPID_UNKNOWN;
  840. }
  841. return hr;
  842. }
  843. STDMETHODIMP COleSite::TranslateUrl(
  844. /* [in] */ DWORD dwTranslate,
  845. /* [in] */ OLECHAR __RPC_FAR *pchURLIn,
  846. /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
  847. {
  848. return E_NOTIMPL;
  849. }
  850. STDMETHODIMP COleSite::FilterDataObject(
  851. /* [in] */ IDataObject __RPC_FAR *pDO,
  852. /* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet)
  853. {
  854. return E_NOTIMPL;
  855. }
  856. HRESULT COleSite::ActivateOLSText(void )
  857. {
  858. LPDISPATCH pDisp = NULL;
  859. // Get the document pointer from this webbrowser.
  860. if (SUCCEEDED(m_lpWebBrowser->get_Document(&pDisp)) && pDisp)
  861. {
  862. IHTMLDocument2* pDoc = NULL;
  863. if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc)) && pDoc)
  864. {
  865. IHTMLElementCollection* pColl = NULL;
  866. // retrieve a reference to the ALL collection
  867. if (SUCCEEDED(pDoc->get_all( &pColl )))
  868. {
  869. // Get the two spans we are interested in from the all collection
  870. VARIANT varName;
  871. VariantInit(&varName);
  872. V_VT(&varName) = VT_BSTR;
  873. varName.bstrVal = A2W(cszOLSNewText);
  874. VARIANT varIdx;
  875. varIdx.vt = VT_UINT;
  876. varIdx.lVal = 0;
  877. LPDISPATCH pDispElt = NULL;
  878. // Get the IDispatch for NewText SPAN, and set it to visible
  879. if (SUCCEEDED(pColl->item(varName, varIdx, &pDispElt)) && pDispElt)
  880. {
  881. IHTMLElement* pElt = NULL;
  882. if (SUCCEEDED(pDispElt->QueryInterface( IID_IHTMLElement, (LPVOID*)&pElt )) && pElt)
  883. {
  884. IHTMLStyle *pStyle = NULL;
  885. // Get the style interface for this element, so we can tweak it
  886. if (SUCCEEDED(pElt->get_style(&pStyle)))
  887. {
  888. pStyle->put_visibility(A2W(TEXT("visible")));
  889. pStyle->Release();
  890. }
  891. pElt->Release();
  892. }
  893. pDispElt->Release();
  894. }
  895. pDispElt = NULL;
  896. varName.bstrVal = A2W(cszOLSOldText);
  897. // Get the IDispatch for OldText SPAN, and set it to hidden
  898. if (SUCCEEDED(pColl->item(varName, varIdx, &pDispElt)) && pDispElt)
  899. {
  900. IHTMLElement* pElt = NULL;
  901. if (SUCCEEDED(pDispElt->QueryInterface( IID_IHTMLElement, (LPVOID*)&pElt )) && pElt)
  902. {
  903. IHTMLStyle *pStyle = NULL;
  904. // Get the style interface for this element, so we can tweak it
  905. if (SUCCEEDED(pElt->get_style(&pStyle)))
  906. {
  907. pStyle->put_visibility(A2W(TEXT("hidden")));
  908. pStyle->Release();
  909. }
  910. pElt->Release();
  911. }
  912. pDispElt->Release();
  913. }
  914. pColl->Release();
  915. } // get_all
  916. pDoc->Release();
  917. }
  918. pDisp->Release();
  919. }
  920. return S_OK;
  921. }
  922. //returns true if focus was sucessfully set
  923. BOOL COleSite::TrySettingFocusOnHtmlElement(IUnknown* pUnk)
  924. {
  925. IHTMLControlElement* pControl = NULL;
  926. BOOL bFocusWasSet = FALSE;
  927. if(SUCCEEDED(pUnk->QueryInterface(IID_IHTMLControlElement, (LPVOID*)&pControl)) && pControl)
  928. {
  929. if(SUCCEEDED(pControl->focus()))
  930. bFocusWasSet = TRUE;
  931. pControl->Release();
  932. }
  933. return bFocusWasSet;
  934. }
  935. BOOL COleSite::SetFocusToFirstHtmlInputElement()
  936. {
  937. VARIANT vIndex;
  938. IDispatch* pDisp = NULL;
  939. IDispatch* pDispElement = NULL;
  940. IHTMLDocument2* pDoc = NULL;
  941. IHTMLElementCollection* pColl = NULL;
  942. IHTMLButtonElement* pButton = NULL;
  943. IHTMLInputButtonElement* pInputButton = NULL;
  944. IHTMLInputFileElement* pInputFile = NULL;
  945. IHTMLInputTextElement* pInputText = NULL;
  946. IHTMLSelectElement* pSelect = NULL;
  947. IHTMLTextAreaElement* pTextArea = NULL;
  948. IHTMLOptionButtonElement* pOptionButton = NULL;
  949. VARIANT varNull = { 0 };
  950. long lLen = 0;
  951. BOOL bFocusWasSet = FALSE;
  952. vIndex.vt = VT_UINT;
  953. if (SUCCEEDED(m_lpWebBrowser->get_Document(&pDisp)) && pDisp)
  954. {
  955. if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pDoc)) && pDoc)
  956. {
  957. if (SUCCEEDED(pDoc->get_all(&pColl)) && pColl)
  958. {
  959. pColl->get_length(&lLen);
  960. for (int i = 0; i < lLen; i++)
  961. {
  962. vIndex.lVal = i;
  963. pDispElement = NULL;
  964. if(SUCCEEDED(pColl->item(vIndex, varNull, &pDispElement)) && pDispElement)
  965. {
  966. pButton = NULL;
  967. pInputButton = NULL;
  968. pInputFile = NULL;
  969. pInputText = NULL;
  970. pSelect = NULL;
  971. if(SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLButtonElement, (LPVOID*)&pButton)) && pButton)
  972. {
  973. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pButton);
  974. pButton->Release();
  975. }
  976. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLInputButtonElement, (LPVOID*)&pInputButton)) && pInputButton)
  977. {
  978. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pInputButton);
  979. pInputButton->Release();
  980. }
  981. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLInputFileElement, (LPVOID*)&pInputFile)) && pInputFile)
  982. {
  983. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pInputFile);
  984. pInputFile->Release();
  985. }
  986. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLInputTextElement, (LPVOID*)&pInputText)) && pInputText)
  987. {
  988. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pInputText);
  989. pInputText->Release();
  990. }
  991. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLSelectElement, (LPVOID*)&pSelect)) && pSelect)
  992. {
  993. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pSelect);
  994. pSelect->Release();
  995. }
  996. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLTextAreaElement, (LPVOID*)&pTextArea)) && pTextArea)
  997. {
  998. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pTextArea);
  999. pTextArea->Release();
  1000. }
  1001. else if (SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLOptionButtonElement, (LPVOID*)&pOptionButton)) && pOptionButton)
  1002. {
  1003. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pOptionButton);
  1004. pOptionButton->Release();
  1005. }
  1006. pDispElement->Release();
  1007. }
  1008. if(bFocusWasSet)
  1009. break;
  1010. }
  1011. pColl->Release();
  1012. }
  1013. pDoc->Release();
  1014. }
  1015. pDisp->Release();
  1016. }
  1017. return bFocusWasSet;
  1018. }
  1019. BOOL COleSite::SetFocusToHtmlPage()
  1020. {
  1021. IDispatch* pDisp = NULL;
  1022. IHTMLDocument2* pDoc = NULL;
  1023. IHTMLElement* pElement = NULL;
  1024. BOOL bFocusWasSet = FALSE;
  1025. DOCHOSTUIINFO pInfo;
  1026. pInfo.cbSize = sizeof(DOCHOSTUIINFO);
  1027. if(SUCCEEDED(GetHostInfo(&pInfo)))
  1028. {
  1029. if(!(pInfo.dwFlags & DOCHOSTUIFLAG_SCROLL_NO))
  1030. {
  1031. if (SUCCEEDED(m_lpWebBrowser->get_Document(&pDisp)) && pDisp)
  1032. {
  1033. if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pDoc)) && pDoc)
  1034. {
  1035. if (SUCCEEDED(pDoc->get_body(&pElement)) && pElement)
  1036. {
  1037. bFocusWasSet = TrySettingFocusOnHtmlElement((IUnknown*)pElement);
  1038. pElement->Release();
  1039. }
  1040. pDoc->Release();
  1041. }
  1042. pDisp->Release();
  1043. }
  1044. }
  1045. }
  1046. return bFocusWasSet;
  1047. }
  1048. HRESULT COleSite::Invoke
  1049. (
  1050. DISPID dispidMember,
  1051. REFIID riid,
  1052. LCID lcid,
  1053. WORD wFlags,
  1054. DISPPARAMS FAR* pdispparams,
  1055. VARIANT FAR* pvarResult,
  1056. EXCEPINFO FAR* pexcepinfo,
  1057. UINT FAR* puArgErr
  1058. )
  1059. {
  1060. HRESULT hr = DISP_E_MEMBERNOTFOUND;
  1061. // Either one of these is good, since we just want to make sure the DOCUMENT pointer is
  1062. // available.
  1063. switch(dispidMember)
  1064. {
  1065. case DISPID_DOCUMENTCOMPLETE:
  1066. case DISPID_NAVIGATECOMPLETE:
  1067. {
  1068. TCHAR szFontFace [MAX_RES_LEN] = TEXT("\0");
  1069. TCHAR szFontSize [MAX_RES_LEN] = TEXT("\0");
  1070. LoadString(ghInstance, IDS_HTML_DEFAULT_FONTFACE, szFontFace, MAX_RES_LEN);
  1071. LoadString(ghInstance, IDS_HTML_DEFAULT_FONTSIZE, szFontSize, MAX_RES_LEN);
  1072. ASSERT(strlen(szFontFace) != 0);
  1073. ASSERT(strlen(szFontSize) != 0);
  1074. // Adjust the HTML properties to our liking based on the offer type
  1075. // html default defs in icwutil.h and icwutil.rc
  1076. // pagetype defs in appdefs.h
  1077. switch(m_dwHtmPageType)
  1078. {
  1079. case PAGETYPE_BILLING:
  1080. case PAGETYPE_CUSTOMPAY:
  1081. case PAGETYPE_ISP_TOS:
  1082. case PAGETYPE_ISP_NORMAL:
  1083. {
  1084. TweakHTML(szFontFace,
  1085. szFontSize,
  1086. m_szBkGrndColor,
  1087. m_szForeGrndColor);
  1088. if(!SetFocusToFirstHtmlInputElement())
  1089. SetFocusToHtmlPage();
  1090. break;
  1091. }
  1092. // For the OLS finish page, we need to tweak it's display by
  1093. // invoking the SetNewText script function
  1094. case PAGETYPE_OLS_FINISH:
  1095. {
  1096. TweakHTML(szFontFace,
  1097. szFontSize,
  1098. HTML_DEFAULT_BGCOLOR,
  1099. HTML_DEFAULT_COLOR);
  1100. ActivateOLSText();
  1101. break;
  1102. }
  1103. case PAGETYPE_ISP_FINISH:
  1104. case PAGETYPE_ISP_CUSTOMFINISH:
  1105. case PAGETYPE_NOOFFERS:
  1106. {
  1107. TweakHTML(szFontFace,
  1108. szFontSize,
  1109. HTML_DEFAULT_SPECIALBGCOLOR,
  1110. HTML_DEFAULT_COLOR);
  1111. break;
  1112. }
  1113. case PAGETYPE_MARKETING:
  1114. case PAGETYPE_BRANDED:
  1115. default:
  1116. {
  1117. //Do just the background bitmap if necessary
  1118. if (m_bUseBkGndBitmap)
  1119. {
  1120. TweakHTML(NULL,
  1121. NULL,
  1122. HTML_DEFAULT_BGCOLOR,
  1123. HTML_DEFAULT_COLOR);
  1124. }
  1125. break;
  1126. }
  1127. }
  1128. DisableHyperlinksInDocument();
  1129. // Show the Page
  1130. ShowHTML();
  1131. break;
  1132. }
  1133. case DISPID_RunIcwTutorApp:
  1134. {
  1135. PostMessage(GetParent(m_hWnd), WM_RUNICWTUTORAPP, 0, 0);
  1136. break;
  1137. }
  1138. default:
  1139. {
  1140. hr = DISP_E_MEMBERNOTFOUND;
  1141. break;
  1142. }
  1143. }
  1144. return hr;
  1145. }
  1146. void COleSite::DisableHyperlinksInDocument()
  1147. {
  1148. VARIANT vIndex;
  1149. IHTMLAnchorElement* pAnchor;
  1150. IHTMLElement* pElement;
  1151. IDispatch* pDisp = NULL;
  1152. IDispatch* pDispElement = NULL;
  1153. IDispatch* pDispElement2 = NULL;
  1154. IHTMLDocument2* pDoc = NULL;
  1155. IHTMLElementCollection* pColl = NULL;
  1156. BSTR bstrInnerHtml = NULL;
  1157. BSTR bstrOuterHtml = NULL;
  1158. VARIANT varNull = { 0 };
  1159. long lLen = 0;
  1160. vIndex.vt = VT_UINT;
  1161. bstrOuterHtml = SysAllocString(A2W(TEXT("&nbsp<SPAN></SPAN>&nbsp")));
  1162. if (SUCCEEDED(m_lpWebBrowser->get_Document(&pDisp)) && pDisp)
  1163. {
  1164. if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pDoc)) && pDoc)
  1165. {
  1166. if (SUCCEEDED(pDoc->get_all(&pColl)) && pColl)
  1167. {
  1168. pColl->get_length(&lLen);
  1169. for (int i = 0; i < lLen; i++)
  1170. {
  1171. vIndex.lVal = i;
  1172. pDispElement = NULL;
  1173. if(SUCCEEDED(pColl->item(vIndex, varNull, &pDispElement)) && pDispElement)
  1174. {
  1175. pAnchor = NULL;
  1176. if(SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLAnchorElement, (LPVOID*)&pAnchor)) && pAnchor)
  1177. {
  1178. pAnchor->Release();
  1179. pElement = NULL;
  1180. if(SUCCEEDED(pDispElement->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElement)) && pElement)
  1181. {
  1182. pElement->get_innerHTML(&bstrInnerHtml);
  1183. pElement->put_outerHTML(bstrOuterHtml);
  1184. pElement->Release();
  1185. if(bstrInnerHtml)
  1186. {
  1187. pDispElement2 = NULL;;
  1188. if(SUCCEEDED(pColl->item(vIndex, varNull, &pDispElement2)) && pDispElement2)
  1189. {
  1190. pElement = NULL;
  1191. if(SUCCEEDED(pDispElement2->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElement)) && pElement)
  1192. {
  1193. pElement->put_innerHTML(bstrInnerHtml);
  1194. SysFreeString(bstrInnerHtml);
  1195. bstrInnerHtml = NULL;
  1196. pElement->Release();
  1197. }
  1198. pDispElement2->Release();
  1199. }
  1200. }
  1201. }
  1202. }
  1203. pDispElement->Release();
  1204. }
  1205. }
  1206. pColl->Release();
  1207. }
  1208. pDoc->Release();
  1209. }
  1210. pDisp->Release();
  1211. }
  1212. if(bstrInnerHtml)
  1213. SysFreeString(bstrInnerHtml);
  1214. SysFreeString(bstrOuterHtml);
  1215. }