
1 // 2 // Copyright (c) 2007, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 31 Jul 07 Andy Frank Creation 7 // 8 9 ** 10 ** Widget defines a reuable snippet of HTML. 11 ** 12 abstract class Widget 13 { 14 15 ////////////////////////////////////////////////////////////////////////// 16 // Constructor 17 ////////////////////////////////////////////////////////////////////////// 18 19 new make() 20 { 21 req = (WebReq)Thread.locals["web.req"] 22 res = (WebRes)Thread.locals["web.res"] 23 } 24 25 ////////////////////////////////////////////////////////////////////////// 26 // Methods 27 ////////////////////////////////////////////////////////////////////////// 28 29 ** 30 ** Render the markup for this widget. This method *must* 31 ** use the `head` and `body` fields for rendering the 32 ** markup in order to produce a valid HTML file. Never 33 ** use 'res.out' directly. 34 ** 35 abstract Void render() 36 37 ** 38 ** Handle a form submission. 39 ** 40 virtual Void submit() 41 { 42 } 43 44 ////////////////////////////////////////////////////////////////////////// 45 // Fields 46 ////////////////////////////////////////////////////////////////////////// 47 48 ** 49 ** The WebReq instance for this request. 50 ** 51 readonly WebReq req 52 53 ** 54 ** The WebRes instance for this request. 55 ** 56 readonly WebRes res 57 58 ** 59 ** The buffered WebOutStream for the <head> element. 60 ** 61 readonly WebOutStream head 62 { 63 get 64 { 65 if (@head == null) 66 @head = (WebOutStream)Thread.locals["web.widget.head"] 67 return @head 68 } 69 } 70 71 ** 72 ** The buffered WebOutStream for the <body> element. 73 ** 74 readonly WebOutStream body 75 { 76 get 77 { 78 if (@body== null) 79 @body = (WebOutStream)Thread.locals["web.widget.body"] 80 return @body 81 } 82 } 83 84 }