any applications requireor are enhanced bythe presentation of aptly named rich text, text in different formats interspersed with images and hyperlinks to other content. Whether the application is a pure content play, such as a news distribution application, or simply needs a bit of pizzazz in its on-line help, HTML is the answer. Easy to write and maintain (ether by hand or with a specialized editor), HTML gives you a great deal of flexibility in how you present text and graphic content. Brew has long had support for HTML using the IHTMLViewer, an IControl-based user interface; recently, this same capability was added to the Brew uiOne Toolkit, the user interface components accessible to C and C++ developers as part of the uiOne SDK. The htmlwidget
, an optional widget bundled with the SDK and used by the uiOne trigplayer, can be used to display HTML in applications using the Brew uiOne Toolkit (BUIT) just as any other widget might. This provides unprecedented flexibility for developers with access to the toolkit (such as handset manufacturers and those writing pre-loaded applications for manufacturers) who need to present rich text from within their applications.
In this article, I'll show you how to use the htmlwidget, summarizing the samplehtmlwidget example that ships with the Brew uiOne SDK. I present only the most relevant code, assuming you're familiar both with the basics of BREW and using widgets and forms from the BUIT itself.
What the HtmlWidget Widget Provides
The htmlwidget provides a slimmed-down HTML viewer suitable for displaying the kinds of content users would expect within a mobile device. A viewer partially compliant with HTML 3.2, its presentation features include:
- Hypertext links
- Bold and large text
- Text coloration
- Text alignment on the horizontal axis (left, center, and right)
- Inline images
- Simple form input support for text input, lists, check boxes and radio buttons, and submit buttons.
Unsurprisingly, it does not support the following:
- Cascading Style Sheets (CSS)
- Background coloration
- Most malformed HTML, such as HTML with mismatched or missing end tags.
Firefox it isn't, but then again, that's not the point; the point is to provide a lightweight widget that can render formatted text efficiently on a wide variety of devices.
The widget itself consists of three classes: the htmlwidget itself, the htmlviewmodel, and the docmodel. The purpose of the htmlwidget is obvious: it's the widget that encapsulates drawing HTML content to the screen. But what about the other two? The htmlviewmodel is an IModel subclass that offers HTML-specific information about the textual contents of an htmlwidget, such as the state of a rendering operation or when the user selects a link to jump to a new page. The docmodel is an IModel subclass that encapsulates document-specific behaviors of a model, such as the ability to load content from an ISource, or track when the widget to which the model belongs is loading a new document.