/////////////////////////////////////////////////////////////////////////////
// Name:        datectrl.h
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     04/01/98
// RCS-ID:      $Id: datectrl.h,v 1.2 2001/04/04 20:38:50 georgetasker Exp $
// Copyright:   (c) 2000 PM-Soft
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef __DATECTRL_G__
#define __DATECTRL_G__

#include "wx/panel.h"
#include "wx/dynarray.h"
#include "wx/list.h"
#include "wx/datetime.h"

class SelectorItemInfo
{
public:
	SelectorItemInfo();

	int mType; // wxDateCtrl::SEL_TYPES_ENUM
	int mFrom, mTill;
	bool mPadZeros;
	char mTagChar;
	wxString mDefault; // or label if type == ST_LABEL
	wxStringList mStrings;
	wxWindow* mpCtrl;
	wxSize mSize;
};

WX_DEFINE_ARRAY( SelectorItemInfo*, SelectorItemInfoListT );

class wxSelectorKeySpy;

class wxDateCtrl : public wxWindow
{
public:
	wxDateCtrl();

	wxDateCtrl( wxWindow* parent, wxWindowID id, 
				const wxPoint& pos = wxDefaultPosition, 
				const wxSize& size = wxDefaultSize, 
				const wxString& format = "%c",
				long style = 0, const wxString& name = "dateCtrl");

	~wxDateCtrl();

	void Create( wxWindow* parent, wxWindowID id, 
				 const wxPoint& pos = wxDefaultPosition, 
				 const wxSize& size = wxDefaultSize, 
				 const wxString& format = "%c",
				 long style = 0, const wxString& name = "dateCtrl" );

	void SetDefaults();

	virtual void AddNumberRangeItem( int from, int till, 
									 const wxString& defaultValue = "0", 
									 char tagChar = 'Z', bool padZeros = TRUE );

	virtual void AddSeparatorLabel( const wxString& label );
	virtual void AddStringListItem( wxStringList& values, 
									const wxString& defaultValue = "",
									char tagChar = 'Z' );

	virtual SelectorItemInfo* FindInfoForWindow( wxWindow* pWnd );

	// removes all format-infos along with controls (if any)
	virtual void Clear();
	virtual SelectorItemInfoListT& GetItems();

	virtual void SetItemGap( int pixels );
	virtual int  GetItemGap();

	virtual void LayoutControls();

	// event handlers

	void OnSize( wxSizeEvent& event );
	void OnSetFocus( wxFocusEvent& event );

	// overriden methods of wxWindowBase

	virtual wxSize DoGetBestSize() const;
	virtual bool Enable(bool enable);
	virtual void SetBgRecursive( wxWindow* pWnd, const wxColour& col );

	// date-related methods

	virtual bool SetFormat( const wxString& fmt );
	virtual bool SetValue( const wxDateTime& dt );
	virtual bool GetValue( wxDateTime& toDt, const wxDateTime& dateDef = wxDefaultDateTime );
	virtual const wxString& GetFormat();

	enum SEL_TYPES_ENUM
	{
		ST_NUMBER_RANGE,
		ST_STRING_LIST,
		ST_LABEL
	};

	DECLARE_DYNAMIC_CLASS( wxDateCtrl )
	DECLARE_EVENT_TABLE()

protected:

	friend class wxSelectorKeySpy;

	virtual void CreateControls();
	virtual void GetTextSize( const wxString& text, wxSize& sz );

	virtual wxStringList& GetMonthNames();
	virtual wxStringList& GetWeekDeyNames();
	virtual wxStringList& GetMonthNamesAbr();
	virtual wxStringList& GetWeekDeyNamesAbr();
	virtual wxStringList& GetAMPMNames();

	virtual int GetYear();
	virtual int GetMonth();
	virtual SelectorItemInfo* FindItemByTagChar( char ch );
	virtual void FixUpDayFieldsByMonth( int month = -1 );
	wxString GetDisplayStringForNumber( int n, SelectorItemInfo* pItem );

protected:
	SelectorItemInfoListT mItems;
	wxSelectorKeySpy*     mpSpy;
	int					  mItemGap; // default: 0 pixels
	wxString			  mFormat;
	bool				  mDefaultSizeUsed;
	bool				  mIsDateEntry;
};

class wxSelectorKeySpy : public wxEvtHandler
{
public:
	wxSelectorKeySpy( wxDateCtrl* pSelector );

	void OnKeyDown( wxKeyEvent& event );
	void OnKillFocus( wxFocusEvent& event );
	void OnSetFocus( wxFocusEvent& event );

	void SpotSpying();

	DECLARE_EVENT_TABLE()

protected:
	wxDateCtrl* mpSelector;
};

#endif // __DATECTRL_G__
