// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2005 Koen Deforche, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WLINEEDIT_H_
#define WLINEEDIT_H_

#include <WFormWidget>

namespace Wt {

/*! \class WLineEdit WLineEdit WLineEdit
 *  \brief %WLineEdit Provides a single line edit.
 *
 * %WLineEdit is an \link WWidget::setInline(bool) inline \endlink widget.
 *
 * To act upon text changes, connect a slot to the changed() signal.
 * This signal is emitted when the user changed the content, and
 * subsequently removes the focus from the line edit.
 *
 * To act upon editing, connect a slot to the
 * WInteractWidget::keyWentUp signal.
 *
 * At all times, the current content may be accessed with the text()
 * method.
 */
class WT_API WLineEdit : public WFormWidget
{
public:
  /*! \brief Enum that describes how the contents is displayed.
   *
   * \sa setEchoMode
   * \sa echoMode
   */
  enum EchoMode { Normal,   //!< Characters are shown.
		  Password, //!< Hide the contents as for a password.
  };

  /*! \brief Construct a line edit with empty content and optional parent.
   */
  WLineEdit(WContainerWidget *parent = 0);

  /*! \brief Construct a line edit with given content and optional parent.
   */
  WLineEdit(const WString& content, WContainerWidget *parent = 0);

  /*! \brief Specify the width of the line edit in number of characters.
   */
  void setTextSize(int chars);

  /*! \brief Get the current width of the line edit in number of characters.
   *
   * \sa setTextSize(int)
   */
  int textSize() const { return textSize_; }

  /*! \brief Get the current content.
   */
  const WString& text() const { return content_; }

  /*! \brief Set the echo mode.
   *
   * The default echo mode is Normal.
   */
  void setEchoMode(EchoMode echoMode);

  /*! \brief Get the echo mode.
   */
  EchoMode echoMode() const { return echoMode_; }

  WValidator::State validate();

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

private:
  WString      content_;
  int          textSize_;
  EchoMode     echoMode_;

  bool contentChanged_;
  bool textSizeChanged_;
  bool echoModeChanged_;

protected:
  virtual void        updateDom(DomElement& element, bool all);
  virtual DomElement *createDomElement();
  virtual void        getDomChanges(std::vector<DomElement *>& result);

  virtual void        setFormData(CgiEntry *entry);
};

}

#endif // WLINEEDIT_H_
