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.

474 lines
15 KiB

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