Next: Creating a custom widget in W3Kit
Up: W3Kit 2.2, An Object-Oriented Toolkit for Interactive WWW Applications
Prev: W3Kit Class Reference

Designing a W3Kit Application

W3Kit applications are built up out of HtmlOutputs -- objects that can perform the basic W3Kit operations of printing themselves into HTML, and archiving themselves onto a TypedStream.

These capabilities are shared by simple low-level input widgets, fancy graphics views, and even the complete fill-out form serving as the application's contents. The W3HtmlOutputs Protocol summarizes the minimum requirements:

    @protocol W3HtmlOutputs
    - printHtml;
    - init;
    - free;
    - read:(TypedStream *)stream;
    - write:(TypedStream *)stream;
    @end

Here is a ``hello world'' style example of how the application contents object would implement the methods of the W3HtmlOutputs protocol. The brief main routine of the program would follow the design outlined in the overview.

- init

Create the default set of interface and computational objects that make up the application, and store them in instance variables. Interface widgets should be created in the order that you want them to receive events in the simulated event loop. Wire up connections between the objects by setting their target objects and action messages (sent to the target when a user event is received). For example:
@interface MyForm:Object
{
    id textInput, textOutput;
}
@end

@implementation MyForm
- init
{
    if(![super init]) return nil;
    textInput = [W3TextField new];
    textOutput = [W3TextField new];
    [[textInput setTarget:textOutput]
        setAction:@selector(takeStringValueFrom:)];
    return self;
}

- printHtml

Lay out the contents of the fill-out form using HTML markup, imbedding the interface widgets into the form by asking each one to printHtml. Note: the output of this method consists of everything between (but not including) the<FORM> and</FORM>directives. The HTML can be printed by using W3App's printf: method; it works just like the printf() function except that it's an Objective-C message. For example:
- printHtml
{
    [W3App printf:"Please type input here:\n<BLOCKQUOTE>"];
    [textInput printHtml];
    [W3App printf:"</BLOCKQUOTE>\n"
        "and it will be echoed here:\n<BLOCKQUOTE>"];
    [textOutput printHtml];
    [W3App printf:"</BLOCKQUOTE>\n"
        "Thank you for your interest in %s\n",
        [textInput stringValue]];
    return self;
}

- write:

Archive up the objects created in the init method. The simplest way to do this is with a one-liner like
- write:(TypedStream *)stream
{
    [super write:stream];
    objc_write_types(stream, "@@", &textInput, &textOutput);
    return self;
}

- read:

Exhume objects archived in past runs with write:. This works just like the former method:
- read:(TypedStream *)stream
{
    [super read:stream];
    objc_read_types(stream, "@@", &textInput, &textOutput);
    return self;
}

- free

Destroy the objects stored in the form, by asking them to free themselves:
- free
{
    [textInput free];
    [textOutput free];
    return [super free];
}
@end


Next: Creating a custom widget in W3Kit
Up: W3Kit 2.2, An Object-Oriented Toolkit for Interactive WWW Applications
Prev: W3Kit Class Reference

[HOME] The Geometry Center Home Page

Author: Paul Burchard
Comments to: webmaster@www.geom.uiuc.edu
Created: Apr 18 1994 --- Last modified: Tue Jun 18 10:22:37 1996