//---------------------------------------------------------------------------

#ifndef ProgHandlePanelH
#define ProgHandlePanelH

#include <vcl.h>
#include "SkinScrollBarUnit.h"
#include "PNGButton.hpp"
/*---------------------------------------------------------------------------
	TProgHandleItem
---------------------------------------------------------------------------*/
class TProgHandleItem;
class TProgHandlePanel;
/*---------------------------------------------------------------------------
	TProgHandleItem
---------------------------------------------------------------------------*/
class TProgHandleItem : public TObject
{
private:
	/***********************************************************************/
	TProgHandleItem *FParent;
	TProgHandlePanel *FOwnerPanel;
	String FCaption;
	bool FIsUnfold;
	bool FIsSelected;
	bool FIsFocus;
	bool FIsHidden;
	bool FIsChecked;
	/***********************************************************************/

	/***********************************************************************/
	int mLevel;
	TRect mRect;
	TRect mValidRect;
	TRect mIconRect;
	TRect mCaptionRect;
	TList *mChildItem;
	TCanvas *mCanvas;
	TPNGButton *mHeaderIconButton;
	TPNGButton *mCheckBox;
	/***********************************************************************/

	void __fastcall DoHeaderClick(TObject *Sender);
	void __fastcall DoCheckClick(TObject *Sender);

	void __fastcall SetCaption(String Value);
	void __fastcall SetUnfold(bool Value);
	void __fastcall SetSelected(bool Value);
	void __fastcall SetHidden(bool Value);
	void __fastcall SetChecked(bool Value);

	int __fastcall GetChildCount();

protected:
	void __fastcall AfterConstruction();

public:
	void *Data;
	__fastcall TProgHandleItem(TProgHandlePanel *OwnerPanel, String Caption);
	__fastcall TProgHandleItem(TProgHandleItem *Parent, String Caption);
	__fastcall ~TProgHandleItem();

	/***********************************************************************/
	void __fastcall DrawItem(TCanvas *Canvas, TRect Rect);
	void __fastcall RedrawItem();
	void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall MouseMove(TShiftState Shift, int X, int Y);
	void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);
	/***********************************************************************/

	/***********************************************************************/
	TProgHandlePanel *GetOwnerPanel();
	void AddChild(TProgHandleItem *Child);
	TProgHandleItem *Child(int Index);
	/***********************************************************************/

__published:
	__property TProgHandleItem *Parent = {read = FParent};
	__property String Caption = {read = FCaption, write = SetCaption};
	__property int ChildCount = {read = GetChildCount};
	__property bool IsUnfold = {read = FIsUnfold, write = SetUnfold};
	__property bool IsSelected = {read = FIsSelected, write = SetSelected};
	__property bool IsHidden = {read = FIsHidden, write = SetHidden};
	__property bool IsChecked = {read = FIsChecked, write = SetChecked};
};
/*---------------------------------------------------------------------------
	TProgHandlePanel
---------------------------------------------------------------------------*/
class TProgHandlePanel : public TPanel
{
private:
	/***********************************************************************/
	int FItemWidth;
	int FItemHeight;
	TNotifyEvent FOnSelectedItem;
	/***********************************************************************/

	/***********************************************************************/
	TList *mTopLevelItemList;
	TList *mItemRectList;
	TList *mItemList;
	int mBeginIndex;
	int mEndIndex;
	int mCurrentItemIndex;
	int mShowCount;
	int mRealShowCount;
	TSkinScrollBar *mScrollBar;

	TProgHandleItem *mCurrentItem;
	/***********************************************************************/

	/***********************************************************************/
	void __fastcall RecalcItemsRect();
	void __fastcall Reset();
	void __fastcall LoadItem(TProgHandleItem* Item);
	TProgHandleItem *GetItem(int Index);
	int __fastcall GetTopLevelItemCount();
	/***********************************************************************/

	/***********************************************************************/
	MESSAGE void __fastcall WMSize(TWMSize &Message);
	MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
	MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
	MESSAGE void __fastcall CMMouseLeave(TMessage &Message);
	MESSAGE void __fastcall WMVScroll(TWMScroll &Message);

	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
		MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
		MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
		MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
		MESSAGE_HANDLER(WM_VSCROLL, TWMScroll, WMVScroll)
	END_MESSAGE_MAP(TPanel)
	/***********************************************************************/

protected:
	void __fastcall AfterConstruction();

	virtual void __fastcall CreateWnd();
	virtual void __fastcall Paint();

	DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
	DYNAMIC void __fastcall MouseMove(TShiftState Shift, int X, int Y);
	DYNAMIC void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);

public:
	__fastcall TProgHandlePanel(TComponent *Owner);
	__fastcall ~TProgHandlePanel();

	void __fastcall DoItemChange(TObject *Sender);
	void __fastcall DoSelectedItem(TObject *Sender);
	void __fastcall DoCurrentItem(TObject *Sender);

	void __fastcall AddTopLevelItem(TProgHandleItem* Item);
	void __fastcall ScrollPos(int Pos);
	void __fastcall SetTextFont(String name, int size);

	TProgHandleItem *GetTopLevelItem(int Index);

__published:
	__property TNotifyEvent OnSelectedItem = {read = FOnSelectedItem, write = FOnSelectedItem};
	__property int TopLevelItemCount = {read = GetTopLevelItemCount};
};
//---------------------------------------------------------------------------
#endif
