// 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 boxes.
 *
 * 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, either connect a slot to the changed()
 * signal, or connect a slot to the
 * \link AbstractToggleButton::checked checked\endlink or
 * \link AbstractToggleButton::unChecked unChecked\endlink signals.
 *
 * The current state (checked or unchecked) may be inspected using the
 * isChecked() method.
 *
 * FIXME: add image functionality for the label.
 *
 * 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 one of the
   * \link AbstractToggleButton::checked checked\endlink or
   * \link AbstractToggleButton::unChecked unChecked \endlink signals.
   *
   * \sa setChecked(), setUnChecked()
   */
  void setChecked(bool);

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

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

public:
  /*! \brief %Signal emitted when the button gets checked.
   */
  EventSignal<void> checked;

  /*! \brief %Signal emitted when the button gets unChecked.
   */
  EventSignal<void> 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_
