|
|
1.1 root 1: /* BioWndProc() - Parent WndProc message processing routine.
2: *
3: * Created by Microsoft Corp., 1988
4: *
5: * Purpose:
6: * WndProc callback function to handle all messages for parent window.
7: *
8: * Arguments:
9: * hWnd - Handle of Window owning message
10: * message - Message itself
11: * mp1 - Extra message-dependent info
12: * mp2 - Extra message-dependent info
13: *
14: * Globals (modified):
15: * Born - Bithdate in julian days. Read from WIN.INI.
16: * SelectDay - Current day being tracked, day is highlighted. Is
17: * in units of days from birth date. Date of present
18: * day initially used in WM_CREATE.
19: * daylight - Defined by environment string TZ. If no such string,
20: * timezone default TZ=PST8PDT used. If daylight field is
21: * used, daylight time correction will occur. See
22: * documentation of tzset() C run-time function.
23: * Day - Day number from date born which is top line being
24: * displayed. Initially three days before SelectDay.
25: * bKid - Boolean indicating whether child window legend is visible.
26: * bBorn - Boolean indicating whether valid birtdate entered or
27: * defined in WIN.INI. Nothing graphed until valid.
28: * rectClient - Size of client area defined by WM_SIZE message
29: * LinesPerPage - Number of system font lines on client area, defined
30: * by WM_SIZE message handling
31: * Color[] - Set of colored pens used to identify cycles.
32: * tmFontInfo - Text Metric structure defined during WM_CREATE
33: *
34: * Globals (referenced):
35: * hAB - Handle to the Anchor Block
36: * hwndAppFrame - Window handle of parent window's frame
37: * hwndKidFrame - Handle to child window used for showing/moving legend.
38: * szAppName[] - RC file program name (Biorhythm).
39: *
40: * Description:
41: * Handle all messages for the parent window.
42: *
43: * Limits:
44: * N/A
45: *
46: */
47:
48: #define INCL_GPI
49: #define INCL_WIN
50: #include <os2.h>
51:
52: #include "bio.h"
53: #include <time.h>
54: #include <stdio.h>
55:
56: /* Read-only global variables */
57: extern HAB hAB;
58: extern HWND hwndApp;
59: extern HWND hwndAppFrame, hwndKidFrame;
60: extern char szAppName[];
61:
62: /* Write-once Global variables */
63: LONG Color[] = {CLR_RED, CLR_GREEN, CLR_BLUE};
64: FONTMETRICS tmFontInfo;
65:
66: /* Read-Write global variables */
67: double Born;
68: long Day, SelectDay;
69: BOOL bKid = TRUE;
70: BOOL bBorn = TRUE;
71: RECTL rectClient;
72: int LinesPerPage;
73:
74:
75: MRESULT FAR PASCAL BioWndProc( hWnd, message, mp1, mp2 )
76: HWND hWnd;
77: USHORT message;
78: MPARAM mp1;
79: MPARAM mp2;
80: {
81: /* Procedures which make up the window class. */
82: int year, month, iDay, i;
83: double day;
84: HPS hPS;
85: RECTL rc;
86:
87: switch( message )
88: {
89:
90: case WM_CREATE:
91: /* Read in birth date from OS2.INI. Error value is 12-31-1899,
92: which is out of range for valid entries. */
93: year = WinQueryProfileInt( hAB, szAppName, "Year", 1899 );
94: month = WinQueryProfileInt( hAB, szAppName, "Month", 12 );
95: day = (double)WinQueryProfileInt( hAB, szAppName, "Day", 31 );
96: /* Compute date of birth in julian days */
97: Born = julian( year, month, day );
98:
99: /* Get time zone environment information */
100: tzset();
101: /* System clock starts 1-1-1970. Get julian date then and how many
102: days have elapsed since, so that number of days since birth date
103: can be determined */
104: SelectDay = (long)(julian( 1970, 1, 1.0 ) +
105: (double)((time(NULL) - timezone + (long)daylight*3600)/86400) -
106: Born);
107:
108: /* If no valid OS2.INI info then automatically bring up dialog box */
109: if (year < 1900) {
110: bBorn = FALSE;
111: WinPostMsg( hWnd, WM_COMMAND, (MPARAM)MAKEULONG(IDDATES, 0), 0L );
112: }
113:
114: /* Put date of the day three lines down on display */
115: Day = SelectDay - 3;
116: /* Initially set elevator */
117: iDay = (int)(Day/365);
118: WinSendMsg( WinWindowFromID( WinQueryWindow(hWnd,QW_PARENT,FALSE),
119: FID_VERTSCROLL),
120: SBM_SETPOS, (MPARAM)MAKEULONG(iDay, 0), 0L );
121:
122: /* Get System font text metrics */
123: hPS = WinGetPS( hWnd );
124: GpiQueryFontMetrics( hPS, (LONG)sizeof tmFontInfo, &tmFontInfo );
125: WinReleasePS( hPS );
126: break;
127:
128: case WM_CLOSE:
129: WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
130: break;
131:
132: case WM_COMMAND:
133: switch (LOUSHORT(mp1)) {
134: case IDDATES:
135: if (WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)BioDlg, NULL, IDD_DATE, NULL )) {
136: WinInvalidateRect( hWnd, NULL, FALSE );
137: iDay = (int)(Day/365);
138: WinSendMsg( WinWindowFromID( hwndAppFrame, FID_VERTSCROLL),
139: SBM_SETPOS, (MPARAM)MAKEULONG(iDay, 0), 0L );
140: }
141: break;
142:
143: case IDKID:
144: if (bKid = !bKid) {
145: WinSendMsg( WinWindowFromID( hwndAppFrame, FID_MENU),
146: MM_SETITEMATTR,
147: (MPARAM)MAKEULONG( IDKID, TRUE ),
148: (MPARAM)MAKEULONG( MIA_CHECKED, MIA_CHECKED) );
149: WinShowWindow( hwndKidFrame, TRUE );
150: } else {
151: WinSendMsg( WinWindowFromID( hwndAppFrame, FID_MENU),
152: MM_SETITEMATTR,
153: (MPARAM)MAKEULONG( IDKID, TRUE ),
154: (MPARAM)MAKEULONG( MIA_CHECKED, 0) );
155: WinShowWindow( hwndKidFrame, FALSE );
156: }
157: break;
158:
159: case IDCOPY:
160: WinMessageBox( HWND_DESKTOP, hWnd,
161: (NPCH)"Coming soon to a theatre near you",
162: (NPCH)"BitBlt to Clipboard", NULL,
163: MB_OK | MB_ICONEXCLAMATION );
164: break;
165:
166: case IDABOUT:
167: WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)About, NULL,
168: IDD_ABOUT, NULL );
169: break;
170:
171: default:
172: break;
173: }
174: break;
175:
176: case WM_SIZE:
177: WinQueryWindowRect( hWnd, &rectClient );
178: LinesPerPage = (int)(rectClient.yTop / tmFontInfo.lMaxBaselineExt);
179: WinSetWindowPos( hwndKidFrame, NULL, 10, 10, 0, 0, SWP_MOVE );
180: break;
181:
182: case WM_CHAR:
183: /* Send keyboard characters to scroll bar to support scrolling,
184: paging, etc. */
185: return WinSendMsg( WinWindowFromID( hwndAppFrame, FID_VERTSCROLL),
186: message, mp1, mp2 );
187: break;
188:
189: case WM_VSCROLL:
190: /* Don't allow any processing until valid birth date entered */
191: if (!bBorn) break;
192:
193: /* Setup for scroll window - full width of client area is scrolled */
194: WinCopyRect( hAB, &rc, &rectClient );
195: switch (HIUSHORT(mp2)) {
196: case SB_LINEUP:
197: /* Update top day of display */
198: Day--;
199: rc.yTop = rectClient.yTop - tmFontInfo.lMaxBaselineExt;
200: rc.yBottom = rectClient.yTop - (LinesPerPage-1) * tmFontInfo.lMaxBaselineExt + 1;
201: WinScrollWindow( hWnd, 0, (SHORT)-tmFontInfo.lMaxBaselineExt, &rc,
202: NULL, NULL, NULL, SW_INVALIDATERGN );
203: break;
204: case SB_LINEDOWN:
205: /* Update top day of display */
206: Day++;
207: rc.yTop = rectClient.yTop - 2*tmFontInfo.lMaxBaselineExt;
208: rc.yBottom = rectClient.yTop - (LinesPerPage) * tmFontInfo.lMaxBaselineExt + 1;
209: WinScrollWindow( hWnd, 0, (SHORT)tmFontInfo.lMaxBaselineExt, &rc,
210: NULL, NULL, NULL, SW_INVALIDATERGN );
211: break;
212: case SB_PAGEUP:
213: Day -= (LinesPerPage-1);
214: break;
215: case SB_PAGEDOWN:
216: Day += (LinesPerPage-1);
217: break;
218: case SB_SLIDERPOSITION:
219: /* Set to birthday of each year because 100 year scale maps to
220: default 100 position scroll bar */
221: Day = (long)(LOUSHORT(mp2) * 365.25);
222: break;
223: default:
224: return 0L;
225: }
226: /* Update scroll bar elevator */
227: iDay = (int)(Day/365);
228: WinSendMsg( WinWindowFromID( hwndAppFrame, FID_VERTSCROLL),
229: SBM_SETPOS, (MPARAM)MAKEULONG(iDay, 0), 0L );
230: /* All but LINEUP/DOWN need full repaint of client area */
231: if ((HIUSHORT(mp2) != SB_LINEUP) && (HIUSHORT(mp2) != SB_LINEDOWN ))
232: WinInvalidateRect( hWnd, NULL, FALSE );
233: WinUpdateWindow( hWnd );
234: break;
235:
236: case WM_PAINT:
237: APPPaint( hWnd );
238: break;
239:
240: case WM_BUTTON1DOWN:
241: /* Don't allow any processing until valid birth date entered */
242: if (!bBorn) break;
243:
244: /* Unhighlight previously selected line and highlight new line */
245: WinCopyRect( hAB, &rc, &rectClient );
246: hPS = WinGetPS( hWnd );
247: for(i=0; i<2; i++) {
248: /* Make sure line is visible before (un)highlighting */
249: if ((SelectDay >= Day) && (SelectDay - Day < LinesPerPage-1)) {
250: rc.yTop = rectClient.yTop - (int)(SelectDay - Day + 1) * tmFontInfo.lMaxBaselineExt;
251: rc.yBottom = rc.yTop - tmFontInfo.lMaxBaselineExt + 1;
252: WinInvertRect( hPS, &rc );
253: }
254: /* New line to highlight */
255: SelectDay = Day + (rectClient.yTop - HIUSHORT(mp1)) /
256: tmFontInfo.lMaxBaselineExt - 1;
257: }
258: WinReleasePS( hPS );
259: break;
260:
261: /* Draw highlight on selected day */
262: if ((SelectDay >= Day) && (SelectDay - Day < LinesPerPage - 1)) {
263: rc.xRight = rectClient.xRight;
264: rc.xLeft = rectClient.xLeft;
265: }
266: default:
267: return WinDefWindowProc( hWnd, message, mp1, mp2 );
268: break;
269: }
270: return( 0L );
271: }
272:
273: /* KidWndProc() - Child WndProc handling legend display.
274: *
275: * Purpose:
276: * WndProc callback function to handle all messages for legend child.
277: *
278: * Arguments:
279: * hWnd - Handle of Window owning message
280: * message - Message itself
281: * mp1 - Extra message-dependent info
282: * mp2 - Extra message-dependent info
283: *
284: * Globals (modified):
285: * none
286: *
287: * Globals (referenced):
288: * hwndApp - Window handle of parent window's client area
289: * tmFontInfo - Text Metric structure defined during WM_CREATE
290: * Color[] - Set of colored pens used to identify cycles.
291: *
292: * Description:
293: * Display legend information relating graph line styles to each
294: * cyle: physical, emotional and intellectual. Notifies parent
295: * to hide child if child window is instructed to close by user.
296: *
297: * Limits:
298: * N/A.
299: *
300: */
301:
302: /* Read-only global variables */
303: extern HWND hwndApp;
304:
305: MRESULT FAR PASCAL KidWndProc( hWnd, message, mp1, mp2 )
306: HWND hWnd;
307: USHORT message;
308: MPARAM mp1;
309: MPARAM mp2;
310: {
311: HPS hPS;
312: RECTL rc;
313: POINTL ptl;
314: int i;
315:
316: switch( message )
317: {
318: case WM_PAINT:
319: hPS = WinBeginPaint( hWnd, NULL, NULL );
320:
321: /* Erase client area */
322: WinQueryWindowRect( hWnd, &rc );
323: WinFillRect( hPS, &rc, CLR_PALEGRAY );
324:
325: ptl.x = 0;
326: ptl.y = tmFontInfo.lMaxDescender;
327: GpiCharStringAt( hPS, &ptl, 9L, (PCH)"Physical " );
328: ptl.y += tmFontInfo.lMaxBaselineExt;
329: GpiCharStringAt( hPS, &ptl, 9L, (PCH)"Emotional" );
330: ptl.y += tmFontInfo.lMaxBaselineExt;
331: GpiCharStringAt( hPS, &ptl, 9L, (PCH)"Intellect" );
332:
333: for (i=0; i<3; i++ ) {
334: GpiSetColor( hPS, Color[i] );
335: ptl.x = tmFontInfo.lAveCharWidth * 10;
336: ptl.y = i * tmFontInfo.lMaxBaselineExt +
337: tmFontInfo.lMaxBaselineExt/2;
338: GpiMove( hPS, &ptl );
339: ptl.x = tmFontInfo.lAveCharWidth * 20;
340: GpiLine( hPS, &ptl );
341: }
342:
343: WinEndPaint( hPS );
344: break;
345:
346:
347: case WM_CLOSE:
348: WinPostMsg( hwndApp, WM_COMMAND, (MPARAM)MAKEULONG(IDKID, 0), 0L );
349: break;
350:
351: default:
352: return WinDefWindowProc( hWnd, message, mp1, mp2 );
353: break;
354: }
355: return( 0L );
356: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.