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

#include <Wt/WCompositeWidget>
#include <Wt/WValidator>

namespace Wt {

class WFormWidget;

/*! \class WValidationStatus Wt/WValidationStatus Wt/WValidationStatus
 *  \brief A widget that keeps track of the validation status of a form widget.
 *
 * <i>Since %Wt 2.1.3, all standard validators provide client-side
 * validation and this is reflected in the form widget using the style
 * class "Wt-invalid" when the validator returns not
 * WValidator::Valid. Therefore, it is unlikely you will need this
 * class anymore.</i>
 *
 * Use a %WValidationStatus widget to act to changes in validation of a
 * WFormWidget. The widget may show visual feed-back of the validation
 * state of the input.
 *
 * Visual feed-back may be given by showing an invalidStateWidget when
 * input is invalid, an invalidEmptyStateWidget when the input is
 * invalid because mandatory and empty, or a validStateWidget when
 * input is valid. All of these widgets may be 0, indicating that no
 * widget will be shown for the corresponding state.
 *
 * When validation state changes from invalid to valid, or from valid
 * to invalid, the widget emits the validated signal. This may be used
 * to for example enable or disable a button.
 * 
 * \deprecated Since %Wt 3.1.1, validation is handled directly on WFormWidget 
 * subclasses.
 */
class WT_API WValidationStatus : public WCompositeWidget
{
public:
  /*! \brief Construct a WValidationStatus widget for another widget.
   *
   * Constructs a validation status widget for the given field.
   *
   * The validation stateWidgets (if not \c 0) will be managed by this
   * widget, and shown and hidden to reflect the current validation
   * state.
   */
  WValidationStatus(WFormWidget *field,
		    WWidget *validStateWidget = 0,
		    WWidget *invalidStateWidget = 0,
		    WWidget *invalidEmptyStateWidget = 0,
		    WContainerWidget *parent = 0);

  /*! \brief Is the field currently considered valid?
   */
  bool valid() const { return state_ == WValidator::Valid; }

  /*! \brief Signal emitted when the validation state changed.
   *
   * The new state of the validation (valid or invalid) is given
   * as argument. This signal gets emitted when the state changes
   * from WValidator::Valid to WValidator::Invalid, or from
   * WValidator::Invalid to WValidator::Valid.
   */
  Signal<bool>& validated() { return validated_; }

private:
  Signal<bool> validated_;

  WContainerWidget *impl_;

  WFormWidget *field_;
  WWidget     *validStateWidget_;
  WWidget     *invalidStateWidget_;
  WWidget     *invalidEmptyStateWidget_;

  WValidator::State state_;

  void inputChanged();
};

}

#endif // WVALIDATION_WIDGET_H_
