//---------------------------------------------------------------------------
#ifndef PanelDBH
#define PanelDBH
//---------------------------------------------------------------------------
#include "StateBtn.h"
//---------------------------------------------------------------------------
//double buffer panel
typedef void __fastcall (__closure *NotifyPaint)(TPanelDB *Sender, TCanvas *pCanvas, TRect rtBKG);
class TPanelDB : public Extctrls::TPanel
{
private:

	bool    m_bDBCreated;
	HDC     m_BufDC;
	HBITMAP m_BufBitmap;

protected:

	TStateBtn *m_BtnSel, *m_BtnFocus;  //may be parent, may be sub
	bool m_bLeft;

	bool      m_bBkgDrawed;
	NotifyPaint FOnDrawBKG, FOnPaintBKG;

	void __fastcall DCInit();
	void __fastcall DCRelease();

	BTNLST     m_LstBtn;
	TStateBtn*   __fastcall GetBtnCur(TPoint pt);

	virtual void __fastcall BtnDown(TStateBtn *pCur, TPoint pt, bool bLeft=true) {}
	virtual void __fastcall BtnUp(TStateBtn *pCur, TStateBtn *pSel, TPoint pt, bool bLeft=true) {}
	virtual void __fastcall BtnMove(TStateBtn *pCur, TPoint pt) {}
	virtual void __fastcall BtnLeave() {}

	virtual void __fastcall DoPaintBKG(TCanvas *pCanvas);
	virtual void __fastcall DoPaintLst(TCanvas *pCanvas);

	virtual void __fastcall Paint(void);
	virtual void __fastcall CreateWnd(void);
	virtual void __fastcall CreateParams(Controls::TCreateParams &Params);

	DYNAMIC void __fastcall Click(void);
	DYNAMIC void __fastcall DblClick(void);
	DYNAMIC void __fastcall MouseDown(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
	DYNAMIC void __fastcall MouseMove(System::Classes::TShiftState Shift, int X, int Y);
	DYNAMIC void __fastcall MouseUp(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
	MESSAGE void __fastcall CMMouseLeave(TMessage &Message);

	MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
	MESSAGE void __fastcall WMSize(Winapi::Messages::TWMSize &Message);
	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
		MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
		MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
	END_MESSAGE_MAP( Vcl::Extctrls::TPanel )

public:

	TCanvas  *m_CanvasDr;  //use for double buffer canvas
	TBitmap  *m_BMPBkg;    //backgroud save
	TRect     m_RtContent; //content rect

	void __fastcall BtnAdd(TStateBtn *pBtn);
	void __fastcall BtnClear();

	__fastcall TPanelDB(System::Classes::TComponent* AOwner);
	__fastcall ~TPanelDB();

__published:

	__property NotifyPaint    OnDrawBKG    = { read=FOnDrawBKG, write=FOnDrawBKG };
	__property NotifyPaint    OnPaintBKG   = { read=FOnPaintBKG,   write=FOnPaintBKG };
};
//---------------------------------------------------------------------------
#endif
