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.

490 lines
12 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: monthly.cxx
  7. //
  8. // Contents: Task wizard monthly trigger property page implementation.
  9. //
  10. // Classes: CMonthlyPage
  11. //
  12. // History: 4-28-1997 DavidMun Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "..\pch\headers.hxx"
  16. #pragma hdrstop
  17. #include "myheaders.hxx"
  18. //
  19. // Constants
  20. //
  21. // NMONTHDAYS_MIN - minimum value for monthly_day_ud spin control
  22. // NMONTHDAYS_MAX - maximun value for monthly_day_ud spin control
  23. // MONTHS_WITHOUT_DAY_31 - used to ensure trigger settings will allow task
  24. // to run
  25. //
  26. #define NMONTHDAYS_MIN 1
  27. #define NMONTHDAYS_MAX 31
  28. #define MONTHS_WITHOUT_DAY_31 (TASK_FEBRUARY | \
  29. TASK_APRIL | \
  30. TASK_JUNE | \
  31. TASK_SEPTEMBER | \
  32. TASK_NOVEMBER)
  33. //+--------------------------------------------------------------------------
  34. //
  35. // Member: CMonthlyPage::CMonthlyPage
  36. //
  37. // Synopsis: ctor
  38. //
  39. // Arguments: [ptszFolderPath] - full path to tasks folder with dummy
  40. // filename appended
  41. // [phPSP] - filled with prop page handle
  42. //
  43. // History: 4-28-1997 DavidMun Created
  44. //
  45. //---------------------------------------------------------------------------
  46. CMonthlyPage::CMonthlyPage(
  47. CTaskWizard *pParent,
  48. LPTSTR ptszFolderPath,
  49. HPROPSHEETPAGE *phPSP):
  50. CTriggerPage(IDD_MONTHLY,
  51. IDS_MONTHLY_HDR2,
  52. ptszFolderPath,
  53. phPSP)
  54. {
  55. TRACE_CONSTRUCTOR(CMonthlyPage);
  56. _idSelectedDayType = 0;
  57. }
  58. //+--------------------------------------------------------------------------
  59. //
  60. // Member: CMonthlyPage::~CMonthlyPage
  61. //
  62. // Synopsis: dtor
  63. //
  64. // History: 4-28-1997 DavidMun Created
  65. //
  66. //---------------------------------------------------------------------------
  67. CMonthlyPage::~CMonthlyPage()
  68. {
  69. TRACE_DESTRUCTOR(CMonthlyPage);
  70. }
  71. //===========================================================================
  72. //
  73. // CPropPage overrides
  74. //
  75. //===========================================================================
  76. //+--------------------------------------------------------------------------
  77. //
  78. // Member: CMonthlyPage::_OnCommand
  79. //
  80. // Synopsis: Handle user input
  81. //
  82. // Arguments: [id] - resource id of control affected
  83. // [hwndCtl] - window handle of control affected
  84. // [codeNotify] - indicates what happened to control
  85. //
  86. // Returns: 0 (handled), 1 (not handled)
  87. //
  88. // History: 5-20-1997 DavidMun Created
  89. //
  90. //---------------------------------------------------------------------------
  91. LRESULT
  92. CMonthlyPage::_OnCommand(
  93. INT id,
  94. HWND hwndCtl,
  95. UINT codeNotify)
  96. {
  97. LRESULT lr = 0;
  98. switch (codeNotify)
  99. {
  100. case BN_CLICKED:
  101. switch (id)
  102. {
  103. case monthly_day_rb:
  104. case monthly_combo_rb:
  105. _idSelectedDayType = (WORD)id;
  106. _EnableDayCombos(id == monthly_combo_rb);
  107. EnableWindow(_hCtrl(monthly_day_edit), id == monthly_day_rb);
  108. EnableWindow(_hCtrl(monthly_day_ud), id == monthly_day_rb);
  109. break;
  110. }
  111. _UpdateWizButtons();
  112. break;
  113. case EN_UPDATE:
  114. {
  115. //
  116. // If the user just pasted non-numeric text or an illegal numeric
  117. // value, overwrite it and complain.
  118. //
  119. INT iNewPos = GetDlgItemInt(Hwnd(), monthly_day_edit, NULL, FALSE);
  120. if (iNewPos < NMONTHDAYS_MIN || iNewPos > NMONTHDAYS_MAX)
  121. {
  122. HWND hUD = _hCtrl(monthly_day_ud);
  123. UpDown_SetPos(hUD, UpDown_GetPos(hUD));
  124. MessageBeep(MB_ICONASTERISK);
  125. }
  126. }
  127. default:
  128. lr = 1;
  129. break;
  130. }
  131. return lr;
  132. }
  133. //+--------------------------------------------------------------------------
  134. //
  135. // Member: CMonthlyPage::_OnInitDialog
  136. //
  137. // Synopsis: Perform initialization that should only occur once.
  138. //
  139. // Arguments: [lParam] - LPPROPSHEETPAGE used to create this page
  140. //
  141. // Returns: TRUE (let windows set focus)
  142. //
  143. // History: 5-20-1997 DavidMun Created
  144. //
  145. //---------------------------------------------------------------------------
  146. LRESULT
  147. CMonthlyPage::_OnInitDialog(
  148. LPARAM lParam)
  149. {
  150. TRACE_METHOD(CMonthlyPage, _OnInitDialog);
  151. TCHAR tszBuff[SCH_BIGBUF_LEN];
  152. ULONG i;
  153. HWND hCombo = _hCtrl(monthly_ordinality_combo);
  154. _UpdateTimeFormat();
  155. for (i = 0; i < ARRAYLEN(g_aWeekData); i++)
  156. {
  157. LoadStr(g_aWeekData[i].ids, tszBuff, SCH_BIGBUF_LEN);
  158. ComboBox_AddString(hCombo, tszBuff);
  159. }
  160. ComboBox_SetCurSel(hCombo, 0);
  161. hCombo = _hCtrl(monthly_day_combo);
  162. for (i = 0; i < ARRAYLEN(g_aDayData); i++)
  163. {
  164. LoadStr(g_aDayData[i].ids, tszBuff, SCH_BIGBUF_LEN);
  165. ComboBox_AddString(hCombo, tszBuff);
  166. }
  167. ComboBox_SetCurSel(hCombo, 0);
  168. _EnableDayCombos(FALSE);
  169. UpDown_SetRange(_hCtrl(monthly_day_ud), NMONTHDAYS_MIN, NMONTHDAYS_MAX);
  170. UpDown_SetPos(_hCtrl(monthly_day_ud), NMONTHDAYS_MIN);
  171. Edit_LimitText(_hCtrl(monthly_day_edit), 3);
  172. for (i = monthly_jan_ckbox; i <= monthly_dec_ckbox; i++)
  173. {
  174. CheckDlgButton(Hwnd(), i, BST_CHECKED);
  175. }
  176. return TRUE;
  177. }
  178. //+--------------------------------------------------------------------------
  179. //
  180. // Member: CMonthlyPage::_OnPSNSetActive
  181. //
  182. // Synopsis: Enable Next button if this page's data is valid
  183. //
  184. // History: 5-20-1997 DavidMun Created
  185. //
  186. // Notes: Some of the page verification is left to the _OnWizNext
  187. // routine. This allows us to respond to invalid data by
  188. // displaying an explanatory message rather than simply
  189. // disabling the Next button.
  190. //
  191. //---------------------------------------------------------------------------
  192. LRESULT
  193. CMonthlyPage::_OnPSNSetActive(
  194. LPARAM lParam)
  195. {
  196. _UpdateWizButtons();
  197. return CPropPage::_OnPSNSetActive(lParam);
  198. }
  199. //+--------------------------------------------------------------------------
  200. //
  201. // Member: CMonthlyPage::_OnWizNext
  202. //
  203. // Synopsis: Validate the selections not already checked by
  204. // _OnPSNSetActive and _OnCommand.
  205. //
  206. // Returns: 0 - advance to next page
  207. // -1 - stay on this page
  208. //
  209. // History: 5-20-1997 DavidMun Created
  210. //
  211. //---------------------------------------------------------------------------
  212. LRESULT
  213. CMonthlyPage::_OnWizNext()
  214. {
  215. USHORT flMonths = _ReadSelectedMonths();
  216. //
  217. // Verify at least one month is selected
  218. //
  219. if (!flMonths)
  220. {
  221. SchedUIMessageDialog(Hwnd(),
  222. IERR_INVALID_MONTHLY_TASK,
  223. MB_OK | MB_ICONERROR | MB_SETFOREGROUND,
  224. (LPTSTR) NULL);
  225. return -1;
  226. }
  227. //
  228. // If the user specified that the trigger should fire on a specific day,
  229. // verify that at least one of the selected months contains that day.
  230. //
  231. if (_idSelectedDayType == monthly_day_rb)
  232. {
  233. USHORT usDay = (USHORT) UpDown_GetPos(_hCtrl(monthly_day_ud));
  234. ULONG idsErrMsg = 0;
  235. if (usDay == 31 &&
  236. (flMonths & MONTHS_WITHOUT_DAY_31) &&
  237. !(flMonths & ~MONTHS_WITHOUT_DAY_31))
  238. {
  239. idsErrMsg = IDS_MONTHS_HAVE_LT_31_DAYS;
  240. }
  241. else if (usDay == 30 && flMonths == TASK_FEBRUARY)
  242. {
  243. idsErrMsg = IDS_MONTHS_HAVE_LT_30_DAYS;
  244. }
  245. if (idsErrMsg)
  246. {
  247. SchedUIMessageDialog(Hwnd(),
  248. idsErrMsg,
  249. MB_OK | MB_ICONERROR | MB_SETFOREGROUND,
  250. (LPTSTR) NULL);
  251. SetWindowLongPtr(Hwnd(), DWLP_MSGRESULT, IDD_MONTHLY);
  252. return -1;
  253. }
  254. }
  255. //
  256. // Trigger is valid, delegate to base to advance to the next page.
  257. //
  258. return CTriggerPage::_OnWizNext();
  259. }
  260. //+--------------------------------------------------------------------------
  261. //
  262. // Member: CMonthlyPage::_UpdateWizButtons
  263. //
  264. // Synopsis: Enable the Next button if a preliminary analysis indicates
  265. // that the user's selections are valid.
  266. //
  267. // History: 5-20-1997 DavidMun Created
  268. //
  269. // Notes: _OnWizNext does additional checking
  270. //
  271. //---------------------------------------------------------------------------
  272. VOID
  273. CMonthlyPage::_UpdateWizButtons()
  274. {
  275. BOOL fEnableNext = TRUE;
  276. if (!_ReadSelectedMonths() || !_idSelectedDayType)
  277. {
  278. fEnableNext = FALSE;
  279. }
  280. if (fEnableNext)
  281. {
  282. _SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);
  283. }
  284. else
  285. {
  286. _SetWizButtons(PSWIZB_BACK);
  287. }
  288. }
  289. //===========================================================================
  290. //
  291. // CTriggerPage overrides
  292. //
  293. //===========================================================================
  294. //+--------------------------------------------------------------------------
  295. //
  296. // Member: CMonthlyPage::FillInTrigger
  297. //
  298. // Synopsis: Fill in the fields of the trigger structure according to the
  299. // settings specified for this type of trigger
  300. //
  301. // Arguments: [pTrigger] - trigger struct to fill in
  302. //
  303. // Modifies: *[pTrigger]
  304. //
  305. // History: 5-06-1997 DavidMun Created
  306. //
  307. // Notes: Precondition is that trigger's cbTriggerSize member is
  308. // initialized.
  309. //
  310. //---------------------------------------------------------------------------
  311. VOID
  312. CMonthlyPage::FillInTrigger(
  313. TASK_TRIGGER *pTrigger)
  314. {
  315. INT i;
  316. WORD *prgfMonths;
  317. if (_idSelectedDayType == monthly_day_rb)
  318. {
  319. pTrigger->TriggerType = TASK_TIME_TRIGGER_MONTHLYDATE;
  320. USHORT usDay = (USHORT) UpDown_GetPos(_hCtrl(monthly_day_ud));
  321. pTrigger->Type.MonthlyDate.rgfDays = 1 << (usDay - 1);
  322. prgfMonths = &pTrigger->Type.MonthlyDate.rgfMonths;
  323. }
  324. else
  325. {
  326. DEBUG_ASSERT(_idSelectedDayType == monthly_combo_rb);
  327. pTrigger->TriggerType = TASK_TIME_TRIGGER_MONTHLYDOW;
  328. i = ComboBox_GetCurSel(_hCtrl(monthly_ordinality_combo));
  329. pTrigger->Type.MonthlyDOW.wWhichWeek = (WORD)g_aWeekData[i].week;
  330. i = ComboBox_GetCurSel(_hCtrl(monthly_day_combo));
  331. pTrigger->Type.MonthlyDOW.rgfDaysOfTheWeek = (WORD)g_aDayData[i].day;
  332. prgfMonths = &pTrigger->Type.MonthlyDOW.rgfMonths;
  333. }
  334. *prgfMonths = _ReadSelectedMonths();
  335. SYSTEMTIME st;
  336. GetLocalTime(&st);
  337. pTrigger->wBeginYear = st.wYear;
  338. pTrigger->wBeginMonth = st.wMonth;
  339. pTrigger->wBeginDay = 1;
  340. DateTime_GetSystemtime(_hCtrl(starttime_dp), &st);
  341. pTrigger->wStartHour = st.wHour;
  342. pTrigger->wStartMinute = st.wMinute;
  343. }
  344. //===========================================================================
  345. //
  346. // CMonthlyPage methods
  347. //
  348. //===========================================================================
  349. //+--------------------------------------------------------------------------
  350. //
  351. // Member: CMonthlyPage::_ReadSelectedMonths
  352. //
  353. // Synopsis: Return a bitmask representing the checked day of week buttons
  354. //
  355. // History: 07-18-1997 DavidMun Created
  356. //
  357. //---------------------------------------------------------------------------
  358. WORD
  359. CMonthlyPage::_ReadSelectedMonths()
  360. {
  361. WORD flMonths = 0;
  362. INT i;
  363. for (i = monthly_jan_ckbox; i <= monthly_dec_ckbox; i++)
  364. {
  365. if (IsDlgButtonChecked(Hwnd(), i))
  366. {
  367. flMonths |= 1 << (i - monthly_jan_ckbox);
  368. }
  369. }
  370. return flMonths;
  371. }
  372. //+--------------------------------------------------------------------------
  373. //
  374. // Member: CMonthlyPage::_EnableDayCombos
  375. //
  376. // Synopsis: Enable or disable the monthly DOW controls
  377. //
  378. // History: 5-20-1997 DavidMun Created
  379. //
  380. //---------------------------------------------------------------------------
  381. VOID
  382. CMonthlyPage::_EnableDayCombos(
  383. BOOL fEnable)
  384. {
  385. EnableWindow(_hCtrl(monthly_ordinality_combo), fEnable);
  386. EnableWindow(_hCtrl(monthly_day_combo), fEnable);
  387. EnableWindow(_hCtrl(monthly_combo_lbl), fEnable);
  388. }