// 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 WICONPAIR_H_
#define WICONPAIR_H_

#include <Wt/WCompositeWidget>
#include <Wt/WEvent>

namespace Wt {

class WImage;

/*! \brief A widget that shows one of two items depending on its state.
 *
 * This widget manages two images, only one of which is shown at a single
 * time, which reflects the current 'state'.
 *
 * The widget may react to click events, by changing state.
 */
class WT_API WIconPair : public WCompositeWidget
{
public:
  /*! \brief Construct an icon pair from the two icons.
   *
   * The constructor takes the URI of the two icons. When clickIsSwitch
   * is set true, clicking on the icon will switch state.
   */
  WIconPair(const std::string& icon1URI, const std::string& icon2URI,
	    bool clickIsSwitch = true, WContainerWidget *parent = 0);

  /*! \brief Set the state, which determines the visible icon.
   *
   * The first icon has number 0, and the second icon has number 1.
   *
   * The default state is 0.
   *
   * \sa state()
   */
  void setState(int num);

  /*! \brief Get the current state.
   *
   * \sa setState()
   */
  int state() const;

  /*! \brief Get the first icon image
   */
  WImage *icon1() const { return icon1_; }
  
  /*! \brief Get the second icon image
   */
  WImage *icon2() const { return icon2_; }

public slots:
  /*! \brief Set state to 0 (show icon 1).
   */
  void showIcon1();

  /*! \brief Set state to 1 (show icon 2).
   */ 
  void showIcon2();

private:
  WContainerWidget *impl_;
  WImage *icon1_;
  WImage *icon2_;

public:
  /*! \brief Signal emitted when clicked while in state 0 (icon 1 is
   *         shown).
   */
  EventSignal<WMouseEvent>& icon1Clicked;

  /*! \brief Signal emitted when clicked while in state 1 (icon 2 is
   *         shown).
   */
  EventSignal<WMouseEvent>& icon2Clicked;
};

}

#endif // WICONPAIR_H_
