Wt  3.7.1
Public Types | Public Member Functions | List of all members
Wt::WLink Class Reference

A value class that defines a hyperlink target. More...

Public Types

enum  Type { Url, Resource, InternalPath }
 An enumeration for a link type. More...
 

Public Member Functions

 WLink ()
 Default constructor. More...
 
 WLink (const char *url)
 Creates a link to a (static) URL. More...
 
 WLink (const std::string &url)
 Creates a link to a (static) URL. More...
 
 WLink (Type type, const std::string &value)
 Creates a link to a (static) URL or an internal path. More...
 
 WLink (WResource *resource)
 Creates a link to a resource. More...
 
Type type () const
 Returns the link type. More...
 
bool isNull () const
 Returns whether the link is unspecified. More...
 
void setUrl (const std::string &url)
 Sets the link URL. More...
 
std::string url () const
 Returns the link URL. More...
 
void setResource (WResource *resource)
 Sets the link resource. More...
 
WResourceresource () const
 Returns the link resource. More...
 
void setInternalPath (const WString &internalPath)
 Sets the link internal path. More...
 
WString internalPath () const
 Returns the internal path. More...
 
void setTarget (AnchorTarget target)
 Sets the location where the linked content should be displayed. More...
 
AnchorTarget target () const
 Returns the location where the linked content should be displayed. More...
 
bool operator== (const WLink &other) const
 Comparison operator.
 
bool operator!= (const WLink &other) const
 Comparison operator.
 

Detailed Description

A value class that defines a hyperlink target.

This class abstracts a link target. Depending on the context, it may reference a URL, a dynamic resource, or (for certain usages) an internal path.

See also
WAnchor, WImage, WMediaPlayer, WPopupMenuItem, WPushButton

Member Enumeration Documentation

◆ Type

An enumeration for a link type.

See also
type()
Enumerator
Url 

A static URL.

Resource 

A dynamic resource.

InternalPath 

An internal path.

Constructor & Destructor Documentation

◆ WLink() [1/5]

Wt::WLink::WLink ( )

Default constructor.

This constructs a null link.

◆ WLink() [2/5]

Wt::WLink::WLink ( const char *  url)

Creates a link to a (static) URL.

See also
setUrl()

◆ WLink() [3/5]

Wt::WLink::WLink ( const std::string &  url)

Creates a link to a (static) URL.

See also
setUrl()

◆ WLink() [4/5]

Wt::WLink::WLink ( Type  type,
const std::string &  value 
)

Creates a link to a (static) URL or an internal path.

Using this constructor, you can create a link to a static URL (type == WLink::Url) or an internal path (type == WLink::InternalPath). For an internal path, the value will be interpreted as a UTF8 encoded string.

See also
setUrl(), setInternalPath()

◆ WLink() [5/5]

Wt::WLink::WLink ( WResource resource)

Creates a link to a resource.

Ownership of the resource is not transferred to the link (or to the widget that deals with it), to allow resources to be shared.

See also
setResource()

Member Function Documentation

◆ internalPath()

WString Wt::WLink::internalPath ( ) const

Returns the internal path.

This returns the internal path perviously set using setInternalPath(), or an empty string otherwise.

See also
setInternalPath().

◆ isNull()

bool Wt::WLink::isNull ( ) const

Returns whether the link is unspecified.

A null link is a link created using the default constructor and points to nowhere.

See also
WLink()

◆ resource()

WResource * Wt::WLink::resource ( ) const

Returns the link resource.

This returns the resource previously set using setResource(), or 0.

See also
setResource()

◆ setInternalPath()

void Wt::WLink::setInternalPath ( const WString internalPath)

Sets the link internal path.

This points the link to the given internal path.

◆ setResource()

void Wt::WLink::setResource ( WResource resource)

Sets the link resource.

This sets the type to WLink::Resource.

Ownership of the resource is not transferred to the link (or to the widget that deals with it), to allow resources to be shared.

◆ setTarget()

void Wt::WLink::setTarget ( AnchorTarget  target)

Sets the location where the linked content should be displayed.

By default, the linked content is displayed in the application (Wt::TargetSelf). When the destination is an HTML document, the application is replaced with the new document. When the link is to a document that cannot be displayed in the browser, it is offered for download or opened using an external program, depending on browser settings.

By setting target to Wt::TargetNewWindow, the destination is displayed in a new browser window or tab.

See also
target()

◆ setUrl()

void Wt::WLink::setUrl ( const std::string &  url)

Sets the link URL.

This sets the type to WLink::Url.

◆ target()

AnchorTarget Wt::WLink::target ( ) const

Returns the location where the linked content should be displayed.

See also
setTarget()

◆ type()

Type Wt::WLink::type ( ) const

Returns the link type.

The type is implicitly set depending on the constructor or after calling setUrl(), setResource() or setInternalPath().

The default type for a null link is WLink::Url.

◆ url()

std::string Wt::WLink::url ( ) const

Returns the link URL.

The return value is the URL set by setUrl(), the resource URL of the resource set using setResource(), or the canonical URL of an internal path within the current application context.


Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13