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

#include <Wt/WLineEdit>
#include <Wt/WTime>
#include <Wt/WTimeValidator>
#include <Wt/WTimePicker>

namespace Wt {

/*! \class WTimeEdit Wt/WTimeEdit Wt/WTimeEdit
 *  \brief A Time field editor
 *
 *  \sa WTimePicker
 *  \sa WTime
 *  \sa WTimeValidator
 *
 * Styling through CSS is not applicable.
 */
class WT_API WTimeEdit : public WLineEdit
{
public:
    /*! \brief Creates a new time edit.
     */
    WTimeEdit(WContainerWidget *parent = 0);

    /*! \brief Sets the time
     *
     *  Does nothing if the current time is \p Null.
     *
     * \sa time()
     */
    void setTime(const WTime& time);

    /*! \brief Returns the time.
     *
     * Returns an invalid time (for which WTime::isValid() returns
     * \c false) if the time could not be parsed using the current
     * format().
     *
     * \sa setTime(), WTime::fromString(), WLineEdit::text()
     */
    WTime time() const;

    /*! \brief Returns the validator
     *
     * \sa WTimeValidator
     */
    virtual WTimeValidator *validator() const;

    /*! \brief Sets the format of the Time
     */
    void setFormat(const WT_USTRING& format);

    /*! \brief Returns the format.
     */
    WT_USTRING format() const;

    /*! \brief set the hidden status
     */
    virtual void setHidden(bool hidden, const WAnimation& animation = WAnimation());

    /*! \brief returns the minutes step
     */
    int minuteStep() const { return timePicker_->minuteStep(); }

    /*! \brief sets the minute step
     */
    void setMinuteStep(int step) { timePicker_->setMinuteStep(step); }

protected:
    /*!
     * \brief render the widget
     */
    virtual void render(WFlags<RenderFlag> flags);

    /*!
     * \brief enable or disable propagation
     */
    virtual void propagateSetEnabled(bool enabled);

    /*! \brief Sets the value from the time scroller to the line edit.
     */
    virtual void setFromTimePicker();

    /*! \brief Sets the value from the line edit to the time scroller.
     */
    virtual void setFromLineEdit();

    /*! \brief sets the text
     */
    virtual void setText(const WString &text) { WLineEdit::setText(text); }

private:
    WPopupWidget *popup_;
    WTimePicker *timePicker_;

    void defineJavaScript();
    void connectJavaScript(Wt::EventSignalBase& s, const std::string& methodName);

};

}

#endif // WTIME_EDIT_H_
