# WimpWorks Information File
# WimpWorks  Jaffa Software 1996-8. All rights reserved.

DEF TASKdetails
	Name		FlexiPlan
	Purpose		To create a year planner
	Author		V Markwart & C Egginton
	Licence		Freeware
	Version		0.03 21 January 1999
	Compress	False
	Memory		0K
	IconbarSide	Right
	IconbarPriority	&00000000
	IconbarSprite	!flexiplan
	IconbarText	
ENDTASK

DEF WEMinclude
ENDWEM

DEF MENUiconMenu%
	FlexiPlan
	Info
		S(infoWindow%)
		
	Quit
		
		CLOSEDOWN
ENDMENU

DEF SUBR_PROCmenu_klik
	Event	3
	Every	-1
DEF PROCmenu_klik(button%)
  PROCmouse(mx%,my%,mb%,window,icon)
  IF button%<>2 THEN
    IF flag%=0 THEN
      MOVEWINDOW(FlexiPlan, mx%-250, my%+50)
    ENDIF
    flag%+=1
    OPENWINDOW(FlexiPlan)
  ENDIF  
ENDPROC
ENDSUBR

DEF SUBR_PROCinit
	Event	0
	Every	-1
DEF PROCinit
DIM workspace% 22

col%=&00000000
inch=46080
cm=18142

open=FALSE
REM Draw file header
 DIM B%(24), D$(6), M$(13), N(13)
 RESTORE +1
 DATA 68,114,97,119,201,0,0,0,0,0,0,0,65,114,99,68,114,97,119,32,32,32,32,32
 FOR I=1 TO 24
   READ B%(I)
 NEXT
 
REM Days of Week 
 RESTORE +1
 DATA Sun,Mon,Tue,Wed,Thu,Fri,Sat
 FOR I=0 TO 6
   READ D$(I)
 NEXT
 
REM Months of Year
 RESTORE +1
 DATA January,31,February,28,March,31,April,30,May,31,June,30,July,31,August,31,September,30,October,31,November,30,December,31
 FOR I=1 TO 12
   READ M$(I),N(I)
 NEXT

  flag%=0
  minyear%=1980
  date$=SYSDATE
  year$=RIGHT$(date$, 4)
  month$=MID$(date$,4,3)
  CASE month$ OF
  WHEN "Jan": month%=1
  WHEN "Feb": month%=2
  WHEN "Mar": month%=3
  WHEN "Apr": month%=4
  WHEN "May": month%=5
  WHEN "Jun": month%=6
  WHEN "Jul": month%=7
  WHEN "Aug": month%=8
  WHEN "Sep": month%=9
  WHEN "Oct": month%=10
  WHEN "Nov": month%=11
  WHEN "Dec": month%=12
  OTHERWISE
    month%=1
  ENDCASE
  SETSTATE(FlexiPlan, 5 + month%,1) 
  yearX%=EVAL(year$)
  SETICON(FlexiPlan, 4, year$)  
ENDPROC
ENDSUBR

DEF SUBR_PROCwin_klik
	Event	12
	Every	-1
DEF PROCwin_klik(window%, icon%, button%)
  IF window%=FlexiPlan THEN
    year$=READICON(window%,4)
    IF year$="" THEN year$="0"
      year%=EVAL(year$)
    ENDIF
    CASE icon% OF
    WHEN 0:
      IF button%=1 THEN open=TRUE ELSE open=FALSE
      month%=GROUPSTATE(FlexiPlan, 1) - 5
    
      PROCmouse(mx%, my%, mb%, window, icon)
      SETSAVE("Plan_"+year$, "file_aff")
      CLOSEWINDOW(FlexiPlan)
      OPENSAVE
    WHEN 1:
      CLOSEWINDOW(FlexiPlan)
    WHEN 2:
      year% -=1
      year$=STR$(year%)
      SETICON(window%, 4, year$)
    WHEN 3:
      year% +=1
      year$=STR$(year%)
      SETICON(window%, 4, year$)
    ENDCASE
    IF year%<minyear% THEN
      year%=minyear%
      year$=STR$(minyear%)
      SETICON(FlexiPlan, 4, year$)
      WARNING("Can't have years less than "+STR$(minyear%), "FlexiPlan")
    ENDIF
  ENDIF
     
ENDPROC
ENDSUBR

DEF SUBR_FNdow
	Event	-1
	Every	-1
DEF FNdow(jd)
  LOCAL a, b
  a=(jd + 1.5)/7
  b=INT(a)
=INT((a-b)*7 + .5)

ENDSUBR

DEF SUBR_FNjulday
	Event	-1
	Every	-1
DEF FNjulday(year, month, day)
  LOCAL a, b, c, d
  IF month<3 THEN year=year-1 : month=month+12
  a=year DIV 100
  b=2-a + a DIV 4
  c=INT(365.25 * year)
  d=INT(30.6001 * (month+1))
=b + c + d + day + 1720994.5    
ENDSUBR

DEF SUBR_PROCmouse
	Event	-1
	Every	-1
DEF PROCmouse(RETURN mx%, RETURN my%, RETURN mb%, RETURN window, RETURN icon)
  SYS "Wimp_GetPointerInfo",,workspace%
  mx%= workspace%!0
  my%= workspace%!4
  mb%= workspace%!8
  window= workspace%!12
  icon= workspace%!16  
ENDPROC
ENDSUBR

DEF SUBR_PROCCreateFile
	Event	-1
	Every	-1
DEF PROCCreateFile(file$)
  
ENDPROC
ENDSUBR

DEF SUBR_FNsave_file
	Event	8
	Every	-1
DEF FNsave_file(file$)
  filename$=file$
  IF filename$="" THEN WARNING("Filename not appropriate", "Flexiplan Error") : ENDPROC
  outfile%=OPENOUT(filename$)
  ON ERROR CLOSE#outfile%: WARNING("Can't create Flexiplan file", "Flexiplan Error"): END

DRAW_INIT(2)
DRAW_FONT("Trinity.Bold", font1%)
DRAW_FONT("Trinity.Medium", font2%)

DRAW_STARTPATH(-1, col%, 1)
REM Draw grid

FOR I=1 TO 16
  DRAW_MOVE(0,0)
  DRAW_LINE(100,100)
NEXT

first1=TRUE
PROCCreateGrid
PROCCreateTextArea
P%=PTR#outfile%
PTR#outfile%=BBoxptr%
PROCs(Xmin)
PROCs(Ymin)
PROCs(Xmax)
PROCs(Ymax)
PTR#outfile%=P%
CLOSE#outfile%
OSCLI("SETTYPE "+filename$+" Drawfile")
IF open=TRUE THEN OPENWINDOW(FlexiPlan)   
=0
ENDSUBR

