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.

520 lines
16 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: editschd.cxx
  7. //
  8. // Contents: Task schedule page for hidden schedules
  9. //
  10. // Classes: CEditSchedPage
  11. //
  12. // History: 15-Mar-1998 SusiA
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.h"
  16. extern LANGID g_LangIdSystem; // LangId of system we are running on.
  17. extern TCHAR szSyncMgrHelp[];
  18. extern ULONG g_aContextHelpIds[];
  19. CEditSchedPage *g_pEditSchedPage = NULL;
  20. extern CSelectItemsPage *g_pSelectItemsPage;
  21. #ifdef _CREDENTIALS
  22. extern CCredentialsPage *g_pCredentialsPage;
  23. #endif // _CREDENTIALS
  24. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  25. //+-------------------------------------------------------------------------------
  26. // FUNCTION: SchedEditDlgProc(HWND, UINT, WPARAM, LPARAM)
  27. //
  28. // PURPOSE: Callback dialog procedure for the property page
  29. //
  30. // PARAMETERS:
  31. // hDlg - Dialog box window handle
  32. // uMessage - current message
  33. // wParam - depends on message
  34. // lParam - depends on message
  35. //
  36. // RETURN VALUE:
  37. //
  38. // Depends on message. In general, return TRUE if we process it.
  39. //
  40. // COMMENTS:
  41. //
  42. //--------------------------------------------------------------------------------
  43. INT_PTR CALLBACK SchedEditDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  44. {
  45. WORD wNotifyCode = HIWORD(wParam); // notification code
  46. switch (uMessage)
  47. {
  48. case WM_INITDIALOG:
  49. if (g_pEditSchedPage)
  50. g_pEditSchedPage->Initialize(hDlg);
  51. InitPage(hDlg,lParam);
  52. return TRUE;
  53. break;
  54. case WM_NOTIFY:
  55. switch (((NMHDR FAR *)lParam)->code)
  56. {
  57. case PSN_APPLY:
  58. if (!g_pEditSchedPage->SetSchedName())
  59. {
  60. SchedUIErrorDialog(hDlg, IERR_INVALIDSCHEDNAME);
  61. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
  62. return TRUE;
  63. }
  64. if (g_pSelectItemsPage)
  65. {
  66. g_pSelectItemsPage->CommitChanges();
  67. }
  68. #ifdef _CREDENTIALS
  69. SCODE sc;
  70. if (g_pCredentialsPage)
  71. {
  72. sc = g_pCredentialsPage->CommitChanges();
  73. if (sc == ERROR_INVALID_PASSWORD)
  74. {
  75. // Passwords didn't match. Let the user know so he/she
  76. // can correct it.
  77. SchedUIErrorDialog(hDlg, IERR_PASSWORD);
  78. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
  79. return TRUE;
  80. }
  81. else if (sc == SCHED_E_ACCOUNT_NAME_NOT_FOUND)
  82. {
  83. // Passwords didn't match. Let the user know so he/she
  84. // can correct it.
  85. SchedUIErrorDialog(hDlg, IERR_ACCOUNT_NOT_FOUND);
  86. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
  87. return TRUE;
  88. }
  89. }
  90. #endif // _CREDENTIALS
  91. break;
  92. case PSN_SETACTIVE:
  93. if (g_pEditSchedPage)
  94. g_pEditSchedPage->Initialize(hDlg);
  95. break;
  96. default:
  97. break;
  98. }
  99. break;
  100. case WM_COMMAND:
  101. if ((wNotifyCode == EN_CHANGE) && (LOWORD(wParam) == IDC_SCHED_NAME_EDITBOX))
  102. {
  103. PropSheet_Changed(GetParent(hDlg), hDlg);
  104. g_pEditSchedPage->SetSchedNameDirty();
  105. return TRUE;
  106. }
  107. break;
  108. case WM_HELP:
  109. {
  110. LPHELPINFO lphi = (LPHELPINFO)lParam;
  111. if (lphi->iContextType == HELPINFO_WINDOW)
  112. {
  113. WinHelp ( (HWND) lphi->hItemHandle,
  114. szSyncMgrHelp,
  115. HELP_WM_HELP,
  116. (ULONG_PTR) g_aContextHelpIds);
  117. }
  118. return TRUE;
  119. }
  120. case WM_CONTEXTMENU:
  121. {
  122. WinHelp ((HWND)wParam,
  123. szSyncMgrHelp,
  124. HELP_CONTEXTMENU,
  125. (ULONG_PTR)g_aContextHelpIds);
  126. return TRUE;
  127. }
  128. default:
  129. break;
  130. }
  131. return FALSE;
  132. }
  133. //+--------------------------------------------------------------------------
  134. //
  135. // Member: CEditSchedPage::CEditSchedPage
  136. //
  137. // Synopsis: ctor
  138. //
  139. // [phPSP] - filled with prop page handle
  140. //
  141. // History: 11-21-1997 SusiA
  142. //
  143. //---------------------------------------------------------------------------
  144. CEditSchedPage::CEditSchedPage(
  145. HINSTANCE hinst,
  146. ISyncSchedule *pISyncSched,
  147. HPROPSHEETPAGE *phPSP)
  148. {
  149. ZeroMemory(&m_psp, sizeof(m_psp));
  150. m_psp.dwSize = sizeof (PROPSHEETPAGE);
  151. m_psp.hInstance = hinst;
  152. m_psp.dwFlags = PSP_DEFAULT;
  153. m_psp.pszTemplate = MAKEINTRESOURCE(IDD_SCHEDPAGE_SCHEDULE);
  154. m_psp.pszIcon = NULL;
  155. m_psp.pfnDlgProc = SchedEditDlgProc;
  156. m_psp.lParam = 0;
  157. g_pEditSchedPage = this;
  158. m_pISyncSched = pISyncSched;
  159. m_pISyncSched->AddRef();
  160. *phPSP = CreatePropertySheetPage(&m_psp);
  161. }
  162. BOOL CEditSchedPage::_Initialize_ScheduleName(HWND hwnd)
  163. {
  164. BOOL fRetVal = FALSE;
  165. TCHAR szStr[MAX_PATH];
  166. DWORD cch = ARRAYSIZE(szStr);
  167. //Schedule Name
  168. if (SUCCEEDED(m_pISyncSched->GetScheduleName(&cch, szStr)))
  169. {
  170. m_hwnd = hwnd;
  171. HWND hwndName = GetDlgItem(hwnd,IDC_SCHED_NAME);
  172. LONG_PTR dwStyle = GetWindowLongPtr(hwndName, GWL_STYLE);
  173. SetWindowLongPtr(hwndName, GWL_STYLE, dwStyle | SS_ENDELLIPSIS);
  174. SetStaticString(hwndName, szStr);
  175. fRetVal = TRUE;
  176. }
  177. return fRetVal;
  178. }
  179. BOOL CEditSchedPage::_Initialize_TriggerString(HWND hwnd)
  180. {
  181. BOOL fRetVal = FALSE;
  182. WCHAR szStr[MAX_PATH];
  183. WCHAR szFmt[MAX_PATH];
  184. WCHAR szParam[MAX_PATH];
  185. ITaskTrigger* pITrigger;
  186. if (SUCCEEDED(m_pISyncSched->GetTrigger(&pITrigger)))
  187. {
  188. TASK_TRIGGER TaskTrigger;
  189. if (SUCCEEDED(pITrigger->GetTrigger(&TaskTrigger)))
  190. {
  191. HRESULT hr;
  192. switch (TaskTrigger.TriggerType)
  193. {
  194. case TASK_EVENT_TRIGGER_ON_IDLE:
  195. LoadString(g_hmodThisDll, IDS_IDLE_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  196. hr = S_OK;
  197. break;
  198. case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
  199. LoadString(g_hmodThisDll, IDS_SYSTEMSTART_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  200. hr = S_OK;
  201. break;
  202. case TASK_EVENT_TRIGGER_AT_LOGON:
  203. LoadString(g_hmodThisDll, IDS_LOGON_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  204. hr = S_OK;
  205. break;
  206. default:
  207. {
  208. LPWSTR pwszString;
  209. hr = pITrigger->GetTriggerString(&pwszString);
  210. if (SUCCEEDED(hr))
  211. {
  212. hr = StringCchCopy(szParam, ARRAYSIZE(szParam), pwszString);
  213. CoTaskMemFree(pwszString);
  214. }
  215. }
  216. break;
  217. }
  218. if (SUCCEEDED(hr))
  219. {
  220. LoadString(g_hmodThisDll, IDS_SCHED_WHEN, szFmt, ARRAYSIZE(szFmt));
  221. if (SUCCEEDED(StringCchPrintf(szStr, ARRAYSIZE(szStr), szFmt, szParam)))
  222. {
  223. fRetVal = TRUE;
  224. }
  225. }
  226. }
  227. pITrigger->Release();
  228. }
  229. if (fRetVal)
  230. {
  231. SetDlgItemText(hwnd,IDC_SCHED_STRING,szStr);
  232. }
  233. return fRetVal;
  234. }
  235. BOOL CEditSchedPage::_Initialize_LastRunString(HWND hwnd)
  236. {
  237. BOOL fRetVal = FALSE;
  238. WCHAR szStr[MAX_PATH];
  239. WCHAR szFmt[MAX_PATH];
  240. WCHAR szParam[MAX_PATH];
  241. WCHAR szParam2[MAX_PATH];
  242. SYSTEMTIME st;
  243. HRESULT hr = m_pISyncSched->GetMostRecentRunTime(&st);
  244. if (S_OK == hr)
  245. {
  246. DWORD dwDateReadingFlags = GetDateFormatReadingFlags(hwnd);
  247. LoadString(g_hmodThisDll, IDS_SCHED_LASTRUN, szFmt, ARRAYSIZE(szFmt));
  248. if (GetDateFormat(LOCALE_USER_DEFAULT,dwDateReadingFlags, &st, NULL,szParam, ARRAYSIZE(szParam)) &&
  249. GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL,szParam2, ARRAYSIZE(szParam2)) &&
  250. SUCCEEDED(StringCchPrintf(szStr, ARRAYSIZE(szStr), szFmt, szParam, szParam2)))
  251. {
  252. fRetVal = TRUE;
  253. }
  254. }
  255. else if (SUCCEEDED(hr) && S_OK != hr)
  256. {
  257. LoadString(g_hmodThisDll, IDS_SCHED_NEVERRUN, szStr, ARRAYSIZE(szStr));
  258. fRetVal = TRUE;
  259. }
  260. if (fRetVal)
  261. {
  262. SetDlgItemText(hwnd,IDC_LASTRUN,szStr);
  263. }
  264. return fRetVal;
  265. }
  266. BOOL CEditSchedPage::_Initialize_NextRunString(HWND hwnd)
  267. {
  268. BOOL fRetVal = FALSE;
  269. WCHAR szStr[MAX_PATH];
  270. WCHAR szFmt[MAX_PATH];
  271. WCHAR szParam[MAX_PATH];
  272. WCHAR szParam2[MAX_PATH];
  273. SYSTEMTIME st;
  274. HRESULT hr = m_pISyncSched->GetNextRunTime(&st);
  275. if (SCHED_S_EVENT_TRIGGER == hr)
  276. {
  277. ITaskTrigger* pITrigger;
  278. if (SUCCEEDED(m_pISyncSched->GetTrigger(&pITrigger)))
  279. {
  280. TASK_TRIGGER TaskTrigger;
  281. if (SUCCEEDED(pITrigger->GetTrigger(&TaskTrigger)))
  282. {
  283. switch (TaskTrigger.TriggerType)
  284. {
  285. case TASK_EVENT_TRIGGER_ON_IDLE:
  286. LoadString(g_hmodThisDll, IDS_IDLE_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  287. break;
  288. case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
  289. LoadString(g_hmodThisDll, IDS_SYSTEMSTART_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  290. break;
  291. case TASK_EVENT_TRIGGER_AT_LOGON:
  292. LoadString(g_hmodThisDll, IDS_LOGON_TRIGGER_STRING, szParam, ARRAYSIZE(szParam));
  293. break;
  294. default:
  295. Assert(0);
  296. break;
  297. }
  298. LoadString(g_hmodThisDll, IDS_NEXTRUN_EVENT, szFmt, ARRAYSIZE(szFmt));
  299. if (SUCCEEDED(StringCchPrintf(szStr, ARRAYSIZE(szStr), szFmt, szParam)))
  300. {
  301. fRetVal = TRUE;
  302. }
  303. }
  304. pITrigger->Release();
  305. }
  306. }
  307. else if (S_OK == hr)
  308. {
  309. DWORD dwDateReadingFlags = GetDateFormatReadingFlags(hwnd);
  310. LoadString(g_hmodThisDll, IDS_SCHED_NEXTRUN, szFmt, ARRAYSIZE(szFmt));
  311. if (SUCCEEDED(GetDateFormat(LOCALE_USER_DEFAULT, dwDateReadingFlags, &st,
  312. NULL,szParam, ARRAYSIZE(szParam))) &&
  313. SUCCEEDED(GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st,
  314. NULL,szParam2, ARRAYSIZE(szParam2))) &&
  315. SUCCEEDED(StringCchPrintf(szStr, ARRAYSIZE(szStr), szFmt, szParam, szParam2)))
  316. {
  317. fRetVal = TRUE;
  318. }
  319. }
  320. else if (SUCCEEDED(hr) && S_OK != hr)
  321. {
  322. LoadString(g_hmodThisDll, IDS_SCHED_NOTAGAIN, szStr, ARRAYSIZE(szStr));
  323. fRetVal = TRUE;
  324. }
  325. if (fRetVal)
  326. {
  327. SetDlgItemText(hwnd,IDC_NEXTRUN,szStr);
  328. }
  329. return fRetVal;
  330. }
  331. //+--------------------------------------------------------------------------
  332. //
  333. // Member: CEditSchedPage::Initialize(HWND hwnd)
  334. //
  335. // Synopsis: initialize the edit schedule page
  336. //
  337. // History: 11-21-1997 SusiA
  338. //
  339. //---------------------------------------------------------------------------
  340. BOOL CEditSchedPage::Initialize(HWND hwnd)
  341. {
  342. BOOL fRetVal = FALSE;
  343. if (_Initialize_ScheduleName(hwnd) &&
  344. _Initialize_TriggerString(hwnd) &&
  345. _Initialize_LastRunString(hwnd) &&
  346. _Initialize_NextRunString(hwnd))
  347. {
  348. // set the limit on the edit box for entering the name
  349. SendDlgItemMessage(hwnd,IDC_SCHED_NAME_EDITBOX,EM_SETLIMITTEXT,MAX_PATH,0);
  350. ShowSchedName();
  351. fRetVal = TRUE;
  352. }
  353. return fRetVal;
  354. }
  355. //--------------------------------------------------------------------------------
  356. //
  357. // FUNCTION: CEditSchedPage::SetSchedNameDirty()
  358. //
  359. // PURPOSE: set the sched name dirty
  360. //
  361. // COMMENTS: Only called frm prop sheet; not wizard
  362. //
  363. //--------------------------------------------------------------------------------
  364. void CEditSchedPage::SetSchedNameDirty()
  365. {
  366. m_fSchedNameChanged = TRUE;
  367. }
  368. //--------------------------------------------------------------------------------
  369. //
  370. // FUNCTION: CEditSchedPage::ShowSchedName()
  371. //
  372. // PURPOSE: change the task's sched name
  373. //
  374. // COMMENTS: Only called frm prop sheet; not wizard
  375. //
  376. //--------------------------------------------------------------------------------
  377. BOOL CEditSchedPage::ShowSchedName()
  378. {
  379. Assert(m_pISyncSched);
  380. WCHAR pwszSchedName[MAX_PATH + 1];
  381. DWORD cchSchedName = ARRAYSIZE(pwszSchedName);
  382. HWND hwndEdit = GetDlgItem(m_hwnd, IDC_SCHED_NAME_EDITBOX);
  383. if (FAILED(m_pISyncSched->GetScheduleName(&cchSchedName, pwszSchedName)))
  384. {
  385. return FALSE;
  386. }
  387. Edit_SetText(hwndEdit, pwszSchedName);
  388. m_fSchedNameChanged = FALSE;
  389. return TRUE;
  390. }
  391. //--------------------------------------------------------------------------------
  392. //
  393. // FUNCTION: CEditSchedPage::SetSchedName()
  394. //
  395. // PURPOSE: change the task's sched name
  396. //
  397. // COMMENTS: Only called frm prop sheet; not wizard
  398. //
  399. //--------------------------------------------------------------------------------
  400. BOOL CEditSchedPage::SetSchedName()
  401. {
  402. Assert(m_pISyncSched);
  403. TCHAR pszSchedName[MAX_PATH + 1];
  404. DWORD dwSize = MAX_PATH;
  405. if (m_fSchedNameChanged)
  406. {
  407. HWND hwndEdit = GetDlgItem(m_hwnd, IDC_SCHED_NAME_EDITBOX);
  408. Edit_GetText(hwndEdit, pszSchedName, MAX_PATH);
  409. if (S_OK != m_pISyncSched->SetScheduleName(pszSchedName))
  410. {
  411. return FALSE;
  412. }
  413. SetStaticString(GetDlgItem(m_hwnd,IDC_SCHED_NAME), pszSchedName);
  414. PropSheet_SetTitle(GetParent(m_hwnd),0, pszSchedName);
  415. }
  416. return TRUE;
  417. }
  418. //+--------------------------------------------------------------------------
  419. //
  420. // Function: SetStaticString (HWND hwnd, LPTSTR pszString)
  421. //
  422. // Synopsis: print out the schedule name in a static text string, with the ...
  423. // if necessary
  424. //
  425. // History: 12-Mar-1998 SusiA
  426. //
  427. //---------------------------------------------------------------------------
  428. BOOL SetStaticString (HWND hwnd, LPTSTR pszString)
  429. {
  430. Assert(hwnd);
  431. Static_SetText(hwnd, pszString);
  432. return TRUE;
  433. }