// 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_TEXTEDIT_H_
#define EXT_TEXTEDIT_H_

#include <Wt/Ext/FormField>

namespace Wt {

  class WTextArea;

  namespace Ext {

/*! \class TextEdit Ext/TextEdit Ext/TextEdit
 *  \brief A rich-text editor.
 *
 * A rich-text editor that provides interactive editing of HTML, including
 * basic mark-up (font, formatting, color, links, and lists).
 *
 * \image html ExtTextEdit-1.png "TextEdit"
 *
 * \note This widget does not work in XHTML documents. Use WTextEdit instead.
 *
 * \ingroup ext
 */
class WT_EXT_API TextEdit : public FormField
{
public:
  /*! \brief Create a rich text editor with empty text.
   */
  TextEdit(WContainerWidget *parent = 0);

  /*! \brief Create a rich text editor initialized with the given HTML text.
   */
  TextEdit(const WT_USTRING& text, WContainerWidget *parent = 0);

  /*! \brief Set the text.
   */
  void setText(const WT_USTRING& value);

  /*! \brief Return the text.
   */
  const WT_USTRING& text() const;

  /*! \brief Set the default location and link text used when inserting a link.
   */
  void setLinkDefault(const WString& text, const WString& location);

  /*! \brief Enable or disable alignment buttons.
   */
  void setEnableAlignments(bool enable);

  /*! \brief Enable or disable changing of text color.
   */
  void setEnableColors(bool enable);

  /*! \brief Enable or disable changing of text font.
   */
  void setEnableFont(bool enable);

  /*! \brief Enable or disable changing of text formatting.
   */
  void setEnableFormat(bool enable);

  /*! \brief Enable or disable insertion of links.
   */
  void setEnableLinks(bool enable);

  /*! \brief Enable or disable insertion of lists.
   */
  void setEnableLists(bool enable);

  /*! \brief Enable or disable a view which shows the raw HTML source.
   */
  void setEnableSourceEdit(bool enable);

  virtual void resize(const WLength& width, const WLength& height);
  
  virtual WValidator::State validate();

protected:
  virtual void createConfig(std::ostream& config);
  virtual WFormWidget *formWidget() const;

private:
  WString linkDefaultText_;
  WString linkDefaultLocation_;
  bool alignments_, colors_, font_, format_, links_, lists_, sourceEdit_;

  WTextArea *textArea_;

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

  virtual void useAsTableViewEditor();
};

  }
}

#endif // EXT_HTMLEDITOR_H_
