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.

421 lines
13 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: wizsel.cxx
  7. //
  8. // Contents: Task schedule credentials selection property page implementation.
  9. //
  10. // Classes: CCredentialsPage
  11. //
  12. // History: 05-22-1998 SusiA
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.h"
  16. // temporariy define new mstask flag in case hasn't
  17. // propogated to sdk\inc
  18. //for CS help
  19. #ifdef _CREDENTIALS
  20. extern TCHAR szSyncMgrHelp[];
  21. extern ULONG g_aContextHelpIds[];
  22. extern DWORD g_dwPlatformId;
  23. CCredentialsPage *g_pCredentialsPage = NULL;
  24. //+-------------------------------------------------------------------------------
  25. // FUNCTION: SchedWizardCredentialsDlgProc(HWND, UINT, WPARAM, LPARAM)
  26. //
  27. // PURPOSE: Callback dialog procedure for the property page
  28. //
  29. // PARAMETERS:
  30. // hDlg - Dialog box window handle
  31. // uMessage - current message
  32. // wParam - depends on message
  33. // lParam - depends on message
  34. //
  35. // RETURN VALUE:
  36. //
  37. // Depends on message. In general, return TRUE if we process it.
  38. //
  39. // COMMENTS:
  40. //
  41. //--------------------------------------------------------------------------------
  42. BOOL CALLBACK SchedWizardCredentialsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  43. {
  44. WORD wNotifyCode = HIWORD(wParam); // notification code
  45. switch (uMessage)
  46. {
  47. case WM_INITDIALOG:
  48. if (g_pCredentialsPage)
  49. g_pCredentialsPage->Initialize(hDlg);
  50. InitPage(hDlg,lParam);
  51. break;
  52. case WM_HELP:
  53. {
  54. LPHELPINFO lphi = (LPHELPINFO)lParam;
  55. if (lphi->iContextType == HELPINFO_WINDOW)
  56. {
  57. WinHelp ( (HWND) lphi->hItemHandle,
  58. szSyncMgrHelp,
  59. HELP_WM_HELP,
  60. (ULONG_PTR) g_aContextHelpIds);
  61. }
  62. return TRUE;
  63. }
  64. case WM_CONTEXTMENU:
  65. {
  66. WinHelp ((HWND)wParam,
  67. szSyncMgrHelp,
  68. HELP_CONTEXTMENU,
  69. (ULONG_PTR)g_aContextHelpIds);
  70. return TRUE;
  71. }
  72. case WM_PAINT:
  73. WmPaint(hDlg, uMessage, wParam, lParam);
  74. break;
  75. case WM_PALETTECHANGED:
  76. WmPaletteChanged(hDlg, wParam);
  77. break;
  78. case WM_QUERYNEWPALETTE:
  79. return( WmQueryNewPalette(hDlg) );
  80. break;
  81. case WM_ACTIVATE:
  82. return( WmActivate(hDlg, wParam, lParam) );
  83. break;
  84. case WM_COMMAND:
  85. switch (LOWORD(wParam))
  86. {
  87. case IDC_USERNAME:
  88. case IDC_PASSWORD:
  89. case IDC_CONFIRMPASSWORD:
  90. {
  91. if (wNotifyCode == EN_CHANGE)
  92. {
  93. PropSheet_Changed(GetParent(hDlg), hDlg);
  94. g_pCredentialsPage->SetDirty();
  95. }
  96. }
  97. break;
  98. case IDC_RUNLOGGEDON:
  99. {
  100. if (wNotifyCode == BN_CLICKED)
  101. {
  102. PropSheet_Changed(GetParent(hDlg), hDlg);
  103. g_pCredentialsPage->SetDirty();
  104. g_pCredentialsPage->SetEnabled(FALSE);
  105. }
  106. }
  107. break;
  108. case IDC_RUNALWAYS:
  109. {
  110. if (wNotifyCode == BN_CLICKED)
  111. {
  112. PropSheet_Changed(GetParent(hDlg), hDlg);
  113. g_pCredentialsPage->SetDirty();
  114. g_pCredentialsPage->SetEnabled(TRUE);
  115. }
  116. }
  117. break;
  118. default:
  119. break;
  120. }
  121. break;
  122. default:
  123. return FALSE;
  124. }
  125. return TRUE;
  126. }
  127. //+--------------------------------------------------------------------------
  128. //
  129. // Member: CCredentialsPage::CCredentialsPage
  130. //
  131. // Synopsis: ctor
  132. //
  133. // [phPSP] - filled with prop page handle
  134. //
  135. // History: 11-21-1997 SusiA
  136. //
  137. //---------------------------------------------------------------------------
  138. CCredentialsPage::CCredentialsPage(
  139. HINSTANCE hinst,
  140. BOOL *pfSaved,
  141. ISyncSchedule *pISyncSched,
  142. HPROPSHEETPAGE *phPSP)
  143. {
  144. ZeroMemory(&m_psp, sizeof(PROPSHEETPAGE));
  145. m_psp.dwSize = sizeof (PROPSHEETPAGE);
  146. m_psp.dwFlags = PSP_DEFAULT;
  147. m_psp.hInstance = hinst;
  148. m_psp.pszTemplate = MAKEINTRESOURCE(IDD_SCHEDPAGE_CREDENTIALS);
  149. m_psp.pszIcon = NULL;
  150. m_psp.pfnDlgProc = (DLGPROC) SchedWizardCredentialsDlgProc;
  151. m_psp.lParam = 0;
  152. g_pCredentialsPage = this;
  153. m_pISyncSched = pISyncSched;
  154. m_pISyncSched->AddRef();
  155. m_pfSaved = pfSaved;
  156. *m_pfSaved = FALSE;
  157. m_fTaskAccountChange = FALSE;
  158. #ifdef WIZARD97
  159. m_psp.dwFlags |= PSP_HIDEHEADER;
  160. #endif // WIZARD97
  161. *phPSP = CreatePropertySheetPage(&m_psp);
  162. }
  163. //+--------------------------------------------------------------------------
  164. //
  165. // Member: CCredentialsPage::Initialize(HWND hwnd)
  166. //
  167. // Synopsis: initialize the credentials page
  168. //
  169. // History: 05-22-1998 SusiA
  170. //
  171. //---------------------------------------------------------------------------
  172. BOOL CCredentialsPage::Initialize(HWND hwnd)
  173. {
  174. m_hwnd = hwnd;
  175. ShowUserName();
  176. //Set the default IDC_ONLY_WHEN_LOGGED_ON check state.
  177. ITask *pITask;
  178. m_pISyncSched->GetITask(&pITask);
  179. DWORD dwFlags;
  180. pITask->GetFlags(&dwFlags);
  181. BOOL fOnlyWhenLoggedOn = dwFlags & TASK_FLAG_RUN_ONLY_IF_LOGGED_ON;
  182. Button_SetCheck(GetDlgItem(m_hwnd,IDC_RUNLOGGEDON), fOnlyWhenLoggedOn);
  183. Button_SetCheck(GetDlgItem(m_hwnd,IDC_RUNALWAYS), !fOnlyWhenLoggedOn);
  184. Edit_LimitText(GetDlgItem(m_hwnd, IDC_PASSWORD), PWLEN);
  185. Edit_LimitText(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD), PWLEN);
  186. Edit_LimitText(GetDlgItem(m_hwnd, IDC_USERNAME), MAX_DOMANDANDMACHINENAMESIZE -1);
  187. SetEnabled(!fOnlyWhenLoggedOn);
  188. pITask->Release();
  189. ShowWindow(m_hwnd, /* nCmdShow */ SW_SHOWNORMAL );
  190. UpdateWindow(m_hwnd);
  191. return TRUE;
  192. }
  193. //--------------------------------------------------------------------------------
  194. //
  195. // FUNCTION: CCredentialsPage::SetDirty()
  196. //
  197. // PURPOSE: we have changed the account info
  198. //
  199. // COMMENTS: Only called frm prop sheet; not wizard
  200. //
  201. //--------------------------------------------------------------------------------
  202. void CCredentialsPage::SetDirty()
  203. {
  204. m_fTaskAccountChange = TRUE;
  205. }
  206. //--------------------------------------------------------------------------------
  207. //
  208. // FUNCTION: CSelectItemsPage::ShowUserName()
  209. //
  210. // PURPOSE: change the task's user name
  211. //
  212. // COMMENTS: Only called frm prop sheet; not wizard
  213. //
  214. //--------------------------------------------------------------------------------
  215. BOOL CCredentialsPage::ShowUserName()
  216. {
  217. Assert(m_pISyncSched);
  218. WCHAR wszUserName[MAX_PATH + 1];
  219. DWORD dwSize = MAX_PATH;
  220. HWND hwndEdit = GetDlgItem(m_hwnd, IDC_USERNAME);
  221. HRESULT hr = m_pISyncSched->GetAccountInformation(&dwSize, wszUserName);
  222. if (FAILED(hr))
  223. {
  224. *wszUserName = L'\0';
  225. }
  226. Edit_SetText(hwndEdit, wszUserName);
  227. //
  228. // Need to set m_fTaskAccountChange here since doing a Edit_SetText causes
  229. // a WM_COMMAND msg with EN_CHANGE to be called for edit boxes.
  230. //
  231. m_fTaskAccountChange = FALSE;
  232. return TRUE;
  233. }
  234. //--------------------------------------------------------------------------------
  235. //
  236. // FUNCTION: CSelectItemsPage::CommitChanges()
  237. //
  238. // PURPOSE: Write all the current Schedule Settings to the registry
  239. //
  240. // COMMENTS: Implemented on main thread.
  241. //
  242. //--------------------------------------------------------------------------------
  243. HRESULT CCredentialsPage::CommitChanges()
  244. {
  245. HRESULT hr = S_OK;
  246. BOOL fAccountChanged = TRUE;
  247. if (m_fTaskAccountChange)
  248. {
  249. BOOL fRunAlways = Button_GetCheck(GetDlgItem(m_hwnd,IDC_RUNALWAYS));
  250. if (fRunAlways)
  251. {
  252. Assert(m_pISyncSched);
  253. WCHAR wcUserBuffMAX_DOMANDANDMACHINENAMESIZE];
  254. WCHAR wcPassword[PWLEN + 1];
  255. WCHAR wcConfirmPassword[PWLEN + 1];
  256. GetDlgItemText(m_hwnd,IDC_USERNAME,wcUserBuff,MAX_DOMANDANDMACHINENAMESIZE);
  257. GetDlgItemText(m_hwnd,IDC_PASSWORD,wcPassword, PWLEN);
  258. GetDlgItemText(m_hwnd,IDC_CONFIRMPASSWORD,wcConfirmPassword, PWLEN);
  259. if (wcscmp(wcPassword, wcConfirmPassword) != 0)
  260. {
  261. // we return this to signal the controlling page not to
  262. // dismiss the dialog.
  263. return(ERROR_INVALID_PASSWORD);
  264. }
  265. ITask *pITask;
  266. if (FAILED(hr = m_pISyncSched->GetITask(&pITask)))
  267. {
  268. return hr;
  269. }
  270. if (FAILED (hr = m_pISyncSched->SetAccountInformation(wcUserBuff,
  271. wcPassword)))
  272. {
  273. AssertSz(0,"ISyncSched->SetAccountInformation failed");
  274. return hr;
  275. }
  276. DWORD dwFlags;
  277. pITask->GetFlags(&dwFlags);
  278. if (FAILED(hr = pITask->SetFlags(dwFlags & (~TASK_FLAG_RUN_ONLY_IF_LOGGED_ON))))
  279. {
  280. AssertSz(0,"ITask->SetFlags failed");
  281. return hr;
  282. }
  283. pITask->Release();
  284. }
  285. else
  286. {
  287. ITask *pITask;
  288. if (FAILED(hr = m_pISyncSched->GetITask(&pITask)))
  289. {
  290. return hr;
  291. }
  292. WCHAR wszDomainAndUser[MAX_DOMANDANDMACHINENAMESIZE];
  293. GetDefaultDomainAndUserName(wszDomainAndUser,TEXT("\\"),MAX_DOMANDANDMACHINENAMESIZE);
  294. if (FAILED(hr = m_pISyncSched->SetAccountInformation(wszDomainAndUser, NULL)))
  295. {
  296. AssertSz(0,"ISyncSched->SetAccountInformation failed");
  297. return hr;
  298. }
  299. DWORD dwFlags;
  300. pITask->GetFlags(&dwFlags);
  301. if (FAILED(hr = pITask->SetFlags(dwFlags | TASK_FLAG_RUN_ONLY_IF_LOGGED_ON)))
  302. {
  303. AssertSz(0,"ITask->SetFlags failed");
  304. return hr;
  305. }
  306. pITask->Release();
  307. }
  308. //Now save the schedule
  309. //NoteNote: optimize by moving the save from wizsel and cred to EditSyncSched
  310. hr = m_pISyncSched->Save();
  311. if (hr == S_OK)
  312. {
  313. *m_pfSaved = TRUE;
  314. }
  315. }
  316. return hr;
  317. }
  318. //+-------------------------------------------------------------------------------
  319. //
  320. // FUNCTION: BOOL CSelectItemsPage::SetEnabled(BOOL fEnabled)
  321. //
  322. // PURPOSE: set the fields enabled according to the RB choice
  323. //
  324. // RETURN VALUE: return TRUE if we process it ok.
  325. //
  326. //+-------------------------------------------------------------------------------
  327. BOOL CCredentialsPage::SetEnabled(BOOL fEnabled)
  328. {
  329. EnableWindow(GetDlgItem(m_hwnd, IDC_USERNAME), fEnabled);
  330. EnableWindow(GetDlgItem(m_hwnd, IDC_PASSWORD), fEnabled);
  331. EnableWindow(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD), fEnabled);
  332. EnableWindow(GetDlgItem(m_hwnd, IDC_RUNAS_TEXT), fEnabled);
  333. EnableWindow(GetDlgItem(m_hwnd, IDC_PASSWORD_TEXT), fEnabled);
  334. EnableWindow(GetDlgItem(m_hwnd, IDC_CONFIRMPASSWORD_TEXT), fEnabled);
  335. return TRUE;
  336. }
  337. #endif // #ifdef _CREDENTIALS