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 WICONPAIR_H_ 8 #define WICONPAIR_H_ 9 10 #include <Wt/WCompositeWidget.h> 11 #include <Wt/WEvent.h> 12 13 namespace Wt { 14 15 class WImage; 16 17 /*! \class WIconPair Wt/WIconPair.h Wt/WIconPair.h 18 * \brief A widget that shows one of two icons depending on its state. 19 * 20 * This is a utility class that simply manages two images, only one of 21 * which is shown at a single time, which reflects the current 22 * 'state'. 23 * 24 * The widget may react to click events, by changing state. 25 * 26 * <h3>CSS</h3> 27 * 28 * This widget does not provide styling, 29 * and can be styled using inline or external CSS as appropriate. 30 * The image may be styled via the <tt><img></tt> elements. 31 */ 32 class WT_API WIconPair : public WCompositeWidget 33 { 34 public: 35 /*! \brief Construct an icon pair from the two icons. 36 * 37 * The constructor takes the URL of the two icons. When 38 * \p clickIsSwitch is set \c true, clicking on the icon will 39 * switch state. 40 */ 41 WIconPair(const std::string& icon1URL, const std::string& icon2URL, 42 bool clickIsSwitch = true); 43 44 /*! \brief Sets the state, which determines the visible icon. 45 * 46 * The first icon has number 0, and the second icon has number 1. 47 * 48 * The default state is 0. 49 * 50 * \sa state() 51 */ 52 void setState(int num); 53 54 /*! \brief Returns the current state. 55 * 56 * \sa setState() 57 */ 58 int state() const; 59 60 /*! \brief Returns the first icon image 61 */ icon1()62 WImage *icon1() const { return icon1_; } 63 64 /*! \brief Returns the second icon image 65 */ icon2()66 WImage *icon2() const { return icon2_; } 67 68 /*! \brief Sets the state to 0 (show icon 1). 69 * 70 * \sa setState(int) 71 */ 72 void showIcon1(); 73 74 /*! \brief Sets the state to 1 (show icon 2). 75 * 76 * \sa setState(int) 77 */ 78 void showIcon2(); 79 80 /*! \brief %Signal emitted when clicked while in state 0 (icon 1 is 81 * shown). 82 * 83 * Equivalent to: 84 * \code 85 * icon1()->clicked() 86 * \endcode 87 */ 88 EventSignal<WMouseEvent>& icon1Clicked(); 89 90 /*! \brief %Signal emitted when clicked while in state 1 (icon 2 is 91 * shown). 92 * 93 * Equivalent to: 94 * \code 95 * icon2()->clicked() 96 * \endcode 97 */ 98 EventSignal<WMouseEvent>& icon2Clicked(); 99 100 private: 101 WContainerWidget *impl_; 102 WImage *icon1_; 103 WImage *icon2_; 104 }; 105 106 } 107 108 #endif // WICONPAIR_H_ 109