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

#include <WCompositeWidget>

namespace Wt {

class WText;
class WLineEdit;
class WPushButton;

/*! \class WInPlaceEdit WInPlaceEdit WInPlaceEdit
 *  \brief %WInPlaceEdit provides an in-place-editable text.
 *
 * The %WInPlaceEdit provides a text that may be edited by the user.
 * On activation, the text turns into a line edit with a save and cancel
 * button.
 *
 * When the user saves the edit, the \link WInPlaceEdit::valueChanged
 * valueChanged \endlink signal is emitted.
 */
class WT_API WInPlaceEdit : public WCompositeWidget
{
public:
  /*! \brief Create an in-place edit with the given text.
   */
  WInPlaceEdit(const WString& text, WContainerWidget *parent = 0);

  /*! \brief The current saved text value.
   */
  const WString& text() const;

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

  /*! \brief Access the line edit.
   */
  WLineEdit *lineEdit() const { return edit_; }

  /*! \brief Access the save button.
   */
  WPushButton *saveButton() const { return save_; }

  /*! \brief Access the save button.
   */
  WPushButton *cancelButton() const { return cancel_; }

public:
  /*! \brief Signal emitted when the value has been changed.
   */
  Signal<WString> valueChanged;

private slots:
  void save();

private:
  WContainerWidget *impl_;
  WText            *text_;
  WLineEdit        *edit_;
  WPushButton      *save_;
  WPushButton      *cancel_;
};

}

#endif // WINPLACE_EDIT_H_
