Task

Create a window that has:

   a label that says   "There have been no clicks yet" 
   a button that says   "click me"


Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.




@1Introduction.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation, either version 3 of the Licence, or
(at your option) any later version.
 
Copyright (c) 2012 Sian Mountbatten.
 
@m cvs simpleapp = "$Id: $"
 
@a@<Prelude@>
BEGIN
@<Included declarations@>
@<Plain values in the outer reach@>
@<Names in the outer reach@>
@<Procedures in the outer reach@>
@<Logic in the outer reach@>
END
@<Postlude@>
 
@ The local compiler requires a special prelude.@^system dependencies@>
 
@<Prel...@>=
PROGRAM simpleapp CONTEXT VOID
USE @<Library preludes@>
 
@ And a special postlude.@^system dependencies@>
 
@<Post...@>=
FINISH
 
@ The program requires the predefined forms and the standard prelude.
 
@<Library...@>=
simpleapp fd,standard
 
@ This Web 68 file provides the Xforms prelude.
 
@iforms.w@>
 
@1Initialisation.
The initial processing consists of initialising the Xforms library.
 
@<Logic...@>=
open(argf,"",arg channel);
fl initialize(argc,argv,"simpleapp",NIL,0);
 
@ Declare the !REF FILE!.
 
@<Names...@>=
FILE @!argf;
 
@1Main processing.
The form is created in !simpleapp fd! the source code of which is 108 lines long.
Firstly, define the callback for the button.
 
@<Proc...@>=
button cb:=(REF FLOBJECT obj,INT data)VOID:
(
	clicks +:= 1;
	fl set object label(text box OF click form,whole(clicks,0)+" click"+
	                    (clicks=1|""|"s")+" on the button")
);
 
@ Declare !clicks!.
 
@<Plain...@>=
INT clicks:=0;
 
@ Create the form, show it and hand control to the Xforms library.
 
@<Logic...@>=
click form:=create form click;
fl show form(click OF click form,fl place center,fl full border,"SimpleApp");
fl do forms
 
@ Declare the form.
 
@<Names...@>=
REF FDCLICK click form;
 
@1Macro declarations.
All the macros used in the program are declared here.
 
@<Include...@>=
macro fl do forms;
macro fl initialize;
macro fl set object label;
macro fl show form;
 
@ To compile the program, use this command:
<pre>
   ca -l mod -l forms simpleapp.w68
</pre>
The predefined form will have been compiled with this command:
<pre>
   ca -m mod simpleappfd.w68
</pre>
The predefined form was created by the <b>fdesign</b> program for the Xforms library,
and the resulting form definition file was converted to Web 68 by the program
<b>fdtow68</b>.