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.

246 lines
7.1 KiB

  1. /*
  2. * Windows Calendar
  3. * Copyright (c) 1985 by Microsoft Corporation, all rights reserved.
  4. * Written by Mark L. Chamberlin, consultant to Microsoft.
  5. *
  6. */
  7. /*
  8. *****
  9. ***** calrem.c
  10. *****
  11. */
  12. #include "cal.h"
  13. /**** FnRemove */
  14. INT_PTR CALLBACK FnRemove (
  15. HWND hwnd,
  16. UINT message,
  17. WPARAM wParam,
  18. LPARAM lParam)
  19. {
  20. DOSDATE dd;
  21. CHAR sz[CCHDASHDATE];
  22. switch (message)
  23. {
  24. case WM_INITDIALOG:
  25. /* Remember the window handle of the dialog for AlertBox. */
  26. vhwndDialog = hwnd;
  27. #ifdef OLDWAY
  28. /*
  29. * NT Bug 9019 says this should start from today's date,
  30. * but I personally think the function is more useful this way,
  31. * so I will leave the code here and just ifdef it out incase
  32. * I can convince others to let me put it back in.
  33. * 30-Jan-1993 JonPa
  34. */
  35. /* Get date string for 1-1-1980 */
  36. dd.month = 1;
  37. dd.day = 1;
  38. dd.year = 1980;
  39. GetDateString(&dd, sz, GDS_SHORT);
  40. #else
  41. /* Get date string for currently selected day */
  42. GetDashDateSel (sz);
  43. #endif
  44. SetDlgItemText (hwnd, IDCN_FROMDATE, sz);
  45. return (TRUE);
  46. case WM_COMMAND:
  47. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  48. case IDOK:
  49. GetRangeOfDates (hwnd);
  50. /* line added to fix keyboard hanging problem when
  51. Calendar is run under ver 3.0 rel 1.11 */
  52. CalSetFocus (GetDlgItem (hwnd, IDCN_FROMDATE));
  53. break;
  54. case IDCANCEL:
  55. EndDialog (hwnd, FALSE);
  56. break;
  57. }
  58. return (TRUE);
  59. }
  60. /* Tell Windows we did not process the message. */
  61. return (FALSE);
  62. }
  63. /**** GetRangeOfDates */
  64. VOID APIENTRY GetRangeOfDates (HWND hwnd)
  65. {
  66. CHAR szDateFrom [CCHDASHDATE];
  67. CHAR szDateTo [CCHDASHDATE];
  68. D3 d3From;
  69. GetDlgItemText (hwnd, IDCN_FROMDATE, szDateFrom, CCHDASHDATE);
  70. if (GetDlgItemText (hwnd, IDCN_TODATE, szDateTo, CCHDASHDATE) == 0)
  71. lstrcpy (szDateTo, szDateFrom);
  72. if (FD3FromDateSz (szDateFrom, &d3From) == 0
  73. && FD3FromDateSz (szDateTo, &vd3To) == 0
  74. && (vdtFrom = DtFromPd3 (&d3From)) <= (vdtTo = DtFromPd3 (&vd3To)))
  75. {
  76. /* Get the index of the first date in the range. Note that if the
  77. date doesn't exist in the tdd, the index of the first date
  78. higher than it is returned.
  79. */
  80. FSearchTdd (vdtFrom, &vitddFirst);
  81. /* Get the index of the last date in the range + 1. If an exact
  82. match is found, increment to get the one beyond the range.
  83. */
  84. if (FSearchTdd (vdtTo, &vitddMax))
  85. vitddMax++;
  86. EndDialog (hwnd, TRUE);
  87. }
  88. else
  89. {
  90. /* Error in date - put up message box. */
  91. AlertBox (vszBadDateRange,
  92. NULL, MB_APPLMODAL | MB_OK | MB_ICONASTERISK);
  93. }
  94. }
  95. /**** Remove - remove the dates within the range vd3From through vd3To.
  96. Call with vdtFrom <= vdtTo since Remove depends on this.
  97. Also, vitddFirst <= vitddLast.
  98. */
  99. VOID APIENTRY Remove ()
  100. {
  101. register WORD idr;
  102. register DR *pdr;
  103. /* Show the hour glass cursor. */
  104. HourGlassOn ();
  105. /* Record edits and disable focus so edits don't get recorded later
  106. into a DR that has been removed.
  107. */
  108. CalSetFocus (NULL);
  109. /* Free up any DRs within the range of dates to be removed. */
  110. for (idr = 0; idr < CDR; idr++)
  111. {
  112. /* Get a pointer to the DR. */
  113. pdr = PdrLock (idr);
  114. if (pdr -> dt >= vdtFrom && pdr -> dt <= vdtTo)
  115. pdr -> dt = DTNIL;
  116. /* Unlock the DR. */
  117. DrUnlock (idr);
  118. }
  119. /* Get rid of the dates. */
  120. ShrinkTdd (vitddFirst, vitddMax - vitddFirst);
  121. /* It's possible that the armed alarm has just been wiped out. If so,
  122. we need to arm a higher one (if there is one). By calling GetNextAlarm
  123. with vftAlarmNext, the current alarm will be kept if it hasn't been
  124. removed. If it has been removed, the next highest alarm will get
  125. armed. Note - there is no need to call AlarmCheck here - the
  126. new alarm is greater than or equal to the old one, and the old
  127. one had not gone off yet.
  128. */
  129. GetNextAlarm (&vftAlarmNext, &vftAlarmNext, TRUE, NULL);
  130. /* The date being displayed may have been removed, so update the
  131. display accordingly. In day mode, only removing the day being
  132. displayed matters, but in month mode, removing any marked days
  133. in the current month requires a redisplay. It doesn't seem worth
  134. the trouble to check for these cases and only update the display
  135. for them, so the display is updated in all cases.
  136. */
  137. if (vfDayMode)
  138. {
  139. /* This can't fail since the selected date is either still in
  140. memory (it wasn't removed) or it was removed and won't require
  141. disk I/O to create (since it has no longer has any data).
  142. Note that SwitchToDate will set the focus (which we turned
  143. off above).
  144. */
  145. SwitchToDate (&vd3Sel);
  146. }
  147. else
  148. {
  149. /* Reset the focus.
  150. Call UpdateMonth since marked days in the current month may
  151. have been removed. UpdateMonth will also call SetNotesEc,
  152. which is necessary since the notes for the selected date may
  153. have been removed. Note that vwDaySticky has not changed,
  154. so the correct day will get selected by UpdateMonth.
  155. */
  156. CalSetFocus (vhwndFocus);
  157. vd3To = vd3Sel;
  158. UpdateMonth ();
  159. }
  160. /* Remove makes the file dirty. */
  161. vfDirty = TRUE;
  162. /* The waiting is over. */
  163. HourGlassOff ();
  164. }
  165. /* Calls to HourGlassOn and HourGlassOff are always balanced, but they
  166. may be nested. For example, LoadCal calls HourGlassOn, then it
  167. calls CleanSlate. Cleanslate calls HourGlassOn, does its stuff,
  168. calls HourGlassOff, and returns to LoadCal. LoadCal does the
  169. rest of its stuff and calls HourGlassOff. To handle this nesting
  170. cleanly and without flicker, a count of calls to HourGlassOn
  171. is kept. When HourGlassOn increments this count from 0 to 1,
  172. the handle of the current cursor is saved away. When HourGlassOff
  173. decrements this count from 1 to 0, the cursor is restored to the
  174. saved one.
  175. */
  176. INT vcHourGlassOn = 0;
  177. HCURSOR vhcsrPrev;
  178. /**** HourGlassOn - put up the hour glass cursor and remember what
  179. the cursor was before.
  180. */
  181. VOID APIENTRY HourGlassOn ()
  182. {
  183. register HCURSOR hcsrTemp;
  184. hcsrTemp = SetCursor (vhcsrWait);
  185. if (vcHourGlassOn++ == 0)
  186. vhcsrPrev = hcsrTemp;
  187. }
  188. /**** HourGlassOff - restore the cursor to what it was before we put
  189. up the hour glass.
  190. */
  191. VOID APIENTRY HourGlassOff ()
  192. {
  193. if (--vcHourGlassOn == 0)
  194. SetCursor (vhcsrPrev);
  195. }