home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / tcl / tcl_1 / !Tcl_doc_Manual_TeX < prev    next >
Encoding:
Text File  |  1996-03-29  |  51.1 KB  |  1,419 lines

  1. % (c) C.T.Stretch 1996
  2. \documentstyle[12pt,a4wide]{report}
  3. \title{Writing RiscOS Applications using Tcl and w}
  4. \author{C.T.Stretch}
  5. \date{March 29,1996\\ For w version 1.2}
  6. \begin{document}
  7. \pagestyle{headings}
  8. \maketitle
  9. \begin{titlepage}
  10. \begin{center}
  11. {\Large Introduction to Tcl and w}
  12. \end{center}
  13.  
  14. This manual describes the use of the w extensions of Tcl to write desktop
  15. application for machines running RiscOS.
  16.  
  17. Tcl (pronounced tickle ) is a simple interpreted scripting language.
  18. It is extensible in that it is easy to add commmands to Tcl, and embeddable
  19. in that it can be included in other applications. 
  20.  
  21. Tcl was invented and implemented by John K.Ousterhout, originally for unix
  22. systems. It is usually used with an extension to the x windowing system called 
  23. Tk, either embedded in applications, or using a general purpose Tcl/Tk program
  24. called wish. Tcl can also be used from the command line using another program
  25. called tclsh. Unix Tcl is split into a generic part and a POSIX extension, 
  26. containing the unix-specific operations such as file handling.
  27.  
  28. The w extensions provide simple interfaces to the RiscOS desktop in Tcl.
  29. they do not attempt to be compatible with, or as comprehensive as Tk.
  30. They  provide an iconbar icon, menus, simple dialog boxes, scrolling windows for
  31. text display, and windows for draw type graphics. They can run command line
  32. tasks using the taskwindow system.
  33.  
  34. The w extensions are usually run from program called shade. They could also
  35. be embedded in RiscOS applications in c. Tasks running w can communicate
  36. with each other.
  37.  
  38. The RiscOS extensions provide equivalent functions to most of the POSIX 
  39. extensions that are appropriate for RiscOS.
  40.  
  41. This manual covers wimp programming using w. It also contains a brief
  42. description of the RiscOS extensions and a list of Tcl commands.
  43.  
  44. The manual does not attempt to teach Tcl programming. You will need to be
  45. familiar with this before attempting to use w. Possible sources of Tcl
  46. documentation include
  47. \begin{enumerate}
  48. \item The book  "Tcl and the Tk Toolkit"
  49. by J.K.Ousterhout (Addison Wesley 1994) ISBN 0-201-63337-X.
  50. \item The online documentation.
  51. \item A manual in html format avaliable by ftp as
  52.  
  53. \verb|ftp://ftp.bdt.com/home/elf/pub/tcltk-man-html6.tar.gz|
  54. \end{enumerate}
  55.  
  56. A RiscOS application using shade will need to be provided with the usual
  57. application directory and files. The !Run file should call shade with
  58. argument a Tcl script file. The TclNew application will create a basic
  59. version of these.
  60.  
  61. \end{titlepage}
  62. \tableofcontents
  63. \sloppy
  64.  
  65. \chapter{Basics}
  66.  
  67. \section{Introduction}
  68.  
  69. The w commands operate by installing a selection of scripts that are called when
  70. various wimp events such as mouse clicks occur.
  71.  
  72. \subsubsection{Example}
  73. \begin{verbatim}
  74.       w_init myprog
  75.       w_bar  -click {clickproc}
  76.       proc clickproc {}\
  77.       { set res [w_error "Someone has clicked on my icon" -ok -cancel]
  78.         if {res==0} exit
  79.       }
  80. \end{verbatim}
  81.  
  82. The \verb|w_init| command starts up the wimp. The application will have name
  83. ``myprog'' in the task display list.
  84. \verb|w_bar| puts an wimp sprite called !myprog on the iconbar.
  85.  If it is clicked on the script ``clickproc'' is interpreted.
  86.  
  87. The clickproc script opens a wimp error window with ``OK'' and ``Cancel''
  88. icons. If the cancel icon is clicked \verb|res| is set to zero and the
  89. application exits.
  90.  
  91. \subsection{Percent substitution}
  92.  Before the scripts are interpreted \%-substitution takes place in order to pass
  93. any necessary arguments to the script. The script is scanned for \% characters.
  94. If the \% is followed by a lower case letter the percent and letter are replaced
  95. by a string, otherwise the \% but not the character is dropped.
  96.  The avaliable substitution letters depend on the event concerned and are
  97. summarized below. Fuller details can be found in later chapters.
  98. \begin{center}
  99. \begin{tabular}{|c|c|l|}
  100. \hline
  101. letter&Event&value\\ \hline
  102. \verb|%b|&Mouse button events&\verb"a|s[S][C]"\\
  103. \verb|%x|&Mouse clicks in draw diagrams&x--coordinate\\
  104. \verb|%y|&Mouse clicks in draw diagrams&y--coordinate\\
  105. \verb|%d|&Dialog box actions&\verb|<tag>|\\
  106. \verb|%t|&Save and load requests&filetype\\
  107. \verb|%w|&Window and menu events&identifier\\
  108. \verb|%o|&Taskwindow output&the output\\
  109. \verb|%n|&Taskwindow output or quit&task identifier\\ \hline
  110. \end{tabular}
  111. \end{center}
  112.  Using other letters can have unpredictable results.
  113.  
  114. \subsection{Error handling}
  115.  
  116. If an uncaught error occurs while interpreting these scripts, or while
  117. interpreting the source file after \verb|w_init| has been called two things
  118. happen
  119. \begin{enumerate}
  120. \item The global variable \verb|w_where| is set to a string indicating which
  121. script the error occured in, for example ``iconbar click'' if the error occurs
  122. when interpreting a script after the iconbar icon is clicked.
  123. \item The contents of global variable \verb|w_debug| are interpreted.
  124. \end{enumerate}
  125.  
  126. \verb|w_init| sets \verb|w_debug| to
  127.  
  128. \begin{verbatim}
  129.     "if {![w_error \"Error in $w_where :- $errorInfo\" -ok -cancel]} exit"
  130. \end{verbatim}
  131.  
  132.     This puts up a wimp error box indicating the place and nature of the error.
  133.     If you click on ``Cancel'' the program exits, on ``OK'' and it continues,
  134.     abandoning the script.
  135.  
  136. {\bf Note:} If an error occurs before a call to \verb|w_bar| and you continue
  137. you will not have an iconbar icon and must quit from the task display.
  138.  
  139. The file \verb|!Tcl.library.debug| contains a slightly more sophisticated
  140.  debugging system. To use it put the line
  141. \begin{verbatim}
  142.        source {<tcl$Dir>.library.debug}
  143. \end{verbatim}
  144.  
  145.     in your code {\em after} the call to \verb|w_init|.
  146.  
  147. \subsection{Return values from event scripts}
  148.  
  149. An event script normally returns the result of its last command.
  150. The \verb|return| command can be used to return at any stage with an optional
  151. result.
  152.  
  153. Some event handlers make use of the returned values, for example if a script
  154. is run in response to a click on an action button in a dialog box the box
  155. will be closed if the script returns zero. Such scripts return small integer
  156. values. String constants are provided as an alternative to the numbers to
  157. make scripts more readable.
  158.  
  159. \begin{center}
  160. \begin{tabular}{|c|c|c|c|c|}
  161. \hline
  162. Number&Saving&Action buttons&Close window&Options\\ \hline
  163. 0&close&close&close&off\\
  164. 1&show&show&show&on\\
  165. 2&failclose&&hide&\\
  166. 3&failshow&&&\\ \hline
  167. \end{tabular}
  168. \end{center}
  169.  
  170. An empty string is considered equivalent to zero.
  171.  
  172. Details of the response to these values are given below.
  173.  
  174. \section{Command descriptions}
  175.  
  176. The descriptions of commands and data in this manual use the following
  177. conventions
  178. \begin{center}
  179. \begin{tabular}{|c|c|c|}
  180. \hline
  181. &Example&Meaning \\ \hline
  182. Angle brackets&\verb|<taskname>|&Substitute an object of the required type\\
  183. Brackets&\verb|[-ok]|&Optional.\\
  184. Braces&\verb|{<component>}|&One or more of.\\
  185. Quotes&\verb|'<'|&Include the text literally.\\ \hline
  186. \end{tabular}
  187. \end{center}
  188.  
  189. Command syntax descriptions may not be complete. Information such as which
  190. options can go together or whether a specific order is required is given
  191. in the following text.
  192.  
  193. \section{Commands}
  194.  
  195. \begin{center}
  196. \begin{tabular}{|l|}
  197. \hline
  198. \verb|w_init <taskname> [<spritefilename>]|\\ \hline
  199. \verb|w_bar [-menu <menudescription>] [-click <script>] [-drag <script>]|\\ \hline
  200. \verb|w_error <string> [-ok] [-cancel]|\\ \hline
  201. \verb|w_info <name>|\\ \hline
  202. \end{tabular}
  203. \end{center}
  204.  
  205. The \verb|w_init| command initializes the w extensions and registers
  206. the task as a wimp application. It must be called before any of the other w 
  207. commands. It can be called once only.
  208. \verb|<taskname>| has a maximum of eight characters, it is used for the
  209. program name in the task display. It is also used as a default window
  210. title and  as a prefix for taskwindow tasknames. If the application puts
  211. an icon on the iconbar using the \verb|w_bar| command the sprite used will
  212. be called \verb|!<taskname>|.
  213. If the optional \verb|<spritefile>| is given, a user sprite area
  214. is set up and the sprite file \verb|<<taskname>$Dir>.<spritefile>|
  215. is loaded. These sprites can be used in draw diagrams and
  216. dialog boxes.
  217.  
  218. The \verb|w_bar| command puts an icon called \verb|!<taskname>| from the
  219. wimp sprite area on the iconbar. (You should include such an icon in your
  220. application's \verb|!Sprites| and \verb|!Sprites22| files if you want to use
  221. \verb|w_bar|). You can attach a menu, a script to be called when the icon
  222. is clicked on, and a script to be called when an icon is dropped on your
  223. icon. Before the click script is run the \%b substitution is set to a
  224. string representing the mouse button used and the modifier keys held down.
  225. The string consists of ``a'' for alter or ``s'' for select, followed by
  226. ``S'' if the shift key is down then folowed by ``C'' for the control key.
  227. Before the drag script is run the global variable \verb|w_file| is set to the
  228. filename and the \%t substitution to the file type.
  229.  
  230. The \verb|w_error| command displays a wimp error box containing \verb|<string>|
  231. truncated to 200 characters. The options give the box ``OK'' and ``Cancel''
  232. buttons. If neither are given an ``OK'' button is provided. The command
  233. returns 1 if the ``OK'' button was used and 0 for ``Cancel''.
  234.  
  235. The \verb|w_info| command returns information on the state of the w system.
  236. The possible name parameters are detailed in the chapters below.
  237.  
  238. \section{Common parameters}
  239.  
  240. \subsection{Lengths}
  241.        Lengths in w commands are given by a (possibly floating point) number
  242. possibly followed immediately by a single letter unit. If no unit letter
  243. is given the length is in OS units. The unit letters are
  244.  
  245.  
  246. \begin{center}
  247. \begin{tabular}{|cl|}
  248. \hline
  249. \verb|<letter>|&Unit\\ \hline
  250.                  i &inches\\
  251.                  m &millimeters\\
  252.                  c ¢imeters\\
  253.                  p &points\\
  254.                  d &draw units\\ \hline
  255. \end{tabular}
  256. \end{center}
  257.  
  258. \subsubsection{Example}
  259. \begin{verbatim}
  260.       w_text mywind create -width 6.5i
  261. \end{verbatim}
  262.  
  263. Creates a text window 6.5 inches wide.
  264.  
  265. \subsection{Fonts}
  266.  
  267. Fonts can be specified in w in two ways
  268.  
  269. \begin{center}
  270. \begin{tabular}{|lcl|}
  271. \hline
  272. \verb|<font>|&$=$&\verb|f<name>[@<length>]|\\
  273. \verb|<font>|&$=$&\verb|F<fontname>[@<length>]|\\ \hline
  274. \end{tabular}
  275. \end{center}
  276.  
  277.     The second form takes a pathname in a font directory. The first looks
  278. up \verb|fonts(<name>)| in the global array \verb|fonts| to obtain a fontname.
  279.  
  280.     The array ``font''  is usually set up with standard names of font types,
  281. allowing users to specify their preferences.
  282.  
  283. \begin{center}
  284. \begin{tabular}{|ll|}
  285. \hline
  286. \verb|<name>|&Use\\ \hline
  287.                      n  & normal font\\
  288.                      i  & italic font\\
  289.                      b  & bold font\\
  290.                      t  & typewriter (monospaced) font\\
  291.                      a  & alternative font\\
  292.                         & (e.g. sans-serif if the others have serifs)\\ \hline
  293. \end{tabular}
  294. \end{center}
  295.  
  296. \subsubsection{Example}
  297. \begin{verbatim}
  298.       set fonts(n) Trinity.Medium
  299.       set fonts(i) Trinity.Italic
  300.       set fonts(b) Trinity.Bold
  301.       w_text mytext write "This is |fi|italic, |fn| this is |fb|bold"
  302.       w_draw mydiagram text (1,1) "This is big and bold" -FTrinity.Bold@40p
  303. \end{verbatim}
  304.  
  305. The first three lines set suitable values in the fonts array. The next two
  306. put text in a text document and a draw diagram.
  307.  
  308. \subsection{Colours}
  309. Colours can be specified in w in two ways
  310.  
  311. \begin{center}
  312. \begin{tabular}{|lcl|}
  313. \hline
  314. \verb|<colour>|&$=$&\verb|<number>:<number>:<number>|\\
  315. \verb|<colour>|&$=$&\verb|<name>|\\ \hline
  316. \end{tabular}
  317. \end{center}
  318.  
  319. In the first form they are given by three numbers in the range 0 to 255
  320. representing the red, green and blue components separated by colons.
  321. Alternatively if a name, not beginning with a digit, is given it
  322. is looked up as \verb|colours(<name>)| in the global array \verb|colours| 
  323. to obtain a number sequence of the above form.
  324. The name \verb"none" gives a transparent ``colour'' for draw path objects.
  325.  
  326. \subsubsection{Example}
  327. \begin{verbatim}
  328.       set colours(red) 255:0:0
  329.       w_text mytext create -fg red -bg 200:200:255
  330. \end{verbatim}
  331.  
  332. This creates a text window with red text on a pale blue background.
  333.  
  334. \subsection{Identifiers}
  335.      Several w commands such as the \verb|w_text| command for creating
  336. text documents take an \verb|<identifier>| parameter. The identifier
  337. can be any Tcl string, usually a name.
  338.  
  339. This is passed to the object when it is created, and used to identify the object
  340. in other calls. Two objects of the same type must be given different
  341. identifiers.
  342.  
  343. \subsubsection{Example}
  344. \begin{verbatim}
  345.        w_text output create
  346.        w_text output print "Hello World"
  347.        w_text output open
  348. \end{verbatim}
  349.  
  350. This creates a scrolling text document with identifier ``output'',
  351. puts some text in it and then opens a window on it.
  352.  
  353. \subsection{File types}
  354. File types can be specified for some commands. They can be a number in decimal
  355. octal or hexadecimal, or a name. Special names are ``directory'' and
  356. ``application'', other names are looked up in system variables
  357. \verb|File$Type_<name>|.
  358.  
  359. \subsubsection{Examples}
  360. \begin{verbatim}
  361.        glob "$.*" Tcl
  362.        glob "$.*" 0x12e
  363.        w_box newbox create tclnew\
  364.        { vlist {save application outdir {savedrag $w_file }}
  365.          {hlist {action Cancel} {default Save {saveclick }}}
  366.        }
  367. \end{verbatim}
  368.  
  369. The two \verb|glob| commands both give a list of all files of type Tcl in
  370. the root directory.
  371. The \verb|w_box| command creates a dalog box for saving applications. The
  372. \verb|save application ...| ensures that the save icon uses the correct
  373. sprite to save an application.
  374.  
  375. \section{Variables used by w}
  376. \begin{center}
  377. \begin{tabular}{|lp{3in}|}
  378. \hline
  379. \verb|w_where|&Set after an uncaught error. Gives the name of the handler
  380. that called this script.\\ \hline
  381. \verb|w_debug|&Script to run after an uncaught error.\\ \hline
  382. \verb|w_file|&Filename for a save or load.\\ \hline
  383. \verb|w_version|&Returns the version of the w extensions to Tcl
  384. as a decimal.\\ \hline
  385. \end{tabular}
  386. \end{center}
  387.  
  388.  
  389. \chapter{Dialog boxes}
  390.  
  391. \section{Introduction}
  392.  
  393. Dialog boxes are constructed and opened in w using the \verb|w_box| command.
  394. Dialog box creation is a two stage process. First a dialog box {\em template}
  395. is created. This is a permanent structure that describes the appearance and
  396. function of a dialog box. Dialog boxes can be created from templates in
  397. two ways. A persitent dialog box can be opened, this remains on display
  398. until the user closes it.  A dialog box template can be attached to a
  399. menu, a box is then opened automatically when the menu entry is traversed.
  400. It is closed when the menu is closed.
  401.  
  402. Dialog boxes in w are created when they are displayed and destroyed when
  403. they are removed from display.
  404.  
  405. The content of a dialog box is made up of one or more {\em components}. A
  406. component consists of a small number (possibly zero) of icons that
  407. contribute to a common purpose. Some components are {\em containers},
  408. they serve to organize other components into lists or boxes.
  409.  
  410. The contents of component icons are passed via global variables. The
  411. name of the variables are given in the templates. If more than one dialog box
  412. is used from the same template it may be necessary to separate the
  413. variables. To do this a dialog box can be {\em tagged}. If a box is tagged
  414. the variable name refers to a global array, and the {\em tag} to an element
  415. name within the array.
  416.  
  417. Each dialog box template has an {\em identifier}. This is a name that is passed
  418. to the template during creation, and used to refer to it when a persistent 
  419. box is opened and when a transient box is attached to a menu.
  420.  
  421. \subsubsection{Example}
  422. \begin{verbatim}
  423.        w_box filebox create "File Name"\
  424.         { vlist {write Filename fname }
  425.                 {default Set  {return show}}
  426.         }
  427.        w_box filebox open
  428. \end{verbatim}
  429.  
  430. The create command creates a dialog box template with identifier ``filebox''.
  431. This has one component, a vertical list. The list is a container with two
  432. components, a writable icon labelled ``Filename'' and and a default action
  433.  item labelled ``Set''. The writable icon keeps its contents in variable
  434.   ``fname''. The default action icon runs the script ``return show''.
  435.  
  436. The second command opens a copy of ``filebox'' as a persistent dialog box.
  437.  
  438. \section{Dialog box components}
  439.  
  440. Each component is a single Tcl word, it is broken up into words, the first
  441. being the component type, and the remainder arguments depending on the type.
  442. \subsection{Action buttons}
  443. \begin{center}
  444. \begin{tabular}{|l|}
  445. \hline
  446. \verb|action <name> [script]|\\ \hline
  447. \verb|default <name> [script]|\\ \hline
  448. \end{tabular}
  449. \end{center}
  450.  
  451. These give a action button icon with \verb|<name>| on it.
  452.  
  453. A mouse click on the icon causes the following action:
  454. If there is no script the box is just closed. If there is a script the script
  455. is interpreted, and the result is examined. If the script returns
  456. ``close'' or ``0'' the box is closed. If it returns ``show'' or ``1'' it
  457. is not.
  458.  
  459. If  \verb|<name>| is ``Cancel'' the same action takes place if the escape key
  460. is pressed with the caret in the dialog box.
  461.  
  462. A \verb|default| component  is the same as \verb|action| component, except that the icon has a border, and its action takes place if the return key  is pressed with the caret
  463. in the dialog box.
  464.  
  465. Before any script is interpreted the \verb|%d| substitution is set to the
  466. dialog box tag and any variables associated with the dialog box are set.
  467.  
  468. \subsection{Display fields}
  469. \begin{center}
  470. \begin{tabular}{|l|}
  471. \hline
  472. \verb|info <name> <text>|\\ \hline
  473. \verb|display <name> <variable> [<width>]|\\ \hline
  474. \verb|watch <name> <variable> [<width>]|\\ \hline
  475. \end{tabular}
  476. \end{center}
  477. These components display a label and a string. The label contains \verb|<name>|
  478.  
  479. For the \verb|info| component the string is given as \verb|<text>| when the
  480. {\em template} is created. For the \verb|display| and \verb|watch| components
  481. it is read from \verb|<variable>| when a box is opened. In the case of
  482. \verb|watch| components it is also updated whenever the variable is altered
  483. while the box is open.
  484.  
  485.  \verb|display| and \verb|watch| components can be given a \verb|width|
  486. argument that gives the number of characters of the string that can be
  487. displayed. This defaults to 20.
  488.  
  489. \subsection{Adjustable components}
  490. \begin{center}
  491. \begin{tabular}{|l|}
  492. \hline
  493. \verb|option  <name> <variable>|\\ \hline
  494. \verb|radio   <name> <variable>|\\ \hline
  495. \verb|write   <name> <variable> [<width>] [<length>]|\\ \hline
  496. \end{tabular}
  497. \end{center}
  498. These components are adjustable by the user. They each take an initial
  499. value from a global variable. Before any script associated with the dialog
  500. box is interpreted the variables are {\em set}. This involves copying the
  501. values from the components back into the variables.
  502.  
  503. Option component variables contain ``0'' if they are deselected and ``1'' 
  504.  if they are selected.
  505.  
  506. Radio components are in the same group if they have the same variable.
  507. There can be a maximum of 15 different groups of radio components in one
  508. dialog box. This variable is set to \verb|<name>| for the selected component.
  509.  
  510.  
  511. \subsection{Decorative components}
  512. \begin{center}
  513. \begin{tabular}{|l|}
  514. \hline
  515. \verb|sprite <spritename>|\\ \hline
  516. \end{tabular}
  517. \end{center}
  518.  
  519. The sprite component display a sprite. The sprite is looked for first in the
  520. user sprite area and then in the wimp sprite area.
  521.  
  522. \subsection{Saving}
  523. \begin{center}
  524. \begin{tabular}{|l|}
  525. \hline
  526. \verb|save  <filetype> <variable> <script>|\\ \hline
  527. \end{tabular}
  528. \end{center}
  529.  
  530. This component consists of a draggable icon corresponding to the filetype
  531. and a writeable icon. When the icon is dragged 
  532. it asks the task it is dropped on to save a file whose leafname is taken
  533. from the writeable icon. If the task responds the script is interpreted with
  534. the global variable \verb|w_file|  set to the full filename required.
  535. Variables are set before the script is interpreted.
  536. The \verb|%d| substitution is set to the dialog box tag.
  537. The script should save to the required filename. The possible return
  538. values of the script are given by
  539. \begin{center}
  540. \begin{tabular}{|c|c|c|}
  541. \hline
  542. String&Number&Meaning\\ \hline
  543. \verb|close|&0&Save succeeded, close the dialog box\\
  544. \verb|show|&1&Save succeeded, leave the dialog box open\\
  545. \verb|failclose|&2&Save failed, close the dialog box\\
  546. \verb|failshow|&3&Save failed, leave the dialog box open\\ \hline
  547. \end{tabular}
  548. \end{center}
  549.  
  550. \subsection{Container components}
  551. \begin{center}
  552. \begin{tabular}{|l|}
  553. \hline
  554. \verb|box <name> <component>|\\ \hline
  555. \verb|vlist {<component>}|\\ \hline
  556. \verb|hlist {<component>}|\\ \hline
  557. \end{tabular}
  558. \end{center}
  559.  
  560. \verb|box| draws a box round  \verb|<component>| with \verb|<name>| written
  561. on it. \verb|vlist| and \verb|hlist| construct vertical and horizontal lists
  562. of components.
  563.  
  564. \section{Commands}
  565.  
  566. \begin{center}
  567. \begin{tabular}{|l|}
  568. \hline
  569. \verb|w_box <identifier> create <title> <component> [-tag]|\\ \hline
  570. \verb|w_box <identifier> open [<tag>]|\\ \hline
  571. \verb|w_info templates|\\ \hline
  572. \end{tabular}
  573. \end{center}
  574.  
  575. The \verb|create| option creates a dialog box template with the given
  576. identifier and title. The contents of the box are \verb|<component>|. This will
  577. usually be a container component. The \verb|-tag| option determines if
  578. a {\em transient} box from this template is tagged. Such a box will be
  579. given the tag (if any) of the menu it is opened from.
  580.  
  581. The \verb|open| option opens a persitent dialog box from the template.
  582. If required a name can be passed as a tag.
  583.  
  584. \subsubsection{Example}
  585. \begin{verbatim}
  586.       w_box mytemplate create "A silly dialog box"\
  587.       { vlist {info Info "text display" }
  588.               {display Display displayvar}
  589.               {watch Watch watchvar}
  590.               {write Write writevar}
  591.               {hlist {option Opt1 opt1 }
  592.                      {option Opt2 opt2 }
  593.                      {option Opt3 opt3 }
  594.               }
  595.               { box "A box"
  596.                 { hlist {radio Radio1 radiovar}
  597.                         {radio Radio2 radiovar}
  598.                         {radio Radio3 radiovar}
  599.               }
  600.               {sprite !tcl}
  601.               {hlist {action Cancel {set boxisopen 0}}
  602.                      {action Show {showvars;return show}}
  603.                      {default " OK " {showvars;set boxisopen 0}}
  604.               }
  605.       }
  606.       w_box mytemplate open box1
  607. \end{verbatim}
  608.  
  609. The \verb|create| option creates a template with a variety of components.
  610. The \verb|open| command opens a persistent box from this template.
  611. This box will use
  612. global variables \verb|displayvar(box1)|, \verb|watchvar(box1)|,
  613. \verb|writevar(box1)|, \verb|opt1(box1)|, \verb|opt2(box1)|, \verb|opt3(box1)|
  614. and  \verb|radiovar(box1)|.
  615.  
  616. If a transient box is opened from a menu using this template it will use
  617. global variables \verb|displayvar|, \verb|watchvar|,
  618. \verb|writevar|, \verb|opt1|, \verb|opt2|, \verb|opt3|
  619. and  \verb|radiovar|, since no \verb|-tag| option was used when creating the
  620. template.
  621.  
  622. The \verb|w_info templates| command returns a list of all template identifiers.
  623.  
  624. \section{Dialog box layout}
  625.  
  626. The layout of dialog boxes in w is not perfect. It attempts to design the
  627. box from the component descriptions without additional input from the
  628. programmer. It may not be possible to do this well.
  629.  
  630. The component sizes are calculated according to the style guide assuming
  631. that characters are in the system font. This may not be correct for other
  632. fonts. Short strings of wide characters may not fit in their icons. This
  633. can be cured by adding spaces.
  634.  
  635. \subsubsection{Example}
  636. \begin{verbatim}
  637.       w_box mytemplate create "A small dialog box"\
  638.       { vlist {info Info "text display" }
  639.               {hlist {action Cancel {set boxisopen 0}}
  640.                      {default " OK " {set boxisopen 1}}
  641.               }
  642.       }
  643. \end{verbatim}
  644.  
  645. The OK should now fit in its icon.
  646.  
  647. A row of similar components all of different sizes does not look good.
  648. w attempts to correct this by {\em equalizing}. If several components of
  649. the same type are consecutive in a vertical or horizontal box they are
  650. enlarged to the size of the largest. This does not apply to container
  651. components or sprites, these components are also ignored when checking
  652. for consecutives.
  653.  
  654. If you have, say, a vertical list consisting of horizontal lists of one
  655. component type, these will only be equalised within the individual horizontal
  656. lists. You can force them all to the same size by padding with spaces.
  657.  
  658. \subsubsection{Example}
  659. \begin{verbatim}
  660.       w_box mytemplate create "Another box"\
  661.       { vlist {hlist {{radio "  R1  " FMvar} {radio R2 FMvar}}
  662.                hlist {{radio Local1 MWvar} {radio Local2 MWvar}}
  663.               }
  664.       }
  665. \end{verbatim}
  666.  
  667. The padding around R1 will cause all four radio components to have the
  668. same size.
  669.  
  670. When the sizes of the individual components have been decided they are
  671. locked together into lists. When locking a vertical list the narrower
  672. components are padded with space. The space is put equally at the ends and
  673. between any sub--components. In particular individual items are centered.
  674. A similar vertical padding occurs when locking a horizontal list.
  675.  
  676. \chapter{Menus}
  677.  
  678. \section{Introduction}
  679. w menus are created from textual menu descriptions. They can be attached
  680. to the iconbar, to draw diagrams and to text documents. They can have 
  681. submenus and transient dialog boxes attached. Entries can be ticked or
  682. greyed out.
  683.  
  684. \section{Menu descriptions}
  685. A menu description is a word that decomposes into a list. The first item
  686. of the list is the menu title, the remainder are menu item descriptions.
  687. There must be at least one of the latter.
  688.  
  689. A menu item description is a word that decomposes into a list, the first item
  690. is the text that appears in the menu. Any remaining items are
  691. \begin{center}
  692. \begin{tabular}{|lp{3in}|}
  693. \hline
  694. \verb|-tag|&Tag the menu item by the window identifier or ``bar''\\ \hline
  695. \verb|-click <script>|&Run script if this item is selected\\ \hline
  696. \verb|-tick  <variable>|&The item can be ticked or unticked by
  697.                                    selecting it. The tick status (0 or 1)
  698.                                    is stored in the variable.
  699.                                    you can change it by writing to the variable
  700.                                    you can monitor it with a trace on the
  701.                                    variable.\\ \hline
  702. \verb|-grey <variable>|&Uses the variable to decide whether the item
  703.                                    is greyed out. A value of 1 will grey
  704.                                    out the entry, 0 will not.\\ \hline
  705. \verb|-sub  <menudescription>|&Create a submenu.\\ \hline
  706. \verb|-dbox <identifier>|&Open a transient dialog box.\\ \hline
  707. \end{tabular}
  708. \end{center}
  709. \verb|-sub| and \verb|-dbox| cannot be used together.
  710. \verb|-click| and \verb|-tick| cannot be used together.
  711. \verb|-tag| must preceed any \verb|-tick|, \verb|-grey| or \verb|-dbox| options.
  712.  
  713. The percent substitution \%w is set to the window identifier
  714. or ``bar'' for an iconbar menu when a menu is open.
  715.  
  716. \subsubsection{Example}
  717. \begin{verbatim}
  718.       w_bar -menu { wtest {Info -dbox progInfo}
  719.                           {Process -click process -grey notready}
  720.                           {Save -dbox saveBox -click {saveMclick %w}}
  721.                           {Quit -click exit}
  722.                   }
  723. \end{verbatim}
  724.  
  725. This puts an icon with a menu on the iconbar. The process entry
  726. is greyed out if global variable \verb|notready| is 1.
  727.  
  728. If the item description read 
  729. \verb|{Process -tag -click process -grey notready}|
  730. the entry would be greyed out if global \verb|notready(bar)| was 1.
  731.  
  732. Notice the Save entry has both a dialog box and a click script.
  733.  
  734. \chapter{Text documents}
  735.  
  736. \section{Introduction}
  737.  
  738. Simple text document display can be handled using the \verb|w_text| command.
  739. A blank document can be created, the formatting options such as margins
  740. can be adjusted and text can be added to the document with or without
  741. wrapping and justification.
  742.  
  743. One or more scrolling windows can be opened on the document.
  744.  
  745. \subsection{Text processing}
  746.  
  747. When text is entered into a document using the write or print commands a
  748. text processing option may be turned on or off. If it is off the text is
  749. included verbatim except that any control characters are replaced by spaces.
  750. The text is displayed in a font and colour specified when the document
  751. is created.
  752.  
  753. If processing is on sequences starting with a bar (\verb"|") are interpreted
  754. as font or colour changes.
  755.  
  756. \begin{center}
  757. \begin{tabular}{|ll|}
  758. \hline
  759. \verb"|<font>| "&Change font\\
  760. \verb"|c<colour>|"&Change colour\\
  761. \verb"||"&Display a \verb"|"\\ \hline
  762. \end{tabular}
  763. \end{center}
  764.  
  765. \section{Commands}
  766. \begin{center}
  767. \begin{tabular}{|l|}
  768. \hline
  769. \verb|w_text <identifier> create {options}|\\ \hline
  770. \verb|w_text <identifier> options {options}|\\ \hline
  771. \verb|w_text <identifier> open|\\ \hline
  772. \verb|w_text <identifier> print {<strings>}|\\ \hline
  773. \verb|w_text <identifier> write {<strings>}|\\ \hline
  774. \verb|w_info documents|\\ \hline
  775. \end{tabular}
  776. \end{center}
  777.  
  778. The \verb|create| command creates a document with the given identifier.
  779. Possible options are
  780. \begin{center}
  781. \begin{tabular}{|lp{3in}|}
  782. \hline
  783. \verb|-title <string>|&
  784.              Sets the title for any windows on the document.\\ \hline
  785. \verb|-close <script>|&Runs the script when the user attempts to close the
  786.                              last window on the document.
  787.                              \%w is set to the document identifier.
  788.                              The script can return:-
  789.                              \begin{tabular}{|c|c|c|}
  790.                              \hline
  791.                              0&close&Close window and diagram.\\
  792.                              1&show&Close neither.\\
  793.                              2&hide&Close window only.\\ \hline
  794.                              \end{tabular}
  795.  
  796.                              If no \verb"-close" option is given the window and
  797.                              document are both closed.\\ \hline
  798. \verb|-fg <colour>|&Sets the main text colour. Default black.\\ \hline
  799. \verb|-bg <colour>|&Sets the background colour. Default white.\\ \hline
  800. \verb|-menu <menudescription>|&The menu is opened from any of the document's
  801.                              windows.\\ \hline
  802. \verb|-width <length>|&Sets the window width.(Default 800 os units)\\ \hline
  803. \verb|-size <length>|&Sets the main font size (Default 20p)\\ \hline
  804. \verb|-height <length>|&Sets the separation between lines.
  805.                        ( Default depends on main font size.)\\ \hline
  806. \end{tabular}
  807. \end{center}
  808.  
  809. The options command sets some options that apply to text added by \verb|write|
  810. or \verb|print| after the \verb|options| command.
  811. The possible options are
  812.  
  813. \begin{center}
  814. \begin{tabular}{|lp{3in}|}
  815. \hline
  816. \verb|-l<length>|&Left margin (from left of window).\\ \hline
  817. \verb|-i<length>|&Paragraph indent (write only) (from left of window).\\ \hline
  818. \verb|-r<length>|&Right margin (from right of window).\\ \hline
  819. \verb"-j[on|off]"&Justify (write only).\\ \hline
  820. \verb"-p[on|off]"&Process.\\ \hline
  821. \verb|-L|&Set left (print only).\\ \hline
  822. \verb|-C|&Center (print only).\\ \hline
  823. \verb|-R|&Set right (print only).\\ \hline
  824. \end{tabular}
  825. \end{center}
  826.  
  827. The initial defaults are \verb|-l0 -i0 -r0 -joff -poff -L|.
  828.  
  829. In justify or process ``off'' or ``on'' can be replaced by 0 or 1.
  830.  
  831. The print and write commands concatenate their string arguments with space
  832. separators. Control characters are replaced with spaces. Processing takes
  833. place if it is turned on.
  834.  
  835. The \verb|print| command displays the result as a
  836. single line, which may overflow the page if it is too long. Print sets the line
  837. left, right or centered as required.
  838.  
  839. The \verb|write| command splits the text into lines. The first line is
  840. inset by the paragraph indent. If the justify option is on all except the
  841. last line will be justified to both margins.
  842.  
  843. Both print and write scroll the most recently opened window (if any)
  844. to show the new text.
  845.  
  846. The \verb|open| command opens a new window to display the document.
  847.  
  848. The \verb|w_info documents| command returns a list of all document identifiers.
  849.  
  850. \subsubsection{Example}
  851. \begin{verbatim}
  852.       w_text mytext create -title "A text window"\
  853.                        -fg blue\
  854.                        -width 6i\
  855.                        -height 30p\
  856.                        -size 20p\
  857.                        -close {expr 2}\
  858.                        -menu $docmenu
  859.       w_text mytext options -l0.5i -pon
  860.       w_text mytext write "This is |fi|italic, |fn| this is |fb|bold"
  861.       w_text mytext open
  862. \end{verbatim}
  863.  
  864.  
  865. \chapter{Draw diagrams}
  866.  
  867. \section{Introduction}
  868.  
  869. Draw diagrams can be created, displayed and saved in w. At present they
  870. support four types of object: text, paths, sprites and group objects.
  871. Font description objects are managed automatically to support fonts used
  872. in text objects. When an object is created a number is returned that can be
  873. used to identify the object if it needs to be removed later.
  874.  
  875. Coordinates in diagrams are in user defined units with origin at the bottom
  876. left hand corner.
  877.  
  878. \section{Object descriptions}
  879.     There are four types of objects displayed in draw diagrams:
  880.     text objects, path objects,sprites and group objects.
  881.  
  882. \subsection{Text objects}
  883. \begin{center}
  884. \begin{tabular}{|l|}
  885. \hline
  886. \verb|<textobject> = text <point> <string> <options>|\\ \hline
  887. \verb|<point> = (<number>,<number>)|\\ \hline
  888. \end{tabular}
  889. \end{center}
  890.  
  891. The possible options are
  892. \begin{center}
  893. \begin{tabular}{|lp{3in}|}
  894. \hline
  895. \verb|-<font>|&The font.\\ \hline
  896. \verb|-c<colour>|&Text colour.\\ \hline
  897. \verb|-b<colour>|&Background colour hint.\\ \hline
  898. \verb"-o[l|c|r][t|m|b]"&Determines which point in the text is placed
  899.                              at the given point. The first character
  900. is the x--position; l for left r for right c for center or nothing for
  901. the text baseline left. The second character is the y--position;
  902. t for top, m for middle, b for bottom or nothing for the text baseline.
  903. \\ \hline
  904. \end{tabular}
  905. \end{center}
  906.  
  907. \subsubsection{Example}
  908. \begin{verbatim}
  909.       w_draw mydiagram text (3,5) "Hello World" -ocm -cgreen
  910. \end{verbatim}
  911.  
  912. Draws green text centered at $(3,5)$.
  913.  
  914. \subsection{Path objects}
  915. \begin{center}
  916. \begin{tabular}{|l|}
  917. \hline
  918. \verb|<path object> =  path <path sequence> <options>|\\ \hline
  919. \verb|<path sequence> = <point>{<gap><point>}[.]|\\ \hline
  920. \end{tabular}
  921. \end{center}
  922.  
  923. A terminating full stop indicates that the path is closed.
  924.  
  925. Gaps can be 
  926. \begin{center}
  927. \begin{tabular}{|lp{3in}|}
  928. \hline
  929. nothing&Move between points.\\ \hline
  930. \verb|-|&Join points with line.\\ \hline
  931. \verb|'<'<point><point>'>'|&Draw a Bezier curve with the given
  932.                             control points\\ \hline
  933. \end{tabular}
  934. \end{center}
  935.  
  936. Possible options are
  937. \begin{center}
  938. \begin{tabular}{|lp{3in}|}
  939. \hline
  940. \verb|-i<colour>|&Interior colour (default none).\\ \hline
  941. \verb|-c<colour>|&Path colour     (default black).\\ \hline
  942. \verb|-t<length>|&Thickness (half width) (default thin).\\ \hline
  943. \verb|-r|&Round corners  (default mitres).\\ \hline
  944. \end{tabular}
  945. \end{center}
  946.  
  947. \subsubsection{Example}
  948. \begin{verbatim}
  949.       set x  1
  950.       set y  1
  951.       set x1 2
  952.       set y1 2
  953.       w_draw mydiagram path ($x,$y)<($x,$y1)($x,$y1)>($x1,$y1). -cblue -t.1i
  954.       w_draw mydiagram path ($x,$y)-($x1,$y)-($x1,$y1)-($x,$y1). -ired -cnone
  955. \end{verbatim}
  956.  
  957. This draws a red square with no boundary and a thick blue line.
  958.  
  959. \subsection{Sprite objects}
  960. \begin{center}
  961. \begin{tabular}{|l|}
  962. \hline
  963. \verb|<sprite object> = sprite <name> <point> [<point>]|\\ \hline
  964. \end{tabular}
  965. \end{center}
  966. \verb|name| is a name of a sprite in the user sprite area,
  967. its bottom left corner is placed at the first point.
  968. If the second point is provided it is the top right
  969. corner, otherwise the sprite is scaled to its natural
  970. mode independent size.
  971. At present sprites of 16 colours or less need to be
  972. provided with a palette, or they will appear in a
  973. peculiar set of colours.
  974.  
  975. \subsection{Group objects}
  976. \begin{center}
  977. \begin{tabular}{|l|}
  978. \hline
  979. \verb|<group object> =  group {<objects>}|\\ \hline
  980. \end{tabular}
  981. \end{center}
  982.  
  983. \subsubsection{Example}
  984. \begin{verbatim}
  985.        w_draw mydiagram group { text (1,2) "Some text"}\
  986.                               { path (2,2)-(2,4)-(3,3).}\
  987.                               { sprite mysprite (3,5)}\
  988.                               { group {text (1,6) "Inner group"}\
  989.                                       {sprite othersprite (2,6) (3,7)}\
  990.                               }
  991. \end{verbatim}
  992.  
  993. \section{Commands}
  994.  
  995. \begin{center}
  996. \begin{tabular}{|l|}
  997. \hline
  998. \verb|w_draw <identifier> create {options}|\\ \hline
  999. \verb|w_draw <identifier> save <filename>|\\ \hline
  1000. \verb|w_draw <identifier> open|\\ \hline
  1001. \verb|w_draw <identifier> [above <number>] <object>|\\ \hline
  1002. \verb|w_draw <identifier> delete <number>|\\ \hline
  1003. \verb|w_info diagrams|\\ \hline
  1004. \end{tabular}
  1005. \end{center}
  1006.  
  1007. The \verb|create| command creates an empty draw diagram with the given
  1008. identifier.
  1009.  
  1010. Possible options are
  1011. \begin{center}
  1012. \begin{tabular}{|lp{3in}|}
  1013. \hline
  1014. \verb|-title <string>|&Sets the title for any windows on the diagram.\\ \hline
  1015. \verb|-close <script>|&Runs the script when the user attempts to close the
  1016.                              last window on the diagram.
  1017.                              \%w is set to the window name.
  1018.                              The script can return:-
  1019.                              \begin{tabular}{|c|c|c|}
  1020.                              \hline
  1021.                              0&close&Close window and diagram.\\
  1022.                              1&show&Close neither.\\
  1023.                              2&hide&Close window only.\\ \hline
  1024.                              \end{tabular}
  1025.                              
  1026.                              If no \verb"-close" option is given the window and
  1027.                              document are both closed.\\ \hline
  1028.  
  1029.  
  1030. \verb|-click <script>|&Runs the script when the user clicks on the diagram.
  1031.                      \%b is set to the button type.
  1032.                       \%x and \%y are set to the position of the click
  1033.                       in user coordinates. (Origin at bottom left)\\ \hline
  1034. \verb|-page <pagesize>|&Sets the diagram size. This can be either
  1035.                       \verb"A<number>[p|l]" or \verb|<length>x<length>|,
  1036.                       p and l denote portrait (default) or landscape.
  1037.                       Without this option the diagram defaults to A4p.\\ \hline
  1038. \verb| -bg <colour>|&Sets the background colour.\\ \hline
  1039. \verb|-xscale <length>|&Determine the scale used for describing\\
  1040. \verb|-yscale <length>|&objects, and for returning mouse clicks. Defaults 1i.
  1041. \\ \hline
  1042. \verb|-menu <menudescription>|&The menu is opened from any of the documents
  1043.                              windows.\\ \hline
  1044. \end{tabular}
  1045. \end{center}
  1046.  
  1047. The \verb|save| command saves the diagram as a draw file to the given filename.
  1048.  
  1049. The \verb|open| command opens a new window on the diagram.
  1050.  
  1051. The \verb|<object>| and \verb|above| commands add a new object to the
  1052. diagram. They return an object identification number. The \verb|above| 
  1053. command places the object above the numbered object in the diagram.
  1054. If the numbered object is not found (use -1 to force this) the object is
  1055. placed at the front. If above is not used the object is placed at the back.
  1056.  
  1057. The delete command deletes the numbered object.
  1058.  
  1059. The \verb|w_info diagrams| command returns a list of all diagram identifiers.
  1060.  
  1061.  
  1062. \chapter{Communication}
  1063.  
  1064. \section{Introduction}
  1065.  
  1066. One of the intended uses of w is to write desktop front ends for other
  1067. programs. For this reason it has several methods for communicating with
  1068. other applications.
  1069.  
  1070.  The \verb|system| command supplied with Tcl cannot be
  1071. used from within desktop applications. When w is initialised it is
  1072. replaced with a new version that calls \verb|Wimp_StartTask|. This allows
  1073. w programs to start up any command line or desktop application, and is used
  1074. when the started program does not need to communicate with w.
  1075.  
  1076. The \verb|w_task| command implements the taskwindow protocol. The w program
  1077. can start a command line task and pass data to and from the task.
  1078.  
  1079. The \verb|w_send| command is for communication between w applications.
  1080. One application can send a script to be interpreted by another application
  1081. and receive the result. This gives a flexible scheme for communication
  1082. between w applications, and is particularly useful for debugging.
  1083.  
  1084. \section{Commands}
  1085.  
  1086. \begin{center}
  1087. \begin{tabular}{|l|}
  1088. \hline
  1089. \verb|system <string>|\\ \hline
  1090. \verb|w_send <wimptask> <script>|\\ \hline
  1091. \verb|w_task <identifier> create {<options>}|\\ \hline
  1092. \verb|w_task <identifier> send <string>|\\ \hline
  1093. \verb|w_task <identifier> kill|\\ \hline
  1094. \verb|w_task <identifier> suspend|\\ \hline
  1095. \verb|w_task <identifier> resume|\\ \hline
  1096. \verb|w_info tasks|\\ \hline
  1097. \verb|w_info wimptasks|\\ \hline
  1098. \end{tabular}
  1099. \end{center}
  1100.  
  1101. The \verb|system| command passes the string to the RiscOS command interpreter
  1102. using \verb|Wimp_StartTask|. This can be used to run command line or desktop
  1103. applications.
  1104.  
  1105. The \verb|w_send| command sends the script to a wimp task. The task is 
  1106. identified by its name in the taskmanager window. If the task is running w
  1107. it will interpret the script and return the result as the result of
  1108. \verb|wimp_task|.
  1109. If an error occurs in sending the script (the taskname cannot be found or
  1110. the task fails to respond) \verb|w_send| returns a standard Tcl error code
  1111. of 1. If an error occurs in the remote script \verb|w_send| returns an error
  1112. with the non--standard code of 5. If the script executes and returns its value
  1113. succesfully \verb|w_send| returns the result with the result code of the
  1114. remote script.
  1115.  
  1116. \subsubsection{Example}
  1117. \begin{verbatim}
  1118.        if {[catch {w_send wtest {info globals}} wvars]}\
  1119.           { w_error "Send to wtest failed"
  1120.             return
  1121.           }
  1122. \end{verbatim}
  1123.  
  1124. This sends the command ``info globals'' to a wimp task called ``wtest''.
  1125. This should return a list of its global variabls, which is placed in
  1126. variable wvars. Notice the send command is enclosed in a catch. This
  1127. should probably be the norm.
  1128.  
  1129. The \verb|w_info wimptasks| command returns a list of all taskwindow task names.
  1130.  
  1131. The \verb|w_task create| command starts up a taskwindow task with the
  1132. given identifier. It can be followed by the following options
  1133.  
  1134. \begin{center}
  1135. \begin{tabular}{|lp{3in}|}
  1136. \hline
  1137. \verb|-receive <script>|&Runs the script when the task sends data
  1138.                              sets \%o to the received data and \%n to the
  1139.                              task identifier.
  1140.                              Note the data may be broken into chunks that are
  1141.                              not at line boundaries.\\ \hline
  1142.  
  1143. \verb|-quit <script>|&Runs the script when the task closes down, sets
  1144.                              \%n to the task identifier.\\ \hline
  1145. \verb|-command <string>|&Passes the string to the RiscOS command line
  1146.                          interpreter in the taskwindow.
  1147.                        The string is truncated to 140 characters.\\ \hline
  1148. \verb|-slot <number>|&Sets the task's initial wimpslot in kilobytes.
  1149.                              Defaults to 128K.\\ \hline
  1150. \end{tabular}
  1151. \end{center}
  1152.  
  1153.  
  1154. The \verb|w_task send| command sends a string to the taskwindow task.
  1155. The \verb|kill|, \verb|suspend| and \verb|resume| commands kill, suspend and
  1156. unsuspend the task. Killing the task will cause any \verb|-close| script to
  1157. be interpreted.
  1158.  
  1159. The \verb|w_info tasks| command returns a list of all task identifiers.
  1160.  
  1161. \chapter{Null events}
  1162.  
  1163. \section{Introduction}
  1164. Most w scripts are interpreted in response to a user action, such as a mouse
  1165. click or icon drag. The \verb|w_null| command allows scripts to be interpreted
  1166. when nothing is happening, usually after a delay.
  1167.  
  1168. \section{Commands}
  1169. \begin{center}
  1170. \begin{tabular}{|l|}
  1171. \hline
  1172. \verb|w_null <identifier> [<script>] [<delay>]|\\ \hline
  1173. \verb"<delay>=<number>c|s|m|h|d"\\ \hline
  1174. \end{tabular}
  1175. \end{center}
  1176.  
  1177. The \verb|w_null| command with a script argument installs the script on a
  1178. null event handler. Any previous script with the same identifier is removed.
  1179.  The script will be called after the delay when the wimp is next not busy.
  1180. The delay is a number followed by one of
  1181. \begin{center}
  1182. \begin{tabular}{|cl|}
  1183. \hline
  1184. \verb|<letter>|&Unit\\ \hline
  1185.                  c ¢iseconds\\
  1186.                  s &seconds\\
  1187.                  m &minutes\\
  1188.                  h &hours\\
  1189.                  d &days\\ \hline
  1190. \end{tabular}
  1191. \end{center}
  1192.  
  1193. If the script returns a delay it is reinstalled to be called again after
  1194. the new delay, otherwise it is removed from the list.
  1195.  
  1196. If \verb|w_null| is called without a script it just removes any script with
  1197. the given identifier from the list.
  1198.  
  1199. \subsubsection{Example}
  1200. \begin{verbatim}
  1201.        w_init Clock
  1202.        w_box display create Clock { watch time tvar}
  1203.        w_box display open
  1204.        w_null update {set tvar [date];return 10s} 0s
  1205. \end{verbatim}
  1206.  
  1207. This is a complete desktop clock program! The \verb|w_null| command creates
  1208. a null event handler called ``update''. This sets variable tvar to a string
  1209. representing the current time and date. This is called at the first opportunity
  1210. as its delay is \verb|0s|. It returns \verb|10s| so it is recalled every
  1211. ten seconds or so. As \verb|tvar| is a watch variable in the dialog box the
  1212. box is updated when the variable is written to.
  1213.  
  1214. \chapter{RiscOS Tcl commands}
  1215. \begin{center}
  1216. \begin{tabular}{|lp{3in}|}
  1217. \hline
  1218. \verb|close <fileId>|&Close a file.\\ \hline
  1219. \verb|date <format>|&Return time or date information.
  1220.  
  1221. \verb|format| uses the same \%-substitutions as \verb|Sys$DateFormat|.
  1222. It defaults to \verb"%24:%mi:%se %dy-%m3-%ce%yr" \\ \hline
  1223. \verb|eof <fileId>|&Returns 1 for end of file 0 otherwise\\ \hline
  1224. \verb|exit [<number>]|&Exits with the give return code (Default 0)\\ \hline
  1225. \verb|flush <fileId>|&Flush buffered output to file.\\ \hline
  1226. \verb|getenv <name>|&Returns the value of the named system variable
  1227.   or an empty string if it does not exist. \\ \hline
  1228. \verb|gets <fileId>|&Returns a line from a file, discards any terminating
  1229. newline\\ \hline
  1230. \verb|gets <fileId> <variable>|&Reads a line from a file into the variable,
  1231.   discards any terminating newline. Returns the length of the string read, or
  1232.   -1 if no characters or newline are read.\\ \hline
  1233. \verb|glob <filename> [<filetype>]|&Returns a list of files
  1234.   matching the filename. The filename can have wildcards
  1235.    \verb|*| or \verb|#| in the leaf
  1236.   name only. If a filetype is supplied only objects matching this type are
  1237.   returned. \\ \hline
  1238. \verb|open <filename> [<access>]|&Opens a file and returns a fileId.
  1239. \\ \hline
  1240. \verb|puts [-nonewline] [<fileId>] <string>|&Writes string to a file
  1241.  (default stdout). Appends a newline unless \verb|-nonewline| is present.
  1242. \\ \hline
  1243. \verb|source <filename>|&Evaluate a file as a Tcl script.\\ \hline
  1244. \verb|system <string>|&Call or chain another program.\\ \hline
  1245. \end{tabular}
  1246. \end{center}
  1247.  
  1248. \begin{center}
  1249. \begin{tabular}{|lp{3in}|}
  1250. \hline
  1251. \verb|file size <filename>|&Returns the file size in bytes. Gives an
  1252. error if the file does not exist.\\ \hline
  1253. \verb|file type <filename>|&Returns the file type as a decimal integer.\\ \hline
  1254. \verb|file exists <filename>|&Returns 1 if the file exists,
  1255.  0 otherwise.\\ \hline
  1256. \verb|file access <filename>|&Returns access details as a string containing
  1257. some of the characters from ``rwxlRWXL'' in that order. Lower case letters
  1258. are for user access.\\ \hline
  1259. \verb|file full <filename>|&Returns the canonicalized version of the file name.
  1260. \\ \hline
  1261. \end{tabular}
  1262. \end{center}
  1263.  
  1264. \section{Built in variables}
  1265. \begin{center}
  1266. \begin{tabular}{|lp{3in}|}
  1267. \hline
  1268. \verb|clock|&Returns the time in centiseconds since the program was started.
  1269. \\ \hline
  1270. \verb|rand|&Returns a random integer in the range 0 to 2147483647\\ \hline
  1271. \verb|riscos_version|&Returns the version of the RiscOS extensions to Tcl
  1272. as a decimal.\\ \hline
  1273. \end{tabular}
  1274. \end{center}
  1275.  
  1276. \chapter{Tcl commands}
  1277.  
  1278. Variable handling
  1279.  
  1280. \begin{center}
  1281. \begin{tabular}{|l|}
  1282. \hline
  1283. \verb|set <variable> [<string>]|\\ \hline
  1284. \verb|global {<variable>}|\\ \hline
  1285. \verb|incr <name> [<integer>]|\\ \hline
  1286. \verb|trace variable <variable> [r][w][u] <command>|\\ \hline
  1287. \verb|trace vdelete <variable> [r][w][u] <command>|\\ \hline
  1288. \verb|trace vinfo <variable>|\\ \hline
  1289. \verb|unset {<variable>}|\\ \hline
  1290. \verb|uplevel [<level>] {<arg>}|\\ \hline
  1291. \verb|upvar [<level>] {<variable> <variable>}|\\ \hline
  1292. \end{tabular}
  1293. \end{center}
  1294.  
  1295. \begin{center}
  1296. \begin{tabular}{|l|}
  1297. \hline
  1298. \verb|array anymore <name> <search>|\\ \hline
  1299. \verb|array donesearch <name> <search>|\\ \hline
  1300. \verb|array exists <name>|\\ \hline
  1301. \verb|array names <name> [<pattern>]|\\ \hline
  1302. \verb|array nextelement <name> <search>|\\ \hline
  1303. \verb|array set <name> <list>|\\ \hline
  1304. \verb|array size <name>|\\ \hline
  1305. \verb|array startsearch <name>|\\ \hline
  1306. \end{tabular}
  1307. \end{center}
  1308.  
  1309. Control flow commands
  1310.  
  1311. \begin{center}
  1312. \begin{tabular}{|l|}
  1313. \hline
  1314. \verb|break|\\ \hline
  1315. \verb|case <string> [in] {<list> <body>}|\\ \hline
  1316. \verb|case <string> [in] '{'{<list> <body>}'}'|\\ \hline
  1317. \verb|continue|\\ \hline
  1318. \verb|for <command> <expr> <command> <command>|\\ \hline
  1319. \verb|foreach <variable> <list> <body>|\\ \hline
  1320. \verb|if <expr> [then] <body> {elsif <expr> <body>} [else] [<body>]|\\ \hline
  1321. \verb|return [-code <code>] [-errorinfo <string>] [-errorcode <code>] <string>|\\ \hline
  1322. \verb|switch [<options>] <string> {<pattern> <body>}|\\ \hline
  1323. \verb|switch [<options>] <string> '{'{<pattern> <body>}'}'|\\ \hline
  1324. \verb|while <expr> <body>|\\ \hline
  1325. \verb|proc <name> <args> <body>|\\ \hline
  1326. \verb|catch <script> [<variable>]|\\ \hline
  1327. \verb|error <message> [<info>] [<code>]|\\ \hline
  1328. \end{tabular}
  1329. \end{center}
  1330.  
  1331. String handling
  1332.  
  1333. \begin{center}
  1334. \begin{tabular}{|l|}
  1335. \hline
  1336. \verb|regexp {<switches>} <expr> <string> <subspec> {<variable>}|\\ \hline
  1337. \verb|regsub {<switches>} <expr> <string> <subspec> <variable>|\\ \hline
  1338. \verb|split <string> [<string>]|\\ \hline
  1339. \verb|scan <string> <format> {<variable>}|\\ \hline
  1340. \verb|format <string> {<arg>}|\\ \hline
  1341. \end{tabular}
  1342. \end{center}
  1343.  
  1344. \begin{center}
  1345. \begin{tabular}{|l|}
  1346. \hline
  1347. \verb|string compare <string> <string>|\\ \hline
  1348. \verb|string first <string> <string>|\\ \hline
  1349. \verb|string index <string> <integer>|\\ \hline
  1350. \verb|string last <string> <string>|\\ \hline
  1351. \verb|string length <string>|\\ \hline
  1352. \verb|string match <pattern> <string>|\\ \hline
  1353. \verb|string range <string> <integer> <integer>|\\ \hline
  1354. \verb|string tolower <string>|\\ \hline
  1355. \verb|string toupper <string>|\\ \hline
  1356. \verb|string trim <string> [<string>]|\\ \hline
  1357. \verb|string trimleft <string> [<string>]|\\ \hline
  1358. \verb|string trimright <string> [<string>]|\\ \hline
  1359. \verb|string wordend <string> <integer>|\\ \hline
  1360. \verb|string wordstart <string> <integer>|\\ \hline
  1361. \end{tabular}
  1362. \end{center}
  1363.  
  1364. List commands
  1365.  
  1366. \begin{center}
  1367. \begin{tabular}{|l|}
  1368. \hline
  1369. \verb|append <variable> {<value>}|\\ \hline
  1370. \verb|concat {<arg>}|\\ \hline
  1371. \verb|join <list> [<string>]|\\ \hline
  1372. \verb|lappend <variable> {<value>}|\\ \hline
  1373. \verb|lindex <list> <index>|\\ \hline
  1374. \verb|linsert <list> <index> {<element>}|\\ \hline
  1375. \verb|list {<arg>}|\\ \hline
  1376. \verb|lrange <list> <first> <last>|\\ \hline
  1377. \verb|llength <list>|\\ \hline
  1378. \verb|lreplace <list> <first> <last> {<element>}|\\ \hline
  1379. \verb|lsearch [<mode>] <list> <pattern>|\\ \hline
  1380. \verb|lsort {<switch>} <list>|\\ \hline
  1381. \end{tabular}
  1382. \end{center}
  1383.  
  1384. Miscellaneous commands
  1385.  
  1386. \begin{center}
  1387. \begin{tabular}{|l|}
  1388. \hline
  1389. \verb|eval {<arg>}|\\ \hline
  1390. \verb|exec {<switch>} {<arg>}|\\ \hline
  1391. \verb|expr {<arg>}|\\ \hline
  1392. \verb|rename <oldname> <newname>|\\ \hline
  1393. \verb|subst [-nobackslashes] [-nocommands] [-novariables] <string>|\\ \hline
  1394. \end{tabular}
  1395. \end{center}
  1396.  
  1397. \begin{center}
  1398. \begin{tabular}{|l|}
  1399. \hline
  1400. \verb|info args <procname>|\\ \hline
  1401. \verb|info body <procname>|\\ \hline
  1402. \verb|info cmdcount|\\ \hline
  1403. \verb|info commands [<pattern>]|\\ \hline
  1404. \verb|info complete <command>|\\ \hline
  1405. \verb|info default <procname> <arg> <varname>|\\ \hline
  1406. \verb|info exists <varname>|\\ \hline
  1407. \verb|info globals <pattern>|\\ \hline
  1408. \verb|info level [<number>]|\\ \hline
  1409. \verb|info library|\\ \hline
  1410. \verb|info locals [<pattern>]|\\ \hline
  1411. \verb|info patchlevel|\\ \hline
  1412. \verb|info procs [<pattern>]|\\ \hline
  1413. \verb|info script|\\ \hline
  1414. \verb|info tclversion|\\ \hline
  1415. \verb|info vars [<pattern>]|\\ \hline
  1416. \end{tabular}
  1417. \end{center}
  1418.  
  1419. \end{document}