home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / drwimp / DrWimp / Documents / TextManual < prev    next >
Encoding:
Text File  |  1997-06-01  |  149.1 KB  |  3,880 lines

  1.  
  2.  
  3.  
  4. DRWIMP
  5.  
  6. Cures your desktop problems!
  7.  
  8.  
  9. Version 3.00 (31-May-97)
  10.  
  11. © Andrew Ayre 1995, 1996, 1997
  12. Manual laid out & mostly proof read by Eddie Lord
  13.  
  14. Public Domain (Freeware)
  15.  
  16.  
  17. Andrew Ayre
  18. 24 Skirbeck Rd
  19. Gillshill Rd
  20. Hull
  21. East Yorkshire
  22. HU8 0HR
  23. England
  24.  
  25.  
  26. CONDITIONS OF USE
  27.  
  28. DrWimp is distributed on an “As Is” basis, without warranty. No liability
  29. can be accepted for any consequential loss or damage, however caused,
  30. arising from the use of this program or other utilities supplied. Boring but
  31. there you go.
  32.  
  33. The DrWimp library may be distributed for free and without the
  34. documentation, examples, utilities, etc. if it is being used in a Public
  35. Domain, Shareware, Cover Disc or Disc Magazine program. If you wish to
  36. distribute it with a commercial program then contact the author to negotiate
  37. royalties.
  38.  
  39. Public Domain libraries may make a reasonable charge for materials,
  40. handling, etc. as long as this does not exceed £2.00 (UK) net for this
  41. DrWimp package.
  42.  
  43. The DrWimp library may be reproduced in part if crunching and mangling
  44. utilities such as !BSquasher and !MakeApp are used, otherwise it must be
  45. reproduced in whole, complete with the conditions of use and the copyright
  46. banner.
  47.  
  48. If the DrWimp library is being reproduced in full then it may be added to
  49. the !RunImage (or similar) file, and does not have to be separate.
  50.  
  51. The DrWimp package (apart from the 3rd party utilities as detailed in the
  52. !!ReadMe!! file) may only be distributed as a whole. For conditions of use
  53. of the third party applications see their own !Help files.
  54.  
  55. For distribution conditions of the DrWimp package as a whole and the files
  56. included in it which are not 3rd party, see the !!ReadMe!! file.
  57.  
  58. The author retains copyright of DrWimp, documentation and examples at all
  59. times.
  60.  
  61. Documentation and utilities can be obtained from the web page below or
  62. direct from the author at:
  63. E-mail:A.J.Ayre@e-eng.hull.ac.uk World Wide
  64. Web:http://whirligig.ecs.soton.ac.uk/~aij295/groover
  65.  
  66. Help on any aspect of DrWimp (and the documentation + utils if you include a
  67. DD disc) can be obtained from the author at:
  68.  
  69. Snail mail: Andrew Ayre
  70.             24 Skirbeck Rd,
  71.             Gillshill Rd,
  72.             Hull,
  73.             East Yorkshire
  74.             HU8 0HR
  75.             England
  76. E-mail:     A.J.Ayre@e-eng.hull.ac.uk
  77.  
  78.  
  79. CONTENTS
  80.  
  81. Section 1 - Introduction
  82.   Prologue
  83.   Getting started
  84.   Handles
  85.   Variables & Strings
  86.   System variables
  87.   Security
  88.  
  89. Section 2 - Tutorials
  90.   Notes  
  91.   1. Getting going
  92.   2. Menus
  93.   3. Windows
  94.   4. Window & icon control
  95.   5. Advanced menus
  96.   6. Panes
  97.   7. Save windows
  98.   8. Errors
  99.   9. Message files
  100.   10. Loading data
  101.   11. Interactive help
  102.   12. Sprite areas & Mouse pointers
  103.   13. Redraws, leafnames & versions
  104.   14. Changing sprites
  105.   15. Large menus & rebuilds
  106.   16. Multitasking operations
  107.   17. “Grubby” tasks
  108.   18. Bars
  109.   19. Sliders
  110.   20. Loading & Saving Drawfiles
  111.   21. Rendering Drawfiles & Sprites
  112.   22. Saving time
  113.   23. Validation Strings
  114.   24. Indirection
  115.   25. Text handling
  116.   26. Printing
  117.   27. Bits & bobs
  118.  
  119. Section 3 - Functions
  120.   1. Misc
  121.   2. Polling
  122.   3. User
  123.   4. Windows
  124.   5. Messages
  125.   6. Icons
  126.   7. Menus
  127.   8. Sprites
  128.   9. Drawfiles
  129.   10. Text
  130.   11. Printing
  131.  
  132.  
  133. SECTION 1 INTRODUCTION
  134.  
  135. Prologue
  136. Ever wanted to write high quality multitasking programs? Can’t quite get the
  137. hang of manipulating words, bytes, menu structures and message systems? Have
  138. you looked in despair at the amount of programming needed to get a single
  139. window on the desktop?
  140.  
  141. Forget all your worries and write superb applications with great ease;
  142. Doctor Wimp is here!
  143.  
  144. DrWimp - solves all your multitasking worries!
  145.  
  146. Banish that dodgy polling code to your disc box! Wipe that broken window
  147. redraw program from your hard drive! Drop that tired out menu creator into
  148. your null: device!!
  149.  
  150.   The DrWimp system consists of:
  151.  
  152. • The DrWimp library.
  153. • A template blank application.
  154. • This manual in Impression Publisher and text format.
  155. • Text files with the history, upgrading and security information.
  156. • Example Template files for standard windows.
  157. • !Fabricate for quick blank template application construction.
  158. • Support files for the tutorials.
  159. • !Func’n’Proc quick browser.
  160. • !Linker BASIC library linker.
  161. • Various PD utilities for compression and code security.
  162. • Example applications written using DrWimp, with fully commented code.
  163.  
  164. DrWimp - THE system to use!
  165.  
  166.  
  167. Getting started
  168.  
  169. In this manual all functions (FN) and procedures (PROC) will be referred to
  170. as just functions.
  171.  
  172. The file DrWimp does all the work, and the !RunImage file is where you
  173. control things from.
  174.  
  175. DrWimp is just a collection of functions that you can call from the
  176. !RunImage file. All the functions in DrWimp are in lower case and preceded
  177. by “wimp_”, eg:
  178.  
  179. PROCwimp_dosomethingamazing(curtain$)
  180.  
  181. Some of these functions need help from you, so they call a function that is
  182. in the !RunImage file, where you can easily tailor it to your applications
  183. needs. All these functions are also in lower case, but they are preceded by
  184. “user_”, eg:
  185.  
  186. FNuser_givemesomehelp(tomato$)
  187.  
  188. For a “blank” application which does nothing all the “user_” functions will
  189. be empty, and return default values if they are of the “FN” type. These
  190. functions have to be there otherwise your application might complain that
  191. one of them can’t be found, regardless of whether they do anything or not.
  192.  
  193. From now on functions in the !RunImage file preceded by “user_” will be
  194. referred to as “user functions”, and functions in the DrWimp file preceded
  195. by “wimp_” will be referred to as “wimp functions”.
  196.  
  197. To save you having to type in a standard set of user functions every time
  198. you write an application, there is a template application called “!MyApp”.
  199. Inside !MyApp is a template !RunImage file. This file calls a function that
  200. starts up your application, because you can’t do anything multitasking until
  201. you call it. You will have to change the details of this call to suit your
  202. application.
  203.  
  204. The utility !Fnc’n’Prc (supplied in the “Utils” folder) is a catalogue of
  205. all the user and wimp functions. It details what parameters you have to pass
  206. and what is returned. It is also a demonstration of the DrWimp system, as it
  207. was written using it, and in particular the ability to easily add panes to
  208. windows and saving files.
  209.  
  210. The source code is included, and is fully commented to help you further
  211. understand how to get DrWimp to do what you want.
  212.  
  213. It may seem that most of the functions have far more parameters than is
  214. needed. This is true in that most of the time the parameters will be largely
  215. the same, but having more parameters gives you, the programmer, as much
  216. flexibility as possible.
  217.  
  218. The main difference that multi-tasking programs have over the others, is
  219. that they are not linear. The program doesn’t start at the top and work its
  220. way to the bottom. Instead, multi-tasking programs jump about depending on
  221. whether an icon has been clicked on, or a window dragged, or a menu item
  222. chosen, etc. All your application has to do is respond to these “events”
  223. when they happen.
  224.  
  225.  
  226. Handles
  227.  
  228. DrWimp expects windows to be loaded in from a templates file. Menus are
  229. created from a shorthand in the !RunImage file. Once you have loaded in a
  230. window or created a menu you need some way of getting at the information so
  231. you can put the menu on the screen, or change some of the window attributes,
  232. etc. The way this is done is by handles, and they form a very important part
  233. in programming the wimp.
  234.  
  235. When you load in a window, DrWimp asks the machine to reserve some memory
  236. for it to put all the information about the window into. It does this using
  237. the DIM command, eg:
  238.  
  239. DIM block% 256
  240.  
  241. This will reserve a chunk of memory 256 bytes long, and the first memory
  242. address in that chunk is in block%. This is so you can find it and change
  243. the contents of the chunk of memory.
  244.  
  245. So if you load in a window called “save”, then you might reserve a chunk of
  246. memory called save%, so you can easily see that the memory address save% is
  247. the start of the information about the save window, you loaded in when the
  248. application first started.
  249.  
  250. The handle to the save window is therefore save%.
  251.  
  252. The same is for menus. When you ask DrWimp to create a menu from the
  253. shorthand that you supply, it gets a chunk of memory and fills it with the
  254. information needed for the wimp to create the menu. eg: if you were creating
  255. a menu for the iconbar icon of your application, then you might call the
  256. handle something like barmenu%.
  257.  
  258. In general it is very wise to call the handle something that reminds you of
  259. what it is a handle for. If you load in five windows, then it would be a bit
  260. stupid to call the handles a%, b%, c%, d%, e%!
  261.  
  262. You will find that most wimp and user functions require a handle to a window
  263. or a menu to be passed to them, so you will need to use them a lot.
  264.  
  265. Look at the following piece of code (the functions will be described in more
  266. detail later on):
  267.  
  268. find% = FNwimp_loadwindow(“Templates”,“find”,0)
  269. PROCwimp_openwindow(find%,1,-1)
  270.  
  271. The first line calls a wimp function that loads in a window from a templates
  272. file called “find”, so we can assume that it is a window for entering
  273. something to find. The function returns a handle to the window, which has
  274. been called find%. From now on, whenever we want to do something with the
  275. find window, we use the variable find%. Look at the second line. Here a wimp
  276. function is being called that opens a window. Passed to it is the window
  277. handle, telling it which window to open (and some numbers regarding the
  278. positions to open it at).
  279.  
  280. The handle could have been called anything, eg:
  281.  
  282. coffee% = FNwimp_loadwindow(“Templates”,“find”,0)
  283.  
  284. Or changed later on, eg:
  285.  
  286. find% = FNwimp_loadwindow(“Templates”,“find”,0)
  287. coffee% = find%
  288.  
  289.  
  290. Variables & Strings
  291.  
  292. One of the first lines of the !RunImage file should be something like:
  293.  
  294. LIBRARY “<MyApp$Dir>.DrWimp”
  295.  
  296. This tells the BASIC interpreter that you want to use a library and where it
  297. is. After this call, the two files (DrWimp and !RunImage) may be separate
  298. but they work as if all the code is in one file. Eg: you can call functions
  299. in DrWimp from !RunImage and call functions in !RunImage from DrWimp.
  300.  
  301. More importantly, any variables or strings that are created in one of the
  302. files and isn’t localised, will be available to both files, so either one
  303. can alter the contents. This can cause problems, because you could be using
  304. a variable in the !RunImage file, and then call a wimp function that also
  305. uses it, so when the function is exited, the variable will be different from
  306. what your code expects. This problem has been largely overcome by localising
  307. most of the variables used in DrWimp. However, there are a handful of
  308. variables that cannot be localised for one reason or another.
  309.  
  310. All but two of the variable names start with a lower case “w”, so you can
  311. easily choose variable names that don’t clash: simply don’t start them with
  312. a “w”.
  313.  
  314. The variables whose names start with “w” should not be changed. The other
  315. variables finished% and NULL are supposed to be changed:
  316.  
  317. By setting finished% to TRUE, the application will quit as soon as possible.
  318. This is how the Quit menu option on the iconbar menu works.
  319.  
  320. By setting NULL to TRUE, the user function PROCuser_null will be called
  321. every time the wimp passes control to the application and nothing is
  322. happening with it, eg: clicking on icons, dragging windows, receiving
  323. messages, etc. This is useful for timed or delayed things. You keep track of
  324. the time and after a certain delay you change a windows contents (say for a
  325. clock) or send a message to another application.
  326.  
  327. If you wanted something to happen continuously like animation then that it
  328. how you would do it.
  329.  
  330.  
  331. System variables
  332.  
  333. It is important that you make sure that your application can run from
  334. anywhere, eg: floppy disc, hard drive, CD, etc, but you have to access files
  335. in the application directory, eg: templates, sprites, message files, etc.
  336.  
  337. System variables differ from BASIC variables in that System variables are
  338. set from the command line using a star command. Unfortunately it isn’t very
  339. easy to read the contents of a system variable from BASIC programs. Because
  340. of this, DrWimp provides a wimp function (FNwimp_sysvariable) to do this for
  341. you, and it will be described in more detail later.
  342.  
  343. When the !Run file of your application is run it sets up a system variable
  344. called “Obey$Dir” which contains the full pathname to your application
  345. directory. So if you have a file called “Templates” inside your application
  346. directory, then its full pathname can be written as <Obey$Dir>.Templates.
  347.  
  348. But if between your !Run file being run and your application loading in a
  349. file, another !Run file from another application is run, Obey$Dir will
  350. change. So in your !Run file you must make a copy of Obey$Dir that can be
  351. used instead. If your application is called “MyApp” then you would use:
  352.  
  353. Set MyApp$Dir <Obey$Dir>
  354.  
  355. and then you would get to your “Templates” file inside your application
  356. directory by using: <MyApp$Dir>.Templates.
  357.  
  358. System variables can also be used for other things. Eg: if you wrote a
  359. database application then you might have to set the maximum number of
  360. records allowed for the amount of memory that you have allocated. The limit
  361. could be put in the !Run file instead of the !RunImage file so
  362. non-programmers don’t have to go and delve into your code. So you could have
  363. a line in your !Run file like:
  364.  
  365. Set MaxRecords 5000
  366.  
  367. Then in your !RunImage file you could read the value with something like:
  368.  
  369. MaxAllowed% = VAL(FNwimp_sysvariable(“MaxRecords”))
  370.  
  371.  
  372. Security
  373.  
  374. If you are going to distribute a new and brilliant application that you have
  375. slaved over for weeks, then you are going to want some security.
  376.  
  377. There are many ways in which you could give your code more security, and I
  378. have found a method which I think does the job perfectly.
  379.  
  380. As an example the total size for the source code for !Linker (!RunImage +
  381. DrWimp) is 55611 bytes (54.3k). After being compressed and mangled the
  382. resulting (and much more secure) !RunImage is 8732 bytes (8.6k).
  383.  
  384. All the utilities to do this are included with the DrWimp package and the
  385. procedure (as reproduced in the “Security” file) is:
  386.  
  387. 1. Link your RunImage with DrWimp using !Linker. Store your original
  388. RunImage somewhere safe.
  389.  
  390. 2. Compress your RunImage using !BSquasher.
  391.  
  392. 3. Turn the BASIC RunImage into an absolute file by dropping it onto
  393. !MakeApp2 and saving under a different name.
  394.  
  395. 3. Compress the RunImage by dropping it onto !Crunch, to give you your final
  396. RunImage to distribute.
  397.  
  398.  
  399. SECTION 2 TUTORIALS
  400.  
  401. Notes
  402.  
  403. I would highly recommend using !TemplEd for editing/creating template files.
  404. It is very easy to use and it is included with DrWimp. Full instructions can
  405. be found in Manual inside the !TemplEd directory. However you can use any
  406. template editor you wish.
  407.  
  408. The tutorials use some support files and pre-made templates files. They can
  409. be found inside the Tutorial directory. The template files contain standard
  410. windows like Info and Save windows. Feel free to use these in your programs
  411. (PD or commercial). There are no conditions attached to them.
  412.  
  413. Before you start, make a copy of the “blank” application !MyApp to work on.
  414. Put it on a fresh disc or in a new directory.
  415.  
  416. If you get stuck or come across a problem then please, don’t hesitate to get
  417. in touch. Your information could benefit other users.
  418.  
  419. Most learning is done through experimentation. In most of the tutorials, you
  420. will be invited to fiddle and generally muck about with the code. The worst
  421. that can happen through doing this is your application crashes and is
  422. quitted by the Task Manager.
  423.  
  424. To help you to understand further how to use DrWimp, some applications are
  425. supplied with the DrWimp system. They have fully commented !RunImage files
  426. so you can study them.
  427.  
  428. A short list of what each demonstrates is given in the “!!ReadMe!!” file.
  429.  
  430.  
  431. 1. Getting going
  432.  
  433. Double-click on !MyApp. Nothing should happen. If you now open the task
  434. manager display and look at the list of tasks, you should see “MyApp” at the
  435. bottom.
  436.  
  437. Load !RunImage into !Edit and take a look at how it works. The !Run file
  438. copies the system variable Obey$Dir into MyApp$Dir. The LIBRARY command can
  439. then be used with the system variable.
  440.  
  441. The application name is put into a string to make it easier to change later
  442. on. The next line is in case of an error. All it does is call
  443. PROCwimp_error. This wimp function will be looked at in more detail later
  444. on.
  445.  
  446. The next line is very important and your application can’t do anything until
  447. it has been called. It registers your application with the task manager and
  448. it returns a handle for your task. This has been put into task%.
  449.  
  450. task%=FNwimp_initialise(appname$,7000,7000,300)
  451.  
  452. For the moment the second and third parameters are just set to largish
  453. values. When the application is finished you can reduce them to as low as
  454. possible with the application still working fully. Basically they are (from
  455. left to right) sizes of areas to reserve for window definitions (including
  456. all the icons in the window), and the indirected text (like large menu
  457. entries and long window titles). The first parameter is the text that
  458. appears in the task manager window, and can be anything. Try it and see! 
  459.  
  460. • Note: the wimp automatically truncates it if it is too long. The last
  461. parameter is the minimum version number of RISC OS that the application is
  462. allowed to run on multiplied by 100. The default is 300, so !MyApp will run
  463. on RISC OS 3.00 or better.
  464. • Note: the version number returned by the WIMP to DrWimp isn’t always very
  465. accurate. For example, if you want to set the minimum version to RISC OS
  466. 3.11, then set the last parameter to 316! This is not the fault of DrWimp.
  467. • Note: don't add any lines before the FNwimp_initialise line, as this could
  468. cause problems with the error handling.
  469.  
  470. The final line calls PROCwimp_poll which makes it multitasking. This is a
  471. continuous loop until your application quits for some reason, such as “Quit”
  472. being chosen from the iconbar menu.
  473.  
  474. The rest of the !RunImage file is all the user functions. They are all empty
  475. at the moment and do nothing or return default values.
  476.  
  477. It doesn’t do much at the moment and there is nowhere for the user to get
  478. access to our application. The best thing to do is add an icon to the
  479. iconbar.
  480.  
  481. After FNwimp_initialise, add the following line:
  482.  
  483. bar%=FNwimp_iconbar(“!myapp”,“”,1)
  484.  
  485. The function returns a handle to the window that contains the icon and where
  486. “!myapp” is the name of the sprite to use for the icon.
  487.  
  488. Try changing it to “!draw” and see what happens. The next parameter is the
  489. text to place under the icon (like the floppy drive icon). If it is an empty
  490. string then no text is printed. Try entering some text and reload the
  491. application. The final parameter controls the side of the iconbar that the
  492. icon appears on. 0 for left and 1 for right.
  493.  
  494.  
  495. 2. Menus
  496.  
  497. What is needed now is a menu for the iconbar. Menus are created by DrWimp
  498. from a shorthand form which is passed as a string. DrWimp translates it into
  499. the correct layout in a block of memory for the wimp to understand. After
  500. the FNwimp_iconbar, add the following line:
  501.  
  502. barmenu%=FNwimp_createmenu(“MyApp/Info/Quit”,0)
  503.  
  504. This creates a menu and returns a handle for it, which is put into barmenu%.
  505. Each entry or item on the menu is separated by a “/”. The first item is the
  506. menu title, so from the line just added, a menu will be created with the
  507. title “MyApp” and two entries. The top one is “Info” and the bottom one is
  508. “Quit”. The last parameter is the maximum number of items allowed to be
  509. used. It is set to 0, so this means that just allow space for the items
  510. specified.
  511.  
  512. At the moment “MyApp” doesn’t know about the menu, all we have done is set
  513. it up in memory. Whenever the Menu button is pressed over a window belonging
  514. to the application, DrWimp calls the user function FNuser_menu. Passed to it
  515. is the window handle (in window%) and the icon number (in icon%). If there
  516. is a menu for that window/icon then we have to return the handle to it,
  517. otherwise return a 0.
  518.  
  519. Move down to FNuser_menu and change it so it is like:
  520.  
  521. DEF FNuser_menu(window%,icon%)
  522. CASE window% OF
  523. WHEN bar% : =barmenu%
  524. ENDCASE
  525. =0
  526.  
  527. As you can see, whenever the window whose handle is bar% (the window
  528. containing the iconbar icon) has menu pressed over it, the handle to the
  529. iconbar menu is returned. Try running the application.
  530.  
  531. As you will see from running it, Quit doesn’t do anything. When a menu item
  532. is selected, DrWimp calls another user function: PROCuser_menuselection.
  533. This time nothing has to be returned, you only have to act on the selection
  534. made by the user. Passed to the function is the handle of the menu that the
  535. user chose an item from (menu%) and the number of the item (item%). The
  536. top-most item is number 1, so for Quit:
  537.  
  538.   menu% = barmenu% and item% = 2.
  539.  
  540.   Add the following to make PROCuser_menuselection look like:
  541.  
  542. DEF PROCuser_menuselection(menu%,item%)
  543. CASE menu% OF
  544. WHEN barmenu% :
  545.   CASE item% OF
  546.   WHEN 2 : finished%=TRUE
  547.   ENDCASE
  548. ENDCASE
  549. ENDPROC
  550.  
  551. Recall from Section 1, setting finished% to TRUE quits the application as
  552. soon as possible. Run the application and confirm that it does indeed work.
  553.  
  554. Try adding some more items to the menu. Don’t forget to increase the “2” in
  555. PROCwimp_menuselection accordingly though! Try getting the computer to make
  556. a beep when you select one of the items. VDU7 would be ideal for this. Note:
  557. there is no need to change the last parameter to FNwimp_createmenu (that
  558. parameter is explained later).
  559.  
  560. Menus may also be created automatically from message files. See the section
  561. on Messages for details.
  562.  
  563.  
  564. 3. Windows
  565.  
  566. What is needed now is an info window that can be accessed from the iconbar
  567. menu. In the tutorials folder you will find the file “Template1”. Copy this
  568. into the !MyApp application directory and rename as “Templates”. You can
  569. examine it if you want by loading it into !TemplEd.
  570.  
  571. Add the following line below FNwimp_iconbar (above FNwimp_createmenu):
  572.  
  573. info%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“info”,0)
  574.  
  575. This function loads in a window from the templates file, whose full pathname
  576. is given in the first parameter. The second parameter is the name of the
  577. window in the templates file, and the last parameter tells DrWimp where to
  578. get the sprites from for the window. A 0 means use the wimp sprite pool
  579. (RMA), and this is the most common option. A handle to a sprite area instead
  580. would mean use that sprite area (as well as RMA sprites), but there are no
  581. sprites (user or RMA) in this window, only the borders built into RISC OS 3.
  582. so the last parameter is set to 0.
  583.  
  584. The function returns a handle to the window which we have put into info%.
  585. Now we need to modify the iconbar menu to take into account the window. This
  586. is very simple to do and it is mostly done automatically. All you have to do
  587. is add the following line after the FNwimp_createmenu:
  588.  
  589. PROCwimp_attachsubmenu(barmenu%,1,info%)
  590.  
  591. The first parameter is the menu handle to attach the submenu to, the second
  592. parameter is the item on that menu to attach the submenu to (in this case 1
  593. which is the top item), and the third parameter is either a handle to
  594. another menu or a window handle. In this case it is the handle to the info
  595. window.
  596.  
  597. And that’s it! Re-load !MyApp and you will now see that the Info menu item
  598. now has a submenu which leads to the info window.
  599.  
  600. You will see in the info window that the Author and Version fields don’t
  601. have the correct information in them. This is very simple to fix, and the
  602. same technique that I am about to describe can be used for any icon that has
  603. text, whether it is a Radio button, a default action button, or just a
  604. comment (if it is indirected, see !TemplEd).
  605.  
  606. First of all the Author field. This is icon number three. You can find the
  607. icon number by loading the Templates file into !TemplEd, opening the info
  608. window and moving the pointer over the icon. The small window at the top
  609. right will give you the icon number. Add the following line just before
  610. PROCwimp_poll:
  611.  
  612. PROCwimp_puticontext(info%,3,“© Joe Bloggs 1996”)
  613.  
  614. Replace “Joe Bloggs” with your own name (there is a limit on the length of
  615. the string though). This is fixed by the indirected size and the physical
  616. size of the box. These can easily be changed using !TemplEd.
  617.  
  618. Now for the Version field. It is common practice to display the version
  619. number and date in the form “X.XX (Dt-Mth-Yr)”, eg:
  620.  
  621.   1.42 (16-Oct-99)
  622.  
  623. Now add the following line just above PROCwimp_poll (changing the date to
  624. today):
  625.  
  626. PROCwimp_puticontext(info%,4,“1.00 (29-Mar-98)”)
  627.  
  628. The parameters to the function are quite simply. From left to right they
  629. are: the window handle, the icon number, and the text to put into the icon
  630. (in the window).
  631.  
  632. • Note that it is important to get the string length correct or you will
  633. lose the slabbed effect in the info box, and if you are using RISC OS 3.5+
  634. the desktop font may revert back to the system font.
  635.  
  636. Check the application works as it is supposed to and then try using the same
  637. method to change the “Purpose” field to something more interesting!
  638.  
  639.  
  640. 4. Window & icon control
  641.  
  642. Most applications have a window that appears when the user clicks on the
  643. iconbar icon. This is very easy to do:
  644.  
  645. Copy “Template2” from the tutorial folder into the !MyApp application
  646. directory, and rename as “Templates” thus overwriting the previous one. Add
  647. the following line below FNwimp_loadwindow to load in a second window:
  648.  
  649. main%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“main”,0)
  650.  
  651. Whenever a Select or Adjust mouse button is pressed over one of !MyApp’s
  652. windows or icons, the user function PROCuser_mouseclick is called, passing
  653. to it the window handle, the icon number, a number relating to the mouse
  654. button pressed and the work area coordinates the point was at. These are in
  655. window%, icon%, button%, workx% and worky% respectively.
  656.  
  657. If you change the window's work area to a button type of “Click” in a
  658. template editor, then the work area has an icon number of -1. This means
  659. that mouse clicks on the work area where there are no icons will also result
  660. in PROCuser_mouseclick being called.
  661.  
  662. Change PROCuser_mouseclick so it looks like:
  663.  
  664. DEF PROCuser_mouseclick(window%,icon%,button%,workx%,worky%)
  665. CASE window% OF
  666. WHEN bar% : PROCwimp_openwindow(main%,1,-1)
  667. ENDCASE
  668. ENDPROC
  669.  
  670. As you can see, when a mouse button is pressed over the iconbar icon, then
  671. PROCwimp_openwindow is called.  The first parameter is the handle of the
  672. window to open. The second means open the window in the centre of the
  673. screen, and the third parameter means open it on top of all other windows.
  674.  
  675. If the second parameter was 0 then the window would open where you last left
  676. it (ie. before it was closed), or if it was being opened for the first time
  677. then it would open as it was positioned in the templates file.
  678.  
  679. If the second parameter was 2 then the window would open centred on the
  680. mouse pointer. Useful if you want to open save windows below the pointer so
  681. the user doesn't have to move the pointer very much to start dragging the
  682. file icon.
  683.  
  684. If the third parameter was -2 then the window would open behind all the
  685. others. If it was a window handle then it would open behind that window.
  686.  
  687. Run !MyApp and check that it works, then try changing the parameters to
  688. PROCwimp_openwindow and see what happens.
  689.  
  690. The window is divided up into three sections. I will use each section to
  691. demonstrate one or more aspects of icon control using DrWimp. The icon
  692. number for each icon can be found by loading the templates file into
  693. !TemplEd as described before.
  694.  
  695. The first section contains a writable icon which can take up to 19
  696. characters. This amount is set by using !TemplEd and changing the indirected
  697. icon size for the writable icon.
  698.  
  699. Entering text into writable icons is fully automated by the wimp. Click in
  700. the icon and the caret will appear so you can enter some text.
  701.  
  702. What we want to do is enter some text and when Return is pressed, or ‘OK’ is
  703. clicked on (icon number =2), the text is read from the icon and copied into
  704. the text icon below.
  705.  
  706. The wimp function FNwimp_geticontext reads text from icons. ie. it is the
  707. dual of PROCwimp_puticontext. The parameters passed are the window handle
  708. and the icon number. The function returns the text in a string. All that we
  709. need to do then is use PROCwimp_puticontext to put the text into the other
  710. icon.
  711.  
  712. Alter PROCuser_mouseclick so it looks like:
  713.  
  714. DEF PROCuser_mouseclick(window%,icon%,button%,workx%,worky%)
  715. CASE window% OF
  716. WHEN bar% : PROCwimp_openwindow(main%,1,-1)
  717. WHEN main% :
  718.   CASE icon% OF
  719.   WHEN 2 :
  720.   text$=FNwimp_geticontext(main%,1)
  721.   PROCwimp_puticontext(main%,11,text$)
  722.   ENDCASE
  723. ENDCASE
  724. ENDPROC
  725.  
  726. Re-load !MyApp and check that it works. You should be able to see from the
  727. code above that the writable icon is number 1, the text icon is number 11,
  728. and the OK icon is number 2.
  729.  
  730. Note that you can only put text into icons if they are what is called
  731. “indirected”. You can make an icon indirected by turning the option on when
  732. editing the icon in a template editor. The indirected number is the maximum
  733. number of characters you can put plus one (the terminator).
  734.  
  735. So making an icon indirected with a value of 11 is enough for putting a
  736. filename in that icon. Reduce the indirected value to as low as possible to
  737. save on memory. If you have an icon like a label that you are never going to
  738. change the text of then you can make it non-indirected to save memory.
  739.  
  740. If you use a lot of indirected icons then you may run out a allocated
  741. memory. If this happens then increase the value which is the the third
  742. parameter to FNwimp_initialise until you have enough space and the errors
  743. stop.
  744.  
  745. Now we have to get the Return key to perform the same action when it is
  746. pressed and the caret is in the writable icon. Pressing the return key in
  747. this situation should always act the same as clicking on the icon with the
  748. yellow trough/border around it (called the Default Action icon).
  749.  
  750. FNuser_keypress is called whenever a key is pressed. Passed to it is the
  751. window handle and the icon number to locate the caret. Also passed to it is
  752. the ASCII number of the key, which for Return is 13. If we use the keypress
  753. to do something, then we must return a 1. This is to stop the keypress being
  754. passed onto other tasks.
  755.  
  756. Alter FNuser_keypress so it is like:
  757.  
  758. DEF FNuser_keypress(window%,icon%,key)
  759. used=0
  760. CASE window% OF
  761. WHEN main% :
  762.   CASE icon% OF
  763.   WHEN 1 :
  764.     IF key=13 THEN
  765.       text$=FNwimp_geticontext(main%,1)
  766.       PROCwimp_puticontext(main%,11,text$)
  767.       used=1
  768.     ENDIF
  769.   ENDCASE
  770. ENDCASE
  771. =used
  772.  
  773.  
  774. There is a lot of code there for what it actually does, but it has be
  775. written so it is easy to add more pieces of code for lots of windows and
  776. icons, with the minimum amount of effort. Also it allows the code to be
  777. executed to be put onto several lines, making easier to read. Note that the
  778. writable icon is number 1, where the caret is when return is pressed.
  779.  
  780. There is just one thing missing now. When you click on the ‘OK’ icon it
  781. presses in briefly. When you press Return it doesn’t. It is much more
  782. reassuring for the user to see it press in, because then they know exactly
  783. what has happened, and that they haven’t just wiped half their document or
  784. any other unsaved data away.
  785.  
  786. DrWimp provides a wimp function to invert or select an icon, and un-select
  787. it again, so all we have to do is select the ‘OK’ icon, copy the text, then
  788. un-select the ‘OK’ icon.
  789.  
  790. Alter the part between “IF key=13 THEN” and “ENDIF” so it looks like:
  791.  
  792. IF key=13 THEN
  793.   PROCwimp_iconselect(main%,2,1)
  794.   text$=FNwimp_geticontext(main%,1)
  795.   PROCwimp_puticontext(main%,11,text$)
  796.   used=1
  797.   PROCwimp_iconselect(main%,2,0)
  798. ENDIF
  799.  
  800. Re-run !MyApp and check it works. 
  801.  
  802. PROCwimp_iconselect has three parameters (window%,icon%,state%). The first
  803. is the window handle and the second is the icon number. In this case it is 2
  804. for the ‘OK’ icon. The last parameter controls the inversion/selection. If
  805. it is a 1 then the icon is selected, a 0 makes it unselected. If you removed
  806. the second PROCwimp_iconselect then the ‘OK’ button would stay pressed in.
  807. Try it and see! On fast machines the short press in may be too quick and
  808. just produce a flicker. You may like to add the following line just above
  809. PROCwimp_iconselect(main%,2,0):
  810.  
  811. PROCwimp_singlepoll
  812.  
  813. The use of that function is explained in a later section on multitasking
  814. operations but for now you can treat it in this case (and really only in
  815. this case) as a short delay.
  816.  
  817. The second section contains two radio buttons and an button labelled ‘Swap’.
  818. Both the radio buttons have the same ESG group (out of an ESG group, only
  819. one radio button can be selected at once (see !TemplEd documents inside the
  820. application and the example application)), so clicking on one de-selects the
  821. other. i.e. when the user clicks on ‘Swap’ the selected and de-selected
  822. radio icons swap over, as if you had clicked on the de-selected one. The
  823. button has an icon number of 6.
  824.  
  825. If you write an application with radio buttons, you have to keep track of
  826. which ones are selected. For !MyApp we will use choice% which will be either
  827. 1 or 2 depending on which one is selected. When you first load !MyApp we
  828. will have it so Choice 1 is selected, so we will set choice% to 1 at the
  829. start. Although you can select the radio icon when editing the templates it
  830. is always best to do this in your program so there is no chance of it
  831. falling over if a user fiddles with the templates file. When ‘Swap’ is
  832. clicked on, we look at choice% to decide which to select and which to
  833. de-select.
  834.  
  835. Just before PROCwimp_poll, add the following lines:
  836.  
  837. choice%=1
  838. PROCwimp_iconselect(main%,4,1)
  839. PROCwimp_iconselect(main%,5,0)
  840.  
  841. After PROCwimp_puticontext(main%,11,text$) in PROCuser_mouseclick, before
  842. the ENDCASE, add the following:
  843.  
  844. WHEN 6 :          
  845. IF choice%=1 THEN
  846.   PROCwimp_iconselect(main%,4,0)
  847.   PROCwimp_iconselect(main%,5,1)
  848. ENDIF
  849. IF choice%=2 THEN
  850.   PROCwimp_iconselect(main%,4,1)
  851.   PROCwimp_iconselect(main%,5,0)
  852. ENDIF
  853. choice%+=1
  854. IF choice%>2 choice%=1
  855. WHEN 4 :
  856. choice%=1
  857. WHEN 5 :
  858. choice%=2
  859.  
  860. It is mostly self explanatory. “choice%+=1:IF choice%>2 choice%=1” toggles
  861. choice% between 1 and 2 to keep track of which one is selected.
  862.  
  863. There isn’t much point in doing this as it is much easier for the user to
  864. simply click on the radio icons instead, but it is a good demonstration in
  865. selecting and de-selecting radio icons.
  866.  
  867. There is a small problem with radio buttons. Try pressing Adjust over a
  868. selected one. You will find that it becomes un-selected. Having none of the
  869. radio buttons selected may be an undesirable situation. It is quite simple
  870. to solve this.
  871.  
  872. If you have a look at PROCuser_mouseclick you will see that the third
  873. parameter passed to is is called button%. Basically, if button%=4 then
  874. Select was pressed. If button%=1 then Adjust was pressed. There are also
  875. numbers for combinations of mouse buttons, but we need not concern ourselves
  876. with that at the moment.
  877.  
  878. Alter the WHEN 4 and WHEN 5 parts so they look like:
  879.  
  880. WHEN 4 :
  881. IF button%=1 PROCwimp_iconselect(main%,4,1)
  882. choice%=1
  883. WHEN 5 :
  884. IF button%=1 PROCwimp_iconselect(main%,5,1)
  885. choice%=2
  886.  
  887. Re-load !MyApp and make sure that you always have to have a radio icon
  888. selected.
  889.  
  890. • Note: the act of clicking on a radio icon with any mouse button will
  891. automatically deselect the others in the same ESG group, so that’s why we
  892. only set the icon clicked on with Adjust and not deselect the other here.
  893.  
  894. The last section has an option icon and two buttons. What we want to do with
  895. this section is control the option icon using the buttons, in much the same
  896. way as for the radio icons. There is a difference though, in that at any one
  897. time, one of the buttons will have to be disabled; there is not much point
  898. clicking on ‘On’ if it is already turned on.
  899.  
  900. Just before PROCwimp_poll, add the following:
  901.  
  902. option%=0
  903. PROCwimp_icondisable(main%,10)
  904.  
  905. option% records the state of the option icon, so if the application ever
  906. needed to act upon its state, it could just look at option%. The function
  907. disables (greys out) the ‘Off’ button (icon number 10). Its duel
  908. PROCwimp_iconenable enables icons and has the same parameters. In
  909. PROCuser_mouseclick, modify it so it is like:
  910.  
  911. WHEN 5 :
  912. IF button%=1 PROCwimp_iconselect(main%,5,1)
  913. choice%=2
  914. WHEN 9 :
  915. PROCwimp_icondisable(main%,9)
  916. PROCwimp_iconenable(main%,10)
  917. PROCwimp_iconselect(main%,8,1)
  918. option%=1
  919. WHEN 10 :
  920. PROCwimp_iconenable(main%,9)
  921. PROCwimp_icondisable(main%,10)
  922. PROCwimp_iconselect(main%,8,0)
  923. option%=0
  924. WHEN 8 :
  925. IF option%=0 THEN
  926.   PROCwimp_iconenable(main%,10)
  927.   PROCwimp_icondisable(main%,9)
  928. ENDIF
  929. IF option%=1 THEN
  930.   PROCwimp_icondisable(main%,10)
  931.   PROCwimp_iconenable(main%,9)
  932. ENDIF
  933. option%=ABS(1-option%)
  934.  
  935. You should be able to see how it works, and know exactly what will happen
  936. when you click on the icons. Run it and check!
  937.  
  938. Using PROCwimp_icondisable and PROCwimp_iconenable you can grey out and
  939. un-grey out any icon you wish. If the user clicks on a disabled icon, then
  940. the mouse click is ignored, and PROCuser_mouseclick is not called.
  941.  
  942. As you can see, PROCuser_mouseclick is probably one of the most important
  943. functions and will contain most of the code to control your WIMP front end.
  944.  
  945. You must have noticed that as soon as you have some un-saved data in a
  946. program (eg. !Edit, !Draw et al), the title of the window has an asterisk
  947. added to end. Using DrWimp this is quite easy to achieve, once you know that
  948. you have some unsaved data...
  949.  
  950. For !MyApp we will assume that we have some unsaved data when ‘OK’ or Return
  951. is pressed. FNwimp_getwindowtitle returns a string containing the name. 
  952.  
  953. PROCwimp_putwindowtitle changes the title to the supplied string. All we
  954. have to do therefore is read the title, add “ *” to the end and put it back.
  955.  
  956. Change the WHEN 2 : section in PROCuser_mouseclick to:
  957.  
  958. WHEN 2 :
  959. text$=FNwimp_geticontext(main%,1)
  960. PROCwimp_puticontext(main%,11,text$)
  961. r=1
  962. title$=FNwimp_getwindowtitle(main%)
  963. IF RIGHT$(title$,2)=“ *” r=0
  964. IF r=1 PROCwimp_putwindowtitle(main%,title$+“ *”)
  965.  
  966. The title is put into title$, then the end is checked to see if “ *” has
  967. already been added (we don’t want to add “ *” each time ‘OK’ is pressed!).
  968. If it hasn’t then the asterisk is added. You should now be able to alter a
  969. part of FNuser_keypress so the title changes when Return is pressed as well.
  970.  
  971. If your program has a save feature (details on how to do that coming up
  972. later) then when the data has been saved you can remove the asterisk from
  973. the title.
  974.  
  975. • Note: In order to change the window title it must be indirected. This is
  976. set up using a template editor like !TemplEd. The indirected size only needs
  977. to be 1.
  978.  
  979. Just a quick thing for you to try while I am dealing with windows: Quite a
  980. few programs have a window that appears in the centre of the screen when it
  981. loads. It stays there for a bit before closing again. Using banners is a
  982. good way of announcing your program or reminding people to register it.
  983. DrWimp has a function that handles banners for you. While the banner is on
  984. the screen, you can still use the desktop and your application.
  985.  
  986. This is how you use it: Just before PROCwimp_poll enter the following line:
  987.  
  988. PROCwimp_banner(info%,3)
  989.  
  990. When you load !MyApp, the info window will appear for three seconds in the
  991. middle of the screen. The info window isn’t really suitable, so I’ll leave
  992. it to you to design a window, load it in, and put things like version number
  993. and date, etc in using PROCwimp_puticontext.
  994.  
  995.  
  996. 5. Advanced menus
  997.  
  998. So far we have only got a simple two item menu with an info window (windows
  999. off menus are called dialogue boxes). There is a lot more you can do with
  1000. menus. This part looks at submenus, ticks, greying out, dotted lines,
  1001. changing item's text, and writable menu items.
  1002.  
  1003. First of all, lets create a menu for our main window. Just below the
  1004. FNwimp_createmenu line that we have already, add the following lines:
  1005.  
  1006. menu$=“MyApp/Info/Item 2/Item 3/Item 4/Save”
  1007. mainmenu%=FNwimp_createmenu(menu$,0)
  1008. PROCwimp_attachsubmenu(mainmenu%,1,info%)
  1009.  
  1010. And attach the menu to the main window by altering FNuser_menu so it looks
  1011. like:
  1012.  
  1013. DEF FNuser_menu(window%,icon%)
  1014. CASE window% OF
  1015. WHEN bar% : =barmenu%
  1016. WHEN main% : =mainmenu%
  1017. ENDCASE
  1018. =0
  1019.  
  1020. When you press Menu anywhere over the main window, you should get a menu
  1021. with 5 items. The first should have a submenu leading to the info window.
  1022.  
  1023. Now create another menu by adding the following line above the menu$=... you
  1024. have just entered:
  1025.  
  1026. i3menu%=FNwimp_createmenu(“Item 3/Help/Tick me!”,0)
  1027.  
  1028. Now you can see from the title of this menu that it is obviously a submenu
  1029. for Item 3 on our main menu. Here is how to add it: instead of entering a
  1030. window handle to the submenu attaching function, you simply enter a menu
  1031. handle. For example below PROCwimp_attachsubmenu(mainmenu%,1,info%), add:
  1032.  
  1033. PROCwimp_attachsubmenu(mainmenu%,3,i3menu%)
  1034.  
  1035. Run !MyApp and take a look at the menu. And that is all there is to it! Here
  1036. is another example of how easy it is to use:
  1037.  
  1038. Before the i3menu%=... line add the following:
  1039.  
  1040. tickmenu%=FNwimp_createmenu(“Tick me!/Bored/Dull/Waffle”,0)
  1041. And after the i3menu%=... line add:
  1042.  
  1043. PROCwimp_attachsubmenu(i3menu%,2,tickmenu%)
  1044.  
  1045. Hence, you can see that it is quite painless to build up very complex menu
  1046. structures.
  1047.  
  1048. As you have seen before, if you choose a menu item then
  1049. PROCuser_menuselection is called. If you choose the first item from the menu
  1050. tickmenu%, then menu%=tickmenu% and item%=1.
  1051.  
  1052. When you create a menu it has no ticks by the side of any items, no dotted
  1053. lines separating items, and none of the items are greyed out. Any that need
  1054. to be done when the application loads, have to be set up after the menu has
  1055. been created.
  1056.  
  1057. PROCwimp_menutick toggles a tick next to the menu item specified. Add the
  1058. following line to the end of PROCuser_menuselection and try it out:
  1059.  
  1060. IF menu%=tickmenu% AND item%=1 PROCwimp_menutick(menu%,item%)
  1061.  
  1062. PROCwimp_menudisable and PROCwimp_menuenable surprisingly enough enable and
  1063. disable menu items!
  1064.  
  1065. At the end of PROCuser_menuselection, add the following lines and try it
  1066. out:
  1067.  
  1068. IF menu%=mainmenu% AND item%=2 PROCwimp_menudisable(menu%,3)
  1069. IF menu%=mainmenu% AND item%=4 PROCwimp_menuenable(menu%,3)
  1070.  
  1071. PROCwimp_menudottedline(menu%,item%) puts a dotted line on the menu below
  1072. the item specified. Try it out by adding the following after i3menu% is
  1073. created:
  1074.  
  1075. PROCwimp_menudottedline(i3menu%,1)
  1076.  
  1077. There are a few more functions related to menus:
  1078.  
  1079. PROCwimp_menupopup(menu%,bar%,x%,y%)
  1080.  
  1081. This brings up the menu menu% at the co-ordinates x%,y% if bar%=0. If bar%=1
  1082. then the menu is positioned for the iconbar icon. This can be useful for the
  1083. menu icons (the icons that depict a menu and are usually to the right of
  1084. writable icons, offering the user a choice of strings to enter into the
  1085. writable icon). You detect a click with Select or Adjust on the icon, read
  1086. the mouse co-ordinates with MOUSE X,Y,B and bring up the menu. You will need
  1087. to add some offsets to x% and y% so then menu appears to the side.
  1088.  
  1089. The text of a menu item can be read by using FNwimp_getmenutext, passing the
  1090. menu handle and the item number. The dual of this is PROCwimp_putmenutext.
  1091. This allows you to change the text of an item. The text can be up to 78
  1092. characters wide but this would cross the screen, so if you don’t know the
  1093. length of the string then truncate it possibly by using some sort of code
  1094. like LEFT$(....,78).
  1095.  
  1096. Delete the PROCwimp_menudisable and PROCwimp_menuenable lines, and put the
  1097. following lines in the same place:
  1098.  
  1099. IF menu%=mainmenu% AND item%=2 THEN
  1100.   PROCwimp_putmenutext(mainmenu%,3,“ABCDEFGHIJKLMNOPQRS”)
  1101. ENDIF
  1102.  
  1103. Try choosing the second menu item with Adjust. The menu will automatically
  1104. adjust its width to accommodate the longest line.
  1105.  
  1106. The last major menu function turns an item into a writable one. A block of
  1107. memory is reserved to put the text into automatically. After the main menu
  1108. has been defined, add the following line:
  1109.  
  1110. PROCwimp_menuwrite(mainmenu%,4,20)
  1111.  
  1112. The first parameter is the menu handle, the second is the item number. It
  1113. doesn’t matter if some text is already there. The third parameter is the
  1114. maximum length allowed to be entered. To read it simply use
  1115. FNwimp_getmenutext when the item is selected.
  1116.  
  1117. The final handful of menu functions don’t really need much description. For
  1118. more details see !Fnc’n’Prc or section 3 in this manual.
  1119.  
  1120. FNwimp_menusize(menu%)      - Returns the number of items in a menu.
  1121. PROCwimp_menuclose      - Closes any open menu.
  1122. FNwimp_getmenutitle(menu%)    - Returns the title of the menu.
  1123. PROCwimp_putmenutitle(menu%,title$)  - Changes the menu title to title$.
  1124.  
  1125.  
  1126. 6. Panes
  1127.  
  1128. Using DrWimp, it is very easy to attach a pane to a window. From the
  1129. tutorials folder, copy “Template3” into the !MyApp directory and rename as
  1130. “Templates”.
  1131.  
  1132. Where the other windows are loaded in, load in the window “pane”:
  1133.  
  1134. pane%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“pane”,0)
  1135.  
  1136. The pane wants to be attached to the main window.  When the main window is
  1137. dragged about, it is actually being continually re-opened all the time. This
  1138. means that PROCuser_openwindow is also being called continually just before
  1139. the window in question is opened.
  1140.  
  1141. Every time the main window is opened we want to first open the pane in the
  1142. window stack position that is supplied. Then, by telling DrWimp that the
  1143. window has a pane using FNuser_pane, the main window is opened below the
  1144. pane.
  1145.  
  1146. In PROCuser_openwindow, add the following lines:
  1147.  
  1148. IF window%=main% THEN
  1149.   xoff%=x%-FNwimp_getwindowsize(pane%,0)
  1150.   PROCwimp_openwindowat(pane%,xoff%,y%,stack%)
  1151. ENDIF
  1152.  
  1153. The pane also needs to be closed when the main window is, so in
  1154. PROCuser_closewindow add the following line:
  1155.  
  1156. IF window%=main% PROCwimp_closewindow(pane%)
  1157.  
  1158. There is one last thing to do; add the following line to FNuser_pane to tell
  1159. DrWimp that the window has a pane:
  1160.  
  1161. IF window%=main% =pane%
  1162.  
  1163. Re-load !MyApp and check that it is working. And that is all there is to it!
  1164. Just a quick explanation of a few things:
  1165.  
  1166. PROCwimp_openwindowat opens the specified window so the top left corner is
  1167. at the co-ordinates x%,y%. If you want the window to open at the top, then
  1168. stack%=-1, or at the bottom, then stack%=-2. If you want the window to open
  1169. behind a certain one, then stack%=the handle of the window to open behind.
  1170.  
  1171. If you want a window to open with another one but not follow it around, then
  1172. in PROCuser_openwindow, use PROCwimp_openwindow. If you set the second
  1173. parameter to 1 then it will continually re-centre, so it is best to set it
  1174. to 0. Also, just pass stack% straight through.
  1175.  
  1176. Multiple panes are easily achieved. Add the following line to load in a
  1177. second pane:
  1178.  
  1179. pane2%=FNwimp_loadwindow("<MyApp$Dir>.Templates","pane2",0)
  1180.  
  1181. Now, we have to consider more carefully the order of the window stack.
  1182.  
  1183. When you have one pane you look to see where the wimp is going to open the
  1184. window in the stack (stored in stack%), then first open the pane in that
  1185. stack position. DrWimp then sees that the window has a pane so opens the
  1186. window behind the pane. This is what we have done so far.
  1187.  
  1188. With two panes you have to decide which one is going to be top-most, with
  1189. the second pane behind that, followed by DrWimp opening the window behind
  1190. the second pane (this can be extended to as many panes as you like).
  1191.  
  1192. We are going to make DrWimp open the second pane behind the current pane, so
  1193. change the section in PROCuser_openwindow to:
  1194.  
  1195. IF window%=main% THEN
  1196.   xoff%=x%-FNwimp_getwindowsize(pane%,0)
  1197.   PROCwimp_openwindowat(pane%,xoff%,y%,stack%)
  1198.   yoff%=y%-FNwimp_getwindowsize(main%,1)
  1199.   PROCwimp_openwindowat(pane2%,x%,yoff%,pane%)
  1200. ENDIF
  1201.  
  1202. So we have the first pane opening in the stack position, then the second
  1203. pane is opened below the first pane, but in order to get DrWimp to open the
  1204. window below the second pane we have to change FNuser_pane to return the
  1205. handle of the bottom-most pane (the second one):
  1206.  
  1207. IF window%=main% =pane2%
  1208.  
  1209. Change the relevant parts in PROCuser_closewindow so when the main window is
  1210. closed both the panes close and check it all works:
  1211.  
  1212. IF window%=main% THEN
  1213.   PROCwimp_closewindow(pane%)
  1214.   PROCwimp_closewindow(pane2%)
  1215. ENDIF
  1216.  
  1217. • Note that you can attach panes to any window, so you could have a window
  1218. with three panes and another with one, etc, but be careful not to attach
  1219. panes to panes!
  1220.  
  1221.  
  1222. 7. Save windows
  1223.  
  1224. Adding and controlling save windows is very easy. Copy the file “Template4”
  1225. from the Tutorials folder into !MyApp and rename as “Templates”. Load in the
  1226. save window:
  1227.  
  1228. save%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“save”,0)
  1229.  
  1230. and after PROCwimp_attachsubmenu(mainmenu%,3,i3menu%), add:
  1231.  
  1232. PROCwimp_attachsubmenu(mainmenu%,5,save%)
  1233.  
  1234. If you run !MyApp now, the save window will behave like any other window
  1235. that hasn’t got any code to tell it what to do. Everything starts to work
  1236. when you add the following line to FNuser_savefiletype:
  1237.  
  1238. IF window%=save% =“FFF”
  1239.  
  1240. DrWimp now knows that save% is a save window and that it saves text files.
  1241. Don't try it just yet as DrWimp will try to filetype the saved file and it
  1242. is not created, so will throw up an error.
  1243.  
  1244. When the icon is dragged to a destination, FNuser_savedata is called. This
  1245. is where you do the actual saving. path$ is the full pathname of the file
  1246. that you are saving to and window% is the handle of the window that the icon
  1247. was dragged from.
  1248.  
  1249. Don’t always assume that the pathname in path$ will be something like
  1250. “IDEFS::Gromit.$.TextFile”, It could be a system variable that the wimp
  1251. expands to a full pathname later on.
  1252.  
  1253. So, enter the following into FNuser_savedata:
  1254.  
  1255. IF window%=save% THEN
  1256.   file%=OPENOUT(path$)
  1257.   BPUT#file%,“This is a text file,”
  1258.   BPUT#file%,“created by MyApp.”
  1259.   CLOSE#file%
  1260.   PROCwimp_menuclose
  1261. ENDIF
  1262.  
  1263. • Note: the filetyping is taken care of by DrWimp.
  1264.  
  1265. You can now drag the icon to the filer or other applications. The error
  1266. messages “You must drag the icon to a filer window to save...” are taken
  1267. care of by DrWimp.
  1268.  
  1269. It is very easy to add lots more save windows. Simply load them in, add them
  1270. to a menu (or provide some way the user can get to them), return their
  1271. filetype from FNuser_savefiletype, and do the saving in FNuser_savedata!
  1272.  
  1273. FNuser_savedata returns a number. This can be a 1 or a 0. Only return a 1 if
  1274. some data was saved, otherwise return a 0. This allows you to do some
  1275. checking in FNuser_savedata then decide whether to save or not depending on
  1276. the results.
  1277.  
  1278. For example at the start of FNuser_savedata, you could check to see whether
  1279. the file path$ exists. If it does then use FNwimp_errorchoice to allow the
  1280. user to decide whether to overwrite the file or not. If they decide not to
  1281. then return a 0, otherwise save the file and return a 1.
  1282.  
  1283. A rather neat trick that can be performed is to open windows as menus. You
  1284. can see the effect if you add the following to the bottom of
  1285. PROCuser_menuselection:
  1286.  
  1287. IF menu%=mainmenu% AND item%=5 THEN
  1288.   MOUSE X,Y,B
  1289.   PROCwimp_menupopup(save%,0,X,Y)
  1290. ENDIF
  1291.  
  1292. Now select the save item from the save menu. You will see that the save
  1293. window opens and stays open until you complete the save or click elsewhere.
  1294. You can tidy this rough example up so that the window is centred on the
  1295. pointer, etc.
  1296.  
  1297. You may have noticed that some save windows have a rather attractive looking
  1298. border around the file icon. Impression is an example of this, but there is
  1299. a small complication as you will see. Change the line where the save window
  1300. is loaded in to:
  1301.  
  1302. save%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“nicesave”,0)
  1303.  
  1304. so a different template is used for the save window. Now run !MyApp and try
  1305. using the save window now. You will probably get an error and the
  1306. application will quit.
  1307.  
  1308. Loading the templates into TemplEd you will see that the icon to be dragged
  1309. is now icon number 3, where it was 0 in the old save window.
  1310. PROCuser_saveicon is used to tell DrWimp which icon to drag for each save
  1311. window. The default value is 0, so if you are using a modified save window
  1312. like this then you must set a new value. So add the following line to
  1313. PROCuser_saveicon:
  1314.  
  1315. IF window%=save% drag%=3
  1316.  
  1317. Reload the application and check that it works.
  1318.  
  1319. PROCuser_saveicon is strange in that it works rather like a function (FN) in
  1320. that it can return values. But whereas a function (FN) can only return one,
  1321. PROCuser_saveicon can return three by using the RETURN keyword. drag% is the
  1322. first one we have come across, and if you don't want to use the default
  1323. value of 0 for the icon to drag, you can set it to something else. There is
  1324. also write% and ok% which you can set for a save window as well. They are
  1325. the icon numbers of the writeable icon where the filename or pathname goes,
  1326. and the OK button to click on to save to the pathname.
  1327.  
  1328. The default for write% is 1 and for ok% its 2. You can simply set these to
  1329. whatever you have used in your window template to override the defaults. For
  1330. example:
  1331.  
  1332. IF window%=save% drag%=1:write%=0:ok%=8
  1333.  
  1334. or:
  1335.  
  1336. IF window%=mainsave% write%=6:ok%=5
  1337.  
  1338.  
  1339. 8. Errors
  1340.  
  1341. If you get an error or you are trying to debug a program, error windows can
  1342. be very useful. They can tell you information while the program is running.
  1343.  
  1344. Error windows can be altered quite a bit, so there are several parameters
  1345. needed to bring one up. There are two wimp functions for error windows:
  1346.  
  1347. PROCwimp_error(title$,error$,button%,prefix%)
  1348.  
  1349. This one is the most common.
  1350.  
  1351. title$   is the title of the window. This is usually the application name.
  1352. error$   is the error message itself. The text is wordwrapped automatically.
  1353. button%  controls the default button. If it is 1 then you get an ‘OK’
  1354. button. If it is a 2 then you get a ‘CANCEL’ button.
  1355. prefix%   allows you to tailor the title to suit the error message. If
  1356. prefix% is 0 then the title is title$. If it is 1 then the title is prefixed
  1357. with “Error from ”. And if it is 2 then the title is prefixed by “Message
  1358. from ”.
  1359.  
  1360. This is the other function.
  1361.  
  1362. FNwimp_errorchoice(title$,error$,prefix%)
  1363.  
  1364.  The parameters act in exactly the same way as for PROCwimp_error. This
  1365. function displays an error window with an ‘OK’ button and a ‘CANCEL’ button.
  1366. If ‘OK’ is clicked on then the function returns a TRUE (-1). If ‘CANCEL’ is
  1367. clicked on then it returns a FALSE (0).
  1368.  
  1369.  
  1370. 9. Message files
  1371.  
  1372. It is getting increasingly common for applications to have Message files.
  1373. These files have most of the text for the application in, so it can be
  1374. easily translated by someone who doesn’t need to know anything about
  1375. programming.
  1376.  
  1377. Copy the “Messages” file from the tutorial folder into the !MyApp directory.
  1378. Load it into !Edit and have a look at it.
  1379.  
  1380. Comments start with a hash “#”. Lines which have text on to be used in the
  1381. application start with what is called a token. This is just a few letters
  1382. that the line can be identified by. The token and the text are separated by
  1383. a colon. For example:
  1384.  
  1385. LIB:Doctor Wimp
  1386.  
  1387. If we wanted to use the line of text “Doctor Wimp” then we would reference
  1388. it by using the token “LIB”.
  1389.  
  1390. • Note: The message file must be terminated by a Return, otherwise the last
  1391. message in the file will not work.
  1392.  
  1393. Lines of text can also have strings inserted into them when they are read
  1394. into the application. For example:
  1395.  
  1396. VER:1.00 (%0-%1-99)
  1397.  
  1398. When you read in this line, you supply two strings. These could be “29“ and
  1399. “Mar” for example. When the line is read in it ends up as “1.00
  1400. (29-Mar-99)”.
  1401.  
  1402. PROCwimp_initmessages(path$) sets up blocks of memory ready to read in the
  1403. lines of text. path$ is the full pathname to the Messages file.
  1404.  
  1405. Somewhere before the PROCwimp_poll, call the function for the Messages file
  1406. inside the !MyApp directory.
  1407.  
  1408. To read a line without substituting any strings you can use
  1409. FNwimp_messlook0(token$). This returns the line of text.
  1410.  
  1411. To read a line and replace “%0” with a string you can use
  1412. FNwimp_messlook1(token$,a$), where “%0” in the messages file is replaced
  1413. with a$.
  1414.  
  1415. To read and substitute two strings you can use
  1416. FNwimp_messlook2(token$,a$,b$). Add the following lines after
  1417. PROCwimp_initmessages and run your application. When you have checked that
  1418. it works you can delete the lines:
  1419.  
  1420. lib$=FNwimp_messlook0(“LIB”)
  1421. PROCwimp_error(appname$,“LIB=”+lib$,1,2)
  1422. os$=FNwimp_messlook1(“OS”,“3.11”)
  1423. PROCwimp_error(appname$,“OS=”+os$,1,2)
  1424. ver$=FNwimp_messlook2(“VER”,“29”,“Mar”)
  1425. PROCwimp_error(appname$,“VER=”+ver$,1,2)
  1426.  
  1427. It is possible to automatically create menus from a message file. For
  1428. example, say you had the following in a messages file:
  1429.  
  1430. BMenuT:Icnbar menu
  1431. BMenu1:Info
  1432. BMenu2:Quit
  1433.  
  1434. Then using the following, a basic iconbar menu could be created with the
  1435. title “Icnbar menu”, and two items, the first being “Info” and the second
  1436. being “Quit”:
  1437.  
  1438. barmenu%=FNwimp_createmessagesmenu("BMenu","",0)
  1439.  
  1440. The first parameter is the tag, and is used to find the bits of the menu in
  1441. the messages file. tag+“T” is the title, tag+“1” is item one, tag+“2” is
  1442. item 2 and so on. The second parameter is the menu title. In this case its
  1443. an empty string so the one in the messages file is used. If we did:
  1444.  
  1445. barmenu%=FNwimp_createmessagemenu("Bmenu",appname$,0)
  1446.  
  1447. instead, then the menu title would be the string appname$, overriding the
  1448. title in the messages file. In fact if you specify a menu title, then the
  1449. tag in the messages file for the title doesn't have to be included, and you
  1450. can just specify the items. The final paramter is the maximum size of the
  1451. menu, and allows the menu to be dynamic. It is exactly the same as the last
  1452. parameter of FNwimp_createmenu.
  1453.  
  1454.  
  1455. 10. Loading data
  1456.  
  1457. This is very simple to do. Whenever a file (or directory or application) is
  1458. dropped onto a window belonging to your application, then FNuser_loaddata is
  1459. called. This is where you actually load it in to a block of memory or an
  1460. array.
  1461.  
  1462. path$   is the full pathname of the file to be loaded. Don’t always assume
  1463. that it is something like : “IDEFS::Andy.$.TextFile”.
  1464. window% is the window handle.
  1465. icon%   the icon number that the file was dropped on to. Most of the time
  1466. you would only need to check if it was a window or the iconbar icon, but it
  1467. can be used for drop-boxes. These are boxes with text in saying something
  1468. like: “Drop file to load here”.
  1469. ftype$   is the filetype of the file to load. Eg: for text files it is
  1470. “FFF”. Files have a three character hexadecimal filetype, but directories
  1471. are “1000”, and applications are “2000”.
  1472. workx%,worky% is the window window% work area coordinates that the file was
  1473. dropped at.
  1474.  
  1475. If you decide to load in the file after looking at all the parameters, then
  1476. you must load it in and return a 1. This is so DrWimp can send a message to
  1477. the filer or any other application that the file came from, saying that it
  1478. has been loaded.
  1479.  
  1480. Here is an example piece of code for loading in a text file in
  1481. FNuser_loaddata
  1482.  
  1483. DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
  1484. used=0
  1485. IF ftype$=“FFF” THEN
  1486. file%=OPENIN(path$)
  1487. L=1
  1488. REPEAT
  1489. A$(L)=GET$#file%
  1490. L+=1
  1491. UNTIL EOF#file%
  1492. CLOSE#file%
  1493. lines%=L-1
  1494. used=1
  1495. ENDIF
  1496. =used
  1497.  
  1498. What it does is load in a text file into an array called A$ (which you will
  1499. need to create before PROCwimp_poll). At the end, lines%=the number of lines
  1500. read in.
  1501.  
  1502. Try altering !MyApp so it can load in a text file, then using the save box,
  1503. allow the user to save the text file to somewhere else. All you have to do
  1504. is alter the save code so it saves the array.
  1505.  
  1506. Files can also be loaded in with double-clicks on the file. They can be made
  1507. to load in your application first, if it isn't already. The only thing you
  1508. need to add to achieve this is a line like the following in your !Run file:
  1509.  
  1510. Set Alias$@RunType_000 Run <Obey$Dir> %%*0
  1511.  
  1512. Change “000” for the filetype you are using, eg. “FFF” for text files.
  1513. Beware though, when a file is loaded in this way, the parameters window% and
  1514. icon% passed to FNwimp_loaddata are both set to 0.
  1515.  
  1516. You may wish to give your filetype a name. Eg. to give the filetype &000 the
  1517. name “TestFile” put a line like the following in both your !Run file and
  1518. !Boot file:
  1519.  
  1520. Set File$Type_000 TestFile
  1521.  
  1522.  
  1523. 11. Interactive help
  1524.  
  1525. DrWimp supports interactive help applications like Acorn’s !Help. All you
  1526. have to do is return the help string for a given window handle and icon
  1527. number. FNuser_help is where you do this.
  1528.  
  1529. Enter the following lines into FNuser_help, reload !MyApp, load !Help, and
  1530. move the pointer over the info window and the iconbar icon:
  1531.  
  1532. DEF FNuser_help(window%,icon%)
  1533. h$=“”
  1534. CASE window% OF
  1535.   WHEN info% :
  1536.   CASE icon% OF
  1537.     WHEN 1 : h$=“This application is called ‘MyApp’ ”
  1538.     WHEN 2 : h$=“It tests the DrWimp library”
  1539.     WHEN 3 : h$=“MyApp was written by Joe Bloggs”
  1540.     WHEN 4 : h$=“This is the version number and date”
  1541.     OTHERWISE : h$=“This is the MyApp info window.”
  1542.   ENDCASE
  1543.   WHEN bar% : h$=“This is the MyApp icon.”
  1544. ENDCASE
  1545. =h$
  1546.  
  1547. FNuser_help is only for windows and icons, if you want to return interactive
  1548. help for menu items, then use FNuser_menuhelp, eg:
  1549.  
  1550. DEF FNuser_menuhelp(menu%,item%)
  1551. h$=“”
  1552. CASE menu% OF
  1553.   WHEN barmenu% :
  1554.     CASE item% OF
  1555.       WHEN 2 : h$=“Click Select to quit"
  1556.     ENDCASE
  1557. ENDCASE
  1558. =h$
  1559.  
  1560.  
  1561. 12. Sprite areas & Mouse pointers
  1562.  
  1563. Whenever the pointer moves in and out of one of !MyApp’s windows, the
  1564. functions PROCuser_enteringwindow and PROCuser_leavingwindow are called.
  1565. This makes it very easy to change the mouse pointer when it is over one of
  1566. your windows. There is a function to change the pointer for you, but first I
  1567. will look at sprite areas as it is closely related:
  1568.  
  1569. All the sprites in the windows so far are from the wimp sprite pool. An
  1570. application can however, create it’s own private sprite areas that are
  1571. stored in the wimpslot, or memory used by the application. This has the
  1572. advantage that when the application quits, all the memory is regained.
  1573. PROCwimp_loadsprites does all the work for you and must be called before
  1574. loading in any windows that use user sprites. Passed to it is a pathname to
  1575. a sprite file and a handle and the file is loaded in. The sprites in that
  1576. area can then be used in windows (see PROCwimp_loadwindow for parameters,
  1577. but briefly you set the last parameter to the handle for the sprite area),
  1578. or for pointers.
  1579.  
  1580. PROCwimp_pointer controls the mouse pointer. Pointer number two is always
  1581. used for the second user definable pointer.
  1582.  
  1583. Copy the file “Sprites” from the tutorials folder into the !MyApp directory.
  1584. Enter the following lines after FNwimp_initialise:
  1585.  
  1586. size%=FNwimp_measurefile("<MyApp$Dir>.Sprites")
  1587. DIM sprites% size%
  1588. a%=FNwimp_loadsprites(“<MyApp$Dir>.Sprites”,sprites%)
  1589.  
  1590. a% is an arbitary variable not being used. This is explained later. In
  1591. PROCuser_enteringwindow, add the following lines:
  1592.  
  1593. IF window%=main% THEN
  1594.   PROCwimp_pointer(1,sprites%,“ptr_hand”)
  1595. ENDIF
  1596.  
  1597. And in PROCuser_leavingwindow, add the following:
  1598.  
  1599. IF window%=main% THEN
  1600.   PROCwimp_pointer(0,0,“”)
  1601. ENDIF
  1602.  
  1603. Run !MyApp and you should find that when you move the pointer over the main
  1604. window, it turns into a hand. The first parameter tells DrWimp whether to
  1605. use the default pointer, or a user defined one. The second parameter should
  1606. be 0 for the wimp sprite pool, and a handle for a user sprite area. The
  1607. default pointer can be found in the RMA, so it should be a 0 to use it. The
  1608. last parameter is the name of the sprite to use for the user defined
  1609. pointer. If you are using the default pointer, then you don’t need to put
  1610. anything into the string.
  1611.  
  1612. It is a good idea to change the pointer into one looking like a caret when
  1613. it is over a writable icon. In the validation field of the icon enter:
  1614.  
  1615. R7;Pptr_write
  1616.  
  1617. •Note: the sprite used for the pointer is usually defined in mode 8 (lo-res)
  1618. or 19 (hi-res), and should be in the Wimp sprite area.
  1619.  
  1620. You can do similar things with other icons like the menu ones. Impression is
  1621. a good example. See the section on validation strings for more details.
  1622.  
  1623.   The method for loading in a sprite file may seem a bit strange, especially
  1624. the idea of passing the handle of the area to the function, instead of it
  1625. returning it to you. This is the same arrangement as loading in drawfiles,
  1626. and allows one block of memory to hold lots of sprite files, all with their
  1627. own handles.
  1628.   Things might become a little clearer if you look at the following example
  1629. code to load in two sprite files:
  1630.  
  1631. size%=FNwimp_measurefile("<MyApp$Dir>.Sprites1")
  1632. size%+=FNwimp_measurefile("<MyApp$Dir>.Sprites2")
  1633. DIM sprites% size%
  1634. sprites1%=sprites%
  1635. sprites2%=FNwimp_loadsprites(“<MyApp$Dir>.Sprites1”,sprites1%)
  1636. a%=FNwimp_loadsprites("<MyApp$Dir>.Sprites2",sprites2%)
  1637.  
  1638. This first measures both the sprite files whose paths are shown, adding the
  1639. size of the second to the first. Then DIM is used to create a block of
  1640. memory big enough to hold both the sprite files. The handle of the first
  1641. sprite file is assigned to the name of the block. The name of the block can
  1642. now be forgotten.
  1643.   The final two lines load in the sprite files. The last parameter is the
  1644. handle of the sprite file being loaded in, and returned is the handle to the
  1645. next sprite file to be loaded into that block.
  1646.   As after loading in both files the area of memory is full, the handle
  1647. returned by the last call of FNwimp_loadsprites cannot be used for anything,
  1648. so is just put into an arbitary variable and forgotten about.
  1649.  
  1650.  
  1651. 13. Redraws, leafnames & versions
  1652.  
  1653. If you have some user graphics in a window, that can’t be redrawn by the
  1654. wimp, then it will ask you to do the redraw. For example, you could be using
  1655. the CIRCLE command to draw a circle in a window.
  1656.  
  1657. When a redraw is required, PROCuser_redraw is called. The handle of the
  1658. window is passed, and the position of the rectangle. The rectangle is like a
  1659. graphics window, so you can redraw all the window contents if you like
  1660. (although that is a bit slow). Anything outside is clipped.
  1661.  
  1662. Sometimes it can be useful to get a leafname from a pathname.
  1663.  
  1664.   pathname = “IDEFS::Andy.$.Progs.Project1.!Wow.Sprites”
  1665.   leafname = “Sprites”
  1666.  
  1667. DrWimp can do this for you with FNwimp_getleafname(path$). It returns the
  1668. leafname.
  1669.  
  1670. It is very likely that the DrWimp library will have some modifications or
  1671. improvements made to it at some point. I very much hope that they will not
  1672. affect the way any existing wimp or user functions are called, but just in
  1673. case, you can call a function to read the version number of the library. So
  1674. if someone decides to replace the library in your application with a newer
  1675. version, then your program can read the version number and refuse to work
  1676. with it.
  1677.  
  1678. FNwimp_libversion returns the version number x 100. So if it is version 1.43
  1679. then it will return 143.
  1680.  
  1681.  
  1682. 14. Changing sprites
  1683.  
  1684. If you have an icon which is a sprite (like the text file icon in the save
  1685. window) then you can change it to another sprite by using
  1686. PROCwimp_puticontext. This will only work however, if the icon is
  1687. indirected. That is set up using a template editor.
  1688.  
  1689. For example: insert the following line just before PROCwimp_poll:
  1690.  
  1691. PROCwimp_puticontext(save%,0,“file_ffd”)
  1692.  
  1693. Re-load !MyApp and the file icon in the save window will now be a Data one.
  1694.  
  1695.  
  1696. 15. Large menus & rebuilds
  1697.  
  1698. Yes, this section is again concerned with menus. In particular: how to
  1699. create very large menus, how to completely change a menu (ie. a re-build),
  1700. and add and remove items.
  1701.  
  1702. Menus can be created so that they are dynamic. In other words, then can grow
  1703. and shrink in accordance with what your application wants.
  1704.  
  1705. You should recall from the introduction section that when a menu is created
  1706. a block of memory of a fixed size is reserved to put the data that the wimp
  1707. needs in. So for example:
  1708.  
  1709. menu%=FNwimp_createmenu(“MyApp/Info/Quit”,0)
  1710.  
  1711. will reserve a block of memory just big enough to hold the menu with only
  1712. the two items specified.
  1713.  
  1714. But what happens if you want to add another item to the menu. This will
  1715. create three items, so all the data for one item will be pushed into the
  1716. next part of the memory. This could be holding the contents of variables
  1717. that you are using, thus corrupting them, or even more likely you will crash
  1718. the application, because you are trying to write to some memory addresses
  1719. that don’t actually exist (address exception errors are the result of this).
  1720.  
  1721. What is needed is a way of making sure the block of memory is big enough.
  1722. This is where the last parameter to FNwimp_createmenu comes in: If it is
  1723. less than or equal to the number of items specified in the string, then the
  1724. block of memory will be just big enough to hold the items given. If it is
  1725. bigger, then it is the maximum number of items that can be on that menu.
  1726.  
  1727. So if you used:
  1728.  
  1729. menu%=FNwimp_createmenu(“MyApp/Info/Quit”,20)
  1730.  
  1731. then you would create a menu the same as before, but you can have up to 20
  1732. items added to it later on.
  1733.  
  1734. PROCwimp_putmenuitem and PROCwimp_removemenuitem add and remove items from
  1735. menus. Note: no check is made to ensure that the menu is not bigger than the
  1736. block of memory; you will have to make sure that the block is big enough.
  1737.  
  1738. PROCwimp_putmenuitem(menu%,item%,item$)
  1739. PROCwimp_removemenuitem(menu%,item%)
  1740.  
  1741. The parameters are mainly self explanatory. If item% in PROCwimp_putmenuitem
  1742. is greater that the total number of items+1 then it will just be added onto
  1743. the end.
  1744.  
  1745. As items are added or removed, items below are shuffled down and up
  1746. respectively.
  1747.  
  1748. If you wanted to re-build or re-create a menu from scratch again, but still
  1749. have the same handle as the last one, then you could call FNwimp_createmenu,
  1750. which would get another chunk of memory and put the data needed into it.
  1751. This means that the block of memory with the original menu in is still
  1752. occupied and therefore wasted. If you do this repeatedly then more and more
  1753. memory is taken up until your application runs out, crashing it.
  1754.  
  1755. A much better way is to use the wimp function PROCwimp_recreatemenu, which
  1756. updates the data in the block of memory containing the old menu.
  1757.  
  1758. PROCwimp_recreatemenu(menu%,menu$)
  1759.  
  1760. menu% is the handle of the menu to re-create. menu$ is a string to build the
  1761. menu from, and is in the usual form, eg:
  1762.  
  1763. “MyApp/Info/Quit”
  1764.  
  1765. The number of items in the new menu shouldn’t be greater than the specified
  1766. maximum value when FNwimp_createmenu was called. For instance, the following
  1767. would probably crash the application, because not enough memory has been
  1768. allocated for all the items in the larger re-created menu. e.g.:
  1769.  
  1770. menu%=FNwimp_createmenu(“MyApp/Quit”,1)
  1771. PROCwimp_recreatemenu(menu%,“MyApp/Info/Quit”)
  1772.  
  1773. When a menu is re-created, all the item attributes like dotted lines,
  1774. greying out, and ticks are removed. If you want to change one or two menu
  1775. items to reflect something in your application like: “Save selection” or
  1776. “Save” depending in this case on whether anything was selected or not, then
  1777. use PROCwimp_putmenutext instead as the attributes are retained.
  1778.  
  1779. If, by recreating your menu an item is moved up or down, then its item% item
  1780. number which is passed to user function will change accordingly. The top
  1781. item is always number 1.
  1782.  
  1783. Now we come to the last part in this section: FNwimp_createmenu and
  1784. PROCwimp_recreatemenu have a major limitation: very large menus cannot be
  1785. built.
  1786.  
  1787. If you think about it, the maximum length of a line allowed in BASIC is
  1788. something like 255 characters. Now, when you create a menu some of these are
  1789. used up with the function name and other parameters, leaving maybe 210
  1790. characters left for the string that the menu is created from. So what
  1791. happens if you want to create a font menu where the number of fonts could be
  1792. in the hundreds?
  1793.  
  1794. DrWimp provides a very easy solution to this which requires modified
  1795. versions of FNwimp_createmenu and PROCwimp_recreatemenu.
  1796.  
  1797. The solution is to put all the menu items into an array, then build the menu
  1798. from the array. This lends itself very well to reading in items like font
  1799. names, or data from support files for your application.
  1800.  
  1801. First of all you need to decide the maximum number of items in the menu. If
  1802. you are creating a font menu, then you can use the SWI “Font_ListFonts” to
  1803. find out the number of fonts. Anyway, add one onto the total size, and DIM
  1804. an array.
  1805.  
  1806. The first element of an array (number 0) is the menu title. The last item
  1807. must be “END”, so DrWimp knows how much of the array to use. 
  1808.  
  1809. • Note: “END” will not appear as a menu item; the element before it will be
  1810. the last one.
  1811.  
  1812. Here is some example code:
  1813.  
  1814. DIM menu$(20)
  1815. menu$(0)=“MyApp”
  1816. menu$(1)=“Info”
  1817. menu$(2)=“Quit”
  1818. menu$(3)=“END”
  1819. barmenu%=FNwimp_createmenuarray(menu$(),20)
  1820. PROCwimp_attachsubmenu(barmenu%,1,info%)
  1821.  
  1822. FNwimp_createmenuarray is passed the name of the array (with empty brackets)
  1823. and the maximum number of items. The last parameter is exactly the same as
  1824. for FNwimp_createmenu, so it could just as easily be “0”, which means that
  1825. more items can’t safely be added, but it makes more sense to set it as the
  1826. size of the array.
  1827.  
  1828. Menus can be re-built using arrays as well. Instead of using
  1829. PROCwimp_recreatemenu, use:
  1830.  
  1831. PROCwimp_recreatemenuarray(menu%,array$())
  1832.  
  1833. Menus created with a string can be recreated with an array, and vice-versa.
  1834. Note: menus created with arrays can be manipulated using the same functions,
  1835. such as PROCwimp_putmenuitem, PROCwimp_menuwrite, etc. The only difference
  1836. is the way that the data to build the menu initially is stored (string or
  1837. array).
  1838.  
  1839.  
  1840. 16. Multitasking operations
  1841.  
  1842. This section is about multitasking raytracing, calculating numbers, loading
  1843. data, file finding, etc. No, I am not going to show you how to write a
  1844. raytracer, etc. but show you how to make operations like these multitask
  1845. easily.
  1846.  
  1847. At the moment, if you wanted to do a multitasking operation, then you would
  1848. have to set NULL to TRUE so PROCuser_null is called continuously, and every
  1849. time it is called, remember where you were up to and do a small bit. This
  1850. can make very tangled code. The difficulty lies in storing where you got up
  1851. to, and this can require a multitude of variables for just one operation.
  1852.  
  1853. A much easier method is to use PROCwimp_singlepoll. When called, it goes
  1854. through the polling loop once. Your operation will already be in some sort
  1855. of loop, so all you have to do is call PROCwimp_singlepoll inside it! This
  1856. very simple technique makes powerful multitasking operations very easy to
  1857. achieve. Change PROCwimp_menuselection so it has lines like:
  1858.  
  1859. CASE menu% OF
  1860. WHEN barmenu% :
  1861.   CASE item% OF
  1862.   WHEN 1 : PROCchangeauthor
  1863.   ENDCASE
  1864. ENDCASE
  1865.  
  1866. And add the following function at the end of !RunImage:
  1867.  
  1868. DEF PROCchangeauthor
  1869. FOR L=1 TO 200
  1870.   PROCwimp_singlepoll
  1871.   a$=“”
  1872.   FOR M=1 TO 6
  1873.     a$+=CHR$(RND(26)+64)
  1874.   NEXT M
  1875.   PROCwimp_puticontext(info%,3,a$)
  1876. NEXT L
  1877. ENDPROC
  1878.  
  1879. Now run !MyApp and choose the first item on the iconbar menu. If you now
  1880. look at the info window, the author field should be constantly changing with
  1881. random letters. You can still use the desktop, and even quit the
  1882. application.
  1883.  
  1884. Note: PROCwimp_singlepoll acts just like PROCwimp_poll. If one of your icons
  1885. is clicked on, then PROCwimp_mouseclick is still called, and if your
  1886. application received messages, then they are acted on, and so on.
  1887.  
  1888. Also note that there is another function that can be used for polling;
  1889. PROCwimp_pollidle. If you remember, if NULL=TRUE then every time that the
  1890. wimp is polled and no events have occurred, PROCuser_null will be called. If
  1891. you used the following instead:
  1892.  
  1893. PROCwimp_pollidle(30)
  1894.  
  1895. then PROCuser_poll will be called only every 30 seconds. This reduces the
  1896. load on the processor and is best used for things like clocks, etc, where
  1897. you would only need to update the clock once a second or minute.
  1898.  
  1899. Note: if you have put a banner up and then used PROCwimp_pollidle with a
  1900. time longer that the banner period, then the banner will stay up until the
  1901. next PROCuser_null.
  1902.  
  1903. There is also the dual of PROCwimp_pollidle, PROCwimp_singlepollidle, which
  1904. is the same but polls the wimp only once instead of repeatedly.
  1905.  
  1906.  
  1907. 17. “Grubby” tasks
  1908.  
  1909. You will sometimes see tasks that load onto the iconbar, but when the icon
  1910. is clicked on they leave the desktop and monotask. When the user has
  1911. finished, they are returned to the desktop, with the application still
  1912. loaded onto the iconbar. Acorn calls these tasks “Grubby tasks”, and they
  1913. are very simple to implement.
  1914.  
  1915. Alter PROCwimp_mouseclick so it has a line like:
  1916.  
  1917. CASE window% OF
  1918. WHEN bar% :
  1919. PROCwimp_starttask(“BASIC -quit <MyApp$Dir>.Mono”)
  1920. ENDCASE
  1921.  
  1922. Create a BASIC file called “Mono” inside the !MyApp directory containing the
  1923. following:
  1924.  
  1925. MODE12
  1926. PRINT “This is monotasking!”
  1927. A$=GET$
  1928. *DESKTOP
  1929. END
  1930.  
  1931. Re-load !MyApp and click on the iconbar icon. Press a key to return to the
  1932. desktop. Note: change the mode number to one suitable for your monitor.
  1933.  
  1934. You will probably want to mangle up the second BASIC file as well as
  1935. !RunImage with DrWimp to give you more security. This is possible if you
  1936. don’t use DrWimp in the second BASIC file. Mangle it up with !MakeApp2 and
  1937. !Crunch in the usual way, and then change the PROCwimp_starttask to
  1938. something like:
  1939.  
  1940. PROCwimp_starttask(“Run <MyApp$Dir>.Mono”)
  1941.  
  1942.  
  1943. 18. Bars
  1944.  
  1945. When you format a disc a bar increases in size to show the amount of the
  1946. disc that has been formatted so far. When you look at the free space on a
  1947. floppy or hard drive you have several bars to show you how much space has
  1948. been used up, is free, and there is in total. When you open the task display
  1949. you are shown lots of bars that depict the amount of memory something is
  1950. using up.
  1951.  
  1952. Using DrWimp it is simple to control bars like those yourself. They can make
  1953. information look much more attractive than numbers. DrWimp allows the length
  1954. (or height) of the bars to be changed. This means that they can be changed
  1955. all the time, or only just before a window containing them is opened.
  1956.  
  1957. Make a fresh copy of !MyApp. From the Tutorial folder, drag the “Template5”
  1958. file into the !MyApp directory, and rename it as “Templates”. Add the
  1959. following lines at the start of !RunImage, just above PROCwimp_poll:
  1960.  
  1961. main%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“main”,0)
  1962. bar%=FNwimp_iconbar(“!MyApp”,“”,1)
  1963. barmenu%=FNwimp_createmenu(“MyApp/Quit”,0)
  1964.  
  1965. and in PROCuser_mouseclick:
  1966.  
  1967. IF window%=bar% PROCwimp_openwindow(main%,1,-1)
  1968.  
  1969. and in FNuser_menu:
  1970.  
  1971. IF window%=bar% =barmenu%
  1972.  
  1973. and in PROCuser_menuselection:
  1974.  
  1975. IF menu%=barmenu% AND item%=1 finished%=TRUE
  1976.  
  1977. If you now double-click on !MyApp you should get an icon on the iconbar with
  1978. a menu with a ‘Quit’ item. Clicking on the icon should produce a small
  1979. window with a red bar in it. What we are going to do is set the bar to a
  1980. random length when it is clicked on.
  1981.  
  1982. First we need to know what the maximum length is, so load the templates into
  1983. !TemplEd by dropping the file onto !TemplEd’s iconbar icon.
  1984.  
  1985. Open the main window by double-clicking on it in the window at the top left.
  1986. Expand the icon info window at the top right to full size and move the
  1987. pointer over the bar.
  1988.  
  1989. The icon info window gives the dimensions of 340x36, so the max length is
  1990. 340. Of course we could extend the icon to whatever size we want using
  1991. !TemplEd, and then using that length.
  1992.  
  1993. Take a look at all the details of the bar icon by double-clicking on it.
  1994. This is how you should set up any icons you want to use as bars. Obviously
  1995. you can change the colour and turn the border on, etc.
  1996.  
  1997. Returning to !RunImage, add the following line to PROCuser_mouseclick:
  1998.  
  1999. IF window%=main% PROCchangelength
  2000.  
  2001. Now add the following function to the end of !RunImage:
  2002.  
  2003. DEF PROCchangelength
  2004. len=RND(340)
  2005. PROCwimp_bar(main%,1,len,0)
  2006. ENDPROC
  2007.  
  2008. Re-load !MyApp, and click on the bar or frame icon behind it.
  2009.  
  2010. It is quite easy to specify the length as a percentage. Alter
  2011. PROCchangelength to:
  2012.  
  2013. DEF PROCchangelength
  2014. len=RND(100)
  2015. len=(340/100)*len
  2016. PROCwimp_bar(main%,1,len,0)
  2017. ENDPROC
  2018.  
  2019. As you can see, len is a percentage chosen at random.
  2020.  
  2021. And just to finish off, alter PROCchangelength to:
  2022.  
  2023. DEF PROCchangelength
  2024. pcent=0
  2025. REPEAT
  2026.   nlen=(340/100)*pcent
  2027.   PROCwimp_bar(main%,1,nlen,0)
  2028.   PROCwimp_singlepoll
  2029.   pcent+=2
  2030. UNTIL pcent>100
  2031. ENDPROC
  2032.  
  2033. You should be able to see that it is now the basis for a multi-tasking
  2034. operation with the percentage done depicted by the bar. Put the operation
  2035. inside the loop, and each time round the loop calculate the percentage done
  2036. instead of incrementing it as I have done.
  2037.  
  2038. You can change the bar to look like however you want it, but I would advise
  2039. against adding any text, sprites, or indirected text.
  2040.  
  2041. One thing you might like to do is add a border around the bar by clicking on
  2042. the “Border” icon in the relevant !TemplEd window. However, if the bar is
  2043. going to be changing in size rapidly then the part of the border at the
  2044. right edge will flicker a lot as that part of the screen is constantly
  2045. redrawn.
  2046.  
  2047. If you want the bar to be a vertical one, i.e. it resizes vertically instead
  2048. of horizonally, then set the fourth parameter of PROCwimp_bar to 1 instead
  2049. of 0.
  2050.  
  2051. Finally, take a look at !Bar in the Examples folder.
  2052.  
  2053.  
  2054. 19. Sliders
  2055.  
  2056. Sliders can be very useful. You see them probably most in colour selection
  2057. windows, where you can use them to drag amounts of red, green and blue.
  2058.  
  2059. Sliders consist of three icons, and must be constructed in a certain way in
  2060. order to work:
  2061.  
  2062. <see drawfile in Documents folder>
  2063.  
  2064. The slider back icon goes completely under the slider icon, and defines the
  2065. area over which the slider can be dragged.
  2066.  
  2067. The slider and slider back icons must both have a button type of
  2068. “Click/Drag”, be filled and have no borders. They however can be any
  2069. thickness, length or colour you like.
  2070.  
  2071. Look at how the sliders are constructed in the supplied templates file if it
  2072. is still not quite clear.
  2073.  
  2074. Copy the file “Template6” from the Tutorials folder into !MyApp and rename
  2075. to “Templates”. After the line where the main window is loaded in add:
  2076.  
  2077. slide%=FNwimp_loadwindow("<MyApp$Dir>.Templates","slide",0)
  2078.  
  2079. Alter the “window%=bar%” part in PROCuser_mouseclick so that is is like:
  2080.  
  2081. IF window%=bar% PROCwimp_openwindow(slide%,1,-1)
  2082.  
  2083. Run !MyApp and you will see that the slider window that appears has two
  2084. sliders in it. Currently they do nothing.
  2085.  
  2086. Just like FNuser_savefiletype makes save windows work as soon as some value
  2087. is returned for them, sliders work as soon as you return relevant values
  2088. from two user functions.
  2089.  
  2090. FNuser_sliderback must return the icon number of the slider back icon, when
  2091. given the slider icon number. For the top slider (loading the templates into
  2092. !TemplEd will show this), the slider is icon number 2, and the slider back
  2093. icon is icon number 1. So add the following line to FNuser_sliderback:
  2094.  
  2095. IF window%=slide% AND icon%=2 =1
  2096.  
  2097. FNuser_slider must return the icon number of the slider icon, when given the
  2098. slider back icon number. Add the following line to FNuser_slider:
  2099.  
  2100. IF window%=slide% AND icon%=1 =2
  2101.  
  2102. Hopefully that should be clear, and running !MyApp will  now enable you to
  2103. click on the top slider or the slider back to make it jump to various
  2104. positions. You can also drag the slider left and right.
  2105.  
  2106. A slider is no good unless you can get a value for it. When a slider is
  2107. moved or dragged, PROCuser_slidervalue is called, and the percentage of the
  2108. slider concerned is passed. So add the following lines to it:
  2109.  
  2110. IF window%=slide% AND icon%=2 THEN
  2111.   PROCwimp_puticontext(slide%,3,STR$pcent%)
  2112. ENDIF
  2113.  
  2114. STR$pcent% converts the percentage to a string, suitable for passing to
  2115. PROCwimp_puticontext.
  2116.  
  2117. Icon (2) is the slider icon. Run the application now and you will see the
  2118. percentage displayed in the box on the right.
  2119.  
  2120. Add the following line to FNuser_sliderback:
  2121.  
  2122. IF window%=slide% AND icon%=6 =5
  2123.  
  2124. and this line to FNuser_slider:
  2125.  
  2126. IF window%=slide% AND icon%=5 =6
  2127.  
  2128. and finally these lines to PROCuser_slidervalue:
  2129.  
  2130. IF window%=slide% AND icon%=6 THEN
  2131.   PROCwimp_puticontext(slide%,7,STR$pcent%)
  2132. ENDIF
  2133.  
  2134. and the bottom slider should now work, so you can see how lots of sliders in
  2135. lots of windows can be used.
  2136.  
  2137. The percentage can be scaled up or down so different ranges can be used,
  2138. e.g. 0-255.
  2139.  
  2140. The percentage of a slider can be read using FNwimp_getsliderpcent and the
  2141. percentage of a slider can be set using PROCwimp_putsliderpcent. Try these
  2142. out to see their effect. Vertical sliders can also be made. If the slider is
  2143. made higher than it is wide, then DrWimp will automatically assume its a
  2144. vertical slider.
  2145.  
  2146.  
  2147. 20. Loading & Saving Drawfiles
  2148.  
  2149. I am not going to add drawfiles to !MyApp here as the example in the
  2150. Examples folder shows how it is all done without the clutter we have added.
  2151. Instead I will cover some points that are worth mentioning.
  2152.  
  2153. Recall that a handle points to the start of a memory block. Drawfiles are
  2154. all loaded into the same block of memory and so in order to have a handle to
  2155. each one, the handles point to the start of the drawfiles in the block.
  2156.  
  2157. Using one block of memory makes the programming much easier than having to
  2158. cope with lots of blocks, one for each drawfile, but it makes the loading in
  2159. of drawfiles seem a little over complicated.
  2160.  
  2161. However if you follow and extend the methods used here then everything will
  2162. work fine, and you don't really need to understand it all.
  2163.  
  2164. Loading in 3 drawfiles, which are inside !MyApp:
  2165.  
  2166. PROCwimp_initdfiles
  2167. path1$="<MyApp$Dir>.Drawfile1"
  2168. path2$="<MyApp$Dir>.Drawfile2"
  2169. path3$="<MyApp$Dir>.Drawfile3"
  2170. size%=0
  2171. size%+=FNwimp_measurefile(path1$)
  2172. size%+=FNwimp_measurefile(path2$)
  2173. size%+=FNwimp_measurefile(path3$)
  2174. DIM drawfiles% size%
  2175. DIM dfilehan%(3)
  2176. dfilehan%(1)=drawfiles%
  2177. dfilehan%(2)=FNwimp_loaddfile(path1$,dfilehan%(1))
  2178. dfilehan%(3)=FNwimp_loaddfile(path2$,dfilehan%(2))
  2179. d%=FNwimp_loaddfile(path3$,dfilehan%(3))
  2180.  
  2181. So you end up with dfilehan%(1) is the handle for the first drawfile,
  2182. dfilehan%(2) is the handle for the second, etc.
  2183.  
  2184. First of all FNwimp_measurefile is used to add up the total sizes of all the
  2185. drawfiles, so the size of block of memory to create is known. Then the block
  2186. (called drawfiles%) is made.
  2187.  
  2188. An array (dfilehan%) is made to hold the handles, and the first handle is
  2189. the start of the block of memory (drawfiles%).
  2190.  
  2191. The other handles are all obtained from FNwimp_loaddfile, which loads in the
  2192. drawfile. Passed to it is the handle (ie the position in the block as to
  2193. where it should be loaded) and returned is the handle to the next drawfile.
  2194.  
  2195. Upon loading the final drawfile we don't need to know the handle for the
  2196. next, and indeed there will be no more room in the block to load any more,
  2197. so it is stored in an arbitrary variable (I used d%), and forgotten about.
  2198.  
  2199. So, to load in more drawfiles, include them in the size totalling part, then
  2200. dim the handle array to the right size, then expand the list of
  2201. FNwimp_loaddfile calls to the required number.
  2202.  
  2203. Never try to work out the sizes of the drawfiles using any other method but
  2204. FNwimp_measurefile, otherwise you may run into trouble.
  2205.  
  2206. As a final example, how to load in a single drawfile:
  2207.  
  2208. PROCwimp_initdfiles
  2209. path1$="<MyApp$Dir>.Drawfile1"
  2210. size%=0
  2211. size%+=FNwimp_measurefile(path1$)
  2212. DIM drawfiles% size%
  2213. DIM dfilehan%(1)
  2214. dfilehan%(1)=drawfiles%
  2215. d%=FNwimp_loaddfile(path1$,dfilehan%(1))
  2216.  
  2217. You could in this case remove the dfilehan% array and just have drawfiles%
  2218. as the handle, but that is up to you to choose which you prefer.
  2219.  
  2220. Drawfiles can easily be saved using PROCwimp_savedfile. Eg. to save the
  2221. first drawfile to a path stored in path$:
  2222.  
  2223. PROCwimp_savedfile(path$,dfilehan%(1))
  2224.  
  2225.  
  2226. 21. Rendering Drawfiles & Sprites
  2227.  
  2228. Drawfiles and sprites can be rendered straight on the screen at a specified
  2229. position or in a window. The latter is much more useful, but is a derivative
  2230. of the former.
  2231.  
  2232. Drawfile Text areas are not rendered as they are rarely used and very
  2233. complex. Text column objects are therefore not rendered either.
  2234.  
  2235. The rendering is “simple”. i.e. no rotation, scaling, shearing, however some
  2236. may be added to DrWimp in later versions.
  2237.  
  2238. PROCwimp_render renders drawfiles onto the screen. The coordinates of the
  2239. bottom left corner are supplied, and two pairs of coordinates to define a
  2240. clipping rectangle. Any objects lying totally outside the clipping rectangle
  2241. are not rendered.
  2242.  
  2243. PROCwimp_rendersprite is the sprite equivelent and works in exactly the same
  2244. way, but instead of having a drawfile handle, there is the sprite name and
  2245. the sprite area handle which contains that sprite.
  2246.  
  2247. PROCwimp_renderwindow renders a drawfile inside a window, and is called in
  2248. PROCuser_redraw like:
  2249.  
  2250. IF window%=main% THEN
  2251.   PROCwimp_renderwindow(main%,dfilehan%(1),50,-50,minx%,miny%,
  2252. maxx%,maxy%)
  2253. ENDIF
  2254.  
  2255. See the example application in the Examples folder for a real example of
  2256. this. Note that in order for PROCuser_redraw to be called for a window, it
  2257. must have its “auto-redraw” flag unset from the template editor.
  2258.  
  2259. As an example for rendering a sprite (assuming it has already been loaded in
  2260. and is in a sprite area whose handle is sprite%):
  2261.  
  2262. IF window%=main% THEN
  2263. PROCwimp_renderwindowsprite(main%,"test",sprite%,50,50,
  2264.                                         minx%,miny%,maxx%,maxy%)
  2265. ENDIF
  2266.  
  2267. FNwimp_getdfilesize returns the width and depth of a drawfile so a window
  2268. can be resized to the size of the drawfile, and then displayed in it. The
  2269. equivalent for sprites is FNwimp_getspritesize.
  2270.  
  2271.  
  2272. 22. Saving time
  2273.  
  2274. You will find that after writing a few applications, in most if not all you
  2275. are having to find a templates file with an info window in it, rename the
  2276. sprites and all occurrences of “MyApp” to your application's name, create an
  2277. iconbar icon and iconbar menu, fill in the details in the info window, set
  2278. the version, etc, etc.
  2279.  
  2280. I have found that doing that over and over again gets tedious, hence the
  2281. utility !Fabricate in the Utils folder. It can do all those things for you
  2282. and save boredom setting in, leaving you to get on with writing the
  2283. interesting parts.
  2284.  
  2285. Full instructions are included in the !Help file inside !Fabricate.
  2286.  
  2287.  
  2288. 23. Validation Strings
  2289.  
  2290. Each icon has a validation string. This can be empty or contain some options
  2291. which are separated by semicolons. The validation string for an icon is set
  2292. in a template editor when editing the icon, and for those with the RISC OS 3
  2293. Programmers Reference Manuals all the options can be found on page 3-102.
  2294.  
  2295. The most common option is rn, where n is a number from 0 to 7, which
  2296. specifies the border type. For example r6 is the default action type border
  2297. and r7 is a writable icon type border. r0 is equivalent to not using the r
  2298. option.
  2299.  
  2300. If the icon can be pressed in then the “slab in” colour can be set. If you
  2301. create a default action button in TemplEd you will see that the validation
  2302. string is r6,3. Try changing the 3 to 7 or 11.
  2303.  
  2304. Another very common option is Pspritename, where spritename is the name of a
  2305. sprite for the pointer when the pointer is over that icon. Usually this is
  2306. something like Pptr_write which changes the pointer to a caret shape over
  2307. writable icons.
  2308.  
  2309. If you have lots of writable icons in a window then you can make it so that
  2310. the caret can be moved between them with the up and down arrow keys, Tab and
  2311. Return. If you put Ktar in the validation string of all your writable icons
  2312. then they can all be navigated in that way. t - Tab, a - arrows, r - Return.
  2313. You can use any combination you like.
  2314.  
  2315. The caret will move in order of icon number so if you have writable icons
  2316. numbered 3,11,7,8,2 then it will move in the order: 2,3,7,8,11 for the down
  2317. arrow, tab or return and 11,8,7,3,2 for the up arrow. So make sure that if
  2318. you are going to use this then your writable icons are numbered in such a
  2319. way that the caret will move in a predictable manner.
  2320.  
  2321. As mentioned, more that one option can be used for each icon if they are
  2322. separated by semicolons. So for a typical writable icon you may have:
  2323. r7;Pptr_write;Ktar.
  2324.  
  2325.  
  2326. 24. Indirection
  2327.  
  2328. Throughout this manual, you will have seen lots of references to “Indirected
  2329. Icons”. Here is a brief description of what it means, and why they are
  2330. important to using the Wimp.
  2331.  
  2332. Each icon on the desktop is defined by a small block of memory. This block
  2333. is of a fixed size and contains a complete description of the icon so the
  2334. Wimp can draw it.
  2335.  
  2336. This block contains the dimensions, a load of flags containing information
  2337. such as whether it is a sprite, text, sprite and text, filled, has a border,
  2338. etc and some data on what it contains, such as actual sprite name or text.
  2339. Most of the flags you can toggle between set and unset using a template
  2340. editor, such as TemplEd.
  2341.  
  2342. The total size of the icon block is 32 bytes. 12 of these are used for
  2343. holding the data. If the icon holds text or is a sprite using the “S”
  2344. validation code then the maximum length of the string must be 11 (plus a
  2345. terminator). If you want to hold more than this then you must make the icon
  2346. indirected by setting the flag in a template editor, and making the value of
  2347. the indirected field the maximum number of characters you wish to hold. The
  2348. text is then stored elsewhere and a pointer to it is placed in the data
  2349. section of the icon block.
  2350.  
  2351. Once an icon has been created (ie. your program has loaded in the window
  2352. containing the icon) then you can only change certain things in the icon
  2353. block. You cannot change the contents of the data section. However, if the
  2354. icon is indirected then you can change the text or sprite name because it is
  2355. not actually held in the icon block but in another block of memory
  2356. elsewhere.
  2357.  
  2358. If you make an icon indirected with an indirected size of 16, then use
  2359. PROCwimp_puticontext to put a string greater than 15 characters long (15
  2360. plus terminator equals 16), strange things may happen. The most common is
  2361. that if the icon has a 3D border then it is lost. The more you go over the
  2362. limit, the messier things get.
  2363.  
  2364.  
  2365. 25. Text Handling
  2366.  
  2367. You should, by now, be able to see how to plot drawfiles and sprites in a
  2368. window (using PROCuser_redraw). With DrWimp it is also possible to plot text
  2369. in a variety of ways. Any outline font can be used at any size and in any
  2370. colour.
  2371.  
  2372. Some of the functions require the name of the font to be provided. The names
  2373. always have to be what I call period seperated. For example:
  2374.  
  2375. "Trinity.Medium"
  2376. "Homerton.Bold.Oblique"
  2377. "Corpus.Medium.Oblique"
  2378.  
  2379. Instead of having spaces, there are periods (full stops).
  2380.  
  2381. PROCwimp_plottext is the most besic function provided, and simply plots a
  2382. string of text on the screen at the required position. You pass to it the
  2383. name of the font you want to use, the point size and foreground and
  2384. background colours.
  2385.  
  2386. PROCwimp_plotwindowtext does the same but plots the text in a window, so you
  2387. would use this in PROCuser_redraw like PROCwimp_renderwindow and
  2388. PROCwimp_renderwindowsprite.
  2389.  
  2390. Fonts can have handles, just like windows, drawfiles, sprites, etc. In fact
  2391. that is how the wimp uses fonts. Whenever PROCwimp_plottext or
  2392. PROCwimp_plotwindowtext is called, a handle for the font is found, the
  2393. string is plotted, then the handle is returned. If you are plotting many
  2394. lines of text, all this handle finding and returning can waste a lot of
  2395. time. DrWimp provides a way of optimising this by providing a wimp function
  2396. to find the handles for you, use slightly different wimp functions to plot
  2397. the text, then allow you to return the handles.
  2398.  
  2399. FNwimp_getfont returns a handle when you tell it the font you require and
  2400. the point size. You would normally get all the handles you require when your
  2401. application loads, before PROCwimp_poll. A 0 is returned if the font could
  2402. not be found so you would have to take into account of this and perhaps find
  2403. an alternative and warn the user.
  2404.  
  2405. trinity12% = FNwimp_getfont("Trinity.Medium",12)
  2406.  
  2407. To plot text, PROCwimp_plottexth and PROCwimp_plotwindowtexth are used. Note
  2408. the “h” on the end of the function name to denote that those functions
  2409. accept font handles instead of fonts names and sizes. PROCuser_redraw
  2410. example:
  2411.  
  2412. IF window%=main% THEN
  2413. PROCwimp_plotwindowtexth(main%,"Test",trinity12%,50,50,0,0,0,
  2414.                             255,255,255,minx%,miny%,maxx%,maxy%)
  2415. ENDIF
  2416.  
  2417. Note the foreground and background colours. 0,0,0 sets the foreground to
  2418. black, and 255,255,255 sets the background to white.
  2419.  
  2420. Finally, when you have finished with a font, you call PROCwimp_losefont. For
  2421. example:
  2422.  
  2423. PROCwimp_losefont(trinity12%)
  2424.  
  2425. This would normally be called when you application is quitting, like after
  2426. the PROCwimp_poll, but before the END.
  2427.  
  2428. Not just simple strings of text can be plotted. Strings of control code
  2429. sequences can be inserted into the string to turn underlining on and off,
  2430. change the font, or change the font colour. DrWimp provides functions to
  2431. produce these control strings. For example:
  2432.  
  2433. t$="Cat "+FNwimp_underline(1)+"dog"+FNwimp_underline(0)+" hen."
  2434.  
  2435. when plotted would result in the word “dog” being underlined. Note the
  2436. positioning of the spaces between the three words so they don't get
  2437. underlined as well. An example of turning the text red:
  2438.  
  2439. t$="Cat "+FNwimp_fontcolour(255,0,0)+"dog."
  2440.  
  2441. would make the word “dog.” turn red. The text can be turned black again
  2442. afterwards with 0,0,0. And for changing the font (assuming homerton20% is a
  2443. font handle already found):
  2444.  
  2445. t$="Cat "+FNwimp_fontchangeh(homerton20%)+"dog."
  2446.  
  2447. would make the word “dog.” appear in the font whose handle is homerton20%.
  2448.  
  2449. Note that there isn't an equivalent FNwimp_fontchange (no “h”) as the
  2450. control sequence only works with font handles.
  2451.  
  2452. Any combination of these can be used to produce the effect you want. Note
  2453. that if you plot a string and the end of it is in red for example, then the
  2454. next line you plot will be in black again. There is no need to change the
  2455. colour back to black as all effects such as colours, underlining and
  2456. changing font only apply for that line only.
  2457.  
  2458. There are two functions for finding the width and height of a string, if it
  2459. were plotted on the screen. They are FNwimp_gettextsize and
  2460. FNwimp_gettextsizeh, with the latter using font handles instead of font
  2461. names and sizes.
  2462.  
  2463. The last two functions also plot text, both on the screen and in windows,
  2464. but they don't always plot with outline fonts. They allow text to be plotted
  2465. using the current desktop font. On pre RISC OS 3.5 machines this is always
  2466. the system font, so that is what will be used. On RISC OS 3.5+ it is the
  2467. outline font that is currently being used for the desktop, which may be the
  2468. system font.
  2469.  
  2470. These allow things like annotations or lists of choices to be constructed,
  2471. knowing they will match the desktop and look like they are text in icons.
  2472.  
  2473. The functions are PROCwimp_deskplottext and PROCwimp_deskplotwindowtext. You
  2474. supply the string to plot, the position and the foreground and background
  2475. colours. There is an extra parameter which allows you to choose whether to
  2476. plot with the left side of the text at the x-coordinate, or plot with the
  2477. text centred on the x-coordinate. They plot stright to the screen and to a
  2478. window respectively.
  2479.  
  2480.  
  2481. 26. Printing
  2482.  
  2483. This section assumes you have a fairly good grasp of how to use
  2484. DrWimp. As there a quite a bit to set up and nothing can be tested until its
  2485. mostly all done, there is no tutorial for this section. However there are
  2486. some example applications in the Examples folder.
  2487.  
  2488. As you have seen, it is possible to plot text, sprites and drawfiles in
  2489. windows by doing the revelant work in PROCuser_redraw. But what if you want
  2490. to print it out? For a start the work area has its origin at the top left of
  2491. a window, making all y coordinates negative. Paper has its origin at the
  2492. bottom left corner of the paper. Plus it seems that if you want to print out
  2493. what you have described in PROCuser_redraw, you will have to duplicate it
  2494. all again. Then there is the problem of fitting lots of pages onto one page
  2495. by reducing them in size and rotation.
  2496.  
  2497. DrWimp makes it relatively easy to print out documents, even using what you
  2498. have already written for PROCuser_redraw, but you will have to make some
  2499. alterations to the coordinate calculations, which are fairly strightforward.
  2500.  
  2501. There are two methods you can use to print out and which you choose depends
  2502. on the application. If you want to print out what is being shown in a window
  2503. because it has all be written in PROCuser_redraw, then you use what we will
  2504. call the “redraw” method. If on the other hand you want to print out
  2505. something that isn't displayed, and only needs to be described for the
  2506. printing then you do all the work in a user function, PROCuser_print. We
  2507. will call this the “user” method.
  2508.  
  2509. DrWimp also provides facilities to find out about the paper, printer driver,
  2510. convert between work area coordinates and screen coordinates, and also
  2511. provides a means for the application to tell the user what is going on and
  2512. giving them the option to cancel the printing.
  2513.  
  2514. The first thing your application needs to do is have some sort of print
  2515. window where the user can specify the range of pages to print, how many to
  2516. fit onto a page and the number of copies to print. Now its not a good idea
  2517. to try and print out when there is no printer driver loaded as your
  2518. application will produce errors and probably quit, so you have to check to
  2519. see if a printer driver is actually loaded. For example:
  2520.  
  2521. loaded%=FNwimp_pdriverpresent
  2522.  
  2523. loaded% will equal 1 if a printer driver is loaded, and a 0 if one isn't.
  2524.  
  2525. Users can load and quit printer drivers at any time and they may be present
  2526. or not whilst your application is runing, so you need to continually check.
  2527. The best time to do this is just before your print window is opened. So you
  2528. might have a function that does the check and you always call it just before
  2529. every PROCwimp_openwindow or PROCwimp_openwindowat for your print window.
  2530.  
  2531. Depending on the result of the check you should disable some icons in the
  2532. print window. For example the icon the user clicks on to initiate the
  2533. printing. Also a common practice is to put the name of the current printer
  2534. in the titlebar of the window or somewhere in the window. So for example you
  2535. could use:
  2536.  
  2537. loaded%=FNwimp_pdriverpresent
  2538. IF loaded%=1 THEN
  2539.   printername$=FNwimp_getpdrivername
  2540.   PROCwimp_putwindowtitle(print%,printername$)
  2541. ELSE
  2542.   PROCwimp_putwindowtitle(print%,"No printer loaded")
  2543. ENDIF
  2544.  
  2545. with print% being the handle of your print window. Its easy to see that in
  2546. that IF..ELSE..ENDIF structure you can enable and disable icons in the print
  2547. window depending on whether the printer driver was loaded or not.
  2548.  
  2549. If you wish you can also get information about the paper size and the
  2550. borders (which you can't print in), to display in the print window. You
  2551. could even draw two small grey and white rectangles to depict the page and
  2552. its borders. But be careful not to try and get any information about the
  2553. page unless a printer driver is loaded!
  2554.  
  2555. Here is a sample piece of code that could go in PROCuser_redraw for the
  2556. print window (assuming its auto redraw flag is off):
  2557.  
  2558. IF window%=print% THEN
  2559.   IF FNwimp_pdriverpresent THEN
  2560.     w%=FNwimp_getpapersize(0,0)
  2561.     h%=FNwimp_getpapersize(1,0)
  2562.     IF h%>=w% scale=h%/120
  2563.     IF w%>h% scale=w%/120
  2564.     w%=w%/scale
  2565.     h%=h%/scale
  2566.     x%=FNwimp_worktoscreen(print%,316,0)
  2567.     y%=FNwimp_worktoscreen(print%,-256,1)
  2568.     PROCwimp_setcolour(160,160,160)
  2569.     RECTANGLE FILL x%,y%,w%,h%
  2570.     lm%=FNwimp_getpapersize(0,1)/scale
  2571.     r%=FNwimp_getpapersize(0,3)/scale
  2572.     bm%=FNwimp_getpapersize(1,1)/scale
  2573.     t%=FNwimp_getpapersize(1,3)/scale
  2574.     PROCwimp_setcolour(255,255,255)
  2575.     RECTANGLE FILL x%+lm%,y%+bm%,r%-lm%,t%-bm%
  2576.   ENDIF
  2577. ENDIF
  2578.  
  2579. which will draw a small depiction of the paper in the window with borders.
  2580. It may be slow though due to it having to find out if a printer driver is
  2581. loaded every time a bit of the window needs redrawing, although you could
  2582. optimise it to take into account the redraw clipping rectangle passed to
  2583. PROCuser_redraw.
  2584.  
  2585. Currently DrWimp supports printing ranges of pages, multiple copies and
  2586. fitting one, two or 4 A4 pages onto a single physical A4 page, so these are
  2587. the options you can provide in your print window. For an example see the
  2588. template file “Print” in the tutorials folder.
  2589.  
  2590. At any time the user could change the current printer, and
  2591. PROCuser_printerchange will be called. When it is, you much check to see if
  2592. the printer driver is still loaded, and update all your page measurements,
  2593. what icons to enable and disable in the print window etc. Basically do all
  2594. your checks again just as if the print window was being opened. Don't
  2595. actually open your print window unless its already open, in which case it
  2596. should update itself.
  2597.  
  2598. If you are printing with outline fonts, which is probably very likely, then
  2599. there is one more consideration to take into account before we can start
  2600. printing. Postscript printers either have fonts with different names or only
  2601. a small selection of fonts, so some printer drivers, particually postscript
  2602. ones may require all fonts that are going to be used, to be declared first.
  2603. As we don't know what printer the user is going to use, or if they require
  2604. fonts to be declared, we must always declare them. This is done in the user
  2605. function PROCuser_declarefonts.
  2606.  
  2607. If you have any drawfiles you are going to print out that contain fonts,
  2608. then the fonts in them also need to be declared.
  2609.  
  2610. In the user function PROCuser_declarefonts you must call
  2611. PROCwimp_declarefont if you want to supply the font name, or
  2612. PROCwimp_declarefonth if you want to give the font handle instead, for each
  2613. font. For drawfiles you call PROCwimp_declaredfilefonts, giving the handle
  2614. of the drawfile, for each drawfile. For example:
  2615.  
  2616. DEF PROCuser_declarefonts
  2617.   PROCwimp_declarefont("Trinity.Medium")
  2618.   PROCwimp_declarefonth(homerton18%)
  2619.   PROCwimp_declaredfilefonts(dfilehan%(1))
  2620. ENDPROC
  2621.  
  2622. See the section on text handling for more information on font handles and
  2623. period seperated font names, and see the section on loading drawfiles for
  2624. more information on drawfile handles.
  2625.  
  2626. Once you have everything set up you are ready to print and one wimp function
  2627. initiates it.
  2628.  
  2629. PROCwimp_print(user%,window%,fpage%,lpage%,perpage%,copies%)
  2630.  
  2631. Setting user% to 1 prints using the user method, and setting it to 0 prints
  2632. using the redraw method. Both of these will be discussed in more detail
  2633. later.
  2634.  
  2635. If using the redraw method then window% is the handle of the window to
  2636. redraw. In other words the window whose contents you want to print out.
  2637. window% is ignored if printing with the user method.
  2638.  
  2639. fpage% and lpage% are the page numbers of the first page to print and the
  2640. last page, respectively. These are inclusive, and don't really matter to
  2641. DrWimp what they are as long as lpage% is equal to or larger than fpage%.
  2642. The numbers you specify for the range of pages are arbitary as far as DrWimp
  2643. is concerned, as the whole range of page numbers will be returned to you one
  2644. by one as you are requested to print each page.
  2645.  
  2646. perpage% can currently be either 1, 2, or 4. If you set it to 1 then each
  2647. page will fit on a physical A4 page. If you specify 2 then two A4 pages will
  2648. be scaled to about 70%, rotated through 90 degrees, and placed side by side
  2649. on a physical A4 page. If you specify 4 then each page will be scaled to 50%
  2650. and four pages will be printed on a single physical A4 page. All this is
  2651. done automatically and the printing as far as you are concerned is exactly
  2652. the same, just that the actual output is affected.
  2653.  
  2654. copies% is the number of copies to print. For example if you want to print
  2655. from page 1 to 4, with two copies, then eight pages will be printing, two
  2656. lots of four. The number of physical pages printed depends on perpage%
  2657. though.
  2658.  
  2659. During printing you may wish to keep the user informed of the progress of
  2660. the printing and give them the option to cancel. This is easily achieved as
  2661. FNuser_printing is repeatedly called. From it you can read the current copy
  2662. being printed, the current page number, the total number of pages that are
  2663. being printed, and the current page being printed (from one to the total
  2664. number).
  2665.  
  2666. From the total number of pages and the current page being printed, you can
  2667. calculate the percentage of pages already printed and display a progress bar
  2668. using PROCwimp_bar. You can also display the current copy and current page
  2669. out of interest.
  2670.  
  2671. Finally, in the progress window you can add a cancel button, and when it is
  2672. clicked on you set a variable to indicate that the user wishes to cancel
  2673. printing. Then, when PROCuser_printing is next called, you look at the
  2674. variable and return a 1 if the printing is to be cancelled. Otherwise you
  2675. return a 0.
  2676.  
  2677. Here is an example of the sort of thing you might put into the user
  2678. function:
  2679.  
  2680. DEF FNuser_printing(copy%,page%,totpages%,pagepos%)
  2681. PROCwimp_puticontext(prog%,0,“Printing page ”+STR$page%+“ (copy                                                   ”+STR$copy%+“)”)
  2682. PROCwimp_bar(prog%,2,(pagepos%/totpages%)*466,0)
  2683. =cancel%
  2684.  
  2685. In the example, prog% is the handle to the progress window, the progress bar
  2686. is icon number 2, which is 466 OS units long, and icon 0 is just a text icon
  2687. to display information.
  2688.  
  2689. cancel% is set to 0 just before PROCwimp_print was called, and in
  2690. PROCuser_mouseclick there would be a line like the following:
  2691.  
  2692. IF window%=prog% AND icon%=4 cancel%=1
  2693.  
  2694. where icon 4 is the cancel button. FNuser_printing can then simply return
  2695. cancel% to indicate if printing is to be cancelled or not.
  2696.  
  2697. Just as a couple of examples so you understand the difference between page%
  2698. and pagepos%:
  2699.  
  2700. Say the user wanted to print pages 2 to 8, one copy. Then as printing
  2701. progresses copy% will stay at one, page% will start at 2 and increase to 8,
  2702. totpages% will stay at 7 (printing pages 2 to 8 inclusive), and pagepos%
  2703. will start at 1 and increase to 7 (totpages%).
  2704.  
  2705. If the user was printing pages 4 to 6, 2 copies, then copy% will start at 1
  2706. and increase to 2, page% will start at 4 and increase to 6, totpages% will
  2707. stay at 3, and pagepos% will start at 1 and increase to 3 (totpages%).
  2708.  
  2709. Now we come to the final part of printing, the actual constructing of the
  2710. pages. First the redraw method.
  2711.  
  2712. When PROCuser_redraw is called and printing is occuring, the variable
  2713. printing% will be TRUE, and page% will contain the page number to print.
  2714. Lets take a simple example of plotting one line of text in trinity medium at
  2715. 12pt. We will assume a handle for the font has already been obtained and is
  2716. in trinity12%. The window we are plotting in has the handle main% (ie. the
  2717. window handle passed to PROCwimp_print was main%), and the text is placed at
  2718. the work area coordinates 50,-100.
  2719.  
  2720. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2721.                                                 printing%,page%)
  2722. IF window%=main% THEN
  2723.   x%=50:y%=-100
  2724.   string$="DrWimp printing test."
  2725.   PROCwimp_plotwindowtexth(main%,string$,trinity12%,x%,y%,
  2726.                       0,0,0,255,255,255,minx%,miny%,maxx%,maxy%)
  2727. ENDIF
  2728. ENDPROC
  2729.  
  2730. Now take a look at how it would be modified to allow the contents of the
  2731. window main% to be printed.
  2732.  
  2733. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2734.                                                 printing%,page%)
  2735. IF window%=main% THEN
  2736.   x%=50:y%=-100
  2737.   IF printing%=TRUE THEN
  2738.     x%=FNwimp_worktopaper(x%,0)
  2739.     y%=FNwimp_worktopaper(y%,1)
  2740.   ENDIF
  2741.   string$="DrWimp printing test."
  2742.   PROCwimp_plotwindowtexth(main%,string$,trinity12%,x%,y%,
  2743.                       0,0,0,255,255,255,minx%,miny%,maxx%,maxy%)
  2744. ENDIF
  2745. ENDPROC
  2746.  
  2747. And thats it! The wimp function FNwimp_worktopaper should be self
  2748. explanatory.
  2749.  
  2750. Now, take a look at this next example:
  2751.  
  2752. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2753.                                                 printing%,page%)
  2754. IF window%=main% THEN
  2755.   x%=50:y%=-200
  2756.   PROCwimp_setcolour(255,0,0)
  2757.   x%=FNwimp_worktoscreen(main%,x%,0)
  2758.   y%=FNwimp_worktoscreen(main%,y%,1)
  2759.   RECTANGLE FILL x%,y%,100,100
  2760. ENDIF
  2761. ENDPROC
  2762.  
  2763. which will draw a red square with the bottom left corner at the work area
  2764. coordinates 50,-200. Now here is the modified version which will allow the
  2765. square to be printed out:
  2766.  
  2767. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2768.                                                 printing%,page%)
  2769. IF window%=main% THEN
  2770.   x%=50:y%=-200
  2771.   PROCwimp_setcolour(255,0,0)
  2772.   x%=FNwimp_worktoscreen(main%,x%,0)
  2773.   y%=FNwimp_worktoscreen(main%,y%,1)
  2774.   IF printing%=TRUE THEN
  2775.     x%=FNwimp_screentopaper(main%,x%,0)
  2776.     y%=FNwimp_screentopaper(main%,y%,1)
  2777.   ENDIF
  2778.   RECTANGLE FILL x%,y%,100,100
  2779. ENDIF
  2780. ENDPROC
  2781.  
  2782. the screen coordinates are converted into paper coordinates via the windows
  2783. work area coordinates. Essentially a screen -> work -> paper conversion.
  2784.  
  2785. One thing to note is that the top left corner of the window main% matches up
  2786. with the top left corner of the paper.
  2787.  
  2788. Now for an example of printing the page number at the bottom of each page.
  2789. You can work out the work area coordinates and/or the page coordinates to
  2790. place the text, but the following example assumes the work area of the
  2791. window main% has been set to the size of an A4 piece of paper. That can be
  2792. done with:
  2793.  
  2794. width%=FNwimp_lengthtoOS(210,100,0)
  2795. height%=FNwimp_lengthtoOS(297,100,0)
  2796. PROCwimp_resizewindow(main%,width%,height%)
  2797.  
  2798. The FNwimp_lengthtoOS call converts 210mm and 297mm at 100% scale to OS
  2799. units. The window is then resized. The example also assumes the programmer
  2800. is keeping track of which page is being displayed with currentpage%. Now for
  2801. the example:
  2802.  
  2803. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2804.                                                 printing%,page%)
  2805. IF window%=main% THEN
  2806.   x%=50:y%=FNwimp_getwindowworksize(main%,1)+150
  2807.   IF printing%=TRUE THEN
  2808.     x%=FNwimp_worktopaper(x%,0)
  2809.     y%=FNwimp_worktopaper(y%,1)
  2810.   ENDIF
  2811.   string$="Page "+STR$currentpage%
  2812.   PROCwimp_plotwindowtexth(main%,string$,trinity12%,x%,y%,
  2813.                       0,0,0,255,255,255,minx%,miny%,maxx%,maxy%)
  2814. ENDIF
  2815. ENDPROC
  2816.  
  2817. The text is plotted 150 OS units up from the bottom of the actual paper to
  2818. allow for printer borders, and to give a bit of space. As stated before,
  2819. currentpage% contains the number of the page currently being displayed.
  2820.  
  2821. There is one problem with this however. It will be displayed fine, but when
  2822. it comes to printing out, every time currentpage% will contain the page
  2823. number of the current page being displayed, so it won't change on paper.
  2824. What is required is a way of using the variable page% passed to
  2825. PROCuser_redraw to make currentpage% change, but without corrupting it, so
  2826. when the printing has finished the redraw won't try to show a different
  2827. page. Here is one method:
  2828.  
  2829. DEF PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,
  2830.                                                 printing%,page%)
  2831. IF window%=main% THEN
  2832.   IF printing%=TRUE c%=currentpage%:currentpage%=page%
  2833.   x%=50:y%=FNwimp_getwindowworksize(main%,1)+150
  2834.   IF printing%=TRUE THEN
  2835.     x%=FNwimp_worktopaper(x%,0)
  2836.     y%=FNwimp_worktopaper(y%,1)
  2837.   ENDIF
  2838.   string$="Page "+STR$currentpage%
  2839.   PROCwimp_plotwindowtexth(main%,string$,trinity12%,x%,y%,
  2840.                       0,0,0,255,255,255,minx%,miny%,maxx%,maxy%)
  2841.   IF printing%=TRUE currentpage%=c%
  2842. ENDIF
  2843. ENDPROC
  2844.  
  2845. If PROCuser_redraw is being called for printing (printing% is TRUE) then
  2846. currentpage% is stored in c% for safekeeping, and set to the number of the
  2847. page being printed. Then when the redraw has finished currentpage% is
  2848. restored to what it was initially.
  2849.  
  2850. Now for the user method of printing. Instead of PROCuser_redraw being
  2851. called, PROCuser_print is called instead, and the page is described in much
  2852. the same way. As there is no window involved you do not need to convert
  2853. between work area, screen and paper coordinates. You simply work in paper
  2854. coordinates, which are exactly the same as OS units, with the origin at the
  2855. bottom left corner of the paper. For example, to print a black square,
  2856. slightly in from the bottom left corner of the paper:
  2857.  
  2858. DEF PROCuser_print(minx%,miny%,maxx%,maxy%,page%)
  2859. PROCwimp_setcolour(0,0,0)
  2860. RECTANGLE FILL 100,100,50,50
  2861. ENDPROC
  2862.  
  2863. You can be more precise with your position in “real” units, for example:
  2864.  
  2865. DEF PROCuser_print(minx%,miny%,maxx%,axy%,page%)
  2866. inch%=FNwimp_lengthtoOS(1,100,1)
  2867. 4cm%=FNwimp_lengthtoOS(40,100,0)
  2868. PROCwimp_setcolour(0,0,0)
  2869. RECTANGLE FILL inch%,inch%,4cm%,4cm%
  2870. ENDPROC
  2871.  
  2872. will print out a black square one inch from the bottom of the page and one
  2873. inch from the left edge of the page, with sides 4cm long.
  2874.  
  2875. With PROCuser_print there is no printing% or currentpage% variables to use
  2876. because it is only called when printing is taking place, and page% holds the
  2877. current page number of the page being printed.
  2878.  
  2879. There is a standard clipping rectangle supplied in page coordinates which
  2880. you can use for optimisation, however I doubt the performance gains would be
  2881. big enough to warrant the extra effort of using the clipping rectangle.
  2882.  
  2883. When developing the printing part of your application you may like to know
  2884. of the method I used for saving on ink and paper when writing DrWimp. I
  2885. added a postscript printer to Printers and set it to print to a file, thus
  2886. creating a postscript file. I then loaded it into the PD application
  2887. RiScript which allows you to view postscript files. The output could then be
  2888. used to debug and verify printing code. One word of warning though, RiScript
  2889. is very slow. Especially on text. If you have a lot of text on the page you
  2890. could be waiting a very long time!
  2891.  
  2892.  
  2893. 27. Bits & bobs
  2894.  
  2895. There are other features of DrWimp like user graphics functions etc which
  2896. are demonstrated by the examples. See their commented !RunImage files.
  2897.  
  2898. Brief overview of some functions:
  2899.  
  2900. FNwimp_resizewindow resizes a window to the supplied width and height. The
  2901. work area is set to the new values, and if it is smaller than the current
  2902. visible area, then the window will shrink.
  2903.  
  2904. PROCwimp_colouricontext changes the colour of some text in an icon to one of
  2905. the 16 desktop colours. This means that you can “grey-out” labels which are
  2906. not filled. If you do that with PROCwimp_icondisable then the unfilled
  2907. background turns white.
  2908.  
  2909. FNwimp_geticonsize is like FNwimp_getwindowsize in that is returns the
  2910. dimensions of an icon.
  2911.  
  2912. FNwimp_geticonstate is the duel of PROCwimp_iconselect, and returns a 1 if
  2913. the icon is selected, or a 0 if it isn't.
  2914.  
  2915. FNwimp_worktoscreen and FNwimp_screentowork convert between screen
  2916. coordinates and a window's work area coordinates.
  2917.  
  2918. PROCwimp_setcolour sets the current GCOL colour for drawing, and uses
  2919. dithering, if the exact colour is not available in the current mode.
  2920.  
  2921. Blocks can be used as a compact way of storing strings, if you have a
  2922. maximum length for a string.
  2923.  
  2924. block%=FNwimp_createblock(10,25)
  2925.  
  2926. Will create a block that can store 10 strings, any of which can be up to 25
  2927. characters in length. block% is the handle to the block.
  2928.  
  2929. PROCwimp_putinblock(block%,"A string",3)
  2930.  
  2931. Will put the string shown into position 3 in the block, whose handle is
  2932. block%.
  2933.  
  2934. s$=FNwimp_getfromblock(block%,3)
  2935.  
  2936. Will extract the string from position 3 in the block whose handle is block%.
  2937.  
  2938.  
  2939. SECTION 3 FUNCTIONS
  2940.  
  2941. 1. Misc
  2942.  
  2943. FNwimp_OStolength(coord,scale,inch%)
  2944. Converts OS units to mm or inches.
  2945. coord = value to convert (can be integer or floating point).
  2946. scale = scaling factor 0-100 (%).
  2947. If inch%=0 the value returned is in mm. If inch%=1 the value returned
  2948. is in inches.
  2949.  
  2950. FNwimp_createblock(items%,length%)
  2951. Creates a block for storing strings in. Returns a handle to the block.
  2952. items% = maximum number of strings to store.
  2953. length% = maximum possible length of each string.
  2954.  
  2955. FNwimp_errorchoice(title$,error$,prefix%)
  2956. Reports an error using a standard error box.
  2957. It has both ‘OK’ and ‘CANCEL’ buttons.
  2958. title$ = title of error window.
  2959. error$ = error message.
  2960. IF prefix% = 0 then the title is title$. If prefix% = 1 then the title
  2961. is prefixed by ‘Error from ’. If prefix% = 2 then the title is prefixed
  2962. by ‘Message from ’.
  2963. Returns TRUE if ‘OK’ pressed. FALSE if ‘CANCEL’ pressed.
  2964.  
  2965. FNwimp_getfromblock(block%,pos%)
  2966. Returns a string stored in a block.
  2967. block% = handle of block.
  2968. pos% = position of string in block (ranging from 1 to maximum as passed
  2969. to FNwimp_createblock).
  2970.  
  2971. FNwimp_getleafname(path$)
  2972. Returns a string containing the leafname from the pathname.
  2973. path$ = pathname.
  2974.  
  2975. FNwimp_getscreensize(side%)
  2976. Returns the dimension of the screen required.
  2977. If side% = 0 returns width. If side% = 1 returns height.
  2978.  
  2979. FNwimp_initialise(name$,wimpmem%,iconmem%,ver%)
  2980. This function registers your application with the Task Manager and
  2981. reserves some memory.
  2982. name$ = the name of your application eg. ‘Draw’.
  2983. wimpmem% = number of bytes to reserve for icon data or menu entries.
  2984. iconmem% = number of bytes to reserve for indirected text. eg. window
  2985. titles or long menu entries.
  2986. ver% = minimum version of RISC OS that the application is allowed to
  2987. run on multiplied by 100.
  2988.  
  2989. FNwimp_lengthtoOS(coord,scale,inch%)
  2990. Converts mm or inches to OS units.
  2991. coord = value to convert (can be integer or floating point).
  2992. scale = scaling factor 0-100 (%).
  2993. If inch%=0 the value coord supplied is in mm. If inch%=1 the value coord
  2994. supplied is in inches.
  2995.  
  2996. FNwimp_libversion
  2997. Returns the version number of the library x 100. Eg. if the version of
  2998. the library is 1.03 then 103 will be returned.
  2999.  
  3000. FNwimp_roundfloat(float)
  3001. Rounds the floating point number up or down and returns the integer.
  3002.  
  3003. FNwimp_screentowork(window%,coord%,side%)
  3004. Converts the x or y screen coordinate coord% to a work area x or y
  3005. coordinate. 
  3006. window% = handle of window whos work area coordinate is being converted
  3007. into.
  3008. coord% = coordinate (x or y).
  3009. If side% = 0 then coord% is a x coordinate, and an x coordinate is
  3010. returned.
  3011. If side% = 1 then coord% is a y coordinate, and a y coordinate is
  3012. returned.
  3013.  
  3014. FNwimp_sysvariable(sysvar$)
  3015. Returns a string for the system variable sysvar$.
  3016. Note ‘<’ and ‘>’ are not required in sysvar$.
  3017.  
  3018. FNwimp_worktoscreen(window%,coord%,side%)
  3019. Converts the x or y work area coordinate coord% to a screen x or y
  3020. coordinate. 
  3021. window% = handle of window whos work area coordinate is being converted.
  3022. coord% = coordinate (x or y).
  3023. If side% = 0 then coord% is a x coordinate, and an x coordinate is
  3024. returned.
  3025. If side% = 1 then coord% is a y coordinate, and a y coordinate is
  3026. returned.
  3027.  
  3028. PROCwimp_bar(window%,icon%,length%,dir%)
  3029. Adjusts the length of a bar.
  3030. window% = handle of window containing the bar.
  3031. icon% = icon number of the bar.
  3032. length% = length of the bar.
  3033. If dir% = 0 then the bar moves horizontally keeping the height constant.
  3034. If dir% = 1 then the bar moves vertically keeping the width constant.
  3035.  
  3036. PROCwimp_error(title$,error$,button%,prefix%)
  3037. Reports an error using a standard error box.
  3038. title$ = title of error window.
  3039. error$ = error message.
  3040. IF button%=1 then will have an ‘OK’ button.
  3041. IF button%=2 then will have a ‘CANCEL’ button.
  3042. prefix% = prefix flag. If = 0 then the title is title$. If = 1 then the
  3043. title is prefixed by ‘Error from ’. If = 2 then the title is prefixed
  3044. by ‘Message from ’.
  3045.  
  3046. PROCwimp_increaseslot(bytes%)
  3047. Increases size of wimslot by bytes% bytes. If not enough available RAM
  3048. then creates an error.
  3049.  
  3050. PROCwimp_pointer(pointer%,area%,pointer$)
  3051. Changes mouse pointer between the deafult (number 1) and the user
  3052. defined pointer (number 2).
  3053. If pointer% = 0 default pointer is used. If pointer% = 1 user defined
  3054. pointer is used.
  3055. If area% = 0 wimp sprite pool is used otherwise area% is a handle to a
  3056. sprite area.
  3057. pointer$ = sprite name of pointer.
  3058.  
  3059. PROCwimp_putinblock(block%,string$,pos%)
  3060. Stores a string in a block which has been created using FNwimp_createblock.
  3061. block% = handle of block.
  3062. string$ = string to store.
  3063. pos% = position to store string in (ranging from 1 to maximum as passed to
  3064. FNwimp_createblock).
  3065.  
  3066. PROCwimp_setcolour(red%,green%,blue)
  3067. Sets the current GCOL colour to the nearest possible for the current mode.
  3068. red% = amount of red in range 0-255.
  3069. green% = amount of green in range 0-255.
  3070. blue% = amount of blue in range 0-255.
  3071.  
  3072. PROCwimp_starttask(command$)
  3073. Sends command$ to the CLI. Omit ‘*’.
  3074.  
  3075.  
  3076. 2. Polling
  3077. PROCwimp_poll
  3078. This function is the main loop of your application. When it has finished,
  3079. your application has quitted. If something happens to your application eg.
  3080. an icon has been clicked on, then the relevent function will be called from
  3081. the loop.
  3082.  
  3083. PROCwimp_pollidle(seconds%)
  3084. If NULL=TRUE then PROCuser_null will be called every seconds% seconds
  3085. instead of every time control is passed to the application and no event
  3086. has occured.
  3087.  
  3088. PROCwimp_singlepoll
  3089. The same as PROCwimp_poll, execpt that it is called once and not in a loop.
  3090. If something happens then the relevent action will still be taken before
  3091. returning.
  3092. Useful for making loops multitask, eg: raytracing, printing, calculating,
  3093. loading in data, etc.
  3094. Note: if calling in PROCuser_null, make sure NULL=FALSE before this call
  3095. (can set to TRUE afterwards) otherwise recursion will occur.
  3096.  
  3097. PROCwimp_singlepollidle(seconds%)
  3098. The same as PROCwimp_pollidle, except that it is called once and not in a
  3099. loop. If something happens then the relevent action will be taken before
  3100. returning. If NULL=TRUE then PROCuser_null will be called after seconds%
  3101. seconds.
  3102. Useful for incorporating delays into multitasking loops.
  3103. Note: if calling in PROCuser_null, make sure NULL=FALSE before this call
  3104. (can set to TRUE afterwards) otherwise recursion will occur.
  3105.  
  3106. 3. User
  3107. FNuser_help(window%,icon%)
  3108. Return a string to be used for interactive help for the window (and icon).
  3109. window% = handle of window (containing icon).
  3110. icon% = number of icon.                     
  3111.  
  3112. FNuser_keypress(window%,icon%,key)
  3113. If a key is pressed while one of your windows has the input focus, or a
  3114. hotkey is pressed, then this function is called. If you don’t use the key
  3115. then return a 0. If you do then return a 1.
  3116. window% = handle of window with input focus.
  3117. icon% = number of icon with caret.
  3118. key = key code. For most keys it is an ASCII number.
  3119.  
  3120. Key          Alone     +Shift    +Ctrl     +Ctrl Shift
  3121. Escape       &1B       &1B       &1B       &1B
  3122. Print (F0)   &180      &190      &1A0      &1B0
  3123. F1-F9        &181-189  &191-199  &1A1-1A9  &1B1-1B9
  3124. Tab          &18A      &19A      &1AA      &1BA
  3125. Copy         &18B      &19B      &1AB      &1BB
  3126. left arrow   &18C      &19C      &1AC      &1BC
  3127. right arrow  &18D      &19D      &1AD      &1BD
  3128. down arrow   &18E      &19E      &1AE      &1BE
  3129. up arrow     &18F      &19F      &1AF      &1BF
  3130. Page down    &19E      &18E      &1BE      &1AE
  3131. Page up      &19F      &18F      &1BF      &1AF
  3132. F10-F12      &1CA-1CC  &1DA-1DC  &1EA-1EC  &1FA-1FC
  3133. Insert       &1CD      &1DD      &1ED      &1FD  
  3134.  
  3135. FNuser_loaddata(path$,window%,icon%,filetype$)
  3136. You load data here. Return a 1 of data was loaded.
  3137. path$ = full pathname of source file.
  3138. window% = handle of window file was dragged on to.
  3139. icon% = number of icon file was dragged on to.
  3140. filetype$ = filetype of file to be loaded. Eg. “FFF”.
  3141.  
  3142. FNuser_menu(window%,icon%)
  3143. IF the specified window (and icon) has a menu which you want to appear when
  3144. Menu is pressed over it, then this function should return the handle of the
  3145. menu.
  3146. window% = handle of window.
  3147. icon% = number of icon.
  3148.  
  3149. FNuser_menuhelp(menu%,item%)
  3150. Return a string to be used for interactive help for the menu item.
  3151. menu% = handle of menu.
  3152. item% = number of item (starting from 1 at the top).
  3153.  
  3154. FNuser_pane(window%)
  3155. IF the window has a pane attached to it, then this function should return
  3156. the window handle of the pane.
  3157. If the window doesn’t have a pane attached, then it should return a -1.
  3158. window% = handle of window.
  3159.  
  3160. FNuser_printing(copy%,page%,totpages%,pagepos%)
  3161. Called repeatedly during printing so application can keep user informed of
  3162. current printing status, and give them the option to cancel printing.
  3163. copy% = number of current copy being printed.
  3164. page% = number of current page being printed.
  3165. totpages% = total number of pages being printed.
  3166. pagepos% = current page being printed (starts at 1 each time and goes up
  3167. to totpages%).
  3168. Return a 1 to cancel printing or a 0 to continue.
  3169.  
  3170. FNuser_savedata(path$,window%)
  3171. When the user is required to save data, this function is called.
  3172. Return a 1 if some data was saved, otherwise return a 0.
  3173. path$ = full pathname of file to save data to.
  3174. window% = handle of save window icon was dragged from.
  3175.  
  3176. FNuser_savefiletype(window%)
  3177. You return the filetype for the save windows. eg. =‘FFF’. For windows that
  3178. aren’t save windows, return an empty string eg. =‘’.
  3179. window% = handle of window%
  3180.  
  3181. FNuser_slider(window%,icon%)
  3182. In order to let DrWimp know that an icon is a slider, return the slider
  3183. icon number.
  3184. window% = handle of window with slider in.
  3185. icon% = icon number of slider back icon.
  3186.  
  3187. FNuser_sliderback(window%,icon%)
  3188. In order to let DrWimp know that an icon is a slider, return the slider
  3189. back icon number.
  3190. window% = handle of window with slider in.
  3191. icon% = icon number of slider.
  3192.  
  3193. PROCuser_closewindow(window%)
  3194. IF this function is called, then the window whose handle is window% has
  3195. just been closed.
  3196.  
  3197. PROCuser_declarefonts
  3198. Any fonts being used in printing must be declared in this function using
  3199. PROCwimp_declarefont or PROCwimp_declarefonth.
  3200.  
  3201. PROCuser_enteringwindow(window%)
  3202. This function is called when the pointer enters a window.
  3203. window% = handle of window.
  3204.  
  3205. PROCuser_leavingwindow(window%)
  3206. This function is called when the pointer leaves a window.
  3207. window% = handle of window.
  3208.  
  3209. PROCuser_menuopen(menu%,icon%)
  3210. Called just before menu is opened.
  3211. menu% = handle of menu jut about to open.
  3212. icon% = icon which pointer is over.
  3213.  
  3214. PROCuser_menuselection(menu%,item%)
  3215. This function is called when the user has chosen a menu item from one of
  3216. your menus.
  3217. menu% = handle of menu.
  3218. item% = item number (top item is 1).
  3219.  
  3220. PROCuser_modechange
  3221. Called when the mode is changed.
  3222.  
  3223. PROCuser_mouseclick(window%,icon%,button%,workx%,worky%)
  3224. IF an icon has been clicked on in one of your windows then this function
  3225. is called.
  3226. window% = handle of window containing icon.
  3227. icon% = number of the icon clicked on.
  3228. button% = which mouse button was pressed. Eg. 4 for Select, 1 for Adjust.
  3229. workx%,worky% = work area coordinates of window window% that pointer was
  3230. at when the mouse button was clicked.
  3231.  
  3232. PROCuser_null
  3233. This is called continuously. So if you are writing something like a clock,
  3234. you would monitor the time here and change any windows as required.
  3235. IF you want to use this function then set NULL=TRUE.
  3236.  
  3237. PROCuser_openwindow(window%,x%,y%,stack%)
  3238. IF this function is called, then the window whose handle is window% has
  3239. been opened with the top left of the window at x%,y% on the screen.
  3240. stack% = window handle to open behind, or -1 for top of window stack, or
  3241. -2 for bottom.
  3242.  
  3243. PROCuser_print(minx%,miny%,maxx%,maxy%,page%)
  3244. Called to draw a page for printing, if user%=1 when PROCwimp_print was
  3245. called.
  3246. minx%,miny% = coordinates of bottom left corner of clipping rectangle
  3247. on page in paper coordinates.
  3248. maxx%,maxy% = coordinates of top right corner of clipping rectangle
  3249. on page in paper coordinates.
  3250. page% = number of page to print.
  3251.  
  3252. PROCuser_printerchange
  3253. Called when the printer settings or the current printer has changed so
  3254. you can update your page measurements, current printer name, etc.
  3255.  
  3256. PROCuser_redraw(window%,minx%,miny%,maxx%,maxy%,printing%,
  3257.                   page%)
  3258. When this function is called, the Wimp wants you to update the specified
  3259. box on the screen. The box is in the work area of the window whose handle
  3260. is window% or if printing then its in paper coordinates where the origin
  3261. is at the bottom left of the paper.
  3262. printing% = TRUE if currently printing, FALSE otherwise.
  3263. page% = number of page currently being printed if printing%=TRUE.
  3264. minx%,miny% = bottom left co-ordinates of box in screen coordinates.
  3265. maxx%,maxy% = top right co-ordinates of box in screen coordinates.
  3266.  
  3267. PROCuser_saveicon(window%,RETURN drag%,RETURN write%,
  3268.                   RETURN ok%)
  3269. This function allows the three save window icons (the one to drag, the
  3270. writeable icon for the filename/pathname, the OK button) to have their
  3271. icon numbers set, if you want to override the defaults.
  3272. Defaults:
  3273.   drag% - 0   write% - 1   ok% - 2
  3274. window% = handle of save window.
  3275.  
  3276. PROCuser_slidervalue(window%,slider%,pcent%)
  3277. When a slider is being dragged or has just finished being dragged, the
  3278. percentage of the slider is passed to this function.
  3279. window% = handle of window with slider in.
  3280. icon% = icon number of slider.
  3281. pcent% = percentage of slider.
  3282.  
  3283. 4. Windows
  3284.  
  3285. FNwimp_getwindowsize(window%,side%)
  3286. Returns the dimension required.
  3287. If side% = 0 returns width. If side% = 1 returns height.
  3288.  
  3289. FNwimp_getwindowtitle(window%)
  3290. Returns a string containing the window title.
  3291. window% = handle of window.
  3292.  
  3293. FNwimp_getwindowworksize(window%,side%)
  3294. Returns the size on OS units of a window work area.
  3295. window% = handle of window.
  3296. If side%=0 the width of the work area is returned. If side%=1 the height
  3297. of the work area is returned.
  3298.  
  3299. FNwimp_iswindowopen(window%)
  3300. Returns a 1 if the window is open otherwise returns a 0.
  3301. window% = handle of window.
  3302.  
  3303. FNwimp_loadwindow(path$,window$,sprite%)
  3304. Loads in a window from a templates file and returns a handle for the
  3305. window.
  3306. path$ = full pathname to templates file.
  3307. window$ = name of window in templates file.
  3308. sprite% = sprite flag. If = 0 then use sprites from wimp area (RMA).
  3309. Otherwise sprite% is a handle to a sprite area.
  3310.  
  3311. PROCwimp_banner(window%,delay%)
  3312. Opens window in the centre of the screen for specified delay before
  3313. closing it.
  3314. window% = handle of window to open.
  3315. delay% = number of seconds to keep window on screen.
  3316.  
  3317. PROCwimp_closewindow(window%)
  3318. Closes a window (removes it from the screen).
  3319. window% = handle of window to close.
  3320.  
  3321. PROCwimp_openwindow(window%,centre%,stack%)
  3322. Opens a window on the screen.
  3323. window% = handle of window to open.
  3324. If centre% = 0 opens window where it was last left on the screen, or
  3325. if it hasn’t been opened before, then where it is positioned in the
  3326. template file.
  3327. If centre% = 1 opens the window centred on the screen (mode
  3328. independent).
  3329. stack% = window handle to open behind, or -1 for top of window stack,
  3330. -2 for bottom, or -3 for current stack position.
  3331.  
  3332. PROCwimp_openwindowat(window%,x%,y%,stack%)
  3333. Opens a window on the screen so the top left of the window is at
  3334. co-ordinates x%,y%.
  3335. window% = handle of window to open.
  3336. stack% = window handle to open behind, or -1 for top of window stack,
  3337. -2 for bottom or -3 for current stack position.
  3338.  
  3339. PROCwimp_putwindowtitle(window%,title$)
  3340. Changes the window title to title$
  3341. window% = handle of window.
  3342.  
  3343. PROCwimp_redrawwindow(whan%)
  3344. Causes the window whose handle is whan% to be redrawn.
  3345.  
  3346. PROCwimp_resizewindow(whan%,width%,height%)
  3347. Resizes the window to the specified width and height which are in OS
  3348. co-ordinates. The work area and the visible area are both set to the
  3349. values.
  3350.  
  3351. 5. Messages
  3352. FNwimp_createmessagemenu(tag$,title$,size%)
  3353. Creates a menu automatically from a Messages file, with the same
  3354. result as FNwimp_createmenu.
  3355. tag$ = tag for menu. Eg: if tag$=“MMenu” then the tag “MMenuT” will
  3356. specify the title, “MMenu1” the first item, “MMenu2” the second etc.
  3357. If title$=“” then the title defined in the message file will be used,
  3358. otherwise title$ will override whatever is defined in the messages
  3359. file.
  3360. IF size%>number of items then the menu is dynamic, ie. the items can
  3361. be increased up to size%.
  3362.  
  3363. FNwimp_messlook0(token$)
  3364. Returns the string in the messages file for the token token$.
  3365.  
  3366. FNwimp_messlook1(token$,a$)
  3367. Returns the string in the messages file for the token token$. Any
  3368. ‘%0’s in the string are replaced with a$ before returning.
  3369.  
  3370. FNwimp_messlook2(token$,a$,b$)
  3371. Returns the string in the messages file for the token token$. Any
  3372. ‘%0’s and ‘%1’s are replaced with a$ and b$ respectively before
  3373. returning.
  3374.  
  3375. PROCwimp_initmessages(path$)
  3376. Reserves blocks of memory and sets up Messages file for use.
  3377. path$ = full pathname of messages file to use.
  3378.  
  3379. 6. Icons
  3380. FNwimp_geticonsize(window%,icon%,side%)
  3381. Returns the dimension required.
  3382. If side% = 0 returns width. If side% = 1 returns height.
  3383.  
  3384. FNwimp_geticonstate(window%,icon%)
  3385. Returns a 1 if the icon is selected and a 0 if it is unselected.
  3386. Useful for reading the state of radio and option icons.
  3387. window% = handle of window containing icon.
  3388. icon% = number of icon.
  3389.  
  3390. FNwimp_geticontext(window%,icon%)
  3391. Returns a string containing the text from the icon.
  3392. window% = handle of window containing icon.
  3393. icon% = icon number.
  3394.  
  3395. FNwimp_getsliderpcent(window%,icon%)
  3396. Returns the percentage of the slider. If the icon is not a slider
  3397. then 0 is returned.
  3398. The number returned is a floating point number in the range 0-100.
  3399. window% = handle of window with slider in.
  3400. icon% = icon number of slider.
  3401.  
  3402. FNwimp_iconbar(sprite$,text$,pos%)
  3403. Places an icon on the iconbar.
  3404. sprite$ = name of sprite to put on iconbar.
  3405. text$ = text to put underneath the icon eg. like the floppy drive
  3406. icon. If text$ = “” then no text will be used, and the icon will
  3407. be positioned correctly.
  3408. pos% = controls the position of the icon. If pos% = 1 then the icon
  3409. will appear on the right. If pos% = 0 then it will appear on the left.
  3410. Returns window handle.
  3411.  
  3412. PROCwimp_colouricontext(window%,icon%,colour%)
  3413. Sets colour of text in icon to colour%.
  3414. window% = handle of window containing icon.
  3415. icon% = number of icon.
  3416. colour% = colour in range 0-15.
  3417.  
  3418. PROCwimp_iconbarsprite(sprite$)
  3419. Changes the sprite used for the iconbar icon to sprite$.
  3420.  
  3421. PROCwimp_iconbit(window%,icon%,bit%,state%)
  3422. Ensures a specific bit of an icon is set to the specified state.
  3423. window% = handle of window contaning icon.
  3424. icon% = number of icon.
  3425. bit% = number of bit to change.
  3426. state% = state to set bit to. Can be 0 or 1.
  3427.  
  3428. PROCwimp_icondisable(window%,icon%)
  3429. Greys out icon so it cannot be selected.
  3430. window% = handle of window containing icon.
  3431. icon% = number of icon.
  3432.  
  3433. PROCwimp_iconenable(window%,icon%)
  3434. Un-greys out icon so it can be selected.
  3435. window% = handle of window containing icon.
  3436. icon% = number of icon.
  3437.  
  3438. PROCwimp_iconselect(window%,icon%,state%)
  3439. Selects (inverts) and un-selects icon.
  3440. window% = handle of window containing icon.
  3441. icon% = number of icon.
  3442. If state% = 0 icon is un-selected. If state% = 1 icon is selected.
  3443.  
  3444. PROCwimp_losecaret
  3445. Removes the caret from the icon it is in.
  3446.  
  3447. PROCwimp_putcaret(window%,icon%)
  3448. Puts the caret in the icon.
  3449. window% = handle of window containing icon.
  3450. icon% = number of icon.
  3451.  
  3452. PROCwimp_puticonbartext(text$)
  3453. If the iconbar icon has text underneath it then it is replaced by text$.
  3454.  
  3455. PROCwimp_puticontext(window%,icon%,text$)
  3456. If the icon is indirected then the text in the icon is replaced with
  3457. text$. If the icon is indirected then an error is caused.
  3458. window% = handle of window containing icon.
  3459. icon% = number of icon.
  3460.  
  3461. PROCwimp_putsliderpcent(window%,icon%,pcent)
  3462. Sets the percentage of the slider. If the icon is not a slider then
  3463. this is ignored.
  3464. window% = handle of window with slider in.
  3465. icon% = icon number of slider.
  3466. pcent = percentage to set.
  3467. Can be integer or floating point number, but must have the range 0-100.
  3468.  
  3469. 7. Menus
  3470. FNwimp_createmenu(menu$,size%)
  3471. Creates a menu structure from the string menu$. The menu handle is
  3472. returned.
  3473. For more information on menu$ see the manual.
  3474. IF size%>number of items then the menu is dynamic, ie. the items can
  3475. be increased up to size%.
  3476.  
  3477. FNwimp_createmenuarray(array$(),size%)
  3478. Creates a menu from the array supplied. Each item of the menu is in a
  3479. seperate element of the array. eg:
  3480. array$(3)=‘Info’. The first element is the menu title, and the last must
  3481. be ‘END’.
  3482. array$() = array to get items from.
  3483. size% = maximum number of elements to allocate room for (doesn’t have to
  3484. be the current number).
  3485. Returns a handle to the menu.
  3486.  
  3487. FNwimp_createmessagemenu(tag$,title$,size%)
  3488. Creates a menu automatically from a Messages file, with the same result
  3489. as FNwimp_createmenu.
  3490. tag$ = tag for menu. Eg: if tag$=“MMenu” then the tag “MMenuT” will
  3491. specify the title, “MMenu1” the first item, “MMenu2” the second etc.
  3492. If title$=“” then the title defined in the message file will be used,
  3493. otherwise title$ will override whatever is defined in the messages file.
  3494. IF size%>number of items then the menu is dynamic, ie. the items can
  3495. be increased up to size%.
  3496.  
  3497. FNwimp_getmenutext(menu%,item%)
  3498. Returns a string containing the text of the menu item.
  3499. menu% = handle of menu.
  3500. item% = number of item (top item is 1).
  3501.  
  3502. FNwimp_getmenutitle(menu%)
  3503. Returns a string containing the title of the menu.
  3504. menu% = handle of menu.
  3505.  
  3506. FNwimp_menusize(menu%)
  3507. Returns the number of entries in the menu.
  3508. menu% = handle of menu.
  3509.  
  3510. PROCwimp_attachsubmenu(menu%,item%,submenu%)
  3511. Attaches a submenu to a menu item.
  3512. menu% = handle of menu.
  3513. item% = item number (top item is 1).
  3514. submenu% = handle of submenu or window handle.
  3515.  
  3516. PROCwimp_menuclose
  3517. Closes the currently active menu.
  3518.  
  3519. PROCwimp_menudisable(menu%,item%)
  3520. Greys out the menu item so it is un-selectable.
  3521. menu% = handle of menu.
  3522. item% = item number (top item is 1).
  3523.  
  3524. PROCwimp_menudottedline(menu%,item%)
  3525. Adds a dotted line to the menu below the item.
  3526. menu% = handle of menu.
  3527. item% = number of item (top item is 1).
  3528.  
  3529. PROCwimp_menuenable(menu%,item%)
  3530. Un-greys out the menu item so it is selectable.
  3531. menu% = handle of menu.
  3532. item% = item number (top item is 1).
  3533.  
  3534. PROCwimp_menupopup(menu%,bar%,x%,y%)
  3535. Brings up the menu whose handle is menu% at the co-ordinates x%,y%.
  3536. If bar%=1 then the menu will be positioned as for an iconbar menu,
  3537. otherwise use 0.
  3538.  
  3539. PROCwimp_menutick(menu%,item%)
  3540. If the item doesn’t have a tick next to it then this function places
  3541. one. If the item does have a tick then it is removed.
  3542. menu% = handle of menu.
  3543. item% = item number (top item is 1).
  3544.  
  3545. PROCwimp_menuwrite(menu%,item%,length%)
  3546. Makes the menu item writeable.
  3547. menu% = handle of menu.
  3548. item% = number of item (top item is 1).
  3549. length% = maximum length of text allowed to be entered.
  3550.  
  3551. PROCwimp_putmenuitem(menu%,item%,item$)
  3552. If the menu is dynamic then item$ will be put into menu item item%.
  3553. Any items below will be shuffled down. If item% is bigger than the
  3554. current number of items+1, then it will be added to the bottom.
  3555. menu% = handle of menu.
  3556.  
  3557. PROCwimp_putmenutext(menu%,item%,text$)
  3558. Replaces menu items text with text$.
  3559. menu% = handle of menu.
  3560. item% = number of item (Top item is 1).
  3561.  
  3562. PROCwimp_putmenutitle(menu%,title$)
  3563. Changes the title of the menu.
  3564. If the title>11 characters then it is truncated.
  3565. menu% = handle of menu.
  3566. title$ = new title.
  3567.  
  3568. PROCwimp_recreatemenu(menu%,menu$)
  3569. Rebuilds the menu using the string menu$. More items can be included
  3570. than the first time as long as you don’t go over the pre-defined limit.
  3571. menu% = handle of menu to rebuild.
  3572.  
  3573. PROCwimp_recreatemenuarray(menu%,array$())
  3574. Rebuilds the menu using the items in the array. The first array item
  3575. (array$(0)) is the menu title, and the last has to be ‘END’.
  3576. Things like ticks and dotted lines are reset.
  3577. menu% = handle of menu to rebuild
  3578. array$() = array to get items from.
  3579.  
  3580. PROCwimp_removemenuitem(menu%,item%)
  3581. Removes the item from the menu. Any items below are shuffled up. If
  3582. there is only one item on the menu, then it cannot be removed.
  3583. menu% = handle of menu. item% = number of item to remove.
  3584.  
  3585. 8. Sprites
  3586. FNwimp_getspritesize(sprite$,sprite%,side%)
  3587. Returns the width or height in OS units of a sprite.
  3588. sprite$ = name of sprite.
  3589. sprite% = handle of sprite area containing sprite.
  3590. If side%=0 then returns width of sprite.
  3591. If side%=1 then returns height of sprite.
  3592.  
  3593. FNwimp_loadsprites(path$,ptr%)
  3594. Loads a spritefile into a block of memory at ptr%.
  3595. Returns a new value of ptr% to load the next in.
  3596. path$ = full pathname to sprite file.
  3597.  
  3598. FNwimp_measurefile(path$)
  3599. Returns the size in bytes needed to store the spritefile.
  3600. Always use this as opposed to any other form of measurement.
  3601. path$ = full pathname of spritefile.
  3602.  
  3603. PROCwimp_rendersprite(sprite$,sprite%,bx%,by%,minx%,miny%,
  3604.                   maxx%,maxy%)
  3605. Renders a sprite on the screen at the specified coordinates, using
  3606. the clipping rectangle.
  3607. sprite$ = name of sprite to plot.
  3608. sprite% = handle of sprite area containing sprite.
  3609. bx%,by% = screen coordinates to put bottom left corner of sprite at.
  3610. minx%,miny% = coordinates of bottom left corner of clipping rectangle
  3611. in screen coordinates.
  3612. maxx%,maxy% = coordinates of top right corner of clipping rectangle
  3613. in screen coordinates.
  3614.  
  3615. PROCwimp_renderwindowsprite(window%,sprite$,sprite%,bx%,by%,
  3616.             minx%,miny%,maxx%,maxy%)
  3617. Renders a sprite in a window. The window must have its auto-redraw
  3618. flag unset.
  3619. window% = handle of window to render sprite in.
  3620. sprite$ = name of sprite to render.
  3621. sprite% = handle of sprite area containing sprite.
  3622. bx%,by% = work area coordinates of where to put bottom left of sprite.
  3623. minx%,miny% = coordinates of bottom left corner of clipping rectangle
  3624. in screen coordinates.
  3625. maxx%,maxy% = coordinates of top right corner of clipping rectangle
  3626. in screen coordinates.
  3627.  
  3628. 9. Drawfiles
  3629. FNwimp_getdfilesize(dfile%,side%)
  3630. Returns the dimension required.
  3631. If side% = 0 returns width. If side% = 1 returns height.
  3632.  
  3633. FNwimp_loaddfile(path$,ptr%)
  3634. Loads a drawfile into a block of memory at ptr%.
  3635. Returns a new value of ptr% to load the next in.
  3636. path$ = full pathname of drawfile.
  3637.  
  3638. FNwimp_measurefile(path$)
  3639. Returns the size in bytes needed to store the drawfile.
  3640. Always use this as opposed to any other form of measurement.
  3641. path$ = full pathname of drawfile.
  3642.  
  3643. PROCwimp_initdfiles
  3644. Initialises various blocks of memory ready to use with drawfiles.
  3645.  
  3646. PROCwimp_render(dfile%,bx%,by%,xl%,yl%,xh%,yh%)
  3647. Renders a drawfile at bx%,by% using the clipping rectangle
  3648. xl%,yl%,xh%,yh%. All coordinates are in OS units.
  3649. dfile% = handle of drawfile to render.
  3650. bx%,by% = coordinates of where to put bottom left corner of drawfile.
  3651. xl%,yl% = coordinates of bottom left corner of clipping rectangle
  3652. in screen coordinates.
  3653. xh%,yh% = coordinates of top right corner of clipping rectangle
  3654. in screen coordinates.
  3655.  
  3656. PROCwimp_renderwindow(w%,dfile%,tx%,ty%,xl%,yl%,xh%,yh%)
  3657. Renders a drawfile in a window. The window must have its auto-redraw
  3658. flag unset.
  3659. w% = handle of window.
  3660. dfile% = handle of drawfile to render.
  3661. tx%,ty% = work area coordinates of where to put bottom left corner of
  3662. drawfile.
  3663. xl%,yl% = coordinates of bottom left corner of clipping rectangle in
  3664. screen coordinates.
  3665. xh%,yh% = coordinates of top right corner of clipping rectangle in
  3666. screen coordinates.
  3667.  
  3668. PROCwimp_savedfile(path$,dfile%)
  3669. Saves a drawfile into a file.
  3670. dfile% = handle of drawfile to save.
  3671. path$ = full pathname to save to.
  3672.  
  3673. 10. Text
  3674. FNwimp_fontcolour(fr%,fg%,fb%)
  3675. Returns control codes in a string to change the current font colour.
  3676. Useful for using in the middle of a string of text being plotted using
  3677. a font.
  3678. fr%,fg%,fb% = red, green and blue components of the foreground colour
  3679. respectively, in the range 0-255.
  3680.  
  3681. FNwimp_fontunderline(on%)
  3682. Returns control codes in a string to turn underlining on or off. Useful
  3683. for using in the middle of a string of text being plotted using a font.
  3684. If on%=0 turns underlining off. If on%=1 turns underlining on.
  3685.  
  3686. FNwimp_getfont(font$,size%)
  3687. Obtains a font handle for a particular font at a particular size.
  3688. font$ = name of font, period seperated. eg: “Trinity.Medium”.
  3689. size% = point size of font.
  3690. Returns 0 if the font cannot be found.
  3691.  
  3692. FNwimp_gettextsize(text$,font$,size%,side%)
  3693. Returns the size of some text in a particular font in OS units.
  3694. text$ = string to measure.
  3695. font$ = name of font, period seperated, eg: “Trinity.Medium”.
  3696. size% = point size of font.
  3697. If side%=0 then the width is returned. If side%=1 then the height is
  3698. returned.
  3699.  
  3700. FNwimp_gettextsizeh(texts%,font%,side%)
  3701. Returns the size of some text in a particular font in OS units, using
  3702. a font handle.
  3703. text$ = string to measure.
  3704. font% = handle of font.
  3705. If side%=0 then the width is returned. If side%=1 then the height is
  3706. returned.
  3707.  
  3708. FNwinp_fontchangeh(font%)
  3709. Returns control codes in a string to change the current font. Useful
  3710. for using in the middle of a string of text being plotted using a
  3711. font.
  3712. font% = handle of font to change to.
  3713.  
  3714. PROCwimp_deskplottext(t$,c%,x%,y%,fr%,fg%,fb%,br%,bg%,bb%)
  3715. Plots text using the current desktop font (always the System Font
  3716. on pre-RISC OS 3.50).
  3717. t$ = string to plot.
  3718. If c%=1 then text is horizontally centred around x%.
  3719. If c%=0 then left side of text is placed at x%.
  3720. x%,y% = coordinates to plot the text at.
  3721. fr%,fg%,fb% = foreground colour red, green and blue amounts in
  3722. range 0-255.
  3723. br%,bg%,bb% = background colour red, green and blue amounts in
  3724. range 0-255.
  3725.  
  3726. PROCwimp_deskplotwindowtext(window%,t$,c%,x%,y%,fr%,fg%,fb%,
  3727.         br%,bg%,bb%,minx%,miny%,maxx%,maxy%)
  3728. Plots text using the current desktop font (always the System Font on
  3729. pre-RISC OS 3.50) in a window.
  3730. window% = handle of window to plot in.
  3731. t$ = string to plot.
  3732. If c%=1 then text is horizontally centred around x%.
  3733. If c%=0 then left side of text is placed at x%.
  3734. x%,y% = coordinates to plot the text at.
  3735. fr%,fg%,fb% = foreground colour red, green and blue amounts in
  3736. range 0-255.
  3737. br%,bg%,bb% = background colour red, green and blue amounts in
  3738. range 0-255.
  3739.  
  3740. PROCwimp_losefont(font%)
  3741. Forgets about a font. Should be called when you have finished with
  3742. the font, eg. when the application is quitting.
  3743. font% = handle of font to loose.
  3744.  
  3745. PROCwimp_plottext(t$,f$,s%,x%,y%,fr%,fg%,fb%,br%,bg%,bb%)
  3746. Plots text using a font.
  3747. t$ = string to plot.
  3748. f$ = name of font period spaced eg: “Trinity.Medium”
  3749. s% = point size of font.
  3750. x%,y% = screen coordinates to plot the text at.
  3751. fr%,fg%,fb% = foreground colour red, green and blue amounts in
  3752. range 0-255.
  3753. br%,bg%,bb% = background colour red, green and blue amounts in
  3754. range 0-255.
  3755.  
  3756. PROCwimp_plottexth(text$,font%,x%,y%,fr%,fg%,fb%,br%,bg%,bb%)
  3757. Plots text using a font (with font handle).
  3758. t$ = string to plot.
  3759. font% = handle of font.
  3760. s% = point size of font.
  3761. x%,y% = coordinates to plot the text at.
  3762. fr%,fg%,fb% = foreground colour red, green and blue amounts in
  3763. range 0-255.
  3764. br%,bg%,bb% = background colour red, green and blue amounts in
  3765. range 0-255.
  3766.  
  3767. PROCwimp_plotwindowtext(window%,t$,f$,s%,x%,y%,fr%,fg%,fb%,br%,
  3768.         bg%,bb%,minx%,miny%,maxx%,maxy%)
  3769. Plots some text in a window.
  3770. window% = handle of window to plot in.
  3771. t$ = string to plot.
  3772. f$ = name of font to use, period seperated, eg: “Trinity.Medium”.
  3773. s% = point size of font.
  3774. x%,y% = work area coordinates to plot text at.
  3775. fr%,fg%,fb% = foreground colour red, green and blue components
  3776. respectively, in the range 0-255.
  3777. br%,bg%,bb% = background colour red, green and blue components in
  3778. the range 0-255
  3779. minx%,miny% = coordinates of bottom left corner of clipping rectangle.
  3780. maxx%,maxy% = coordinates of top right corner of clipping rectangle.
  3781.  
  3782. PROCwimp_plotwindowtexth(window%,t$,font%,x%,y%,fr%,fg%,fb%,
  3783.         br%,bg%,bb%,minx%,miny%,maxx%,maxy%)
  3784. Plots some text in a window using font handle.
  3785. window% = handle of window to plot in.
  3786. t$ = string to plot.
  3787. font% = handle of font to use.
  3788. s% = point size of font.
  3789. x%,y% = work area coordinates to plot text at.
  3790. fr%,fg%,fb% = foreground colour red, green and blue components
  3791. respectively, in the range 0-255.
  3792. br%,bg%,bb% = background colour red, green and blue components
  3793. respectively, in the range 0-255
  3794. minx%,miny% = coordinates of bottom left corner of clipping rectangle.
  3795. maxx%,maxy% = coordinates of top right corner of clipping rectangle.
  3796.  
  3797. 11. Printing
  3798. FNwimp_getpapersize(side%,type%)
  3799. Returns various information about the current paper size.
  3800. IF side%=0 then a horizonal measurement is returned. If side%=1 then
  3801. a vertical measurement is returned. Which measurement is determined
  3802. by type%.
  3803. If type%=0 then the width or height is returned.
  3804. If type%=1 then the left or bottom margin is returned.
  3805. If type%=2 then the printable width or printable height is returned.
  3806. If type%=3 then the right or top margin is returned.
  3807.  
  3808. FNwimp_getpdrivername
  3809. If a printer driver is loaded, then this function returns a string
  3810. containing the name of the printer driver. Check to make sure one
  3811. is loaded first with FNwimp_pdriverpresent.
  3812.  
  3813. FNwimp_papertoscreen(window%,coord%,side%)
  3814. Converts a paper x or y coordinate to a screen x or y coordinate.
  3815. window% = handle of window whose work area to use.
  3816. coord% = coordinate (x or y).
  3817. If side%=0 then coord% is a x coordinate, and a x coordinate is
  3818. returned.
  3819. If side%=1 then coord% is a y coordinate, and a y coordinate is
  3820. returned.
  3821.  
  3822. FNwimp_papertowork(coord%,side%)
  3823. Converts a paper x or y coordinate to a work area x or y coordinate.
  3824. coord% = coordinate (x or y).
  3825. If side%=0 then coord% is a x coordinate, and a x coordinate is
  3826. returned.
  3827. If side%=1 then coord% is a y coordinate, and a y coordinate is
  3828. returned.
  3829.  
  3830. FNwimp_pdriverpresent
  3831. Checks to see if a printer driver is loaded.
  3832. Returns a 0 if one isn’t, returns a 1 if one is.
  3833.  
  3834. FNwimp_screentopaper(window%,coord%,side%)
  3835. Converts a screen x or y coordinate to a paper x or y coordinate.
  3836. window% = handle of window whose work area to use.
  3837. coord% = coordinate (x or y).
  3838. If side%=0 then coord% is a x coordinate, and a x coordinate is
  3839. returned.
  3840. If side%=1 then coord% is a y coordinate, and a y coordinate is
  3841. returned.
  3842.  
  3843. FNwimp_worktopaper(coord%,side%)
  3844. Converts a work area x or y coordinate to a paper x or y coordinate.
  3845. coord% = coordinate (x or y).
  3846. If side%=0 then coord% is a x coordinate, and a x coordinate is
  3847. returned.
  3848. If side%=1 then coord% is a y coordinate, and a y coordinate is
  3849. returned.
  3850.  
  3851. PROCwimp_declaredfilefonts(drawfile%)
  3852. Declares the fonts used in a drawfile (especially) for postscript
  3853. printing.
  3854. drawfile% = handle of drawfile to be printed.
  3855.  
  3856. PROCwimp_declarefont(font$)
  3857. Declares a font for printing.
  3858. font$ = name of font to declare, period seperated. eg:
  3859. “Trinity.Medium”.
  3860.  
  3861. PROCwimp_declarefonth(font%)
  3862. Declares a font for printing using font handle.
  3863. font% = handle of font to declare.
  3864.  
  3865. PROCwimp_print(user%,window%,fpage%,lpage%,perpage%,copies%)
  3866. Initiates printing of a document.
  3867. IF user%=0 PROCuser_redraw is called to draw the pages, with
  3868. printing% set to TRUE and the clipping rectangle set to the page
  3869. coordinates. If user%=1 PROCuser_print is called to draw the pages.
  3870. window% = handle of window to redraw if user%=0.
  3871. fpage% = page number of first page to print.
  3872. lpage% = page number of last page to print.
  3873. perpage% = number of A4 pages to fit onto a physical A4 page.
  3874. Can be 1, 2 or 4.
  3875. copies% = number of copies of the document to print.
  3876.  
  3877.  
  3878. EOF
  3879.  
  3880.