Source code of Windows XP (NT5)
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.

444 lines
13 KiB

  1. // ***************************************************************************
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include "resource.h"
  5. #include "wizard.h"
  6. #include "ncreg.h"
  7. #include "ncui.h"
  8. extern const WCHAR c_szEmpty[];
  9. // ***************************************************************************
  10. // Function: SetupFonts
  11. //
  12. // Purpose: Generate bold or large bold fonts based on the font of the
  13. // window specified
  14. //
  15. // Parameters: hwnd [IN] - Handle of window to base font on
  16. // pBoldFont [OUT] - The newly generated font, NULL if the
  17. // font could not be generated
  18. // fLargeFont [IN] - If TRUE, generate a 12 point bold font for
  19. // use in the wizard "welcome" page.
  20. //
  21. // Returns: nothing
  22. // ***************************************************************************
  23. VOID SetupConnectFonts(HWND hwnd, HFONT * pBoldFont, BOOL fLargeFont)
  24. {
  25. LOGFONT BoldLogFont;
  26. HFONT hFont;
  27. WCHAR FontSizeString[MAX_PATH];
  28. INT FontSize;
  29. Assert(pBoldFont);
  30. *pBoldFont = NULL;
  31. // Get the font used by the specified window
  32. hFont = (HFONT)::SendMessage(hwnd, WM_GETFONT, 0, 0L);
  33. if (NULL == hFont)
  34. {
  35. // If not found then the control is using the system font
  36. hFont = (HFONT)GetStockObject(SYSTEM_FONT);
  37. }
  38. if (hFont)
  39. {
  40. // Get the font info so we can generate the BOLD version
  41. if (GetObject(hFont, sizeof(BoldLogFont), &BoldLogFont))
  42. {
  43. // Create the Bold Font
  44. BoldLogFont.lfWeight = FW_BOLD;
  45. HDC hdc = GetDC(hwnd);
  46. if (hdc)
  47. {
  48. // Large (tall) font is an option
  49. if (fLargeFont)
  50. {
  51. // Load size and name from resources, since these may change
  52. // from locale to locale based on the size of the system font, etc.
  53. UINT nLen = lstrlenW(SzLoadIds(IDS_LARGEFONTNAME));
  54. if ((0 < nLen) && (nLen < LF_FACESIZE))
  55. {
  56. lstrcpyW(BoldLogFont.lfFaceName,SzLoadIds(IDS_LARGEFONTNAME));
  57. }
  58. FontSize = 12;
  59. nLen = lstrlen(SzLoadIds(IDS_LARGEFONTSIZE));
  60. if ((nLen < celems(FontSizeString)) && (0 < nLen))
  61. {
  62. lstrcpyW(FontSizeString, SzLoadIds(IDS_LARGEFONTSIZE));
  63. FontSize = wcstoul(FontSizeString, NULL, 10);
  64. }
  65. BoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  66. }
  67. *pBoldFont = CreateFontIndirect(&BoldLogFont);
  68. ReleaseDC(hwnd, hdc);
  69. }
  70. }
  71. }
  72. }
  73. // ***************************************************************************
  74. // Function: OnConnectPageActivate
  75. //
  76. // Purpose: Handle the PSN_SETACTIVE notification
  77. //
  78. // Parameters: hwndDlg [IN] - Handle to the Connect dialog
  79. //
  80. // Returns: BOOL
  81. // ***************************************************************************
  82. BOOL OnConnectPageActivate(HWND hwndDlg)
  83. {
  84. TraceTag(ttidWizard, "Entering Connect Menu page...");
  85. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0L);
  86. CWizard * pWizard =
  87. reinterpret_cast<CWizard *>(::GetWindowLongPtr(hwndDlg, DWLP_USER));
  88. Assert(NULL != pWizard);
  89. if (pWizard->GetFirstPage() == IDD_Connect)
  90. {
  91. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
  92. }
  93. else
  94. {
  95. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  96. }
  97. return TRUE;
  98. }
  99. // ***************************************************************************
  100. // Function: OnConnectWizNext
  101. //
  102. // Purpose: Handle the PSN_WIZNEXT notification
  103. //
  104. // Parameters: hwndDlg [IN] - Handle to the Connect dialog
  105. //
  106. // Returns: BOOL
  107. // ***************************************************************************
  108. BOOL OnConnectWizNext(HWND hwndDlg)
  109. {
  110. tstring str;
  111. // Retrieve the CWizard instance from the dialog
  112. CWizard * pWizard =
  113. reinterpret_cast<CWizard *>(::GetWindowLongPtr(hwndDlg, DWLP_USER));
  114. Assert(NULL != pWizard);
  115. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  116. if ( ! IsPostInstall(pWizard) || (0 == pWizard->UlProviderCount()))
  117. {
  118. return TRUE;
  119. }
  120. // Find the selected provider and go to it's first page
  121. for (ULONG ulIdx = 0; ulIdx < pWizard->UlProviderCount(); ulIdx++)
  122. {
  123. CWizProvider * pWizProvider = pWizard->PWizProviders(ulIdx);
  124. Assert(NULL != pWizProvider);
  125. Assert(0 != pWizProvider->ULPageCount());
  126. if (IsDlgButtonChecked(hwndDlg, pWizProvider->GetBtnIdc()))
  127. {
  128. pWizard->SetCurrentProvider(ulIdx);
  129. HPROPSHEETPAGE hPage = (pWizProvider->PHPropPages())[0];
  130. Assert(NULL != hPage);
  131. PostMessage(GetParent(hwndDlg), PSM_SETCURSEL, 0,
  132. (LPARAM)(HPROPSHEETPAGE)hPage);
  133. }
  134. }
  135. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  136. return TRUE;
  137. }
  138. // ***************************************************************************
  139. BOOL OnConnectDialogInit(HWND hwndDlg, LPARAM lParam)
  140. {
  141. INT nIdx;
  142. INT nrgIdc[] = {CHK_MAIN_DIALUP, TXT_MAIN_DIALUP_1,
  143. CHK_MAIN_VPN, TXT_MAIN_VPN_1};
  144. // The order here should be the same as the vertical order in the resources
  145. INT nrgChks[] = {CHK_MAIN_DIALUP, CHK_MAIN_VPN};
  146. // Initialize our pointers to property sheet info.
  147. PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
  148. Assert(psp->lParam);
  149. ::SetWindowLongPtr(hwndDlg, DWLP_USER, psp->lParam);
  150. CWizard * pWizard = reinterpret_cast<CWizard *>(psp->lParam);
  151. Assert(NULL != pWizard);
  152. if (pWizard->GetFirstPage() == IDD_Connect)
  153. {
  154. pWizard->LoadAndInsertDeferredProviderPages(::GetParent(hwndDlg), IDD_Advanced);
  155. }
  156. // Get the bold font for the radio buttons
  157. HFONT hBoldFont = NULL;
  158. SetupConnectFonts(hwndDlg, &hBoldFont, FALSE);
  159. if (NULL != hBoldFont)
  160. {
  161. // Remember the font handle so we can free it on exit
  162. pWizard->SetPageData(IDD_Connect, (LPARAM)hBoldFont);
  163. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  164. {
  165. HWND hwndCtl = GetDlgItem(hwndDlg, nrgChks[nIdx]);
  166. Assert(NULL != hwndCtl);
  167. SetWindowFont(hwndCtl, hBoldFont, TRUE);
  168. }
  169. }
  170. // Populate the UI
  171. for (ULONG ulIdx = 0;
  172. ulIdx < pWizard->UlProviderCount();
  173. ulIdx++)
  174. {
  175. CWizProvider * pWizProvider = pWizard->PWizProviders(ulIdx);
  176. Assert(NULL != pWizProvider);
  177. Assert(0 != pWizProvider->ULPageCount());
  178. // Get the radio button associated with this provider
  179. INT nIdcBtn = pWizProvider->GetBtnIdc();
  180. // Find the set of controls to enable in the array
  181. for (nIdx = 0; nIdx < celems(nrgIdc); nIdx += 2)
  182. {
  183. if (nrgIdc[nIdx] == nIdcBtn)
  184. {
  185. // Enable the controls
  186. for (INT un = 0; un < 2; un++)
  187. {
  188. HWND hwndBtn = GetDlgItem(hwndDlg, nrgIdc[nIdx + un]);
  189. Assert(NULL != hwndBtn);
  190. EnableWindow(hwndBtn, TRUE);
  191. }
  192. break;
  193. }
  194. }
  195. }
  196. // Find the top most enabled radio button
  197. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  198. {
  199. if (IsWindowEnabled(GetDlgItem(hwndDlg, nrgChks[nIdx])))
  200. {
  201. CheckRadioButton(hwndDlg, CHK_MAIN_DIALUP, CHK_MAIN_VPN, nrgChks[nIdx]);
  202. break;
  203. }
  204. }
  205. return TRUE;
  206. }
  207. // ***************************************************************************
  208. // Function: dlgprocConnect
  209. //
  210. // Purpose: Dialog Procedure for the Connect wizard page
  211. //
  212. // Parameters: standard dlgproc parameters
  213. //
  214. // Returns: INT_PTR
  215. // ***************************************************************************
  216. INT_PTR CALLBACK dlgprocConnect( HWND hwndDlg, UINT uMsg,
  217. WPARAM wParam, LPARAM lParam )
  218. {
  219. BOOL frt = FALSE;
  220. switch (uMsg)
  221. {
  222. case WM_INITDIALOG:
  223. frt = OnConnectDialogInit(hwndDlg, lParam);
  224. break;
  225. case WM_NOTIFY:
  226. {
  227. LPNMHDR pnmh = (LPNMHDR)lParam;
  228. switch (pnmh->code)
  229. {
  230. // propsheet notification
  231. case PSN_HELP:
  232. break;
  233. case PSN_SETACTIVE:
  234. frt = OnConnectPageActivate(hwndDlg);
  235. break;
  236. case PSN_APPLY:
  237. break;
  238. case PSN_KILLACTIVE:
  239. break;
  240. case PSN_RESET:
  241. break;
  242. case PSN_WIZBACK:
  243. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Main);
  244. return(TRUE);
  245. case PSN_WIZFINISH:
  246. break;
  247. case PSN_WIZNEXT:
  248. frt = OnConnectWizNext(hwndDlg);
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. break;
  255. default:
  256. break;
  257. }
  258. return(frt);
  259. }
  260. // ***************************************************************************
  261. // Function: ConnectPageCleanup
  262. //
  263. // Purpose: As a callback function to allow any page allocated memory
  264. // to be cleaned up, after the page will no longer be accessed.
  265. //
  266. // Parameters: pWizard [IN] - The wizard against which the page called
  267. // register page
  268. // lParam [IN] - The lParam supplied in the RegisterPage call
  269. // ***************************************************************************
  270. VOID ConnectPageCleanup(CWizard *pWizard, LPARAM lParam)
  271. {
  272. HFONT hBoldFont = (HFONT)pWizard->GetPageData(IDD_Connect);
  273. if (NULL != hBoldFont)
  274. {
  275. DeleteObject(hBoldFont);
  276. }
  277. }
  278. // ***************************************************************************
  279. // Function: CreateConnectPage
  280. //
  281. // Purpose: To determine if the Connect page needs to be shown, and to
  282. // to create the page if requested. Note the Main page is
  283. // responsible for initial installs also.
  284. //
  285. // Parameters: pWizard [IN] - Ptr to a Wizard instance
  286. // pData [IN] - Context data to describe the world in
  287. // which the Wizard will be run
  288. // fCountOnly [IN] - If True, only the maximum number of
  289. // pages this routine will create need
  290. // be determined.
  291. // pnPages [IN] - Increment by the number of pages
  292. // to create/created
  293. //
  294. // Returns: HRESULT, S_OK on success
  295. // ***************************************************************************
  296. HRESULT HrCreateConnectPage(CWizard *pWizard, PINTERNAL_SETUP_DATA pData,
  297. BOOL fCountOnly, UINT *pnPages)
  298. {
  299. HRESULT hr = S_OK;
  300. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  301. {
  302. // RAS PostInstall only
  303. (*pnPages)++;
  304. // If not only counting, create and register the page
  305. if ( ! fCountOnly)
  306. {
  307. HPROPSHEETPAGE hpsp;
  308. PROPSHEETPAGE psp;
  309. TraceTag(ttidWizard, "Creating Connect Page");
  310. psp.dwSize = sizeof( PROPSHEETPAGE );
  311. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  312. psp.hInstance = _Module.GetResourceInstance();
  313. psp.pszTemplate = MAKEINTRESOURCE( IDD_Connect );
  314. psp.hIcon = NULL;
  315. psp.pfnDlgProc = dlgprocConnect;
  316. psp.lParam = reinterpret_cast<LPARAM>(pWizard);
  317. psp.pszHeaderTitle = SzLoadIds(IDS_T_Connect);
  318. psp.pszHeaderSubTitle = SzLoadIds(IDS_ST_Connect);
  319. hpsp = CreatePropertySheetPage( &psp );
  320. if (hpsp)
  321. {
  322. pWizard->RegisterPage(IDD_Connect, hpsp,
  323. ConnectPageCleanup, NULL);
  324. }
  325. else
  326. {
  327. hr = E_OUTOFMEMORY;
  328. }
  329. }
  330. }
  331. TraceHr(ttidWizard, FAL, hr, FALSE, "HrCreateConnectPage");
  332. return hr;
  333. }
  334. // ***************************************************************************
  335. // Function: AppendConnectPage
  336. //
  337. // Purpose: Add the Connect page, if it was created, to the set of pages
  338. // that will be displayed.
  339. //
  340. // Parameters: pWizard [IN] - Ptr to Wizard Instance
  341. // pahpsp [IN,OUT] - Array of pages to add our page to
  342. // pcPages [IN,OUT] - Count of pages in pahpsp
  343. // ***************************************************************************
  344. VOID AppendConnectPage(CWizard *pWizard, HPROPSHEETPAGE* pahpsp, UINT *pcPages)
  345. {
  346. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  347. {
  348. HPROPSHEETPAGE hPage = pWizard->GetPageHandle(IDD_Connect);
  349. Assert(hPage);
  350. pahpsp[*pcPages] = hPage;
  351. (*pcPages)++;
  352. }
  353. }
  354. // ***************************************************************************