#pragma once
#include "skinnablewindow.h"
#include "listitem.h"
#include "inplaceedit.h"
#include "verticalscrollbar.h"
#include <list>

class SkinnableListBox :
	public SkinnableButton
{
public:
	SkinnableListBox(void);
	~SkinnableListBox(void);

	virtual int Create(HWND parent = 0);
	void AddItem(ListItem * item);
	ListItem * CreateItem(const TCHAR* text = NULL, int key = 0);
	int DeleteItem(ListItem *);
	ListItem * GetItemByKey(int key);
	ListItem * GetItemByName(const TCHAR * name);
	ListItem * GetItemByIndex(int i);
	void GetKeys(Vector<int>& keys);
	void DeleteAllItems();



	void SetSelection(int key);
	void SetSelection(const TCHAR * name);
	void SetSelection(ListItem * item);
	void ClearSelection();

	virtual void OnScroll(HWND h);
	virtual void OnButton(HWND h);
	virtual void OnRightButton(HWND h);
	virtual void OnDblButton(HWND h);
	virtual void OnPopupStart(WPARAM wParam, LPARAM lParam);
	virtual void OnPopupEnd(WPARAM wParam, LPARAM lParam);
	void OnListDeleteItem(WPARAM wParam, LPARAM lParam);

	// when empty
	void ShowEmptyItem(const TCHAR * text, Appearance& appearance);
	void HideEmptyItem();

	// the data entry item
	void ShowDataEntry(const TCHAR * text, Appearance& x);
	void HideDataEntry();

	// the list 
	std::list<ListItem*> items;
	ListItem * selectedItem; // the currently selected item, null if none selected

	VerticalScrollBar scrollbar;
	void ShowScrollBar();
	void HideScrollBar();

	SkinnableWindow itemwindow;
	InPlaceEdit inplace;

private:
	// optional behaviors
	int AllowInPlaceEdit;
	int ShowingDataEntry;
	int maxHeight;
	ListItem DataEntry;
	CRITICAL_SECTION cs;

	Appearance EmptyStyle;
	ListItem EmptyItem;
	int ShowingEmptyItem;

	void FitToContents();

};

typedef std::list<ListItem*>::iterator lipos;
