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

#ifndef TableViewUnitH
#define TableViewUnitH
//---------------------------------------------------------------------------
#include "ScrollViewUnit.h"
#include "StateBtn.h"

/*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
*   *   *   *   *   *   *   *   TTableView  *   *   *   *   *
*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   */

#define NOSET -1

class TTableView;
typedef int __fastcall(__closure *TNotiTable)(TTableView *Sender);
typedef int __fastcall(__closure *TNotiT2C)(TTableView *Sender, int iCellIndex);
typedef int __fastcall(__closure *TNotiCell)(TStateBtn *Sender);
typedef int __fastcall(__closure *TNotiCellPt)(TStateBtn *Sender, TPoint pt);
typedef int __fastcall(__closure *TNotiC2C)(TStateBtn *Src, TStateBtn *Des, TPoint pt);
typedef int __fastcall(__closure *TNotiIconsNum)(TStateBtn *parent);
typedef int __fastcall(__closure *TNotiIconsBounds)(TStateBtn *sender, TRect &rtBounds);

typedef vector<int> VCINT;
typedef enum{
	CELLS_Default=0,
	CELLS_Up,
	CELLS_Down,
	CELLS_Page
}CELLS;

typedef enum{
	SBS_NONE=10,
	SBS_POS,
	SBS_TOP,
	SBS_BOTTOM
}SBS;

class TUIDelegate;
class TMDDelegate;

class TTableView: public TScrollView
{

private:

	TNotifyEvent FOnChange;

	int FIndSel, FIndFocus, FCount,
		FHgtSmall;

	bool m_bTop, m_bBom;

	int  m_PosTotal, m_PosPage, m_PosBegin;

	int  m_DBNum, m_DBNeed,
		 m_IndTop, m_IndBeg,
		 m_UIOff, m_UIOffMerge,
		 m_HgtSmall, m_HgtTop, m_HgtOver;

	VCINT m_VCHGT, m_VCPOS, m_VCCHG;

	TPanelDB *m_Title;
	TPanelDB *m_Bottom;
	int __fastcall getContentHeight();

	bool __fastcall DoTableInit();
	bool __fastcall DoLstInitial();
	void __fastcall DoLstChg(CELLS eCELLS=CELLS_Default, int Offset=0);
	void __fastcall DoLstChgPos(CELLS eCELLS=CELLS_Default, int Offset=0);
	void __fastcall DoLstChgCel(CELLS eCELLS=CELLS_Default, bool bPaint=true);
	void __fastcall DoChgPos(TObject *Sender, short ScrollCode, int iTopLine);


	int  __fastcall DoHgtTitle(TObject *Sender);
	int  __fastcall DoHgtBottom(TObject *Sender);

protected:

	bool __fastcall IsCellVisible(int iCellIndex);

	virtual void __fastcall DoChgSize(TObject *Sender, TRect rtPanelDB){}
	virtual	int  __fastcall DoMouseWheel(TObject *Sender){}
	virtual void __fastcall DoPaintLst(TCanvas *pCanvas);

public:

	__fastcall TTableView(TComponent* Owner);
	__fastcall ~TTableView();

	bool __fastcall ReloadData(int iCellIndex=NOSET, SBS iSBS=SBS_NONE, int iTopline=NOSET);

	TStateBtn* __fastcall GetCellAds(int iCellIndex);
	int  	   __fastcall GetCellHgt(int index);
	int  	   __fastcall GetCellBeg();
	int  	   __fastcall GetCellBom();
	int  	   __fastcall GetCellNum();
	void 	   __fastcall SetCellInd(int iCellIndex);
	void 	   __fastcall SetSBPos(SBS iSBS=SBS_TOP, int iTopline=0);

__published:

	__property int IndFocus = { read =FIndFocus, write=FIndFocus, default=NOSET };
	__property int IndSel   = { read =FIndSel,   write=FIndSel,   default=NOSET };
	__property int HgtSmall = { read =FHgtSmall, write=FHgtSmall, default=NOSET };
	__property int Count	= { read =GetCellNum };
	__property TNotifyEvent OnChange = {read=FOnChange, write=FOnChange };

private:

	TNotiT2C     FOnCellHgt;
	TNotiTable   FOnTitle;
	TNotiTable   FOnBottom;
	TNotiCellPt  FOnClickL;
	TNotiCellPt  FOnClickLP;
	TNotiCellPt  FOnClickR;
	TNotiCellPt  FOnClickRP;

__published:

	__property TNotiT2C     OnCellHgt = { read = FOnCellHgt, write = FOnCellHgt };
	__property TNotiTable   OnTitle   = { read = FOnTitle,   write = FOnTitle };
	__property TNotiTable   OnBottom  = { read = FOnBottom,  write = FOnBottom };
	__property TNotiCellPt  OnClickL  = { read = FOnClickL,  write = FOnClickL };
	__property TNotiCellPt  OnClickLP = { read = FOnClickLP, write = FOnClickLP };
	__property TNotiCellPt  OnClickR  = { read = FOnClickR,  write = FOnClickR };
	__property TNotiCellPt  OnClickRP = { read = FOnClickRP, write = FOnClickRP };

private:

	TNotiT2C    FOnMDCell;
	TNotiTable  FOnMDNum;
	TNotiTable  FOnMDTop;
	TNotiTable  FOnMDBottom;
	TNotiC2C    FOnMDMOV;

__published:

	__property TNotiT2C   OnMDCell   = { read  = FOnMDCell,   write = FOnMDCell };
	__property TNotiTable OnMDNum    = { read  = FOnMDNum,    write = FOnMDNum };
	__property TNotiTable OnMDTop    = { read  = FOnMDTop,    write = FOnMDTop };
	__property TNotiTable OnMDBottom = { read  = FOnMDBottom, write = FOnMDBottom };
	__property TNotiC2C   OnMDMOV    = { read  = FOnMDMOV,    write = FOnMDMOV };
};

#endif


