/*
* FX Editor List Box
* @version 8-28-06
* @author Joseph 'Pcjoe' Florencio
*/

#pragma warning (disable:4786)
#pragma warning (disable:4530)

#ifndef FXEDITORLISTBOX_H
#define FXEDITORLISTBOX_H
#include <VGUI_Panel.h>
#include <VGUI_TablePanel.h>
#include <VGUI_HeaderPanel.h>
#include <VGUI_TextGrid.h>
#include <VGUI_Label.h>
#include "vgui_fxeditormisc.h"
#include <string>
#include <map>
using namespace std;

/*
* List Box Input Signal
*/
class CListBoxItem;
class CListBoxMenu;
class CHandler_ListBox : public InputSignal
{
public:
	// Constructor
	CHandler_ListBox(CListBoxItem *pItem, CListBoxMenu *pMenu);

	// Mouse Release
	void mouseReleased(MouseCode code,Panel* panel);

	void cursorEntered(Panel *panel) { }
	void cursorExited(Panel* panel) { }
	void cursorMoved(int x,int y,Panel* panel) {};
	void mousePressed(MouseCode code,Panel* panel) {}
	void mouseDoublePressed(MouseCode code,Panel* panel) {};
	void mouseWheeled(int delta,Panel* panel) {};
	void keyPressed(KeyCode code,Panel* panel) {};
	void keyTyped(KeyCode code,Panel* panel) {};
	void keyReleased(KeyCode code,Panel* panel) {};
	void keyFocusTicked(Panel* panel) {};

private:
	CListBoxItem *m_pItem;
	CListBoxMenu *m_pMenu;
};


/*
* List Box Item
*/
class CListBoxItem
{
public:
	/*
	* Constructor
	*/
	CListBoxItem(const char *pText, int idx, int x, int y, int wide, int tall, BitmapTGA *pImageBg=NULL, BitmapTGA *pImageMo=NULL, BitmapTGA *pImageSel=NULL);

	// Set as Current
	void setAsCurrent( void );

	// Disable Current
	void disableCurrent( void );

	/*
	* Accessors/Mutators
	*/
	void setButton( CFadeImageButton *pBtn ) { m_pButton = pBtn; }
	CFadeImageButton *getButton( void ) { return m_pButton; }

	void setImageBg( BitmapTGA *pImg ) { m_pImageBg = pImg; }
	BitmapTGA *getImageBg( void ) { return m_pImageBg; }
	
	void setImageMouseOver( BitmapTGA *pImg ) { m_pImageMouseOver = pImg; }
	BitmapTGA *getImageMouseOver( void ) { return m_pImageMouseOver; }
	
	void setImageSelect( BitmapTGA *pImg ) { m_pImageSelect = pImg; }
	BitmapTGA *getImageSelect( void ) { return m_pImageSelect; }

	void setText( string strText ) { m_strText = strText; }
	string getText( void ) { return m_strText; }

	void setCurrent( bool bCurrent ) { m_bCurrent = bCurrent; }
	bool getCurrent( void ) { return m_bCurrent; }

	void setIndex( int idx ) { m_iIdx = idx; }
	int getIndex( void ) { return m_iIdx; }

private:
	CFadeImageButton *m_pButton;
	BitmapTGA *m_pImageBg;
	BitmapTGA *m_pImageMouseOver;
	BitmapTGA *m_pImageSelect;
	string m_strText;
	bool m_bCurrent;
	int m_iIdx;
};

/*
* List Box Menu
*/
class CListBoxMenu : public CTFScrollPanel
{
public:
	/*
	* Constructor
	*/
	CListBoxMenu(int x, int y, int wide, int tall, const char *imgbg, const char *imgmo, const char *imgsel);

	/*
	* Destructor
	*/
	~CListBoxMenu();

	// Get next avail index
	int getNextIndex( void );

	// Add item - leave index as 0 for auto indexing
	CListBoxItem *addItem( const char *text, int idx=0 );

	// Set Selected
	void setSelected( int idx );
	void setSelected( string strItem );
	void setSelected( CListBoxItem *pItem );

	// Disable all select
	void disableAllSelect( void );

	// Select Callback (called whenever an item is clicked on
	virtual void selectCallback( CListBoxItem *pItem ) {}

	// Remove All
	void removeAll( void );

	/*
	* Accessors/Mutators
	*/
	void setImageBg( BitmapTGA *pImg ) { m_pImageBg = pImg; }
	BitmapTGA *getImageBg( void ) { return m_pImageBg; }

