RISC USER DESKTOP DIARY

Missing the diary feature from the Arthur Desktop? Mike Ironmonger goes one better with a fully multi-tasking version for use under RISC OS.

This article, with part two to follow next month, describes a useful diary facility to add to your RISC OS Desktop. The program runs from an application directory, and uses all the standard Desktop features. When installed, the diary icon appears on the menu bar. Clicking on this icon opens the diary window to display a calendar for a single month. Two arrows at the top allow you to move through the months in steps of a month (using Select), or a year (use Adjust).

Whenever the current date is on display, this is highlighted by a black border, while any date for which an entry exists is highlighted with a grey background. Clicking the Menu button on the diary window opens up a menu with the following options:

Go to the current date
Save all entries
Print entries for the currently displayed month
Print entries for the currently displayed year
Print all entries

As with all Wimp menus, choosing an item from the menu with the Adjust button (rather than with Select) will leave the menu in place.

Clicking on a date with an entry opens a window showing that entry, which can then be edited. Clicking on a date with no entry highlights the date and opens an empty window ready for some new text. The entry window allows four lines of 40 characters, with the name of the day and the date forming the window title. Up to 10 such windows may be open at any one time, for cross referencing entries for different dates.

When editing an entry, the standard text caret is shown and this may be moved up, down, left or right with the cursor keys. Home takes you to the start of the first line while Return takes you to the start of the next line, unless you are already on the last line. The mouse pointer can also be used to position the text caret in the window. Text is entered from the keyboard as required, and Delete works as expected. Pressing the Menu button over an entry window displays a menu allowing you to clear all text (in the window), delete the entry completely (including the window), or print the entry.

All entries are saved to a single file for subsequent reloading, though you can create as many separate diary files as you wish. Saving and loading follows RISC OS standards. To load a diary file, double click on its icon, or drag it onto the Diary icon on the menu bar (once installed). If a file is loaded which has an entry for the current date then a window will automatically be opened showing that entry. However, dragging a diary file into the calendar window or an entry window, will merge the entries in that file with those already loaded and present, overwriting existing entries where necessary.

Diary files use the same file type as the old Arthur Desktop Diary, but the new diary files use a different and much more compact format. As a result, Arthur diary files cannot be loaded directly into the new diary application, but a conversion program, called Converter, is included on the magazine disc to perform just this task. When run, it asks for the name and year of the existing file, and a new name for the diary file. The old diary file is then loaded, converted to the new format, and then saved with the new name.

SETTING UP THE APPLICATION

You will need to create a directory called !Diary (just click on the drive icon, and then press Menu over the resulting directory viewer and choose the new directory option from the menu) in which to save four files, !Boot and !Run (both Obey files), !Sprite (the sprite file) and !RunImage (the runnable program itself). Listing 1 is the boot file, and this should be created using Edit (press Menu on its icon on the icon bar and create a new Obey file). Save this as file !Boot in directory !Diary. Similarly, type in Listing 2 to create the Obey file !Run which should also be saved in your !Diary directory.

Listing 1

| !Boot file for Diary program
| by Mike Ironmonger
Set File$Type_FEF Diary
Set Alias$@RunType_FEF Run <Obey$Dir>.!Run %%*0
IconSprites <Obey$Dir>.!Sprites

Listing 2

| !Run file for Diary program
| by Mike Ironmonger
Set File$Type_FEF Diary
Set Alias$@RunType_FEF Run <Obey$Dir>.!Run %%*0
IconSprites <Obey$Dir>.!Sprites
WimpSlot -min 64K -max 64K
Run <Obey$Dir>.!RunImage %*0

Listing 3 is a short program which you will need to run to create the !Sprite file. Before you do this you will need to load the font Trinity from Applications disc 1 (Apps1). The program SpriteMake creates two sprites (using the letter 'D' from the Trinity font), one to represent the Diary program (in a directory viewer and on the icon bar), and a second for diary files. Unfortunately, there is no simple way in a magazine to create more complex sprites, but the magazine disc contains a !Sprite file with more elaborate icons. If you are typing in the program yourself, you may wish to use ArcPaint to create more detailed sprites of your own design. These should be called !Diary and file_fef, and designed in mode 12 with the Desktop palette to a size of 34 by 17 graphics units. The !Sprite file on the magazine disc also contains equivalent small icons called sm!diary and sm_fef.

Listing 3

10 REM > SpriteMake
20 MODE12:GCOL 129:CLG
30 SYS "Font_FindFont",,"Trinity.Medium",30*16,30*16 TO A%
40 SYS "Font_FindFont",,"Trinity.Medium",24*16,24*16 TO B%
50 SYS "Font_SetFontColours",A%,1,2,5
60 SYS "Font_Paint",,"D",16,12,8
70 MOVE 0,0:MOVE 66,64:*SGET !diary
80 GCOL128:CLG
90 SYS "Font_SetFontColours",B%,0,1,6
100 SYS "Font_Paint",,"D",16,14,16
110 GCOL7
120 LINE 0,0,66,0:DRAW 66,64
130 DRAW 0,64:DRAW 0,0
140 MOVE 0,0:MOVE 66,64:*SGET file_fef
150 *SSAVE !Sprites

