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.

382 lines
9.6 KiB

  1. /*
  2. * IDOCHOSTUIHANDLER.CPP
  3. * IDocHostUIHandler for Document Objects CSite class
  4. *
  5. * Copyright (c)1995-1999 Microsoft Corporation, All Rights Reserved
  6. */
  7. #include "stdafx.h"
  8. #include <docobj.h>
  9. #include "site.h"
  10. #include "DHTMLEd.h"
  11. #include "DHTMLEdit.h"
  12. #include "proxyframe.h"
  13. /**
  14. Note: the m_cRef count is provided for debugging purposes only.
  15. CSite controls the destruction of the object through delete,
  16. not reference counting
  17. */
  18. /*
  19. * CImpIDocHostUIHandler::CImpIDocHostUIHandler
  20. * CImpIDocHostUIHandler::~CImpIDocHostUIHandler
  21. *
  22. * Parameters (Constructor):
  23. * pSite PCSite of the site we're in.
  24. * pUnkOuter LPUNKNOWN to which we delegate.
  25. */
  26. CImpIDocHostUIHandler::CImpIDocHostUIHandler( PCSite pSite, LPUNKNOWN pUnkOuter)
  27. {
  28. m_cRef = 0;
  29. m_pSite = pSite;
  30. m_pUnkOuter = pUnkOuter;
  31. }
  32. CImpIDocHostUIHandler::~CImpIDocHostUIHandler( void )
  33. {
  34. }
  35. /*
  36. * CImpIDocHostUIHandler::QueryInterface
  37. * CImpIDocHostUIHandler::AddRef
  38. * CImpIDocHostUIHandler::Release
  39. *
  40. * Purpose:
  41. * IUnknown members for CImpIOleDocumentSite object.
  42. */
  43. STDMETHODIMP CImpIDocHostUIHandler::QueryInterface( REFIID riid, void **ppv )
  44. {
  45. return m_pUnkOuter->QueryInterface( riid, ppv );
  46. }
  47. STDMETHODIMP_(ULONG) CImpIDocHostUIHandler::AddRef( void )
  48. {
  49. ++m_cRef;
  50. return m_pUnkOuter->AddRef();
  51. }
  52. STDMETHODIMP_(ULONG) CImpIDocHostUIHandler::Release( void )
  53. {
  54. --m_cRef;
  55. return m_pUnkOuter->Release();
  56. }
  57. // * CImpIDocHostUIHandler::GetHostInfo
  58. // *
  59. // * Purpose: Called at initialisation
  60. // *
  61. STDMETHODIMP CImpIDocHostUIHandler::GetHostInfo( DOCHOSTUIINFO* pInfo )
  62. {
  63. DWORD dwFlags = 0;
  64. BOOL bDialogEditing = FALSE;
  65. BOOL bDisplay3D= FALSE;
  66. BOOL bScrollbars = FALSE;
  67. BOOL bFlatScrollbars = FALSE;
  68. BOOL bContextMenu = FALSE;
  69. m_pSite->GetFrame()->HrGetDisplay3D(bDisplay3D);
  70. m_pSite->GetFrame()->HrGetScrollbars(bScrollbars);
  71. m_pSite->GetFrame()->HrGetDisplayFlatScrollbars(bFlatScrollbars);
  72. if (bDialogEditing == TRUE)
  73. dwFlags |= DOCHOSTUIFLAG_DIALOG;
  74. if (bDisplay3D == FALSE)
  75. dwFlags |= DOCHOSTUIFLAG_NO3DBORDER;
  76. if (bScrollbars == FALSE)
  77. dwFlags |= DOCHOSTUIFLAG_SCROLL_NO;
  78. if (bFlatScrollbars)
  79. dwFlags |= DOCHOSTUIFLAG_FLAT_SCROLLBAR;
  80. if (bContextMenu == FALSE)
  81. dwFlags |= DOCHOSTUIFLAG_DISABLE_HELP_MENU;
  82. pInfo->dwFlags = dwFlags;
  83. pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
  84. return S_OK;
  85. }
  86. // * CImpIDocHostUIHandler::ShowUI
  87. // *
  88. // * Purpose: Called when MSHTML.DLL shows its UI
  89. // *
  90. STDMETHODIMP CImpIDocHostUIHandler::ShowUI(
  91. DWORD /*dwID*/,
  92. IOleInPlaceActiveObject * /*pActiveObject*/,
  93. IOleCommandTarget * /*pCommandTarget*/,
  94. IOleInPlaceFrame * /*pFrame*/,
  95. IOleInPlaceUIWindow * /*pDoc*/)
  96. {
  97. // We've already got our own UI in place so just return S_OK
  98. return S_OK;
  99. }
  100. // * CImpIDocHostUIHandler::HideUI
  101. // *
  102. // * Purpose: Called when MSHTML.DLL hides its UI
  103. // *
  104. STDMETHODIMP CImpIDocHostUIHandler::HideUI(void)
  105. {
  106. return S_OK;
  107. }
  108. // * CImpIDocHostUIHandler::UpdateUI
  109. // *
  110. // * Purpose: Called when MSHTML.DLL updates its UI
  111. // *
  112. STDMETHODIMP CImpIDocHostUIHandler::UpdateUI(void)
  113. {
  114. // we fire this from proxyframe's IOleCommandTarget
  115. return S_OK;
  116. }
  117. // * CImpIDocHostUIHandler::EnableModeless
  118. // *
  119. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::EnableModeless
  120. // *
  121. STDMETHODIMP CImpIDocHostUIHandler::EnableModeless(BOOL /*fEnable*/)
  122. {
  123. return E_NOTIMPL;
  124. }
  125. // * CImpIDocHostUIHandler::OnDocWindowActivate
  126. // *
  127. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnDocWindowActivate
  128. // *
  129. STDMETHODIMP CImpIDocHostUIHandler::OnDocWindowActivate(BOOL /*fActivate*/)
  130. {
  131. return E_NOTIMPL;
  132. }
  133. // * CImpIDocHostUIHandler::OnFrameWindowActivate
  134. // *
  135. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnFrameWindowActivate
  136. // *
  137. STDMETHODIMP CImpIDocHostUIHandler::OnFrameWindowActivate(BOOL /*fActivate*/)
  138. {
  139. return E_NOTIMPL;
  140. }
  141. // * CImpIDocHostUIHandler::ResizeBorder
  142. // *
  143. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::ResizeBorder
  144. // *
  145. STDMETHODIMP CImpIDocHostUIHandler::ResizeBorder(
  146. LPCRECT /*prcBorder*/,
  147. IOleInPlaceUIWindow* /*pUIWindow*/,
  148. BOOL /*fRameWindow*/)
  149. {
  150. return E_NOTIMPL;
  151. }
  152. // * CImpIDocHostUIHandler::ShowContextMenu
  153. // *
  154. // * Purpose: Called when MSHTML.DLL would normally display its context menu
  155. // *
  156. STDMETHODIMP CImpIDocHostUIHandler::ShowContextMenu(
  157. DWORD /*dwID*/,
  158. POINT* pptPosition,
  159. IUnknown* /*pCommandTarget*/,
  160. IDispatch* /*pDispatchObjectHit*/)
  161. {
  162. USES_CONVERSION;
  163. HMENU hmenu = NULL;
  164. INT id = 0;
  165. HRESULT hr = NOERROR;
  166. LONG lLBound, lUBound, lIndex, lLBoundState, lUBoundState;
  167. BSTR bstr=0;
  168. SAFEARRAY * psaStrings = NULL;
  169. SAFEARRAY * psaStates = NULL;
  170. int i;
  171. BOOL ok = FALSE;
  172. ULONG state = 0;
  173. CComBSTR _bstr;
  174. _ASSERTE(m_pSite);
  175. _ASSERTE(m_pSite->GetFrame());
  176. _ASSERTE(m_pSite->GetFrame()->GetControl());
  177. _ASSERTE(m_pSite->GetFrame()->GetControl()->m_hWndCD);
  178. // Correct X & Y position for local coordinates:
  179. POINT ptPos = *pptPosition;
  180. HWND hwndDoc = m_pSite->GetFrame()->GetDocWindow ();
  181. _ASSERTE ( hwndDoc );
  182. _ASSERTE ( ::IsWindow ( hwndDoc ) );
  183. if ( ( NULL != hwndDoc ) && ::IsWindow ( hwndDoc ) )
  184. {
  185. ::ScreenToClient ( hwndDoc, &ptPos );
  186. // correct for scrolling
  187. POINT ptScrollPos;
  188. if ( SUCCEEDED ( m_pSite->GetFrame()->GetScrollPos ( &ptScrollPos ) ) )
  189. {
  190. ptPos.x += ptScrollPos.x;
  191. ptPos.y += ptScrollPos.y;
  192. }
  193. m_pSite->GetFrame()->GetControl()->Fire_ShowContextMenu ( ptPos.x, ptPos.y );
  194. }
  195. psaStrings = m_pSite->GetFrame()->GetMenuStrings();
  196. psaStates = m_pSite->GetFrame()->GetMenuStates();
  197. if (NULL == psaStrings || NULL == psaStates)
  198. return S_OK;
  199. SafeArrayGetLBound(psaStrings, 1, &lLBound);
  200. SafeArrayGetUBound(psaStrings, 1, &lUBound);
  201. SafeArrayGetLBound(psaStates, 1, &lLBoundState);
  202. SafeArrayGetUBound(psaStates, 1, &lUBoundState);
  203. if (lLBound != lLBoundState || lUBound != lUBoundState)
  204. return S_OK;
  205. // there arrays have no elements
  206. #if 0
  207. Bug 15224: lower and upper bound are both zero if there is one element in sthe array.
  208. psaStrings is NULL if there are no strings.
  209. if (lLBound == lUBound)
  210. return S_OK;
  211. #endif
  212. hmenu = CreatePopupMenu();
  213. if (NULL == hmenu)
  214. {
  215. hr = HRESULT_FROM_WIN32(::GetLastError());
  216. return hr;
  217. }
  218. for (lIndex=lLBound, i=0; lIndex<=lUBound && i <= 256; lIndex++, i++)
  219. {
  220. if ( FADF_BSTR & psaStrings->fFeatures )
  221. {
  222. SafeArrayGetElement(psaStrings, &lIndex, &bstr);
  223. _bstr = bstr;
  224. }
  225. else if ( FADF_VARIANT & psaStrings->fFeatures )
  226. {
  227. VARIANT var;
  228. VariantInit ( &var );
  229. SafeArrayGetElement(psaStrings, &lIndex, &var);
  230. VariantChangeType ( &var, &var, 0, VT_BSTR );
  231. _bstr = var.bstrVal;
  232. VariantClear ( &var );
  233. }
  234. else
  235. {
  236. _ASSERTE ( ( FADF_BSTR | FADF_VARIANT ) & psaStrings->fFeatures );
  237. return E_UNEXPECTED;
  238. }
  239. if ( FADF_VARIANT & psaStates->fFeatures )
  240. {
  241. VARIANT var;
  242. VariantInit ( &var );
  243. SafeArrayGetElement(psaStates, &lIndex, &var);
  244. VariantChangeType ( &var, &var, 0, VT_I4 );
  245. state = var.lVal;
  246. VariantClear ( &var );
  247. }
  248. else
  249. {
  250. // A safe array of integers seems to use an fFeatures == 0, which can't
  251. // safely be tested for.
  252. SafeArrayGetElement(psaStates, &lIndex, &state);
  253. }
  254. if (_bstr.Length() == 0)
  255. state = MF_SEPARATOR|MF_ENABLED;
  256. else if (state == triGray)
  257. state = MF_GRAYED;
  258. else if (state == triChecked)
  259. state = MF_CHECKED|MF_ENABLED;
  260. else
  261. state = MF_ENABLED;
  262. ok = AppendMenu(hmenu, MF_STRING | state, i+35000, W2T(_bstr.m_str));
  263. _ASSERTE(ok);
  264. }
  265. id = (INT)TrackPopupMenu(
  266. hmenu,
  267. TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  268. pptPosition->x,
  269. pptPosition->y,
  270. 0,
  271. m_pSite->GetFrame()->GetControl()->m_hWndCD,
  272. NULL);
  273. _ASSERTE(id == 0 || (id >= 35000 && id <= 35000+i));
  274. if (id >= 35000 && id <= 35000+i)
  275. m_pSite->GetFrame()->GetControl()->Fire_ContextMenuAction(id-35000);
  276. DestroyMenu(hmenu);
  277. return S_OK;
  278. }
  279. // * CImpIDocHostUIHandler::TranslateAccelerator
  280. // *
  281. // * Purpose: Called from MSHTML.DLL's TranslateAccelerator routines
  282. // *
  283. STDMETHODIMP CImpIDocHostUIHandler::TranslateAccelerator(LPMSG /*lpMsg*/,
  284. /* [in] */ const GUID __RPC_FAR * /*pguidCmdGroup*/,
  285. /* [in] */ DWORD /*nCmdID*/)
  286. {
  287. return S_FALSE;
  288. }
  289. // * CImpIDocHostUIHandler::GetOptionKeyPath
  290. // *
  291. // * Purpose: Called by MSHTML.DLL to find where the host wishes to store
  292. // * its options in the registry
  293. // *
  294. STDMETHODIMP CImpIDocHostUIHandler::GetOptionKeyPath(BSTR* pbstrKey, DWORD)
  295. {
  296. pbstrKey = NULL; // docs say this should be set to null if not used
  297. return S_OK;
  298. }
  299. STDMETHODIMP CImpIDocHostUIHandler::GetDropTarget(
  300. /* [in] */ IDropTarget __RPC_FAR * /*pDropTarget*/,
  301. /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR * /*ppDropTarget*/)
  302. {
  303. return E_NOTIMPL;
  304. }
  305. STDMETHODIMP CImpIDocHostUIHandler::GetExternal(
  306. /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
  307. {
  308. _ASSERTE ( ppDispatch );
  309. if ( NULL == ppDispatch )
  310. {
  311. return E_INVALIDARG;
  312. }
  313. *ppDispatch = NULL;
  314. return E_NOTIMPL;
  315. }
  316. STDMETHODIMP CImpIDocHostUIHandler::TranslateUrl(
  317. /* [in] */ DWORD /*dwTranslate*/,
  318. /* [in] */ OLECHAR __RPC_FAR * /*pchURLIn*/,
  319. /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR * /*ppchURLOut*/)
  320. {
  321. return E_NOTIMPL;
  322. }
  323. STDMETHODIMP CImpIDocHostUIHandler::FilterDataObject(
  324. /* [in] */ IDataObject __RPC_FAR * /*pDO*/,
  325. /* [out] */ IDataObject __RPC_FAR *__RPC_FAR * /*ppDORet*/)
  326. {
  327. return E_NOTIMPL;
  328. }