Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Types | Public Member Functions | Protected Member Functions
Wt::WPaintedWidget Class Reference

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, PngImage }
 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)
 Sets the preferred rendering method.
Method preferredMethod () const
 Returns the preferred rendering method.
void update (WFlags< PaintFlag > flags=0)
 Lets the widget repaint itself.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
void addArea (WAbstractArea *area)
 Adds an interactive area.
void insertArea (int index, WAbstractArea *area)
 Inserts 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.
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget (WContainerWidget *parent=0)
 Create an InteractWidget with optional parent.
EventSignal< WKeyEvent > & keyWentDown ()
 Event signal emitted when a keyboard key is pushed down.
EventSignal< WKeyEvent > & keyPressed ()
 Event signal emitted when a "character" was entered.
EventSignal< WKeyEvent > & keyWentUp ()
 Event signal emitted when a keyboard key is released.
EventSignalenterPressed ()
 Event signal emitted when enter was pressed.
EventSignalescapePressed ()
 Event signal emitted when escape was pressed.
EventSignal< WMouseEvent > & clicked ()
 Event signal emitted when a mouse key was clicked on this widget.
EventSignal< WMouseEvent > & doubleClicked ()
 Event signal emitted when a mouse key was double clicked on this widget.
EventSignal< WMouseEvent > & mouseWentDown ()
 Event signal emitted when a mouse key was pushed down on this widget.
EventSignal< WMouseEvent > & mouseWentUp ()
 Event signal emitted when a mouse key was released on this widget.
EventSignal< WMouseEvent > & mouseWentOut ()
 Event signal emitted when the mouse went out of this widget.
EventSignal< WMouseEvent > & mouseWentOver ()
 Event signal emitted when the mouse entered this widget.
EventSignal< WMouseEvent > & mouseMoved ()
 Event signal emitted when the mouse moved over this widget.
EventSignal< WMouseEvent > & mouseDragged ()
 Event signal emitted when the mouse is dragged over this widget.
EventSignal< WMouseEvent > & mouseWheel ()
 Event signal emitted when the mouse scroll wheel was used.
EventSignal< WTouchEvent > & touchStarted ()
 Event signal emitted when a finger is placed on the screen.
EventSignal< WTouchEvent > & touchEnded ()
 Event signal emitted when a finger is removed from the screen.
EventSignal< WTouchEvent > & touchMoved ()
 Event signal emitted when a finger, which is already placed on the screen, is moved across the screen.
EventSignal< WGestureEvent > & gestureStarted ()
 Event signal emitted when a gesture is started.
EventSignal< WGestureEvent > & gestureChanged ()
 Event signal emitted when a gesture is changed.
EventSignal< WGestureEvent > & gestureEnded ()
 Event signal emitted when a gesture is ended.
void setDraggable (const std::string &mimeType, WWidget *dragWidget=0, bool isDragWidgetOnly=false, WObject *sourceWidget=0)
 Configure dragging for drag and drop.
virtual void load ()
 Loads content just before the widget is used.
virtual bool isEnabled () const
 Returns whether the widget is enabled.
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget (WContainerWidget *parent=0)
 Construct a WebWidget with a given parent.
virtual void setPositionScheme (PositionScheme scheme)
 Sets the CSS position scheme.
virtual PositionScheme positionScheme () const
 Returns the CSS position scheme.
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
 Sets CSS offsets for a non-statically positioned widget.
virtual WLength offset (Side s) const
 Returns a CSS offset.
virtual WLength width () const
 Returns the width.
virtual WLength height () const
 Returns the height.
virtual void setMinimumSize (const WLength &width, const WLength &height)
 Sets a minimum size.
virtual WLength minimumWidth () const
 Returns the minimum width.
virtual WLength minimumHeight () const
 Returns the minimum height.
virtual void setMaximumSize (const WLength &width, const WLength &height)
 Sets a maximum size.
virtual WLength maximumWidth () const
 Returns the maximum width.
virtual WLength maximumHeight () const
 Returns the maximum height.
virtual void setLineHeight (const WLength &height)
 Sets the CSS line height for contained text.
