/usr/include/Wt/WPushButton is in libwt-dev 3.3.0-1build1.
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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | // 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 WPUSHBUTTON_H_
#define WPUSHBUTTON_H_
#include <Wt/WAnchor>
#include <Wt/WFormWidget>
#include <Wt/WJavaScript>
#include <Wt/WLink>
#include <Wt/WText>
namespace Wt {
/*! \class WPushButton Wt/WPushButton Wt/WPushButton
* \brief A widget that represents a push button.
*
* To act on a button click, connect a slot to the clicked() signal.
*
* \if cpp
* Usage example:
* \code
* Wt::WPushButton *ok = new Wt::WPushButton("Okay");
* ok->clicked().connect(ok, &Wt::WPushButton::disable);
* ok->clicked().connect(this, &MyClass::processData);
* \endcode
* \endif
*
* %WPushButton is an \link WWidget::setInline(bool) inline \endlink widget.
*
* <h3>CSS</h3>
*
* The widget corresponds to the HTML <tt><button></tt> tag (with some
* exceptions in the bootstrap theme).
*/
class WT_API WPushButton : public WFormWidget
{
public:
/*! \brief Creates a push button.
*/
WPushButton(WContainerWidget *parent = 0);
/*! \brief Creates a push button with given label text.
*
* The default text format is PlainText.
*/
WPushButton(const WString& text, WContainerWidget *parent = 0);
virtual ~WPushButton();
/*! \brief Sets the default property.
*
* The only effect of a default button is that it is may be rendered
* in a different style, depending on the theme.
*/
void setDefault(bool enabled);
/*! \brief Returns whether the button is a default button.
*
* \sa setDefault()
*/
bool isDefault() const;
/*! \brief Sets whether the button is checkable.
*
* A checkable button can be checked and unchecked, and clicking
* will toggle between these two states.
*
* \sa setChecked(bool)
*/
void setCheckable(bool checkable);
/*! \brief Returns whether a button is checkable.
*
* \sa setCheckable()
*/
bool isCheckable() const;
/*! \brief Sets the button state.
*
* This is ignored for a button which is not checkable.
*
* This method does not emit one of the checked() or unChecked()
* signals.
*
* \sa setCheckable(), setChecked(), setUnChecked()
*/
void setChecked(bool checked);
/*! \brief Checks the button.
*
* Does not emit the checked() signal.
*
* \sa setChecked(bool)
*/
void setChecked();
/*! \brief Unchecks the button.
*
* Does not emit the unChecked() signal.
*
* \sa setChecked(bool)
*/
void setUnChecked();
/*! \brief Returns the button state.
*
* \sa setChecked()
*/
bool isChecked() const;
/*! \brief Sets the button text.
*
* The default text format is Wt::PlainText.
*
* When the current text format is Wt::XHTMLText, and \p 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 \c false indicates that the text
* format was changed in order to be able to accept the new text.
*
* \sa setTextFormat()
*/
bool setText(const WString& text);
/*! \brief Returns the button text.
*
* \sa setText()
*/
const WString& text() const { return text_.text; }
/*! \brief Sets the text format.
*
* 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::PlainText.
*/
bool setTextFormat(TextFormat format);
/*! \brief Returns the text format.
*
* \sa setTextFormat()
*/
TextFormat textFormat() const { return text_.format; }
/*! \brief Sets an icon.
*
* The icon is placed to the left of the text.
*/
void setIcon(const WLink& link);
/*! \brief Returns the icon.
*
* \sa setIcon()
*/
WLink icon() const { return icon_; }
/*! \brief Sets a destination link.
*
* This method can be used to make the button behave like a WAnchor
* (or conversely, an anchor look like a button) and redirect to
* another URL when clicked.
*
* The \p link may be to a URL, a resource, or an internal path.
*
* By default, a button does not link to an URL and you should
* listen to the clicked() signal to react to a click event.
*/
void setLink(const WLink& link);
/*! \brief Returns the destination link.
*
* \sa setLink()
*/
const WLink& link() const { return linkState_.link; }
/*! \brief Sets a destination URL (<b>deprecated</b>).
*
* \deprecated Use setLink() insteadd.
*/
void setRef(const std::string& url);
/*! \brief Returns the destination URL (<b>deprecated</b>).
*
* When the button refers to a resource, the current resource URL is
* returned. Otherwise, the URL is returned that was set using
* setRef().
*
* \sa setRef(), WResource::url()
*
* \deprecated Use link() instead.
*/
std::string ref() const { return linkState_.link.url(); }
/*! \brief Sets a destination resource (<b>deprecated</b>).
*
* This method can be used to make the button behave like a WAnchor
* (or conversely, an anchor look like a button) and redirect to
* another resource when clicked.
*
* A resource specifies application-dependent content, which may be
* generated by your application on demand.
*
* This sets the \p resource as the destination of the button,
* and is an alternative to setRef(). The resource may be cleared by
* passing \p resource = \c 0.
*
* The button does not assume ownership of the resource.
*
* \sa setRef()
*
* \deprecated Use setLink() instead.
*/
void setResource(WResource *resource);
/*! \brief Returns the destination resource (<b>deprecated</b>).
*
* Returns \c 0 if no resource has been set.
*
* \sa setResource()
*
* \deprecated Use link() instead.
*/
WResource *resource() const { return linkState_.link.resource(); }
/*! \brief Returns the current value.
*
* Returns an empty string, since a button has no value.
*/
virtual WT_USTRING valueText() const;
/*! \brief Sets the current value.
*
* Has no effect, since a button has not value.
*/
virtual void setValueText(const WT_USTRING& value);
/*! \brief Sets the link target.
*
* This sets the target where the linked contents should be displayed.
* The default target is TargetSelf.
*/
void setLinkTarget(AnchorTarget target);
/*! \brief Returns the location where the linked content should be
* displayed.
*
* \sa setLinkTarget()
*/
AnchorTarget linkTarget() const { return linkState_.target; }
void setMenu(WPopupMenu *menu);
WPopupMenu *menu() const { return popupMenu_; }
virtual void refresh();
/*! \brief %Signal emitted when the button gets checked.
*
* This signal is emitted when the user checks the button.
*
* You can use the clicked() signal to react to any change of the
* button state.
*
* \sa setCheckable()
*/
EventSignal<>& checked();
/*! \brief %Signal emitted when the button gets unchecked.
*
* This signal is emitted when the user unchecks the button.
*
* You can use the clicked() signal to react to any change of the
* button state.
*
* \sa setCheckable()
*/
EventSignal<>& unChecked();
private:
static const char *CHECKED_SIGNAL;
static const char *UNCHECKED_SIGNAL;
static const int BIT_TEXT_CHANGED = 0;
static const int BIT_ICON_CHANGED = 1;
static const int BIT_ICON_RENDERED = 2;
static const int BIT_LINK_CHANGED = 3;
static const int BIT_DEFAULT = 4;
static const int BIT_IS_CHECKABLE = 5;
static const int BIT_IS_CHECKED = 6;
static const int BIT_CHECKED_CHANGED = 7;
WAnchor::LinkState linkState_;
WText::RichText text_;
WLink icon_;
std::bitset<8> flags_;
WPopupMenu *popupMenu_;
protected:
virtual void updateDom(DomElement& element, bool all);
virtual DomElementType domElementType() const;
virtual void propagateRenderOk(bool deep);
virtual void getDomChanges(std::vector<DomElement *>& result,
WApplication *app);
private:
void doRedirect();
void resourceChanged();
void renderHRef(DomElement& href);
void toggled();
};
}
#endif // WPUSHBUTTON_H_
|