home *** CD-ROM | disk | FTP | other *** search
- $m20000 !memory space.
- DEFINT "a-z" ! Make 'em all integers
- ap_id&=APPL_INIT() !DA identity.
- IF ap_id& !Is this one my ID.
- my_id&=MENU_REGISTER(ap_id&," Calendar") !Yes it seems to be.
- DO
- ~EVNT_MESAG(0)
- IF MENU(1)=40 !If DA has been opened
- @get_data
- @init
- ON MENU MESSAGE GOSUB message
- ON MENU KEY GOSUB mkey
- REPEAT
- ON MENU
- UNTIL exit%
- CLOSEW #1
- ENDIF
- LOOP
- ENDIF
- SYSTEM
- > PROCEDURE init ! Initialize things
- ts%=4
- pad%=42
- IF rez%=2
- ts%=13
- ENDIF
- DEFTEXT 1,1,0,ts%
- GEMSYS 77 ! graf_handle
- xchar%=INT{GINTOUT+2} ! character width
- ychar%=INT{GINTOUT+4} ! character height
- ~WIND_GET(0,4,wx%,wy%,ww%,wh%) ! Get work area of the desktop
- ~FORM_DIAL(3,0,0,0,0,wx%,wy%,ww%,wh%) ! Send a redraw message to the desktop
- wx%=ww%/2-xchar%*(pad%/2)-1 ! Set up a default window size and center it
- wy%=wh%/2-ychar%*(10.4)
- ww%=xchar%*(pad%)
- wh%=ychar%*(pad%/2)
- CLEARW #1
- TITLEW #1,"Calendar © Choices"
- OPENW #1,wx%,wy%,ww%,wh%,&X111111111111 ! Open our window
- IF rez%<1
- FULLW #1
- ENDIF
- handle%=W_HAND(#1)
- RETURN
- > PROCEDURE message ! Handle GEM messages
- wx%=MENU(5) ! intout coordinates
- wy%=MENU(6)
- ww%=MENU(7)
- wh%=MENU(8)
- '
- SELECT MENU(1) ! Get message type
- CASE 20 ! WM_REDRAW
- @redraw
- CASE 21 ! WM_TOPPED
- TOPW #1
- CASE 22 ! WM_CLOSED
- @quit
- CASE 23 ! WM_FULLED
- full%=1-full% ! Toggle between full and normal
- IF full%
- ox%=wx% ! If we're going to "full", save old window size
- oy%=wy%
- ow%=ww%
- oh%=wh%
- FULLW #1
- ELSE ! Otherwise set it back to old size
- ~WIND_SET(handle%,5,ox%,oy%,ow%,oh%)
- ENDIF
- CASE 24
- flag!=FALSE
- SELECT MENU(5)
- CASE 1
- @get_data
- @redraw
- CASE 2
- DEC month%
- IF month%<1
- month%=12
- DEC year%
- ENDIF
- @redraw
- CASE 3
- INC month%
- IF month%>12
- month%=1
- INC year%
- ENDIF
- @redraw
- CASE 6
- DEC year%
- @redraw
- CASE 7
- INC year%
- @redraw
- ENDSELECT
- CASE 27 ! WM_SIZED
- full%=0
- ~WIND_SET(handle%,5,wx%,wy%,MAX(180,ww%),MAX(80,wh%))
- CASE 28 ! WM_MOVED
- full%=0
- ~WIND_SET(handle%,5,wx%,wy%,ww%,wh%)
- ENDSELECT
- RETURN
- > PROCEDURE mkey ! Handle keypresses
- k$=UPPER$(CHR$(MENU(14) AND 255))
- SELECT k$
- CASE " " ! Spacebar brings up About box
- @about
- CASE "Q",27 ! Q or Esc quits program
- @quit
- ENDSELECT
- RETURN
- > PROCEDURE about ! Tell 'em what we've got, Roy.
- ALERT 1," | Calendar © Choices | by Roy E. Dean ",1," OK ",b%
- RETURN
- > PROCEDURE redraw ! Walk the rectangle list and do redraws
- ~WIND_UPDATE(1) ! Lock out other activity while we redraw
- ~WIND_GET(handle%,11,rx%,ry%,rw%,rh%) ! Get first rectangle in the list
- ~WIND_GET(handle%,4,ax%,ay%,aw%,ah%) ! Work area of our window
- REPEAT
- IF RC_INTERSECT(ax%,ay%,aw%,ah%,rx%,ry%,rw%,rh%) ! Find intersection
- CLIP rx%,ry%,rw%,rh% OFFSET ax%,ay% ! Set clipping to the area in question
- CLEARW #1 ! Clear the area
- @fillwindow ! Call our routine to redraw the area
- CLIP 0,0,WORK_OUT(0),WORK_OUT(1) ! Reset full-screen clipping
- ENDIF
- ~WIND_GET(handle%,12,rx%,ry%,rw%,rh%) ! Get next rectangle in the list
- UNTIL rw%=0 AND rh%=0 ! Keep repeating until no more rectangles
- ~WIND_UPDATE(0) ! Reenable other GEM activity
- RETURN
- > PROCEDURE fillwindow ! Redraw sections of our window
- IF year%=1992 AND month%=12
- flag!=TRUE
- ENDIF
- @print_cal
- RETURN
- > PROCEDURE quit
- ALERT 3," | Do you want to quit? | ",1," Quit | No ",b%
- IF b%=1
- CLOSEW #1
- exit%=TRUE
- ENDIF
- RETURN
- > PROCEDURE get_data
- rez%=XBIOS(4)
- MODE 0
- exit%=FALSE
- roy$=LEFT$(DATE$,2)
- year$=RIGHT$(DATE$,4)
- year%=VAL(year$)
- month$=MID$(DATE$,4,2)
- month%=VAL(month$)
- flag!=TRUE
- dait$=" 1 2 3 4 5 6 7 8 910111213141516171819"
- dait$=dait$+"202122232425262728293031 "
- daynames$=" Sun Mon Tue Wed Thu "
- daynames$=daynames$+" Fri Sat"
- monthname$="January February March April May June July "
- monthname$=monthname$+" August SeptemberOctober November December "
- monthdays$="312831303130313130313031"
- RETURN
- > PROCEDURE print_cal
- FOR mb%=1 TO month%
- mc%=mb%
- yc%=year%
- @calendar_day_of_week
- w1%=weekday%
- mc%=mb%
- month1$=MID$(monthname$,(mc%-1)*9+1,9)
- IF mb%>=month%
- CLS
- PRINT
- PRINT SPC(LEN(daynames$)*(pad%/100));month1$;" ";year%
- PRINT
- PRINT daynames$
- PRINT
- PRINT
- ENDIF
- mc%=mb%
- @days_in_month
- d1%=dm%
- FOR i%=1 TO 6
- j%=1
- IF i%>4 AND ((i%-1)*7+j%)>d1%+w1%
- ELSE
- IF mb%=>month%
- @weeks
- PRINT
- PRINT
- PRINT
- ENDIF
- ENDIF
- NEXT i%
- NEXT mb%
- RETURN
- > PROCEDURE calendar_day_of_week
- IF mc%<3
- ADD mc%,12
- DEC yc%
- ENDIF
- weekday%=1+2*mc%+INT(0.6*(mc%+1))+yc%+INT(yc%/4)-INT(yc%/100)+INT(yc%/400)+2
- weekday%=weekday%-INT(weekday%/7)*7
- weekday%=weekday%+6
- weekday%=weekday%-INT(weekday%/7)*7
- RETURN
- > PROCEDURE days_in_month
- IF mc%=2
- IF INT(year%/4)=year%/4
- MID$(monthdays$,2*mc%,1)="9"
- ENDIF
- IF INT(year%/4)<>year%/4
- MID$(monthdays$,2*mc%,1)="8"
- ENDIF
- ENDIF
- dm%=VAL(MID$(monthdays$,2*mc%-1,2))
- RETURN
- > PROCEDURE weeks
- FOR j%=1 TO 7
- e1%=((i%-1)*7+j%+6-w1%)*2-1
- IF ((i%-1)*7+j%)>(d1%+w1%)
- day$="__"
- ELSE
- day$=MID$(dait$,e1%,2)
- ENDIF
- IF roy$=day$ AND flag!
- DEFTEXT 3,1,0,ts%
- ENDIF
- PRINT " ";day$;" ";
- DEFTEXT 1,1,0,ts%
- NEXT j%
- RETURN
-