home *** CD-ROM | disk | FTP | other *** search
- WIMP programming: a crash course.
-
- If you already know how to program the WIMP, you may skip this bit, as
- double-clicking on !LibStore should tell you all you need. However,
- for a newcomer all this business of icons creation and menus can be
- very confusing.
-
- Newcomers:
-
- 1. Get a template editor. This doesn't have to be the famous !FormEd,
- which I gave up ages ago. !Glazier is very good, but the public domain
- version is very buggy. The best I have come across is !TemplEd, which
- is PD and can be obtained from various PD libraries.
- 2. You need to be reasonably good at programming BASIC!
- 3. A good editor is recommended. It is not advisable to run from outside
- the desktop, so it must be multitasking. !Edit (RO3) just passes, but
- !Zap v1.00+ is probably the best freeware one (v0.90 has got a major
- bug which causes it to seize up).
- 4. Some form of debugging tool that lets you kill a program when
- it gets in a loop is also recommended. I use 'BugBuster' from RISC User,
- and I know of no others, but I might write my own someday...
- 5. Get RISC OS 3. Most people already have it, but if you don't...
- a) all programs I use work on it (and I have one or two golden
- oldies.
- b) despite rumours to the contrary, most old hard discs and filing
- systems work without upgrading, although upgrading is recommended.
- c) It is wonderful compared to RO2. Having the applics in ROM is
- really convienient.
- d) It looks really good when you run !Newerlook (PD from doggysoft)
- and almost manages to impress PC users (who are jealous because
- they're stuck with MS Windows which is slow, buggy and ugly).
- 6. To really understand what's going on, get a book on the WIMP.
-
- Starting out
-
- If you have attempted at writing your own WIMP proggies before you
- will appreciate that reams and reams of code are needed simply to
- get a simple program that bleeps every so often, and there is the
- problem of the fact that if you get a value wrong, very strange things
- can happen (light pink windows in 256 colour modes for example). However,
- you need not worry any more! The libraries here are provided to take all
- the work and hassle out of writing a multi-tasking program.
-
- Loading libraries
-
- To load one of these wonderful, all singing, all dancing libraries, you
- need to include a line of the form:
- LIBRARY "SystemLib:<Libtype>.<Libname>"
- <Libtype> is the type of library. At the time of writing, there is just
- 'WIMP' and 'Sprites'.
-
- A first program
-
- Well, it's time to marvel at a bleeping desktop... this program simply
- bleeps every second and is quit via the task manager.
-
- REM >!Runimage (Wimp Library Demo 1) }
- REM by Andrew Hunter } --- standard waffle - what it's for,
- REM for 32-bit machines } etc.
- : --- useful to break up program.
- LIBRARY "SystemLib:WimpLib.Poll" --- load library(s)
- ON ERROR SYS "Wimp_CloseDown":REPORT:PRINT ERL:END - report errors.
- PROCstartup("Wimplib1 (Bleeper)",2) --- Tell the WIMP we want in.
- respond%(0)=TRUE --- we want to be told about NULL events
- PROCpollidle(0,100) --- let the library do the work...
- END --- goodbye!
- :
- DEFPROCrespond_null --- null event occured, so...
- VDU7 --- be wonderful
- ENDPROC --- go back to the library.
-
- It is very simple to understand, and an incredibly short program.
- Things to note:
-
- PROCstartup() - takes two things: the name ("Wimplib1...") that appears
- in the task manager, and the version of RISC OS that
- it is designed to run under. This starts up the WIMP,
- sets up block% (famous among WIMP programmers everywhere)
- and any other arrays/variables needed (such as respond%).
- PROCpollidle - one of two - PROCpoll() and PROCpollidle. Both take a mask,
- which might as well be 0. If you don't need null events,
- set it to one. PROCpollidle takes a time (in centiseconds)
- to place between null events.
- respond%() - tells the library which events to respond to. A full list
- can be found in the instructions for the 'Poll' library.
-
- Application directories
-
- Not all programmers know how to create one of these properly. It's simple
- but tedious, so there are several programs that automate this. I don't
- use them. So...
-
- 1. Create a directory with a name beginning with ! (it won't show the
- ordinary directory icon...)
- 2. SHIFT+ double click on it.
- 3. Create a '!Run' file containing lines like the following (it should
- be of type Obey):
- |
- | !Run file for !myapp
- |
-
- Set myapp$Dir <Obey$Dir> --- so you can shove it anywhere you like.
- Iconsprites <Obey$Dir>.!Sprites --- if you have a !Sprites file
- WimpSlot -min 8192K -max 16384K --- memory requirements (OTT here!)
- <myapp$Dir>.!RunImage
-
- Change myapp to whatever the name of your program.
- 4. Save your program inside as !RunImage.
- 5. Create the sprite for it. Make sure it gives a good idea of what the
- program does. The best sprites can be created with the aid of !ChangeFSI.
- Call the sprite '!myapp' (or whatever the name of the directory is) and
- save it in a file called '!Sprites'.
-
- Templates
-
- Why did I just explain that to you? Well, you will need it for the next
- demo which is...
-
- TEMPLATES!
-
- I could show you the method !WimpLib2 & 3 uses which is to do it manually.
- This is boring and tedious, and lends itself to long programs. Once
- a window is created, the library does all the handling for you.
-
- Two libraries are used here:
- Templates & Windows.
-
- Templates provides facilities for the loading of templates, and windows
- provides facilities for maintaining them.
-
- So, having loaded the two libraries, you have to create a template. Firstly
- you have to design it using a template editor, placing icons, etc where you
- want them. Make sure that the template is redrawn by the WIMP (i.e. is not
- hatched by the template proggy). Then you have to start up the windows
- routine using startup_windows() with the maximum number of windows you want
- to use. Straight afterwards call PROCload_templates() with the name of the
- template file (eg: <myapp$dir>.Templates), and the amount of space to
- reserve for indirected space (4096 is normally plenty). Then create a
- procedure DEFPROCuser_load. This has to tell the template library which
- templates to load. You can place many different types of template load
- routine inside this procedure, but the simplest to use is
- FNcreate_template(). This returns the window handle (as well as storing it in
- an array) and actually creates the window. You may then open the window using
- PROCopenwindow(), giving it the window handle.
-
- The poll library will handle all events associated with the window, so once
- you have opened it, you no longer need to worry about it. If you want to have
- a look at a demo program, a suitably commented one is provided in the !Demos
- application (SHIFT+double click it to find it).
-
- Responding to events
-
- An array, respond%() is set up by PROCstartup(). This allows you to tell the
- library which events your task wants to respond to. The main ones are:
-
- 3 - window closing. The templates demo uses this to detect when you are
- closing its window, so it can quit. If this is set to TRUE, PROCrespond_close
- is called every time the close button is clicked on one of your windows.
- 6 - mouse clicked. This is called when the mouse is clicked over an object
- belonging to your task - an icon or a window usually. PROCrespond_click is
- called.
- 9 - menu clicked. This is called whenever a selection is made off a menu.
- PROCrespond_menu is called.
-
- To activate an event, set respond%(n) to TRUE, where n is the event number.
- You should also set the variable quit% to TRUE when you want your task to
- end.
-
- Windows
-
- You do not need to keep track of all the window handles in your program, as
- the library provides an array that does it all for you. This array is called
- handle%(). handle%(0) contains the first created windows handle, handle%(1)
- contains the second and so on.
-
- Handling clicks
-
- To handle clicks, set respond%(6) to TRUE. Then, every time a click event
- occurs, your DEFPROCrespond_click will be called, with various variables set
- up. The ones you should be interested in are ihandle%, whandle% and button%,
- which contain the window handle and the icon handle of the window and icon
- that was clicked on. The icon handle is the icon number that you gave it in
- the template editor. This stays fixed. The window handle can vary, so I
- recommend using the handle%() array to find it. button% contains the mouse
- button number: 1 for adjust, 2 for menu and 4 for select (yes - it is four).
-
- Icons
-
- You now need the 'Icons' library.
-
- The most important procedures in handling icons are: PROCnewtext()
- PROCnewvalid() FNreadicon() PROCiconbaricon()
-
- PROCnewtext() takes the window handle, icon handle and the text to change
- that icons contents to. The icon MUST be indirected.
-
- PROCnewvalid() takes the window handle, icon handle and the text to change
- that icons validation string to. The icon MUST be indirected.
-
- FNreadicon() takes the window and icon handle and returns its contents in
- text.
-
- PROCiconbaricon() creates an icon on the iconbar. It takes the name of the
- sprite and which side the icon should go on - -1 for the right or -2 for the
- left.
- Note that the demo for this has very few comments, as the functions are
- mostly self-explainitory. To quit this demo, click the right mouse button on
- the iconbar icon.
-
- Filing operations
-
- You now need the 'Messages' library.
-
- I am leaving out the instructions for the menus because even under !Libstore
- they are surprisingly complex. If you want to have a go, there is a demo of
- the menus and the procedures are described in the !Libstore application.
- !Libstore makes the WIMP messaging system very simple. It deals with almost
- all of the messages involved, in the end returning you with a filename you
- can save to.
-
- Firstly, you have to set respond%(17),(18),(19) all to TRUE, and add
- DEFPROCrespond_message, which simply calls PROCstandard_messages. The need
- for this is due the the structure of !LibStore. For saving, you then need to
- add three functions which return appropriate values:
- FNtype : returns the filetype of the file
- FNlen : returns the estimated length (or -1 if you can't be bothered)
- FNname : returns the filename (just the filename, without the pathname before
- it, i.e. 'Jim' not 'ADFS::MyDisc.$.Demos.Libstore.Jim'). A function
- 'FNfilename()', which takes a full pathname, is provided to strip the path
- from the front of the filename.
-
- There are then two procedures you need to add:
- DEFPROCdosave(filename$) - saves the file to 'filename$'.
- DEFPROCdoload(filename$,type%) - loads file 'filename$' which has filetype
- 'type%'. To start the whole process off, PROCdragbox() needs to be called
- with the window handle and icon handle of the sprite icon.
-
- Errors:
-
- The oddest error is 'window definition won't fit'. This is caused when you
- are loading templates and IS NOT MY FAULT. Its cause can be either that you
- have spelt the name wrong (RO gets confused and tries to load a non-existant
- template) or that you have created a HUGE template that just won't fit into
- the memory !LibStore has reserved for it. You could try increasing the 4096
- in PROCload_templates to 8192 or 16384, but if that doesn't work, use lots of
- small windows rather than one large one.
-
- Contacting me:
-
- I can be contacted over Arcade BBS as Ahunter. Please don't
- hesitate to report any bugs, although as I have been using this for over two
- years without fault, I doubt there are any... You can also ask questions,
- tell me how rushed this manual is and generally critisise, but only expect
- replies for the former.
-
- I hope you find this useful and produce many great programs with it.
-
- Disclaimer:
-
- I can take no responsibilty for loss or damage of data resulting from the use
- of this application and the libraries therein. You use this entirely at your
- own risk.
-
- Bye!
-