Wt::WText Class Reference

A widget that renders (XHTML) text. More...

#include <Wt/WText>

Inheritance diagram for Wt::WText:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 WText (WContainerWidget *parent=0)
 Construct a text widget with an empty text.
 WText (const WString &text, WContainerWidget *parent=0)
 Construct a text widget with given text.
 WText (const WString &text, TextFormat textFormat, WContainerWidget *parent=0)
 Construct a text widget with given text and format.
 WText (bool inlined, const WString &text, WContainerWidget *parent=0)
 Construct a text widget with a given text.
const WStringtext () const
 Returns the text.
bool setText (const WString &text)
 Set the text.
bool setTextFormat (TextFormat format)
 Set the textFormat.
TextFormat textFormat () const
 Returns the textFormat.
bool setFormatting (Formatting format)
 Set the formatting (deprecated).
Formatting formatting () const
 Returns the formatting (deprecated).
void setWordWrap (bool on)
 Configure word wrapping.
bool wordWrap () const
 Returns whether the widget may break lines.
virtual void refresh ()
 Refresh the widget.


Detailed Description

A widget that renders (XHTML) text.

The text is provided through a WString, which may either hold a literal text, or a key to localized text which is looked up in locale dependent XML files (see WString::tr()).

Use setTextFormat() to configure the textFormat of the text. The default textFormat is Wt::XHMTLText, which allows any XHMTL textFormat to be included in the text. Tags and attributes that indicate "active" content are not allowed and stripped out, to avoid security risks exposed by JavaScript such as the common web-based Cross-Site Scripting (XSS) malicious attack.

The Wt::PlainText format will display the text literally (escaping any HTML special characters).

In some situations, Wt::XHTMLUnsafeText is useful. Like XHTMLText, it allows XHTML markup, but it also allows potentially dangerous tags and attributes. Use this if you're sure that a user cannot interfere with the text set, and XHTMLText is too limiting.

WText is by default an inline widget, unless the XHTML contents starts with a block-level element such as <div>, <h> or <p>.

See also:
WApplication::setLocale()

WApplication::messageResourceBundle()


Constructor & Destructor Documentation

Wt::WText::WText ( const WString text,
WContainerWidget parent = 0 
)

Construct a text widget with given text.

The textFormat is set to Wt::XHTMLText, unless the text is literal (not created using WString::tr()) and it could not be parsed as valid XML. In that case the textFormat is set to Wt::PlainText.

Therefore, if you wish to use Wt::XHTMLText, but cannot be sure about text being valid XML, you should verify that the textFormat() is Wt::XHTMLText after construction.

The XML parser will silently discard malicious tags and attributes silently for literal text with Wt::XHTMLText.

Wt::WText::WText ( const WString text,
TextFormat  textFormat,
WContainerWidget parent = 0 
)

Construct a text widget with given text and format.

If textFormat is Wt::XHTMLText and text is not literal (not created using WString::tr()), then if the text could not be parsed as valid XML, the textFormat is changed to Wt::PlainText.

Therefore, if you wish to use Wt::XHTMLText, but cannot be sure about text being valid XML, you should verify that the textFormat() is Wt::XHTMLText after construction.

The XML parser will silently discard malicious tags and attributes silently for literal text with textFormat of Wt::XHTMLText.

Wt::WText::WText ( bool  inlined,
const WString text,
WContainerWidget parent = 0 
)

Construct a text widget with a given text.

Deprecated:
Not useful anymore. Let the widget autodetect using its heuristics, or call setInline() explicitly after construction.
This is an overloaded constructor provided for convience and equivalent to:

 WText *t = new WText(text, parent);
 t->setInline(inlined)

The format is set to Wt::XHTMLText, unless the text is literal (not created using WString::tr()) and it could not be parsed as valid XML. In that case the textFormat is set to Wt::PlainText.

The XML parser will silently discard malicious tags and attributes silently for literal text with Wt::XHTMLText.

Therefore, if you wish to use Wt::XHTMLText, but cannot be sure about text being valid XML, you should verify that the textFormat() is Wt::XHTMLText after construction.

Note:
Since 2.1.4, some heuristics are used to see if the text is an HTML block-level element, so this constructor is no longer as useful.


Member Function Documentation

const WString& Wt::WText::text (  )  const [inline]

Returns the text.

When a literal XHTMLFormatted text was set, this may differ from the text that was set since malicious tags/attributes may have been stripped.

See also:
setText(const WString&)

bool Wt::WText::setText ( const WString text  ) 

Set the text.

When the current format is Wt::XHTMLText, and text is literal (not created using WString::tr()), it is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is changed to Wt::PlainText.

Returns whether the text could be set using the current textFormat. A return value of false indicates that the textFormat was changed in order to be able to accept the new text.

See also:
text(), setText()

bool Wt::WText::setTextFormat ( TextFormat  format  ) 

Set the textFormat.

The textFormat controls how the string should be interpreted: either as plain text, which is displayed literally, or as XHTML-markup.

When changing the textFormat to Wt::XHTMLText, and the current text is literal (not created using WString::tr()), the current text is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is left unchanged, and this method returns false.

Returns whether the textFormat could be set for the current text.

The default format is Wt::XHTMLText.

TextFormat Wt::WText::textFormat (  )  const [inline]

Returns the textFormat.

See also:
setTextFormat()

bool Wt::WText::setFormatting ( Formatting  format  ) 

Set the formatting (deprecated).

Deprecated:
Has been renamed to setTextFormat().

Formatting Wt::WText::formatting (  )  const [inline]

Returns the formatting (deprecated).

Deprecated:
Has been renamed to textFormat()

void Wt::WText::setWordWrap ( bool  on  ) 

Configure word wrapping.

When on is true, the widget may break lines, creating a multi-line text. When on is false, the text will displayed on a single line, unless the text contains end-of-lines (for Wt::PlainText) or <br /> tags or other block-level tags (for Wt::XHTMLText).

The default value is true.

See also:
wordWrap()

bool Wt::WText::wordWrap (  )  const [inline]

Returns whether the widget may break lines.

See also:
setWordWrap(bool)

void Wt::WText::refresh (  )  [virtual]

Refresh the widget.

The refresh method is invoked when the locale is changed using WApplication::setLocale() or when the user hit the refresh button.

The widget must actualize its contents in response.

Reimplemented from Wt::WWebWidget.


Generated on Fri Apr 24 16:26:00 2009 for Wt by doxygen 1.5.6