virtual WLength lineHeight () const
 Returns the CSS line height for contained text.
virtual void setFloatSide (Side s)
 Specifies a CSS float side.
virtual Side floatSide () const
 Returns the CSS float side.
virtual void setClearSides (WFlags< Side > sides)
 Sets the sides that should be cleared of floats.
virtual WFlags< SideclearSides () const
 Returns the sides that should remain empty.
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
 Sets CSS margins around the widget.
virtual WLength margin (Side side) const
 Returns a CSS margin set.
virtual void setHiddenKeepsGeometry (bool enabled)
 Sets whether the widget keeps its geometry when hidden.
virtual bool hiddenKeepsGeometry () const
 Returns whether the widget keeps its geometry when hidden.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.
virtual bool isHidden () const
 Returns whether the widget is set hidden.
virtual bool isVisible () const
 Returns whether the widget is visible.
virtual void setDisabled (bool disabled)
 Sets whether the widget is disabled.
virtual bool isDisabled () const
 Returns whether the widget is set disabled.
virtual void setPopup (bool popup)
 Lets the widget overlay over other sibling widgets.
virtual bool isPopup () const
 Returns whether the widget is overlayed.
virtual void setInline (bool isInline)
 Sets whether the widget is displayed inline or as a block.
virtual bool isInline () const
 Returns whether the widget is displayed inline or as block.
virtual void setDecorationStyle (const WCssDecorationStyle &style)
 Sets a CSS decoration style.
virtual WCssDecorationStyledecorationStyle ()
 Returns the decoration style of this widget.
virtual void setStyleClass (const WString &styleClass)
 Sets (one or more) CSS style classes.
virtual WString styleClass () const
 Returns the CSS style class.
virtual void addStyleClass (const WString &styleClass, bool force=false)
 Adds a CSS style class.
virtual void removeStyleClass (const WString &styleClass, bool force=false)
 Removes a CSS style class.
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength())
 Sets the vertical alignment.
virtual AlignmentFlag verticalAlignment () const
 Returns the vertical alignment.
virtual WLength verticalAlignmentLength () const
 Returns the fixed vertical alignment that was set.
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
 Sets a tooltip.
virtual WString toolTip () const
 Returns the tooltip.
virtual void refresh ()
 Refresh the widget.
virtual void setAttributeValue (const std::string &name, const WString &value)
 Sets an attribute value.
virtual WString attributeValue (const std::string &name) const
 Returns an attribute value.
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
 Sets a JavaScript member.
virtual std::string javaScriptMember (const std::string &name) const
 Returns the value of a JavaScript member.
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
 Calls a JavaScript member.
virtual bool loaded () const
 Returns whether this widget has been loaded.
virtual void setTabIndex (int index)
 Sets the tab index.
virtual int tabIndex () const
 Returns the tab index.
virtual void setId (const std::string &id)
 Sets the CSS Id.
virtual WWidgetfind (const std::string &name)
 Finds a descendent widget by name.
virtual void setSelectable (bool selectable)
 Sets as selectable.
virtual void doJavaScript (const std::string &javascript)
 Executes the given JavaScript statements when the widget is rendered or updated.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
void setLoadLaterWhenInvisible (bool)
 Change the way the widget is loaded when invisible.
const std::vector< WWidget * > & children () const
 Returns contained widgets.
SignalchildrenChanged ()
 Signal emitted when children have been added or removed.
bool isRendered () const
 Returns whether the widget is rendered.
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 Destructor.
WWidgetparent () const
 Returns the parent widget.
void setWidth (const WLength &width)
 Sets the width.
void setHeight (const WLength &height)
 Sets the height.
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
 Positions a widget next to another widget.
std::string jsRef () const
 Returns a JavaScript expression to the corresponding DOM node.
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 Sets a mime type to be accepted for dropping.
virtual void stopAcceptDrops (const std::string &mimeType)
 Indicates that a mime type is no longer accepted for dropping.
virtual void htmlText (std::ostream &out)
 Streams the (X)HTML representation.
void hide ()
 Hides the widget.
