home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
pocketbk
/
utilsu
/
worktime20
/
v2.06
/
worktime.opl
< prev
next >
Wrap
Text File
|
1995-01-04
|
25KB
|
1,129 lines
APP WorkTime
TYPE $1003
EXT "WTM"
ICON "\OPD\Worktime.pic"
ENDA
PROC Start:
global sad&,maxday&,d1970&,d2038&
global off&,exists%,cur&
global gcy%,gcmax%
global setup&(10)
global bmeet&,bleave&,bnormal&,bcomnt$(20)
global fonttyp%,zoom%,lines%,h% Rem for zoomming
global prolist$(255)
Rem --- Constants ---
sad& = 86400 REM Seconds a day (24*60*60)
maxday& = 86399 REM 23:59:59
d1970& = 25567 REM days(1,1,1970)
d2038& = 50422 REM days(19,1,2038) Rem Not 100% correct, but closer than a Pentium ;-)
defaultwin 1
statuswin on,2
gsetwin 0,0,415,160
SysReq:(cmd$(3),cmd$(2)) rem open file
Handler:
ENDP
PROC SysReq:(act$,file$) REM For system requests
SaveFile:
if act$="X" rem Close and Exit
stop
elseif act$="C" rem Create new file
MkFile:(file$)
elseif act$="O" rem Open file
OpenFile:(file$)
endif
ENDP
PROC SetFont:
local i%(32),font%
Rem
Rem Recalculate all font size dependent values
Rem
font%=fonttyp%+zoom%
setup&(10)=font%
gfont font%
font font%,0
ginfo i%()
h%=i%(3)
Rem TODO: Extract screen width
Rem TODO: and recalc column widths
lines%=(gheight-8)/h%
gcmax%=(lines%-1)*h%
off&=Offset&:(cur&,1-lines%) :gcy%=gcmax%
REM -- A repaint: is needed after this
rem cursor 1,1,255,h%,2 REM To bad max width is 255, really
ENDP
PROC Handler:
global a%(6)
onerr Error
while 1
getevent a%()
@("x"+hex$(a%(1))):
continue
Rem This part is only reached when no
Rem corresponding event handler is found.
Rem Keypresses fall back on either TextED: or RecED:
Error::
if err=-99 and a%(1)<256
if a%(1)>64 rem Textchars
TextED:
else Rem Other
RecED:
endif
else
ShowErr:(hex$(a%(1)))
endif
endwh
ENDP
PROC MkFile:(reqfile$)
local file$(128),o%(6)
o%(1)=1 :o%(2)=6 :o%(3)=8 :o%(4)=8 :o%(5)=10 :o%(6)=0
file$=parse$(reqfile$,"LOC::M:\*.WTM",o%())
trap create file$,A,meet&,leave&,normal&,total&,comment$
if err
ShowErr:("Cannot create '"+file$+"'")
else
append rem Append empty entry
setname file$
setup&(1)=28800 REM 08:00:00 = 8*60*60 / Monday
setup&(2)=28800 REM 08:00:00 = 8*60*60 / Tuesday
setup&(3)=28800 REM 08:00:00 = 8*60*60 / Wedensday
setup&(4)=28800 REM 08:00:00 = 8*60*60 / Thursday
setup&(5)=18000 REM 05:00:00 = 5*60*60 / Friday
setup&(6)=0 rem Saturday
setup&(7)=0 rem Sunday
setup&(8)=0 rem Morning slack
setup&(9)=0 rem Evening slack
setup&(10)=9 :fonttyp%=9 :zoom%=0
cur&=Early&:(Now&:) :off&=cur&-lines%*sad& :gcy%=gcmax% :exists%=0
SetFont:
Repaint:
endif
ENDP
PROC OpenFile:(file$)
local n%,sp%,set$(255),v$(10),sep$(1)
trap open file$,A,meet&,leave&,normal&,total&,comment$
if err
setname "-none-"
ShowErr:("Cannot open '"+file$+"'")
x26f: Rem As if user pressed Psion-O again to open file
return
endif
setname file$
Rem
Rem Comment string from first entry holds
Rem all the setup values.
Rem Extract and save as setup&(1-10)
Rem
set$=a.comment$
Rem Decide on what seperator was used
Rem for packing the setup values.
if loc(set$,chr$(13))
sep$=chr$(13) Rem NEW setup
else
sep$=" " Rem OLD setup
endif
n%=1 :sp%=loc(set$,sep$)
while sp%>0 and n%<=10
setup&(n%)=val(left$(set$,sp%-1))
if sp%>=len(set$) :break :endif
set$=right$(set$,len(set$)-sp%)
n%=n%+1 :sp%=loc(set$,sep$)
endwh
if sp% :prolist$=left$(set$,sp%-1) :endif
Rem reset if bad font value (happens when readng old format)
if setup&(10)<5 or setup&(10)>12
setup&(10)=9
SaveSet: Rem update change
endif
fonttyp%=int(setup&(10)/4)*4+1
zoom% =setup&(10)-fonttyp%
SetFont:
first :cur&=0 :MovTo:(datetosecs(year,month,day,23,59,59),1)
ENDP
PROC ShowErr:(txt$)
dinit
dtext "",txt$,$400
dtext "",err$(err),$600
dtext ""," "
dbuttons "Exit program",%x,"Continue",-13
lock on
if dialog=%x :stop :endif
lock off
ENDP
PROC Repaint:
ggrey 2 :gcls
Paint:(off&,lines%)
Cursor:
ENDP
PROC Cursor:
gat 1,gcy%+4 :gfill 300,h%,2
ENDP
PROC Paint:(from&,l%)
local y%,dy%,lin%
local yr%,mo%,da%,ho%,m%,s%,yrd%,wd%
local oldcur&,oldpos%,oldex%,oldcurd&
oldpos%=pos :oldcur&=cur& :oldex%=exists%
gborder $203
MovTo:(off&,0)
y%=MovCnt%:(from&,0)*h%
dy% = h%*l%
ggrey 1
gat 90,y%+4 :glineby 0,dy%
gat 190,y%+4 :glineby 0,dy%
gat 240,y%+4 :glineby 0,dy%
gat 300,y%+4 :glineby 0,dy%
lin%=l%
while (lin%>0)
secstodate cur&,yr%,mo%,da%,ho%,m%,s%,yrd%
wd% = dow(da%,mo%,yr%)
ggrey 1 :gat 1,y%+4
if wd%=6 or wd%=7
gfill 300,h%,0
else
glineby 300,0
endif
ggrey 0
gat 7,y%+3
gmove 0,h% :gprintb dayname$(wd%),30
gmove 30,0 :gprintb num$(da%,2),16,1
gmove 20,0 :gprintb month$(mo%),30
if exists%
gmove 35,0 :gprintb Time$:(cur&,0,0),40,1
gmove 40,0 :gprintb "-",10
if a.leave&
gmove 5,0 :gprintb Time$:(a.leave&,0,0),40,1
gmove 50,0 :gprintb Time$:(a.leave&-cur&-a.normal&,1,0),45,1
gmove 50,0 :gprintb Time$:(a.total&,1,0),55,1
gmove 70,0
else
gmove 175,0
endif
gprintb a.comment$,99
endif
MovRel:(1,0)
y% = y%+h% :lin%=lin%-1
endwh
ggrey 1 :gat 1,y%+4 :glineby 300,0 :ggrey 0
position oldpos% :cur&=oldcur& :exists%=oldex%
ENDP
PROC Time$:(t&,sign%,secs%)
local res$(30),yr%,mo%,da%,ho%,mi%,se%,yrd%
secstodate abs(t&),yr%,mo%,da%,ho%,mi%,se%,yrd%
if yr%=1970 :ho%=ho%+(da%-1)*24 :endif
if ho%<10 :res$=res$+" " :endif
if t&<0 :res$=res$+"-"
elseif sign% :res$=res$+"+"
endif
res$=res$+num$(ho%,3)+":"
if mi%<10 :res$=res$+"0" :endif
res$=res$+num$(mi%,2)
if secs%
res$=res$+":"
if se%<10 :res$=res$+"0" :endif
res$=res$+num$(se%,2)
endif
return res$
ENDP
PROC RecED:
local m&,l&,n&,c$(20),morn&,even&
local yr%,mo%,dy%,hr%,mn%,sc%,yd%,wd%
local ret%,new$(13)
morn& = Early&:(cur&)
secstodate cur&,yr%,mo%,dy%,hr%,mn%,sc%,yd%
wd%=dow(dy%,mo%,yr%)
Rem See if an entry already exists
if exists%
m&=cur&-morn&
l&=a.leave&
if l& :l&=l&-morn& :endif
n&=a.normal&
c$=a.comment$
new$=""
else
Rem Fill in Defaults
m&=8*60*60
n&=setup&(wd%)
l&=m&+n&
new$=" (new entry)"
endif
Rem Display edit dialog
dinit dayname$(wd%)+" "+num$(dy%,2)+" "+month$(mo%)+" "+num$(yr%,4)+new$
dtime m&,"Meet",1,0,maxday&
dtime l&,"Leave",1,0,maxday&
dtext "Worktime",Time$:(l&-m&,0,1),0
dtime n&,"Normal time",0,0,maxday&
dtext "Todays diff",Time$:(l&-m&-n&,1,1),0
dtext "Total diff",Time$:(a.total&,1,1),0
dedit c$,"Comment",20
lock on :ret% = dialog :lock off
if ret%
a.meet&=m&+morn&
if l& :l&=l&+morn& :if m&>l& :l&=l&+sad& :endif :endif
a.leave&=l&
a.normal&=n&
a.comment$=c$
if exists% :update :else :append :endif
Reorder:
PaintCur:
endif
ENDP
PROC TextED:
local c$(20), ret%
if exists%
c$=a.comment$+chr$(a%(1))
else
a.meet&=cur&+28800 Rem current day at 08:00 => cur& + 8*60*60
a.normal&=0
a.leave&=0
c$=chr$(a%(1))
endif
dinit "Comment"
dedit c$,"",20
REM - So how do I position the cursor
REM to the end of the 'dedit' string ?
REM If you have an idea please tell me...
lock on :ret% = dialog :lock off
if ret%
a.comment$=c$
if exists% :update :else :append :endif
Reorder:
PaintCur:
endif
ENDP
PROC SaveFile:
trap close
if err<>0 and err<>-102
ShowErr:("Error closing file")
endif
ENDP
PROC PaintCur:
Cursor:
paint:(cur&,1)
Cursor:
ENDP
Rem current entry is always the one
Rem just less than or eual to cur&
Rem exists% tells if tec really exists
PROC MovCurs:(d%)
local rd%
if abs(d%)>lines%
if d%>0
off&=Offset&:(cur&,1-lines%) :gcy%=gcmax%
else
off&=cur& :gcy%=0
endif
Repaint:
return
endif
Cursor:
gcy%=gcy%+d%*h%
if gcy%<0 rem Move UP (scrolls down)
rd% = gcy%/h%
off&=cur&
ggrey 2 :gscroll 0,-rd%*h%,1,4,410,gcmax% :ggrey 0
paint:(off&,-rd%)
gcy% = 0
elseif gcy%>gcmax% rem Move DOWN (scrolls up)
rd% = (gcy%-gcmax%)/h%
off& = Offset&:(off&,rd%)
ggrey 2 :gscroll 0,-rd%*h%,1,4+h%,410,gcmax% :ggrey 0
paint:(Offset&:(o