// AsOptionGroup.h: interface for the CAsOptionGroup class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(_ASOPTIONGROUP_H_)
#define _ASOPTIONGROUP_H_

#include <map>
#include "AsOptionRow.h"
#include "AsBaseCell.h"
#include "AsFontInfo.h"
#include "IAsOptionRowListener.h"
#include "AsCellEnum.h"
#include "cmString.h"

using namespace std;

typedef map<cmString, CAsOptionRow*> AsOptionRowMap;

class IAsOptionGroupListener;

class CAsOptionGroup : public IAsOptionRowListener
{
public:
	CAsOptionGroup();
	virtual ~CAsOptionGroup();

	enum enAsOptionGroupHitTest {
		enAsOptionGroupHitTest_None = 0,
		enAsOptionGroupHitTest_Expand,
		enAsOptionGroupHitTest_Splitter,
		enAsOptionGroupHitTest_Header,
		enAsOptionGroupHitTest_Rows
	};

	// implementation of IAsOptionRowListener
	//
	void OnRowSelection(CAsOptionRow* selectedRow, bool redraw = true);

	void Draw(CDC* pDC);

	void SetCaption(const cmString& caption);
	cmString GetCaption() const;

	void SetDescription(const cmString& description);
	cmString GetDescription() const;

	AsOptionRowMap* GetRows();

	CAsOptionRow* AddRow(const cmString& name, const cmString& caption, enCellType valueCellType);
	CAsOptionRow* GetRow(const cmString& name);

	void SetDrawArea(const CRect& drawArea);
	CRect GetDrawArea() const;

	void SetTitleRowHeight(int height);
	int GetTitleRowHeight() const;

	void SetPropertyRowsHeight(int height);
	int GetPropertyRowsHeight() const;

	void SetVerticalStripWidth(int width);
	int GetVerticalStripWidth() const;

	void SetBorderColor(COLORREF borderColor);
	COLORREF GetBorderColor() const;

	void SetTitleRowBkColor(COLORREF bkColor);
	COLORREF GetTitleRowBkColor() const;

	void SetPropertyRowsBkColor(COLORREF bkColor);
	COLORREF GetPropertyRowsBkColor() const;

	void SetVerticalSplitterPos(int pos);
	int GetVerticalSplitterPos() const;

	enAsOptionGroupHitTest HitTest(const CPoint& pt);

	void RegisterListener(IAsOptionGroupListener* listener);

	void SetParentWindow(CWnd* parentWnd);

	bool ProcessMessage(DWORD msg, DWORD lParam, DWORD wParam, const CPoint& pt, const CRect& parentRect, bool& needRedraw);

	void SetFontInfo(const cmString& fontName, int fontSize = 10, bool fontBold = false);
	void SetFontInfo(const CAsFontInfo& fontInfo);

	// row selection management
	//
	CAsBaseCell* MoveSelection(	bool moveUp, 
								bool keepTopSelection, 
								bool keepBottomSelection,
								bool& selectionLost,
								bool redraw = true);
	void SelectBottomRow(bool redraw = true);
	void SelectHeader(bool select, bool redraw = true);
	void ClearSelection(bool redraw = true);
	CAsBaseCell* GetHeaderCell();

	CAsBaseCell* GetFocusedCell();

	bool IsSelected();

	void GetSelectionInfo(cmString& caption, cmString& description);
	CAsOptionRow* GetSelectedRow();

	void SetHeaderFontInfo(const CAsFontInfo& fontInfo);
	void SetHeaderFontInfo(const cmString& fontName, int fontSize, bool fontBold);

	void SetSorted(bool sorted);
	bool GetSorted() const;

protected:

	void OnExpandButtonPressed(bool redraw = true);


	CAsBaseCell header_;
	
	AsOptionRowMap rows_;

	CRect drawArea_;
	CRect expandRect_;

	int titleRowHeight_;
	int propertyRowsHeight_;
	int verticalStripWidth_;
	int verticalSplitterPos_;

	cmString caption_;
	cmString description_;

	COLORREF borderColor_;
	COLORREF titleRowBkColor_;
	COLORREF propertyRowsBkColor_;
	COLORREF verticalStripBkColor_;

	bool expanded_;

	IAsOptionGroupListener* listener_;
	CWnd* parentWnd_;

	CAsFontInfo fontInfo_;

	bool headerIsSelected_;

	bool sorted_;
};

#endif // !defined(_ASOPTIONGROUP_H_)
