/usr/include/Wt/WPaintedWidget is in libwt-dev 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WPAINTED_WIDGET_H_
#define WPAINTED_WIDGET_H_
#include <Wt/WInteractWidget>
#include <Wt/WJavaScript>
namespace Wt {
class WAbstractArea;
class WImage;
class WPaintDevice;
class WWidgetPainter;
/*! \class WPaintedWidget Wt/WPaintedWidget Wt/WPaintedWidget
* \brief 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:
*
* <table>
* <tr><td><b>Browser</b></td><td><b>Methods</b></td>
* <td><b>Default method</b></td></tr>
* <tr><td>Firefox 1.5+</td><td>HtmlCanvas, InlineSVG, PngImage</td>
* <td>HtmlCanvas</td></tr>
* <tr><td>Internet Explorer 6.0+</td><td>InlineVML, PngImage</td>
* <td>InlineVML</td></tr>
* <tr><td>Internet Explorer 9+</td><td>HtmlCanvas, InlineSVG, PngImage</td>
* <td>HtmlCanvas</td></tr>
* <tr><td>Safari</td><td>HtmlCanvas, InlineSVG, PngImage</td>
* <td>HtmlCanvas</td></tr>
* <tr><td>Opera</td><td>InlineSVG, HtmlCanvas*, PngImage</td>
* <td>InlineSVG</td></tr>
* <tr><td>other</td><td>?</td><td>HtmlCanvas, PngImage</td></tr>
* </table>
*
* <i>* HtmlCanvas occasionally suffers from rendering artefacts in Opera.</i>
*
* 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
* <tt><send-xhtml-mime-type></tt> 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.
*
* \if cpp
* Usage example:
* \code
* 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_;
* };
* \endcode
* \endif
*
* <h3>CSS</h3>
*
* Styling through CSS is not applicable.
*
* \note A %WPaintedWidget requires that it is given a size using resize() or
* by a layout manager.
*
* \sa WImage
*
* \ingroup painting
*/
class WT_API WPaintedWidget : public WInteractWidget
{
public:
/*! \brief Enumeration that indicates a rendering method.
*/
enum Method {
/*! \brief SVG (Most browsers) or VML (Internet Explorer < 9) embedded in
* the page.
*/
InlineSvgVml,
/*! \brief The WHATWG HTML 5 canvas element.
*/
HtmlCanvas,
/*! \brief Using a PNG image resource.
*/
PngImage
};
/*! \brief Create a new painted widget.
*/
WPaintedWidget(WContainerWidget *parent = 0);
/*! \brief Destructor.
*/
~WPaintedWidget();
/*! \brief Sets the preferred rendering method.
*
* When \p method is supported by the browser, then it is chosen
* for rendering.
*/
void setPreferredMethod(Method method);
/*! \brief Returns the preferred rendering method.
*
* \sa setPreferredMethod(Method)
*/
Method preferredMethod() const { return preferredMethod_; }
/*! \brief 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.
*/
void update(WFlags<PaintFlag> flags = 0);
virtual void resize(const WLength& width, const WLength& height);
/*! \brief Adds an interactive area.
*
* Adds the \p area which listens to events in a specific region
* of the widget. Areas are organized in a list, to which the given
* \p area is appended. When areas overlap, the area with the
* lowest index receives the event.
*
* Ownership of the \p 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).
*
* \sa insertArea(int, WAbstractArea *)
*/
void addArea(WAbstractArea *area);
/*! \brief Inserts an interactive area.
*
* Inserts the \p area which listens to events in the
* coresponding area of the widget. Areas are organized in a list,
* and the <i>area</i> is inserted at index \p index. When areas
* overlap, the area with the lowest index receives the event.
*
* Ownership of the \p 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).
*
* \sa addArea(WAbstractArea *)
*/
void insertArea(int index, WAbstractArea *area);
/*! \brief Removes an interactive area.
*
* Removes the \p area from this widget, returning the
* ownership.
*
* \sa addArea(WAbstractArea *)
*/
void removeArea(WAbstractArea *area);
/*! \brief Returns the interactive area at the given index.
*
* Returns \c 0 if \p index was invalid.
*
* \sa insertArea(int, WAbstractArea *)
*/
WAbstractArea *area(int index) const;
/*! \brief Returns the interactive areas set for this widget.
*
* \sa addArea()
*/
const std::vector<WAbstractArea *> areas() const;
protected:
virtual void layoutSizeChanged(int width, int height);
/*! \brief Paints the widget.
*
* You should reimplement this method to paint the contents of the widget,
* using the given paintDevice.
*/
virtual void paintEvent(WPaintDevice *paintDevice) = 0;
virtual DomElementType domElementType() const;
virtual void updateDom(DomElement& element, bool all);
virtual DomElement *createDomElement(WApplication *app);
virtual void getDomChanges(std::vector<DomElement *>& result,
WApplication *app);
virtual void propagateRenderOk(bool deep);
virtual void enableAjax();
private:
Method preferredMethod_;
WWidgetPainter *painter_;
bool needRepaint_;
bool sizeChanged_;
bool areaImageAdded_;
WFlags<PaintFlag> repaintFlags_;
WImage *areaImage_;
int renderWidth_, renderHeight_;
void resizeCanvas(int width, int height);
bool createPainter();
void createAreaImage();
friend class WWidgetVectorPainter;
friend class WWidgetCanvasPainter;
friend class WWidgetRasterPainter;
};
}
#endif // WPAINTED_WIDGET_H_
|