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.

376 lines
12 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. ****** calcmd.c
  7. *
  8. */
  9. #include "cal.h"
  10. #include <shellapi.h>
  11. /**** CalCommand - process menu command. */
  12. VOID APIENTRY CalCommand (
  13. HWND hwnd,
  14. INT idcm)
  15. {
  16. register HDC hDC;
  17. register DT dt;
  18. HWND hwndFocus;
  19. DWORD iSelFirst;
  20. DWORD iSelLast;
  21. INT tmStart12;
  22. INT itdd;
  23. DD *pdd;
  24. BOOL fTemp;
  25. /* Make the target date the same as the selected date. Several
  26. commands depend on this.
  27. */
  28. vd3To = vd3Sel;
  29. switch (idcm)
  30. {
  31. case IDCM_ABOUT:
  32. ShellAbout(hwnd, vrgsz[IDS_CALENDAR], "",
  33. LoadIcon((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  34. MAKEINTRESOURCE(1)));
  35. break;
  36. case IDCM_EXIT:
  37. PostMessage(hwnd, WM_CLOSE, 0, 0L);
  38. break;
  39. case IDCM_NEW:
  40. if (FCheckSave (FALSE))
  41. {
  42. vfOpenFileReadOnly = FALSE; /* in case earlier file was readonly */
  43. CleanSlate (TRUE);
  44. }
  45. break;
  46. case IDCM_OPEN:
  47. if (FCheckSave (FALSE))
  48. {
  49. vfOpenFileReadOnly = FALSE; /* in case earlier file was readonly */
  50. OpenCal ();
  51. }
  52. break;
  53. case IDCM_SAVE:
  54. if (vfOpenFileReadOnly)
  55. {
  56. AlertBox (vszFileReadOnly, (CHAR *)NULL,MB_APPLMODAL|MB_OK|
  57. MB_ICONEXCLAMATION);
  58. break;
  59. }
  60. else
  61. if (vfOriginalFile)
  62. {
  63. hwndFocus = GetFocus();
  64. FSaveFile (vszFileSpec, TRUE);
  65. SetFocus(hwndFocus);
  66. break;
  67. }
  68. /* There is no original file, which means we are still
  69. untitled, so we can't do a Save without getting a file
  70. name from the user. Fall into the Save As to do so.
  71. */
  72. case IDCM_SAVEAS:
  73. CallSaveAsDialog();
  74. break;
  75. case IDCM_PAGESETUP:
  76. FDoDialog (IDD_PAGESETUP);
  77. break;
  78. case IDCM_PRINT:
  79. if (FDoDialog (IDD_PRINT))
  80. Print ();
  81. break;
  82. case IDCM_PRINTERSETUP:
  83. vPD.Flags |= PD_PRINTSETUP; /* invoke only the Setup dialog */
  84. bPrinterSetupDone = PrintDlg ((LPPRINTDLG)&vPD);
  85. break;
  86. case IDCM_REMOVE:
  87. if (FDoDialog (IDD_REMOVE))
  88. Remove ();
  89. break;
  90. /* Guy hit delete key - either shifted or unshifted. */
  91. case IDCM_DEL:
  92. /* If window with focus is not edit ctl, nop. */
  93. if ((hwndFocus = GetFocus()) == vhwnd2B)
  94. break;
  95. /* Do something only if there is a non-null selection. */
  96. MSendMsgEM_GETSEL(hwndFocus, &iSelFirst, &iSelLast);
  97. if (iSelFirst != iSelLast)
  98. {
  99. /* If shifted delete, do a cut (which is a menu function.) */
  100. if ((GetKeyState(VK_SHIFT) < 0) || (GetKeyState(VK_DELETE) >= 0))
  101. {
  102. HiliteMenuItem(vhwnd0, GetMenu(vhwnd0), IDCM_CUT, MF_HILITE | MF_BYCOMMAND);
  103. SendMessage(hwndFocus, WM_CUT, (WORD)0, 0L);
  104. HiliteMenuItem(vhwnd0, GetMenu(vhwnd0), IDCM_CUT, MF_BYCOMMAND);
  105. /* Otherwise, do a clear (which is not a menu function.) */
  106. }
  107. else
  108. SendMessage(hwndFocus, WM_CLEAR, (WORD)0, 0L);
  109. }
  110. break;
  111. /* Note - Cut, Copy, and Paste are only enabled when
  112. one of the edit controls has the focus, so we know
  113. it's OK to just send the command to the edit control.
  114. */
  115. case IDCM_CUT:
  116. SendMessage (GetFocus (), WM_CUT, (WORD)0, 0L);
  117. break;
  118. case IDCM_COPY:
  119. SendMessage (GetFocus (), WM_COPY, (WORD)0, 0L);
  120. break;
  121. case IDCM_PASTE:
  122. SendMessage (GetFocus (), WM_PASTE, (WORD)0, 0L);
  123. break;
  124. case IDCM_DAY:
  125. DayMode (&vd3Sel);
  126. break;
  127. case IDCM_MONTH:
  128. vmScrollPos = 0;
  129. hmScrollPos = 0;
  130. MonthMode();
  131. break;
  132. case IDCM_TODAY:
  133. if (vfDayMode)
  134. SwitchToDate (&vd3Cur);
  135. else
  136. {
  137. /* added setfocus to fix bug where if in another month,
  138. * and focus in notes area, today's notes would get
  139. * overwritten with the current notes. why? who knows!
  140. */
  141. CalSetFocus(vhwnd2B);
  142. JumpDate (&vd3Cur);
  143. }
  144. break;
  145. case IDCM_PREVIOUS:
  146. if (vfDayMode)
  147. {
  148. if ((dt = DtFromPd3 (&vd3Sel)) != DTFIRST)
  149. {
  150. GetD3FromDt (--dt, &vd3To);
  151. SwitchToDate (&vd3To);
  152. }
  153. }
  154. else
  155. {
  156. /* Show the previous month . */
  157. /* This causes the new month window to be displayed
  158. from week 1 */
  159. vmScrollPos = 0;
  160. SetScrollPos (vhwnd2B, SB_VERT, vmScrollPos,TRUE);
  161. ShowMonthPrevNext (FALSE);
  162. }
  163. break;
  164. case IDCM_NEXT:
  165. if (vfDayMode)
  166. {
  167. if ((dt = DtFromPd3 (&vd3Sel)) != DTLAST)
  168. {
  169. GetD3FromDt (++dt, &vd3To);
  170. SwitchToDate (&vd3To);
  171. }
  172. }
  173. else
  174. {
  175. /* Show the next month. */
  176. vmScrollPos = 0;
  177. SetScrollPos (vhwnd2B, SB_VERT, vmScrollPos, TRUE);
  178. ShowMonthPrevNext (TRUE);
  179. }
  180. break;
  181. case IDCM_DATE:
  182. if (FDoDialog (IDD_DATE))
  183. {
  184. if (vfDayMode)
  185. SwitchToDate (&vd3To);
  186. else {
  187. /* added setfocus to fix bug where if in another month,
  188. * and focus in notes area, today's notes would get
  189. * overwritten with the current notes. why? who knows!
  190. */
  191. CalSetFocus(vhwnd2B);
  192. JumpDate (&vd3To);
  193. }
  194. }
  195. break;
  196. case IDCM_SET:
  197. AlarmToggle ();
  198. break;
  199. case IDCM_CONTROLS:
  200. if (FDoDialog (IDD_CONTROLS))
  201. {
  202. /* It's possible that the user just increased the
  203. Early Ring period. If so, it may be time for the
  204. next alarm to go off. Call AlarmCheck directly since
  205. CalTimer won't do it until the minute changes, and
  206. that might not be soon enough.
  207. Note that shortening the Early Ring period does not
  208. cause alarms that have previously gone off (due to
  209. the older, longer Early Ring period) to go off again.
  210. For example if the Early Ring period was 10, at 9:20
  211. the 9:30 alarm went off. If at 9:23 the user changes
  212. the Early Ring period to 5 minutes, the 9:30 alarm
  213. will not go off again at 9:25. The user has already
  214. seen the alarm.
  215. */
  216. AlarmCheck ();
  217. /* Changing the alarm controls makes the file dirty.
  218. Note that the user may not have actually changed
  219. the settings, but he did push the OK button, and
  220. that's close enough. It would be a waste of code
  221. to only set the dirty flag when the settings are
  222. actually different.
  223. */
  224. vfDirty = TRUE;
  225. }
  226. break;
  227. case IDCM_MARK:
  228. dt = DtFromPd3(&vd3Sel); /* fetch selected day */
  229. FSearchTdd (dt, &itdd);
  230. pdd = TddLock() + itdd;
  231. TddUnlock();
  232. viMarkSymbol = pdd->fMarked; /* set viMarkSymbol with active
  233. marks on selected day */
  234. /* show mark dialog */
  235. fTemp = (BOOL)DialogBox(vhInstance,
  236. MAKEINTRESOURCE(IDD_MARK), vhwnd0,
  237. FnMarkDay);
  238. vhwndDialog = NULL;
  239. if (fTemp)
  240. CmdMark ();
  241. break;
  242. /* Go Do help. Since menu items match numbers in help file,
  243. * no need to change them before calling help.
  244. */
  245. case IDCM_HELP:
  246. WinHelp(hwnd, vszHelpFile, HELP_INDEX, 0L);
  247. break;
  248. case IDCM_USINGHELP:
  249. WinHelp(hwnd, NULL, HELP_HELPONHELP, 0L);
  250. break;
  251. case IDCM_SEARCH:
  252. WinHelp(hwnd, vszHelpFile, HELP_PARTIALKEY, (DWORD_PTR)"");
  253. break;
  254. case IDCM_SPECIALTIME:
  255. if (FDoDialog (IDD_SPECIALTIME))
  256. {
  257. if (vfInsert)
  258. InsertSpecial ();
  259. else
  260. DeleteSpecial ();
  261. }
  262. break;
  263. case IDCM_DAYSETTINGS:
  264. if (FDoDialog (IDD_DAYSETTINGS))
  265. {
  266. /* Changing the day settings makes the file dirty.
  267. Note that the user may not have actually changed
  268. the settings, but he did push the OK button, and
  269. that's close enough. It would be a waste of code
  270. to only set the dirty flag when the settings are
  271. actually different.
  272. */
  273. vfDirty = TRUE;
  274. /* Redisplay the time since the clock format
  275. may have been changed.
  276. */
  277. hDC = CalGetDC (vhwnd2A);
  278. DispTime (hDC);
  279. ReleaseDC (vhwnd2A, hDC);
  280. if (vfDayMode)
  281. {
  282. /* Since the clock format, interval, and starting
  283. hour all affect the day mode display, just
  284. call DayMode to redisplay the whole works.
  285. */
  286. DayMode (&vd3Sel);
  287. }
  288. }
  289. break;
  290. /* Added new key functionality. Ctrl+Home scrolls appointment
  291. * window to StartTime. Ctrl+End scrolls to StartTime + 12 hours.
  292. * 26-Mar-1987.
  293. */
  294. case IDCM_START12:
  295. tmStart12 = vtmStart + 12 * 60; /* 12 hours later */
  296. if (tmStart12 > TMLAST-61)
  297. tmStart12 = TMLAST-61;
  298. /* fall thru... */
  299. case IDCM_START:
  300. if (vfDayMode && (GetFocus() == vhwnd3))
  301. FScrollDay(SB_THUMBPOSITION,
  302. ItmFromTm(idcm==IDCM_START ? vtmStart : tmStart12));
  303. break;
  304. }
  305. }
  306. /**** FDoDialog - Do modal dialog. */
  307. BOOL APIENTRY FDoDialog (INT idd)
  308. {
  309. INT fTemp;
  310. fTemp = (INT)DialogBox(vhInstance, MAKEINTRESOURCE(idd),
  311. vhwnd0, vrglpfnDialog[idd-1]);
  312. /* Tell AlertBox there is no longer a dialog active. */
  313. vhwndDialog = NULL;
  314. return (fTemp);
  315. }