	void setImageMouseOver( BitmapTGA *pImg ) { m_pImageMouseOver = pImg; }
	BitmapTGA *getImageMouseOver( void ) { return m_pImageMouseOver; }

	void setImageSelect( BitmapTGA *pImg ) { m_pImageSelect = pImg; }
	BitmapTGA *getImageSelect( void ) { return m_pImageSelect; }

protected:
	vector<CListBoxItem*> m_Items;
	BitmapTGA *m_pImageBg;
	BitmapTGA *m_pImageMouseOver;
	BitmapTGA *m_pImageSelect;
};

/*
* Drop Down Menu Input Signal
*/
class CListBoxDropDownMenu;
class CHandler_DropDown : public InputSignal
{
public:
	// Constructor
	CHandler_DropDown(CListBoxDropDownMenu *pMenu);

	// Mouse Release
	void mouseReleased(MouseCode code,Panel* panel);

	void cursorEntered(Panel *panel) { }
	void cursorExited(Panel* panel) { }
	void cursorMoved(int x,int y,Panel* panel) {};
	void mousePressed(MouseCode code,Panel* panel) {}
	void mouseDoublePressed(MouseCode code,Panel* panel) {};
	void mouseWheeled(int delta,Panel* panel) {};
	void keyPressed(KeyCode code,Panel* panel) {};
	void keyTyped(KeyCode code,Panel* panel) {};
	void keyReleased(KeyCode code,Panel* panel) {};
	void keyFocusTicked(Panel* panel) {};

private:
	CListBoxDropDownMenu *m_pMenu;
};


/*
* List Box Drop Down (used with drop down menu)
*/
class CDropDownMenu;
class CListBoxDropDownMenu : public CListBoxMenu
{
public:
	/*
	* Constructor
	*/
	CListBoxDropDownMenu(int x, int y, int wide, int tall, const char *imgbg, const char *imgmo, const char *imgsel);

	// Select Callback (called whenever an item is clicked on)
	virtual void selectCallback( CListBoxItem *pItem );

	// Show panel
	void showPanel( void );

	// Hide panel
	void hidePanel( void );

	// Reposition Panel
	void repositionPanel( void );

	/*
	* Accessors/Mutators
	*/
	void setDropDownMenu( CDropDownMenu *pMenu ) { m_pDropMenu = pMenu; }
	CDropDownMenu *getDropDownMenu( void ) { return m_pDropMenu; }
private:
	CDropDownMenu *m_pDropMenu;
};

/*
* Drop Down Menu
*/
class CDropDownMenu : public CTransparentPanel
{
public:
	/*
	* Constructor
	*/
	CDropDownMenu(int x, int y, int wide, int tall);

	// Update text
	void updateText( string text );


	/*
	* Accessors/Mutators
	*/
	void setMenu( CListBoxDropDownMenu *pMenu ) { m_pMenu = pMenu; }
	CListBoxDropDownMenu *getMenu( void ) { return m_pMenu; }

	void setTextButton( CFadeImageButton *pBtn ) { m_pText = pBtn; }
	CFadeImageButton *getTextButton( void ) { return m_pText; }

	void setDownButton( CFadeImageButton *pBtn ) { m_pDownBtn = pBtn; }
	CFadeImageButton *getDownButton( void ) { return m_pDownBtn; }

protected:
	// Hacked paint to act as think to update m_pMenu position
	virtual void paint();

private:
	CListBoxDropDownMenu *m_pMenu;
	CFadeImageButton *m_pText;
	CFadeImageButton *m_pDownBtn;
};

/*
* File Browser
*/
class CFileListBoxMenu : public CListBoxMenu
{
public:
	/*
	* Constructor
	*/
	CFileListBoxMenu(int x, int y, int wide, int tall, const char *dir, const char *imgbg, const char *imgmo, const char *imgsel);

	// Add file type
	void addFileType( string strType );

	// Select Callback (called whenever an item is clicked on)
	virtual void selectCallback( CListBoxItem *pItem );

	// Clear items and add file list
	void buildFileList( void );

	/*
	* Accessors/Mutators
	*/
	void setBaseDir( string strDir ) { m_strBaseDir = strDir; }
	string getBaseDir( void ) { return m_strBaseDir; }

protected:
	string m_strBaseDir;
	vector<string> m_fileTypes;
};

#endif