Now that the concepts are clear, we can take a look at the standard main routine for W3Kit applications and understand how it implements this organization.
Note the Objective-C message calls, enclosed in brackets []. They use the SmallTalk-style format [object message:arg].
void main(int argc, char *argv[])
{
W3App = [W3Application newArgc:argc argv:argv];
if([W3App loadFromHttp]) [W3App run];
else [W3App setContents:[MyForm new]];
[W3App printHtml];
[W3App free];
exit(0);
}
Here is an ``exploded view'' which explains what is happening at each step:
W3App = [W3Application newArgc:argc argv:argv]
Reads in server input. Determines application name.
Sets the global W3App equal to the resulting
W3Application instance (the assignment is for emphasis only).
[W3App loadFromHttp]
Unarchives all of the interface widgets comprising the contents of the fill-out form, from the server input. The objects and their interconnections are recreated, but only their ``essential'' state is restored.
[W3App run]
Messages corresponding to ``simulated user events'', such as
text entry and mouse clicks, are sent to the interface widgets.
Events are sent in order of htmlID (see below).
This process restores the ``non-essential'' state of the interface,
as modified by the user on the client side.
[W3App setContents:[MyForm new]]
If no incoming HTTP query data was found, the application bootstraps
itself, creating a start-up document.
The [MyForm new] message is responsible for creating
the application's default set of interface widgets.
As each widget is created, it is automatically
assigned an htmlID in order of creation.
/* optional synchronization or out-of-line return here */
Some applications can gain efficiency by delaying synchronization of
state changes until after the event loop. Other applications
may want to return an out-of-line image (using the display
method of the 2D and 3D graphics widgets) instead of printing out
a new fill-out form.
[W3App printHtml]
The interface objects archive their ``essential'' state, and this
information is automatically encoded for insertion into the new
fill-out form.
Server output is initiated, and the contents of the new fill-out form
are printed out to it (using the form object's printHtml
method). Inlined images are also generated during this process.
[W3App free]
Cleanup.
The Geometry Center Home Page
Author: Paul Burchard
Comments to:
webmaster@geom.umn.edu
Created: Apr 18 1994 ---
Last modified: Jun 18 1996