1 // This may look like C code, but it's really -*- C++ -*- 2 /* 3 * Copyright (C) 2012 Emweb bv, Herent, Belgium. 4 * 5 * See the LICENSE file for terms of use. 6 */ 7 #ifndef WT_WTHEME_H 8 #define WT_WTHEME_H 9 10 #include <Wt/WObject.h> 11 #include <Wt/WGlobal.h> 12 #include <Wt/WValidator.h> 13 14 namespace Wt { 15 16 class DomElement; 17 class WStringStream; 18 19 /*! \brief Enumeration for the role of a subwidget (for theme support) 20 * 21 * \sa WTheme::apply() 22 */ 23 enum WidgetThemeRole { 24 MenuItemIcon = 100, 25 MenuItemCheckBox = 101, 26 MenuItemClose = 102, 27 28 DialogCoverWidget = 200, 29 DialogTitleBar = 201, 30 DialogBody = 202, 31 DialogFooter = 203, 32 DialogCloseIcon = 204, 33 DialogContent = 205, // For bootstrap 3 modal-content style 34 35 TableViewRowContainer = 300, 36 37 DatePickerPopup = 400, 38 DatePickerIcon = 401, 39 TimePickerPopup = 410, 40 TimePickerPopupContent = 411, 41 42 PanelTitleBar = 500, 43 PanelCollapseButton = 501, 44 PanelTitle = 502, 45 PanelBody = 503, 46 PanelBodyContent = 504, 47 48 AuthWidgets = 600, 49 50 InPlaceEditing = 700, 51 InPlaceEditingButtonsContainer = 701, 52 InPlaceEditingButton = 702, 53 54 Navbar = 800, 55 NavCollapse = 801, 56 NavBrand = 802, 57 NavbarForm = 803, 58 NavbarSearchForm = 804, 59 NavbarSearchInput = 805, 60 NavbarMenu = 806, 61 NavbarBtn = 807, 62 NavbarAlignLeft = 808, 63 NavbarAlignRight = 809 64 }; 65 66 /*! \brief Enumeration for the role of a css class (for theme support) 67 * 68 * \sa WTheme::utilityCssClass() 69 */ 70 enum UtilityCssClassRole { 71 ToolTipInner = 100, 72 ToolTipOuter = 101 73 }; 74 75 /*! \brief Enumeration for the role of a DOM element (for theme support) 76 * 77 * \sa WTheme::apply() 78 */ 79 enum ElementThemeRole { 80 MainElement = 0, 81 ToggleButtonRole = 1, 82 ToggleButtonInput = 2, 83 ToggleButtonSpan = 3, 84 85 FormLabel = 4, 86 FormText = 5, 87 FormButton = 6, 88 FileUploadForm = 7, 89 FileUploadInput = 8, 90 91 ProgressBarBar = 100, 92 ProgressBarLabel = 101 93 }; 94 95 /*! \brief Enumeration that indicates what validation styles are to be applie 96 * 97 * \sa WTheme::applyValidationStyle() 98 */ 99 enum class ValidationStyleFlag { 100 InvalidStyle = 0x1, 101 ValidStyle = 0x2 102 }; 103 104 W_DECLARE_OPERATORS_FOR_FLAGS(ValidationStyleFlag) 105 106 /** \brief All validation styles */ 107 static const WFlags<ValidationStyleFlag> ValidationAllStyles 108 = ValidationStyleFlag::InvalidStyle | ValidationStyleFlag::ValidStyle; 109 110 /*! \class WTheme Wt/WTheme.h Wt/WTheme.h 111 * 112 * Abstract base class for themes in %Wt. 113 * 114 * \sa WApplication::setTheme() 115 */ 116 class WT_API WTheme : public WObject 117 { 118 public: 119 /*! \brief Constructor. 120 */ 121 WTheme(); 122 123 /*! \brief Destructor. 124 */ 125 virtual ~WTheme(); 126 127 /*! \brief Returns a theme name. 128 * 129 * Returns a unique name for the theme. This name is used by the default 130 * implementation of resourcesUrl() to compute a location for the theme's 131 * resources. 132 */ 133 virtual std::string name() const = 0; 134 135 /*! \brief Returns the URL where theme-related resources are stored. 136 * 137 * The default implementation considers a folder within %Wt's 138 * resource directory, based on the theme name(). 139 */ 140 virtual std::string resourcesUrl() const; 141 142 /*! \brief Serves the CSS for the theme. 143 * 144 * This must serve CSS declarations for the theme. 145 * 146 * The default implementation serves all the styleSheets(). 147 */ 148 virtual void serveCss(WStringStream& out) const; 149 150 /*! \brief Returns a vector with stylesheets for the theme. 151 * 152 * This should return a vector with stylesheets that implement the 153 * theme. This list may be tailored to the current user agent, which 154 * is read from the application environment. 155 */ 156 virtual std::vector<WLinkedCssStyleSheet> styleSheets() const = 0; 157 158 /*! \brief Called when the theme is assigned to a WApplication 159 * 160 * This allows the theme to do things like load resource bundles when it 161 * is added to an application using WApplication::setTheme(). 162 * 163 * The default implementation does nothing. 164 */ 165 virtual void init(WApplication *app) const; 166 167 /*! \brief Applies the theme to a child of a composite widget. 168 * 169 * The \p widgetRole indicates the role that \p child has within the 170 * implementation of the \p widget. 171 */ 172 virtual void apply(WWidget *widget, WWidget *child, int widgetRole) 173 const = 0; 174 175 /*! \brief Applies the theme to a DOM element that renders a widget. 176 * 177 * The \p element is a rendered representation of the \p widget, and 178 * may be further customized to reflect the theme. 179 */ 180 virtual void apply(WWidget *widget, DomElement& element, int elementRole) 181 const = 0; 182 183 /*! \brief Sets the data target for a widget. 184 * 185 * The \p widget is a bootstrap element that requires a data-bs-target 186 * attribute to function (with Bootstrap JS). The \p target is the 187 * element that is targeted by the \p widget. 188 */ setDataTarget(WWidget * widget,WWidget * target)189 virtual void setDataTarget(WWidget *widget, WWidget *target) const {}; 190 191 /*! \brief Returns a generic CSS class name for a disabled element. 192 */ 193 virtual std::string disabledClass() const = 0; 194 195 /*! \brief Returns a generic CSS class name for an active element. 196 */ 197 virtual std::string activeClass() const = 0; 198 199 /*! \brief Returns a generic CSS class name for the chosen role. 200 * 201 * \sa WTheme::utilityCssClassRole 202 */ 203 virtual std::string utilityCssClass(int utilityCssClassRole) const = 0; 204 205 /*! \brief Returns whether the theme allows for an anchor to be styled 206 * as a button. 207 */ 208 virtual bool canStyleAnchorAsButton() const = 0; 209 210 /*! \brief Applies a style that indicates the result of validation. 211 */ 212 virtual void applyValidationStyle(WWidget *widget, 213 const Wt::WValidator::Result& validation, 214 WFlags<ValidationStyleFlag> flags) const 215 = 0; 216 217 virtual bool canBorderBoxElement(const DomElement& element) const = 0; 218 }; 219 220 } 221 222 #endif // WT_WTHEME_H 223