// 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_CALENDAR_H_
#define EXT_CALENDAR_H_

#include <Wt/WJavaScript>
#include <Wt/WDate>
#include <Wt/Ext/Component>

namespace Wt {

  namespace Ext {

/*! \class Calendar Wt/Ext/Calendar Wt/Ext/Calendar
 *  \brief A calendar.
 *
 * The calendar provides navigation by month and year, and indicates the
 * current day.
 *
 * The calendar only allows selection of a single day, and you may
 * listen for when the user selects a new date using the selected()
 * signal.
 *
 * The API is a subset of the WCalendar API:
 * <ul>
 *   <li>limited to single selection mode: no 
 *     \link WCalendar::setMultipleSelection(bool) setMultipleSelection(bool)\endlink,
 *     \link WCalendar::select(const std::set<WDate>&) select(const std::set<WDate>&)\endlink methods;</li>
 *   <li>no support for programmatory navigation: no
 *      \link WCalendar::browseToNextMonth() browseToNextMonth() \endlink,
 *      \link WCalendar::browseTo() browseTo()\endlink, etc... methods
 *   </li>
 *   <li>no support for getting information on what is currently displayed: no
 *      \link WCalendar::currentMonth() currentMonth()\endlink and
 *      \link WCalendar::currentYear() currentYear()\endlink methods.
 * </ul>
 *
 * Here is a snapshot taken on 01/09/2007 (shown as today), and 12/09/2007
 * currently selected.
 * \image html ExtCalendar-1.png "Calendar"
 *
 * \ingroup ext
 */
class WT_EXT_API Calendar : public Component
{
public:
  /*! \brief Create a new calendar.
   *
   * Constructs a new calendar, with optional support for internationalization.
   * The calendar shows the current day, and has an empty selection.
   */
  Calendar(bool i18n = false, WContainerWidget *parent = 0);

  /*! \brief Select a date.
   *
   * Select one date.
   */
  void select(const WDate& date);

   /*! \brief Get the current selection.
   *
   * Returns the set of dates currently selected. This set contains 0
   * or 1 dates.
   */ 
  const std::set<WDate>& selection() const { return selection_; }

  /*! \brief %Signal emitted when the user changes the selection.
   *
   * Emitted after the user has changed the current selection, before
   * the selected() signal is emitted.
   */
  Signal<void>& selectionChanged() { return selectionChanged_; }

  /*! \brief %Signal emitted when the user has selected a date.
   *
   * This signal indicates that the user has selected a new date,
   * which is only available when in single selection mode.
   */
  Signal<void>& selected() { return selected_; }

protected:
  virtual void updateExt();
  virtual void createConfig(std::ostream& config);

private:
  Signal<void>    selectionChanged_, selected_;
  std::set<WDate> selection_;

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

  JSignal<std::string> extDateSelected_;
  void onSelect(std::string date);
};

  }
}

#endif // EXT_CALENDAR_H_
