Coverage Report

Created: 2026-02-26 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WCssDecorationStyle.h
Line
Count
Source
1
// This may look like C code, but it's really -*- C++ -*-
2
/*
3
 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4
 *
5
 * See the LICENSE file for terms of use.
6
 */
7
#ifndef WCSSDECORATIONSTYLE_H_
8
#define WCSSDECORATIONSTYLE_H_
9
10
#include <Wt/WBorder.h>
11
#include <Wt/WColor.h>
12
#include <Wt/WFont.h>
13
#include <Wt/WLink.h>
14
#include <Wt/WWidget.h>
15
16
namespace Wt {
17
18
/*! \brief Text decoration options
19
 */
20
enum class TextDecoration {
21
  Underline   = 0x1, //!< Underline
22
  Overline    = 0x2, //!< Overline
23
  LineThrough = 0x4, //!< LineThrough
24
  Blink       = 0x8, //!< Blink
25
  None        = 0x10 //!< None
26
};
27
28
class DomElement;
29
class WWebWidget;
30
31
/*! \defgroup style Style classes
32
 *  \brief Collection of classes for markup of widgets.
33
 *
34
 * The recommended way to provide style information for your %Wt
35
 * application is using CSS stylesheets. You may add rules to the
36
 * inline style sheet using WCssStyleSheet::addRule(), or by linking
37
 * one or more external stylesheets using WApplication::useStyleSheet().
38
 *
39
 * Alternatively, you may also provide style information directly,
40
 * using WCssDecorationStyle, which you can manipulate for each widget
41
 * using WWidget::decorationStyle().
42
 */
43
44
/*! \class WCssDecorationStyle Wt/WCssDecorationStyle.h Wt/WCssDecorationStyle.h
45
 *  \brief A style class for a single widget or style sheet rule.
46
 *
47
 * You can manipulate the decoration style of a single widget using
48
 * WWidget::decorationStyle() or you can use a WCssDecorationStyle to
49
 * add a rule to the inline style sheet using
50
 * WCssStyleSheet::addRule(const std::string&, const WCssDecorationStyle& style, const std::string&).
51
 *
52
 * \if cpp
53
 * Usage example:
54
 * \code
55
 * Wt::WWidget *widget = ...
56
 * widget->decorationStyle().setCursor(Cursor::PointingHand);
57
 * \endcode
58
 * \endif
59
 *
60
 * \ingroup style
61
 */
62
class WT_API WCssDecorationStyle : public WObject
63
{
64
public:
65
  /*! \brief Creates a default style.
66
   */
67
  WCssDecorationStyle();
68
69
  /*! \brief Copy constructor
70
   */
71
  WCssDecorationStyle(const WCssDecorationStyle& other);
72
73
  /*! \brief Destructor.
74
   */
75
  ~WCssDecorationStyle();
76
77
  /*! \brief Assignment operator.
78
   */
79
  WCssDecorationStyle& operator= (const WCssDecorationStyle& other);
80
81
  /*! \brief Sets the cursor style.
82
   */
83
  void setCursor(Cursor c);
84
85
  /*! \brief Returns the cursor style.
86
   *
87
   * \sa setCursor()
88
   */
89
0
  Cursor cursor() const { return cursor_; }
90
91
  /*! \brief Sets a custom cursor image Url.
92
   *
93
   * The Url should point to a .cur file (this shoul be a real .cur file,
94
   * renaming an .ico is not enough for Internet Explorer).
95
   */
96
  void setCursor(std::string cursorImage,
97
                 Cursor fallback = Cursor::Arrow);
98
99
  /*! \brief Returns the cursor image.
100
   *
101
   * \sa setCursor()
102
   */
103
0
  std::string cursorImage() const { return cursorImage_; }
104
105
  /*! \brief Sets the background color.
106
   */
107
  void setBackgroundColor(WColor color);
108
109
  /*! \brief Returns the background color.
110
   *
111
   * \sa setBackgroundColor()
112
   */
113
0
  WColor backgroundColor() const { return backgroundColor_; }
114
115
  /*! \brief Sets a background image.
116
   *
117
   * The \p link may be a URL or a resource.
118
   *
119
   * The image may be placed in a particular location by specifying
120
   * sides by OR'ing Wt::Side values together, e.g. (Side::Right | Side::Top).
121
   */
122
  void setBackgroundImage(const WLink& link,
123
                          WFlags<Orientation> repeat
124
                            = Orientation::Horizontal | Orientation::Vertical,
125
                          WFlags<Side> sides = None);
126
127
#ifdef WT_TARGET_JAVA
128
  /*! \brief Sets a background image.
129
   *
130
   * The image may be placed in a particular location by specifying
131
   * sides by OR'ing Wt::Side values together, e.g. (Side::Right | Side::Top).
132
   */
133
  void setBackgroundImage(const std::string& url,
134
                          WFlags<Orientation> repeat
135
                            = Orientation::Horizontal | Orientation::Vertical,
136
                          WFlags<Side> sides = None);
137
#endif // WT_TARGET_JAVA
138
139
  /*! \brief Returns the background image URL.
140
   *
141
   * \sa setBackgroundImage()
142
   */
143
0
  std::string backgroundImage() const { return backgroundImage_.url(); }
144
145
  /*! \brief Returns the background image repeat.
146
   *
147
   * \sa setBackgroundImage()
148
   */
149
0
  WFlags<Orientation> backgroundImageRepeat() const { return backgroundImageRepeat_; }
150
151
  /*! \brief Sets the text color.
152
   */
153
  void setForegroundColor(WColor color);
154
155
  /*! \brief Returns the text color.
156
   *
157
   * \sa setForegroundColor()
158
   */
159
0
  WColor foregroundColor() const { return foregroundColor_; }
160
161
  /*! \brief Sets the border style.
162
   *
163
   * The given \p border will be set for the specified \p sides.
164
   *
165
   * A different border style may be specified for each of the four
166
   * sides.
167
   */
168
  void setBorder(WBorder border, WFlags<Side> sides = AllSides);
169
170
  /*! \brief Returns the border style.
171
   *
172
   * Returns the border style set using setBorder() for the given \p
173
   * side.
174
   *
175
   * \sa setBorder()
176
   *
177
   * \note Prior to version 3.1.9 it was not possible to pass a side
178
   *       and only one border could be configured.
179
   */
180
  WBorder border(Side side = Side::Top) const;
181
182
  /*! \brief Sets the text font.
183
   */
184
  void setFont(const WFont& font);
185
186
  /*! \brief Returns the font.
187
   *
188
   * \sa setFont()
189
   */
190
0
  WFont& font() { return font_; }
191
0
  const WFont& font() const { return font_; }
192
193
  /*! \brief Sets text decoration options.
194
   *
195
   * You may logically or together any of the options of the
196
   * TextDecoration enumeration.
197
   *
198
   * The default is 0.
199
   */
200
  void setTextDecoration(WFlags<TextDecoration> decoration);
201
202
  /*! \brief Returns the text decoration options.
203
   *
204
   * \sa setTextDecoration()
205
   */
206
0
  WFlags<TextDecoration> textDecoration() const { return textDecoration_; }
207
208
  std::string cssText();
209
  void updateDomElement(DomElement& element, bool all);
210
211
private:
212
  WWebWidget               *widget_;
213
  Cursor                    cursor_;
214
  std::string               cursorImage_;
215
  std::unique_ptr<WBorder>  border_[4];
216
  WColor                    backgroundColor_;
217
  WColor                    foregroundColor_;
218
  WLink                     backgroundImage_;
219
  WFlags<Orientation>       backgroundImageRepeat_;
220
  WFlags<Side>              backgroundImageLocation_;
221
  WFont                     font_;
222
  WFlags<TextDecoration>    textDecoration_;
223
224
  bool                      cursorChanged_;
225
  bool                      borderChanged_;
226
  bool                      foregroundColorChanged_;
227
  bool                      backgroundColorChanged_;
228
  bool                      backgroundImageChanged_;
229
  bool                      fontChanged_;
230
  bool                      textDecorationChanged_;
231
232
  void changed(WFlags<RepaintFlag> flags = None);
233
  void backgroundImageResourceChanged();
234
  WBorder borderI(unsigned i) const;
235
236
  void copy(const WCssDecorationStyle& other);
237
238
  void setWebWidget(WWebWidget *widget);
239
  friend class WWebWidget;
240
};
241
242
W_DECLARE_OPERATORS_FOR_FLAGS(TextDecoration)
243
244
}
245
246
#endif // WCSSDECORATIONSTYLE_H_