// ------------------------------------------------------------------------------------ //
//																						//
//	File: Asura_GUIMenu_Widget_TextBox.h												//
//																						//
//	Description: ListBox widget class													//
//																						//
//	Created: Steve Keen - 9/11/06														//
//																						//
//	Copyright (C) 2006 Rebellion (Derby), All Rights Reserved.							//
// ------------------------------------------------------------------------------------ //

#ifndef __ASURA_GUIMENU_WIDGET_TEXTBOX_H__
#define __ASURA_GUIMENU_WIDGET_TEXTBOX_H__

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifdef ASURA_USE_GUI_MENU_SYSTEM
#include "Asura_GUIMenu_Widget_Base.h"

// -- Typedef -------------------------------------------------------------------------

// -- Enums ---------------------------------------------------------------------------

// -- Defines -------------------------------------------------------------------------
#define ASURA_GUIMENU_WIDGET_TEXTBOX_LOCAL_FLAG_START	16

// chunk versions:
// 0 - initial version
// 1 - MH added text entry data
// 2 - MH added console var
// 3 - MH added m_bIsPasswordField
// 4 - MH added m_bAllowBlankString
#define ASURA_CHUNK_WIDGET_TEXTBOX_VERSION 4

// -- Structures ----------------------------------------------------------------------

// -- Class ---------------------------------------------------------------------------

class Asura_GUIMenu_Element_Text;

class Asura_GUIMenu_Widget_TextBox : public Asura_GUIMenu_Widget_Base
{
	friend class Tools_GUIMenu_Widget_TextBox;

	// -- Functions -----------------------------------------------------------------------
public:
	enum Asura_GUIMenu_Inherit_Flag_Widget_TextBox_Type
	{
		ASURA_GUIMENU_WIDGET_TEXTBOX_LOCAL_FLAG_TEXTENTRY	= (1<<(ASURA_GUIMENU_WIDGET_TEXTBOX_LOCAL_FLAG_START+0)),
		ASURA_GUIMENU_WIDGET_TEXTBOX_LOCAL_FLAG_MAX  		= (1<<(ASURA_GUIMENU_WIDGET_TEXTBOX_LOCAL_FLAG_START+15))
	};

	Asura_GUIMenu_Widget_TextBox();
	virtual ~Asura_GUIMenu_Widget_TextBox();

	virtual void 				Update( float fElapsedTime);//, unsigned int uButtons, POINT ptMousePos);
	virtual void 				Render( u_int uState);
	virtual void				Copy( const Asura_GUIMenu_Root* pxSource);

	virtual u_int				ProcessInputActivity( const Asura_GUIMenu_Input& xInput);

	// -- UI Message handler functions --
	virtual bool				OnInit( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnDeInit( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnDataChange( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnDataRequest( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnClicked( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnRollIn( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnRollOut( const Asura_Message_GUIMenu_Notify* pxMessage);
	virtual bool				OnEnable( const Asura_Message_GUIMenu_Notify* pxMessage);

	virtual void				TextInputEnded();

	bool						SetActiveText( Asura_Hash_ID uHashTextElement);

	Asura_Hash_ID				GetActiveTextHashID( void) const;

//	virtual	void				UpdateInheritedValues( bool bOnInit = false);

	void						SetTextEntryMaxChars( u_int uMaxChars );	// not including null.
	u_int						GetTextEntryMaxChars() const { return m_uTextEntryMaxChars; }
	bool						IsTextEntryBox() const { return m_uTextEntryMaxChars != 0; }
	bool						IsPasswordField() const { return IsTextEntryBox() && m_bIsPasswordField; }

#ifdef ASURA_TOOLS
	virtual void				UpdateLocalDataFromStyle( void);
	virtual void				WriteToChunkStream( Asura_Chunk_Stream& xStream) const;
	virtual void				ExportToXML(Tools_GUIMenu_XMLExporter* pxExporter) const;
#endif

	virtual void				ReadFromChunkStream( Asura_Chunk_Stream& xStream, Asura_GUIMenu_Root* pxParentObject, u_int uChunkVersion);

	// accessors for chunk reading and tools code
	Asura_GUIMenu_ConsoleVar&	GetConsoleVar() { return m_xConsoleVar; }
	const Asura_GUIMenu_ConsoleVar&	GetConsoleVar() const { return m_xConsoleVar; }

	virtual bool				RemoveFromThisContainer( Asura_GUIMenu_Root* pxObject);


protected:
	void						SetupDefaultElements( void);
	void						BuildDisplayParams( void);

private:

	// -- Variables -----------------------------------------------------------------------
public:

protected:

private:
	float						m_fOffsetYLimit;

	Asura_GUIMenu_Element_Text* m_pxActiveTextElement;
	u_int						m_uActiveTextFlagBackup;

	// text entry buffer and settings
	Asura_UnicodeChar*			m_wszTextEntryString;
	u_int						m_uTextEntryMaxChars;
	bool						m_bIsPasswordField;
	bool						m_bAllowBlankString;

	// console var to set from text entry buffer
	Asura_GUIMenu_ConsoleVar	m_xConsoleVar;

	typedef Asura_GUIMenu_Widget_Base PARENT;
};
#endif // ASURA_USE_GUI_MENU_SYSTEM
#endif // __ASURA_GUIMENU_WIDGET_TEXTBOX_H__
