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.

1179 lines
32 KiB

  1. /*********************************************************************************
  2. DocHost.c
  3. - This file contains the code for implementing a DOC Object COntainer
  4. which we will use to host trident
  5. Copyright 1992 - 1996 Microsoft Corporation. All Rights Reserved.
  6. Revision History:
  7. When Who What
  8. -------- ------------------ ---------------------------------------
  9. 04/22/97 Vikram Madan Ported from athenas dochost code
  10. ***********************************************************************************/
  11. #include <_apipch.h>
  12. LPTSTR c_szWABDocHostWndClass = TEXT("WAB_DocHost");
  13. LPCREATEURLMONIKER lpfnCreateURLMoniker = NULL;
  14. BOOL fTridentCoinit = FALSE;
  15. //
  16. // Function Prototypes
  17. //
  18. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  19. void WMSize(LPIWABDOCHOST lpIWABDocHost, int x, int y);
  20. HRESULT HrCreateDocObj(LPIWABDOCHOST lpIWABDocHost, LPCLSID pCLSID);
  21. HRESULT HrShow(LPIWABDOCHOST lpIWABDocHost);
  22. HRESULT HrCloseDocObj(LPIWABDOCHOST lpIWABDocHost);
  23. HRESULT HrDocHost_Init(LPIWABDOCHOST lpIWABDocHost, BOOL fInit);
  24. HRESULT HrCreateDocView(LPIWABDOCHOST lpIWABDocHost, LPOLEDOCUMENTVIEW pViewToActivate);
  25. HRESULT HrLoadTheURL(LPIWABDOCHOST lpWABDH, LPTSTR pszURL);
  26. HRESULT HrLoadFromMoniker(LPIWABDOCHOST lpIWABDocHost, LPMONIKER pmk);
  27. //
  28. // IWABDocHost jump tables is defined here...
  29. //
  30. IWABDOCHOST_Vtbl vtblIWABDOCHOST = {
  31. VTABLE_FILL
  32. IWABDOCHOST_QueryInterface,
  33. IWABDOCHOST_AddRef,
  34. IWABDOCHOST_Release,
  35. };
  36. IWDH_OLEWINDOW_Vtbl vtblIWDH_OLEWINDOW = {
  37. VTABLE_FILL
  38. (IWDH_OLEWINDOW_QueryInterface_METHOD *) IWABDOCHOST_QueryInterface,
  39. (IWDH_OLEWINDOW_AddRef_METHOD *) IWABDOCHOST_AddRef,
  40. (IWDH_OLEWINDOW_Release_METHOD *) IWABDOCHOST_Release,
  41. IWDH_OLEWINDOW_GetWindow,
  42. IWDH_OLEWINDOW_ContextSensitiveHelp,
  43. };
  44. IWDH_OLEINPLACEFRAME_Vtbl vtblIWDH_OLEINPLACEFRAME = {
  45. VTABLE_FILL
  46. (IWDH_OLEINPLACEFRAME_QueryInterface_METHOD *) IWABDOCHOST_QueryInterface,
  47. (IWDH_OLEINPLACEFRAME_AddRef_METHOD *) IWABDOCHOST_AddRef,
  48. (IWDH_OLEINPLACEFRAME_Release_METHOD *) IWABDOCHOST_Release,
  49. (IWDH_OLEINPLACEFRAME_GetWindow_METHOD *) IWDH_OLEWINDOW_GetWindow,
  50. (IWDH_OLEINPLACEFRAME_ContextSensitiveHelp_METHOD *) IWDH_OLEWINDOW_ContextSensitiveHelp,
  51. IWDH_OLEINPLACEFRAME_GetBorder,
  52. IWDH_OLEINPLACEFRAME_RequestBorderSpace,
  53. IWDH_OLEINPLACEFRAME_SetBorderSpace,
  54. IWDH_OLEINPLACEFRAME_SetActiveObject,
  55. IWDH_OLEINPLACEFRAME_InsertMenus,
  56. IWDH_OLEINPLACEFRAME_SetMenu,
  57. IWDH_OLEINPLACEFRAME_RemoveMenus,
  58. IWDH_OLEINPLACEFRAME_SetStatusText,
  59. IWDH_OLEINPLACEFRAME_EnableModeless,
  60. IWDH_OLEINPLACEFRAME_TranslateAccelerator,
  61. };
  62. IWDH_OLEINPLACESITE_Vtbl vtblIWDH_OLEINPLACESITE = {
  63. VTABLE_FILL
  64. (IWDH_OLEINPLACESITE_QueryInterface_METHOD *) IWABDOCHOST_QueryInterface,
  65. (IWDH_OLEINPLACESITE_AddRef_METHOD *) IWABDOCHOST_AddRef,
  66. (IWDH_OLEINPLACESITE_Release_METHOD *) IWABDOCHOST_Release,
  67. (IWDH_OLEINPLACESITE_GetWindow_METHOD *) IWDH_OLEWINDOW_GetWindow,
  68. (IWDH_OLEINPLACESITE_ContextSensitiveHelp_METHOD *) IWDH_OLEWINDOW_ContextSensitiveHelp,
  69. IWDH_OLEINPLACESITE_CanInPlaceActivate,
  70. IWDH_OLEINPLACESITE_OnInPlaceActivate,
  71. IWDH_OLEINPLACESITE_OnUIActivate,
  72. IWDH_OLEINPLACESITE_GetWindowContext,
  73. IWDH_OLEINPLACESITE_Scroll,
  74. IWDH_OLEINPLACESITE_OnUIDeactivate,
  75. IWDH_OLEINPLACESITE_OnInPlaceDeactivate,
  76. IWDH_OLEINPLACESITE_DiscardUndoState,
  77. IWDH_OLEINPLACESITE_DeactivateAndUndo,
  78. IWDH_OLEINPLACESITE_OnPosRectChange,
  79. };
  80. IWDH_OLECLIENTSITE_Vtbl vtblIWDH_OLECLIENTSITE = {
  81. VTABLE_FILL
  82. (IWDH_OLECLIENTSITE_QueryInterface_METHOD *) IWABDOCHOST_QueryInterface,
  83. (IWDH_OLECLIENTSITE_AddRef_METHOD *) IWABDOCHOST_AddRef,
  84. (IWDH_OLECLIENTSITE_Release_METHOD *) IWABDOCHOST_Release,
  85. IWDH_OLECLIENTSITE_SaveObject,
  86. IWDH_OLECLIENTSITE_GetMoniker,
  87. IWDH_OLECLIENTSITE_GetContainer,
  88. IWDH_OLECLIENTSITE_ShowObject,
  89. IWDH_OLECLIENTSITE_OnShowWindow,
  90. IWDH_OLECLIENTSITE_RequestNewObjectLayout,
  91. };
  92. IWDH_OLEDOCUMENTSITE_Vtbl vtblIWDH_OLEDOCUMENTSITE = {
  93. VTABLE_FILL
  94. (IWDH_OLEDOCUMENTSITE_QueryInterface_METHOD *) IWABDOCHOST_QueryInterface,
  95. (IWDH_OLEDOCUMENTSITE_AddRef_METHOD *) IWABDOCHOST_AddRef,
  96. (IWDH_OLEDOCUMENTSITE_Release_METHOD *) IWABDOCHOST_Release,
  97. IWDH_OLEDOCUMENTSITE_ActivateMe,
  98. };
  99. //
  100. // Interfaces supported by this object
  101. //
  102. #define WABDH_cInterfaces 6
  103. LPIID WABDH_LPIID[WABDH_cInterfaces] =
  104. {
  105. (LPIID) &IID_IUnknown,
  106. (LPIID) &IID_IOleWindow,
  107. (LPIID) &IID_IOleInPlaceFrame,
  108. (LPIID) &IID_IOleInPlaceSite,
  109. (LPIID) &IID_IOleClientSite,
  110. (LPIID) &IID_IOleDocumentSite,
  111. };
  112. //$$
  113. void UninitTrident()
  114. {
  115. if(fTridentCoinit)
  116. {
  117. CoUninitialize();
  118. fTridentCoinit = FALSE;
  119. }
  120. }
  121. //$$//////////////////////////////////////////////////////////////////////////
  122. //
  123. // Release memory related to the IWABDocHost pointer
  124. //
  125. //////////////////////////////////////////////////////////////////////////////
  126. void ReleaseDocHostObject(LPIWABDOCHOST lpIWABDocHost)
  127. {
  128. HrCloseDocObj(lpIWABDocHost);
  129. SafeRelease(lpIWABDocHost->m_lpOleObj);
  130. SafeRelease(lpIWABDocHost->m_pDocView);
  131. SafeRelease(lpIWABDocHost->m_pInPlaceActiveObj);
  132. HrDocHost_Init(lpIWABDocHost, FALSE);
  133. DebugTrace(TEXT("IID_IWABDocHost refCount: %d\n"),lpIWABDocHost->lcInit);
  134. DebugTrace(TEXT("IID_IOleWindow refCount: %d\n"),lpIWABDocHost->lpIWDH_OleWindow->lcInit);
  135. DebugTrace(TEXT("IID_IOleInPlaceFrame refCount: %d\n"),lpIWABDocHost->lpIWDH_OleInPlaceFrame->lcInit);
  136. DebugTrace(TEXT("IID_IOleInPlaceSite refCount: %d\n"),lpIWABDocHost->lpIWDH_OleInPlaceSite->lcInit);
  137. DebugTrace(TEXT("IID_IOleClientSite refCount: %d\n"),lpIWABDocHost->lpIWDH_OleClientSite->lcInit);
  138. DebugTrace(TEXT("IID_IOleDocumentSite refCount: %d\n"),lpIWABDocHost->lpIWDH_OleDocumentSite->lcInit);
  139. MAPIFreeBuffer(lpIWABDocHost);
  140. return;
  141. }
  142. //$$//////////////////////////////////////////////////////////////////////////
  143. //
  144. // Creates a New IWABDocHost Object
  145. //
  146. //////////////////////////////////////////////////////////////////////////////
  147. HRESULT HrNewWABDocHostObject(LPVOID * lppIWABDocHost)
  148. {
  149. LPIWABDOCHOST lpIWABDocHost = NULL;
  150. SCODE sc;
  151. HRESULT hr = hrSuccess;
  152. //
  153. // Allocate space for the IAB structure
  154. //
  155. if (FAILED(sc = MAPIAllocateBuffer(sizeof(IWABDOCHOST), (LPVOID *) &lpIWABDocHost))) {
  156. hr = ResultFromScode(sc);
  157. goto err;
  158. }
  159. MAPISetBufferName(lpIWABDocHost, TEXT("WAB Doc Host Object"));
  160. ZeroMemory(lpIWABDocHost, sizeof(IWABDOCHOST));
  161. lpIWABDocHost->lpVtbl = &vtblIWABDOCHOST;
  162. lpIWABDocHost->cIID = WABDH_cInterfaces;
  163. lpIWABDocHost->rglpIID = WABDH_LPIID;
  164. InitializeCriticalSection(&lpIWABDocHost->cs);
  165. lpIWABDocHost->lpIWDH = lpIWABDocHost;
  166. sc = MAPIAllocateMore(sizeof(IWABDOCHOST_OLEWINDOW), lpIWABDocHost, &(lpIWABDocHost->lpIWDH_OleWindow));
  167. if(sc)
  168. goto err;
  169. ZeroMemory(lpIWABDocHost->lpIWDH_OleWindow, sizeof(IWABDOCHOST_OLEWINDOW));
  170. lpIWABDocHost->lpIWDH_OleWindow->lpVtbl = &vtblIWDH_OLEWINDOW;
  171. lpIWABDocHost->lpIWDH_OleWindow->lpIWDH = lpIWABDocHost;
  172. sc = MAPIAllocateMore(sizeof(IWABDOCHOST_OLEINPLACEFRAME), lpIWABDocHost, &(lpIWABDocHost->lpIWDH_OleInPlaceFrame));
  173. if(sc)
  174. goto err;
  175. ZeroMemory(lpIWABDocHost->lpIWDH_OleInPlaceFrame, sizeof(IWABDOCHOST_OLEINPLACEFRAME));
  176. lpIWABDocHost->lpIWDH_OleInPlaceFrame->lpVtbl = &vtblIWDH_OLEINPLACEFRAME;
  177. lpIWABDocHost->lpIWDH_OleInPlaceFrame->lpIWDH = lpIWABDocHost;
  178. sc = MAPIAllocateMore(sizeof(IWABDOCHOST_OLEINPLACESITE), lpIWABDocHost, &(lpIWABDocHost->lpIWDH_OleInPlaceSite));
  179. if(sc)
  180. goto err;
  181. ZeroMemory(lpIWABDocHost->lpIWDH_OleInPlaceSite, sizeof(IWABDOCHOST_OLEINPLACESITE));
  182. lpIWABDocHost->lpIWDH_OleInPlaceSite->lpVtbl = &vtblIWDH_OLEINPLACESITE;
  183. lpIWABDocHost->lpIWDH_OleInPlaceSite->lpIWDH = lpIWABDocHost;
  184. sc = MAPIAllocateMore(sizeof(IWABDOCHOST_OLECLIENTSITE), lpIWABDocHost, &(lpIWABDocHost->lpIWDH_OleClientSite));
  185. if(sc)
  186. goto err;
  187. ZeroMemory(lpIWABDocHost->lpIWDH_OleClientSite, sizeof(IWABDOCHOST_OLECLIENTSITE));
  188. lpIWABDocHost->lpIWDH_OleClientSite->lpVtbl = &vtblIWDH_OLECLIENTSITE;
  189. lpIWABDocHost->lpIWDH_OleClientSite->lpIWDH = lpIWABDocHost;
  190. sc = MAPIAllocateMore(sizeof(IWABDOCHOST_OLEDOCUMENTSITE), lpIWABDocHost, &(lpIWABDocHost->lpIWDH_OleDocumentSite));
  191. if(sc)
  192. goto err;
  193. ZeroMemory(lpIWABDocHost->lpIWDH_OleDocumentSite, sizeof(IWABDOCHOST_OLEDOCUMENTSITE));
  194. lpIWABDocHost->lpIWDH_OleDocumentSite->lpVtbl = &vtblIWDH_OLEDOCUMENTSITE;
  195. lpIWABDocHost->lpIWDH_OleDocumentSite->lpIWDH = lpIWABDocHost;
  196. lpIWABDocHost->lpVtbl->AddRef(lpIWABDocHost);
  197. *lppIWABDocHost = (LPVOID)lpIWABDocHost;
  198. return(hrSuccess);
  199. err:
  200. FreeBufferAndNull(&lpIWABDocHost);
  201. return(hr);
  202. }
  203. /**
  204. *
  205. * The Interface methods
  206. *
  207. *
  208. ***/
  209. STDMETHODIMP_(ULONG)
  210. IWABDOCHOST_AddRef(LPIWABDOCHOST lpIWABDocHost)
  211. {
  212. //DebugTrace(TEXT(">>>>>AddRef: %x\trefCount: %d->%d\n"),lpIWABDocHost,lpIWABDocHost->lcInit,lpIWABDocHost->lcInit+1);
  213. return(++(lpIWABDocHost->lcInit));
  214. }
  215. STDMETHODIMP_(ULONG)
  216. IWABDOCHOST_Release(LPIWABDOCHOST lpIWABDocHost)
  217. {
  218. //DebugTrace(TEXT("<<<<<Release: %x\trefCount: %d->%d\n"),lpIWABDocHost,lpIWABDocHost->lcInit,lpIWABDocHost->lcInit-1);
  219. if(--(lpIWABDocHost->lcInit)==0 &&
  220. (lpIWABDocHost == lpIWABDocHost->lpIWDH))
  221. {
  222. ReleaseDocHostObject(lpIWABDocHost);
  223. return (0);
  224. }
  225. return(lpIWABDocHost->lcInit);
  226. }
  227. STDMETHODIMP
  228. IWABDOCHOST_QueryInterface(LPIWABDOCHOST lpIWABDocHost,
  229. REFIID lpiid,
  230. LPVOID * lppNewObj)
  231. {
  232. LPVOID lp = NULL;
  233. if(!lppNewObj)
  234. return MAPI_E_INVALID_PARAMETER;
  235. *lppNewObj = NULL;
  236. if(IsEqualIID(lpiid, &IID_IUnknown))
  237. lp = (LPVOID) lpIWABDocHost->lpIWDH;
  238. if(IsEqualIID(lpiid, &IID_IOleWindow))
  239. {
  240. DebugTrace(TEXT("WABDocHost:QI - IOleWindow\n"));
  241. lp = (LPVOID) (LPOLEWINDOW) lpIWABDocHost->lpIWDH->lpIWDH_OleWindow;
  242. }
  243. if(IsEqualIID(lpiid, &IID_IOleInPlaceUIWindow))
  244. {
  245. DebugTrace(TEXT("WABDocHost:QI - IOleInPlaceUIWindow\n"));
  246. lp = (LPVOID) (LPOLEINPLACEUIWINDOW) lpIWABDocHost->lpIWDH->lpIWDH_OleInPlaceFrame;
  247. }
  248. if(IsEqualIID(lpiid, &IID_IOleInPlaceFrame))
  249. {
  250. DebugTrace(TEXT("WABDocHost:QI - IOleInPlaceFrame\n"));
  251. lp = (LPVOID) (LPOLEINPLACEFRAME) lpIWABDocHost->lpIWDH->lpIWDH_OleInPlaceFrame;
  252. }
  253. if(IsEqualIID(lpiid, &IID_IOleInPlaceSite))
  254. {
  255. DebugTrace(TEXT("WABDocHost:QI - IOleInPlaceSite\n"));
  256. lp = (LPVOID) (LPOLEINPLACESITE) lpIWABDocHost->lpIWDH->lpIWDH_OleInPlaceSite;
  257. }
  258. if(IsEqualIID(lpiid, &IID_IOleClientSite))
  259. {
  260. DebugTrace(TEXT("WABDocHost:QI - IOleClientSite\n"));
  261. lp = (LPVOID) (LPOLECLIENTSITE) lpIWABDocHost->lpIWDH->lpIWDH_OleClientSite;
  262. }
  263. if(IsEqualIID(lpiid, &IID_IOleDocumentSite))
  264. {
  265. DebugTrace(TEXT("WABDocHost:QI - IOleDocumentSite\n"));
  266. lp = (LPVOID) (LPOLEDOCUMENTSITE) lpIWABDocHost->lpIWDH->lpIWDH_OleDocumentSite;
  267. }
  268. if(!lp)
  269. {
  270. return E_NOINTERFACE;
  271. }
  272. ((LPIWABDOCHOST) lp)->lpVtbl->AddRef((LPIWABDOCHOST) lp);
  273. *lppNewObj = lp;
  274. return S_OK;
  275. }
  276. /***
  277. *
  278. *
  279. * IOleWindowMethods
  280. *
  281. *
  282. ****/
  283. STDMETHODIMP
  284. IWDH_OLEWINDOW_GetWindow(LPIWABDOCHOST_OLEWINDOW lpIWABDocHost,
  285. HWND * phWnd)
  286. {
  287. DebugTrace(TEXT("IOleWindowMethod: GetWindow\n"));
  288. if(phWnd)
  289. {
  290. *phWnd = lpIWABDocHost->lpIWDH->m_hwnd;
  291. }
  292. return S_OK;
  293. }
  294. STDMETHODIMP
  295. IWDH_OLEWINDOW_ContextSensitiveHelp(LPIWABDOCHOST_OLEWINDOW lpWABDH,
  296. BOOL fEnterMode)
  297. {
  298. DebugTrace(TEXT("IOleWindowMethod: ContextSensitiveHelp\n"));
  299. return E_NOTIMPL;
  300. }
  301. /***
  302. *
  303. *
  304. * IOleInPlaceUIWindow methods
  305. *
  306. *
  307. ***/
  308. STDMETHODIMP
  309. IWDH_OLEINPLACEFRAME_GetBorder(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  310. LPRECT lprc)
  311. {
  312. DebugTrace(TEXT("IOleInPlaceFrame: GetBorder\n"));
  313. return E_NOTIMPL;
  314. }
  315. STDMETHODIMP
  316. IWDH_OLEINPLACEFRAME_RequestBorderSpace(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  317. LPCBORDERWIDTHS pborderwidths)
  318. {
  319. DebugTrace(TEXT("IOleInPlaceFrame: RequestBorderSpace\n"));
  320. return S_OK;
  321. }
  322. STDMETHODIMP
  323. IWDH_OLEINPLACEFRAME_SetBorderSpace(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  324. LPCBORDERWIDTHS pborderwidths)
  325. {
  326. DebugTrace(TEXT("IOleInPlaceFrame: SetBorderSpace\n"));
  327. return S_OK;
  328. }
  329. STDMETHODIMP
  330. IWDH_OLEINPLACEFRAME_SetActiveObject(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  331. IOleInPlaceActiveObject * pActiveObject,
  332. LPCOLESTR lpszObjName)
  333. {
  334. DebugTrace(TEXT("IOleInPlaceFrame: SetActiveObject\n"));
  335. SafeRelease(lpWABDH->lpIWDH->m_pInPlaceActiveObj);
  336. lpWABDH->lpIWDH->m_pInPlaceActiveObj = pActiveObject;
  337. if(lpWABDH->lpIWDH->m_pInPlaceActiveObj)
  338. lpWABDH->lpIWDH->m_pInPlaceActiveObj->lpVtbl->AddRef(lpWABDH->lpIWDH->m_pInPlaceActiveObj);
  339. return S_OK;
  340. }
  341. /***
  342. *
  343. *
  344. * IOleInPlaceFrame Methods
  345. *
  346. *
  347. *
  348. ***/
  349. STDMETHODIMP
  350. IWDH_OLEINPLACEFRAME_InsertMenus(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  351. HMENU hMenu,
  352. LPOLEMENUGROUPWIDTHS lpMenuWidths)
  353. {
  354. DebugTrace(TEXT("IOleInPlaceFrame: InsertMenus\n"));
  355. return S_OK;
  356. }
  357. STDMETHODIMP
  358. IWDH_OLEINPLACEFRAME_SetMenu(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  359. HMENU hMenu,
  360. HOLEMENU hOleMenu,
  361. HWND hWnd)
  362. {
  363. DebugTrace(TEXT("IOleInPlaceFrame: SetMenu\n"));
  364. return S_OK;
  365. }
  366. STDMETHODIMP
  367. IWDH_OLEINPLACEFRAME_RemoveMenus(LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  368. HMENU hMenu)
  369. {
  370. DebugTrace(TEXT("IOleInPlaceFrame: RemoveMenus\n"));
  371. return S_OK;
  372. }
  373. STDMETHODIMP
  374. IWDH_OLEINPLACEFRAME_SetStatusText( LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  375. LPCOLESTR pszStatusText)
  376. {
  377. DebugTrace(TEXT("IOleInPlaceFrame: SetStatusText\n"));
  378. return S_OK;
  379. }
  380. STDMETHODIMP
  381. IWDH_OLEINPLACEFRAME_EnableModeless( LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  382. BOOL fEnable)
  383. {
  384. DebugTrace(TEXT("IOleInPlaceFrame: EnableModeless\n"));
  385. return E_NOTIMPL;
  386. }
  387. STDMETHODIMP
  388. IWDH_OLEINPLACEFRAME_TranslateAccelerator( LPIWABDOCHOST_OLEINPLACEFRAME lpWABDH,
  389. MSG * lpmsg,
  390. WORD wID)
  391. {
  392. DebugTrace(TEXT("IOleInPlaceFrame: TranslateAccelerator\n"));
  393. return E_NOTIMPL;
  394. }
  395. /***
  396. *
  397. *
  398. *
  399. * IOleInPlaceSite methods
  400. *
  401. *
  402. ***/
  403. STDMETHODIMP
  404. IWDH_OLEINPLACESITE_CanInPlaceActivate( LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  405. {
  406. DebugTrace(TEXT("IOleInPlaceSite: CanInPlaceActivate\n"));
  407. return S_OK;
  408. }
  409. STDMETHODIMP
  410. IWDH_OLEINPLACESITE_OnInPlaceActivate( LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  411. {
  412. LPOLEINPLACEOBJECT pInPlaceObj = 0;
  413. DebugTrace(TEXT("IOleInPlaceSite: OnInPlaceActivate\n"));
  414. /**/
  415. lpWABDH->lpIWDH->m_lpOleObj->lpVtbl->QueryInterface( lpWABDH->lpIWDH->m_lpOleObj,
  416. &IID_IOleInPlaceObject,
  417. (LPVOID *) &pInPlaceObj);
  418. lpWABDH->lpIWDH->m_pIPObj = pInPlaceObj;
  419. if(pInPlaceObj)
  420. {
  421. pInPlaceObj->lpVtbl->GetWindow(pInPlaceObj,
  422. &(lpWABDH->lpIWDH->m_hwndDocObj));
  423. Assert(IsWindow(lpWABDH->lpIWDH->m_hwndDocObj));
  424. }
  425. /**/
  426. return S_OK;
  427. }
  428. STDMETHODIMP
  429. IWDH_OLEINPLACESITE_OnUIActivate( LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  430. {
  431. DebugTrace(TEXT("IOleInPlaceSite: OnUIActivate\n"));
  432. return S_OK;
  433. }
  434. STDMETHODIMP
  435. IWDH_OLEINPLACESITE_GetWindowContext( LPIWABDOCHOST_OLEINPLACESITE lpWABDH,
  436. LPOLEINPLACEFRAME * ppFrame,
  437. LPOLEINPLACEUIWINDOW * ppDoc,
  438. LPRECT lprcPosRect,
  439. LPRECT lprcClipRect,
  440. LPOLEINPLACEFRAMEINFO lpFrameInfo)
  441. {
  442. DebugTrace(TEXT("IOleInPlaceSite: GetWindowContext\n"));
  443. *ppFrame = (LPOLEINPLACEFRAME)lpWABDH->lpIWDH->lpIWDH_OleInPlaceFrame;
  444. *ppDoc = NULL; // NULL means doc window is same as frame window
  445. (*ppFrame)->lpVtbl->AddRef(*ppFrame); // for the inplace frame
  446. GetClientRect(lpWABDH->lpIWDH->m_hwnd, lprcClipRect);
  447. GetClientRect(lpWABDH->lpIWDH->m_hwnd, lprcPosRect);
  448. lpFrameInfo->fMDIApp = FALSE;
  449. lpFrameInfo->hwndFrame=lpWABDH->lpIWDH->m_hwnd;
  450. lpFrameInfo->haccel = NULL;
  451. lpFrameInfo->cAccelEntries = 0;
  452. return S_OK;
  453. }
  454. STDMETHODIMP
  455. IWDH_OLEINPLACESITE_Scroll( LPIWABDOCHOST_OLEINPLACESITE lpWABDH,
  456. SIZE scrollExtent)
  457. {
  458. DebugTrace(TEXT("IOleInPlaceSite: Scroll\n"));
  459. return S_OK;
  460. }
  461. STDMETHODIMP
  462. IWDH_OLEINPLACESITE_OnUIDeactivate(LPIWABDOCHOST_OLEINPLACESITE lpWABDH,
  463. BOOL fUndoable)
  464. {
  465. DebugTrace(TEXT("IOleInPlaceSite: OnUIDeactivate\n"));
  466. return S_OK;
  467. }
  468. STDMETHODIMP
  469. IWDH_OLEINPLACESITE_OnInPlaceDeactivate(LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  470. {
  471. DebugTrace(TEXT("IOleInPlaceSite: OnInPlaceDeactivate\n"));
  472. SafeRelease(lpWABDH->lpIWDH->m_pIPObj);
  473. return S_OK;
  474. }
  475. STDMETHODIMP
  476. IWDH_OLEINPLACESITE_DiscardUndoState(LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  477. {
  478. DebugTrace(TEXT("IOleInPlaceSite: DiscardUndoState\n"));
  479. return E_NOTIMPL;
  480. }
  481. STDMETHODIMP
  482. IWDH_OLEINPLACESITE_DeactivateAndUndo(LPIWABDOCHOST_OLEINPLACESITE lpWABDH)
  483. {
  484. DebugTrace(TEXT("IOleInPlaceSite: DeactivateAndUndo\n"));
  485. return E_NOTIMPL;
  486. }
  487. STDMETHODIMP
  488. IWDH_OLEINPLACESITE_OnPosRectChange(LPIWABDOCHOST_OLEINPLACESITE lpWABDH,
  489. LPCRECT lprcPosRect)
  490. {
  491. DebugTrace(TEXT("IOleInPlaceSite: OnPosRectChange\n"));
  492. return E_NOTIMPL;
  493. }
  494. /****
  495. *
  496. * OLECLIENTSITE methods
  497. *
  498. ***/
  499. STDMETHODIMP
  500. IWDH_OLECLIENTSITE_SaveObject(LPIWABDOCHOST_OLECLIENTSITE lpWABDH)
  501. {
  502. DebugTrace(TEXT("IOleClientSite: SaveObject\n"));
  503. return E_NOTIMPL;
  504. }
  505. STDMETHODIMP
  506. IWDH_OLECLIENTSITE_GetMoniker( LPIWABDOCHOST_OLECLIENTSITE lpWABDH,
  507. DWORD dwAssign,
  508. DWORD dwWhichMoniker,
  509. LPMONIKER * ppmnk)
  510. {
  511. DebugTrace(TEXT("IOleClientSite: GetMoniker\n"));
  512. return E_NOTIMPL;
  513. }
  514. STDMETHODIMP
  515. IWDH_OLECLIENTSITE_GetContainer(LPIWABDOCHOST_OLECLIENTSITE lpWABDH,
  516. LPOLECONTAINER * ppCont)
  517. {
  518. DebugTrace(TEXT("IOleClientSite: GetContainer\n"));
  519. if(ppCont)
  520. *ppCont = NULL;
  521. return E_NOINTERFACE;
  522. }
  523. STDMETHODIMP
  524. IWDH_OLECLIENTSITE_ShowObject(LPIWABDOCHOST_OLECLIENTSITE lpWABDH)
  525. {
  526. DebugTrace(TEXT("IOleClientSite: ShowObject\n"));
  527. return S_OK;
  528. }
  529. STDMETHODIMP
  530. IWDH_OLECLIENTSITE_OnShowWindow(LPIWABDOCHOST_OLECLIENTSITE lpWABDH,
  531. BOOL fShow)
  532. {
  533. DebugTrace(TEXT("IOleClientSite: OnShowWindow\n"));
  534. return E_NOTIMPL;
  535. }
  536. STDMETHODIMP
  537. IWDH_OLECLIENTSITE_RequestNewObjectLayout(LPIWABDOCHOST_OLECLIENTSITE lpWABDH)
  538. {
  539. DebugTrace(TEXT("IOleClientSite: RequestNewObjectLayout\n"));
  540. return E_NOTIMPL;
  541. }
  542. /***
  543. *
  544. *
  545. *
  546. * IOleDocumentSite Methods
  547. *
  548. *
  549. ***/
  550. STDMETHODIMP
  551. IWDH_OLEDOCUMENTSITE_ActivateMe(LPIWABDOCHOST_OLEDOCUMENTSITE lpWABDH,
  552. LPOLEDOCUMENTVIEW pViewToActivate)
  553. {
  554. DebugTrace(TEXT("IOleDocumentSite: ActivateMe: %x\n"), pViewToActivate);
  555. return HrCreateDocView(lpWABDH->lpIWDH, pViewToActivate);
  556. }
  557. /******
  558. *
  559. *
  560. *
  561. * Non Interface functions
  562. *
  563. *
  564. *
  565. *
  566. *******/
  567. LRESULT CALLBACK_16 WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  568. {
  569. LPIWABDOCHOST lpWABDH;
  570. lpWABDH = (LPIWABDOCHOST) GetWindowLongPtr(hwnd, GWLP_USERDATA);
  571. switch(msg)
  572. {
  573. case WM_CREATE:
  574. {
  575. LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
  576. lpWABDH = (LPIWABDOCHOST) lpcs->lpCreateParams;
  577. if(lpWABDH)
  578. {
  579. lpWABDH->m_hwnd = hwnd;
  580. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LPARAM)lpWABDH);
  581. lpWABDH->lpVtbl->AddRef(lpWABDH);
  582. }
  583. else
  584. return -1;
  585. }
  586. break;
  587. case WM_SETFOCUS:
  588. if(lpWABDH->m_pDocView)
  589. lpWABDH->m_pDocView->lpVtbl->UIActivate( lpWABDH->m_pDocView,
  590. TRUE);
  591. break;
  592. case WM_SIZE:
  593. WMSize(lpWABDH, LOWORD(lParam), HIWORD(lParam));
  594. return 0;
  595. case WM_CLOSE:
  596. return 0; // prevent alt-f4's
  597. case WM_NCDESTROY:
  598. {
  599. if(lpWABDH)
  600. {
  601. SetWindowLongPtr(lpWABDH->m_hwnd, GWLP_USERDATA, (LPARAM) 0);
  602. lpWABDH->m_hwnd = NULL;
  603. lpWABDH->lpVtbl->Release(lpWABDH);
  604. }
  605. }
  606. break;
  607. }
  608. return DefWindowProc(hwnd, msg, wParam, lParam);
  609. }
  610. //$$
  611. void WMSize(LPIWABDOCHOST lpWABDH, int cxBody, int cyBody)
  612. {
  613. RECT rc={0};
  614. if(lpWABDH->m_pDocView)
  615. {
  616. rc.bottom=cyBody;
  617. rc.right=cxBody;
  618. lpWABDH->m_pDocView->lpVtbl->SetRect(lpWABDH->m_pDocView,
  619. &rc);
  620. }
  621. }
  622. //$$
  623. HRESULT HrCreateDocObj(LPIWABDOCHOST lpWABDH, LPCLSID pCLSID)
  624. {
  625. HRESULT hr = S_OK;
  626. if(!pCLSID)
  627. return MAPI_E_INVALID_PARAMETER;
  628. Assert(!lpWABDH->m_lpOleObj);
  629. Assert(!lpWABDH->m_pDocView);
  630. if (CoInitialize(NULL) == S_FALSE)
  631. {
  632. // Already initialized, undo the extra.
  633. CoUninitialize();
  634. }
  635. else
  636. fTridentCoinit = TRUE;
  637. hr = CoCreateInstance( pCLSID,
  638. NULL,
  639. CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
  640. &IID_IOleObject,
  641. (LPVOID *)&(lpWABDH->m_lpOleObj));
  642. if (FAILED(hr))
  643. {
  644. DebugTrace(TEXT("!!!!ERROR: Unable to CoCreateInstance(Trident)\n"));
  645. goto error;
  646. }
  647. hr = lpWABDH->m_lpOleObj->lpVtbl->SetClientSite( lpWABDH->m_lpOleObj,
  648. (LPOLECLIENTSITE)lpWABDH->lpIWDH_OleClientSite);
  649. if (FAILED(hr))
  650. goto error;
  651. error:
  652. return hr;
  653. }
  654. //$$
  655. HRESULT HrShow(LPIWABDOCHOST lpWABDH)
  656. {
  657. RECT rc;
  658. HRESULT hr;
  659. GetClientRect(lpWABDH->m_hwnd, &rc);
  660. hr=lpWABDH->m_lpOleObj->lpVtbl->DoVerb( lpWABDH->m_lpOleObj,
  661. OLEIVERB_SHOW,
  662. NULL,
  663. (LPOLECLIENTSITE)lpWABDH->lpIWDH_OleClientSite,
  664. 0,
  665. lpWABDH->m_hwnd,
  666. &rc);
  667. if(FAILED(hr))
  668. goto error;
  669. error:
  670. return hr;
  671. }
  672. //$$
  673. HRESULT HrCloseDocObj(LPIWABDOCHOST lpWABDH)
  674. {
  675. LPOLEINPLACEOBJECT pInPlaceObj=0;
  676. if(lpWABDH->lpIWDH->m_pIPObj)
  677. lpWABDH->lpIWDH->m_pIPObj->lpVtbl->InPlaceDeactivate(lpWABDH->lpIWDH->m_pIPObj);
  678. if(lpWABDH->m_pDocView)
  679. {
  680. lpWABDH->m_pDocView->lpVtbl->Show(lpWABDH->m_pDocView, FALSE);
  681. lpWABDH->m_pDocView->lpVtbl->UIActivate(lpWABDH->m_pDocView, FALSE);
  682. lpWABDH->m_pDocView->lpVtbl->CloseView( lpWABDH->m_pDocView, 0);
  683. lpWABDH->m_pDocView->lpVtbl->SetInPlaceSite(lpWABDH->m_pDocView, NULL);
  684. SafeRelease(lpWABDH->m_pDocView);
  685. lpWABDH->m_pDocView=NULL;
  686. }
  687. if (lpWABDH->m_lpOleObj)
  688. {
  689. lpWABDH->m_lpOleObj->lpVtbl->SetClientSite( lpWABDH->m_lpOleObj, NULL);
  690. // close the ole object, but blow off changes as we have either extracted
  691. // them ourselves or don't care.
  692. lpWABDH->m_lpOleObj->lpVtbl->Close(lpWABDH->m_lpOleObj, OLECLOSE_NOSAVE);
  693. SafeRelease(lpWABDH->m_lpOleObj);
  694. }
  695. lpWABDH->m_pIPObj=NULL;
  696. return NOERROR;
  697. }
  698. //$$
  699. HRESULT HrInit(LPIWABDOCHOST lpWABDH,
  700. HWND hwndParent,
  701. int idDlgItem,
  702. DWORD dhbBorder)
  703. {
  704. HRESULT hr;
  705. HWND hwnd;
  706. if(!IsWindow(hwndParent))
  707. return MAPI_E_INVALID_PARAMETER;
  708. hr=HrDocHost_Init(lpWABDH, TRUE);
  709. if(FAILED(hr))
  710. goto error;
  711. {
  712. RECT rc = {0};
  713. HWND hWndFrame = GetDlgItem(hwndParent, IDC_DETAILS_TRIDENT_STATIC);
  714. GetChildClientRect(hWndFrame, &rc);
  715. hwnd=CreateWindowEx(WS_EX_NOPARENTNOTIFY, //| WS_EX_CLIENTEDGE,
  716. c_szWABDocHostWndClass,
  717. NULL,
  718. WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_CHILD|WS_TABSTOP,
  719. rc.left,rc.top,
  720. rc.right-rc.left,rc.bottom-rc.top,
  721. hwndParent,
  722. (HMENU)IntToPtr(idDlgItem),
  723. hinstMapiXWAB,
  724. (LPVOID)lpWABDH);
  725. if(!hwnd)
  726. {
  727. hr=MAPI_E_NOT_ENOUGH_MEMORY;
  728. goto error;
  729. }
  730. }
  731. error:
  732. return hr;
  733. }
  734. //$$
  735. HRESULT HrDocHost_Init(LPIWABDOCHOST lpWABDH, BOOL fInit)
  736. {
  737. static BOOL fInited=FALSE;
  738. WNDCLASS wc={0};
  739. if(fInit)
  740. {
  741. if(fInited) // already regisered
  742. return NOERROR;
  743. wc.lpfnWndProc = WndProc; //CDocHost::ExtWndProc;
  744. wc.hInstance = hinstMapiXWAB;
  745. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  746. wc.lpszClassName = c_szWABDocHostWndClass;
  747. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  748. wc.style = CS_DBLCLKS;
  749. if(!RegisterClass(&wc)) // This will fail if class is already registered in which case continue
  750. {
  751. DebugTrace(TEXT("RegisterClass: %s failed\n"), c_szWABDocHostWndClass);
  752. if(GetLastError() == ERROR_NOT_ENOUGH_MEMORY)
  753. return MAPI_E_NOT_ENOUGH_MEMORY;
  754. }
  755. fInited=TRUE;
  756. }
  757. else
  758. {
  759. if (fInited)
  760. {
  761. if(!UnregisterClass(c_szWABDocHostWndClass, hinstMapiXWAB))
  762. {
  763. DebugTrace(TEXT("Could not Unregister %s. GetLastError(): %d\n"),c_szWABDocHostWndClass, GetLastError());
  764. }
  765. fInited=FALSE;
  766. }
  767. }
  768. return S_OK;
  769. }
  770. //$$
  771. HRESULT HrCreateDocView(LPIWABDOCHOST lpWABDH, LPOLEDOCUMENTVIEW pViewToActivate)
  772. {
  773. HRESULT hr;
  774. LPOLEDOCUMENT pOleDoc=NULL;
  775. // if we weren't handed a DocumentView pointer, get one
  776. if(!pViewToActivate)
  777. {
  778. hr=OleRun((struct IUnknown *)(lpWABDH->m_lpOleObj));
  779. if(FAILED(hr))
  780. goto error;
  781. hr=lpWABDH->m_lpOleObj->lpVtbl->QueryInterface(lpWABDH->m_lpOleObj,
  782. &IID_IOleDocument,
  783. (LPVOID*)&pOleDoc);
  784. if(FAILED(hr))
  785. goto error;
  786. hr=pOleDoc->lpVtbl->CreateView( pOleDoc,
  787. (LPOLEINPLACESITE) lpWABDH->lpIWDH_OleInPlaceSite,
  788. NULL,
  789. 0,
  790. &(lpWABDH->m_pDocView));
  791. if(FAILED(hr))
  792. goto error;
  793. }
  794. else
  795. lpWABDH->m_pDocView = pViewToActivate;
  796. hr=lpWABDH->m_pDocView->lpVtbl->SetInPlaceSite(lpWABDH->m_pDocView,
  797. (LPOLEINPLACESITE)lpWABDH->lpIWDH_OleInPlaceSite);
  798. if(FAILED(hr))
  799. goto error;
  800. // if we were handed a document view pointer, addref it after calling SetInPlaceSite
  801. if(pViewToActivate)
  802. pViewToActivate->lpVtbl->AddRef(pViewToActivate);
  803. hr=lpWABDH->m_pDocView->lpVtbl->Show( lpWABDH->m_pDocView,
  804. TRUE);
  805. if(FAILED(hr))
  806. goto error;
  807. error:
  808. if(pOleDoc)
  809. SafeRelease(pOleDoc);
  810. return hr;
  811. }
  812. //$$
  813. HRESULT HrLoadTheURL(LPIWABDOCHOST lpWABDH, LPTSTR pszURL)
  814. {
  815. WCHAR wszURL[1024]; //INTERNET_MAX_URL_LENGTH + 1];
  816. LPMONIKER pmk=0;
  817. HINSTANCE hInstURLMON = NULL;
  818. HRESULT hr = S_OK;
  819. StrCpyN(wszURL,pszURL, ARRAYSIZE(wszURL));
  820. hInstURLMON = LoadLibrary( TEXT("urlmon.dll"));
  821. if(!hInstURLMON)
  822. {
  823. hr = MAPI_E_NOT_INITIALIZED;
  824. goto error;
  825. }
  826. lpfnCreateURLMoniker = (LPCREATEURLMONIKER) GetProcAddress( hInstURLMON, "CreateURLMoniker");
  827. if(!lpfnCreateURLMoniker)
  828. {
  829. FreeLibrary(hInstURLMON);
  830. goto error;
  831. }
  832. hr = lpfnCreateURLMoniker(NULL, wszURL, &pmk);
  833. if(FAILED(hr))
  834. goto error;
  835. hr = HrLoadFromMoniker(lpWABDH, pmk);
  836. if(FAILED(hr))
  837. goto error;
  838. error:
  839. if(pmk)
  840. SafeRelease(pmk);
  841. if(lpfnCreateURLMoniker)
  842. FreeLibrary(hInstURLMON);
  843. return hr;
  844. }
  845. //$$
  846. HRESULT HrLoadURL(LPIWABDOCHOST lpWABDH, LPTSTR pszURL)
  847. {
  848. HRESULT hr=S_OK;
  849. HCURSOR hcur;
  850. hcur = SetCursor(LoadCursor(NULL, IDC_WAIT));
  851. if(!pszURL)
  852. {
  853. hr=MAPI_E_INVALID_PARAMETER;
  854. goto error;
  855. }
  856. if (!lpWABDH->m_lpOleObj)
  857. {
  858. hr = HrCreateDocObj(lpWABDH,
  859. (LPCLSID)&CLSID_HTMLDocument);
  860. if(FAILED(hr))
  861. goto error;
  862. hr = HrLoadTheURL(lpWABDH, pszURL);
  863. if(FAILED(hr))
  864. goto error;
  865. hr = HrShow(lpWABDH);
  866. if (FAILED(hr))
  867. goto error;
  868. }
  869. error:
  870. if(hcur)
  871. SetCursor(hcur);
  872. return hr;
  873. }
  874. //$$
  875. HRESULT HrLoadFromMoniker(LPIWABDOCHOST lpWABDH,
  876. LPMONIKER pmk)
  877. {
  878. HRESULT hr=E_FAIL;
  879. LPPERSISTMONIKER pPMoniker=0;
  880. LPBC pbc=0;
  881. hr=lpWABDH->m_lpOleObj->lpVtbl->QueryInterface(lpWABDH->m_lpOleObj,
  882. &IID_IPersistMoniker,
  883. (LPVOID *)&pPMoniker);
  884. if(FAILED(hr))
  885. goto error;
  886. hr=CreateBindCtx(0, &pbc);
  887. if(FAILED(hr))
  888. goto error;
  889. hr=pPMoniker->lpVtbl->Load( pPMoniker,
  890. TRUE,
  891. pmk,
  892. pbc,
  893. STGM_READWRITE);
  894. if(FAILED(hr))
  895. goto error;
  896. error:
  897. if(pbc)
  898. SafeRelease(pbc);
  899. if(pPMoniker)
  900. SafeRelease(pPMoniker);
  901. return hr;
  902. }