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.

300 lines
8.1 KiB

  1. #include "precomp.h"
  2. #include "mcinc.h"
  3. #include "panel.h"
  4. #include "marswin.h"
  5. #include "axhost.h"
  6. //#include "befact.h"
  7. CMarsAxHostWindow::~CMarsAxHostWindow()
  8. {
  9. }
  10. STDMETHODIMP CMarsAxHostWindow::SetSite(IUnknown* pUnkSite)
  11. {
  12. m_spMarsPanel.Release();
  13. CMarsPanel::GetFromUnknown(pUnkSite, &m_spMarsPanel);
  14. return CAxHostWindow::SetSite(pUnkSite);
  15. }
  16. STDMETHODIMP CMarsAxHostWindow::OnUIActivate()
  17. {
  18. if (m_spMarsPanel)
  19. {
  20. m_spMarsPanel->OnUIActivate();
  21. }
  22. return S_OK;
  23. }
  24. STDMETHODIMP CMarsAxHostWindow::TranslateAccelerator(LPMSG lpMsg, DWORD grfModifiers)
  25. {
  26. HRESULT hr;
  27. if (m_spMarsPanel)
  28. {
  29. hr = m_spMarsPanel->TranslateAccelerator(lpMsg, grfModifiers);
  30. }
  31. else
  32. {
  33. hr = S_FALSE;
  34. }
  35. return hr;
  36. }
  37. LRESULT CMarsAxHostWindow::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  38. {
  39. m_bHaveFocus = TRUE;
  40. if (!m_bReleaseAll)
  41. {
  42. if (m_spOleObject != NULL)
  43. {
  44. CComPtr<IOleClientSite> spClientSite;
  45. GetControllingUnknown()->QueryInterface(IID_IOleClientSite, (void**)&spClientSite);
  46. if (spClientSite != NULL)
  47. m_spOleObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, spClientSite, 0, m_hWnd, &m_rcPos);
  48. }
  49. if(!m_bWindowless && !IsChild(::GetFocus()))
  50. ::SetFocus(::GetWindow(m_hWnd, GW_CHILD));
  51. }
  52. bHandled = FALSE;
  53. return 0;
  54. }
  55. LRESULT CMarsAxHostWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  56. {
  57. if (m_spMarsPanel)
  58. {
  59. m_spMarsPanel->OnWindowPosChanging((WINDOWPOS *)lParam);
  60. }
  61. bHandled = FALSE;
  62. return 0;
  63. }
  64. LRESULT CMarsAxHostWindow::OnWindowPosChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  65. {
  66. if (m_spMarsPanel)
  67. {
  68. m_spMarsPanel->OnWindowPosChanged((WINDOWPOS *)lParam);
  69. }
  70. bHandled = FALSE;
  71. return 0;
  72. }
  73. LRESULT CMarsAxHostWindow::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  74. {
  75. if(m_spMarsPanel)
  76. {
  77. MINMAXINFO* pInfo = (MINMAXINFO*)lParam;
  78. POINT ptMin;
  79. POINT ptMax;
  80. m_spMarsPanel->GetMinMaxInfo( ptMin, ptMax );
  81. if(ptMin.x >= 0) pInfo->ptMinTrackSize.x = ptMin.x;
  82. if(ptMin.y >= 0) pInfo->ptMinTrackSize.y = ptMin.y;
  83. if(ptMax.x >= 0) pInfo->ptMaxTrackSize.x = ptMax.x;
  84. if(ptMax.y >= 0) pInfo->ptMaxTrackSize.y = ptMax.y;
  85. }
  86. return 0;
  87. }
  88. STDMETHODIMP CMarsAxHostWindow::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  89. DISPPARAMS *pdispparams, VARIANT *pvarResult,
  90. EXCEPINFO *pexcepinfo, UINT *puArgErr)
  91. {
  92. HRESULT hr = CAxHostWindow::Invoke(dispidMember, riid, lcid, wFlags, pdispparams,
  93. pvarResult, pexcepinfo, puArgErr);
  94. if (FAILED(hr))
  95. {
  96. if ((DISPID_AMBIENT_USERAGENT == dispidMember) &&
  97. (DISPATCH_PROPERTYGET == wFlags) &&
  98. (NULL != pvarResult))
  99. {
  100. // BUGBUG: Once "real" C++ panel interface is defined, this should be
  101. // set by the host
  102. CHAR szUA[MAX_PATH];
  103. DWORD dwSize = ARRAYSIZE(szUA);
  104. if (SUCCEEDED(ObtainUserAgentString(0, szUA, &dwSize)))
  105. {
  106. LPSTR pszAppend = szUA + dwSize - 2; // skip back to the ')'
  107. if (*pszAppend != ')')
  108. {
  109. pszAppend = StrRChrA(szUA, pszAppend, ')');
  110. }
  111. if (pszAppend)
  112. {
  113. const CHAR c_szUserAgentAppend[] = "; PCHSHELL 2.0)";
  114. *pszAppend = '\0';
  115. StrCatBuffA(szUA, c_szUserAgentAppend, ARRAYSIZE(szUA));
  116. CComBSTR bstrUA(szUA);
  117. if (bstrUA)
  118. {
  119. pvarResult->vt = VT_BSTR;
  120. pvarResult->bstrVal = bstrUA.Detach();
  121. hr = S_OK;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. return hr;
  128. }
  129. HRESULT CMarsAxHostWindow::AskHostForDocHostUIHandler( CComPtr<IDocHostUIHandler>& spHost )
  130. {
  131. return QueryService( IID_IDocHostUIHandler, IID_IDocHostUIHandler, (void**)&spHost );
  132. }
  133. // IOleInPlaceSite overrides
  134. STDMETHODIMP CMarsAxHostWindow::GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO pFrameInfo)
  135. {
  136. HRESULT hr;
  137. if (ppFrame && ppDoc && lprcPosRect && lprcClipRect)
  138. {
  139. hr = S_OK;
  140. if (m_spMarsPanel)
  141. {
  142. m_spMarsPanel->QueryInterface(IID_IOleInPlaceUIWindow, (void **)ppDoc);
  143. m_spMarsPanel->Document()->MarsWindow()->QueryInterface(IID_IOleInPlaceFrame, (void **)ppFrame);
  144. GetClientRect(lprcPosRect);
  145. GetClientRect(lprcClipRect);
  146. pFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
  147. pFrameInfo->fMDIApp = m_bMDIApp;
  148. pFrameInfo->hwndFrame = GetParent();
  149. m_spMarsPanel->Document()->MarsWindow()->GetAccelerators(&pFrameInfo->haccel, &pFrameInfo->cAccelEntries);
  150. hr = S_OK;
  151. }
  152. else
  153. {
  154. hr = E_UNEXPECTED;
  155. }
  156. }
  157. else
  158. {
  159. hr = E_POINTER;
  160. }
  161. return hr;
  162. }
  163. STDMETHODIMP CMarsAxHostWindow::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext)
  164. {
  165. // We let IE enable SBCMDID_ADDTOFAVORITES for us along with the other context menus
  166. return OLECMDERR_E_NOTSUPPORTED;
  167. }
  168. HRESULT CMarsAxHostWindow::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt,
  169. VARIANT *pvarargIn, VARIANT *pvarargOut)
  170. {
  171. // HACK: Shdocvw sometimes tests specifically for a value like
  172. // OLECMDERR_E_NOTSUPPORTED and will not perform an essential action
  173. // if we return something more generic like E_FAIL
  174. HRESULT hr = OLECMDERR_E_NOTSUPPORTED;
  175. if (pguidCmdGroup != NULL)
  176. {
  177. if (*pguidCmdGroup == CGID_DocHostCommandHandler)
  178. {
  179. // Trident calls us with this command group as an extension
  180. // to IDocHostUIHandler
  181. if (m_spMarsPanel)
  182. {
  183. hr = m_spMarsPanel->OnDocHostUIExec(pguidCmdGroup, nCmdID,
  184. nCmdexecopt, pvarargIn, pvarargOut);
  185. }
  186. }
  187. }
  188. return hr;
  189. }
  190. HRESULT GetDoc2FromAxWindow(CMarsAxWindow *pAxWin, IHTMLDocument2 **ppDoc2)
  191. {
  192. ATLASSERT((NULL != ppDoc2) && (NULL != pAxWin));
  193. *ppDoc2 = NULL;
  194. pAxWin->QueryControl(IID_IHTMLDocument2, (void **)ppDoc2);
  195. if (!*ppDoc2)
  196. {
  197. CComPtr<IWebBrowser2> spWebBrowser2;
  198. pAxWin->QueryControl(IID_IWebBrowser2, (void **)&spWebBrowser2);
  199. if (spWebBrowser2)
  200. {
  201. CComPtr<IDispatch> spdisp;
  202. spWebBrowser2->get_Document(&spdisp);
  203. if (spdisp)
  204. {
  205. spdisp->QueryInterface(IID_IHTMLDocument2, (void **)ppDoc2);
  206. }
  207. }
  208. }
  209. return (*ppDoc2) ? S_OK : E_NOINTERFACE;
  210. }
  211. HRESULT GetWin2FromDoc2(IHTMLDocument2 *pDoc2, IHTMLWindow2 **ppWin2)
  212. {
  213. ATLASSERT(NULL != ppWin2);
  214. *ppWin2 = NULL;
  215. if (pDoc2)
  216. {
  217. pDoc2->get_parentWindow(ppWin2);
  218. }
  219. return (NULL != *ppWin2) ? S_OK : E_FAIL;
  220. }
  221. HRESULT GetWin2FromAxWindow(CMarsAxWindow *pAxWin, IHTMLWindow2 **ppWin2)
  222. {
  223. CComPtr<IHTMLDocument2> spDoc2;
  224. GetDoc2FromAxWindow(pAxWin, &spDoc2);
  225. return GetWin2FromDoc2(spDoc2, ppWin2);
  226. }
  227. HRESULT GetControlWindow(CMarsAxWindow *pAxWin, HWND *phwnd)
  228. {
  229. CComPtr<IOleWindow> spOleWindow;
  230. if (SUCCEEDED(pAxWin->QueryControl(&spOleWindow)) &&
  231. SUCCEEDED(spOleWindow->GetWindow(phwnd)))
  232. {
  233. ATLASSERT((*phwnd != (HWND)-1) && (*phwnd != NULL));
  234. return S_OK;
  235. }
  236. return E_FAIL;
  237. }