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.

498 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. ****** cal2.c
  7. *
  8. */
  9. #include "cal.h"
  10. #include <time.h>
  11. HDC vhDCTemp; /* Save code by not having to pass the HDC on each
  12. call to DrawArrow and DrawArrowBorder. */
  13. /**** CalPaint ****/
  14. VOID APIENTRY CalPaint (
  15. HWND hwnd,
  16. HDC hDC)
  17. {
  18. register D3 *pd3;
  19. if (hwnd == vhwnd1)
  20. PatBlt (hDC, 0, vycoNotesBox, vcxWnd2A , vcyBorder, PATCOPY);
  21. if (hwnd == vhwnd2A)
  22. {
  23. DispTime (hDC);
  24. /* Assume we are in month mode so we will display the
  25. current date.
  26. */
  27. pd3 = &vd3Cur;
  28. /* Set up global for DrawArrow and DrawArrowBorder. */
  29. vhDCTemp = hDC;
  30. #ifdef BUG_8560
  31. /* We want the arrows to have the border color. */
  32. SetTextColor (hDC, GetSysColor (COLOR_WINDOWFRAME));
  33. /* Draw left arrow. */
  34. DrawArrow (vhbmLeftArrow, vxcoLeftArrowFirst);
  35. /* Draw border at left end of left arrow. */
  36. DrawArrowBorder (vxcoLeftArrowFirst);
  37. /* Draw border between left and right arrows. */
  38. DrawArrowBorder (vxcoLeftArrowMax);
  39. /* Draw right arrow. */
  40. DrawArrow (vhbmRightArrow, vxcoRightArrowFirst);
  41. /* Draw border to right of right arrow. */
  42. DrawArrowBorder (vxcoRightArrowMax - vcxBorder);
  43. #endif
  44. /* Set colors back to defaults. */
  45. SetDefaultColors (hDC);
  46. /* Want to display the page date, not the current date. */
  47. pd3 = &vd3Sel;
  48. DispDate (hDC, pd3);
  49. return;
  50. }
  51. if (hwnd == vhwnd2B)
  52. {
  53. PatBlt (hDC, 0, 0, vcxWnd2B+ vcxVScrollBar, vcyBorder, PATCOPY);
  54. if (vfDayMode)
  55. DayPaint (hDC);
  56. else
  57. {
  58. PaintMonthGrid (hDC);
  59. PaintMonth (hDC);
  60. }
  61. }
  62. }
  63. #ifdef BUG_8560
  64. ******************* The following are no longer required ********************
  65. /**** DrawArrow ****/
  66. VOID APIENTRY DrawArrow (
  67. HBITMAP hbm,
  68. INT xco)
  69. {
  70. SelectObject (vhDCMemory, hbm);
  71. BitBlt (vhDCTemp, xco, vcyBorder, vcxHScrollBar, vcyHScrollBar,
  72. vhDCMemory, 0, 0, SRCCOPY);
  73. }
  74. /**** DrawArrowBorder ****/
  75. VOID APIENTRY DrawArrowBorder (INT xco)
  76. {
  77. PatBlt (vhDCTemp, xco, 0, vcxBorder, vcyWnd2A, PATCOPY);
  78. }
  79. ************************ No longer required ********************************
  80. #endif
  81. /**** DispTime - Display the current time. ****/
  82. VOID APIENTRY FAR DispTime (HDC hDC)
  83. {
  84. CHAR sz [CCHTIMESZ + 2]; /* added 2 for spaces. 19 Sep 89 Clark Cyr */
  85. /* Convert the time into an ASCII string. */
  86. GetTimeSz (vftCur.tm, sz);
  87. lstrcat((LPSTR)sz, (LPSTR)" ");
  88. /* Output the time. */
  89. TextOut (hDC, vcxFont, vcyExtLead, (LPSTR)sz, lstrlen((LPSTR)sz));
  90. }
  91. /**** GetTimeSz - convert the time into a zero terminated ASCII string. ****/
  92. INT APIENTRY GetTimeSz (
  93. TM tm, /* The time to convert. */
  94. CHAR *sz) /* pointer to the buffer to receive the string -
  95. the caller should allocate CCHTIMESZ chars. */
  96. {
  97. #ifndef NOCOMMON
  98. DOSTIME dt;
  99. dt.minutes = tm % 60;
  100. dt.hour = tm / 60;
  101. return(GetTimeString(&dt, sz, GTS_LEADINGZEROS | GTS_LEADINGSPACE));
  102. #else
  103. WORD wHour;
  104. /* Put in the boiler plate. */
  105. lstrcpy (sz + 2, ": ");
  106. wHour = tm / 60;
  107. if (!vfHour24)
  108. {
  109. lstrcpy (sz + 5, "am");
  110. if (wHour > 11)
  111. {
  112. /* Change to pm, and adjust down the hour. */
  113. *(sz + 5) = 'p';
  114. wHour -= 12;
  115. }
  116. /* Convert the 0 hour (midnight) to 12 (am is already selected). */
  117. if (wHour == 0)
  118. wHour = 12;
  119. }
  120. /* Convert the hours to ASCII. */
  121. ByteTo2Digs ((BYTE)wHour, sz);
  122. /* Change leading 0 to space if in 12 hour mode. */
  123. if (!vfHour24 && *sz == '0')
  124. *sz = ' ';
  125. /* Convert the minutes to ASCII. */
  126. ByteTo2Digs ((BYTE)(tm % 60), sz + 3);
  127. #endif
  128. }
  129. /**** ByteTo2Digs - convert byte to 2 decimal ASCII digits. ****/
  130. VOID APIENTRY ByteTo2Digs (
  131. BYTE b, /* The byte to convert from binary to ASCII. */
  132. CHAR *pch) /* Pointer to output buffer (must be at least 2
  133. chars long.
  134. */
  135. {
  136. *pch++ = b / 10 + '0';
  137. *pch = b % 10 + '0';
  138. }
  139. /**** DispDate - Display date in Wnd2A. */
  140. VOID APIENTRY FAR DispDate (
  141. HDC hDC,
  142. D3 *pd3)
  143. {
  144. RECT rc;
  145. HBRUSH hbr;
  146. CHAR sz [CCHDATEDISP];
  147. /* Convert the current date into an ASCII string. */
  148. GetDateDisp (pd3, sz);
  149. /* Erase the background */
  150. GetClientRect(vhwnd2A, (LPRECT)&rc);
  151. rc.left = vxcoDate;
  152. if (hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW)))
  153. {
  154. FillRect(hDC, (LPRECT)&rc, hbr);
  155. DeleteObject(hbr);
  156. }
  157. else
  158. FillRect(hDC, (LPRECT)&rc, GetStockObject(WHITE_BRUSH));
  159. SetBkMode(hDC,TRANSPARENT);
  160. /* Output the date. Use transparent mode so we don't erase the background
  161. * color.
  162. */
  163. TextOut (hDC, vxcoDate+2, vcyExtLead, (LPSTR)sz, lstrlen ((LPSTR)sz));
  164. SetBkMode(hDC,OPAQUE);
  165. }
  166. /**** GetDateDisp - convert the date to an ASCII string of the form:
  167. weekday, month, day, year. For example, "Sunday, March 30, 1985".
  168. ****/
  169. VOID APIENTRY GetDateDisp (
  170. D3 *pd3,
  171. CHAR *sz)
  172. {
  173. DOSDATE dd;
  174. dd.dayofweek = 0xff; /* so it'll calculate day of week */
  175. dd.year = pd3->wYear + 1980;
  176. dd.month = pd3->wMonth + 1;
  177. dd.day = pd3->wDay + 1;
  178. GetLongDateString(&dd, sz, GDS_LONG | GDS_DAYOFWEEK);
  179. }
  180. /**** FillBuf - fill buffer with specified count of specified byte.
  181. Return a pointer to the buffer position following the filled bytes.
  182. ****/
  183. BYTE * APIENTRY FillBuf (
  184. BYTE *pb,
  185. INT cb,
  186. BYTE b)
  187. {
  188. while (cb--)
  189. *pb++ = b;
  190. return (pb);
  191. }
  192. #ifndef NOCOMMON
  193. /**** WordToASCII - convert word to ASCII digits - return a pointer
  194. to the first character following the generated digits.
  195. ****/
  196. CHAR * APIENTRY WordToASCII (
  197. WORD w, /* Word to convert. */
  198. CHAR *pch, /* Pointer to output buffer. */
  199. BOOL fLeadZero) /* TRUE for leading zeroes,
  200. FALSE to suppress leading zeroes.
  201. */
  202. {
  203. WORD wPlace;
  204. WORD wDig;
  205. for (wPlace = 10000; wPlace > 0; wPlace /= 10)
  206. {
  207. wDig = w / wPlace;
  208. w %= wPlace;
  209. if (wDig != 0 || fLeadZero || wPlace == 1)
  210. {
  211. *pch++ = wDig + '0';
  212. /* After the first digit gets put down, we're no longer
  213. going to see leading zeros. Prevent additional zeroes
  214. from being suppressed by setting fLeadZero to TRUE.
  215. */
  216. fLeadZero = TRUE;
  217. }
  218. }
  219. return (pch);
  220. }
  221. #endif
  222. /**** GetDashDateSel - convert the selected date to an ASCII string
  223. of the form: mm-dd-yyyy. For example, "4-21-1985".
  224. ****/
  225. VOID APIENTRY GetDashDateSel (CHAR *sz)
  226. {
  227. #ifndef NOCOMMON
  228. DOSDATE dd;
  229. dd.month = vd3Sel.wMonth + 1;
  230. dd.day = vd3Sel.wDay + 1;
  231. dd.year = vd3Sel.wYear + 1980;
  232. GetDateString(&dd, sz, GDS_SHORT);
  233. #else
  234. sz = WordToASCII ((WORD)(vd3Sel.wMonth + 1), sz, FALSE);
  235. *sz++ = '-';
  236. sz = WordToASCII ((WORD)(vd3Sel.wDay + 1), sz, FALSE);
  237. *sz++ = '-';
  238. *(WordToASCII ((WORD)(vd3Sel.wYear + 1980), sz, FALSE)) = '\0';
  239. #endif
  240. }
  241. /**** FGetTmFromTimeSz
  242. The format for inputting the time is: [h]h[:mm][a|am|p|pm]
  243. In other words:
  244. - at least one digit must be used to specify the hour (even if it's 0)
  245. - the minutes are optional but if specified must be two digits preceded
  246. by a colon
  247. - the am/pm designation is optional and can be abbreviated by just a or p
  248. - The am/pm designation can use any combination of upper and lower case
  249. - If hours > 12 then OK if pm specified, but error if am specified.
  250. - if hours == 0 then OK if am specified, but error if pm specified.
  251. - If 1 <= hour <= 12 then default to am if no am/pm specification.
  252. ****/
  253. INT APIENTRY FGetTmFromTimeSz (
  254. CHAR *sz, /* INPUT - ASCII time string. */
  255. TM *ptm) /* OUTPUT - converted time - unchanged if we
  256. return FALSE.
  257. */
  258. {
  259. DOSTIME dt;
  260. INT iErr;
  261. if ((iErr = ParseTimeString(&dt, sz)) == 0)
  262. {
  263. *ptm = dt.hour * 60 + dt.minutes;
  264. return(TRUE);
  265. }
  266. return(iErr);
  267. }
  268. /**** SkipSpace - skip spaces in a sz. ****/
  269. VOID APIENTRY SkipSpace (CHAR **psz)
  270. {
  271. while (**psz == ' ')
  272. (*psz)++;
  273. }
  274. #ifdef NOCOMMON
  275. /**** FGetWord - convert ASCII digits into a word
  276. in the range 0 to 65535 inclusive.
  277. ****/
  278. BOOL APIENTRY FGetWord (
  279. CHAR **ppch,
  280. WORD *pw)
  281. {
  282. LONG l;
  283. CHAR ch;
  284. l = 0;
  285. /* Must see at least one digit. */
  286. if (!isdigit (**ppch))
  287. return (FALSE);
  288. while (isdigit (ch = **ppch))
  289. {
  290. l = l * 10 + (ch - '0');
  291. (*ppch)++;
  292. if (l > 65535)
  293. return (FALSE);
  294. }
  295. *pw = (WORD)l;
  296. return (TRUE);
  297. }
  298. #endif
  299. /**** ChUpperCase - convert from lower to upper case. ****/
  300. #ifdef DISABLE
  301. CHAR APIENTRY ChUpperCase (CHAR ch)
  302. {
  303. return (ch >= 'a' && ch <= 'z' ? ch - 'a' + 'A' : ch);
  304. }
  305. #endif
  306. /**** FD3FromDateSz
  307. Format supported: mm-dd-yyyy
  308. (Slashes (/) may be used instead of dashes.)
  309. If the year is in the range 0 through 99, it is assumed that the
  310. low order digits of 19yy have been specified.
  311. ****/
  312. BOOL APIENTRY FD3FromDateSz (
  313. CHAR *sz, /* INPUT - ASCII date string. */
  314. D3 *pd3) /* OUTPUT - converted date. Unchanged if
  315. we return FALSE.
  316. */
  317. {
  318. DOSDATE dd;
  319. INT iErr;
  320. if ((iErr = ParseDateString(&dd, sz)) == 0)
  321. {
  322. pd3->wMonth = dd.month - 1;
  323. pd3->wDay = dd.day - 1;
  324. pd3->wYear = dd.year - 1980;
  325. }
  326. return(iErr);
  327. }
  328. /**** GetD3FromDt ****/
  329. VOID APIENTRY GetD3FromDt (
  330. DT dt,
  331. D3 *pd3)
  332. {
  333. register INT cDaysYear;
  334. register INT i;
  335. INT cDaysMonth;
  336. /* See how many 4 year periods are in it (366 for leap year, 3 * 365
  337. for the next 3 years.
  338. */
  339. pd3 -> wYear = 4 * (dt / 1461);
  340. dt = dt % 1461;
  341. /* Account for the individual years. Again, the first year is
  342. a leap year, the next two are normal (only two since we already
  343. divided by groups of 4 years).
  344. */
  345. cDaysYear = 366;
  346. while ((INT)dt >= cDaysYear)
  347. {
  348. dt -= (DT)cDaysYear;
  349. pd3 -> wYear++;
  350. cDaysYear = 365;
  351. }
  352. /* Subtract out days of each month. Note that we add one
  353. to the count of days in the month for February in a leap year.
  354. */
  355. for (i = MONTHJAN; (INT)dt >= (cDaysMonth = vrgcDaysMonth [i] +
  356. (cDaysYear == 366 && i == MONTHFEB ? 1 : 0)); i++)
  357. dt -= (DT)cDaysMonth;
  358. pd3 -> wMonth = (WORD)i;
  359. /* Whatever's left is the offset into the month. */
  360. pd3 -> wDay = (WORD)dt;
  361. }
  362. /**** Set text of an edit ctl and then place selection at end. */
  363. VOID APIENTRY SetEcText(
  364. HWND hwnd,
  365. CHAR * sz)
  366. {
  367. WPARAM iSelFirst;
  368. WPARAM iSelLast;
  369. SetWindowText(hwnd, sz);
  370. iSelFirst = iSelLast = -1;
  371. SendMessage(hwnd, EM_SETSEL, iSelFirst, iSelLast);
  372. }