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

#include <Wt/Ext/FormField>

namespace Wt {
  class WAbstractToggleButton;
  namespace Ext {

/*! \class AbstractToggleButton Ext/AbstractToggleButton
 *         Ext/AbstractToggleButton
 *  \brief Abstract base class for radio button and check box.
 *
 * A toggle button provides a button with a boolean state (checked or
 * unchecked), and a text label.
 *
 * To act on a change of the state, you can listen to the checked() or
 * unChecked() signals.
 *
 * The current state (checked or unchecked) may be inspected using the
 * isChecked() method.
 *
 * The API is identical to the WAbstractToggleButton API.
 *
 * \ingroup ext
 */
class WT_EXT_API AbstractToggleButton : public FormField
{
protected:
  AbstractToggleButton(WAbstractToggleButton *wtWidget,
		       const WString& text, WContainerWidget *parent);

public:
  /*! \brief Change the text of the label.
   */
  void setText(const WString& text);

  /*! \brief Get the text of the label.
   */
  const WString text() const { return text_; }

  /*! \brief Returns the state of the button.
   */
  bool isChecked() const;

public slots:
  /*! \brief Change the state of the button.
   *
   * Does not emit the checked() or unChecked() signals.
   *
   * \sa setChecked(), setUnChecked()
   */
  void setChecked(bool);

  /*! \brief Set the button checked.
   *
   * Does not emit the checked() signal.
   *
   * \sa setChecked(bool)
   */
  virtual void setChecked();

  /*! \brief Set the button unChecked.
   *
   * Does not emit the unChecked() signal.
   *
   * \sa setChecked(bool)
   */
  virtual void setUnChecked();

public:
  /*! \brief %Signal emitted when the button gets checked.
   *
   * \sa unChecked()
   */
  EventSignal<>& checked();

  /*! \brief %Signal emitted when the button gets unChecked.
   *
   * \sa checked()
   */
  EventSignal<>& unChecked();

private:
  WAbstractToggleButton *wtWidget_;
  WString                text_;

  virtual std::string createJS(DomElement *inContainer);
  virtual std::string getExtName() const = 0;

  virtual void useAsTableViewEditor();

protected:
  WAbstractToggleButton *wtWidget() const { return wtWidget_; }
  virtual void createConfig(std::ostream& config);
  virtual WFormWidget *formWidget() const;
  virtual bool applySelfCss() const;
};

  }
}

#endif // EXT_ABSTRACT_TOGGLE_BUTTON_H_
