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

#ifndef BtnPanelUnitH
#define BtnPanelUnitH
//---------------------------------------------------------------------------
#include <Vcl.AppEvnts.hpp>
//---------------------------------------------------------------------------
#include <vector>
using namespace std;
//---------------------------------------------------------------------------
#ifndef SAFE_DELETE(p)
#define SAFE_DELETE(p) { if(p) { delete (p);     (p)=NULL; } }
#endif
//---------------------------------------------------------------------------
typedef enum{

	Bs_NORMAL=0,
	Bs_ENTER,
	Bs_DOWN,
    Bs_DISABLE,
	Bs_NONE

}BtnState;

typedef enum{

	Ms_LDOWN=0,
	Ms_LUP,
	Ms_LLDOWN,
	Ms_RDOWN,
	Ms_RUP,
	Ms_ENTER,
	Ms_LEAVE,
	Ms_MOVE,
	Ms_DRAG,
	Ms_NONE
}MsState;
//---------------------------------------------------------------------------
class TBtnPanel;
typedef vector<TBtnPanel *> VCTBtnPanel;
extern VCTBtnPanel::iterator vc_pFindVCTBtnPanel;
//---------------------------------------------------------------------------
typedef void __fastcall (__closure *PanelMsEvent)(int MsTmp, int XPos, int YPos);
typedef void __fastcall (__closure *PanelDrEvent)(int BsTmp, TRect TRectTmp, TCanvas *pCanvas);
//---------------------------------------------------------------------------
class TBtnPanel: public TComponent
{

private:

	TApplicationEvents *m_pAppEvents;
	bool 			m_bPalEn, m_bPalLD, m_bPalRD;
	void __fastcall OnAppEvents(tagMSG &Msg, bool &Handled);

	TBtnPanel       *m_pParentBtn;
	VCTBtnPanel		m_VCSubtn;
	bool 			m_bBtnEn, m_bBtnLD, m_bBtnRD;
	int             m_BtnCurStateBac;

	bool __fastcall IsBtnHandleAppEvent(unsigned int message, int XPos, int YPos);
	bool __fastcall IsPtInSubtn(int XPos, int YPos);
	void __fastcall BtnHandleAppEvent(MsState MsSrcTmp, int XPos, int YPos);
	void __fastcall BtnHandleState();
	void __fastcall BtnMsEvent(MsState  MsTmp, int XPos, int YPos);
	void __fastcall BtnDrEvent(BtnState BsTmp, int XPos, int YPos);

	void __fastcall PaintParent(TCanvas *CanvasDrawCus);
	void __fastcall PaintSub(TCanvas *CanvasDraw);

	// -----
	int  		 FLeft, FTop, FWidth, FHeight;
	bool         FEnabled;
	bool 	     FDown;
	bool         FStateEnter;
	int  		 FStateCount;
	int     	 FBtnCurState;
	bool 		 FTransparent;
	BYTE 		 FTransparentValue;
	PanelMsEvent FPanelMsEvent;
	PanelDrEvent FPanelDrEvent;

public:

	TWinControl    *m_pTWnCtl;
	void __fastcall SetBounds(int nLeft, int nTop, int nWidth, int nHeight);
	void __fastcall AddSubPanel(TBtnPanel *pTBtnPanel);
	void __fastcall Update(bool bEreaseBkg=true);
	void __fastcall Paint(TCanvas *Canvas=NULL, bool bParent=true);

	__fastcall  TBtnPanel(TWinControl *pTWnCtl);
	__fastcall ~TBtnPanel();

__published:

	__property int  Left        = { read=FLeft,       write=FLeft,       default=0 };
	__property int  Top         = { read=FTop,        write=FTop,        default=0 };
	__property int  Width       = { read=FWidth,      write=FWidth,      default=0 };
	__property int  Height      = { read=FHeight,     write=FHeight,     default=0 };
	__property bool StateEnter  = { read=FStateEnter, write=FStateEnter, default=true };
	__property bool Enabled     = { read=FEnabled,    write=FEnabled,    default=true };
	__property bool Down        = { read=FDown,       write=FDown,       default=false };
	__property int  BtnCurState = { read=FBtnCurState,write=FBtnCurState,default=Bs_NORMAL};
	__property int  StateCount  = { read=FStateCount, write=FStateCount, default=3 };
	__property bool Transparent      = { read=FTransparent,      write=FTransparent,      default=false };
	__property BYTE TransparentValue = { read=FTransparentValue, write=FTransparentValue, default=255 };
	__property PanelMsEvent OnPanelMsEvent = { read=FPanelMsEvent , write=FPanelMsEvent };
	__property PanelDrEvent OnPanelDrEvent = { read=FPanelDrEvent , write=FPanelDrEvent };
};
//---------------------------------------------------------------------------
#endif

/******************************************
******************READ ME******************
*******************************************
@ 先触发鼠标事件，在触发绘制事件
@ 事件坐标体系是绝对坐标;
@ 绘制坐标体系是相对坐标;
@ 自身重绘，子view相应重绘；
@ 自身rect发生变化，父view相应重绘；
@ 只画png需要设置trans
@ StateCount-->BtnState;
@ Ms_LLDOWN-->event no paint;
*******************************************
*******************************************
*******************************************/

