// 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_LINEEDIT_H_
#define EXT_LINEEDIT_H_

#include <Wt/Ext/FormField>

namespace Wt {

  class WLineEdit;

  namespace Ext {

/*! \class LineEdit Wt/Ext/LineEdit Wt/Ext/LineEdit
 *  \brief A line edit.
 *
 * 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 keyWentUp() signal.
 *
 * At all times, the current content may be accessed with the text()
 * method.
 *
 * The API is a super-set of the WLineEdit API.
 *
 * \ingroup ext
 */
class WT_EXT_API LineEdit : public FormField
{
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 Create a new line edit with empty content.
   */
  LineEdit(WContainerWidget *parent = 0);

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

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

  /*! \brief Return the current width of the line edit in number of characters.
   *
   * \sa setTextSize(int)
   */  
  int textSize() const;
  
  /*! \brief Change the content of the line edit.
   */
  void  setText(const WString& value);
 
  /*! \brief Return the current content.
   */
  const WString& text() const;

  /*! \brief Specify the maximum length of text that can be entered.
   *
   * A value <= 0 indicates that there is no limit.
   *
   * The default value is -1.
   */
  void setMaxLength(int length);

  /*! \brief Returns the maximum length of text that can be entered.
   *
   * \sa setMaxLength(int)
   */
  int maxLength() const;

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

  /*! \brief Return the echo mode.
   */
  EchoMode echoMode() const;
 
  virtual WValidator::State validate();

  void setEmptyDisplayText(const WString& text);
  void setGrowToContent(bool grow, int minWidth = 30, int maxWidth = 800);

  /*! \brief Event signal emitted when a keyboard key is pushed down.
   */
  EventSignal<WKeyEvent>& keyWentDown();

   /*! \brief Event signal emitted when a keyboard key is pressed.
   */
  EventSignal<WKeyEvent>& keyPressed();
    
  /*! \brief Event signal emitted when a keyboard key is released.
   */
  EventSignal<WKeyEvent>& keyWentUp();

  /*! \brief Event signal emitted when enter was pressed.
   *
   * This signal is emitted when the Enter or Return key was pressed.
   *
   * \sa WInteractWidget::enterPressed()
   */
  EventSignal<>& enterPressed();

protected:
  WLineEdit *lineEdit() const { return lineEdit_; }
  virtual WFormWidget *formWidget() const;
  virtual void createConfig(std::ostream& config);

private:
  WLineEdit    *lineEdit_;

  virtual std::string createJS(DomElement *inContainer);

  virtual void useAsTableViewEditor();
};

  }
}

#endif // EXT_LINEEDIT_H_
