Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Rendering HTML Using the Brew uiOne Toolkit : Page 3

Leverage one of the most ubiquitous computing standards, HTML, from within your Brew uiOne Toolkit-based application.


advertisement
Handling Callbacks from the HTMLWidget
A lot of the interactions with HTML are actually asynchronous—not just document loading and rendering, but user actions as well. Consequently, the two models provided by the htmlwidget invoke your listeners for a variety of reasons, including:
  1. When the document is reset (the docmodel sends an EVT_HDM_RESET event).
  2. When the document loading has stopped (the docmodel sends an EVT_HDM_STOP event).
  3. The first visible region has been rendered, including any embedded objects (the htmlviewmodel sends an EVT_HVM_PAGEDONE event).


  4. Rendering is complete (the htmlviewmodel sends an EVT_HVM_DONE event).
  5. The document, including embedded objects, is fully loaded (the htmlviewmodel sends an EVT_HVM_CONTENTDONE event).
  6. The user has selected a hyperlink (the htmlviewmodel sends an EVT_HVM_JUMP event).
  7. The user clicked the submit button on a form (the htmlviewmodel sends an EVT_HVM_SUBMIT event).
  8. Focus has changed between one item and another within the view (the htmlviewmodel sends an EVT_HVM_FOCUS event).
  9. The listeners, not surprisingly, consist of a series of if statements against these events. The docmodel's listener is the simplest; you could use this to update a UI to indicate when a network action is taking place, for example:

    void samplehtmlwidgetapp_htmldoclistener(samplehtmlwidgetapp* me, ModelEvent *pEv) { if (pEv->evCode == EVT_HDM_RESET) { } if (pEv->evCode == EVT_HDM_STOP) { } return; }

    The htmlviewmodel is more complex; but that's because it must handle more events, although the sample code doesn't handle many events, either:

    void samplehtmlwidgetapp_htmlviewlistener(samplehtmlwidgetapp* me, ModelEvent *pEv) { if (pEv->evCode == EVT_HVM_DONE) { } if (pEv->evCode == EVT_HVM_PAGEDONE) { } if (pEv->evCode == EVT_HVM_CONTENTDONE) { } if (pEv->evCode == EVT_HVM_JUMP) { samplehtmlwidgetapp_loadhtmlfile(me, ((HtmlViewEvent *)pEv)->u.jump.pszURL); } if (pEv->evCode == EVT_HVM_SUBMIT) { } if (pEv->evCode == EVT_HVM_FOCUS) { } return; }

    The sample code only intercepts the EVT_HVM_JUMP event, and uses it to trigger the loading of a new file's worth of HTML using the code you saw in the previous section. If you're loading content from the network, it might be a good idea to use the EVT_HVM_CONTENTDONE method to deactivate a busy indicator, giving the user some indication of when loading starts and stops for a specific page. You can also handle form submissions using EVT_HVM_SUBMIT; the form data is encoded within the submit field of the event union, and has the following fields:
    • posElem is the position of the link that triggered the submit
    • pszURL is the URL to which the data should be sent
    • pszMethod is the HTTP method to be used when sending the data (e.g., "POST")
    • pszData is the data to be sent if the pszMethod isn't "GET".
    Using HTML and intercepting form input, you can build a fairly robust test application by intercepting form data for user input and processing it within your application.

    Surf's Up!
    Well, not quite—as both the documentation for the htmlwidget and I point out in this article, the widget is designed for well-formed application-native content, not general surfing. Nonetheless, if you have a need for rich text display in your BUIT application, look no further than Brew's htmlwidget.



Ray Rischpater is the chief architect at Rocket Mobile, Inc., specializing in the design and development of messaging and information access applications for today's wireless devices. Ray is the author of several books on software development including "eBay Application Development" and "Software Development for the QUALCOMM BREW Platform," both available from Apress, and is an active amateur radio operator.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap