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.

314 lines
9.5 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "resource.h"
  4. #include "wizard.h"
  5. typedef struct tagGuardData
  6. {
  7. CWizard * pWizard;
  8. CWizProvider * pWizProvider;
  9. } GuardData;
  10. BOOL OnGuardPageActivate(HWND hwndDlg)
  11. {
  12. TraceFileFunc(ttidGuiModeSetup);
  13. HPROPSHEETPAGE hPage;
  14. GuardData * pData = reinterpret_cast<GuardData *>(::GetWindowLongPtr(hwndDlg, DWLP_USER));
  15. TraceTag(ttidWizard, "Entering guard page...");
  16. Assert(NULL != pData);
  17. CWizard * pWizard = pData->pWizard;
  18. CWizProvider * pWizProvider = pData->pWizProvider;
  19. LPARAM ulId = reinterpret_cast<LPARAM>(pWizProvider);
  20. PAGEDIRECTION PageDir = pWizard->GetPageDirection(ulId);
  21. // If the current provider is not the provider whose pages this
  22. // page is guarding, return to the main or install mode page
  23. // as appropriate
  24. Assert(pWizard->GetCurrentProvider());
  25. if (pWizProvider != pWizard->GetCurrentProvider())
  26. {
  27. // Doesn't hurt to set this providers guard page to face forward
  28. pWizard->SetPageDirection(ulId, NWPD_FORWARD);
  29. // Since guard pages always follow a provider's pages, and in the
  30. // LAN case there is only one provider. We can assert that this is
  31. // the post install case, and that we're not processing the LAN, and
  32. // that the Main page exists
  33. Assert(IsPostInstall(pWizard));
  34. Assert(!pWizard->FProcessLanPages());
  35. CWizProvider* pWizProvider = pWizard->GetCurrentProvider();
  36. switch (pWizProvider->GetBtnIdc())
  37. {
  38. case CHK_MAIN_PPPOE:
  39. case CHK_MAIN_INTERNET:
  40. Assert(NULL != pWizard->GetPageHandle(IDD_Internet_Connection));
  41. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Internet_Connection);
  42. TraceTag(ttidWizard, "Guard page to Internet page...");
  43. break;
  44. // return to the Connect menu dialog
  45. case CHK_MAIN_DIALUP:
  46. case CHK_MAIN_VPN:
  47. Assert(NULL != pWizard->GetPageHandle(IDD_Connect));
  48. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Connect);
  49. TraceTag(ttidWizard, "Guard page to Connect page...");
  50. break;
  51. // return to the Advanced menu dialog
  52. case CHK_MAIN_INBOUND:
  53. case CHK_MAIN_DIRECT:
  54. Assert(NULL != pWizard->GetPageHandle(IDD_Advanced));
  55. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Advanced);
  56. TraceTag(ttidWizard, "Guard page to Advanced page...");
  57. break;
  58. // all others return to the Main dialog
  59. default:
  60. Assert(NULL != pWizard->GetPageHandle(IDD_Main));
  61. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Main);
  62. TraceTag(ttidWizard, "Guard page to Main page...");
  63. }
  64. }
  65. else
  66. {
  67. // This is the current providers guard page, which way do we go?
  68. if (NWPD_FORWARD == PageDir)
  69. {
  70. UINT idd;
  71. if (!IsPostInstall(pWizard))
  72. idd = IDD_FinishSetup;
  73. else
  74. idd = IDD_Finish;
  75. // Going forward means go to the finish page
  76. pWizard->SetPageDirection(ulId, NWPD_BACKWARD);
  77. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, idd);
  78. TraceTag(ttidWizard, "Guard page to Finish page...");
  79. }
  80. else
  81. {
  82. // Temporarily accept focus
  83. //
  84. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0);
  85. pWizard->SetPageDirection(ulId, NWPD_FORWARD);
  86. TraceTag(ttidWizard, "Guard page to last of the provider's pages...");
  87. // Going backward means go to the last of the provider's pages
  88. //
  89. Assert(0 < pWizProvider->ULPageCount());
  90. if (pWizard->FProcessLanPages())
  91. {
  92. // For the LAN case, jump directly to the last page
  93. //
  94. HPROPSHEETPAGE * rghPage = pWizProvider->PHPropPages();
  95. hPage = rghPage[pWizProvider->ULPageCount() - 1];
  96. PostMessage(GetParent(hwndDlg), PSM_SETCURSEL, 0,
  97. (LPARAM)(HPROPSHEETPAGE)hPage);
  98. }
  99. else
  100. {
  101. // The RAS pages don't want to work very hard at tracking
  102. // direction and supporting jumping to their last page so
  103. // we'll help them a bit by accepting focus here and then
  104. // backing up
  105. //
  106. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_BACK);
  107. }
  108. }
  109. }
  110. return TRUE;
  111. }
  112. //
  113. // Function: dlgprocGuard
  114. //
  115. // Purpose: Dialog Procedure for the Guard wizard page
  116. //
  117. // Parameters: standard dlgproc parameters
  118. //
  119. // Returns: INT_PTR
  120. //
  121. INT_PTR CALLBACK dlgprocGuard( HWND hwndDlg, UINT uMsg,
  122. WPARAM wParam, LPARAM lParam )
  123. {
  124. TraceFileFunc(ttidGuiModeSetup);
  125. BOOL frt = FALSE;
  126. switch (uMsg)
  127. {
  128. case WM_INITDIALOG:
  129. {
  130. // Initialize our pointers to property sheet info.
  131. PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
  132. Assert(psp->lParam);
  133. ::SetWindowLongPtr(hwndDlg, DWLP_USER, psp->lParam);
  134. }
  135. break;
  136. case WM_NOTIFY:
  137. {
  138. LPNMHDR pnmh = (LPNMHDR)lParam;
  139. switch (pnmh->code)
  140. {
  141. // propsheet notification
  142. case PSN_HELP:
  143. break;
  144. case PSN_SETACTIVE:
  145. frt = OnGuardPageActivate( hwndDlg );
  146. break;
  147. case PSN_APPLY:
  148. break;
  149. case PSN_KILLACTIVE:
  150. break;
  151. case PSN_RESET:
  152. break;
  153. case PSN_WIZBACK:
  154. break;
  155. case PSN_WIZFINISH:
  156. break;
  157. case PSN_WIZNEXT:
  158. break;
  159. default:
  160. break;
  161. }
  162. }
  163. break;
  164. default:
  165. break;
  166. }
  167. return( frt );
  168. }
  169. //
  170. // Function: GuardPageCleanup
  171. //
  172. // Purpose: As a callback function to allow any page allocated memory
  173. // to be cleaned up, after the page will no longer be accessed.
  174. //
  175. // Parameters: pWizard [IN] - The wizard against which the page called
  176. // register page
  177. // lParam [IN] - The lParam supplied in the RegisterPage call
  178. //
  179. // Returns: nothing
  180. //
  181. VOID GuardPageCleanup(CWizard *pWizard, LPARAM lParam)
  182. {
  183. TraceFileFunc(ttidGuiModeSetup);
  184. #if DBG
  185. CWizProvider *p = reinterpret_cast<CWizProvider *>(lParam);
  186. #endif
  187. MemFree(reinterpret_cast<void*>(lParam));
  188. }
  189. //
  190. // Function: HrCreateGuardPage
  191. //
  192. // Purpose: To determine if the Guard page needs to be shown, and to
  193. // to create the page if requested. Note the Guard page is
  194. // responsible for initial installs also.
  195. //
  196. // Parameters: pWizard [IN] - Ptr to a Wizard instance
  197. // pWizProvider [IN] - Ptr to the wizard provider this guard
  198. // page will be associated with.
  199. //
  200. // Returns: HRESULT, S_OK on success
  201. //
  202. NOTHROW
  203. HRESULT HrCreateGuardPage(CWizard *pWizard, CWizProvider *pWizProvider)
  204. {
  205. TraceFileFunc(ttidGuiModeSetup);
  206. HRESULT hr = E_OUTOFMEMORY;
  207. HPROPSHEETPAGE hpsp;
  208. PROPSHEETPAGE psp;
  209. GuardData * pData = reinterpret_cast<GuardData*>(MemAlloc(sizeof(GuardData)));
  210. if (pData)
  211. {
  212. TraceTag(ttidWizard, "Creating Guard Page");
  213. psp.dwSize = sizeof( PROPSHEETPAGE );
  214. psp.dwFlags = 0;
  215. psp.hInstance = _Module.GetResourceInstance();
  216. psp.pszTemplate = MAKEINTRESOURCE(IDD_Guard);
  217. psp.hIcon = NULL;
  218. psp.pfnDlgProc = dlgprocGuard;
  219. psp.lParam = reinterpret_cast<LPARAM>(pData);
  220. hpsp = CreatePropertySheetPage(&psp);
  221. if (hpsp)
  222. {
  223. pData->pWizard = pWizard;
  224. pData->pWizProvider = pWizProvider;
  225. pWizard->RegisterPage(reinterpret_cast<LPARAM>(pWizProvider),
  226. hpsp, GuardPageCleanup,
  227. reinterpret_cast<LPARAM>(pData));
  228. hr = S_OK;
  229. }
  230. else
  231. {
  232. MemFree(pData);
  233. }
  234. }
  235. TraceHr(ttidWizard, FAL, hr, FALSE, "HrGetGuardPage");
  236. return hr;
  237. }
  238. //
  239. // Function: AppendGuardPage
  240. //
  241. // Purpose: Add the Guard page, if it was created, to the set of pages
  242. // that will be displayed.
  243. //
  244. // Parameters: pWizard [IN] - Ptr to a Wizard instance
  245. // pWizProvider [IN] - Ptr to a WizProvider instance
  246. // pahpsp [IN,OUT] - Array of pages to add our page to
  247. // pcPages [IN,OUT] - Count of pages in pahpsp
  248. //
  249. // Returns: Nothing
  250. //
  251. VOID AppendGuardPage(CWizard *pWizard, CWizProvider *pWizProvider,
  252. HPROPSHEETPAGE* pahpsp, UINT *pcPages)
  253. {
  254. TraceFileFunc(ttidGuiModeSetup);
  255. Assert(NULL != pWizard);
  256. Assert(NULL != pWizProvider);
  257. HPROPSHEETPAGE hPage = pWizard->GetPageHandle(reinterpret_cast<LPARAM>(pWizProvider));
  258. if (hPage)
  259. {
  260. pahpsp[*pcPages] = hPage;
  261. (*pcPages)++;
  262. }
  263. else
  264. {
  265. // page should be there
  266. Assert(0);
  267. }
  268. }