The last listing is part one of the program proper, which should be typed in and saved in the !Diary directory with the name !RunImage. I suggest you also save a separate copy of this program under the name Split1 to which part two can be appended next month. This month's program implements the calendar only, without the facility for making text entries. The additional code to provide these features will be added next month. Once all four files have been saved in the directory !Diary, double clicking on the !Diary icon from the Desktop will install the diary program as an application with its icon on the menu bar. Clicking on the menu bar icon will run the diary application as described above.

Line 90 in the program is designed to assist in trapping any errors that may arise as a result of mis-typing the program listing. Once you are confident that all is working as it should be, change this line to read:
90 ON ERROR PROCerror(ERR,REPORT$)

Next month, in addition to the remaining code which adds the text entry and printing facilities, we will be providing some information about the workings of the Diary program itself.

Listing 4

10 REM >$.Split1
20 REM Program Desktop Diary
30 REM Version A 2.51
40 REM Author Mike Ironmonger
50 REM RISC User September 1989
60 REM Program Subject To Copyright
70 :
80 PROCinitialise
90 ON ERROR VDU4:PRINT REPORT$;" at line ";ERL:END
100 :
110 REPEAT
120 SYS "Wimp_Poll",51,block% TO A%
130 CASE A% OF
140 WHEN 2 : SYS "Wimp_OpenWindow",,block%
150 WHEN 3 : PROCclose_window(!block%,FALSE)
160 WHEN 6 : PROCbutton_click(block%!
8,block%!12,block%!16)
190 WHEN 9 : PROCmenu_select(!block%,block%!4)
200 WHEN 17,18 : PROCreceive(block%!1
6)
210 ENDCASE
220 UNTIL quit%
230 SYS "Wimp_CloseDown"
240 END
250 :
260 DEFPROCclose_window(W%,del%)
350 !block%=W%:SYS "Wimp_CloseWindow",,block%
360 ENDPROC
370 :
380 DEFPROCbutton_click(B%,W%,I%)
390 CASE B% OF
400 WHEN 1 : PROCsa_click(12)
410 WHEN 2 : PROCmenu_click(W%,!block%,block%!4+12)
420 WHEN 4 : PROCsa_click(1)
440 ENDCASE
450 ENDPROC
460 :
700 DEFPROCmenu_select(A%,B%)
710 SYS "Wimp_GetPointerInfo",,block%:stay%=block%!8=1
720 CASE mw% OF
730 WHEN -2 : IF A%=0 quit%=TRUE
740 WHEN w_diary% : CASE A% OF
750 WHEN 0 : PROCnew_month((today%>>
8)-month%)
770 ENDCASE
830 ENDCASE
840 IF stay% PROCmenu_click(mw%,mx%,my%)
850 ENDPROC
860 :
870 DEFPROCreceive(M%)
880 CASE M% OF
890 WHEN 0 : quit%=TRUE
920 ENDCASE
930 ENDPROC
940 :
950 DEFPROCsa_click(inc%)
960 CASE W% OF
970 WHEN -2 : PROCnew_month(0):PROCopen_window(w_diary%)
990 WHEN w_diary% : CASE I% OF
1000 WHEN 0 : PROCnew_month(-inc%)
1010 WHEN 1 : PROCnew_month(inc%)
1030 ENDCASE
1040 ENDCASE
1050 ENDPROC
1060 :
1070 DEFPROCmenu_click(W%,X%,Y%)
1080 mw%=W%:mx%=X%:my%=Y%
1090 CASE W% OF
1100 WHEN -2 : PROCmaster_menu("Diary","Quit,",X%,140)
1110 WHEN w_diary% : PROCmaster_menu("Diary","Goto today,Save notes,Print notes,",X%,Y%)
1130 ENDCASE
1140 ENDPROC
1150 :
1290 DEFPROCnew_month(inc%)
1300 IF month%+inc%<0 ENDPROC
1310 block%!0=w_diary%:FORI%=4TO34:block%!4=I%:SYS "Wimp_DeleteIcon",,block%:NEXT
1320 month%+=inc%
1330 m%=month% MOD 12:y%=month% DIV 12
1340 $month_buff%=month$(m%)+" "+STR$y%
1350 PROCset_icon_state(w_diary%,3,0,0)
1360 X%=8+FNday(y%,m%,1)*64:Y%=-152
1370 FORD%=1TOnum_days%(m%)-(m%=1 AND FNleap_year(y%))
1380 E%=(month%<<8)+D%
1390 B%=FNicon(w_diary%,STR$D%,X%,Y%,44,44,&27003009)
1400 X%+=64:IF X%=456 X%=8:Y%-=48
1410 NEXT
1420 SYS "Wimp_ForceRedraw",w_diary%,8,-392,436,-108
1430 T%=FNtoday:IF T%<>today% today%=T%
1440 IF month%=(today%>>8) PROCset_icon_state(w_diary%,3+today%AND255,4,4)
1450 ENDPROC
1460 :
2240 DEFFNleap_year(Y%)
2250 =(0=Y%MOD4 AND (Y%MOD100<>0 OR Y%MOD400=0))
2260 DEFFNday(Y%,M%,D%)
2270 =(365*Y%+Y%DIV4-Y%DIV100+Y%DIV400+days_so_far%(M%)+(M%<2 AND FNleap_year(Y%))-2+D%)MOD7
2980 DEFPROCset_icon_state(!block%,block%!4,block%!8,block%!12)
2990 SYS "Wimp_SetIconState",,block%
3000 ENDPROC
3010 :
3150 DEFFNtoday
3160 ?block%=1:SYS "OS_Word",14,block%
3170 A%=?block%:Y%=10*(A%>>4)+(A%AND15)
3180 A%=block%?1:M%=22799+Y%*12+10*(A%>>4)+(A%AND15)
3190 A%=block%?2
3200 =(M%<<8)+10*(A%>>4)+(A%AND15)
3210 :
3220 DEFPROCerror(!block%,$(block%+4))
3230 SYS "Wimp_ReportError",block%,1,"Diary"
3240 ENDPROC
3250 :
3260 DEFPROCinitialise
3270 DIM block% 90,menu% 400
3290 DIM month$(11),num_days%(11)
3300 DIM days_so_far%(11),day$(6)
3310 month$()="January","February","March","April","May","June","July","August","September","October","November","December"
3320 num_days%()=31,28,31,30,31,30,31,3
1,30,31,30,31
3330 days_so_far%()=0,31,59,90,120,151,
181,212,243,273,304,334
3340 day$()="Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
3350 :
3360 today%=FNtoday:month%=today%>>8
3370 quit%=FALSE
3380 :
3390 SYS "Wimp_Initialise",200,&4B53415
4,"Diary"
3400 A%=FNind_icon(-1,A%,1,7,"!diary",0,0,58,68,&3102)
3410 w_diary%=FNcreate_window("Diary
",A%,0,130,884,444,400,0,13,19)
3420 A%=FNicon(w_diary%,CHR$136,8,-64,4
4,52,&2700203D)
3430 A%=FNicon(w_diary%,CHR$137,392,-64,44,52,&2700203D)
3440 A%=FNind_icon(w_diary%,A%,-1,28,"Mon Tue Wed Thu Fri Sat Sun",0,-108,450,3
6,&7000101)
3450 A%=FNind_icon(w_diary%,month_buff%,-1,15,"",102,-56,240,36,&7000109)
3460 :
3610 ENDPROC
3620 :
3630 DEFFNcreate_window(title$,RETURN buff%,len%,X%,Y%,W%,H%,bg%,hg%,F%)
3640 $block%=STRING$(88,CHR$0)
3650 !block%=X%:block%!4=Y%-H%
3660 block%!8=X%+W%:block%!12=Y%
3670 block%!28=F%:block%!32=&207
3680 block%?35=bg%:block%!36=&103
3690 block%?38=hg%:block%!44=-H%
3700 block%!48=W%:block%!56=&19
3710 $(block%+72)=title$
3720 IF len%>0 DIM buff% len%:block%!56=&119:block%!72=buff%:block%!76=-1:block%!80=len%
3730 SYS "Wimp_CreateWindow",,block% TO
H%
3740 =H%
3750 :
3760 DEFPROCopen_window(!block%)
3770 SYS "Wimp_GetWindowState",,block%
3780 block%!28=-1:SYS "Wimp_OpenWindow",,block%
3790 ENDPROC
3800 :
3810 DEFFNicon(!block%,text$,L%,B%,W%,H%,block%!20)
3820 block%!4=L%:block%!8=B%
3830 block%!12=L%+W%:block%!16=B%+H%
3840 IF text$<>"" $(block%+24)=text$
3850 SYS "Wimp_CreateIcon",,block% TO I%
3860 =I%
3870 :
3880 DEFFNind_icon(window%,RETURN buff%,block%!28,len%,text$,L%,B%,W%,H%,F%)
3890 IF buff%<&8000 DIM buff% len%
3900 block%!24=buff%:block%!32=len%
3910 IF text$<>"" $buff%=text$
3920 =FNicon(window%,"",L%,B%,W%,H%,F%)
3930 :
3940 DEFPROCmaster_menu(title$,m$,X%,Y%)
3950 PROCcreate_menu(menu%,title$,m$)
3960 SYS "Wimp_CreateMenu",,menu%,X%-menu%!16/2,Y%
3970 ENDPROC
3980 :
3990 DEFPROCcreate_menu(M%,title$,m$)
4000 LOCAL I%,max%
4010 $M%=title$:M%!12=&70207
4020 M%!20=44:M%!24=0
4030 I%=M%+28:max%=LEN(title$)-2
4040 REPEAT
4050 A%=INSTR(m$,","):IF A%>max% max%=A%
4060 !I%=0:I%!4=0
4070 $(I%+12)=LEFT$(m$,A%-1)
4080 m$=MID$(m$,A%+1)
4140 I%!8=&7000021:I%+=24
4150 UNTIL m$=""
4160 I%!-24=&80:M%!16=max%*16
4170 ENDPROC