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 8 #ifndef ROUNDED_WIDGET_H_ 9 #define ROUNDED_WIDGET_H_ 10 11 #include <Wt/WCompositeWidget.h> 12 13 #include <array> 14 15 #include "CornerImage.h" 16 17 namespace Wt { 18 class WContainerWidget; 19 } 20 21 /** 22 * @addtogroup styleexample 23 */ 24 /*@{*/ 25 26 /*! \brief A widget with rounded corners. 27 * 28 * This widgets represents a widget for which any combination of its four 29 * corners may be rounded. Although rounded corners is not a standard part 30 * of the CSS specification, this widget will be rendered identical on 31 * all platforms. 32 * 33 * The contents of the widget is managed inside a WContainerWidget, which 34 * is accessed using the contents() method. 35 * 36 * The radius of the rounded corners, the background color of the image, 37 * and the surrounding color may be changed at all times. 38 * 39 * The RoundedWidget is part of the %Wt style example. 40 * 41 * \sa CornerImage. 42 */ 43 class RoundedWidget : public WCompositeWidget 44 { 45 public: 46 /*! \brief Construct a widget with any combination of its corners 47 * rounded. 48 */ 49 RoundedWidget(WFlags<Corner> corners = WFlags<Corner>(Corner::TopLeft) | 50 Corner::TopRight | 51 Corner::BottomLeft | 52 Corner::BottomRight); 53 54 /*! \brief Set the widget background color. 55 * 56 * Because the background color also affects the color of the 57 * corner images, the background color cannot be set using the 58 * WCssDecorationStyle() of the widget. 59 */ 60 void setBackgroundColor(WColor color); 61 62 /*! \brief Get the widget background color. 63 */ backgroundColor()64 WColor backgroundColor() const { return backgroundColor_; } 65 66 /*! \brief Show or hide rounded corners. 67 */ 68 void enableRoundedCorners(bool how); 69 70 /*! \brief Set the corner radius of the widget. 71 */ 72 void setCornerRadius(int radius); 73 74 /*! \brief Get the corner radius of the widget. 75 */ cornerRadius()76 int cornerRadius() const { return radius_; } 77 78 /*! \brief Set the surrounding color of the widget. 79 * 80 * This color will be used "outside" the corner, in each of the 81 * corner images. 82 */ 83 void setSurroundingColor(WColor color); 84 85 /*! \brief Get the surrounding color of the widget. 86 */ surroundingColor()87 WColor surroundingColor() const { return surroundingColor_; } 88 89 /*! \brief Access the contents container. 90 * 91 * The contents WContainerWidget represents the contents inside 92 * the rounded widget. 93 */ contents()94 WContainerWidget *contents() const { return contents_; } 95 96 private: 97 //! Background color 98 WColor backgroundColor_; 99 100 //! "Surrounding" color -- maybe we can use a transparent color ? 101 WColor surroundingColor_; 102 103 //! Radius 104 int radius_; 105 106 //! OR'ed specification of the corners which are to be rounded. 107 WFlags<Corner> corners_; 108 109 //! The container widget in which to store the contents. 110 WContainerWidget *contents_; 111 112 //! This composite widget is implemented as a WContainerWidget 113 WContainerWidget *impl_; 114 115 //! A container at the top which renders the top rounding 116 WContainerWidget *top_; 117 118 //! A container at the bottom renders the bottom rounding 119 WContainerWidget *bottom_; 120 121 //! Up to four CornerImages for each corner. 122 std::array<Wt::Core::observing_ptr<CornerImage>, 4> images_; 123 124 //! Create the implementation. 125 void create(); 126 127 //! Adjust the image (colors and radius). 128 void adjust(); 129 }; 130 131 /*@}*/ 132 133 #endif // ROUNDED_WIDGET_H_ 134