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.

503 lines
17 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // USERINFO.CPP - Functions for
  7. //
  8. // HISTORY:
  9. //
  10. // 05/13/98 donaldm Created.
  11. // 08/19/98 donaldm BUGBUG: The code to collect and save the user
  12. // entered data is not optimal in terms of size
  13. // and can/should be cleaned up at some future time
  14. //
  15. //*********************************************************************
  16. #include "pre.h"
  17. #define BACK 0
  18. #define NEXT 1
  19. enum DlgLayout
  20. {
  21. LAYOUT_FE = 0,
  22. LAYOUT_JPN,
  23. LAYOUT_US
  24. };
  25. HWND hDlgUserInfoCompany = NULL;
  26. HWND hDlgUserInfoNoCompany = NULL;
  27. HWND hDlgCurrentUserInfo = NULL;
  28. WORD g_DlgLayout;
  29. // This function will initialize the data in the user information dialog edit controls.
  30. // The data used to initalize comes from the UserInfo object in ICWHELP.DLL
  31. void InitUserInformation
  32. (
  33. HWND hDlg
  34. )
  35. {
  36. BOOL bRetVal;
  37. IUserInfo *pUserInfo = gpWizardState->pUserInfo;
  38. BSTR bstr;
  39. // Get initial user info data values from the ICWHELP user info object, and
  40. // set the value in the ISPDATA object
  41. // we only need to do this 1 time per ICW session
  42. if(!gpWizardState->bUserEnteredData)
  43. {
  44. pUserInfo->CollectRegisteredUserInfo(&bRetVal);
  45. // Set this state varialbe, since the user has seen the user info page
  46. gpWizardState->bUserEnteredData = TRUE;
  47. }
  48. // The return value from CollectRegisteredUserInfo is FALSE if there is no data in the
  49. // registry. In this case we set bWasNoUserInfo so that we can persist it later. We
  50. // only want to persis the user info it we complete sucessfully, and if there was
  51. // no user info.
  52. gpWizardState->bWasNoUserInfo = !bRetVal;
  53. // Put all the initial values, with no validation
  54. pUserInfo->get_FirstName(&bstr);
  55. if (GetDlgItem(hDlg, IDC_USERINFO_FE_NAME))
  56. {
  57. SetDlgItemText(hDlg,IDC_USERINFO_FE_NAME, W2A(bstr));
  58. }
  59. else
  60. {
  61. SetDlgItemText(hDlg, IDC_USERINFO_FIRSTNAME, W2A(bstr));
  62. SysFreeString(bstr);
  63. pUserInfo->get_LastName(&bstr);
  64. SetDlgItemText(hDlg, IDC_USERINFO_LASTNAME, W2A(bstr));
  65. }
  66. SysFreeString(bstr);
  67. if (GetDlgItem(hDlg, IDC_USERINFO_COMPANYNAME))
  68. {
  69. pUserInfo->get_Company(&bstr);
  70. SetDlgItemText(hDlg, IDC_USERINFO_COMPANYNAME, W2A(bstr));
  71. SysFreeString(bstr);
  72. }
  73. pUserInfo->get_Address1(&bstr);
  74. SetDlgItemText(hDlg, IDC_USERINFO_ADDRESS1, W2A(bstr));
  75. SysFreeString(bstr);
  76. pUserInfo->get_Address2(&bstr);
  77. SetDlgItemText(hDlg, IDC_USERINFO_ADDRESS2, W2A(bstr));
  78. SysFreeString(bstr);
  79. pUserInfo->get_City(&bstr);
  80. SetDlgItemText(hDlg, IDC_USERINFO_CITY, W2A(bstr));
  81. SysFreeString(bstr);
  82. pUserInfo->get_State(&bstr);
  83. SetDlgItemText(hDlg, IDC_USERINFO_STATE, W2A(bstr));
  84. SysFreeString(bstr);
  85. pUserInfo->get_ZIPCode(&bstr);
  86. SetDlgItemText(hDlg, IDC_USERINFO_ZIP, W2A(bstr));
  87. SysFreeString(bstr);
  88. pUserInfo->get_PhoneNumber(&bstr);
  89. SetDlgItemText(hDlg, IDC_USERINFO_PHONE, W2A(bstr));
  90. SysFreeString(bstr);
  91. }
  92. BOOL bValidateSaveUserInformation (HWND hDlg, BOOL fForward)
  93. {
  94. UINT uCtrlID;
  95. BOOL bValid = FALSE;
  96. IUserInfo *pUserInfo = gpWizardState->pUserInfo;
  97. IICWISPData *pISPData = gpWizardState->pISPData;
  98. TCHAR szTemp[MAX_RES_LEN] = TEXT("\0");
  99. WORD wPrevValidationValue = 0;
  100. if (fForward)
  101. wPrevValidationValue = ISPDATA_Validate_DataPresent;
  102. else
  103. wPrevValidationValue = ISPDATA_Validate_None;
  104. while (1)
  105. {
  106. if (GetDlgItem(hDlg, IDC_USERINFO_FE_NAME))
  107. {
  108. uCtrlID = IDC_USERINFO_FE_NAME;
  109. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  110. if (!pISPData->PutDataElement(ISPDATA_USER_FE_NAME, szTemp, wPrevValidationValue))
  111. break;
  112. // Set the input data into the pUserInfo object
  113. pUserInfo->put_FirstName(A2W(szTemp));
  114. // Since we used FE_NAME, we need to clear FIRSTNAME and LASTNAME, so they are not sent in the
  115. // query string
  116. pISPData->PutDataElement(ISPDATA_USER_FIRSTNAME, NULL, ISPDATA_Validate_None);
  117. pISPData->PutDataElement(ISPDATA_USER_LASTNAME, NULL, ISPDATA_Validate_None);
  118. }
  119. else
  120. {
  121. uCtrlID = IDC_USERINFO_FIRSTNAME;
  122. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  123. if (!pISPData->PutDataElement(ISPDATA_USER_FIRSTNAME, szTemp, wPrevValidationValue))
  124. break;
  125. pUserInfo->put_FirstName(A2W(szTemp));
  126. uCtrlID = IDC_USERINFO_LASTNAME;
  127. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  128. if (!pISPData->PutDataElement(ISPDATA_USER_LASTNAME, szTemp, wPrevValidationValue))
  129. break;
  130. pUserInfo->put_LastName(A2W(szTemp));
  131. // Since we did not use FE_NAME, we need to clear it
  132. pISPData->PutDataElement(ISPDATA_USER_FE_NAME, NULL, ISPDATA_Validate_None);
  133. }
  134. if (GetDlgItem(hDlg, IDC_USERINFO_COMPANYNAME))
  135. {
  136. uCtrlID = IDC_USERINFO_COMPANYNAME;
  137. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  138. if (!pISPData->PutDataElement(ISPDATA_USER_COMPANYNAME, szTemp, wPrevValidationValue))
  139. break;
  140. pUserInfo->put_Company(A2W(szTemp));
  141. }
  142. else
  143. {
  144. pISPData->PutDataElement(ISPDATA_USER_COMPANYNAME, NULL, ISPDATA_Validate_None);
  145. }
  146. uCtrlID = IDC_USERINFO_ADDRESS1;
  147. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  148. if (!pISPData->PutDataElement(ISPDATA_USER_ADDRESS, szTemp, wPrevValidationValue))
  149. break;
  150. pUserInfo->put_Address1(A2W(szTemp));
  151. // Only validate address 2 if we are in Japanese layout, since FE and US layout
  152. // have this an on optional field
  153. uCtrlID = IDC_USERINFO_ADDRESS2;
  154. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  155. if (!pISPData->PutDataElement(ISPDATA_USER_MOREADDRESS, szTemp, wPrevValidationValue))
  156. break;
  157. pUserInfo->put_Address2(A2W(szTemp));
  158. uCtrlID = IDC_USERINFO_CITY;
  159. GetDlgItemText(hDlg, uCtrlID , szTemp, ARRAYSIZE(szTemp));
  160. if (!pISPData->PutDataElement(ISPDATA_USER_CITY, szTemp, wPrevValidationValue))
  161. break;
  162. pUserInfo->put_City(A2W(szTemp));
  163. uCtrlID = IDC_USERINFO_STATE;
  164. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  165. if (!pISPData->PutDataElement(ISPDATA_USER_STATE, szTemp, wPrevValidationValue))
  166. break;
  167. pUserInfo->put_State(A2W(szTemp));
  168. uCtrlID = IDC_USERINFO_ZIP;
  169. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  170. if (!pISPData->PutDataElement(ISPDATA_USER_ZIP, szTemp, wPrevValidationValue))
  171. break;
  172. pUserInfo->put_ZIPCode(A2W(szTemp));
  173. uCtrlID = IDC_USERINFO_PHONE;
  174. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  175. if (!pISPData->PutDataElement(ISPDATA_USER_PHONE, szTemp, wPrevValidationValue))
  176. break;
  177. pUserInfo->put_PhoneNumber(A2W(szTemp));
  178. // If we get here, then all fields are valid
  179. bValid = TRUE;
  180. break;
  181. }
  182. if (!bValid)
  183. SetFocus(GetDlgItem(hDlg, uCtrlID));
  184. return (bValid);
  185. }
  186. INT_PTR CALLBACK UserInfoDlgProc
  187. (
  188. HWND hDlg,
  189. UINT uMsg,
  190. WPARAM wParam,
  191. LPARAM lParam
  192. )
  193. {
  194. switch (uMsg)
  195. {
  196. case WM_CTLCOLORDLG:
  197. case WM_CTLCOLORSTATIC:
  198. if(gpWizardState->cmnStateData.bOEMCustom)
  199. {
  200. SetTextColor((HDC)wParam, gpWizardState->cmnStateData.clrText);
  201. SetBkMode((HDC)wParam, TRANSPARENT);
  202. return (INT_PTR) GetStockObject(NULL_BRUSH);
  203. }
  204. break;
  205. case WM_SHOWWINDOW:
  206. {
  207. if((BOOL)wParam)
  208. InitUserInformation(hDlg);
  209. break;
  210. }
  211. // User clicked next, so we need to collect and validate dat
  212. case WM_USER_BACK:
  213. {
  214. if (bValidateSaveUserInformation(hDlg, BACK))
  215. SetPropSheetResult(hDlg,TRUE);
  216. else
  217. SetPropSheetResult(hDlg, FALSE);
  218. return TRUE;
  219. }
  220. case WM_USER_NEXT:
  221. {
  222. if (bValidateSaveUserInformation(hDlg, NEXT))
  223. SetPropSheetResult(hDlg,TRUE);
  224. else
  225. SetPropSheetResult(hDlg, FALSE);
  226. return TRUE;
  227. }
  228. }
  229. // Default return value if message is not handled
  230. return FALSE;
  231. }
  232. /*******************************************************************
  233. NAME: SwitchUserInfoType
  234. ********************************************************************/
  235. void SwitchUserInfoDlg
  236. (
  237. HWND hDlg,
  238. BOOL bNeedCompanyName
  239. )
  240. {
  241. UINT idDlg;
  242. // Hide the current userinfo window if there is one
  243. if (hDlgCurrentUserInfo)
  244. ShowWindow(hDlgCurrentUserInfo, SW_HIDE);
  245. // Figure out which template to use
  246. switch(g_DlgLayout)
  247. {
  248. case LAYOUT_FE:
  249. if (bNeedCompanyName)
  250. idDlg = IDD_USERINFO_FE;
  251. else
  252. idDlg = IDD_USERINFO_FE_NO_COMPANY;
  253. break;
  254. case LAYOUT_JPN:
  255. if (bNeedCompanyName)
  256. idDlg = IDD_USERINFO_JPN;
  257. else
  258. idDlg = IDD_USERINFO_JPN_NO_COMPANY;
  259. break;
  260. case LAYOUT_US:
  261. if (bNeedCompanyName)
  262. idDlg = IDD_USERINFO_US;
  263. else
  264. idDlg = IDD_USERINFO_US_NO_COMPANY;
  265. break;
  266. }
  267. // Create the necessary dialog
  268. if (bNeedCompanyName)
  269. {
  270. if (NULL == hDlgUserInfoCompany)
  271. {
  272. hDlgUserInfoCompany = CreateDialog(ghInstanceResDll,
  273. MAKEINTRESOURCE(idDlg),
  274. hDlg,
  275. UserInfoDlgProc);
  276. }
  277. hDlgCurrentUserInfo = hDlgUserInfoCompany;
  278. }
  279. else
  280. {
  281. if (NULL == hDlgUserInfoNoCompany)
  282. {
  283. hDlgUserInfoNoCompany = CreateDialog(ghInstanceResDll,
  284. MAKEINTRESOURCE(idDlg),
  285. hDlg,
  286. UserInfoDlgProc);
  287. }
  288. hDlgCurrentUserInfo = hDlgUserInfoNoCompany;
  289. }
  290. // Show the new payment type window
  291. ShowWindowWithParentControl(hDlgCurrentUserInfo);
  292. }
  293. /*******************************************************************
  294. NAME: UserInfoInitProc
  295. SYNOPSIS: Called when page is displayed
  296. ENTRY: hDlg - dialog window
  297. fFirstInit - TRUE if this is the first time the dialog
  298. is initialized, FALSE if this InitProc has been called
  299. before (e.g. went past this page and backed up)
  300. ********************************************************************/
  301. BOOL CALLBACK UserInfoInitProc
  302. (
  303. HWND hDlg,
  304. BOOL fFirstInit,
  305. UINT *puNextPage
  306. )
  307. {
  308. // Create a local reference for the ISPData object
  309. IICWISPData *pISPData = gpWizardState->pISPData;
  310. PAGEINFO *pPageInfo = (PAGEINFO *) GetWindowLongPtr(hDlg,DWLP_USER);
  311. if (fFirstInit)
  312. {
  313. // Figure out which dialog layout to use, FE or US
  314. // This is a 1 time calculation, since the user cannot change locales while running ICW
  315. switch (GetUserDefaultLCID())
  316. {
  317. case LCID_JPN:
  318. g_DlgLayout = LAYOUT_JPN;
  319. // Load the appropriate nested dialog accelerator table
  320. pPageInfo->hAccelNested = LoadAccelerators(ghInstanceResDll,
  321. MAKEINTRESOURCE(IDA_USERINFO_JPN));
  322. break;
  323. case LCID_CHT:
  324. case LCID_S_KOR:
  325. case LCID_N_KOR:
  326. case LCID_CHS:
  327. g_DlgLayout = LAYOUT_FE;
  328. pPageInfo->hAccelNested = LoadAccelerators(ghInstanceResDll,
  329. MAKEINTRESOURCE(IDA_USERINFO_FE));
  330. break;
  331. default:
  332. g_DlgLayout = LAYOUT_US;
  333. pPageInfo->hAccelNested = LoadAccelerators(ghInstanceResDll,
  334. MAKEINTRESOURCE(IDA_USERINFO_US));
  335. break;
  336. }
  337. }
  338. else
  339. {
  340. ASSERT(gpWizardState->lpSelectedISPInfo);
  341. // if we've travelled through external apprentice pages,
  342. // it's easy for our current page pointer to get munged,
  343. // so reset it here for sanity's sake.
  344. gpWizardState->uCurrentPage = ORD_PAGE_USERINFO;
  345. DWORD dwConfigFlags = gpWizardState->lpSelectedISPInfo->get_dwCFGFlag();
  346. // Setup the ISPData object so that is can apply proper validation based on the selected ISP
  347. pISPData->PutValidationFlags(gpWizardState->lpSelectedISPInfo->get_dwRequiredUserInputFlags());
  348. // Switch in the correct User Info Dialog template
  349. SwitchUserInfoDlg(hDlg, dwConfigFlags & ICW_CFGFLAG_USE_COMPANYNAME);
  350. }
  351. return TRUE;
  352. }
  353. /*******************************************************************
  354. NAME: UserInfoOKProc
  355. SYNOPSIS: Called when Next or Back btns pressed from page
  356. ENTRY: hDlg - dialog window
  357. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  358. puNextPage - if 'Next' was pressed,
  359. proc can fill this in with next page to go to. This
  360. parameter is ingored if 'Back' was pressed.
  361. pfKeepHistory - page will not be kept in history if
  362. proc fills this in with FALSE.
  363. EXIT: returns TRUE to allow page to be turned, FALSE
  364. to keep the same page.
  365. ********************************************************************/
  366. BOOL CALLBACK UserInfoOKProc
  367. (
  368. HWND hDlg,
  369. BOOL fForward,
  370. UINT *puNextPage,
  371. BOOL *pfKeepHistory
  372. )
  373. {
  374. // Create a local reference for the ISPData object
  375. IICWISPData* pISPData = gpWizardState->pISPData;
  376. DWORD dwConfigFlags = gpWizardState->lpSelectedISPInfo->get_dwCFGFlag();
  377. if (fForward)
  378. {
  379. // Collect, valicate, and save user entered information
  380. if (dwConfigFlags & ICW_CFGFLAG_USE_COMPANYNAME)
  381. {
  382. if (!SendMessage(hDlgUserInfoCompany, WM_USER_NEXT, 0, 0l))
  383. return FALSE;
  384. }
  385. else
  386. {
  387. if (!SendMessage(hDlgUserInfoNoCompany, WM_USER_NEXT, 0, 0l))
  388. return FALSE;
  389. }
  390. // Figure out which page to goto next, based on the config flags
  391. while (1)
  392. {
  393. if (ICW_CFGFLAG_BILL & dwConfigFlags)
  394. {
  395. *puNextPage = ORD_PAGE_BILLINGOPT;
  396. break;
  397. }
  398. if (ICW_CFGFLAG_PAYMENT & dwConfigFlags)
  399. {
  400. *puNextPage = ORD_PAGE_PAYMENT;
  401. break;
  402. }
  403. // We need to skip both billing and payment pages, so goto the dial page
  404. *puNextPage = ORD_PAGE_ISPDIAL;
  405. break;
  406. }
  407. }
  408. else
  409. {
  410. // Collect, valicate, and save user entered information
  411. if (dwConfigFlags & ICW_CFGFLAG_USE_COMPANYNAME)
  412. {
  413. if (!SendMessage(hDlgUserInfoCompany, WM_USER_BACK, 0, 0l))
  414. return FALSE;
  415. }
  416. else
  417. {
  418. if (!SendMessage(hDlgUserInfoNoCompany, WM_USER_BACK, 0, 0l))
  419. return FALSE;
  420. }
  421. }
  422. return TRUE;
  423. }