void animateHide (const WAnimation &animation)
 Hides the widget using an animation.
void show ()
 Shows the widget.
void animateShow (const WAnimation &animation)
 Shows the widget using an animation.
void enable ()
 Enables the widget.
void disable ()
 Disable thes widget.
bool layoutSizeAware () const
 Returns whether the widget is layout size aware.
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.

Protected Member Functions

virtual void layoutSizeChanged (int width, int height)
 Virtual method that indicates a size change.
virtual Method getMethod () const
 Returns the actual method used for rendering.
virtual void paintEvent (WPaintDevice *paintDevice)=0
 Paints the widget.
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled)
 Propagates that a widget was enabled or disabled through children.
- Protected Member Functions inherited from Wt::WWebWidget
virtual void removeChild (WObject *child)
 Removes a child object.
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 Sets the widget to be aware of its size set by a layout manager.
 WWidget (WContainerWidget *parent=0)
 Creates a widget.
virtual void dropEvent (WDropEvent dropEvent)
 Handles a drop event.
virtual int boxPadding (Orientation orientation) const
 Returns the widget's built-in padding.
virtual int boxBorder (Orientation orientation) const
 Returns the widget's built-in border width.
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.

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, PngImage HtmlCanvas
Internet Explorer 6.0+InlineVML, PngImage InlineVML
Internet Explorer 9+HtmlCanvas, InlineSVG, PngImage HtmlCanvas
SafariHtmlCanvas, InlineSVG, PngImage HtmlCanvas
OperaInlineSVG, HtmlCanvas*, PngImage InlineSVG
other?HtmlCanvas, PngImage

* 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().

In some browsers, 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. Firefox 4 and Chrome do support svg in normal html mode.

The PngImage is the most portable rendering method, and may be the fastest if the painting is of high complexity and/or the image is fairly small.

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::WPaintDevice *paintDevice) {
Wt::WPainter painter(paintDevice);
painter.drawLine(20, 20, foo_, foo_);
...
}
private:
int foo_;
};

CSS

Styling through CSS is not applicable.

Note:
A WPaintedWidget requires that it is given a size using resize() or by a layout manager.
See also:
WImage

Member Enumeration Documentation

Enumeration that indicates a rendering method.

Enumerator:
InlineSvgVml 

SVG (Most browsers) or VML (Internet Explorer < 9) embedded in the page.

HtmlCanvas 

The WHATWG HTML 5 canvas element.

PngImage 

Using a PNG image resource.

Reimplemented from Wt::WObject.


Member Function Documentation

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

Adds 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 *)
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()
void Wt::WPaintedWidget::enableAjax ( )
protectedvirtual

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.

WPaintedWidget::Method Wt::WPaintedWidget::getMethod ( ) const
protectedvirtual

Returns the actual method used for rendering.

The default method considers browser capabilites and the preferred method to make an actual choice for the implementation.

You may want to reimplement this method to override this choice.

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

Inserts 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::layoutSizeChanged ( int  width,
int  height 
)
protectedvirtual

Virtual method that indicates a size change.

This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called.

See also:
setLayoutSizeAware()

Reimplemented from Wt::WWidget.

virtual void Wt::WPaintedWidget::paintEvent ( WPaintDevice paintDevice)
protectedpure virtual

Paints 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.

Method Wt::WPaintedWidget::preferredMethod ( ) const

Returns the preferred rendering method.

See also:
setPreferredMethod(Method)
void Wt::WPaintedWidget::removeArea ( WAbstractArea area)

Removes an interactive area.

Removes the area from this widget, returning the ownership.

See also:
addArea(WAbstractArea *)
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.

When inserted in a layout manager, the widget may be informed about its current size using setLayoutSizeAware(). If you have defined a "wtResize()" JavaScript method for the widget, then this method will also be called. operation.

See also:
width(), height()

Reimplemented from Wt::WWebWidget.

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

Sets the preferred rendering method.

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

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

Lets the widget repaint itself.

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

Unless a Wt::PaintUpdate paint flag is set, the widget is first cleared.


Generated on Sun May 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1