#ifndef __NT_WIDGET_H__
#define __NT_WIDGET_H__

#include <vector>
#include <queue>

#include "NTCurses.h"
#include "NTEvent.h"

namespace NTCurses {



class NTWidget {
public:
	NTWidget();
	NTWidget( NT::NTString id );
	NTWidget( NT::NTString id , NTWidget *parent );
	NTWidget( NTWidget *parent );
	virtual ~NTWidget();
	virtual void Create( void ); /* create curses object */
	virtual bool IsCreated( void );	/* is curses object created */
	virtual void Destroy( void ); /* destroy curses object */
	virtual void Init( void );	/* init the object */
	virtual void InitChildWidgets( void );	/* init the child widgets */
	virtual void Deinit( void );	/* deinit */
	virtual void DeinitChildWidgets( void );	/* deinit the child widgets */
	virtual void Draw( void );	/* draw the object */
	virtual void DrawChildWidgets( void ); /* call child draws */

	virtual void HandleKeyEvent( int keycode );	/* key event */
	virtual void HandleMouseEvent( int mx , int my , int mz , unsigned int bstate );
	virtual void HandleGotFocusEvent( void );	/* onfocus event */
	virtual void HandleLostFocusEvent( void );	/* lost focus event */
	virtual bool BeforeLostFocus( void );	/* before lost focus */

	virtual void HandleEvent( NTEvent evt );
	virtual void HandleEvents( void );
	virtual void HandleChildEvents( void );
	virtual void EventLoop( void );
	
	virtual void SetStringValue( NT::NTString val );	/* abstract function */
	virtual NT::NTString GetStringValue( void );		/* abstract function */
	virtual void SetStringParams( NT::NTString val );	/* abstract function */
	virtual NT::NTString GetStringParams( void );		/* abstract function */

	// child stuff
	void AddChildWidget( NTWidget *child );
	void DelChildWidget( unsigned int numofwidget );
	void DelChildWidget( NTWidget *child );
	unsigned int GetNumberOfChildWidgets( void );
	NTWidget *GetParentWidget( void );
	int GetActiveChildWidgetNumber( void );
	int GetChildWidgetNumber( NTWidget *child );
	NTWidget *GetChildWidgetFromNumber( int widgetnum );
	int GetNextEnabledChildWidgetNumber( int widgetnum );
	int GetPrevEnabledChildWidgetNumber( int widgetnum );

	virtual unsigned int GetRelativeX();
	virtual unsigned int GetRelativeY();

	// event stuff
	void PushEvent( NTEvent evt );
	void PushActiveChildEvent( NTEvent evt );
	bool HasEvent( void );
	NTEvent PopEvent( void );

	NTCurses *GetCurses( void );
	virtual void SetDirty( bool val );
	virtual bool GetDirty( void );
	virtual void SetAllChildDirty( void );
	void SetValid( bool val );
	bool GetValid( void );
	virtual void SetActive( bool val );
	virtual bool GetActive( void );
	void SetLostFocusSubmit( bool val );
	bool GetLostFocusSubmit( void );

	void SetActiveChildFromNumber( unsigned int num );
	void SetActiveChild( NTWidget *child );
	NTWidget *GetActiveChild( void );

	virtual void SetEnabled( bool val );
	virtual bool GetEnabled( void );
	virtual void SetX( unsigned int val );
	virtual unsigned int GetX( void );
	virtual void SetY( unsigned int val );
	virtual unsigned int GetY( void );
	virtual void SetPos( unsigned int x , unsigned int y );
	virtual void SetWidth( unsigned int val );
	virtual unsigned int GetWidth( void );
	virtual void SetHeight( unsigned int val );
	virtual unsigned int GetHeight( void );

	virtual void SetSize( unsigned int w , unsigned int h );
	NTCurses *oCurses;

	// debug stuff
	void SetDebug( bool val );
	void SetId( NT::NTString val );

protected:
	// protected methods
	NT::NTString sId;
	virtual void InitWidget( void );

	// protected properties
	NTWidget *oParent;
	std::vector<NTWidget *> oChilds;
	std::queue<NTEvent> oEvents;

	bool bDirty;
	bool bValid;
	bool bActive;
	bool bEnabled;
	bool bLostFocusSubmit;
	
	unsigned int uX;
	unsigned int uY;
	unsigned int uWidth;
	unsigned int uHeight;
	
	// debug stuff
	bool bDebug;
};

}


#endif
