1
0

HTMLContainer.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. #include "HTMLContainer.h"
  2. #include <exdisp.h>
  3. #include <mshtmdid.h>
  4. #include <mshtml.h>
  5. #include <exdispid.h>
  6. #include <strsafe.h>
  7. #ifndef DISPID_NEWWINDOW3
  8. #define DISPID_NEWWINDOW3 273
  9. #endif
  10. // ---------------------------------------------------------------
  11. IConnectionPoint *HTMLContainer::GetConnectionPoint (REFIID riid)
  12. {
  13. IUnknown *punk = getUnknown ();
  14. if (!punk)
  15. return 0;
  16. IConnectionPointContainer *pcpc;
  17. IConnectionPoint *pcp = 0;
  18. HRESULT hr = punk->QueryInterface (IID_IConnectionPointContainer, (void **) & pcpc);
  19. if (SUCCEEDED (hr))
  20. {
  21. pcpc->FindConnectionPoint (riid, &pcp);
  22. pcpc->Release();
  23. }
  24. punk->Release();
  25. return pcp;
  26. }
  27. void HTMLContainer::SyncSizeToWindow(HWND hwnd)
  28. {
  29. RECT rect;
  30. GetWindowRect(hwnd, &rect);
  31. int height = (rect.bottom - rect.top);
  32. // if we get a null height then hide the html control (after limiting to 1px)
  33. // and also hide it's parent window - is mainly for ml_wire to prevent display
  34. // glitches when resizing the bottom segment all the way to the bottom
  35. ShowWindow(m_hwnd,height?SW_SHOWNA:SW_HIDE);
  36. ShowWindow(hwnd,height?SW_SHOWNA:SW_HIDE);
  37. setLocation(0, 0, rect.right - rect.left, height?height:1);
  38. }
  39. // uncomment if you ever want to use mozilla instead of IE
  40. // change the CLSID_WebBrowser in the constructor below to CLSID_MozillaBrowser
  41. // but window.external from javascript doesn't work :(
  42. static const CLSID CLSID_MozillaBrowser=
  43. { 0x1339B54C, 0x3453, 0x11D2, { 0x93, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
  44. HTMLContainer::HTMLContainer(HWND hwnd)
  45. : m_pweb (0), pszHostCSS(NULL), m_cRefs(1), m_hwnd(hwnd), m_punk(NULL)
  46. {
  47. bInitialized = (S_OK == CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)) ? true : false;
  48. dwHostInfoFlags = DOCHOSTUIFLAG_NO3DOUTERBORDER | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIDBLCLK_DEFAULT;
  49. dwDownloadFlags = DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_PRAGMA_NO_CACHE;
  50. memset(&m_rect, 0, sizeof(m_rect));
  51. add(CLSID_WebBrowser);
  52. IUnknown *punk = getUnknown();
  53. if (punk)
  54. {
  55. if (SUCCEEDED(punk->QueryInterface (IID_IWebBrowser2, (void **) & m_pweb))
  56. || SUCCEEDED(punk->QueryInterface (IID_IWebBrowser, (void **) & m_pweb)))
  57. {
  58. IConnectionPoint *icp = GetConnectionPoint(DIID_DWebBrowserEvents2);
  59. if (icp)
  60. {
  61. m_dwCookie = 0;
  62. icp->Advise(static_cast<IDispatch *>(this), &m_dwCookie);
  63. icp->Release();
  64. }
  65. }
  66. else
  67. m_pweb=0;
  68. punk->Release();
  69. }
  70. }
  71. HTMLContainer::HTMLContainer()
  72. : m_pweb (0), pszHostCSS(NULL), m_cRefs(1), m_hwnd(NULL), m_punk(NULL)
  73. {
  74. bInitialized = (S_OK == CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)) ? true : false;
  75. dwHostInfoFlags = DOCHOSTUIFLAG_NO3DOUTERBORDER | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIDBLCLK_DEFAULT;
  76. dwDownloadFlags = DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_PRAGMA_NO_CACHE;
  77. memset(&m_rect, 0, sizeof(m_rect));
  78. add(CLSID_WebBrowser);
  79. IUnknown *punk = getUnknown();
  80. if (punk)
  81. {
  82. if (SUCCEEDED(punk->QueryInterface (IID_IWebBrowser2, (void **) & m_pweb))
  83. || SUCCEEDED(punk->QueryInterface (IID_IWebBrowser, (void **) & m_pweb)))
  84. {
  85. IConnectionPoint *icp = GetConnectionPoint(DIID_DWebBrowserEvents2);
  86. if (icp)
  87. {
  88. m_dwCookie = 0;
  89. icp->Advise(static_cast<IDispatch *>(this), &m_dwCookie);
  90. icp->Release();
  91. }
  92. }
  93. else
  94. m_pweb=0;
  95. punk->Release();
  96. }
  97. }
  98. HTMLContainer::~HTMLContainer()
  99. {
  100. close();
  101. if (pszHostCSS) { free(pszHostCSS); pszHostCSS = NULL; }
  102. if (bInitialized) CoUninitialize();
  103. }
  104. void HTMLContainer::close()
  105. {
  106. IOleObject *pioo;
  107. if ( m_punk )
  108. {
  109. HRESULT hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  110. if (SUCCEEDED(hr))
  111. {
  112. pioo->Close(OLECLOSE_NOSAVE);
  113. pioo->Release();
  114. }
  115. }
  116. if (m_punk)
  117. {
  118. m_punk->Release();
  119. m_punk = NULL;
  120. }
  121. if (m_pweb)
  122. {
  123. m_pweb->Quit();
  124. m_pweb->Release();
  125. m_pweb = 0;
  126. }
  127. }
  128. STDMETHODIMP HTMLContainer::QueryInterface(REFIID riid, PVOID *ppvObject)
  129. {
  130. if (!ppvObject)
  131. return E_POINTER;
  132. if (IsEqualIID(riid, IID_IOleClientSite))
  133. *ppvObject = (IOleClientSite *)this;
  134. else if (IsEqualIID(riid, IID_IOleInPlaceSite))
  135. *ppvObject = (IOleInPlaceSite *)this;
  136. else if (IsEqualIID(riid, IID_IOleInPlaceFrame))
  137. *ppvObject = (IOleInPlaceFrame *)this;
  138. else if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  139. *ppvObject = (IOleInPlaceUIWindow *)this;
  140. else if (IsEqualIID(riid, IID_IOleControlSite))
  141. *ppvObject = (IOleControlSite *)this;
  142. else if (IsEqualIID(riid, IID_IOleWindow))
  143. *ppvObject = this;
  144. else if (IsEqualIID(riid, IID_IDispatch))
  145. *ppvObject = (IDispatch *)this;
  146. else if (IsEqualIID(riid, IID_IUnknown))
  147. *ppvObject = this;
  148. else if (IsEqualIID(riid, IID_IDocHostUIHandler))
  149. *ppvObject = (IDocHostUIHandler *)this;
  150. else
  151. {
  152. *ppvObject = NULL;
  153. return E_NOINTERFACE;
  154. }
  155. AddRef();
  156. return S_OK;
  157. }
  158. ULONG HTMLContainer::AddRef(void)
  159. {
  160. return ++m_cRefs;
  161. }
  162. ULONG HTMLContainer::Release(void)
  163. {
  164. if (--m_cRefs)
  165. return m_cRefs;
  166. return 0;
  167. }
  168. HRESULT HTMLContainer::SaveObject()
  169. {
  170. return E_NOTIMPL;
  171. }
  172. HRESULT HTMLContainer::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER * ppMk)
  173. {
  174. return E_NOTIMPL;
  175. }
  176. HRESULT HTMLContainer::GetContainer(LPOLECONTAINER * ppContainer)
  177. {
  178. return E_NOINTERFACE;
  179. }
  180. HRESULT HTMLContainer::ShowObject()
  181. {
  182. return S_OK;
  183. }
  184. HRESULT HTMLContainer::OnShowWindow(BOOL fShow)
  185. {
  186. return S_OK;
  187. }
  188. HRESULT HTMLContainer::RequestNewObjectLayout()
  189. {
  190. return E_NOTIMPL;
  191. }
  192. HRESULT HTMLContainer::GetWindow(HWND * lphwnd)
  193. {
  194. if (!IsWindow(m_hwnd))
  195. return S_FALSE;
  196. *lphwnd = m_hwnd;
  197. return S_OK;
  198. }
  199. HRESULT HTMLContainer::ContextSensitiveHelp(BOOL fEnterMode)
  200. {
  201. return E_NOTIMPL;
  202. }
  203. HRESULT HTMLContainer::CanInPlaceActivate(void)
  204. {
  205. return S_OK;
  206. }
  207. HRESULT HTMLContainer::OnInPlaceActivate(void)
  208. {
  209. return S_OK;
  210. }
  211. HRESULT HTMLContainer::OnUIActivate(void)
  212. {
  213. return S_OK;
  214. }
  215. HRESULT HTMLContainer::GetWindowContext(IOleInPlaceFrame ** ppFrame, IOleInPlaceUIWindow ** ppIIPUIWin,
  216. LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  217. {
  218. *ppFrame = (IOleInPlaceFrame *)this;
  219. *ppIIPUIWin = NULL;
  220. RECT rect;
  221. GetClientRect(m_hwnd, &rect);
  222. lprcPosRect->left = 0;
  223. lprcPosRect->top = 0;
  224. lprcPosRect->right = rect.right;
  225. lprcPosRect->bottom = rect.bottom;
  226. CopyRect(lprcClipRect, lprcPosRect);
  227. lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
  228. lpFrameInfo->fMDIApp = FALSE;
  229. lpFrameInfo->hwndFrame = m_hwnd;
  230. lpFrameInfo->haccel = 0;
  231. lpFrameInfo->cAccelEntries = 0;
  232. (*ppFrame)->AddRef();
  233. return S_OK;
  234. }
  235. HRESULT HTMLContainer::Scroll(SIZE scrollExtent)
  236. {
  237. return E_NOTIMPL;
  238. }
  239. HRESULT HTMLContainer::OnUIDeactivate(BOOL fUndoable)
  240. {
  241. return E_NOTIMPL;
  242. }
  243. HRESULT HTMLContainer::OnInPlaceDeactivate(void)
  244. {
  245. return S_OK;
  246. }
  247. HRESULT HTMLContainer::DiscardUndoState(void)
  248. {
  249. return E_NOTIMPL;
  250. }
  251. HRESULT HTMLContainer::DeactivateAndUndo(void)
  252. {
  253. return E_NOTIMPL;
  254. }
  255. HRESULT HTMLContainer::OnPosRectChange(LPCRECT lprcPosRect)
  256. {
  257. return S_OK;
  258. }
  259. HRESULT HTMLContainer::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
  260. {
  261. return E_NOTIMPL;
  262. }
  263. HRESULT HTMLContainer::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  264. {
  265. return E_NOTIMPL;
  266. }
  267. HRESULT HTMLContainer::RemoveMenus(HMENU hmenuShared)
  268. {
  269. return E_NOTIMPL;
  270. }
  271. HRESULT HTMLContainer::SetStatusText(LPCOLESTR pszStatusText)
  272. {
  273. return S_OK;
  274. }
  275. HRESULT HTMLContainer::TranslateAccelerator(LPMSG lpmsg, WORD wID)
  276. {
  277. return S_OK;
  278. }
  279. HRESULT HTMLContainer::EnableModeless(BOOL fEnable)
  280. {
  281. return E_NOTIMPL;
  282. }
  283. HRESULT HTMLContainer::OnControlInfoChanged()
  284. {
  285. return E_NOTIMPL;
  286. }
  287. HRESULT HTMLContainer::LockInPlaceActive(BOOL fLock)
  288. {
  289. return E_NOTIMPL;
  290. }
  291. HRESULT HTMLContainer::GetExtendedControl(IDispatch **ppDisp)
  292. {
  293. if (ppDisp == NULL)
  294. return E_INVALIDARG;
  295. *ppDisp = (IDispatch *)this;
  296. (*ppDisp)->AddRef();
  297. return S_OK;
  298. }
  299. HRESULT HTMLContainer::TransformCoords(POINTL *pptlHimetric, POINTF *pptfContainer, DWORD dwFlags)
  300. {
  301. return E_NOTIMPL;
  302. }
  303. HRESULT HTMLContainer::TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers)
  304. {
  305. return S_FALSE;
  306. }
  307. HRESULT HTMLContainer::OnFocus(BOOL fGotFocus)
  308. {
  309. return E_NOTIMPL;
  310. }
  311. HRESULT HTMLContainer::ShowPropertyFrame(void)
  312. {
  313. return E_NOTIMPL;
  314. }
  315. HRESULT HTMLContainer::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  316. {
  317. *rgdispid = DISPID_UNKNOWN;
  318. return DISP_E_UNKNOWNNAME;
  319. }
  320. HRESULT HTMLContainer::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  321. {
  322. return E_NOTIMPL;
  323. }
  324. HRESULT HTMLContainer::GetTypeInfoCount(unsigned int FAR * pctinfo)
  325. {
  326. return E_NOTIMPL;
  327. }
  328. void HTMLContainer::OnBeforeNavigate(IDispatch *pDispatch, LPCWSTR pszURL, DWORD dwFlags, LPCWSTR pszTargetFrameName, VARIANT *vtPostData, LPCWSTR pszHeaders, VARIANT_BOOL *Cancel)
  329. {
  330. }
  331. void HTMLContainer::OnNavigateError(IDispatch *pDispatch, LPCWSTR pszURL, LPCWSTR pszTargetFrameName, INT nStatusCode, VARIANT_BOOL *Cancel)
  332. {
  333. }
  334. void HTMLContainer::OnNavigateComplete(IDispatch *pDispatch, LPCWSTR pszURL)
  335. {
  336. }
  337. void HTMLContainer::OnDocumentComplete(IDispatch *pDisp, LPCWSTR pszURL)
  338. {
  339. }
  340. void HTMLContainer::OnDownloadBegin(void)
  341. {
  342. }
  343. void HTMLContainer::OnDownloadComplete(void)
  344. {
  345. }
  346. void HTMLContainer::OnFileDownload(VARIANT_BOOL *ActiveDocument, VARIANT_BOOL *Cancel)
  347. {
  348. }
  349. void HTMLContainer::OnNewWindow2(IDispatch **ppDisp, VARIANT_BOOL *Cancel)
  350. {
  351. }
  352. void HTMLContainer::OnNewWindow3(IDispatch **ppDisp, VARIANT_BOOL *Cancel, DWORD dwFlags, LPCWSTR pszUrlContext, LPCWSTR pszUrl)
  353. {
  354. }
  355. void HTMLContainer::OnProgressChange(long Progress, long ProgressMax)
  356. {
  357. }
  358. void HTMLContainer::OnStatusTextChange(LPCWSTR pszText)
  359. {
  360. }
  361. #define GET_SAFE_DISP_BSTR(_val) ((_val.pvarVal && VT_BSTR == _val.pvarVal->vt) ? _val.pvarVal->bstrVal : NULL)
  362. #define GET_SAFE_DISP_I4(_val) ((_val.pvarVal && VT_I4 == _val.pvarVal->vt) ? _val.pvarVal->intVal : 0)
  363. HRESULT HTMLContainer::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  364. {
  365. switch (dispid)
  366. {
  367. case DISPID_BEFORENAVIGATE2:
  368. OnBeforeNavigate();
  369. OnBeforeNavigate( pdispparams->rgvarg[6].pdispVal, GET_SAFE_DISP_BSTR(pdispparams->rgvarg[5]),
  370. GET_SAFE_DISP_I4(pdispparams->rgvarg[4]), GET_SAFE_DISP_BSTR(pdispparams->rgvarg[3]),
  371. pdispparams->rgvarg[2].pvarVal, GET_SAFE_DISP_BSTR(pdispparams->rgvarg[1]), pdispparams->rgvarg[0].pboolVal);
  372. break;
  373. case DISPID_NAVIGATEERROR:
  374. {
  375. VARIANT * vt_statuscode = pdispparams->rgvarg[1].pvarVal;
  376. DWORD dwStatusCode = vt_statuscode->lVal;
  377. if (dwStatusCode == 200)
  378. {
  379. *pdispparams->rgvarg[0].pboolVal = VARIANT_TRUE;
  380. break;
  381. }
  382. OnNavigateError();
  383. OnNavigateError(pdispparams->rgvarg[4].pdispVal, GET_SAFE_DISP_BSTR(pdispparams->rgvarg[3]),
  384. GET_SAFE_DISP_BSTR(pdispparams->rgvarg[2]), GET_SAFE_DISP_I4(pdispparams->rgvarg[1]), pdispparams->rgvarg[0].pboolVal);
  385. }
  386. break;
  387. case DISPID_NAVIGATECOMPLETE2:
  388. OnNavigateComplete();
  389. OnNavigateComplete(pdispparams->rgvarg[1].pdispVal, GET_SAFE_DISP_BSTR(pdispparams->rgvarg[0]));
  390. break;
  391. case DISPID_DOCUMENTCOMPLETE:
  392. OnDocumentComplete(pdispparams->rgvarg[1].pdispVal, GET_SAFE_DISP_BSTR(pdispparams->rgvarg[0]));
  393. break;
  394. case DISPID_DOWNLOADBEGIN:
  395. OnDownloadBegin();
  396. break;
  397. case DISPID_DOWNLOADCOMPLETE:
  398. OnDownloadComplete();
  399. break;
  400. case DISPID_FILEDOWNLOAD:
  401. OnFileDownload(pdispparams->rgvarg[1].pboolVal, pdispparams->rgvarg[0].pboolVal);
  402. break;
  403. case DISPID_NEWWINDOW2:
  404. OnNewWindow2(pdispparams->rgvarg[1].ppdispVal, pdispparams->rgvarg[0].pboolVal);
  405. break;
  406. case DISPID_NEWWINDOW3:
  407. OnNewWindow3(pdispparams->rgvarg[4].ppdispVal, pdispparams->rgvarg[3].pboolVal,
  408. pdispparams->rgvarg[2].intVal, pdispparams->rgvarg[1].bstrVal, pdispparams->rgvarg[0].bstrVal);
  409. break;
  410. case DISPID_PROGRESSCHANGE:
  411. OnProgressChange(pdispparams->rgvarg[1].lVal, pdispparams->rgvarg[0].lVal);
  412. break;
  413. case DISPID_STATUSTEXTCHANGE:
  414. OnStatusTextChange(GET_SAFE_DISP_BSTR(pdispparams->rgvarg[0]));
  415. break;
  416. case DISPID_AMBIENT_USERAGENT:
  417. /* TODO:
  418. pvar->vt = VT_BSTR;
  419. pvar->bstrVal = SysAllocString("...");
  420. return S_OK;
  421. */
  422. break;
  423. case DISPID_AMBIENT_DLCONTROL:
  424. pvarResult->vt = VT_I4;
  425. pvarResult->lVal = dwDownloadFlags;
  426. return S_OK;
  427. }
  428. return DISP_E_MEMBERNOTFOUND;
  429. }
  430. void HTMLContainer::add(CLSID clsid)
  431. {
  432. HRESULT hr; // return code
  433. CoCreateInstance(clsid,
  434. NULL,
  435. CLSCTX_INPROC_SERVER/* | CLSCTX_LOCAL_SERVER*/,
  436. IID_IUnknown,
  437. (PVOID *)&m_punk);
  438. if (!m_punk)
  439. return ;
  440. IOleObject *pioo;
  441. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  442. if (FAILED(hr))
  443. return ;
  444. pioo->SetClientSite(this);
  445. pioo->Release();
  446. IPersistStreamInit *ppsi;
  447. hr = m_punk->QueryInterface(IID_IPersistStreamInit, (PVOID *) & ppsi);
  448. if (SUCCEEDED(hr))
  449. {
  450. ppsi->InitNew();
  451. ppsi->Release();
  452. }
  453. }
  454. void HTMLContainer::remove()
  455. {
  456. if (!m_punk)
  457. return ;
  458. HRESULT hr;
  459. IOleObject *pioo;
  460. IOleInPlaceObject *pipo;
  461. /*
  462. benski> enabling this makes everything lock up!
  463. IConnectionPoint *icp = GetConnectionPoint(DIID_DWebBrowserEvents2);
  464. if (icp)
  465. {
  466. // m_dwCookie = 0;
  467. HRESULT hr = icp->Unadvise(m_dwCookie);
  468. icp->Release();
  469. }
  470. */
  471. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  472. if (SUCCEEDED(hr))
  473. {
  474. pioo->Close(OLECLOSE_NOSAVE);
  475. pioo->SetClientSite(NULL);
  476. pioo->Release();
  477. }
  478. hr = m_punk->QueryInterface(IID_IOleInPlaceObject, (PVOID *) & pipo);
  479. if (SUCCEEDED(hr))
  480. {
  481. pipo->UIDeactivate();
  482. pipo->InPlaceDeactivate();
  483. pipo->Release();
  484. }
  485. m_punk->Release();
  486. m_punk = NULL;
  487. }
  488. void HTMLContainer::setLocation(int x, int y, int width, int height)
  489. {
  490. m_rect.left = x;
  491. m_rect.top = y;
  492. m_rect.right = x + width;
  493. m_rect.bottom = y + height;
  494. if (!m_punk)
  495. return ;
  496. HRESULT hr;
  497. IOleInPlaceObject *pipo;
  498. hr = m_punk->QueryInterface(IID_IOleInPlaceObject, (PVOID *) & pipo);
  499. if (FAILED(hr))
  500. return ;
  501. pipo->SetObjectRects(&m_rect, &m_rect);
  502. pipo->Release();
  503. }
  504. HRESULT HTMLContainer::GetBorder(LPRECT lprectBorder)
  505. {
  506. return E_NOTIMPL;
  507. }
  508. HRESULT HTMLContainer::RequestBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  509. {
  510. return E_NOTIMPL;
  511. }
  512. HRESULT HTMLContainer::SetBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  513. {
  514. return E_NOTIMPL;
  515. }
  516. HRESULT HTMLContainer::SetActiveObject(IOleInPlaceActiveObject * pActiveObject, LPCOLESTR lpszObjName)
  517. {
  518. return E_NOTIMPL;
  519. }
  520. void HTMLContainer::setVisible(BOOL fVisible)
  521. {
  522. if (!m_punk)
  523. return ;
  524. HRESULT hr;
  525. IOleObject *pioo;
  526. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  527. if (FAILED(hr))
  528. return ;
  529. if (fVisible)
  530. {
  531. pioo->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, this, 0, m_hwnd, &m_rect);
  532. pioo->DoVerb(OLEIVERB_SHOW, NULL, this, 0, m_hwnd, &m_rect);
  533. }
  534. else
  535. pioo->DoVerb(OLEIVERB_HIDE, NULL, this, 0, m_hwnd, NULL);
  536. pioo->Release();
  537. }
  538. void HTMLContainer::setFocus(BOOL fFocus)
  539. {
  540. if (!m_punk)
  541. return ;
  542. HRESULT hr;
  543. IOleObject *pioo;
  544. if (fFocus)
  545. {
  546. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  547. if (FAILED(hr))
  548. return ;
  549. pioo->DoVerb(OLEIVERB_UIACTIVATE, NULL, this, 0, m_hwnd, &m_rect);
  550. pioo->Release();
  551. }
  552. }
  553. bool HTMLContainer::translateKey(LPMSG pMsg)
  554. {
  555. if (!m_punk)
  556. return false;
  557. HRESULT hr;
  558. IOleInPlaceActiveObject *pao;
  559. hr = m_punk->QueryInterface(IID_IOleInPlaceActiveObject, (PVOID *) & pao);
  560. if (FAILED(hr))
  561. return false;
  562. HRESULT res = pao->TranslateAccelerator(pMsg);
  563. pao->Release();
  564. return res == S_OK;
  565. }
  566. /**************************************************************************
  567. * adContainer::getDispatch()
  568. **************************************************************************/
  569. IDispatch * HTMLContainer::getDispatch()
  570. {
  571. if (!m_punk)
  572. return NULL;
  573. IDispatch *pdisp = NULL;
  574. m_punk->QueryInterface(IID_IDispatch, (PVOID *) & pdisp);
  575. return pdisp;
  576. }
  577. /**************************************************************************
  578. * adContainer::getUnknown()
  579. **************************************************************************/
  580. IUnknown * HTMLContainer::getUnknown()
  581. {
  582. if (!m_punk)
  583. return NULL;
  584. m_punk->AddRef();
  585. return m_punk;
  586. }
  587. // ***********************************************************************
  588. // IDocHostUIHandler
  589. // ***********************************************************************
  590. HRESULT HTMLContainer::ShowContextMenu(DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved)
  591. {
  592. return E_NOTIMPL;
  593. }
  594. HRESULT HTMLContainer::GetHostInfo(DOCHOSTUIINFO __RPC_FAR *pInfo)
  595. {
  596. pInfo->cbSize = sizeof(DOCHOSTUIINFO);
  597. pInfo->dwFlags = dwHostInfoFlags;
  598. if (pszHostCSS)
  599. {
  600. INT strlen;
  601. OLECHAR *pocCSS;
  602. strlen = lstrlenW(pszHostCSS);
  603. if (strlen)
  604. {
  605. strlen++;
  606. pocCSS = (OLECHAR*)CoTaskMemAlloc(strlen * sizeof(OLECHAR));
  607. if (pocCSS && S_OK== StringCchCopyW(pocCSS, strlen, pszHostCSS)) pInfo->pchHostCss = pocCSS;
  608. }
  609. }
  610. return S_OK;
  611. }
  612. HRESULT HTMLContainer::ShowUI(DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc)
  613. {
  614. return E_NOTIMPL;
  615. }
  616. HRESULT HTMLContainer::HideUI(void)
  617. {
  618. return E_NOTIMPL;
  619. }
  620. HRESULT HTMLContainer::UpdateUI(void)
  621. {
  622. return E_NOTIMPL;
  623. }
  624. HRESULT HTMLContainer::OnDocWindowActivate(BOOL fActivate)
  625. {
  626. return E_NOTIMPL;
  627. }
  628. HRESULT HTMLContainer::OnFrameWindowActivate(BOOL fActivate)
  629. {
  630. return E_NOTIMPL;
  631. }
  632. HRESULT HTMLContainer::ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow)
  633. {
  634. return E_NOTIMPL;
  635. }
  636. HRESULT HTMLContainer::TranslateAccelerator(LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID)
  637. {
  638. return E_NOTIMPL;
  639. }
  640. HRESULT HTMLContainer::GetOptionKeyPath(LPOLESTR __RPC_FAR *pchKey, DWORD dw)
  641. {
  642. return E_NOTIMPL;
  643. }
  644. HRESULT HTMLContainer::GetDropTarget(IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)
  645. {
  646. return E_NOTIMPL;
  647. }
  648. HRESULT HTMLContainer::GetExternal(IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
  649. {
  650. return E_NOTIMPL;
  651. }
  652. HRESULT HTMLContainer::TranslateUrl(DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
  653. {
  654. return E_NOTIMPL;
  655. }
  656. HRESULT HTMLContainer::FilterDataObject(IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet)
  657. {
  658. return E_NOTIMPL;
  659. }
  660. BOOL HTMLContainer::SetHostCSS(LPCWSTR pszHostCSS)
  661. {
  662. if (this->pszHostCSS) { free(this->pszHostCSS); this->pszHostCSS = NULL; }
  663. if (pszHostCSS && *pszHostCSS) this->pszHostCSS = _wcsdup(pszHostCSS);
  664. return TRUE;
  665. }
  666. HWND HTMLContainer::GetHostHWND(void)
  667. {
  668. if (m_punk)
  669. {
  670. IOleInPlaceObject *pipo;
  671. m_punk->QueryInterface(IID_IOleInPlaceObject, (PVOID *)&pipo);
  672. if (pipo)
  673. {
  674. HWND hwndHost;
  675. pipo->GetWindow(&hwndHost);
  676. pipo->Release();
  677. return hwndHost;
  678. }
  679. }
  680. return NULL;
  681. }
  682. DWORD HTMLContainer::SetDownloadFlags(DWORD dwFlags)
  683. {
  684. DWORD temp;
  685. temp = dwDownloadFlags;
  686. dwDownloadFlags = dwFlags;
  687. return temp;
  688. }
  689. DWORD HTMLContainer::SetHostInfoFlags(DWORD dwFlags)
  690. {
  691. DWORD temp;
  692. temp = dwHostInfoFlags;
  693. dwHostInfoFlags = dwFlags;
  694. return temp;
  695. }