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.

3667 lines
120 KiB

  1. #include "private.h"
  2. #include "schedui.h"
  3. #include "offl_cpp.h"
  4. #include "dialmon.h" // For WAITCURSOR
  5. #include "shellids.h" // For Help IDs
  6. //xnotfmgr - can probably nuke most of this file
  7. #define TF_DLGCTL TF_ALWAYS
  8. #define TF_DUMPTRIGGER 0
  9. #define MAX_GROUPNAME_LEN 40
  10. #define MAX_LOADSTRING_LEN 64
  11. #define MAX_SHORTTIMEFORMAT_LEN 80
  12. #define MAX_TIMESEP_LEN 8
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Design constants
  15. /////////////////////////////////////////////////////////////////////////////
  16. #define TASK_ALLDAYS (TASK_SUNDAY | TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY | TASK_THURSDAY | TASK_FRIDAY | TASK_SATURDAY)
  17. #define TASK_WEEKDAYS (TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY | TASK_THURSDAY | TASK_FRIDAY)
  18. #define TASK_WEEKENDDAYS (TASK_SUNDAY | TASK_SATURDAY)
  19. #define TASK_ALLMONTHS (TASK_JANUARY | TASK_FEBRUARY | TASK_MARCH | TASK_APRIL | TASK_MAY | TASK_JUNE | TASK_JULY | TASK_AUGUST | TASK_SEPTEMBER | TASK_OCTOBER | TASK_NOVEMBER | TASK_DECEMBER)
  20. #define DEFAULT_DAILY_EVERYNDAYS 1
  21. #define DEFAULT_DAILY_EVERYNDAYS_MIN 1
  22. #define DEFAULT_DAILY_EVERYNDAYS_MAX 999
  23. #define DEFAULT_WEEKLY_REPEATWEEKS 1
  24. #define DEFAULT_WEEKLY_REPEATWEEKS_MIN 1
  25. #define DEFAULT_WEEKLY_REPEATWEEKS_MAX 99
  26. #define DEFAULT_MONTHLY_DAY_MIN 1
  27. #define DEFAULT_MONTHLY_DAY_MAX 31
  28. #define DEFAULT_MONTHLY_MONTHS 1
  29. #define DEFAULT_MONTHLY_MONTHS_MIN 1
  30. #define DEFAULT_MONTHLY_MONTHS_MAX 6
  31. #define DEFAULT_UPDATETIME_HRS 0 // 12:00am
  32. #define DEFAULT_UPDATETIME_MINS 0
  33. #define DEFAULT_REPEATUPDATE_HRS 1
  34. #define DEFAULT_REPEATUPDATE_HRS_MIN 1
  35. #define DEFAULT_REPEATUPDATE_HRS_MAX 99
  36. #define DEFAULT_REPEAT_START_HRS 9 // 9:00am
  37. #define DEFAULT_REPEAT_START_MINS 0
  38. #define DEFAULT_REPEAT_END_HRS 17 // 5:00pm
  39. #define DEFAULT_REPEAT_END_MINS 0
  40. #define DEFAULT_RANDOM_MINUTES_INTERVAL 30
  41. // NOTE: These #defines have a dependency on the numeric order of the
  42. // controls in the dialog resource! Make sure they are contiguious
  43. // in RESOURCE.H! [jaym]
  44. #define IDC_TYPE_GROUP_FIRST IDC_CUSTOM_DAILY
  45. #define IDC_TYPE_GROUP_LAST IDC_CUSTOM_MONTHLY
  46. // Group type radio buttons
  47. #define IDC_DAILY_GROUP_FIRST IDC_CUSTOM_DAILY_EVERYNDAYS
  48. #define IDC_DAILY_GROUP_LAST IDC_CUSTOM_DAILY_EVERYWEEKDAY
  49. // Daily group type radio buttons
  50. #define IDC_MONTHLY_GROUP_FIRST IDC_CUSTOM_MONTHLY_DAYOFMONTH
  51. #define IDC_MONTHLY_GROUP_LAST IDC_CUSTOM_MONTHLY_PERIODIC
  52. // Monthly group type radio buttons
  53. #define IDC_TIME_GROUP_FIRST IDC_CUSTOM_TIME_UPDATEAT
  54. #define IDC_TIME_GROUP_LAST IDC_CUSTOM_TIME_REPEATEVERY
  55. // Time radio buttons
  56. #define IDC_CUSTOM_DAILY_FIRST IDC_CUSTOM_DAILY_EVERYNDAYS
  57. #define IDC_CUSTOM_DAILY_LAST IDC_CUSTOM_DAILY_STATIC1
  58. #define IDC_CUSTOM_WEEKLY_FIRST IDC_CUSTOM_WEEKLY_STATIC1
  59. #define IDC_CUSTOM_WEEKLY_LAST IDC_CUSTOM_WEEKLY_DAY7
  60. #define IDC_CUSTOM_MONTHLY_FIRST IDC_CUSTOM_MONTHLY_DAYOFMONTH
  61. #define IDC_CUSTOM_MONTHLY_LAST IDC_CUSTOM_MONTHLY_STATIC4
  62. // Group type controls
  63. #define IDS_MONTHLY_LIST1_FIRST IDS_WEEK1
  64. #define IDS_MONTHLY_LIST1_LAST IDS_WEEK5
  65. // Combo box items.
  66. #define CX_DIALOG_GUTTER 10
  67. #define CY_DIALOG_GUTTER 10
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Module variables
  70. /////////////////////////////////////////////////////////////////////////////
  71. static const TCHAR s_szRepeatHrsAreMins[] = TEXT("RepeatHrsAreMins");
  72. static const CTLGRPITEM c_rgnCtlGroups[] =
  73. {
  74. // 'Container' control First item in control Last item in control
  75. //------------------------- --------------------------- ----------------------
  76. { IDC_CUSTOM_GROUP_DAILY, IDC_CUSTOM_DAILY_FIRST, IDC_CUSTOM_DAILY_LAST },
  77. { IDC_CUSTOM_GROUP_WEEKLY, IDC_CUSTOM_WEEKLY_FIRST, IDC_CUSTOM_WEEKLY_LAST },
  78. { IDC_CUSTOM_GROUP_MONTHLY, IDC_CUSTOM_MONTHLY_FIRST, IDC_CUSTOM_MONTHLY_LAST },
  79. };
  80. static const CTLGRPITEM c_rgnCtlItems[] =
  81. {
  82. // 'Container' control First item in control Last item in control
  83. //------------------------- --------------------------- ----------------------
  84. { IDC_CUSTOM_MONTHLY_PERIODIC_LIST1, IDS_MONTHLY_LIST1_FIRST, IDS_MONTHLY_LIST1_LAST },
  85. };
  86. static const WORD c_rgwMonthMaps[] =
  87. {
  88. 0x0FFF, // every month 111111111111b
  89. 0x0AAA, // every other month 101010101010b
  90. 0x0924, // every 3 months 100100100100b
  91. 0x0888, // every 4 months 100010001000b
  92. 0x0842, // every 5 months 100001000010b
  93. 0x0820 // every 6 months 100000100000b
  94. };
  95. #define NUM_CUSTOM_DAYSOFTHEWEEK 3
  96. static WORD s_rgwDaysOfTheWeek[NUM_CUSTOM_DAYSOFTHEWEEK+7] =
  97. {
  98. TASK_ALLDAYS,
  99. TASK_WEEKDAYS,
  100. TASK_WEEKENDDAYS,
  101. // ...
  102. };
  103. // NOTE: These should be kept in line with IDS_DAY1 to IDS_DAY3
  104. extern TCHAR c_szHelpFile[];
  105. DWORD aCustomDlgHelpIDs[] =
  106. {
  107. IDD_CUSTOM_SCHEDULE, IDH_CUSTOM_SCHEDULE,
  108. IDC_CUSTOM_NEWGROUP, IDH_SCHEDULE_NEW,
  109. IDC_CUSTOM_REMOVEGROUP, IDH_SCHEDULE_REMOVE,
  110. IDC_CUSTOM_GROUP_LIST, IDH_NEW_NAME,
  111. IDC_CUSTOM_GROUP_EDIT, IDH_NEW_NAME,
  112. IDC_CUSTOM_DAILY, IDH_SCHED_DAYS,
  113. IDC_CUSTOM_WEEKLY, IDH_SCHED_DAYS,
  114. IDC_CUSTOM_MONTHLY, IDH_SCHED_DAYS,
  115. IDC_CUSTOM_DAILY_EVERYNDAYS, IDH_SCHED_FREQUENCY,
  116. IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT, IDH_SCHED_FREQUENCY,
  117. IDC_CUSTOM_DAILY_STATIC1, IDH_SCHED_FREQUENCY,
  118. IDC_CUSTOM_DAILY_EVERYWEEKDAY, IDH_SCHED_FREQUENCY,
  119. IDC_CUSTOM_WEEKLY_STATIC1, IDH_SCHED_FREQUENCY,
  120. IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT, IDH_SCHED_FREQUENCY,
  121. IDC_CUSTOM_WEEKLY_STATIC2, IDH_SCHED_FREQUENCY,
  122. IDC_CUSTOM_WEEKLY_DAY1, IDH_SCHED_FREQUENCY,
  123. IDC_CUSTOM_WEEKLY_DAY2, IDH_SCHED_FREQUENCY,
  124. IDC_CUSTOM_WEEKLY_DAY3, IDH_SCHED_FREQUENCY,
  125. IDC_CUSTOM_WEEKLY_DAY4, IDH_SCHED_FREQUENCY,
  126. IDC_CUSTOM_WEEKLY_DAY5, IDH_SCHED_FREQUENCY,
  127. IDC_CUSTOM_WEEKLY_DAY6, IDH_SCHED_FREQUENCY,
  128. IDC_CUSTOM_WEEKLY_DAY7, IDH_SCHED_FREQUENCY,
  129. IDC_CUSTOM_MONTHLY_DAYOFMONTH, IDH_SCHED_FREQUENCY,
  130. IDC_CUSTOM_MONTHLY_STATIC3, IDH_SCHED_FREQUENCY,
  131. IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT, IDH_SCHED_FREQUENCY,
  132. IDC_CUSTOM_MONTHLY_STATIC4, IDH_SCHED_FREQUENCY,
  133. IDC_CUSTOM_MONTHLY_PERIODIC, IDH_SCHED_FREQUENCY,
  134. IDC_CUSTOM_MONTHLY_PERIODIC_LIST1, IDH_SCHED_FREQUENCY,
  135. IDC_CUSTOM_MONTHLY_PERIODIC_LIST2, IDH_SCHED_FREQUENCY,
  136. IDC_CUSTOM_MONTHLY_STATIC1, IDH_SCHED_FREQUENCY,
  137. IDC_CUSTOM_MONTHLY_PERIODIC_EDIT, IDH_SCHED_FREQUENCY,
  138. IDC_CUSTOM_MONTHLY_STATIC2, IDH_SCHED_FREQUENCY,
  139. IDC_CUSTOM_TIME_UPDATEAT, IDH_SCHED_TIME,
  140. IDC_CUSTOM_TIME_UPDATEAT_TIME, IDH_SCHED_TIME,
  141. IDC_CUSTOM_TIME_REPEATEVERY, IDH_SCHED_REPEAT,
  142. IDC_CUSTOM_TIME_REPEATEVERY_EDIT, IDH_SCHED_REPEAT,
  143. IDC_CUSTOM_TIME_REPEATBETWEEN, IDH_SCHED_REPEAT,
  144. IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME, IDH_SCHED_REPEAT,
  145. IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME, IDH_SCHED_REPEAT,
  146. IDC_CUSTOM_MINIMIZENETUSE, IDH_VARY_START
  147. };
  148. // Help IDs
  149. /////////////////////////////////////////////////////////////////////////////
  150. // Local functions
  151. /////////////////////////////////////////////////////////////////////////////
  152. void InitDlgCtls(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  153. void PositionDlgCtls(HWND hwndDlg);
  154. void InitDlgDefaults(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  155. void InitDlgInfo(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  156. BOOL HandleDlgButtonClick(HWND hwndDlg, WPARAM wParam, SSUIDLGINFO * pDlgInfo);
  157. BOOL HandleButtonClick(HWND hwndDlg, WPARAM wParam);
  158. BOOL HandleGroupChange(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  159. void SetDlgCustomType(HWND hwndDlg, int iType);
  160. void SetDlgWeekDays(HWND hwndDlg, WORD rgfDaysOfTheWeek);
  161. WORD GetDlgWeekDays(HWND hwndDlg);
  162. void SetTaskTriggerToDefaults(TASK_TRIGGER * pTaskTrigger);
  163. void SetTaskTriggerFromDlg(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  164. HRESULT CreateScheduleGroupFromDlg(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  165. void OnDataChanged(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  166. HRESULT ApplyDlgChanges(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  167. BOOL ValidateDlgFields(HWND hwndDlg, SSUIDLGINFO * pDlgInfo);
  168. UINT GetDlgGroupName(HWND hwndDlg, LPTSTR pszGroupName, int cchGroupNameLen);
  169. int GetDlgGroupNameLength(HWND hwndDlg);
  170. BOOL SetDlgItemMonth(HWND hwndDlg, int idCtl, WORD rgfMonths);
  171. WORD GetDlgItemMonth(HWND hwndDlg, int idCtl);
  172. void SetDlgItemNextUpdate(HWND hwndDlg, int idCtl, SSUIDLGINFO * pDlgInfo);
  173. HRESULT GetSchedGroupTaskTrigger(PNOTIFICATIONCOOKIE pGroupCookie,TASK_TRIGGER * pTaskTrigger);
  174. BOOL CALLBACK ShowScheduleUIDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  175. DWORD IncTime(DWORD dwTime, int iIncHours, int iIncMinutes);
  176. int DayFromDaysFlags(DWORD rgfDays);
  177. int MonthCountFromMonthsFlags(WORD rgfMonths);
  178. int DayIndexFromDaysOfTheWeekFlags(WORD rgfDaysOfTheWeek);
  179. HRESULT GetDaysOfWeekString(WORD rgfDaysOfTheWeek, LPTSTR ptszBuf, UINT cchBuf);
  180. HRESULT GetMonthsString(WORD rgfMonths, LPTSTR ptszBuf, UINT cchBuf);
  181. void RestrictDlgItemRange(HWND hwndDlg, int idCtl, SSUIDLGINFO * pDlgInfo);
  182. void RestrictTimeRepeatEvery(HWND hwndDlg);
  183. int SGMessageBox(HWND hwndParent, UINT idStringRes, UINT uType);
  184. #ifdef DEBUG
  185. void DumpTaskTrigger(TASK_TRIGGER * pTaskTrigger);
  186. #endif // DEBUG
  187. /////////////////////////////////////////////////////////////////////////////
  188. // ScheduleSummaryFromGroup
  189. /////////////////////////////////////////////////////////////////////////////
  190. HRESULT ScheduleSummaryFromGroup
  191. (
  192. /* [in] */ PNOTIFICATIONCOOKIE pGroupCookie,
  193. /* [in][out] */ LPTSTR pszSummary,
  194. /* [in] */ UINT cchSummary
  195. )
  196. {
  197. //xnotfmgr
  198. HRESULT hrResult;
  199. ASSERT((pszSummary != NULL) && (cchSummary > 0));
  200. for (;;)
  201. {
  202. *pszSummary = TEXT('\0');
  203. TASK_TRIGGER tt;
  204. if (FAILED(hrResult = GetSchedGroupTaskTrigger(pGroupCookie, &tt)))
  205. break;
  206. if (FAILED(hrResult = ScheduleSummaryFromTaskTrigger(&tt, pszSummary, cchSummary)))
  207. break;
  208. hrResult = S_OK;
  209. break;
  210. }
  211. return hrResult;
  212. }
  213. /////////////////////////////////////////////////////////////////////////////
  214. // ScheduleSummaryFromTaskTrigger
  215. /////////////////////////////////////////////////////////////////////////////
  216. HRESULT ScheduleSummaryFromTaskTrigger
  217. (
  218. TASK_TRIGGER * pTT,
  219. LPTSTR pszSummary,
  220. UINT cchSummary
  221. )
  222. {
  223. TCHAR szLineOut[128];
  224. TCHAR szFormat[128];
  225. HRESULT hrResult;
  226. if (!MLLoadString(IDS_SUMMARY_UPDATE, szLineOut, ARRAYSIZE(szLineOut)))
  227. {
  228. hrResult = HRESULT_FROM_WIN32(GetLastError());
  229. return hrResult;
  230. }
  231. StrNCpy(pszSummary, szLineOut, cchSummary);
  232. switch (pTT->TriggerType)
  233. {
  234. case TASK_TIME_TRIGGER_DAILY:
  235. {
  236. if (pTT->Type.Daily.DaysInterval == 1)
  237. {
  238. // Daily -- every day
  239. if (!MLLoadString(IDS_SUMMARY_EVERY_DAY, szLineOut, ARRAYSIZE(szLineOut)))
  240. {
  241. hrResult = HRESULT_FROM_WIN32(GetLastError());
  242. return hrResult;
  243. }
  244. }
  245. else
  246. {
  247. // Daily -- every %d days
  248. if (!MLLoadString(IDS_SUMMARY_DAILY_FORMAT, szFormat, ARRAYSIZE(szFormat)))
  249. {
  250. hrResult = HRESULT_FROM_WIN32(GetLastError());
  251. return hrResult;
  252. }
  253. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat,
  254. pTT->Type.Daily.DaysInterval);
  255. }
  256. lstrcatn(pszSummary, szLineOut, cchSummary);
  257. break;
  258. }
  259. case TASK_TIME_TRIGGER_WEEKLY:
  260. {
  261. TCHAR szDOW[128];
  262. if (FAILED(hrResult = GetDaysOfWeekString( pTT->Type.Weekly.rgfDaysOfTheWeek,
  263. szDOW,
  264. ARRAYSIZE(szDOW))))
  265. {
  266. return hrResult;
  267. }
  268. if (pTT->Type.Weekly.WeeksInterval == 1)
  269. {
  270. // Daily -- every weekday
  271. if (pTT->Type.Weekly.rgfDaysOfTheWeek == TASK_WEEKDAYS)
  272. {
  273. if (!MLLoadString(IDS_SUMMARY_EVERY_WEEKDAY, szLineOut, ARRAYSIZE(szLineOut)))
  274. {
  275. hrResult = HRESULT_FROM_WIN32(GetLastError());
  276. return hrResult;
  277. }
  278. }
  279. else
  280. {
  281. // Weekly -- every %s of every week
  282. if (!MLLoadString(IDS_SUMMARY_EVERY_WEEK_FORMAT, szFormat, ARRAYSIZE(szFormat)))
  283. {
  284. hrResult = HRESULT_FROM_WIN32(GetLastError());
  285. return hrResult;
  286. }
  287. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat, szDOW);
  288. }
  289. }
  290. else
  291. {
  292. TCHAR szWeeks[16];
  293. // Weekly -- every %s of every %s weeks
  294. if (!MLLoadString(IDS_SUMMARY_WEEKLY_FORMAT, szFormat, ARRAYSIZE(szFormat)))
  295. {
  296. hrResult = HRESULT_FROM_WIN32(GetLastError());
  297. return hrResult;
  298. }
  299. wnsprintf(szWeeks, ARRAYSIZE(szWeeks), "%d", pTT->Type.Weekly.WeeksInterval);
  300. TCHAR * rgpsz[2] = { szDOW, szWeeks };
  301. if (!FormatMessage( FORMAT_MESSAGE_FROM_STRING
  302. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  303. szFormat,
  304. 0,
  305. 0,
  306. szLineOut,
  307. ARRAYSIZE(szLineOut),
  308. (va_list*)rgpsz))
  309. {
  310. hrResult = HRESULT_FROM_WIN32(GetLastError());
  311. return hrResult;
  312. }
  313. }
  314. lstrcatn(pszSummary, szLineOut, cchSummary);
  315. break;
  316. }
  317. case TASK_TIME_TRIGGER_MONTHLYDATE:
  318. {
  319. if (pTT->Type.MonthlyDate.rgfMonths == TASK_ALLMONTHS)
  320. {
  321. // Monthly -- on day %d of every month
  322. if (!MLLoadString(
  323. IDS_SUMMARY_EVERY_MONTHLYDATE_FORMAT,
  324. szFormat,
  325. ARRAYSIZE(szFormat)))
  326. {
  327. hrResult = HRESULT_FROM_WIN32(GetLastError());
  328. return hrResult;
  329. }
  330. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat,
  331. DayFromDaysFlags(pTT->Type.MonthlyDate.rgfDays));
  332. }
  333. else
  334. {
  335. // Monthly -- on day %d of %s
  336. if (!MLLoadString(
  337. IDS_SUMMARY_MONTHLYDATE_FORMAT,
  338. szFormat,
  339. ARRAYSIZE(szFormat)))
  340. {
  341. hrResult = HRESULT_FROM_WIN32(GetLastError());
  342. return hrResult;
  343. }
  344. TCHAR szMonths[128];
  345. if (FAILED(hrResult = GetMonthsString( pTT->Type.MonthlyDate.rgfMonths,
  346. szMonths,
  347. ARRAYSIZE(szMonths))))
  348. {
  349. return hrResult;
  350. }
  351. TCHAR szDay[16];
  352. wnsprintf(szDay, ARRAYSIZE(szDay), "%d",
  353. DayFromDaysFlags(pTT->Type.MonthlyDate.rgfDays));
  354. TCHAR * rgpsz[2] = { szDay, szMonths };
  355. if (!FormatMessage( FORMAT_MESSAGE_FROM_STRING
  356. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  357. szFormat,
  358. 0,
  359. 0,
  360. szLineOut,
  361. ARRAYSIZE(szLineOut),
  362. (va_list*)rgpsz))
  363. {
  364. hrResult = HRESULT_FROM_WIN32(GetLastError());
  365. return hrResult;
  366. }
  367. }
  368. lstrcatn(pszSummary, szLineOut, cchSummary);
  369. break;
  370. }
  371. case TASK_TIME_TRIGGER_MONTHLYDOW:
  372. {
  373. ASSERT((pTT->Type.MonthlyDOW.wWhichWeek >= TASK_FIRST_WEEK));
  374. ASSERT((pTT->Type.MonthlyDOW.wWhichWeek <= TASK_LAST_WEEK));
  375. TCHAR szWeek[32];
  376. if (!MLLoadString(
  377. IDS_MONTHLY_LIST1_FIRST + pTT->Type.MonthlyDOW.wWhichWeek - 1,
  378. szWeek,
  379. ARRAYSIZE(szWeek)))
  380. {
  381. hrResult = HRESULT_FROM_WIN32(GetLastError());
  382. return hrResult;
  383. }
  384. TCHAR szDOW[128];
  385. if (FAILED(hrResult = GetDaysOfWeekString( pTT->Type.MonthlyDOW.rgfDaysOfTheWeek,
  386. szDOW,
  387. ARRAYSIZE(szDOW))))
  388. {
  389. return hrResult;
  390. }
  391. if (pTT->Type.MonthlyDate.rgfMonths == TASK_ALLMONTHS)
  392. {
  393. // Monthly -- on the %s %s of every month
  394. if (!MLLoadString(
  395. IDS_SUMMARY_EVERY_MONTHLYDOW_FORMAT,
  396. szFormat,
  397. ARRAYSIZE(szFormat)))
  398. {
  399. hrResult = HRESULT_FROM_WIN32(GetLastError());
  400. return hrResult;
  401. }
  402. TCHAR * rgpsz[2] = { szWeek, szDOW };
  403. if (!FormatMessage( FORMAT_MESSAGE_FROM_STRING
  404. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  405. szFormat,
  406. 0,
  407. 0,
  408. szLineOut,
  409. ARRAYSIZE(szLineOut),
  410. (va_list*)rgpsz))
  411. {
  412. hrResult = HRESULT_FROM_WIN32(GetLastError());
  413. return hrResult;
  414. }
  415. }
  416. else
  417. {
  418. TCHAR szMonths[128];
  419. if (FAILED(hrResult = GetMonthsString( pTT->Type.MonthlyDOW.rgfMonths,
  420. szMonths,
  421. ARRAYSIZE(szMonths))))
  422. {
  423. return hrResult;
  424. }
  425. // Monthly -- on the %s %s of %s
  426. if (!MLLoadString(
  427. IDS_SUMMARY_MONTHLYDOW_FORMAT,
  428. szFormat,
  429. ARRAYSIZE(szFormat)))
  430. {
  431. hrResult = HRESULT_FROM_WIN32(GetLastError());
  432. return hrResult;
  433. }
  434. TCHAR * rgpsz[3] = { szWeek, szDOW, szMonths };
  435. if (!FormatMessage( FORMAT_MESSAGE_FROM_STRING
  436. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  437. szFormat,
  438. 0,
  439. 0,
  440. szLineOut,
  441. ARRAYSIZE(szLineOut),
  442. (va_list*)rgpsz))
  443. {
  444. hrResult = HRESULT_FROM_WIN32(GetLastError());
  445. return hrResult;
  446. }
  447. }
  448. lstrcatn(pszSummary, szLineOut, cchSummary);
  449. break;
  450. }
  451. default:
  452. {
  453. ASSERT(FALSE);
  454. return E_FAIL;
  455. }
  456. }
  457. TCHAR szStartTime[MAX_SHORTTIMEFORMAT_LEN];
  458. SYSTEMTIME st = { 0 };
  459. st.wHour = pTT->wStartHour;
  460. st.wMinute = pTT->wStartMinute;
  461. EVAL(GetTimeFormat( LOCALE_USER_DEFAULT,
  462. TIME_NOSECONDS,
  463. &st,
  464. NULL,
  465. szStartTime,
  466. ARRAYSIZE(szStartTime)) > 0);
  467. // Handle the 'Time' settings.
  468. if (pTT->MinutesInterval == 0)
  469. {
  470. // at %s
  471. if (!MLLoadString(
  472. IDS_SUMMARY_ONCE_DAY_FORMAT,
  473. szFormat,
  474. ARRAYSIZE(szFormat)))
  475. {
  476. hrResult = HRESULT_FROM_WIN32(GetLastError());
  477. return hrResult;
  478. }
  479. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat, szStartTime);
  480. lstrcatn(pszSummary, szLineOut, cchSummary);
  481. }
  482. else
  483. {
  484. if ((pTT->MinutesInterval % 60) == 0) //repeating on the hour
  485. {
  486. if ((pTT->MinutesInterval / 60) == 1)
  487. {
  488. // every hour
  489. if (!MLLoadString(
  490. IDS_SUMMARY_REPEAT_EVERY_HOUR,
  491. szLineOut,
  492. ARRAYSIZE(szLineOut)))
  493. {
  494. hrResult = HRESULT_FROM_WIN32(GetLastError());
  495. return hrResult;
  496. }
  497. }
  498. else
  499. {
  500. // every %d hours
  501. if (!MLLoadString(
  502. IDS_SUMMARY_REPEAT_HOURLY_FORMAT,
  503. szFormat,
  504. ARRAYSIZE(szFormat)))
  505. {
  506. hrResult = HRESULT_FROM_WIN32(GetLastError());
  507. return hrResult;
  508. }
  509. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat,
  510. (pTT->MinutesInterval / 60));
  511. }
  512. }
  513. else //not integral hours, use minutes
  514. {
  515. if (pTT->MinutesInterval == 1)
  516. {
  517. // every minute
  518. if (!MLLoadString(
  519. IDS_SUMMARY_REPEAT_EVERY_MIN,
  520. szLineOut,
  521. ARRAYSIZE(szLineOut)))
  522. {
  523. hrResult = HRESULT_FROM_WIN32(GetLastError());
  524. return hrResult;
  525. }
  526. }
  527. else
  528. {
  529. // every %d minutes
  530. if (!MLLoadString(
  531. IDS_SUMMARY_REPEAT_MINUTELY_FORMAT,
  532. szFormat,
  533. ARRAYSIZE(szFormat)))
  534. {
  535. hrResult = HRESULT_FROM_WIN32(GetLastError());
  536. return hrResult;
  537. }
  538. wnsprintf(szLineOut, ARRAYSIZE(szLineOut), szFormat,
  539. pTT->MinutesInterval);
  540. }
  541. }
  542. lstrcatn(pszSummary, szLineOut, cchSummary);
  543. // between %s and %s
  544. if (pTT->MinutesDuration != (24 * 60))
  545. {
  546. if (!MLLoadString(
  547. IDS_SUMMARY_REPEAT_BETWEEN_FORMAT,
  548. szFormat,
  549. ARRAYSIZE(szFormat)))
  550. {
  551. hrResult = HRESULT_FROM_WIN32(GetLastError());
  552. return hrResult;
  553. }
  554. DWORD dwEndTime = IncTime( MAKELONG(pTT->wStartHour, pTT->wStartMinute),
  555. (pTT->MinutesDuration / 60),
  556. (pTT->MinutesDuration % 60));
  557. ZeroMemory(&st, SIZEOF(SYSTEMTIME));
  558. st.wHour = LOWORD(dwEndTime);
  559. st.wMinute = HIWORD(dwEndTime);
  560. TCHAR szEndTime[MAX_SHORTTIMEFORMAT_LEN];
  561. EVAL(GetTimeFormat( LOCALE_USER_DEFAULT,
  562. TIME_NOSECONDS,
  563. &st,
  564. NULL,
  565. szEndTime,
  566. ARRAYSIZE(szEndTime)) > 0);
  567. TCHAR * rgpsz[2] = { szStartTime, szEndTime };
  568. if (!FormatMessage( FORMAT_MESSAGE_FROM_STRING
  569. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  570. szFormat,
  571. 0,
  572. 0,
  573. szLineOut,
  574. ARRAYSIZE(szLineOut),
  575. (va_list*)rgpsz))
  576. {
  577. hrResult = HRESULT_FROM_WIN32(GetLastError());
  578. return hrResult;
  579. }
  580. lstrcatn(pszSummary, szLineOut, cchSummary);
  581. }
  582. }
  583. return S_OK;
  584. }
  585. /////////////////////////////////////////////////////////////////////////////
  586. // GetDaysOfWeekString
  587. /////////////////////////////////////////////////////////////////////////////
  588. HRESULT GetDaysOfWeekString
  589. (
  590. WORD rgfDaysOfTheWeek,
  591. LPTSTR ptszBuf,
  592. UINT cchBuf
  593. )
  594. {
  595. if (rgfDaysOfTheWeek == 0)
  596. return E_INVALIDARG;
  597. int cch;
  598. TCHAR tszSep[8];
  599. BOOL fMoreThanOne = FALSE;
  600. HRESULT hrResult;
  601. // REVIEW: Could probably make this simpler by creating a table [jaym]
  602. // TASK_* -> LOCALE_SABBREVDAYNAME?
  603. // REARCHITECT: Needs a re-write, hard to understand code
  604. if (!MLLoadString(IDS_SUMMARY_LIST_SEP, tszSep, ARRAYSIZE(tszSep)))
  605. {
  606. hrResult = HRESULT_FROM_WIN32(GetLastError());
  607. return hrResult;
  608. }
  609. *ptszBuf = TEXT('\0');
  610. if (rgfDaysOfTheWeek & TASK_MONDAY)
  611. {
  612. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  613. LOCALE_SABBREVDAYNAME1,
  614. ptszBuf,
  615. cchBuf))
  616. {
  617. hrResult = HRESULT_FROM_WIN32(GetLastError());
  618. return hrResult;
  619. }
  620. fMoreThanOne = TRUE;
  621. }
  622. if (rgfDaysOfTheWeek & TASK_TUESDAY)
  623. {
  624. if (fMoreThanOne)
  625. lstrcat(ptszBuf, tszSep);
  626. cch = lstrlen(ptszBuf);
  627. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  628. LOCALE_SABBREVDAYNAME2,
  629. ptszBuf + cch,
  630. cchBuf - cch))
  631. {
  632. hrResult = HRESULT_FROM_WIN32(GetLastError());
  633. return hrResult;
  634. }
  635. fMoreThanOne = TRUE;
  636. }
  637. if (rgfDaysOfTheWeek & TASK_WEDNESDAY)
  638. {
  639. if (fMoreThanOne)
  640. lstrcat(ptszBuf, tszSep);
  641. cch = lstrlen(ptszBuf);
  642. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  643. LOCALE_SABBREVDAYNAME3,
  644. ptszBuf + cch,
  645. cchBuf - cch))
  646. {
  647. hrResult = HRESULT_FROM_WIN32(GetLastError());
  648. return hrResult;
  649. }
  650. fMoreThanOne = TRUE;
  651. }
  652. if (rgfDaysOfTheWeek & TASK_THURSDAY)
  653. {
  654. if (fMoreThanOne)
  655. lstrcat(ptszBuf, tszSep);
  656. cch = lstrlen(ptszBuf);
  657. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  658. LOCALE_SABBREVDAYNAME4,
  659. ptszBuf + cch,
  660. cchBuf - cch))
  661. {
  662. hrResult = HRESULT_FROM_WIN32(GetLastError());
  663. return hrResult;
  664. }
  665. fMoreThanOne = TRUE;
  666. }
  667. if (rgfDaysOfTheWeek & TASK_FRIDAY)
  668. {
  669. if (fMoreThanOne)
  670. lstrcat(ptszBuf, tszSep);
  671. cch = lstrlen(ptszBuf);
  672. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  673. LOCALE_SABBREVDAYNAME5,
  674. ptszBuf + cch,
  675. cchBuf - cch))
  676. {
  677. hrResult = HRESULT_FROM_WIN32(GetLastError());
  678. return hrResult;
  679. }
  680. fMoreThanOne = TRUE;
  681. }
  682. if (rgfDaysOfTheWeek & TASK_SATURDAY)
  683. {
  684. if (fMoreThanOne)
  685. lstrcat(ptszBuf, tszSep);
  686. cch = lstrlen(ptszBuf);
  687. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  688. LOCALE_SABBREVDAYNAME6,
  689. ptszBuf + cch,
  690. cchBuf - cch))
  691. {
  692. hrResult = HRESULT_FROM_WIN32(GetLastError());
  693. return hrResult;
  694. }
  695. fMoreThanOne = TRUE;
  696. }
  697. if (rgfDaysOfTheWeek & TASK_SUNDAY)
  698. {
  699. if (fMoreThanOne)
  700. lstrcat(ptszBuf, tszSep);
  701. cch = lstrlen(ptszBuf);
  702. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  703. LOCALE_SABBREVDAYNAME7,
  704. ptszBuf + cch,
  705. cchBuf - cch))
  706. {
  707. hrResult = HRESULT_FROM_WIN32(GetLastError());
  708. return hrResult;
  709. }
  710. }
  711. return S_OK;
  712. }
  713. /////////////////////////////////////////////////////////////////////////////
  714. // GetMonthsString
  715. /////////////////////////////////////////////////////////////////////////////
  716. HRESULT GetMonthsString
  717. (
  718. WORD rgfMonths,
  719. LPTSTR ptszBuf,
  720. UINT cchBuf
  721. )
  722. {
  723. if (rgfMonths == 0)
  724. return E_INVALIDARG;
  725. int cch;
  726. TCHAR tszSep[8];
  727. BOOL fMoreThanOne = FALSE;
  728. HRESULT hr;
  729. if (!MLLoadString(IDS_SUMMARY_LIST_SEP, tszSep, ARRAYSIZE(tszSep)))
  730. {
  731. hr = HRESULT_FROM_WIN32(GetLastError());
  732. return hr;
  733. }
  734. *ptszBuf = TEXT('\0');
  735. for (WORD i = 0; i < 12; i++)
  736. {
  737. if ((rgfMonths >> i) & 0x1)
  738. {
  739. if (fMoreThanOne)
  740. lstrcat(ptszBuf, tszSep);
  741. cch = lstrlen(ptszBuf);
  742. if (!GetLocaleInfo( LOCALE_USER_DEFAULT,
  743. LOCALE_SABBREVMONTHNAME1 + i,
  744. ptszBuf + cch,
  745. cchBuf - cch))
  746. {
  747. hr = HRESULT_FROM_WIN32(GetLastError());
  748. return hr;
  749. }
  750. fMoreThanOne = TRUE;
  751. }
  752. }
  753. return S_OK;
  754. }
  755. /////////////////////////////////////////////////////////////////////////////
  756. // ShowScheduleUI
  757. /////////////////////////////////////////////////////////////////////////////
  758. HRESULT ShowScheduleUI
  759. (
  760. /* [in] */ HWND hwndParent,
  761. /* [in][out] */ PNOTIFICATIONCOOKIE pGroupCookie,
  762. /* [in][out] */ DWORD * pdwFlags
  763. )
  764. {
  765. //xnotfmgr
  766. SSUIDLGINFO ssuiDlgInfo = { 0 };
  767. HRESULT hrResult;
  768. // Initialize the custom time edit control class.
  769. INITCOMMONCONTROLSEX icc;
  770. icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
  771. icc.dwICC = ICC_DATE_CLASSES;
  772. EVAL(SUCCEEDED(InitCommonControlsEx(&icc)));
  773. for (;;)
  774. {
  775. // REVIEW: Check for invalid/conflicting dwFlags. [jaym]
  776. if (
  777. (pGroupCookie == NULL)
  778. ||
  779. (pdwFlags == NULL)
  780. )
  781. {
  782. return E_INVALIDARG;
  783. }
  784. ssuiDlgInfo.dwFlags = *pdwFlags;
  785. ssuiDlgInfo.pGroupCookie = pGroupCookie;
  786. // Get the GetRunTimes function entry point from URLMON.
  787. if ((ssuiDlgInfo.hinstURLMON = LoadLibrary(TEXT("URLMON.DLL"))) != NULL)
  788. {
  789. EVAL((ssuiDlgInfo.pfnGetRunTimes = (GRTFUNCTION)GetProcAddress( ssuiDlgInfo.hinstURLMON,
  790. TEXT("GetRunTimes"))) != NULL);
  791. }
  792. else
  793. TraceMsg(TF_ERROR, "Unable to LoadLibrary(URLMON.DLL)");
  794. // Setup the TASK_TRIGGER with default or sched. group info.
  795. if (ssuiDlgInfo.dwFlags & SSUI_CREATENEWSCHEDULE)
  796. {
  797. *(ssuiDlgInfo.pGroupCookie) = GUID_NULL;
  798. SetTaskTriggerToDefaults(&ssuiDlgInfo.ttTaskTrigger);
  799. }
  800. else
  801. {
  802. ASSERT(ssuiDlgInfo.dwFlags & SSUI_EDITSCHEDULE);
  803. if (FAILED(hrResult = GetSchedGroupTaskTrigger( ssuiDlgInfo.pGroupCookie,
  804. &ssuiDlgInfo.ttTaskTrigger)))
  805. {
  806. hrResult = E_INVALIDARG;
  807. break;
  808. }
  809. }
  810. // See if we want to specify schedule hours in minutes.
  811. ReadRegValue( HKEY_CURRENT_USER,
  812. WEBCHECK_REGKEY,
  813. s_szRepeatHrsAreMins,
  814. &ssuiDlgInfo.dwRepeatHrsAreMins,
  815. SIZEOF(&ssuiDlgInfo.dwRepeatHrsAreMins));
  816. #ifdef DEBUG
  817. if (ssuiDlgInfo.dwRepeatHrsAreMins)
  818. TraceMsg(TF_ALWAYS, "!!! WARNING! Treating Repeat Hours as Minutes !!!");
  819. #endif // DEBUG
  820. // Show the dialog.
  821. int iResult;
  822. if ((iResult = DialogBoxParam( MLGetHinst(),
  823. MAKEINTRESOURCE(IDD_CUSTOM_SCHEDULE),
  824. hwndParent,
  825. ShowScheduleUIDlgProc,
  826. (LPARAM)&ssuiDlgInfo)) < 0)
  827. {
  828. TraceMsg(TF_ERROR, "SSUI: DialogBoxParam failed");
  829. hrResult = E_FAIL;
  830. break;
  831. }
  832. switch (iResult)
  833. {
  834. case IDCANCEL:
  835. {
  836. if (!(ssuiDlgInfo.dwFlags & SSUI_EDITSCHEDULE))
  837. break;
  838. // FALL THROUGH!!!
  839. }
  840. case IDOK:
  841. {
  842. *pdwFlags = ssuiDlgInfo.dwFlags;
  843. if (ssuiDlgInfo.dwFlags & SSUI_SCHEDULELISTUPDATED)
  844. {
  845. ASSERT(ssuiDlgInfo.pGroupCookie != NULL);
  846. ASSERT(*(ssuiDlgInfo.pGroupCookie) != GUID_NULL);
  847. pGroupCookie = ssuiDlgInfo.pGroupCookie;
  848. }
  849. break;
  850. }
  851. default:
  852. {
  853. ASSERT(FALSE);
  854. break;
  855. }
  856. }
  857. hrResult = S_OK;
  858. break;
  859. }
  860. if (ssuiDlgInfo.hinstURLMON != NULL)
  861. FreeLibrary(ssuiDlgInfo.hinstURLMON);
  862. return hrResult;
  863. }
  864. /////////////////////////////////////////////////////////////////////////////
  865. // ShowScheduleUIDlgProc
  866. /////////////////////////////////////////////////////////////////////////////
  867. BOOL CALLBACK ShowScheduleUIDlgProc
  868. (
  869. HWND hwndDlg,
  870. UINT uMsg,
  871. WPARAM wParam,
  872. LPARAM lParam
  873. )
  874. {
  875. SSUIDLGINFO * pDlgInfo = (SSUIDLGINFO *)GetWindowLong(hwndDlg, DWL_USER);
  876. switch (uMsg)
  877. {
  878. case WM_INITDIALOG:
  879. {
  880. SSUIDLGINFO * pDlgInfo = (SSUIDLGINFO *)lParam;
  881. ASSERT(pDlgInfo != NULL);
  882. SetWindowLong(hwndDlg, DWL_USER, lParam);
  883. // Resize the dialog -- controls are to the right in RC.
  884. RECT rectCancel;
  885. GetWindowRect(GetDlgItem(hwndDlg, IDCANCEL), &rectCancel);
  886. MapWindowPoints(HWND_DESKTOP, hwndDlg, (POINT *)&rectCancel, 2);
  887. SetWindowPos( hwndDlg,
  888. NULL,
  889. 0,
  890. 0,
  891. rectCancel.right
  892. + (GetSystemMetrics(SM_CXDLGFRAME) * 2)
  893. + CX_DIALOG_GUTTER,
  894. rectCancel.bottom
  895. + (GetSystemMetrics(SM_CYDLGFRAME) * 2)
  896. + GetSystemMetrics(SM_CYCAPTION)
  897. + CY_DIALOG_GUTTER,
  898. SWP_NOMOVE
  899. | SWP_NOACTIVATE
  900. | SWP_NOZORDER
  901. | SWP_NOOWNERZORDER);
  902. // Initialize the initial dialog settings and content.
  903. InitDlgCtls(hwndDlg, pDlgInfo);
  904. InitDlgInfo(hwndDlg, pDlgInfo);
  905. break;
  906. }
  907. case WM_HELP:
  908. {
  909. MLWinHelpWrap((HWND)((LPHELPINFO) lParam)->hItemHandle,
  910. c_szHelpFile,
  911. HELP_WM_HELP,
  912. (DWORD)aCustomDlgHelpIDs);
  913. break;
  914. }
  915. case WM_CONTEXTMENU:
  916. {
  917. MLWinHelpWrap((HWND)wParam,
  918. c_szHelpFile,
  919. HELP_CONTEXTMENU,
  920. (DWORD)aCustomDlgHelpIDs);
  921. break;
  922. }
  923. case WM_COMMAND:
  924. {
  925. if (pDlgInfo == NULL)
  926. return FALSE;
  927. switch (LOWORD(wParam))
  928. {
  929. case IDOK:
  930. {
  931. if (
  932. pDlgInfo->bDataChanged
  933. &&
  934. FAILED(ApplyDlgChanges(hwndDlg, pDlgInfo))
  935. )
  936. {
  937. break;
  938. }
  939. if (pDlgInfo->bScheduleChanged)
  940. pDlgInfo->dwFlags |= SSUI_SCHEDULECHANGED;
  941. // FALL THROUGH!!!
  942. }
  943. case IDCANCEL:
  944. {
  945. EVAL(SUCCEEDED(SchedGroupComboBox_Clear(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST))));
  946. EndDialog(hwndDlg, wParam);
  947. break;
  948. }
  949. case IDC_CUSTOM_GROUP_EDIT:
  950. {
  951. switch (HIWORD(wParam))
  952. {
  953. case EN_CHANGE:
  954. {
  955. pDlgInfo->bDataChanged = TRUE;
  956. pDlgInfo->bScheduleNameChanged = TRUE;
  957. break;
  958. }
  959. default:
  960. break;
  961. }
  962. break;
  963. }
  964. case IDC_CUSTOM_GROUP_LIST:
  965. {
  966. switch (HIWORD(wParam))
  967. {
  968. case CBN_EDITCHANGE:
  969. {
  970. pDlgInfo->bDataChanged = TRUE;
  971. pDlgInfo->bScheduleNameChanged = TRUE;
  972. break;
  973. }
  974. case CBN_SELCHANGE:
  975. {
  976. HandleGroupChange(hwndDlg, pDlgInfo);
  977. break;
  978. }
  979. default:
  980. break;
  981. }
  982. break;
  983. }
  984. case IDC_CUSTOM_MONTHLY_PERIODIC_LIST1:
  985. case IDC_CUSTOM_MONTHLY_PERIODIC_LIST2:
  986. {
  987. switch (HIWORD(wParam))
  988. {
  989. case CBN_SELCHANGE:
  990. {
  991. OnDataChanged(hwndDlg, pDlgInfo);
  992. break;
  993. }
  994. default:
  995. break;
  996. }
  997. break;
  998. }
  999. case IDC_CUSTOM_TIME_REPEATEVERY_EDIT:
  1000. case IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT:
  1001. case IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT:
  1002. case IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT:
  1003. case IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT:
  1004. case IDC_CUSTOM_MONTHLY_PERIODIC_EDIT:
  1005. {
  1006. switch (HIWORD(wParam))
  1007. {
  1008. case EN_CHANGE:
  1009. {
  1010. OnDataChanged(hwndDlg, pDlgInfo);
  1011. break;
  1012. }
  1013. case EN_KILLFOCUS:
  1014. {
  1015. RestrictDlgItemRange(hwndDlg, LOWORD(wParam), pDlgInfo);
  1016. break;
  1017. }
  1018. default:
  1019. break;
  1020. }
  1021. break;
  1022. }
  1023. default:
  1024. {
  1025. if (HandleDlgButtonClick(hwndDlg, wParam, pDlgInfo))
  1026. OnDataChanged(hwndDlg, pDlgInfo);
  1027. break;
  1028. }
  1029. }
  1030. break;
  1031. }
  1032. case WM_NOTIFY:
  1033. {
  1034. switch (wParam)
  1035. {
  1036. case IDC_CUSTOM_TIME_UPDATEAT_TIME:
  1037. case IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME:
  1038. case IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME:
  1039. {
  1040. switch (((NMHDR *)lParam)->code)
  1041. {
  1042. case DTN_DATETIMECHANGE:
  1043. {
  1044. OnDataChanged(hwndDlg, pDlgInfo);
  1045. RestrictTimeRepeatEvery(hwndDlg);
  1046. break;
  1047. }
  1048. default:
  1049. break;
  1050. }
  1051. break;
  1052. }
  1053. default:
  1054. break;
  1055. }
  1056. break;
  1057. }
  1058. default:
  1059. return FALSE;
  1060. }
  1061. return TRUE;
  1062. }
  1063. /////////////////////////////////////////////////////////////////////////////
  1064. // HandleDlgButtonClick
  1065. /////////////////////////////////////////////////////////////////////////////
  1066. BOOL HandleDlgButtonClick
  1067. (
  1068. HWND hwndDlg,
  1069. WPARAM wParam,
  1070. SSUIDLGINFO * pDlgInfo
  1071. )
  1072. {
  1073. switch (LOWORD(wParam))
  1074. {
  1075. case IDC_CUSTOM_NEWGROUP:
  1076. {
  1077. ASSERT(pDlgInfo != NULL);
  1078. int iReply = IDNO;
  1079. if (pDlgInfo->bDataChanged)
  1080. {
  1081. // Ask user if they want to save changes.
  1082. iReply = SGMessageBox( hwndDlg,
  1083. IDS_CUSTOM_INFO_SAVECHANGES,
  1084. MB_YESNOCANCEL | MB_ICONQUESTION);
  1085. }
  1086. switch (iReply)
  1087. {
  1088. case IDYES:
  1089. {
  1090. // Apply changes
  1091. if (FAILED(ApplyDlgChanges(hwndDlg, pDlgInfo)))
  1092. break;
  1093. // FALL THROUGH!!!
  1094. }
  1095. case IDNO:
  1096. {
  1097. pDlgInfo->dwFlags |= SSUI_CREATENEWSCHEDULE;
  1098. *(pDlgInfo->pGroupCookie) = GUID_NULL;
  1099. SetTaskTriggerToDefaults(&pDlgInfo->ttTaskTrigger);
  1100. InitDlgInfo(hwndDlg, pDlgInfo);
  1101. break;
  1102. }
  1103. case IDCANCEL:
  1104. break;
  1105. }
  1106. break;
  1107. }
  1108. case IDC_CUSTOM_REMOVEGROUP:
  1109. {
  1110. // REVIEW: Can we check to see if the group is really in use. [jaym]
  1111. // Tell user that they are removing a group that may be in use.
  1112. if (SGMessageBox( hwndDlg,
  1113. IDS_CUSTOM_INFO_REMOVEGROUP,
  1114. MB_YESNO | MB_ICONWARNING) == IDYES)
  1115. {
  1116. NOTIFICATIONCOOKIE groupCookie;
  1117. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST);
  1118. if (
  1119. SUCCEEDED(SchedGroupComboBox_GetCurGroup( hwndCombo,
  1120. &groupCookie))
  1121. &&
  1122. SUCCEEDED(DeleteScheduleGroup(&groupCookie))
  1123. )
  1124. {
  1125. // Reset the list and select the first group
  1126. EVAL(SUCCEEDED(SchedGroupComboBox_Fill(hwndCombo)));
  1127. ComboBox_SetCurSel(hwndCombo, 0);
  1128. pDlgInfo->dwFlags |= SSUI_SCHEDULEREMOVED;
  1129. // Make sure we don't ask the user to save changes.
  1130. pDlgInfo->bDataChanged = FALSE;
  1131. HandleGroupChange(hwndDlg, pDlgInfo);
  1132. }
  1133. else
  1134. {
  1135. SGMessageBox( hwndDlg,
  1136. IDS_CUSTOM_ERROR_REMOVEGROUP,
  1137. MB_OK | MB_ICONWARNING);
  1138. break;
  1139. }
  1140. }
  1141. break;
  1142. }
  1143. case IDC_CUSTOM_WEEKLY_DAY1:
  1144. case IDC_CUSTOM_WEEKLY_DAY2:
  1145. case IDC_CUSTOM_WEEKLY_DAY3:
  1146. case IDC_CUSTOM_WEEKLY_DAY4:
  1147. case IDC_CUSTOM_WEEKLY_DAY5:
  1148. case IDC_CUSTOM_WEEKLY_DAY6:
  1149. case IDC_CUSTOM_WEEKLY_DAY7:
  1150. case IDC_CUSTOM_MINIMIZENETUSE:
  1151. {
  1152. return TRUE;
  1153. }
  1154. default:
  1155. return HandleButtonClick(hwndDlg, wParam);
  1156. }
  1157. return FALSE;
  1158. }
  1159. /////////////////////////////////////////////////////////////////////////////
  1160. // HandleButtonClick
  1161. /////////////////////////////////////////////////////////////////////////////
  1162. BOOL HandleButtonClick
  1163. (
  1164. HWND hwndDlg,
  1165. WPARAM wParam
  1166. )
  1167. {
  1168. BOOL bEnable = (IsDlgButtonChecked(hwndDlg, LOWORD(wParam)) == BST_CHECKED);
  1169. switch (LOWORD(wParam))
  1170. {
  1171. case IDC_CUSTOM_DAILY:
  1172. case IDC_CUSTOM_WEEKLY:
  1173. case IDC_CUSTOM_MONTHLY:
  1174. {
  1175. SetDlgCustomType(hwndDlg, LOWORD(wParam));
  1176. break;
  1177. }
  1178. case IDC_CUSTOM_DAILY_EVERYNDAYS:
  1179. {
  1180. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT), bEnable);
  1181. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_SPIN), bEnable);
  1182. break;
  1183. }
  1184. case IDC_CUSTOM_DAILY_EVERYWEEKDAY:
  1185. {
  1186. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT), !bEnable);
  1187. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_SPIN), !bEnable);
  1188. break;
  1189. }
  1190. case IDC_CUSTOM_MONTHLY_DAYOFMONTH:
  1191. {
  1192. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT), bEnable);
  1193. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_SPIN), bEnable);
  1194. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT), bEnable);
  1195. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_SPIN), bEnable);
  1196. ListBox_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST1), !bEnable);
  1197. ListBox_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2), !bEnable);
  1198. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_EDIT), !bEnable);
  1199. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_SPIN), !bEnable);
  1200. break;
  1201. }
  1202. case IDC_CUSTOM_MONTHLY_PERIODIC:
  1203. {
  1204. ListBox_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST1), bEnable);
  1205. ListBox_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2), bEnable);
  1206. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_EDIT), bEnable);
  1207. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_SPIN), bEnable);
  1208. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT), !bEnable);
  1209. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_SPIN), !bEnable);
  1210. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT), !bEnable);
  1211. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_SPIN), !bEnable);
  1212. break;
  1213. }
  1214. case IDC_CUSTOM_TIME_UPDATEAT:
  1215. {
  1216. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), bEnable);
  1217. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_EDIT), !bEnable);
  1218. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_SPIN), !bEnable);
  1219. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN), !bEnable);
  1220. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), !bEnable);
  1221. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), !bEnable);
  1222. break;
  1223. }
  1224. case IDC_CUSTOM_TIME_REPEATEVERY:
  1225. {
  1226. Edit_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_EDIT), bEnable);
  1227. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_SPIN), bEnable);
  1228. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN), bEnable);
  1229. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), !bEnable);
  1230. bEnable = (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN) == BST_CHECKED);
  1231. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), bEnable);
  1232. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), bEnable);
  1233. break;
  1234. }
  1235. case IDC_CUSTOM_TIME_REPEATBETWEEN:
  1236. {
  1237. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), bEnable);
  1238. EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), bEnable);
  1239. // Restrict 'repeat between' to time range - 1hr
  1240. if (bEnable)
  1241. RestrictTimeRepeatEvery(hwndDlg);
  1242. else
  1243. {
  1244. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_SPIN),
  1245. DEFAULT_REPEATUPDATE_HRS_MIN, DEFAULT_REPEATUPDATE_HRS_MAX);
  1246. }
  1247. break;
  1248. }
  1249. default:
  1250. return FALSE;
  1251. }
  1252. return TRUE;
  1253. }
  1254. /////////////////////////////////////////////////////////////////////////////
  1255. // HandleGroupChange
  1256. /////////////////////////////////////////////////////////////////////////////
  1257. BOOL HandleGroupChange
  1258. (
  1259. HWND hwndDlg,
  1260. SSUIDLGINFO * pDlgInfo
  1261. )
  1262. {
  1263. int iReply = IDNO;
  1264. BOOL bChanged = FALSE;
  1265. if (pDlgInfo->bDataChanged)
  1266. {
  1267. // Ask user if they want to save changes.
  1268. iReply = SGMessageBox( hwndDlg,
  1269. IDS_CUSTOM_INFO_SAVECHANGES,
  1270. MB_YESNO | MB_ICONQUESTION);
  1271. }
  1272. switch (iReply)
  1273. {
  1274. case IDYES:
  1275. {
  1276. // Apply changes
  1277. if (FAILED(ApplyDlgChanges(hwndDlg, pDlgInfo)))
  1278. break;
  1279. // FALL THROUGH!!!
  1280. }
  1281. case IDNO:
  1282. {
  1283. // No longer creating new schedule, the
  1284. // user has selected an existing schedule.
  1285. pDlgInfo->dwFlags &= ~SSUI_CREATENEWSCHEDULE;
  1286. EVAL(SUCCEEDED(SchedGroupComboBox_GetCurGroup( GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST),
  1287. pDlgInfo->pGroupCookie)));
  1288. EVAL(SUCCEEDED(GetSchedGroupTaskTrigger( pDlgInfo->pGroupCookie,
  1289. &pDlgInfo->ttTaskTrigger)));
  1290. InitDlgInfo(hwndDlg, pDlgInfo);
  1291. pDlgInfo->bScheduleChanged = TRUE;
  1292. bChanged = TRUE;
  1293. break;
  1294. }
  1295. default:
  1296. {
  1297. ASSERT(FALSE);
  1298. break;
  1299. }
  1300. }
  1301. return bChanged;
  1302. }
  1303. /////////////////////////////////////////////////////////////////////////////
  1304. // InitDlgCtls
  1305. /////////////////////////////////////////////////////////////////////////////
  1306. void InitDlgCtls
  1307. (
  1308. HWND hwndDlg,
  1309. SSUIDLGINFO * pDlgInfo
  1310. )
  1311. {
  1312. DWORD i;
  1313. // Reposition the dialog controls.
  1314. PositionDlgCtls(hwndDlg);
  1315. // Load the common combo box values.
  1316. for (i = 0; i < ARRAYSIZE(c_rgnCtlItems); i++)
  1317. {
  1318. HWND hwndCtl = GetDlgItem(hwndDlg, c_rgnCtlItems[i].idContainer);
  1319. ASSERT(hwndCtl != NULL);
  1320. for (int j = c_rgnCtlItems[i].idFirst; j <= c_rgnCtlItems[i].idLast; j++)
  1321. {
  1322. TCHAR szString[MAX_LOADSTRING_LEN];
  1323. EVAL(MLLoadString(j, szString, MAX_LOADSTRING_LEN) != 0);
  1324. EVAL(ComboBox_AddString(hwndCtl, szString) != CB_ERR);
  1325. }
  1326. }
  1327. DWORD dwFirstDay = 0;
  1328. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1329. LOCALE_IFIRSTDAYOFWEEK,
  1330. (char *)&dwFirstDay,
  1331. SIZEOF(DWORD)));
  1332. dwFirstDay = LOCALE_SDAYNAME1 + (dwFirstDay - TEXT('0'));
  1333. // Load check and combo boxes with the days of the weeks
  1334. int iDay;
  1335. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2);
  1336. TCHAR szDayName[32];
  1337. for (i = dwFirstDay; i < dwFirstDay+7; i++)
  1338. {
  1339. iDay = ((i <= LOCALE_SDAYNAME7) ? i : (LOCALE_SDAYNAME1 + (i - LOCALE_SDAYNAME7 - 1)));
  1340. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1341. iDay,
  1342. szDayName,
  1343. ARRAYSIZE(szDayName)));
  1344. SetDlgItemText( hwndDlg,
  1345. IDC_CUSTOM_WEEKLY_DAY1 + (i - dwFirstDay),
  1346. szDayName);
  1347. int iIndex = ComboBox_AddString(hwndCombo, szDayName);
  1348. // Initialize the lookup table for the combobox as we go.
  1349. if (iDay == LOCALE_SDAYNAME1)
  1350. s_rgwDaysOfTheWeek[iIndex] = TASK_MONDAY;
  1351. else if (iDay == LOCALE_SDAYNAME2)
  1352. s_rgwDaysOfTheWeek[iIndex] = TASK_TUESDAY;
  1353. else if (iDay == LOCALE_SDAYNAME3)
  1354. s_rgwDaysOfTheWeek[iIndex] = TASK_WEDNESDAY;
  1355. else if (iDay == LOCALE_SDAYNAME4)
  1356. s_rgwDaysOfTheWeek[iIndex] = TASK_THURSDAY;
  1357. else if (iDay == LOCALE_SDAYNAME5)
  1358. s_rgwDaysOfTheWeek[iIndex] = TASK_FRIDAY;
  1359. else if (iDay == LOCALE_SDAYNAME6)
  1360. s_rgwDaysOfTheWeek[iIndex] = TASK_SATURDAY;
  1361. else if (iDay == LOCALE_SDAYNAME7)
  1362. s_rgwDaysOfTheWeek[iIndex] = TASK_SUNDAY;
  1363. else
  1364. ASSERT(FALSE);
  1365. }
  1366. // Show/Hide controls based on dialog type.
  1367. if (pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE)
  1368. {
  1369. // Hide the 'New' and 'Remove' buttons if
  1370. // we are creating a new schedule group.
  1371. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_NEWGROUP), SW_HIDE);
  1372. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_REMOVEGROUP), SW_HIDE);
  1373. // Hide the dropdown schedule group list.
  1374. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST), SW_HIDE);
  1375. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT), SW_SHOW);
  1376. }
  1377. else if (pDlgInfo->dwFlags & SSUI_EDITSCHEDULE)
  1378. {
  1379. // Hide the schedule group name edit.
  1380. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT), SW_HIDE);
  1381. ShowWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST), SW_SHOW);
  1382. EVAL(SUCCEEDED(SchedGroupComboBox_Fill(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST))));
  1383. EVAL(SUCCEEDED(SchedGroupComboBox_SetCurGroup(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST), pDlgInfo->pGroupCookie)));
  1384. }
  1385. else
  1386. ASSERT(FALSE);
  1387. // Setup spinner ranges.
  1388. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_SPIN),
  1389. DEFAULT_DAILY_EVERYNDAYS_MIN, DEFAULT_DAILY_EVERYNDAYS_MAX);
  1390. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_WEEKLY_REPEATWEEKS_SPIN),
  1391. DEFAULT_WEEKLY_REPEATWEEKS_MIN, DEFAULT_WEEKLY_REPEATWEEKS_MAX);
  1392. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_SPIN),
  1393. DEFAULT_MONTHLY_DAY_MIN, DEFAULT_MONTHLY_DAY_MAX);
  1394. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_SPIN),
  1395. DEFAULT_MONTHLY_MONTHS_MIN, DEFAULT_MONTHLY_MONTHS_MAX);
  1396. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_SPIN),
  1397. DEFAULT_MONTHLY_MONTHS_MIN, DEFAULT_MONTHLY_MONTHS_MAX);
  1398. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_SPIN),
  1399. DEFAULT_REPEATUPDATE_HRS_MIN, DEFAULT_REPEATUPDATE_HRS_MAX);
  1400. // Setup the time picker controls to use a short time format with no seconds.
  1401. TCHAR szTimeFormat[MAX_SHORTTIMEFORMAT_LEN];
  1402. LPTSTR pszTimeFormat = szTimeFormat;
  1403. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1404. LOCALE_STIMEFORMAT,
  1405. szTimeFormat,
  1406. ARRAYSIZE(szTimeFormat)));
  1407. TCHAR szTimeSep[MAX_TIMESEP_LEN];
  1408. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1409. LOCALE_STIME,
  1410. szTimeSep,
  1411. ARRAYSIZE(szTimeSep)));
  1412. int cchTimeSep = lstrlen(szTimeSep);
  1413. TCHAR szShortTimeFormat[MAX_SHORTTIMEFORMAT_LEN];
  1414. LPTSTR pszShortTimeFormat = szShortTimeFormat;
  1415. // Remove the seconds format string and preceeding separator.
  1416. while (*pszTimeFormat)
  1417. {
  1418. if ((*pszTimeFormat != TEXT('s')) && (*pszTimeFormat != TEXT('S')))
  1419. *pszShortTimeFormat++ = *pszTimeFormat;
  1420. else
  1421. {
  1422. *pszShortTimeFormat = TEXT('\0');
  1423. StrTrim(szShortTimeFormat, TEXT(" "));
  1424. StrTrim(szShortTimeFormat, szTimeSep);
  1425. pszShortTimeFormat = szShortTimeFormat + lstrlen(szShortTimeFormat);
  1426. }
  1427. pszTimeFormat++;
  1428. }
  1429. *pszShortTimeFormat = TEXT('\0');
  1430. // Set the format for the time picker controls.
  1431. DateTime_SetFormat(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), szShortTimeFormat);
  1432. DateTime_SetFormat(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), szShortTimeFormat);
  1433. DateTime_SetFormat(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), szShortTimeFormat);
  1434. }
  1435. /////////////////////////////////////////////////////////////////////////////
  1436. // PositionDlgCtls
  1437. /////////////////////////////////////////////////////////////////////////////
  1438. void PositionDlgCtls
  1439. (
  1440. HWND hwndDlg
  1441. )
  1442. {
  1443. RECT rectDestGroup;
  1444. GetWindowRect(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_DEST), &rectDestGroup);
  1445. MapWindowPoints(HWND_DESKTOP, hwndDlg, (POINT *)&rectDestGroup, 2);
  1446. for (int i = 0; i < ARRAYSIZE(c_rgnCtlGroups); i++)
  1447. {
  1448. HWND hwndGroup = GetDlgItem(hwndDlg, c_rgnCtlGroups[i].idContainer);
  1449. ASSERT(hwndGroup != NULL);
  1450. RECT rectSrcGroup;
  1451. GetWindowRect(hwndGroup, &rectSrcGroup);
  1452. MapWindowPoints(HWND_DESKTOP, hwndDlg, (POINT *)&rectSrcGroup, 2);
  1453. for (int j = c_rgnCtlGroups[i].idFirst; j <= c_rgnCtlGroups[i].idLast; j++)
  1454. {
  1455. HWND hwndItem = GetDlgItem(hwndDlg, j);
  1456. RECT rectItem;
  1457. GetWindowRect(hwndItem, &rectItem);
  1458. MapWindowPoints(HWND_DESKTOP, hwndDlg, (POINT *)&rectItem, 2);
  1459. MoveWindow( hwndItem,
  1460. rectDestGroup.left + (rectItem.left - rectSrcGroup.left),
  1461. rectDestGroup.top + (rectItem.top - rectSrcGroup.top),
  1462. (rectItem.right - rectItem.left),
  1463. (rectItem.bottom - rectItem.top),
  1464. FALSE);
  1465. }
  1466. }
  1467. }
  1468. /////////////////////////////////////////////////////////////////////////////
  1469. // InitDlgDefaults
  1470. /////////////////////////////////////////////////////////////////////////////
  1471. void InitDlgDefaults
  1472. (
  1473. HWND hwndDlg,
  1474. SSUIDLGINFO * pDlgInfo
  1475. )
  1476. {
  1477. TCHAR szDefaultName[MAX_GROUPNAME_LEN];
  1478. // Init control defaults for new schedule group.
  1479. MLLoadString(IDS_CUSTOM_NEWSCHEDDEFNAME, szDefaultName, ARRAYSIZE(szDefaultName));
  1480. if (pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE)
  1481. {
  1482. SetDlgItemText(hwndDlg, IDC_CUSTOM_GROUP_EDIT, szDefaultName);
  1483. SetDlgItemText(hwndDlg, IDC_CUSTOM_GROUP_LIST, szDefaultName);
  1484. pDlgInfo->bDataChanged = FALSE;
  1485. }
  1486. // If we are creating a new schedule, everything needs to be saved.
  1487. pDlgInfo->bDataChanged = ((pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE) ? TRUE : FALSE);
  1488. // Daily group
  1489. CheckRadioButton(hwndDlg, IDC_TYPE_GROUP_FIRST, IDC_TYPE_GROUP_LAST, IDC_CUSTOM_DAILY);
  1490. // Daily group properties
  1491. CheckRadioButton(hwndDlg, IDC_DAILY_GROUP_FIRST, IDC_DAILY_GROUP_LAST, IDC_CUSTOM_DAILY_EVERYNDAYS);
  1492. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS, NULL);
  1493. SetDlgItemInt(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT, DEFAULT_DAILY_EVERYNDAYS, FALSE);
  1494. // Weekly group properties
  1495. SetDlgItemInt(hwndDlg, IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT, DEFAULT_WEEKLY_REPEATWEEKS, FALSE);
  1496. SYSTEMTIME stLocal;
  1497. GetLocalTime(&stLocal);
  1498. WORD rgfDaysOfTheWeek = (1 << stLocal.wDayOfWeek);
  1499. SetDlgWeekDays(hwndDlg, rgfDaysOfTheWeek);
  1500. // Monthly group properties
  1501. CheckRadioButton(hwndDlg, IDC_MONTHLY_GROUP_FIRST, IDC_MONTHLY_GROUP_LAST, IDC_CUSTOM_MONTHLY_DAYOFMONTH);
  1502. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH, NULL);
  1503. SetDlgItemInt(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT, stLocal.wDay, FALSE);
  1504. SetDlgItemInt(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT, DEFAULT_MONTHLY_MONTHS, FALSE);
  1505. // REVIEW: Create code to figure out item to select for current date. [jaym]
  1506. ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST1), 0);
  1507. ComboBox_SetCurSel( GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2),
  1508. DayIndexFromDaysOfTheWeekFlags(rgfDaysOfTheWeek));
  1509. SetDlgItemInt(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_EDIT, DEFAULT_MONTHLY_MONTHS, FALSE);
  1510. // Time properties
  1511. CheckRadioButton(hwndDlg, IDC_TIME_GROUP_FIRST, IDC_TIME_GROUP_LAST, IDC_CUSTOM_TIME_UPDATEAT);
  1512. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT, NULL);
  1513. SYSTEMTIME st = { 0 };
  1514. GetLocalTime(&st);
  1515. st.wHour = DEFAULT_UPDATETIME_HRS;
  1516. st.wMinute = DEFAULT_UPDATETIME_MINS;
  1517. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), GDT_VALID, &st);
  1518. SetDlgItemInt(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_EDIT, DEFAULT_REPEATUPDATE_HRS, FALSE);
  1519. st.wHour = DEFAULT_REPEAT_START_HRS;
  1520. st.wMinute = DEFAULT_REPEAT_START_MINS;
  1521. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), GDT_VALID, &st);
  1522. st.wHour = DEFAULT_REPEAT_END_HRS;
  1523. st.wMinute = DEFAULT_REPEAT_END_MINS;
  1524. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), GDT_VALID, &st);
  1525. // Disable some controls if we are a predefined group.
  1526. HWND hwndGroupList = GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST);
  1527. HWND hwndGroupEdit = FindWindowEx( hwndGroupList,
  1528. NULL,
  1529. TEXT("Edit"),
  1530. NULL);
  1531. if (*(pDlgInfo->pGroupCookie) == NOTFCOOKIE_SCHEDULE_GROUP_DAILY)
  1532. {
  1533. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY), TRUE);
  1534. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_WEEKLY), FALSE);
  1535. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY), FALSE);
  1536. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_REMOVEGROUP), FALSE);
  1537. Edit_SetReadOnly(hwndGroupEdit, TRUE);
  1538. }
  1539. else if (*(pDlgInfo->pGroupCookie) == NOTFCOOKIE_SCHEDULE_GROUP_WEEKLY)
  1540. {
  1541. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY), FALSE);
  1542. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_WEEKLY), TRUE);
  1543. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY), FALSE);
  1544. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_REMOVEGROUP), FALSE);
  1545. Edit_SetReadOnly(hwndGroupEdit, TRUE);
  1546. }
  1547. else if (*(pDlgInfo->pGroupCookie) == NOTFCOOKIE_SCHEDULE_GROUP_MONTHLY)
  1548. {
  1549. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY), FALSE);
  1550. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_WEEKLY), FALSE);
  1551. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY), TRUE);
  1552. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_REMOVEGROUP), FALSE);
  1553. Edit_SetReadOnly(hwndGroupEdit, TRUE);
  1554. }
  1555. else
  1556. {
  1557. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_DAILY), TRUE);
  1558. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_WEEKLY), TRUE);
  1559. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY), TRUE);
  1560. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOM_REMOVEGROUP), TRUE);
  1561. Edit_SetReadOnly(hwndGroupEdit, FALSE);
  1562. }
  1563. // Make sure the combo redraws so the enable
  1564. // or disable of the edit control looks good.
  1565. RedrawWindow(hwndGroupList, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1566. // Vary start of next update
  1567. CheckDlgButton(hwndDlg, IDC_CUSTOM_MINIMIZENETUSE, BST_CHECKED);
  1568. }
  1569. /////////////////////////////////////////////////////////////////////////////
  1570. // SetDlgCustomType
  1571. /////////////////////////////////////////////////////////////////////////////
  1572. void SetDlgCustomType
  1573. (
  1574. HWND hwndDlg,
  1575. int iType
  1576. )
  1577. {
  1578. int i;
  1579. for (i = IDC_CUSTOM_DAILY_FIRST; i <= IDC_CUSTOM_DAILY_LAST; i++)
  1580. ShowWindow(GetDlgItem(hwndDlg, i), ((iType == IDC_CUSTOM_DAILY) ? SW_SHOW : SW_HIDE));
  1581. for (i = IDC_CUSTOM_WEEKLY_FIRST; i <= IDC_CUSTOM_WEEKLY_LAST; i++)
  1582. ShowWindow(GetDlgItem(hwndDlg, i), ((iType == IDC_CUSTOM_WEEKLY) ? SW_SHOW : SW_HIDE));
  1583. for (i = IDC_CUSTOM_MONTHLY_FIRST; i <= IDC_CUSTOM_MONTHLY_LAST; i++)
  1584. ShowWindow(GetDlgItem(hwndDlg, i), ((iType == IDC_CUSTOM_MONTHLY) ? SW_SHOW : SW_HIDE));
  1585. }
  1586. /////////////////////////////////////////////////////////////////////////////
  1587. // InitDlgInfo
  1588. /////////////////////////////////////////////////////////////////////////////
  1589. void InitDlgInfo
  1590. (
  1591. HWND hwndDlg,
  1592. SSUIDLGINFO * pDlgInfo
  1593. )
  1594. {
  1595. int nIDTriggerType;
  1596. TASK_TRIGGER * pTT = &(pDlgInfo->ttTaskTrigger);
  1597. #ifdef DEBUG
  1598. DumpTaskTrigger(pTT);
  1599. #endif // DEBUG
  1600. pDlgInfo->bInitializing = TRUE;
  1601. // Initialize defaults for dialog controls.
  1602. InitDlgDefaults(hwndDlg, pDlgInfo);
  1603. CheckDlgButton( hwndDlg,
  1604. IDC_CUSTOM_MINIMIZENETUSE,
  1605. ((pTT->wRandomMinutesInterval == 0) ? BST_UNCHECKED : BST_CHECKED));
  1606. // Initialize the 'Time' settings.
  1607. if (pTT->MinutesInterval == 0)
  1608. {
  1609. // Update at N
  1610. CheckRadioButton(hwndDlg, IDC_TIME_GROUP_FIRST, IDC_TIME_GROUP_LAST, IDC_CUSTOM_TIME_UPDATEAT);
  1611. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT, NULL);
  1612. SYSTEMTIME st = { 0 };
  1613. GetLocalTime(&st);
  1614. st.wHour = pTT->wStartHour;
  1615. st.wMinute = pTT->wStartMinute;
  1616. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), GDT_VALID, &st);
  1617. }
  1618. else
  1619. {
  1620. // Repeat every N hour(s)
  1621. CheckRadioButton(hwndDlg, IDC_TIME_GROUP_FIRST, IDC_TIME_GROUP_LAST, IDC_CUSTOM_TIME_REPEATEVERY);
  1622. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY, NULL);
  1623. SetDlgItemInt( hwndDlg,
  1624. IDC_CUSTOM_TIME_REPEATEVERY_EDIT,
  1625. ((pDlgInfo->dwRepeatHrsAreMins)
  1626. ? pTT->MinutesInterval
  1627. : (pTT->MinutesInterval / 60)),
  1628. FALSE);
  1629. // Between X and Y
  1630. if (pTT->MinutesDuration != (24 * 60))
  1631. {
  1632. CheckDlgButton(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN, BST_CHECKED);
  1633. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN, NULL);
  1634. SYSTEMTIME st = { 0 };
  1635. GetLocalTime(&st);
  1636. st.wHour = pTT->wStartHour;
  1637. st.wMinute = pTT->wStartMinute;
  1638. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME), GDT_VALID, &st);
  1639. DWORD dwEndTime = IncTime( MAKELONG(pTT->wStartHour, pTT->wStartMinute),
  1640. (pTT->MinutesDuration / 60),
  1641. (pTT->MinutesDuration % 60));
  1642. st.wHour = LOWORD(dwEndTime);
  1643. st.wMinute = HIWORD(dwEndTime);
  1644. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME), GDT_VALID, &st);
  1645. }
  1646. }
  1647. // Initialize the 'Days' settings.
  1648. switch (pTT->TriggerType)
  1649. {
  1650. case TASK_TIME_TRIGGER_DAILY:
  1651. {
  1652. nIDTriggerType = IDC_CUSTOM_DAILY;
  1653. // Every N day(s)
  1654. CheckRadioButton(hwndDlg, IDC_DAILY_GROUP_FIRST, IDC_DAILY_GROUP_LAST, IDC_CUSTOM_DAILY_EVERYNDAYS);
  1655. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS, NULL);
  1656. SetDlgItemInt(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT, pTT->Type.Daily.DaysInterval, FALSE);
  1657. break;
  1658. }
  1659. case TASK_TIME_TRIGGER_WEEKLY:
  1660. {
  1661. // Special case for Weekly repeating every 1 week
  1662. if (
  1663. (pTT->Type.Weekly.WeeksInterval == 1)
  1664. &&
  1665. (pTT->Type.Weekly.rgfDaysOfTheWeek == TASK_WEEKDAYS)
  1666. )
  1667. {
  1668. if (*(pDlgInfo->pGroupCookie) == NOTFCOOKIE_SCHEDULE_GROUP_WEEKLY)
  1669. {
  1670. nIDTriggerType = IDC_CUSTOM_WEEKLY;
  1671. // Weekly -- Every 1 week on MTWTF
  1672. SetDlgItemInt(hwndDlg, IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT, 1, FALSE);
  1673. SetDlgWeekDays(hwndDlg, TASK_WEEKDAYS);
  1674. }
  1675. else
  1676. {
  1677. nIDTriggerType = IDC_CUSTOM_DAILY;
  1678. // Daily -- Every weekday
  1679. CheckRadioButton(hwndDlg, IDC_DAILY_GROUP_FIRST, IDC_DAILY_GROUP_LAST, IDC_CUSTOM_DAILY_EVERYWEEKDAY);
  1680. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_DAILY_EVERYWEEKDAY, NULL);
  1681. }
  1682. }
  1683. else
  1684. {
  1685. nIDTriggerType = IDC_CUSTOM_WEEKLY;
  1686. // Weekly -- Every N weeks on SMTWTFS
  1687. // Every N weeks
  1688. SetDlgItemInt(hwndDlg, IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT, pTT->Type.Weekly.WeeksInterval, FALSE);
  1689. // on SMTWTFS
  1690. SetDlgWeekDays(hwndDlg, pTT->Type.Weekly.rgfDaysOfTheWeek);
  1691. }
  1692. break;
  1693. }
  1694. case TASK_TIME_TRIGGER_MONTHLYDATE:
  1695. {
  1696. nIDTriggerType = IDC_CUSTOM_MONTHLY;
  1697. // Monthly -- Day X of every Y month(s)
  1698. CheckRadioButton(hwndDlg, IDC_MONTHLY_GROUP_FIRST, IDC_MONTHLY_GROUP_LAST, IDC_CUSTOM_MONTHLY_DAYOFMONTH);
  1699. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH, NULL);
  1700. // Day X
  1701. SetDlgItemInt( hwndDlg,
  1702. IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT,
  1703. DayFromDaysFlags(pTT->Type.MonthlyDate.rgfDays),
  1704. FALSE);
  1705. // of every Y month(s)
  1706. SetDlgItemMonth(hwndDlg,
  1707. IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT,
  1708. pTT->Type.MonthlyDate.rgfMonths);
  1709. break;
  1710. }
  1711. case TASK_TIME_TRIGGER_MONTHLYDOW:
  1712. {
  1713. nIDTriggerType = IDC_CUSTOM_MONTHLY;
  1714. // Monthly -- The X Y of every Z month(s)
  1715. CheckRadioButton(hwndDlg, IDC_MONTHLY_GROUP_FIRST, IDC_MONTHLY_GROUP_LAST, IDC_CUSTOM_MONTHLY_PERIODIC);
  1716. HandleDlgButtonClick(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC, NULL);
  1717. // The X
  1718. ComboBox_SetCurSel( GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST1),
  1719. pTT->Type.MonthlyDOW.wWhichWeek-1);
  1720. // Y
  1721. ComboBox_SetCurSel( GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2),
  1722. DayIndexFromDaysOfTheWeekFlags(pTT->Type.MonthlyDOW.rgfDaysOfTheWeek));
  1723. // of every Z month(s)
  1724. SetDlgItemMonth(hwndDlg,
  1725. IDC_CUSTOM_MONTHLY_PERIODIC_EDIT,
  1726. pTT->Type.MonthlyDOW.rgfMonths);
  1727. break;
  1728. }
  1729. default:
  1730. {
  1731. ASSERT(FALSE);
  1732. break;
  1733. }
  1734. }
  1735. CheckRadioButton(hwndDlg, IDC_TYPE_GROUP_FIRST, IDC_TYPE_GROUP_LAST, nIDTriggerType);
  1736. HandleDlgButtonClick(hwndDlg, nIDTriggerType, NULL);
  1737. SetTaskTriggerFromDlg(hwndDlg, pDlgInfo);
  1738. SetDlgItemNextUpdate(hwndDlg, IDC_CUSTOM_NEXTUPDATE, pDlgInfo);
  1739. // Set focus to the group name control.
  1740. if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT)))
  1741. SetFocus(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT));
  1742. else
  1743. SetFocus(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST));
  1744. // Make sure we get asked to save for new groups.
  1745. pDlgInfo->bDataChanged = ((pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE) ? TRUE : FALSE);
  1746. pDlgInfo->bScheduleNameChanged = FALSE;
  1747. pDlgInfo->bInitializing = FALSE;
  1748. }
  1749. /////////////////////////////////////////////////////////////////////////////
  1750. // SetDlgWeekDays
  1751. /////////////////////////////////////////////////////////////////////////////
  1752. void SetDlgWeekDays
  1753. (
  1754. HWND hwndDlg,
  1755. WORD rgfDaysOfTheWeek
  1756. )
  1757. {
  1758. // If it doesn't have any days, stick one in arbitrarily.
  1759. if (rgfDaysOfTheWeek == 0)
  1760. rgfDaysOfTheWeek = TASK_SUNDAY;
  1761. DWORD dwFirstDay = 0;
  1762. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1763. LOCALE_IFIRSTDAYOFWEEK,
  1764. (char *)&dwFirstDay,
  1765. SIZEOF(DWORD)));
  1766. dwFirstDay = LOCALE_SDAYNAME1 + (dwFirstDay - TEXT('0'));
  1767. for (DWORD i = dwFirstDay; i <= dwFirstDay+7; i++)
  1768. {
  1769. BOOL bCheck;
  1770. int iDay = ((i <= LOCALE_SDAYNAME7) ? i
  1771. : (LOCALE_SDAYNAME1 + (i - LOCALE_SDAYNAME7 - 1)));
  1772. if (iDay == LOCALE_SDAYNAME1)
  1773. bCheck = (rgfDaysOfTheWeek & TASK_MONDAY);
  1774. else if (iDay == LOCALE_SDAYNAME2)
  1775. bCheck = (rgfDaysOfTheWeek & TASK_TUESDAY);
  1776. else if (iDay == LOCALE_SDAYNAME3)
  1777. bCheck = (rgfDaysOfTheWeek & TASK_WEDNESDAY);
  1778. else if (iDay == LOCALE_SDAYNAME4)
  1779. bCheck = (rgfDaysOfTheWeek & TASK_THURSDAY);
  1780. else if (iDay == LOCALE_SDAYNAME5)
  1781. bCheck = (rgfDaysOfTheWeek & TASK_FRIDAY);
  1782. else if (iDay == LOCALE_SDAYNAME6)
  1783. bCheck = (rgfDaysOfTheWeek & TASK_SATURDAY);
  1784. else if (iDay == LOCALE_SDAYNAME7)
  1785. bCheck = (rgfDaysOfTheWeek & TASK_SUNDAY);
  1786. else
  1787. ASSERT(FALSE);
  1788. CheckDlgButton( hwndDlg,
  1789. IDC_CUSTOM_WEEKLY_DAY1 + (i - dwFirstDay),
  1790. (bCheck ? BST_CHECKED : BST_UNCHECKED));
  1791. }
  1792. }
  1793. /////////////////////////////////////////////////////////////////////////////
  1794. // GetDlgWeekDays
  1795. /////////////////////////////////////////////////////////////////////////////
  1796. WORD GetDlgWeekDays
  1797. (
  1798. HWND hwndDlg
  1799. )
  1800. {
  1801. WORD wDays = 0;
  1802. DWORD dwFirstDay = 0;
  1803. EVAL(GetLocaleInfo( LOCALE_USER_DEFAULT,
  1804. LOCALE_IFIRSTDAYOFWEEK,
  1805. (char *)&dwFirstDay,
  1806. SIZEOF(DWORD)));
  1807. dwFirstDay = LOCALE_SDAYNAME1 + (dwFirstDay - TEXT('0'));
  1808. for (DWORD i = dwFirstDay; i <= dwFirstDay+7; i++)
  1809. {
  1810. if (IsDlgButtonChecked( hwndDlg,
  1811. IDC_CUSTOM_WEEKLY_DAY1 + (i - dwFirstDay)) == BST_CHECKED)
  1812. {
  1813. int iDay = ((i <= LOCALE_SDAYNAME7) ? i
  1814. : (LOCALE_SDAYNAME1 + (i - LOCALE_SDAYNAME7 - 1)));
  1815. if (iDay == LOCALE_SDAYNAME1)
  1816. wDays |= TASK_MONDAY;
  1817. else if (iDay == LOCALE_SDAYNAME2)
  1818. wDays |= TASK_TUESDAY;
  1819. else if (iDay == LOCALE_SDAYNAME3)
  1820. wDays |= TASK_WEDNESDAY;
  1821. else if (iDay == LOCALE_SDAYNAME4)
  1822. wDays |= TASK_THURSDAY;
  1823. else if (iDay == LOCALE_SDAYNAME5)
  1824. wDays |= TASK_FRIDAY;
  1825. else if (iDay == LOCALE_SDAYNAME6)
  1826. wDays |= TASK_SATURDAY;
  1827. else if (iDay == LOCALE_SDAYNAME7)
  1828. wDays |= TASK_SUNDAY;
  1829. else
  1830. ASSERT(FALSE);
  1831. }
  1832. }
  1833. return wDays;
  1834. }
  1835. /////////////////////////////////////////////////////////////////////////////
  1836. // SetTaskTriggerFromDlg
  1837. /////////////////////////////////////////////////////////////////////////////
  1838. void SetTaskTriggerFromDlg
  1839. (
  1840. HWND hwndDlg,
  1841. SSUIDLGINFO * pDlgInfo
  1842. )
  1843. {
  1844. BOOL bTranslated;
  1845. TASK_TRIGGER * pTT = &pDlgInfo->ttTaskTrigger;
  1846. ZeroMemory(pTT, SIZEOF(TASK_TRIGGER));
  1847. pTT->cbTriggerSize = SIZEOF(TASK_TRIGGER);
  1848. // Init start date to now.
  1849. SYSTEMTIME st;
  1850. GetLocalTime(&st);
  1851. pTT->wBeginYear = st.wYear;
  1852. pTT->wBeginMonth = st.wMonth;
  1853. pTT->wBeginDay = st.wDay;
  1854. // Vary start of update
  1855. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_MINIMIZENETUSE) == BST_CHECKED)
  1856. pTT->wRandomMinutesInterval = DEFAULT_RANDOM_MINUTES_INTERVAL;
  1857. else
  1858. pTT->wRandomMinutesInterval = 0;
  1859. // Initialize the 'Time' related settings.
  1860. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT) == BST_CHECKED)
  1861. {
  1862. // Update at N
  1863. SYSTEMTIME st = { 0 };
  1864. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_UPDATEAT_TIME), &st);
  1865. pTT->wStartHour = st.wHour;
  1866. pTT->wStartMinute = st.wMinute;
  1867. }
  1868. else
  1869. {
  1870. // Repeat every N hours
  1871. ASSERT(IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY) == BST_CHECKED)
  1872. // Between X and Y
  1873. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN) == BST_CHECKED)
  1874. {
  1875. // Between X
  1876. SYSTEMTIME st = { 0 };
  1877. DateTime_GetSystemtime( GetDlgItem( hwndDlg,
  1878. IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME),
  1879. &st);
  1880. pTT->wStartHour = st.wHour;
  1881. pTT->wStartMinute = st.wMinute;
  1882. WORD wStartMins = (st.wHour * 60) + st.wMinute;
  1883. DateTime_GetSystemtime( GetDlgItem( hwndDlg,
  1884. IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME),
  1885. &st);
  1886. WORD wEndMins = (st.wHour * 60) + st.wMinute;
  1887. // And Y
  1888. if (wStartMins > wEndMins)
  1889. pTT->MinutesDuration = (1440 - wStartMins) + wEndMins;
  1890. else
  1891. pTT->MinutesDuration = wEndMins - wStartMins;
  1892. }
  1893. else
  1894. {
  1895. // If we are not between a hour range, begin update at the start of the day.
  1896. pTT->wStartHour = 0; // 12:00am
  1897. pTT->wStartMinute = 0;
  1898. pTT->MinutesDuration = (24 * 60);
  1899. }
  1900. // Set the interval.
  1901. int iHours = GetDlgItemInt( hwndDlg,
  1902. IDC_CUSTOM_TIME_REPEATEVERY_EDIT,
  1903. &bTranslated,
  1904. FALSE);
  1905. ASSERT(bTranslated && (iHours > 0));
  1906. if (pDlgInfo->dwRepeatHrsAreMins)
  1907. pTT->MinutesInterval = iHours;
  1908. else
  1909. pTT->MinutesInterval = iHours * 60;
  1910. }
  1911. // Initialize the 'Days' related settings.
  1912. // Daily schedule
  1913. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_DAILY) == BST_CHECKED)
  1914. {
  1915. // Daily -- Every N days
  1916. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_DAILY_EVERYNDAYS) == BST_CHECKED)
  1917. {
  1918. pTT->TriggerType = TASK_TIME_TRIGGER_DAILY;
  1919. pTT->Type.Daily.DaysInterval = GetDlgItemInt( hwndDlg,
  1920. IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT,
  1921. &bTranslated,
  1922. FALSE);
  1923. }
  1924. else
  1925. {
  1926. // Daily -- Every Weekday
  1927. ASSERT(IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_DAILY_EVERYWEEKDAY));
  1928. pTT->TriggerType = TASK_TIME_TRIGGER_WEEKLY;
  1929. pTT->Type.Weekly.WeeksInterval = 1;
  1930. pTT->Type.Weekly.rgfDaysOfTheWeek = TASK_WEEKDAYS;
  1931. }
  1932. }
  1933. // Weekly schedule
  1934. else if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_WEEKLY) == BST_CHECKED)
  1935. {
  1936. pTT->TriggerType = TASK_TIME_TRIGGER_WEEKLY;
  1937. // Weekly -- Repeat every N days
  1938. pTT->Type.Weekly.WeeksInterval = GetDlgItemInt( hwndDlg,
  1939. IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT,
  1940. &bTranslated,
  1941. FALSE);
  1942. // Weekly -- Days of the week
  1943. pTT->Type.Weekly.rgfDaysOfTheWeek = GetDlgWeekDays(hwndDlg);
  1944. }
  1945. // Monthly schedule
  1946. else
  1947. {
  1948. ASSERT(IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_MONTHLY) == BST_CHECKED);
  1949. // Monthly -- Day X of every Y month(s)
  1950. if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH) == BST_CHECKED)
  1951. {
  1952. pTT->TriggerType = TASK_TIME_TRIGGER_MONTHLYDATE;
  1953. int iDate = GetDlgItemInt( hwndDlg,
  1954. IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT,
  1955. &bTranslated,
  1956. FALSE);
  1957. ASSERT(iDate > 0);
  1958. // Day X
  1959. pTT->Type.MonthlyDate.rgfDays = (1 << (iDate - 1));
  1960. // of every Y month(s)
  1961. pTT->Type.MonthlyDate.rgfMonths = GetDlgItemMonth(hwndDlg, IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT);
  1962. }
  1963. else
  1964. {
  1965. // Monthly -- The X Y of every Z month(s)
  1966. ASSERT(IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC) == BST_CHECKED);
  1967. pTT->TriggerType = TASK_TIME_TRIGGER_MONTHLYDOW;
  1968. // The X
  1969. int iWeek = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST1))+1;
  1970. ASSERT((iWeek >= TASK_FIRST_WEEK) && (iWeek <= TASK_LAST_WEEK));
  1971. pTT->Type.MonthlyDOW.wWhichWeek = iWeek;
  1972. // Y
  1973. int iDaysOfWeek = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_LIST2));
  1974. ASSERT((iDaysOfWeek >= 0) && (iDaysOfWeek < ARRAYSIZE(s_rgwDaysOfTheWeek)));
  1975. pTT->Type.MonthlyDOW.rgfDaysOfTheWeek = s_rgwDaysOfTheWeek[iDaysOfWeek];
  1976. // of every Z month(s)
  1977. pTT->Type.MonthlyDOW.rgfMonths = GetDlgItemMonth(hwndDlg, IDC_CUSTOM_MONTHLY_PERIODIC_EDIT);
  1978. }
  1979. }
  1980. }
  1981. /////////////////////////////////////////////////////////////////////////////
  1982. // SetTaskTriggerToDefaults
  1983. /////////////////////////////////////////////////////////////////////////////
  1984. void SetTaskTriggerToDefaults
  1985. (
  1986. TASK_TRIGGER * pTT
  1987. )
  1988. {
  1989. ASSERT(pTT != NULL);
  1990. // REVIEW: Make this a const static struct and assign instead of function?
  1991. ZeroMemory(pTT, SIZEOF(TASK_TRIGGER));
  1992. pTT->cbTriggerSize = SIZEOF(TASK_TRIGGER);
  1993. pTT->wStartHour = DEFAULT_UPDATETIME_HRS;
  1994. pTT->wStartMinute = DEFAULT_UPDATETIME_MINS;
  1995. pTT->TriggerType = TASK_TIME_TRIGGER_DAILY;
  1996. pTT->Type.Daily.DaysInterval = DEFAULT_DAILY_EVERYNDAYS;
  1997. }
  1998. /////////////////////////////////////////////////////////////////////////////
  1999. // OnDataChanged
  2000. /////////////////////////////////////////////////////////////////////////////
  2001. void OnDataChanged
  2002. (
  2003. HWND hwndDlg,
  2004. SSUIDLGINFO * pDlgInfo
  2005. )
  2006. {
  2007. // Ignore if we are setting up the dialog control values.
  2008. if (pDlgInfo->bInitializing)
  2009. return;
  2010. // Update the TASK_TRIGGER to new user settings.
  2011. SetTaskTriggerFromDlg(hwndDlg, pDlgInfo);
  2012. // Calc and display next update time.
  2013. SetDlgItemNextUpdate(hwndDlg, IDC_CUSTOM_NEXTUPDATE, pDlgInfo);
  2014. // Data changed
  2015. pDlgInfo->bDataChanged = TRUE;
  2016. }
  2017. /////////////////////////////////////////////////////////////////////////////
  2018. // ApplyDlgChanges
  2019. /////////////////////////////////////////////////////////////////////////////
  2020. HRESULT ApplyDlgChanges
  2021. (
  2022. HWND hwndDlg,
  2023. SSUIDLGINFO * pDlgInfo
  2024. )
  2025. {
  2026. HRESULT hrResult;
  2027. if (ValidateDlgFields(hwndDlg, pDlgInfo))
  2028. {
  2029. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST);
  2030. if (pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE)
  2031. {
  2032. if (SUCCEEDED(hrResult = CreateScheduleGroupFromDlg(hwndDlg, pDlgInfo)))
  2033. {
  2034. pDlgInfo->dwFlags |= SSUI_SCHEDULECREATED;
  2035. // Update the combobox with the new group, just
  2036. // in case we aren't closing the dialog.
  2037. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2038. GetDlgGroupName(hwndDlg, szGroupName, ARRAYSIZE(szGroupName));
  2039. EVAL(SUCCEEDED(SchedGroupComboBox_AddGroup( hwndCombo,
  2040. szGroupName,
  2041. pDlgInfo->pGroupCookie)));
  2042. }
  2043. else
  2044. {
  2045. // REVIEW: Error message! [jaym]
  2046. MessageBeep(MB_ICONEXCLAMATION);
  2047. }
  2048. }
  2049. else
  2050. {
  2051. ASSERT(pDlgInfo->dwFlags & SSUI_EDITSCHEDULE);
  2052. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2053. GetDlgGroupName(hwndDlg, szGroupName, ARRAYSIZE(szGroupName));
  2054. WCHAR wszGroupName[MAX_GROUPNAME_LEN];
  2055. MyStrToOleStrN(wszGroupName, MAX_GROUPNAME_LEN, szGroupName);
  2056. GROUPINFO gi;
  2057. gi.cbSize = SIZEOF(GROUPINFO);
  2058. gi.pwzGroupname = wszGroupName;
  2059. SetTaskTriggerFromDlg(hwndDlg, pDlgInfo);
  2060. #ifdef DEBUG
  2061. DumpTaskTrigger(&pDlgInfo->ttTaskTrigger);
  2062. #endif // DEBUG
  2063. if (SUCCEEDED(hrResult = ModifyScheduleGroup( pDlgInfo->pGroupCookie,
  2064. &pDlgInfo->ttTaskTrigger,
  2065. NULL,
  2066. &gi,
  2067. 0)))
  2068. {
  2069. pDlgInfo->dwFlags |= SSUI_SCHEDULECHANGED;
  2070. //xnotfmgr
  2071. // Reset combo list entry because name may have changed.
  2072. NOTIFICATIONCOOKIE cookie;
  2073. EVAL(SUCCEEDED(SchedGroupComboBox_GetCurGroup(hwndCombo, &cookie)));
  2074. EVAL(SUCCEEDED(SchedGroupComboBox_RemoveGroup(hwndCombo, pDlgInfo->pGroupCookie)));
  2075. EVAL(SUCCEEDED(SchedGroupComboBox_AddGroup(hwndCombo, szGroupName, pDlgInfo->pGroupCookie)));
  2076. EVAL(SUCCEEDED(SchedGroupComboBox_SetCurGroup(hwndCombo, &cookie)));
  2077. }
  2078. else
  2079. {
  2080. // REVIEW: Error message! [jaym]
  2081. MessageBeep(MB_ICONEXCLAMATION);
  2082. }
  2083. }
  2084. }
  2085. else
  2086. hrResult = E_FAIL;
  2087. return hrResult;
  2088. }
  2089. /////////////////////////////////////////////////////////////////////////////
  2090. // ValidateDlgFields
  2091. /////////////////////////////////////////////////////////////////////////////
  2092. BOOL ValidateDlgFields
  2093. (
  2094. HWND hwndDlg,
  2095. SSUIDLGINFO * pDlgInfo
  2096. )
  2097. {
  2098. BOOL bResult = FALSE; // Assume the worst.
  2099. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2100. GetDlgGroupName(hwndDlg, szGroupName, ARRAYSIZE(szGroupName));
  2101. for (;;)
  2102. {
  2103. int cchGroupNameLen = GetDlgGroupNameLength(hwndDlg);
  2104. // Check length of group name. Tell user if too long.
  2105. if (cchGroupNameLen >= MAX_GROUPNAME_LEN)
  2106. {
  2107. SGMessageBox( hwndDlg,
  2108. IDS_CUSTOM_ERROR_NAMETOOLONG,
  2109. MB_OK | MB_ICONEXCLAMATION);
  2110. break;
  2111. }
  2112. // Make sure we have a description
  2113. if (cchGroupNameLen <= 0)
  2114. {
  2115. SGMessageBox( hwndDlg,
  2116. IDS_CUSTOM_ERROR_NAMEREQUIRED,
  2117. MB_OK | MB_ICONEXCLAMATION);
  2118. break;
  2119. }
  2120. // Check to see if group name is already in use.
  2121. if (
  2122. (
  2123. pDlgInfo->bScheduleNameChanged
  2124. ||
  2125. (pDlgInfo->dwFlags & SSUI_CREATENEWSCHEDULE)
  2126. )
  2127. &&
  2128. ScheduleGroupExists(szGroupName)
  2129. )
  2130. {
  2131. SGMessageBox( hwndDlg,
  2132. IDS_CUSTOM_ERROR_NAMEEXISTS,
  2133. MB_OK | MB_ICONEXCLAMATION);
  2134. break;
  2135. }
  2136. // NOTE: Spin ranges are checked in RestrictDlgItemRange()
  2137. bResult = TRUE;
  2138. break;
  2139. }
  2140. if (!bResult)
  2141. {
  2142. // Set focus to the group name control.
  2143. if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT)))
  2144. SetFocus(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT));
  2145. else
  2146. SetFocus(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST));
  2147. }
  2148. return bResult;
  2149. }
  2150. /////////////////////////////////////////////////////////////////////////////
  2151. // GetDlgGroupName
  2152. /////////////////////////////////////////////////////////////////////////////
  2153. UINT GetDlgGroupName
  2154. (
  2155. HWND hwndDlg,
  2156. LPTSTR pszGroupName,
  2157. int cchGroupNameLen
  2158. )
  2159. {
  2160. UINT uResult;
  2161. if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT)))
  2162. {
  2163. uResult = GetDlgItemText( hwndDlg,
  2164. IDC_CUSTOM_GROUP_EDIT,
  2165. pszGroupName,
  2166. cchGroupNameLen);
  2167. }
  2168. else if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST)))
  2169. {
  2170. uResult = GetDlgItemText( hwndDlg,
  2171. IDC_CUSTOM_GROUP_LIST,
  2172. pszGroupName,
  2173. cchGroupNameLen);
  2174. }
  2175. else
  2176. uResult = 0;
  2177. return uResult;
  2178. }
  2179. /////////////////////////////////////////////////////////////////////////////
  2180. // GetDlgGroupNameLength
  2181. /////////////////////////////////////////////////////////////////////////////
  2182. int GetDlgGroupNameLength
  2183. (
  2184. HWND hwndDlg
  2185. )
  2186. {
  2187. HWND hwndCtl;
  2188. if (
  2189. IsWindowVisible(hwndCtl = GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_EDIT))
  2190. ||
  2191. IsWindowVisible(hwndCtl = GetDlgItem(hwndDlg, IDC_CUSTOM_GROUP_LIST))
  2192. )
  2193. {
  2194. return GetWindowTextLength(hwndCtl);
  2195. }
  2196. else
  2197. return 0;
  2198. }
  2199. /////////////////////////////////////////////////////////////////////////////
  2200. // CreateScheduleGroupFromDlg
  2201. /////////////////////////////////////////////////////////////////////////////
  2202. HRESULT CreateScheduleGroupFromDlg
  2203. (
  2204. HWND hwndDlg,
  2205. SSUIDLGINFO * pDlgInfo
  2206. )
  2207. {
  2208. HRESULT hrResult;
  2209. ASSERT(hwndDlg != NULL);
  2210. ASSERT(IsWindow(hwndDlg));
  2211. ASSERT(pDlgInfo != NULL);
  2212. for (;;)
  2213. {
  2214. *(pDlgInfo->pGroupCookie) = GUID_NULL;
  2215. // Get the Trigger info from the dialog control states.
  2216. SetTaskTriggerFromDlg(hwndDlg, pDlgInfo);
  2217. #ifdef DEBUG
  2218. DumpTaskTrigger(&pDlgInfo->ttTaskTrigger);
  2219. #endif // DEBUG
  2220. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2221. GetDlgGroupName(hwndDlg, szGroupName, ARRAYSIZE(szGroupName));
  2222. WCHAR wszGroupName[MAX_GROUPNAME_LEN];
  2223. MyStrToOleStrN(wszGroupName, MAX_GROUPNAME_LEN, szGroupName);
  2224. GROUPINFO gi;
  2225. gi.cbSize = SIZEOF(GROUPINFO);
  2226. gi.pwzGroupname = wszGroupName;
  2227. if (FAILED(hrResult = CreateScheduleGroup( &pDlgInfo->ttTaskTrigger,
  2228. NULL,
  2229. &gi,
  2230. 0,
  2231. pDlgInfo->pGroupCookie)))
  2232. {
  2233. TraceMsg(TF_ERROR, "CSGFD: Unable to CreateScheduleGroup");
  2234. break;
  2235. }
  2236. break;
  2237. }
  2238. return hrResult;
  2239. }
  2240. /////////////////////////////////////////////////////////////////////////////
  2241. // RestrictDlgItemRange
  2242. /////////////////////////////////////////////////////////////////////////////
  2243. void RestrictDlgItemRange
  2244. (
  2245. HWND hwndDlg,
  2246. int idCtl,
  2247. SSUIDLGINFO * pDlgInfo
  2248. )
  2249. {
  2250. // Special case repeat-every, which is based on the
  2251. // time values of other controls in the dialog.
  2252. if (
  2253. (idCtl == IDC_CUSTOM_TIME_REPEATEVERY_EDIT)
  2254. &&
  2255. (IsDlgButtonChecked(hwndDlg, IDC_CUSTOM_TIME_REPEATBETWEEN) == BST_CHECKED)
  2256. )
  2257. {
  2258. RestrictTimeRepeatEvery(hwndDlg);
  2259. }
  2260. else
  2261. {
  2262. int nMin;
  2263. int nMax;
  2264. int nDefault;
  2265. BOOL bTranslated;
  2266. // Get predefined range
  2267. switch (idCtl)
  2268. {
  2269. case IDC_CUSTOM_DAILY_EVERYNDAYS_EDIT:
  2270. {
  2271. nMin = DEFAULT_DAILY_EVERYNDAYS_MIN;
  2272. nMax = DEFAULT_DAILY_EVERYNDAYS_MAX;
  2273. nDefault = DEFAULT_DAILY_EVERYNDAYS;
  2274. break;
  2275. }
  2276. case IDC_CUSTOM_WEEKLY_REPEATWEEKS_EDIT:
  2277. {
  2278. nMin = DEFAULT_WEEKLY_REPEATWEEKS_MIN;
  2279. nMax = DEFAULT_WEEKLY_REPEATWEEKS_MAX;
  2280. nDefault = DEFAULT_WEEKLY_REPEATWEEKS;
  2281. break;
  2282. }
  2283. case IDC_CUSTOM_MONTHLY_DAYOFMONTH_DAY_EDIT:
  2284. {
  2285. SYSTEMTIME stLocal;
  2286. GetLocalTime(&stLocal);
  2287. nMin = DEFAULT_MONTHLY_DAY_MIN;
  2288. nMax = DEFAULT_MONTHLY_DAY_MAX;
  2289. nDefault = stLocal.wDay;
  2290. break;
  2291. }
  2292. case IDC_CUSTOM_MONTHLY_DAYOFMONTH_MONTH_EDIT:
  2293. {
  2294. nMin = DEFAULT_MONTHLY_MONTHS_MIN;
  2295. nMax = DEFAULT_MONTHLY_MONTHS_MAX;
  2296. nDefault = DEFAULT_MONTHLY_MONTHS;
  2297. break;
  2298. }
  2299. case IDC_CUSTOM_MONTHLY_PERIODIC_EDIT:
  2300. {
  2301. nMin = DEFAULT_MONTHLY_MONTHS_MIN;
  2302. nMax = DEFAULT_MONTHLY_MONTHS_MAX;
  2303. nDefault = DEFAULT_MONTHLY_MONTHS;
  2304. break;
  2305. }
  2306. case IDC_CUSTOM_TIME_REPEATEVERY_EDIT:
  2307. {
  2308. nMin = DEFAULT_REPEATUPDATE_HRS_MIN;
  2309. nMax = DEFAULT_REPEATUPDATE_HRS_MAX;
  2310. nDefault = DEFAULT_REPEATUPDATE_HRS;
  2311. break;
  2312. }
  2313. default:
  2314. {
  2315. ASSERT(FALSE);
  2316. break;
  2317. }
  2318. }
  2319. // Get current value
  2320. BOOL bChanged = FALSE;
  2321. int nCurrent = (int)GetDlgItemInt(hwndDlg, idCtl, &bTranslated, TRUE);
  2322. if (bTranslated)
  2323. {
  2324. int nRestricted = min(nMax, max(nMin, nCurrent));
  2325. if (nRestricted != nCurrent)
  2326. SetDlgItemInt(hwndDlg, idCtl, nRestricted, TRUE);
  2327. }
  2328. else
  2329. SetDlgItemInt(hwndDlg, idCtl, nDefault, TRUE);
  2330. }
  2331. }
  2332. /////////////////////////////////////////////////////////////////////////////
  2333. // RestrictTimeRepeatEvery
  2334. /////////////////////////////////////////////////////////////////////////////
  2335. void RestrictTimeRepeatEvery
  2336. (
  2337. HWND hwndDlg
  2338. )
  2339. {
  2340. SYSTEMTIME st = { 0 };
  2341. DateTime_GetSystemtime( GetDlgItem( hwndDlg,
  2342. IDC_CUSTOM_TIME_REPEATBETWEEN_START_TIME),
  2343. &st);
  2344. WORD wStartMins = (st.wHour * 60) + st.wMinute;
  2345. DateTime_GetSystemtime( GetDlgItem( hwndDlg,
  2346. IDC_CUSTOM_TIME_REPEATBETWEEN_END_TIME),
  2347. &st);
  2348. WORD wEndMins = (st.wHour * 60) + st.wMinute;
  2349. WORD nHours;
  2350. if (wStartMins > wEndMins)
  2351. nHours = ((1440 - wStartMins) + wEndMins) / 60;
  2352. else
  2353. nHours = (wEndMins - wStartMins) / 60;
  2354. if (nHours <= 0)
  2355. nHours = DEFAULT_REPEATUPDATE_HRS_MIN;
  2356. UpDown_SetRange(GetDlgItem(hwndDlg, IDC_CUSTOM_TIME_REPEATEVERY_SPIN),
  2357. DEFAULT_REPEATUPDATE_HRS_MIN, nHours);
  2358. BOOL bTranslated;
  2359. int nRepeatEvery = GetDlgItemInt( hwndDlg,
  2360. IDC_CUSTOM_TIME_REPEATEVERY_EDIT,
  2361. &bTranslated,
  2362. FALSE);
  2363. int nRestricted = min(nHours, max(1, nRepeatEvery));
  2364. if (nRestricted != nRepeatEvery)
  2365. {
  2366. SetDlgItemInt( hwndDlg,
  2367. IDC_CUSTOM_TIME_REPEATEVERY_EDIT,
  2368. nRestricted,
  2369. FALSE);
  2370. }
  2371. }
  2372. /////////////////////////////////////////////////////////////////////////////
  2373. // Helper functions
  2374. /////////////////////////////////////////////////////////////////////////////
  2375. /////////////////////////////////////////////////////////////////////////////
  2376. // GetSchedGroupTaskTrigger
  2377. /////////////////////////////////////////////////////////////////////////////
  2378. HRESULT GetSchedGroupTaskTrigger
  2379. (
  2380. PNOTIFICATIONCOOKIE pGroupCookie,
  2381. TASK_TRIGGER * pTT
  2382. )
  2383. {
  2384. //xnotfmgr
  2385. INotificationMgr * pNotificationMgr = NULL;
  2386. IScheduleGroup * pScheduleGroup = NULL;
  2387. HRESULT hrResult;
  2388. ASSERT(pGroupCookie != NULL);
  2389. ASSERT(pTT != NULL);
  2390. for (;;)
  2391. {
  2392. ZeroMemory(pTT, SIZEOF(TASK_TRIGGER));
  2393. pTT->cbTriggerSize = SIZEOF(TASK_TRIGGER);
  2394. if (FAILED(hrResult = GetNotificationMgr(&pNotificationMgr)))
  2395. {
  2396. TraceMsg(TF_ERROR, "GSGTaskTrigger: Unable to get NotificationMgr");
  2397. break;
  2398. }
  2399. if (FAILED(hrResult = pNotificationMgr->FindScheduleGroup( pGroupCookie,
  2400. &pScheduleGroup,
  2401. 0)))
  2402. {
  2403. TraceMsg(TF_ERROR, "GSGTaskTrigger: Unable to locate schedule group");
  2404. break;
  2405. }
  2406. if (FAILED(hrResult = pScheduleGroup->GetAttributes(pTT,
  2407. NULL,
  2408. NULL,
  2409. NULL,
  2410. NULL,
  2411. NULL)))
  2412. {
  2413. TraceMsg(TF_ERROR, "GSGTaskTrigger: Unable to get schedule group attributes");
  2414. break;
  2415. }
  2416. break;
  2417. }
  2418. SAFERELEASE(pScheduleGroup);
  2419. SAFERELEASE(pNotificationMgr);
  2420. return hrResult;
  2421. }
  2422. /////////////////////////////////////////////////////////////////////////////
  2423. // CreateScheduleGroup
  2424. /////////////////////////////////////////////////////////////////////////////
  2425. HRESULT CreateScheduleGroup
  2426. (
  2427. /* [in] */ PTASK_TRIGGER pTaskTrigger,
  2428. /* [in] */ PTASK_DATA pTaskData,
  2429. /* [in] */ PGROUPINFO pGroupInfo,
  2430. /* [in] */ GROUPMODE grfGroupMode,
  2431. /* [out] */ PNOTIFICATIONCOOKIE pGroupCookie
  2432. )
  2433. {
  2434. //xnotfmgr
  2435. INotificationMgr * pNotificationMgr = NULL;
  2436. IScheduleGroup * pScheduleGroup = NULL;
  2437. HRESULT hrResult;
  2438. for (;;)
  2439. {
  2440. if (pGroupCookie == NULL)
  2441. return E_INVALIDARG;
  2442. if (FAILED(hrResult = GetNotificationMgr(&pNotificationMgr)))
  2443. {
  2444. TraceMsg(TF_ERROR, "CSG: Unable to get NotificationMgr");
  2445. break;
  2446. }
  2447. if (FAILED(hrResult = pNotificationMgr->CreateScheduleGroup(0,
  2448. &pScheduleGroup,
  2449. pGroupCookie,
  2450. 0)))
  2451. {
  2452. TraceMsg(TF_ERROR, "CSG: Unable to CreateScheduleGroup");
  2453. break;
  2454. }
  2455. ASSERT(!pTaskData);
  2456. if (FAILED(hrResult = pScheduleGroup->SetAttributes(pTaskTrigger,
  2457. pTaskData,
  2458. pGroupCookie,
  2459. pGroupInfo,
  2460. grfGroupMode)))
  2461. {
  2462. TraceMsg(TF_ERROR, "CSG: Unable to SetAttributes");
  2463. break;
  2464. }
  2465. break;
  2466. }
  2467. SAFERELEASE(pScheduleGroup);
  2468. SAFERELEASE(pNotificationMgr);
  2469. return hrResult;
  2470. }
  2471. /////////////////////////////////////////////////////////////////////////////
  2472. // ModifyScheduleGroup
  2473. /////////////////////////////////////////////////////////////////////////////
  2474. HRESULT ModifyScheduleGroup
  2475. (
  2476. /* [in] */ PNOTIFICATIONCOOKIE pGroupCookie,
  2477. /* [in] */ PTASK_TRIGGER pTaskTrigger,
  2478. /* [in] */ PTASK_DATA pTaskData,
  2479. /* [in] */ PGROUPINFO pGroupInfo,
  2480. /* [in] */ GROUPMODE grfGroupMode
  2481. )
  2482. {
  2483. //xnotfmgr
  2484. INotificationMgr * pNotificationMgr = NULL;
  2485. IScheduleGroup * pScheduleGroup = NULL;
  2486. HRESULT hrResult;
  2487. // This might take a while.
  2488. WAITCURSOR Hourglass;
  2489. for (;;)
  2490. {
  2491. if (
  2492. (pGroupCookie == NULL)
  2493. ||
  2494. (*pGroupCookie == GUID_NULL)
  2495. )
  2496. {
  2497. return E_INVALIDARG;
  2498. }
  2499. if (FAILED(hrResult = GetNotificationMgr(&pNotificationMgr)))
  2500. {
  2501. TraceMsg(TF_ERROR, "MSG: Unable to get NotificationMgr");
  2502. break;
  2503. }
  2504. if (FAILED(hrResult = pNotificationMgr->FindScheduleGroup( pGroupCookie,
  2505. &pScheduleGroup,
  2506. 0)))
  2507. {
  2508. TraceMsg(TF_ERROR, "MSG: Unable to locate schedule group");
  2509. break;
  2510. }
  2511. ASSERT(!pTaskData);
  2512. if (FAILED(hrResult = pScheduleGroup->SetAttributes(pTaskTrigger,
  2513. pTaskData,
  2514. pGroupCookie,
  2515. pGroupInfo,
  2516. grfGroupMode)))
  2517. {
  2518. TraceMsg(TF_ERROR, "MSG: Unable to SetAttributes");
  2519. break;
  2520. }
  2521. {
  2522. LPENUMNOTIFICATION pEnum = NULL;
  2523. NOTIFICATIONITEM item = {0};
  2524. OOEBuf ooeBuf;
  2525. HRESULT hr;
  2526. if (FAILED(hr = pScheduleGroup->GetEnumNotification(0, &pEnum)))
  2527. {
  2528. TraceMsg(TF_ERROR, "MSG: Unable to GetEnumNotification");
  2529. break;
  2530. }
  2531. memset(&ooeBuf, 0, sizeof(ooeBuf));
  2532. item.cbSize = sizeof(NOTIFICATIONITEM);
  2533. ULONG cItems = 0;
  2534. DWORD dwBufSize = 0;
  2535. hr = pEnum->Next(1, &item, &cItems);
  2536. while (SUCCEEDED(hr) && cItems) {
  2537. ASSERT(item.pNotification);
  2538. hr = LoadOOEntryInfo(&ooeBuf, &item, &dwBufSize);
  2539. SAFERELEASE(item.pNotification);
  2540. if (hr == S_OK) {
  2541. LPMYPIDL pooi = COfflineFolderEnum::NewPidl(dwBufSize);
  2542. if (pooi) {
  2543. CopyToMyPooe(&ooeBuf, &(pooi->ooe));
  2544. _GenerateEvent( SHCNE_UPDATEITEM,
  2545. (LPITEMIDLIST)pooi,
  2546. NULL);
  2547. COfflineFolderEnum::FreePidl(pooi);
  2548. } else {
  2549. hr = E_OUTOFMEMORY; // Ignore it?
  2550. }
  2551. }
  2552. ZeroMemory(&ooeBuf, sizeof(ooeBuf));
  2553. item.cbSize = sizeof(NOTIFICATIONITEM);
  2554. cItems = 0;
  2555. dwBufSize = 0;
  2556. hr = pEnum->Next(1, &item, &cItems);
  2557. }
  2558. SAFERELEASE(item.pNotification);
  2559. SAFERELEASE(pEnum);
  2560. }
  2561. break;
  2562. }
  2563. SAFERELEASE(pScheduleGroup);
  2564. SAFERELEASE(pNotificationMgr);
  2565. return hrResult;
  2566. }
  2567. /////////////////////////////////////////////////////////////////////////////
  2568. // DeleteScheduleGroup
  2569. /////////////////////////////////////////////////////////////////////////////
  2570. HRESULT DeleteScheduleGroup
  2571. (
  2572. /* [in] */ PNOTIFICATIONCOOKIE pGroupCookie
  2573. )
  2574. {
  2575. //xnotfmgr
  2576. INotificationMgr * pNotificationMgr = NULL;
  2577. HRESULT hrResult;
  2578. for (;;)
  2579. {
  2580. if (
  2581. (pGroupCookie == NULL)
  2582. ||
  2583. (*pGroupCookie == GUID_NULL)
  2584. )
  2585. {
  2586. return E_INVALIDARG;
  2587. }
  2588. if (FAILED(hrResult = GetNotificationMgr(&pNotificationMgr)))
  2589. {
  2590. TraceMsg(TF_ERROR, "DSG: Unable to get NotificationMgr");
  2591. break;
  2592. }
  2593. if (FAILED(hrResult = pNotificationMgr->RevokeScheduleGroup(pGroupCookie,
  2594. NULL,
  2595. 0)))
  2596. {
  2597. TraceMsg(TF_ERROR, "DSG: RevokeScheduleGroup FAILED");
  2598. break;
  2599. }
  2600. break;
  2601. }
  2602. SAFERELEASE(pNotificationMgr);
  2603. return hrResult;
  2604. }
  2605. /////////////////////////////////////////////////////////////////////////////
  2606. // ScheduleGroupExists
  2607. /////////////////////////////////////////////////////////////////////////////
  2608. BOOL ScheduleGroupExists
  2609. (
  2610. LPCTSTR lpszGroupName
  2611. )
  2612. {
  2613. //xnotfmgr
  2614. INotificationMgr * pNotificationMgr = NULL;
  2615. IEnumScheduleGroup * pEnumSchedGroup = NULL;
  2616. BOOL bResult = FALSE;
  2617. for (;;)
  2618. {
  2619. if (FAILED(GetNotificationMgr(&pNotificationMgr)))
  2620. {
  2621. TraceMsg(TF_ERROR, "SGE: Unable to get NotificationMgr");
  2622. break;
  2623. }
  2624. if (FAILED(pNotificationMgr->GetEnumScheduleGroup(0, &pEnumSchedGroup)))
  2625. {
  2626. TraceMsg(TF_ERROR, "SGE: Unable to GetEnumScheduleGroup");
  2627. break;
  2628. }
  2629. // Iterate through all the schedule groups
  2630. ULONG celtFetched;
  2631. IScheduleGroup * pScheduleGroup = NULL;
  2632. while (
  2633. SUCCEEDED(pEnumSchedGroup->Next(1,
  2634. &pScheduleGroup,
  2635. &celtFetched))
  2636. &&
  2637. (celtFetched != 0)
  2638. )
  2639. {
  2640. GROUPINFO info = { 0 };
  2641. ASSERT(pScheduleGroup != NULL);
  2642. // Get the schedule group attributes.
  2643. if (
  2644. SUCCEEDED(pScheduleGroup->GetAttributes(NULL,
  2645. NULL,
  2646. NULL,
  2647. &info,
  2648. NULL,
  2649. NULL))
  2650. )
  2651. {
  2652. ASSERT(info.cbSize == SIZEOF(GROUPINFO));
  2653. ASSERT(info.pwzGroupname != NULL);
  2654. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2655. MyOleStrToStrN(szGroupName, MAX_GROUPNAME_LEN, info.pwzGroupname);
  2656. SAFEDELETE(info.pwzGroupname);
  2657. // See if this is the schedule group name we are looking for.
  2658. if (StrCmpI(lpszGroupName, szGroupName) == 0)
  2659. {
  2660. bResult = TRUE;
  2661. break;
  2662. }
  2663. }
  2664. else
  2665. TraceMsg(TF_ERROR, "SGE: Unable to GetAttributes");
  2666. SAFERELEASE(pScheduleGroup);
  2667. }
  2668. break;
  2669. }
  2670. SAFERELEASE(pEnumSchedGroup);
  2671. SAFERELEASE(pNotificationMgr);
  2672. return bResult;
  2673. }
  2674. /////////////////////////////////////////////////////////////////////////////
  2675. // SetDlgItemMonth
  2676. /////////////////////////////////////////////////////////////////////////////
  2677. BOOL SetDlgItemMonth
  2678. (
  2679. HWND hwndDlg,
  2680. int idCtl,
  2681. WORD rgfMonths
  2682. )
  2683. {
  2684. return SetDlgItemInt( hwndDlg,
  2685. idCtl,
  2686. MonthCountFromMonthsFlags(rgfMonths),
  2687. FALSE);
  2688. }
  2689. /////////////////////////////////////////////////////////////////////////////
  2690. // MonthCountFromMonthsFlags
  2691. /////////////////////////////////////////////////////////////////////////////
  2692. int MonthCountFromMonthsFlags
  2693. (
  2694. WORD rgfMonths
  2695. )
  2696. {
  2697. for (int iMonths = 0; iMonths < ARRAYSIZE(c_rgwMonthMaps); iMonths++)
  2698. {
  2699. if (c_rgwMonthMaps[iMonths] == rgfMonths)
  2700. break;
  2701. }
  2702. // If we didn't find it, assume every month
  2703. if (iMonths == ARRAYSIZE(c_rgwMonthMaps))
  2704. iMonths = 0;
  2705. return iMonths+1;
  2706. }
  2707. /////////////////////////////////////////////////////////////////////////////
  2708. // DayIndexFromDaysOfTheWeekFlags
  2709. /////////////////////////////////////////////////////////////////////////////
  2710. int DayIndexFromDaysOfTheWeekFlags
  2711. (
  2712. WORD rgfDaysOfTheWeek
  2713. )
  2714. {
  2715. int idxDay;
  2716. for (idxDay = 0; idxDay < ARRAYSIZE(s_rgwDaysOfTheWeek); idxDay++)
  2717. {
  2718. if (s_rgwDaysOfTheWeek[idxDay] == rgfDaysOfTheWeek)
  2719. break;
  2720. }
  2721. if (idxDay == ARRAYSIZE(s_rgwDaysOfTheWeek))
  2722. idxDay = 0;
  2723. return idxDay;
  2724. }
  2725. /////////////////////////////////////////////////////////////////////////////
  2726. // GetDlgItemMonth
  2727. /////////////////////////////////////////////////////////////////////////////
  2728. WORD GetDlgItemMonth
  2729. (
  2730. HWND hwndDlg,
  2731. int idCtl
  2732. )
  2733. {
  2734. BOOL bTranslated;
  2735. int iVal = GetDlgItemInt( hwndDlg,
  2736. idCtl,
  2737. &bTranslated,
  2738. FALSE);
  2739. if (
  2740. bTranslated
  2741. &&
  2742. ((iVal > 0) && (iVal <= ARRAYSIZE(c_rgwMonthMaps)))
  2743. )
  2744. {
  2745. return c_rgwMonthMaps[iVal-1];
  2746. }
  2747. return 0;
  2748. }
  2749. /////////////////////////////////////////////////////////////////////////////
  2750. // SetDlgItemNextUpdate
  2751. /////////////////////////////////////////////////////////////////////////////
  2752. void SetDlgItemNextUpdate
  2753. (
  2754. HWND hwndDlg,
  2755. int idCtl,
  2756. SSUIDLGINFO * pDlgInfo
  2757. )
  2758. {
  2759. //xnotfmgr
  2760. WORD cDate = 1;
  2761. FILETIME dateNextUpdate;
  2762. TCHAR szNextUpdate[128];
  2763. SYSTEMTIME stBegin;
  2764. GetLocalTime(&stBegin);
  2765. if (
  2766. (pDlgInfo->pfnGetRunTimes != NULL)
  2767. &&
  2768. SUCCEEDED(pDlgInfo->pfnGetRunTimes( pDlgInfo->ttTaskTrigger,
  2769. NULL,
  2770. &stBegin,
  2771. NULL,
  2772. &cDate,
  2773. &dateNextUpdate))
  2774. &&
  2775. (cDate != 0)
  2776. )
  2777. {
  2778. FileTimeToSystemTime(&dateNextUpdate, &stBegin);
  2779. }
  2780. else
  2781. GetLocalTime(&stBegin);
  2782. LPTSTR pszNextUpdate = szNextUpdate;
  2783. GetDateFormat( LOCALE_USER_DEFAULT,
  2784. DATE_LONGDATE,
  2785. &stBegin,
  2786. NULL,
  2787. pszNextUpdate,
  2788. ARRAYSIZE(szNextUpdate) / 2);
  2789. pszNextUpdate += lstrlen(pszNextUpdate); *pszNextUpdate++ = TEXT(' ');
  2790. GetTimeFormat( LOCALE_USER_DEFAULT,
  2791. TIME_NOSECONDS,
  2792. &stBegin,
  2793. NULL,
  2794. pszNextUpdate,
  2795. ARRAYSIZE(szNextUpdate) / 2);
  2796. SetDlgItemText(hwndDlg, idCtl, szNextUpdate);
  2797. }
  2798. /////////////////////////////////////////////////////////////////////////////
  2799. // IncTime
  2800. /////////////////////////////////////////////////////////////////////////////
  2801. DWORD IncTime
  2802. (
  2803. DWORD dwTime,
  2804. int iIncHours,
  2805. int iIncMinutes
  2806. )
  2807. {
  2808. int iMins = (LOWORD(dwTime) * 60) + HIWORD(dwTime);
  2809. int iIncMins = (iIncHours * 60) + iIncMinutes;
  2810. int iDeltaMins = iMins + iIncMins;
  2811. if (iDeltaMins > ((24 * 60) - 1))
  2812. iDeltaMins = iDeltaMins - (24 * 60);
  2813. else if (iDeltaMins < 0)
  2814. iDeltaMins = ((24 * 60) - 1);
  2815. return MAKELONG((iDeltaMins / 60), (iDeltaMins % 60));
  2816. }
  2817. /////////////////////////////////////////////////////////////////////////////
  2818. // DayFromDaysFlags
  2819. /////////////////////////////////////////////////////////////////////////////
  2820. int DayFromDaysFlags
  2821. (
  2822. DWORD rgfDays
  2823. )
  2824. {
  2825. DWORD dwMask = 1;
  2826. int iDay = 1;
  2827. while (dwMask)
  2828. {
  2829. if (rgfDays & dwMask)
  2830. break;
  2831. dwMask <<= 1;
  2832. iDay++;
  2833. }
  2834. if (iDay > 31)
  2835. iDay = 1;
  2836. return iDay;
  2837. }
  2838. /////////////////////////////////////////////////////////////////////////////
  2839. // Schedule group combo box helper functions
  2840. /////////////////////////////////////////////////////////////////////////////
  2841. /////////////////////////////////////////////////////////////////////////////
  2842. // SchedGroupComboBox_Fill
  2843. /////////////////////////////////////////////////////////////////////////////
  2844. HRESULT SchedGroupComboBox_Fill
  2845. (
  2846. HWND hwndCombo
  2847. )
  2848. {
  2849. //xnotfmgr
  2850. INotificationMgr * pNotificationMgr = NULL;
  2851. IEnumScheduleGroup * pEnumSchedGroup = NULL;
  2852. HRESULT hrResult;
  2853. ASSERT(hwndCombo != NULL);
  2854. ASSERT(IsWindow(hwndCombo));
  2855. for (;;)
  2856. {
  2857. SchedGroupComboBox_Clear(hwndCombo);
  2858. if (FAILED(hrResult = GetNotificationMgr(&pNotificationMgr)))
  2859. {
  2860. TraceMsg(TF_ERROR, "FCBSG: Unable to get NotificationMgr");
  2861. break;
  2862. }
  2863. if (FAILED(hrResult = pNotificationMgr->GetEnumScheduleGroup(0, &pEnumSchedGroup)))
  2864. {
  2865. TraceMsg(TF_ERROR, "FCBSG: Unable to GetEnumScheduleGroup");
  2866. break;
  2867. }
  2868. // Iterate through all the schedule gropus
  2869. ULONG celtFetched;
  2870. IScheduleGroup * pScheduleGroup = NULL;
  2871. while (
  2872. SUCCEEDED(hrResult = pEnumSchedGroup->Next( 1,
  2873. &pScheduleGroup,
  2874. &celtFetched))
  2875. &&
  2876. (celtFetched != 0)
  2877. )
  2878. {
  2879. GROUPINFO info = { 0 };
  2880. NOTIFICATIONCOOKIE cookie = { 0 };
  2881. ASSERT(pScheduleGroup != NULL);
  2882. // Get the schedule group attributes.
  2883. if (
  2884. SUCCEEDED(pScheduleGroup->GetAttributes(NULL,
  2885. NULL,
  2886. &cookie,
  2887. &info,
  2888. NULL,
  2889. NULL))
  2890. &&
  2891. (cookie != NOTFCOOKIE_SCHEDULE_GROUP_MANUAL)
  2892. )
  2893. {
  2894. ASSERT(info.cbSize == SIZEOF(GROUPINFO));
  2895. ASSERT(info.pwzGroupname != NULL);
  2896. TCHAR szGroupName[MAX_GROUPNAME_LEN];
  2897. MyOleStrToStrN(szGroupName, MAX_GROUPNAME_LEN, info.pwzGroupname);
  2898. SAFEDELETE(info.pwzGroupname);
  2899. EVAL(SUCCEEDED(SchedGroupComboBox_AddGroup( hwndCombo,
  2900. szGroupName,
  2901. &cookie)));
  2902. }
  2903. else
  2904. TraceMsg(TF_ERROR, "FCBSG: Unable to GetAttributes");
  2905. SAFERELEASE(pScheduleGroup);
  2906. }
  2907. break;
  2908. }
  2909. SAFERELEASE(pEnumSchedGroup);
  2910. SAFERELEASE(pNotificationMgr);
  2911. return hrResult;
  2912. }
  2913. /////////////////////////////////////////////////////////////////////////////
  2914. // SchedGroupComboBox_Clear
  2915. /////////////////////////////////////////////////////////////////////////////
  2916. HRESULT SchedGroupComboBox_Clear
  2917. (
  2918. HWND hwndCombo
  2919. )
  2920. {
  2921. //xnotfmgr
  2922. ASSERT(hwndCombo != NULL);
  2923. ASSERT(IsWindow(hwndCombo));
  2924. for (int i = 0; i < ComboBox_GetCount(hwndCombo); i++)
  2925. {
  2926. PNOTIFICATIONCOOKIE pCookie = (PNOTIFICATIONCOOKIE)ComboBox_GetItemData(hwndCombo, i);
  2927. if ((pCookie != NULL) && ((DWORD)pCookie != CB_ERR))
  2928. MemFree(pCookie);
  2929. }
  2930. ComboBox_ResetContent(hwndCombo);
  2931. return S_OK;
  2932. }
  2933. /////////////////////////////////////////////////////////////////////////////
  2934. // SchedGroupComboBox_AddGroup
  2935. /////////////////////////////////////////////////////////////////////////////
  2936. HRESULT SchedGroupComboBox_AddGroup
  2937. (
  2938. HWND hwndCombo,
  2939. LPCTSTR pszGroupName,
  2940. PNOTIFICATIONCOOKIE pGroupCookie
  2941. )
  2942. {
  2943. //xnotfmgr
  2944. ASSERT(hwndCombo != NULL);
  2945. ASSERT(IsWindow(hwndCombo));
  2946. ASSERT(pszGroupName != NULL);
  2947. ASSERT(pGroupCookie != NULL);
  2948. // Add the schedule group name to the combobox.
  2949. int iIndex = ComboBox_AddString(hwndCombo, pszGroupName);
  2950. if ((iIndex != CB_ERR) && (iIndex != CB_ERRSPACE))
  2951. {
  2952. // Attach the schedule group cookie to the item data.
  2953. PNOTIFICATIONCOOKIE pCookie = (PNOTIFICATIONCOOKIE)MemAlloc(LPTR,
  2954. SIZEOF(NOTIFICATIONCOOKIE));
  2955. if (pCookie == NULL)
  2956. return E_OUTOFMEMORY;
  2957. *pCookie = *pGroupCookie;
  2958. ComboBox_SetItemData(hwndCombo, iIndex, (DWORD)pCookie);
  2959. return S_OK;
  2960. }
  2961. else
  2962. ASSERT(FALSE);
  2963. return E_FAIL;
  2964. }
  2965. /////////////////////////////////////////////////////////////////////////////
  2966. // SchedGroupComboBox_RemoveGroup
  2967. /////////////////////////////////////////////////////////////////////////////
  2968. HRESULT SchedGroupComboBox_RemoveGroup
  2969. (
  2970. HWND hwndCombo,
  2971. PNOTIFICATIONCOOKIE pGroupCookie
  2972. )
  2973. {
  2974. //xnotfmgr
  2975. ASSERT(hwndCombo != NULL);
  2976. ASSERT(IsWindow(hwndCombo));
  2977. ASSERT(pGroupCookie != NULL);
  2978. ASSERT(*pGroupCookie != GUID_NULL);
  2979. for (int i = 0 ; i < ComboBox_GetCount(hwndCombo); i++)
  2980. {
  2981. PNOTIFICATIONCOOKIE pCookie = (PNOTIFICATIONCOOKIE)ComboBox_GetItemData(hwndCombo, i);
  2982. ASSERT(pCookie != NULL);
  2983. if (*pCookie == *pGroupCookie)
  2984. {
  2985. MemFree(pCookie);
  2986. EVAL(ComboBox_DeleteString(hwndCombo, i));
  2987. return S_OK;
  2988. }
  2989. }
  2990. ASSERT(FALSE);
  2991. return E_FAIL;
  2992. }
  2993. /////////////////////////////////////////////////////////////////////////////
  2994. // SchedGroupComboBox_SetCurGroup
  2995. /////////////////////////////////////////////////////////////////////////////
  2996. HRESULT SchedGroupComboBox_SetCurGroup
  2997. (
  2998. HWND hwndCombo,
  2999. PNOTIFICATIONCOOKIE pGroupCookie
  3000. )
  3001. {
  3002. //xnotfmgr
  3003. ASSERT(hwndCombo != NULL);
  3004. ASSERT(IsWindow(hwndCombo));
  3005. if (pGroupCookie == NULL || *pGroupCookie == GUID_NULL)
  3006. return E_INVALIDARG;
  3007. for (int i = 0 ; i < ComboBox_GetCount(hwndCombo); i++)
  3008. {
  3009. PNOTIFICATIONCOOKIE pData = (PNOTIFICATIONCOOKIE)ComboBox_GetItemData(hwndCombo, i);
  3010. if (pData && *pData == *pGroupCookie)
  3011. {
  3012. EVAL(ComboBox_SetCurSel(hwndCombo, i) != -1);
  3013. return S_OK;
  3014. }
  3015. }
  3016. ASSERT(FALSE);
  3017. return E_FAIL;
  3018. }
  3019. /////////////////////////////////////////////////////////////////////////////
  3020. // SchedGroupComboBox_GetCurGroup
  3021. /////////////////////////////////////////////////////////////////////////////
  3022. HRESULT SchedGroupComboBox_GetCurGroup
  3023. (
  3024. HWND hwndCombo,
  3025. PNOTIFICATIONCOOKIE pGroupCookie
  3026. )
  3027. {
  3028. //xnotfmgr
  3029. ASSERT(hwndCombo != NULL);
  3030. ASSERT(IsWindow(hwndCombo));
  3031. ASSERT(pGroupCookie != NULL);
  3032. int iIndex = ComboBox_GetCurSel(hwndCombo);
  3033. if (iIndex != CB_ERR)
  3034. {
  3035. PNOTIFICATIONCOOKIE pCookie = (PNOTIFICATIONCOOKIE)ComboBox_GetItemData(hwndCombo, iIndex);
  3036. if (pCookie == NULL)
  3037. return E_INVALIDARG;
  3038. *pGroupCookie = *pCookie;
  3039. return S_OK;
  3040. }
  3041. ASSERT(FALSE);
  3042. return E_FAIL;
  3043. }
  3044. ////////////////////////////////////////////////////////////////////////////////
  3045. ////////////////////////////////////////////////////////////////////////////////
  3046. //
  3047. // wrappers for schedui combobox functions, to fill list and get current selection,
  3048. // that are aware of a NULL itemdata field representing the Publisher's Recommended
  3049. // Schedule entry (NULL itemdata means no groupCookie means use task trigger).
  3050. //
  3051. ////////////////////////////////////////////////////////////////////////////////
  3052. HRESULT FillScheduleList (HWND hwndCombo, POOEBuf pBuf)
  3053. {
  3054. //first, fill with schedule groups
  3055. HRESULT hr = SchedGroupComboBox_Fill (hwndCombo);
  3056. //then, if channel, add "publisher schedule" to list
  3057. if (pBuf->bChannel)
  3058. {
  3059. TCHAR tcBuf[128];
  3060. MLLoadString(IDS_SCHEDULE_PUBLISHER, tcBuf, ARRAYSIZE(tcBuf));
  3061. ComboBox_AddString (hwndCombo, tcBuf);
  3062. //leave itemdata (cookie ptr) NULL
  3063. }
  3064. return hr;
  3065. }
  3066. HRESULT SetScheduleGroup (HWND hwndCombo, CLSID* pGroupCookie, POOEBuf pBuf)
  3067. {
  3068. //xnotfmgr
  3069. HRESULT hr;
  3070. if (pBuf->bChannel && (pBuf->fChannelFlags & CHANNEL_AGENT_DYNAMIC_SCHEDULE))
  3071. hr = E_FAIL; //force to Publisher's Schedule
  3072. else
  3073. hr = SchedGroupComboBox_SetCurGroup (hwndCombo, pGroupCookie);
  3074. if (FAILED (hr))
  3075. {
  3076. if (pBuf->bChannel)
  3077. {
  3078. //we are a channel; look for Publisher's Schedule (null cookie ptr)
  3079. for (int i = 0; i < ComboBox_GetCount (hwndCombo); i++)
  3080. {
  3081. if (!ComboBox_GetItemData(hwndCombo, i))
  3082. {
  3083. EVAL(ComboBox_SetCurSel(hwndCombo, i) != -1);
  3084. return S_OK;
  3085. }
  3086. }
  3087. hr = E_FAIL;
  3088. }
  3089. }
  3090. return hr;
  3091. }