SWFContainer.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. #include "SWFContainer.h"
  2. #include <strsafe.h>
  3. // ---------------------------------------------------------------
  4. IConnectionPoint *SWFContainer::GetConnectionPoint (REFIID riid)
  5. {
  6. IUnknown *punk = getUnknown ();
  7. if (!punk)
  8. return 0;
  9. IConnectionPointContainer *pcpc;
  10. IConnectionPoint *pcp = 0;
  11. HRESULT hr = punk->QueryInterface (IID_IConnectionPointContainer, (void **) & pcpc);
  12. if (SUCCEEDED (hr))
  13. {
  14. pcpc->FindConnectionPoint (riid, &pcp);
  15. pcpc->Release();
  16. }
  17. punk->Release();
  18. return pcp;
  19. }
  20. void SWFContainer::SyncSizeToWindow(HWND hwnd)
  21. {
  22. RECT rect;
  23. GetClientRect(hwnd, &rect);
  24. int height = (rect.bottom - rect.top);
  25. // if we get a null height then hide the html control (after limiting to 1px)
  26. // and also hide it's parent window - is mainly for ml_wire to prevent display
  27. // glitches when resizing the bottom segment all the way to the bottom
  28. //ShowWindow(m_hwnd,height?SW_SHOWNA:SW_HIDE);
  29. //ShowWindow(hwnd,height?SW_SHOWNA:SW_HIDE);
  30. setLocation(0, 0, rect.right - rect.left, height?height:1);
  31. }
  32. SWFContainer::SWFContainer(HWND hwnd)
  33. : flash (0), m_cRefs(1), m_hwnd(hwnd), m_punk(NULL),
  34. externalInterface(0)
  35. {
  36. bInitialized = (S_OK == CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)) ? true : false;
  37. memset(&m_rect, 0, sizeof(m_rect));
  38. add(ShockwaveFlashObjects::CLSID_ShockwaveFlash);
  39. IUnknown *punk = getUnknown();
  40. if (punk)
  41. {
  42. if (SUCCEEDED(punk->QueryInterface (ShockwaveFlashObjects::IID_IShockwaveFlash, (void **) & flash)))
  43. {
  44. IConnectionPoint *icp = GetConnectionPoint(ShockwaveFlashObjects::DIID__IShockwaveFlashEvents);
  45. if (icp)
  46. {
  47. m_dwCookie = 0;
  48. HRESULT hr = icp->Advise(static_cast<IDispatch *>(this), &m_dwCookie);
  49. icp->Release();
  50. }
  51. }
  52. else
  53. flash=0;
  54. punk->Release();
  55. }
  56. }
  57. SWFContainer::~SWFContainer()
  58. {
  59. close();
  60. if (bInitialized) CoUninitialize();
  61. }
  62. void SWFContainer::close()
  63. {
  64. IOleObject *pioo;
  65. if ( m_punk )
  66. {
  67. HRESULT hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  68. if (SUCCEEDED(hr))
  69. {
  70. pioo->Close(OLECLOSE_NOSAVE);
  71. pioo->Release();
  72. }
  73. }
  74. if (m_punk)
  75. {
  76. m_punk->Release();
  77. m_punk = NULL;
  78. }
  79. if (flash)
  80. {
  81. flash->Stop();
  82. flash->Release();
  83. flash = 0;
  84. }
  85. }
  86. STDMETHODIMP SWFContainer::QueryInterface(REFIID riid, PVOID *ppvObject)
  87. {
  88. if (!ppvObject)
  89. return E_POINTER;
  90. if (IsEqualIID(riid, IID_IOleClientSite))
  91. *ppvObject = (IOleClientSite *)this;
  92. else if (IsEqualIID(riid, IID_IOleInPlaceSite))
  93. *ppvObject = (IOleInPlaceSite *)this;
  94. else if (IsEqualIID(riid, IID_IOleInPlaceFrame))
  95. *ppvObject = (IOleInPlaceFrame *)this;
  96. else if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  97. *ppvObject = (IOleInPlaceUIWindow *)this;
  98. // else if (IsEqualIID(riid, IID_IOleControlSite))
  99. // *ppvObject = (IOleControlSite *)this;
  100. else if (IsEqualIID(riid, IID_IOleWindow))
  101. *ppvObject = this;
  102. else if (IsEqualIID(riid, IID_IDispatch))
  103. *ppvObject = (IDispatch *)this;
  104. else if (IsEqualIID(riid, IID_IUnknown))
  105. *ppvObject = this;
  106. else if (IsEqualIID(riid, __uuidof(ShockwaveFlashObjects::_IShockwaveFlashEvents)))
  107. *ppvObject = (IDispatch *)this;
  108. else
  109. {
  110. *ppvObject = NULL;
  111. return E_NOINTERFACE;
  112. }
  113. AddRef();
  114. return S_OK;
  115. }
  116. ULONG SWFContainer::AddRef(void)
  117. {
  118. return ++m_cRefs;
  119. }
  120. ULONG SWFContainer::Release(void)
  121. {
  122. if (--m_cRefs)
  123. return m_cRefs;
  124. // PostQuitMessage(0);
  125. delete this;
  126. return 0;
  127. }
  128. HRESULT SWFContainer::SaveObject()
  129. {
  130. return E_NOTIMPL;
  131. }
  132. HRESULT SWFContainer::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER * ppMk)
  133. {
  134. return E_NOTIMPL;
  135. }
  136. HRESULT SWFContainer::GetContainer(LPOLECONTAINER * ppContainer)
  137. {
  138. return E_NOINTERFACE;
  139. }
  140. HRESULT SWFContainer::ShowObject()
  141. {
  142. return S_OK;
  143. }
  144. HRESULT SWFContainer::OnShowWindow(BOOL fShow)
  145. {
  146. return S_OK;
  147. }
  148. HRESULT SWFContainer::RequestNewObjectLayout()
  149. {
  150. return E_NOTIMPL;
  151. }
  152. HRESULT SWFContainer::GetWindow(HWND * lphwnd)
  153. {
  154. if (!IsWindow(m_hwnd))
  155. return S_FALSE;
  156. *lphwnd = m_hwnd;
  157. return S_OK;
  158. }
  159. HRESULT SWFContainer::ContextSensitiveHelp(BOOL fEnterMode)
  160. {
  161. return E_NOTIMPL;
  162. }
  163. HRESULT SWFContainer::CanInPlaceActivate(void)
  164. {
  165. return S_OK;
  166. }
  167. HRESULT SWFContainer::OnInPlaceActivate(void)
  168. {
  169. return S_OK;
  170. }
  171. HRESULT SWFContainer::OnUIActivate(void)
  172. {
  173. return S_OK;
  174. }
  175. HRESULT SWFContainer::GetWindowContext(IOleInPlaceFrame ** ppFrame, IOleInPlaceUIWindow ** ppIIPUIWin,
  176. LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  177. {
  178. *ppFrame = (IOleInPlaceFrame *)this;
  179. *ppIIPUIWin = NULL;
  180. RECT rect;
  181. GetClientRect(m_hwnd, &rect);
  182. lprcPosRect->left = 0;
  183. lprcPosRect->top = 0;
  184. lprcPosRect->right = rect.right;
  185. lprcPosRect->bottom = rect.bottom;
  186. CopyRect(lprcClipRect, lprcPosRect);
  187. lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
  188. lpFrameInfo->fMDIApp = FALSE;
  189. lpFrameInfo->hwndFrame = m_hwnd;
  190. lpFrameInfo->haccel = 0;
  191. lpFrameInfo->cAccelEntries = 0;
  192. (*ppFrame)->AddRef();
  193. return S_OK;
  194. }
  195. HRESULT SWFContainer::Scroll(SIZE scrollExtent)
  196. {
  197. return E_NOTIMPL;
  198. }
  199. HRESULT SWFContainer::OnUIDeactivate(BOOL fUndoable)
  200. {
  201. return E_NOTIMPL;
  202. }
  203. HRESULT SWFContainer::OnInPlaceDeactivate(void)
  204. {
  205. return S_OK;
  206. }
  207. HRESULT SWFContainer::DiscardUndoState(void)
  208. {
  209. return E_NOTIMPL;
  210. }
  211. HRESULT SWFContainer::DeactivateAndUndo(void)
  212. {
  213. return E_NOTIMPL;
  214. }
  215. HRESULT SWFContainer::OnPosRectChange(LPCRECT lprcPosRect)
  216. {
  217. return S_OK;
  218. }
  219. HRESULT SWFContainer::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
  220. {
  221. return E_NOTIMPL;
  222. }
  223. HRESULT SWFContainer::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  224. {
  225. return E_NOTIMPL;
  226. }
  227. HRESULT SWFContainer::RemoveMenus(HMENU hmenuShared)
  228. {
  229. return E_NOTIMPL;
  230. }
  231. HRESULT SWFContainer::SetStatusText(LPCOLESTR pszStatusText)
  232. {
  233. return S_OK;
  234. }
  235. HRESULT SWFContainer::TranslateAccelerator(LPMSG lpmsg, WORD wID)
  236. {
  237. return S_OK;
  238. }
  239. HRESULT SWFContainer::EnableModeless(BOOL fEnable)
  240. {
  241. return E_NOTIMPL;
  242. }
  243. HRESULT SWFContainer::OnControlInfoChanged()
  244. {
  245. return E_NOTIMPL;
  246. }
  247. HRESULT SWFContainer::LockInPlaceActive(BOOL fLock)
  248. {
  249. return E_NOTIMPL;
  250. }
  251. HRESULT SWFContainer::GetExtendedControl(IDispatch **ppDisp)
  252. {
  253. if (ppDisp == NULL)
  254. return E_INVALIDARG;
  255. *ppDisp = (IDispatch *)this;
  256. (*ppDisp)->AddRef();
  257. return S_OK;
  258. }
  259. HRESULT SWFContainer::TransformCoords(POINTL *pptlHimetric, POINTF *pptfContainer, DWORD dwFlags)
  260. {
  261. return E_NOTIMPL;
  262. }
  263. HRESULT SWFContainer::TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers)
  264. {
  265. return S_FALSE;
  266. }
  267. HRESULT SWFContainer::OnFocus(BOOL fGotFocus)
  268. {
  269. return E_NOTIMPL;
  270. }
  271. HRESULT SWFContainer::ShowPropertyFrame(void)
  272. {
  273. return E_NOTIMPL;
  274. }
  275. HRESULT SWFContainer::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  276. {
  277. *rgdispid = DISPID_UNKNOWN;
  278. return DISP_E_UNKNOWNNAME;
  279. }
  280. HRESULT SWFContainer::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  281. {
  282. return E_NOTIMPL;
  283. }
  284. HRESULT SWFContainer::GetTypeInfoCount(unsigned int FAR * pctinfo)
  285. {
  286. return E_NOTIMPL;
  287. }
  288. #define GET_SAFE_DISP_BSTR(_val) ((_val.pvarVal && VT_BSTR == _val.pvarVal->vt) ? _val.pvarVal->bstrVal : NULL)
  289. #define GET_SAFE_DISP_I4(_val) ((_val.pvarVal && VT_I4 == _val.pvarVal->vt) ? _val.pvarVal->intVal : 0)
  290. void SWFContainer::add(CLSID clsid)
  291. {
  292. HRESULT hr; // return code
  293. CoCreateInstance(clsid,
  294. NULL,
  295. CLSCTX_INPROC_SERVER/* | CLSCTX_LOCAL_SERVER*/,
  296. IID_IUnknown,
  297. (PVOID *)&m_punk);
  298. if (!m_punk)
  299. return ;
  300. IOleObject *pioo;
  301. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  302. if (FAILED(hr))
  303. return ;
  304. pioo->SetClientSite(this);
  305. pioo->Release();
  306. IPersistStreamInit *ppsi;
  307. hr = m_punk->QueryInterface(IID_IPersistStreamInit, (PVOID *) & ppsi);
  308. if (SUCCEEDED(hr))
  309. {
  310. ppsi->InitNew();
  311. ppsi->Release();
  312. }
  313. }
  314. void SWFContainer::remove()
  315. {
  316. if (!m_punk)
  317. return ;
  318. HRESULT hr;
  319. IOleObject *pioo;
  320. IOleInPlaceObject *pipo;
  321. /*
  322. benski> enabling this makes everything lock up!
  323. IConnectionPoint *icp = GetConnectionPoint(DIID_DWebBrowserEvents2);
  324. if (icp)
  325. {
  326. // m_dwCookie = 0;
  327. HRESULT hr = icp->Unadvise(m_dwCookie);
  328. icp->Release();
  329. }
  330. */
  331. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  332. if (SUCCEEDED(hr))
  333. {
  334. pioo->Close(OLECLOSE_NOSAVE);
  335. pioo->SetClientSite(NULL);
  336. pioo->Release();
  337. }
  338. hr = m_punk->QueryInterface(IID_IOleInPlaceObject, (PVOID *) & pipo);
  339. if (SUCCEEDED(hr))
  340. {
  341. pipo->UIDeactivate();
  342. pipo->InPlaceDeactivate();
  343. pipo->Release();
  344. }
  345. m_punk->Release();
  346. m_punk = NULL;
  347. }
  348. void SWFContainer::setLocation(int x, int y, int width, int height)
  349. {
  350. m_rect.left = x;
  351. m_rect.top = y;
  352. m_rect.right = x + width;
  353. m_rect.bottom = y + height;
  354. if (!m_punk)
  355. return ;
  356. HRESULT hr;
  357. IOleInPlaceObject *pipo;
  358. hr = m_punk->QueryInterface(IID_IOleInPlaceObject, (PVOID *) & pipo);
  359. if (FAILED(hr))
  360. return ;
  361. pipo->SetObjectRects(&m_rect, &m_rect);
  362. pipo->Release();
  363. }
  364. HRESULT SWFContainer::GetBorder(LPRECT lprectBorder)
  365. {
  366. return E_NOTIMPL;
  367. }
  368. HRESULT SWFContainer::RequestBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  369. {
  370. return E_NOTIMPL;
  371. }
  372. HRESULT SWFContainer::SetBorderSpace(LPCBORDERWIDTHS lpborderwidths)
  373. {
  374. return E_NOTIMPL;
  375. }
  376. HRESULT SWFContainer::SetActiveObject(IOleInPlaceActiveObject * pActiveObject, LPCOLESTR lpszObjName)
  377. {
  378. return E_NOTIMPL;
  379. }
  380. void SWFContainer::setVisible(BOOL fVisible)
  381. {
  382. if (!m_punk)
  383. return ;
  384. HRESULT hr;
  385. IOleObject *pioo;
  386. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  387. if (FAILED(hr))
  388. return ;
  389. if (fVisible)
  390. {
  391. pioo->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, this, 0, m_hwnd, &m_rect);
  392. pioo->DoVerb(OLEIVERB_SHOW, NULL, this, 0, m_hwnd, &m_rect);
  393. }
  394. else
  395. pioo->DoVerb(OLEIVERB_HIDE, NULL, this, 0, m_hwnd, NULL);
  396. pioo->Release();
  397. }
  398. void SWFContainer::setFocus(BOOL fFocus)
  399. {
  400. if (!m_punk)
  401. return ;
  402. HRESULT hr;
  403. IOleObject *pioo;
  404. if (fFocus)
  405. {
  406. hr = m_punk->QueryInterface(IID_IOleObject, (PVOID *) & pioo);
  407. if (FAILED(hr))
  408. return ;
  409. pioo->DoVerb(OLEIVERB_UIACTIVATE, NULL, this, 0, m_hwnd, &m_rect);
  410. pioo->Release();
  411. }
  412. }
  413. bool SWFContainer::translateKey(LPMSG pMsg)
  414. {
  415. if (!m_punk)
  416. return false;
  417. HRESULT hr;
  418. IOleInPlaceActiveObject *pao;
  419. hr = m_punk->QueryInterface(IID_IOleInPlaceActiveObject, (PVOID *) & pao);
  420. if (FAILED(hr))
  421. return false;
  422. HRESULT res = pao->TranslateAccelerator(pMsg);
  423. pao->Release();
  424. return res == S_OK;
  425. }
  426. enum
  427. {
  428. FLASH_DISPID_EXTERNALINTERFACE_CALL = 197,
  429. };
  430. HRESULT SWFContainer::Invoke(
  431. /* [in] */ DISPID dispIdMember,
  432. /* [in] */ REFIID riid,
  433. /* [in] */ LCID lcid,
  434. /* [in] */ WORD wFlags,
  435. /* [out][in] */ DISPPARAMS *pDispParams,
  436. /* [out] */ VARIANT *pVarResult,
  437. /* [out] */ EXCEPINFO *pExcepInfo,
  438. /* [out] */ UINT *puArgErr)
  439. {
  440. switch (dispIdMember)
  441. {
  442. case 0x000007a6 : // OnProgress
  443. break;
  444. case 0x00000096 : // FSCommand
  445. break;
  446. case FLASH_DISPID_EXTERNALINTERFACE_CALL : // ExternalInterface.call()
  447. {
  448. if (externalInterface)
  449. externalInterface->ExternalInterface_call(pDispParams->rgvarg[0].bstrVal);
  450. }
  451. break;
  452. }
  453. return DISP_E_MEMBERNOTFOUND;
  454. }
  455. /**************************************************************************
  456. * adContainer::getUnknown()
  457. **************************************************************************/
  458. IUnknown * SWFContainer::getUnknown()
  459. {
  460. if (!m_punk)
  461. return NULL;
  462. m_punk->AddRef();
  463. return m_punk;
  464. }