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.

504 lines
12 KiB

  1. /*
  2. * h o t w i z u i . c p p
  3. *
  4. * Purpose:
  5. * HotMail Wizard UI
  6. *
  7. * History
  8. *
  9. * Copyright (C) Microsoft Corp. 1995, 1996.
  10. */
  11. #include <pch.hxx>
  12. #include <mshtml.h>
  13. #include <mshtmhst.h>
  14. #include <mimeole.h>
  15. #include "dllmain.h"
  16. #include <hotwiz.h>
  17. #include "hotwizui.h"
  18. #include "hotwizom.h"
  19. #include "shlwapi.h"
  20. #include "resource.h"
  21. #define CX_DEF_WIZARD 503
  22. #define CY_DEF_WIZARD 400
  23. typedef BOOL (WINAPI *PFNDLLREGWNDCLASS)(const SHDRC * pshdrc);
  24. //+---------------------------------------------------------------
  25. //
  26. // Member: Constructor
  27. //
  28. // Synopsis:
  29. //
  30. //---------------------------------------------------------------
  31. CHotMailWizard::CHotMailWizard()
  32. {
  33. m_hwnd=NULL;
  34. m_hwndOC=NULL;
  35. m_hwndOwner = NULL;
  36. m_cRef=1;
  37. m_pXTag = NULL;
  38. m_prc = NULL;
  39. m_pszFriendlyW = NULL;
  40. m_pszUrlW = NULL;
  41. m_fPrompt = TRUE;
  42. m_pWizHost = NULL;
  43. DllAddRef();
  44. }
  45. //+---------------------------------------------------------------
  46. //
  47. // Member: Destructor
  48. //
  49. // Synopsis:
  50. //
  51. //---------------------------------------------------------------
  52. CHotMailWizard::~CHotMailWizard()
  53. {
  54. ReleaseObj(m_pXTag);
  55. DllRelease();
  56. }
  57. ULONG CHotMailWizard::AddRef()
  58. {
  59. return ++m_cRef;
  60. }
  61. ULONG CHotMailWizard::Release()
  62. {
  63. m_cRef--;
  64. if (m_cRef == 0)
  65. {
  66. delete this;
  67. return 0;
  68. }
  69. return m_cRef;
  70. }
  71. HRESULT CHotMailWizard::QueryInterface(REFIID riid, LPVOID *lplpObj)
  72. {
  73. if(!lplpObj)
  74. return E_INVALIDARG;
  75. *lplpObj = NULL; // set to NULL, in case we fail.
  76. if (IsEqualIID(riid, IID_IUnknown))
  77. *lplpObj = (LPVOID)this;
  78. else if (IsEqualIID(riid, IID_IElementBehaviorFactory))
  79. *lplpObj = (LPVOID)(IElementBehaviorFactory*)this;
  80. else if (IsEqualIID(riid, IID_IServiceProvider))
  81. *lplpObj = (LPVOID)(IServiceProvider*)this;
  82. else if (IsEqualIID(riid, IID_IDocHostUIHandler))
  83. *lplpObj = (LPVOID)(IDocHostUIHandler *)this;
  84. else if (IsEqualIID(riid, IID_IHotWizard))
  85. *lplpObj = (LPVOID)(IHotWizard *)this;
  86. else
  87. return E_NOINTERFACE;
  88. AddRef();
  89. return NOERROR;
  90. }
  91. INT_PTR CALLBACK CHotMailWizard::ExtDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  92. {
  93. CHotMailWizard *pThis;
  94. if(msg==WM_INITDIALOG)
  95. {
  96. pThis=(CHotMailWizard *)lParam;
  97. if(!pThis)
  98. return -1;
  99. if(FAILED(pThis->_OnInitDialog(hwnd)))
  100. return -1;
  101. }
  102. pThis = (CHotMailWizard *)GetWindowLongPtr(hwnd, DWLP_USER);
  103. return pThis ? pThis->_DlgProc(hwnd, msg, wParam, lParam) : FALSE;
  104. }
  105. HRESULT CHotMailWizard::_OnInitDialog(HWND hwnd)
  106. {
  107. LPRECT prc;
  108. RECT rc;
  109. HRESULT hr = S_OK;
  110. TCHAR rgch[CCHMAX_STRINGRES + 100],
  111. rgchFmt[CCHMAX_STRINGRES];
  112. LPSTR pszFriendly=NULL;
  113. // setup local vars
  114. m_hwnd = hwnd;
  115. SetWindowLongPtr(hwnd, DWLP_USER, (LPARAM)this);
  116. // figure out initial size, use default if non specified
  117. if (!m_prc)
  118. {
  119. SetRect(&rc, 0, 0, CX_DEF_WIZARD, CY_DEF_WIZARD);
  120. prc = &rc;
  121. }
  122. else
  123. prc = m_prc;
  124. // create WebOC
  125. IF_FAILEXIT(hr = _CreateOCHost());
  126. // load our page
  127. _LoadPage(m_pszUrlW);
  128. // size the dialog
  129. SetWindowPos(hwnd, 0, prc->left, prc->top, prc->right - prc->left, prc->bottom - prc->top, SWP_NOZORDER);
  130. // if no rect was passed in then center the dialog
  131. if (!m_prc)
  132. CenterDialog(hwnd);
  133. // if the dialog passed in a friendly name, set the dialog title to reflect this
  134. if (m_pszFriendlyW)
  135. {
  136. IF_NULLEXIT(pszFriendly = PszToANSI(CP_ACP, m_pszFriendlyW));
  137. if (LoadString(g_hInstRes, idsFmtSetupAccount, rgchFmt, ARRAYSIZE(rgchFmt)))
  138. {
  139. wnsprintf(rgch, ARRAYSIZE(rgch), rgchFmt, pszFriendly);
  140. SetWindowText(hwnd, rgch);
  141. }
  142. }
  143. // success - addref ourselves (released in NCDESTROY)
  144. AddRef();
  145. // disable parent window if we are modal
  146. if (m_hwndOwner)
  147. EnableWindow(m_hwndOwner, FALSE);
  148. exit:
  149. MemFree(pszFriendly);
  150. return hr;
  151. }
  152. HRESULT CHotMailWizard::_OnNCDestroy()
  153. {
  154. SetWindowLongPtr(m_hwnd, DWLP_USER, NULL);
  155. m_hwnd = NULL;
  156. Release();
  157. PostQuitMessage(0);
  158. return S_OK;
  159. }
  160. BOOL CHotMailWizard::_DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  161. {
  162. RECT rc;
  163. LPSTR psz;
  164. HRESULT hr;
  165. TCHAR rgch[CCHMAX_STRINGRES];
  166. switch (msg)
  167. {
  168. case WM_SIZE:
  169. if (m_hwndOC)
  170. {
  171. RECT rc;
  172. GetClientRect(hwnd, &rc);
  173. SetWindowPos(m_hwndOC, NULL, 0, 0, rc.right, rc.bottom, SWP_NOZORDER|SWP_NOMOVE);
  174. }
  175. break;
  176. case HWM_SETDIRTY:
  177. m_fPrompt = (BOOL) wParam;
  178. break;
  179. case WM_CLOSE:
  180. *rgch=0;
  181. GetWindowText(hwnd, rgch, ARRAYSIZE(rgch));
  182. if (m_fPrompt &&
  183. MessageBoxInst(g_hInstRes, m_hwnd, rgch, MAKEINTRESOURCE(idsPromptCloseWiz), NULL, MB_OKCANCEL)==IDCANCEL)
  184. return 0;
  185. if (m_hwndOwner)
  186. EnableWindow(m_hwndOwner, TRUE);
  187. DestroyWindow(hwnd);
  188. break;
  189. case WM_DESTROY:
  190. m_hwndOC = NULL;
  191. break;
  192. case WM_NCDESTROY:
  193. _OnNCDestroy();
  194. break;
  195. }
  196. return FALSE;
  197. };
  198. HRESULT CHotMailWizard::TranslateAccelerator(MSG *lpmsg)
  199. {
  200. IOleInPlaceActiveObject *pIPAO=0;
  201. HRESULT hr = S_FALSE;
  202. if (m_hwndOC &&
  203. OCHost_QueryInterface(m_hwndOC, IID_IOleInPlaceActiveObject, (LPVOID*)&pIPAO)==S_OK)
  204. {
  205. hr = pIPAO->TranslateAccelerator(lpmsg);
  206. pIPAO->Release();
  207. }
  208. return hr;
  209. }
  210. HRESULT CHotMailWizard::_CreateOCHost()
  211. {
  212. HRESULT hr = E_FAIL;
  213. // Create an OCHost window
  214. m_hwndOC = CreateWindow(OCHOST_CLASS, NULL,
  215. WS_CHILD|WS_TABSTOP|WS_VISIBLE,
  216. 0, 0, 300, 300,
  217. m_hwnd, NULL, g_hInst, NULL);
  218. if (m_hwndOC)
  219. {
  220. OCHINITSTRUCT ocs;
  221. ocs.cbSize = sizeof(OCHINITSTRUCT);
  222. ocs.clsidOC = CLSID_WebBrowser;
  223. ocs.punkOwner = (IUnknown *)(IServiceProvider *)this;
  224. hr = OCHost_InitOC(m_hwndOC, (LPARAM)&ocs);
  225. if (!FAILED(hr))
  226. {
  227. OCHost_DoVerb(m_hwndOC, OLEIVERB_INPLACEACTIVATE, FALSE);
  228. OCHost_DoVerb(m_hwndOC, OLEIVERB_UIACTIVATE, FALSE);
  229. OCHost_DoVerb(m_hwndOC, OLEIVERB_SHOW, FALSE);
  230. }
  231. }
  232. return hr;
  233. }
  234. HRESULT CHotMailWizard::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
  235. {
  236. // don't show a default menu
  237. if (dwID == CONTEXT_MENU_DEFAULT)
  238. return S_OK;
  239. return E_NOTIMPL;
  240. }
  241. HRESULT CHotMailWizard::ShowUI(DWORD dwID, IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame,IOleInPlaceUIWindow *pDoc)
  242. {
  243. return E_NOTIMPL;
  244. }
  245. HRESULT CHotMailWizard::HideUI()
  246. {
  247. return E_NOTIMPL;
  248. }
  249. HRESULT CHotMailWizard::UpdateUI()
  250. {
  251. return E_NOTIMPL;
  252. }
  253. HRESULT CHotMailWizard::EnableModeless(BOOL fActivate)
  254. {
  255. return E_NOTIMPL;
  256. }
  257. HRESULT CHotMailWizard::OnDocWindowActivate(BOOL fActivate)
  258. {
  259. return E_NOTIMPL;
  260. }
  261. HRESULT CHotMailWizard::OnFrameWindowActivate(BOOL fActivate)
  262. {
  263. return E_NOTIMPL;
  264. }
  265. HRESULT CHotMailWizard::ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
  266. {
  267. return E_NOTIMPL;
  268. }
  269. HRESULT CHotMailWizard::TranslateAccelerator(LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
  270. {
  271. return E_NOTIMPL;
  272. }
  273. HRESULT CHotMailWizard::GetOptionKeyPath(LPOLESTR *pchKey, DWORD dw)
  274. {
  275. return E_NOTIMPL;
  276. }
  277. HRESULT CHotMailWizard::GetDropTarget(IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
  278. {
  279. return E_NOTIMPL;
  280. }
  281. HRESULT CHotMailWizard::GetExternal(IDispatch **ppDispatch)
  282. {
  283. return E_NOTIMPL;
  284. }
  285. HRESULT CHotMailWizard::TranslateUrl(DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
  286. {
  287. return E_NOTIMPL;
  288. }
  289. HRESULT CHotMailWizard::FilterDataObject( IDataObject *pDO, IDataObject **ppDORet)
  290. {
  291. return E_NOTIMPL;
  292. }
  293. HRESULT CHotMailWizard::QueryService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
  294. {
  295. if (IsEqualGUID(guidService, SID_SElementBehaviorFactory))
  296. return QueryInterface(riid, ppvObject);
  297. return E_NOTIMPL;
  298. }
  299. HRESULT CHotMailWizard::FindBehavior(LPOLESTR pchBehavior, LPOLESTR pchBehaviorUrl, IElementBehaviorSite* pSite, IElementBehavior** ppBehavior)
  300. {
  301. HRESULT hr=S_OK;
  302. COEHotWizOm *pWizOM=NULL;
  303. if ((StrCmpIW(pchBehavior, L"WIZARD")==0 && StrCmpIW(pchBehaviorUrl, L"#DEFAULT#WIZARD")==0))
  304. {
  305. if (m_pXTag == NULL)
  306. {
  307. pWizOM = new COEHotWizOm();
  308. if (!pWizOM)
  309. return E_OUTOFMEMORY;
  310. hr = pWizOM->Init(m_hwnd, m_pWizHost);
  311. if (FAILED(hr))
  312. goto error;
  313. hr = pWizOM->QueryInterface(IID_IElementBehavior, (LPVOID *)&m_pXTag);
  314. if (FAILED(hr))
  315. goto error;
  316. // Now that we have IElementBehaviour, release the "IUnknown" we got from new COEHotWizOm()
  317. pWizOM->Release();
  318. }
  319. if (m_pXTag)
  320. {
  321. *ppBehavior = m_pXTag;
  322. m_pXTag->AddRef();
  323. return S_OK;
  324. }
  325. }
  326. error:
  327. ReleaseObj(pWizOM);
  328. return hr;
  329. }
  330. HRESULT CHotMailWizard::GetHostInfo(DOCHOSTUIINFO *pInfo)
  331. {
  332. pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
  333. pInfo->dwFlags = DOCHOSTUIFLAG_SCROLL_NO|DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY|DOCHOSTUIFLAG_NO3DBORDER;
  334. //This sets the flags that match the browser's encoding
  335. fGetBrowserUrlEncoding(&pInfo->dwFlags);
  336. pInfo->pchHostCss = PszDupW(L"OE\\:WIZARD { behavior:url(#DEFAULT#WIZARD) }");
  337. pInfo->pchHostNS = PszDupW(L"OE");
  338. return S_OK;
  339. }
  340. HRESULT CHotMailWizard::Show(HWND hwndOwner, LPWSTR pszUrl, LPWSTR pszCaption, IHotWizardHost *pWizHost, RECT *prc)
  341. {
  342. HRESULT hr=E_FAIL;
  343. MSG msg;
  344. HINSTANCE hShDocVw=NULL;
  345. PFNDLLREGWNDCLASS pfnRegisterClass;
  346. SHDRC shdrc;
  347. HWND hwnd;
  348. if (pszUrl == NULL)
  349. return E_INVALIDARG;
  350. hShDocVw = LoadLibrary("SHDOCVW.DLL");
  351. if (!hShDocVw)
  352. goto error;
  353. pfnRegisterClass = (PFNDLLREGWNDCLASS)GetProcAddress(hShDocVw, "DllRegisterWindowClasses");
  354. if (!pfnRegisterClass)
  355. goto error;
  356. shdrc.cbSize = sizeof(SHDRC);
  357. shdrc.dwFlags = SHDRCF_OCHOST;
  358. if (!pfnRegisterClass(&shdrc))
  359. goto error;
  360. // stuff the data we care about into members
  361. m_prc = prc;
  362. m_hwndOwner = hwndOwner;
  363. m_pszUrlW = pszUrl;
  364. m_pszFriendlyW = pszCaption;
  365. m_pWizHost = pWizHost; // Modal, so no need to AddRef
  366. // show the dialog
  367. hwnd = CreateDialogParam(g_hInstRes, MAKEINTRESOURCE(iddHotWizDlg), m_hwndOwner, CHotMailWizard::ExtDlgProc, (LONG_PTR)this);
  368. if (!hwnd)
  369. return E_FAIL;
  370. while (GetMessage(&msg, NULL, 0, 0))
  371. {
  372. if(TranslateAccelerator(&msg) == S_OK)
  373. continue;
  374. TranslateMessage(&msg);
  375. DispatchMessage(&msg);
  376. }
  377. hr = S_OK;
  378. error:
  379. if (hShDocVw)
  380. FreeLibrary(hShDocVw);
  381. return hr;
  382. }
  383. HRESULT CHotMailWizard::_LoadPage(LPWSTR pszUrlW)
  384. {
  385. IWebBrowser *pWebOC;
  386. HRESULT hr = E_FAIL;
  387. if (m_hwndOC &&
  388. OCHost_QueryInterface(m_hwndOC, IID_IWebBrowser, (LPVOID*)&pWebOC)==S_OK)
  389. {
  390. hr = pWebOC->Navigate(pszUrlW, 0, 0, 0, 0);
  391. pWebOC->Release();
  392. }
  393. return hr;
  394. }