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
@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
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:
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:
write:
.
This works just like the former method:
- read:(TypedStream *)stream { [super read:stream]; objc_read_types(stream, "@@", &textInput, &textOutput); return self; }
- free
free
themselves:
- free { [textInput free]; [textOutput free]; return [super free]; } @end
Author: Paul Burchard
Comments to:
webmaster@geom.umn.edu
Created: Apr 18 1994 ---
Last modified: Tue Jun 18 10:22:37 1996