Wt
4.11.0
|
A value class that defines a hyperlink target. More...
#include <WLink.h>
Public Types | |
typedef LinkType | Type |
Typedef for enum Wt::LinkType. | |
typedef LinkTarget | Target |
Typedef for enum Wt::LinkTarget. | |
Public Member Functions | |
WLink () | |
Default constructor. | |
WLink (const char *url) | |
Creates a link to a (static) URL. | |
WLink (const std::string &url) | |
Creates a link to a (static) URL. | |
WLink (LinkType type, const std::string &value) | |
Creates a link to a (static) URL or an internal path. | |
WLink (const std::shared_ptr< WResource > &resource) | |
Creates a link to a resource. | |
LinkType | type () const |
Returns the link type. | |
bool | isNull () const |
Returns whether the link is unspecified. | |
void | setUrl (const std::string &url) |
Sets the link URL. | |
std::string | url () const |
Returns the link URL. | |
void | setResource (const std::shared_ptr< WResource > &resource) |
Sets the link resource. | |
std::shared_ptr< WResource > | resource () const |
Returns the link resource. | |
void | setInternalPath (const WString &internalPath) |
Sets the link internal path. | |
WString | internalPath () const |
Returns the internal path. | |
void | setTarget (LinkTarget target) |
Sets the location where the linked content should be displayed. | |
LinkTarget | target () const |
Returns the location where the linked content should be displayed. | |
bool | operator== (const WLink &other) const |
Comparison operator. | |
bool | operator!= (const WLink &other) const |
Comparison operator. | |
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.
Wt::WLink::WLink | ( | ) |
Default constructor.
This constructs a null link.
Creates a link to a (static) URL or an internal path.
Using this constructor, you can create a link to a static URL (type
== LinkType::Url) or an internal path (type
== LinkType::InternalPath). For an internal path, the value
will be interpreted as a CharEncoding::UTF8 encoded string.
Creates a link to a resource.
WString Wt::WLink::internalPath | ( | ) | const |
Returns the internal path.
This returns the internal path perviously set using setInternalPath(), or an empty string otherwise.
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.
std::shared_ptr< WResource > Wt::WLink::resource | ( | ) | const |
Returns the link resource.
This returns the resource previously set using setResource(), or 0
.
Sets the link internal path.
This points the link to the given internal path.
Sets the link resource.
This sets the type to LinkType::Resource.
void Wt::WLink::setTarget | ( | LinkTarget | target | ) |
Sets the location where the linked content should be displayed.
By default, the linked content is displayed in the application (Wt::LinkTarget::Self). 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::LinkTarget::NewWindow, the destination is displayed in a new browser window or tab.
Sets the link URL.
This sets the type to LinkType::Url.
LinkTarget Wt::WLink::target | ( | ) | const |
Returns the location where the linked content should be displayed.
LinkType 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 LinkType::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.