#ifndef _COMMON_CALENDARCONTROL_HPP_
#define _COMMON_CALENDARCONTROL_HPP_
#ifndef _COMMON_CONTROL_HPP_
#include <common/control.hpp>
#endif
#ifndef _COMMON_COMMCTRL_HPP_
#include <common/commctrl.hpp>
#endif
#ifndef _COMMON_RGBCOLOR_HPP_
#include <common/rgbcolor.hpp>
#endif
#ifndef _COMMON_SYSTEMTIME_HPP_
#include <common/systime.hpp>
#endif

class CalendarControl : public Control
{
public:
  enum CalendarStyles{DayState=MCS_DAYSTATE,MultiSelect=MCS_MULTISELECT,NoToday=MCS_NOTODAY,NoTodayCircle=MCS_NOTODAYCIRCLE,WeekNumbers=MCS_WEEKNUMBERS};
  enum ColorProp{BkGnd=MCSC_BACKGROUND,Text=MCSC_TEXT,BkTitle=MCSC_TITLEBK,FgTitle=MCSC_TITLETEXT,BkMonth=MCSC_MONTHBK,TrailText=MCSC_TRAILINGTEXT};
  CalendarControl(GUIWindow &parentWnd,HWND hControlWnd,UINT controlID);
  CalendarControl(GUIWindow &parentWnd,UINT controlID,const Rect &initRect=Rect(),DWORD style=WS_CLIPCHILDREN|WS_CLIPSIBLINGS|MCS_DAYSTATE,DWORD styleEx=0);
	virtual ~CalendarControl();
	bool getMinReqRect(Rect &minReqRect)const;
	bool setColor(ColorProp colorProp,const RGBColor &color);
  bool getDate(SystemTime &systemTime)const;
	bool setDate(const SystemTime &systemTime)const;
	bool setCurrent(const SystemTime &systemTime)const;
  bool getCurrent(SystemTime &systemTime)const;
  bool resize(void);
  void setSelChangeHandler(PureCallback *pSelChangeHandler);
	void setDayStateHandler(PureCallback *pDayStateHandler);
	void setSelectHandler(PureCallback *pSelectHandler);
protected:
 virtual bool handleSelChange(NMSELCHANGE &nmSelChange);
 virtual bool handleDayState(NMDAYSTATE &nmDayState);
 virtual bool handleSelect(NMSELCHANGE &nmSelChange);
private:
	CallbackData::ReturnType notifyHandler(CallbackData &someCallbackData);

	Callback<CalendarControl> mNotifyHandler;
  CallbackPointer mSelChangeHandler;
	CallbackPointer mDayStateHandler;
	CallbackPointer mSelectHandler;
  GUIWindow &mParentWnd;
};

inline
bool CalendarControl::getMinReqRect(Rect &minReqRect)const
{
  if(!isValid())return false;
	return sendMessage(MCM_GETMINREQRECT,0,(LPARAM)(LONG)&minReqRect.getRect());
}

inline
bool CalendarControl::setColor(ColorProp colorProp,const RGBColor &color)
{
  if(!isValid())return false;
	return sendMessage(MCM_SETCOLOR,colorProp,COLORREF(color));
}

inline
bool CalendarControl::getDate(SystemTime &systemTime)const
{
  if(!isValid())return false;
  return sendMessage(MCM_GETTODAY,0,(LPARAM)(LONG)&systemTime.getSYSTEMTIME());
}

inline
bool CalendarControl::setDate(const SystemTime &systemTime)const
{
  if(!isValid())return false;
  return sendMessage(MCM_SETTODAY,0,(LPARAM)(LONG)&((SystemTime&)systemTime).getSYSTEMTIME());
}

inline
bool CalendarControl::setCurrent(const SystemTime &systemTime)const
{
  if(!isValid())return false;
	return sendMessage(MCM_SETCURSEL,0,(LPARAM)(LONG)&((SystemTime&)systemTime).getSYSTEMTIME());
}

inline
bool CalendarControl::getCurrent(SystemTime &systemTime)const
{
  if(!isValid())return false;
	return sendMessage(MCM_GETCURSEL,0,(LPARAM)(LONG)&systemTime.getSYSTEMTIME());
}

inline
void CalendarControl::setSelChangeHandler(PureCallback *pSelChangeHandler)
{
  mSelChangeHandler=CallbackPointer(pSelChangeHandler);
}

inline
void CalendarControl::setDayStateHandler(PureCallback *pDayStateHandler)
{
  mDayStateHandler=CallbackPointer(pDayStateHandler);
}

inline
void CalendarControl::setSelectHandler(PureCallback *pSelectHandler)
{
  mSelectHandler=CallbackPointer(pSelectHandler);
}
#endif