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.

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