Wt::WPaintedWidget Class Reference
[Painting system]

A widget that is painted using vector graphics. More...

#include <Wt/WPaintedWidget>

Inheritance diagram for Wt::WPaintedWidget:

Inheritance graph
[legend]

List of all members.

Public Types

enum  Method { InlineSvgVml, HtmlCanvas }
 Enumeration that indicates a rendering method. More...

Public Member Functions

 WPaintedWidget (WContainerWidget *parent=0)
 Create a new painted widget.
 ~WPaintedWidget ()
 Destructor.
void setPreferredMethod (Method method)
 Set the preferred rendering method.
Method preferredMethod () const
 Get the preferred rendering method.
void update (WFlags< PaintFlag > flags=0)
 Let the widget repaint itself.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
void addArea (WAbstractArea *area)
 Add an interactive area.
void insertArea (int index, WAbstractArea *area)
 Insert an interactive area.
void removeArea (WAbstractArea *area)
 Removes an interactive area.
WAbstractAreaarea (int index) const
 Returns the interactive area at the given index.
const std::vector
< WAbstractArea * > 
areas () const
 Returns the interactive areas set for this widget.

Protected Member Functions

virtual void paintEvent (WPaintDevice *paintDevice)=0
 Paint the widget.
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.


Detailed Description

A widget that is painted using vector graphics.

A painted widget is rendered from basic drawing primitives. Rendering is done not on the server but on the browser, using different rendering methods:

BrowserMethods Default method
Firefox 1.5+HtmlCanvas, InlineSVG HtmlCanvas
Internet Explorer 6.0+InlineVML InlineVML
SafariHtmlCanvas, InlineSVG HtmlCanvas
OperaInlineSVG, HtmlCanvas* InlineSVG
other?HtmlCanvas
* HtmlCanvas occasionally suffers from rendering artefacts in Opera.

The different rendering methods correspond to different WPaintDevice implementations, from which this widget choses a suitable one depending on the browser capabilities and configuration.

If no JavaScript is available, the JavaScript-based HtmlCanvas will not be used, and InlineSVG will be used instead. The method used may be changed by using setPreferredMethod().

InlineSVG requires that the document is rendered as XHTML. This must be enabled in the configuration file using the <send-xhtml-mime-type> option. By default, this option is off.

To use a WPaintedWidget, you must derive from it and reimplement paintEvent(WPaintDevice *paintDevice). To paint on a WPaintDevice, you will need to use a WPainter. Repainting is triggered by calling the update() method.

Usage example:

 class MyPaintedWidget : public Wt::WPaintedWidget
 {
 public:
   MyPaintedWidget(Wt::WContainerWidget *parent = 0)
     : Wt::WPaintedWidget(parent),
       foo_(100)
   {
      resize(200, 200); // provide a default size
   }

   void setFoo(int foo) {
      foo_ = foo;
      update(); // trigger a repaint
   }

 protected:
   void paintEvent(Wt::WPaintedWidget *paintDevice) {
     Wt::WPainter painter(paintDevice);
     painter.drawLine(20, 20, foo_, foo_);
     ...
   }

 private:
   int foo_;
 };

Note:
A WPaintedWidget requires that its size is specified in pixel units using resize().
See also:
WImage

Member Enumeration Documentation

Enumeration that indicates a rendering method.

Enumerator:
InlineSvgVml  SVG (Most browsers) or VML (Internet Explorer) embedded in the page.
HtmlCanvas  The WHATWG HTML 5 canvas element.

Reimplemented from Wt::WObject.


Member Function Documentation

void Wt::WPaintedWidget::setPreferredMethod ( Method  method  ) 

Set the preferred rendering method.

When method is supported by the browser, then it is chosen for rendering.

Method Wt::WPaintedWidget::preferredMethod (  )  const [inline]

Get the preferred rendering method.

See also:
setPreferredMethod(Method)

void Wt::WPaintedWidget::update ( WFlags< PaintFlag flags = 0  ) 

Let the widget repaint itself.

Repainting is not immediate, but happens after when the event loop is exited.

void Wt::WPaintedWidget::resize ( const WLength width,
const WLength height 
) [virtual]

Resizes the widget.

Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength::isAuto().

This applies to CSS-based layout, and only block widgets can be given a size reliably.

See also:
width(), height()

Reimplemented from Wt::WWebWidget.

void Wt::WPaintedWidget::addArea ( WAbstractArea area  ) 

Add an interactive area.

Adds the area which listens to events in a specific region of the widget. Areas are organized in a list, to which the given area is appended. When areas overlap, the area with the lowest index receives the event.

Ownership of the area is transferred to the widget.

Note:
When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a WRectArea that corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
See also:
insertArea(int, WAbstractArea *)

void Wt::WPaintedWidget::insertArea ( int  index,
WAbstractArea area 
)

Insert an interactive area.

Inserts the area which listens to events in the coresponding area of the widget. Areas are organized in a list, and the area is inserted at index index. When areas overlap, the area with the lowest index receives the event.

Ownership of the Area is transferred to the widget.

Note:
When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a WRectArea that corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
See also:
addArea(WAbstractArea *)

void Wt::WPaintedWidget::removeArea ( WAbstractArea area  ) 

Removes an interactive area.

Removes the area from this widget, returning the ownership.

See also:
addArea(WAbstractArea *)

WAbstractArea * Wt::WPaintedWidget::area ( int  index  )  const

Returns the interactive area at the given index.

Returns 0 if index was invalid.

See also:
insertArea(int, WAbstractArea *)

const std::vector< WAbstractArea * > Wt::WPaintedWidget::areas (  )  const

Returns the interactive areas set for this widget.

See also:
addArea()

virtual void Wt::WPaintedWidget::paintEvent ( WPaintDevice paintDevice  )  [protected, pure virtual]

Paint the widget.

You should reimplement this method to paint the contents of the widget, using the given paintDevice.

Implemented in Wt::Chart::WCartesianChart, and Wt::Chart::WPieChart.

void Wt::WPaintedWidget::enableAjax (  )  [protected, virtual]

Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

See also:
WApplication::enableAjax()

Reimplemented from Wt::WWebWidget.


Generated on Tue Nov 3 15:34:33 2009 for Wt by doxygen 1.5.6