1 /* ------------- calendar.c ------------- */
7 static int DyMo
[] = {31,28,31,30,31,30,31,31,30,31,30,31};
12 static void FixDate(void)
14 /* ---- adjust Feb for leap year ---- */
15 if (ttm
.tm_year
% 4 == 0)
17 if (ttm
.tm_year
% 100 == 0)
19 if (ttm
.tm_year
% 400 == 0)
38 ttm
.tm_mday
= min(ttm
.tm_mday
, DyMo
[ttm
.tm_mon
]);
41 /* ---- build calendar dates array ---- */
42 static void BuildDateArray(void)
45 memset(dys
, 0, sizeof dys
);
47 /* ----- compute the weekday for the 1st ----- */
48 offset
= ((ttm
.tm_mday
-1) - ttm
.tm_wday
) % 7;
52 offset
= (offset
- 7) * -1;
53 /* ----- build the dates into the array ---- */
54 for (dy
= 1; dy
<= DyMo
[ttm
.tm_mon
]; dy
++)
58 static void CreateWindowMsg(DFWINDOW wnd
)
61 DfDrawBox(wnd
, 1, 2, CALHEIGHT
-4, CALWIDTH
-4);
62 for (x
= 5; x
< CALWIDTH
-4; x
+= 4)
63 DfDrawVector(wnd
, x
, 2, CALHEIGHT
-4, FALSE
);
64 for (y
= 4; y
< CALHEIGHT
-3; y
+=2)
65 DfDrawVector(wnd
, 1, y
, CALWIDTH
-4, TRUE
);
68 static void DisplayDates(DFWINDOW wnd
)
73 char banner
[CALWIDTH
-1];
76 DfSetStandardColor(wnd
);
77 DfPutWindowLine(wnd
, "Sun Mon Tue Wed Thu Fri Sat", 2, 1);
78 memset(banner
, ' ', CALWIDTH
-2);
79 strftime(banner1
, 16, "%B, %Y", &ttm
);
80 offset
= (CALWIDTH
-2 - strlen(banner1
)) / 2;
81 strcpy(banner
+offset
, banner1
);
83 DfPutWindowLine(wnd
, banner
, 0, 0);
85 for (week
= 0; week
< 6; week
++) {
86 for (day
= 0; day
< 7; day
++) {
87 int dy
= dys
[week
*7+day
];
91 if (dy
== ttm
.tm_mday
)
92 sprintf(dyln
, "%c%c%c%2d %c",
94 DfSelectForeground(wnd
)+0x80,
95 DfSelectBackground(wnd
)+0x80,
98 sprintf(dyln
, "%2d ", dy
);
100 DfSetStandardColor(wnd
);
101 DfPutWindowLine(wnd
, dyln
, 2 + day
* 4, 3 + week
*2);
106 static int KeyboardMsg(DFWINDOW wnd
, DF_PARAM p1
)
110 if (ttm
.tm_mon
== 0) {
121 if (ttm
.tm_mon
== 12) {
135 static int CalendarProc(DFWINDOW wnd
,DFMESSAGE msg
,
136 DF_PARAM p1
,DF_PARAM p2
)
139 case DFM_CREATE_WINDOW
:
140 DfDefaultWndProc(wnd
, msg
, p1
, p2
);
141 CreateWindowMsg(wnd
);
144 if (KeyboardMsg(wnd
, p1
))
148 DfDefaultWndProc(wnd
, msg
, p1
, p2
);
152 if ((int)p1
== DF_ID_HELP
) {
153 DfDisplayHelp(wnd
, "Calendar");
157 case DFM_CLOSE_WINDOW
:
163 return DfDefaultWndProc(wnd
, msg
, p1
, p2
);
166 void Calendar(DFWINDOW pwnd
)
169 time_t tim
= time(NULL
);
170 ttm
= *localtime(&tim
);
171 Cwnd
= DfDfCreateWindow(DF_PICTUREBOX
,
173 -1, -1, CALHEIGHT
, CALWIDTH
,
174 NULL
, pwnd
, CalendarProc
,
182 DfSendMessage(Cwnd
, DFM_SETFOCUS
, TRUE
, 0);