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

#ifndef StylePanelH
#define StylePanelH

#include "StyleItem.h"
#include "ToolpalPanel.h"
#include "SkinTrackBar.h"
#include "SkinHintWindow.h"
//#include "PopMenuUnit.h"

class TStylePanel : public TToolpalPanel
{
protected:
	TCommonItem * m_pTopItem, *m_pFocItem, *m_pSelItem,
			*m_pDragItem, *m_pDropItem, *m_pHoverItem, *m_pPlayItem;
	int m_nItemShow, m_nTotalLine,
		m_nItemHeight, m_nItemWidth,
		m_iFocLine, m_iSelLine, m_iTopLine, m_iHoverLine,
		m_iFocCol;

	bool m_bPlaying;

	TPoint ptDown;

	System::Classes::TList* m_aItems;
	TTimer *m_pTimer;

	TSkinTrackBar* m_VolTrackBar;
//	TPopMenuBar *m_PopupMenu;          //右键菜单
	TEdit* m_editName;

//	TSkinHintWindow* m_Hint;
//	TTimer *m_HintTimer;
//	TPoint pMove;
//	String HintStr;

	virtual void Init()=0;
	void CalcViewArea();
	void ScrollView( int nPos, bool bRedraw=true );
	void ResetScrollBar();
	void ShowSelItem();

	//滑动条
	void __fastcall TrackBarChange(System::TObject* Sender);

//	void __fastcall HintTimerProc(System::TObject* Sender);

	TCommonItem* GetItem( int iSty, int iSeg, int iTrk );
	TCommonItem* GetNextItem( TCommonItem *pItem );
	TCommonItem* GetPrevItem( TCommonItem *pItem );
	virtual void ClearAllItems();
	virtual void DeleteItem( TCommonItem *pItem, int iLine );
	virtual void RestoreItems(){};

	TStyleItem* __fastcall AddStyle( TPROSTYLE* info, DWORD opts=0 );
	TTrackItem* AddTrack(  TSegmentItem* pSeg, TTrackItem* pDropTrk, bool bOwn=true );

	TCommonItem* HitTest( int X, int Y, WORD* iCol );

	void SetFold( TCommonItem *pFoldItem, int iFoldLine );
	void SetHover( TCommonItem *pItem, int iLine );
	virtual void SetSelect( TCommonItem *pItem, int iLine );

	void DrawItem( TCommonItem *pItem, int iLine, WORD iCol );
	void DrawDragImg( TCommonItem *pDragItem );

	void SetUnfoldTimer(TCommonItem *pItem, TCommonItem *pHoverItem);
	TCommonItem* GetTrackHoverItem( TCommonItem* pItem, int &iHoverLine );

	virtual bool StartDrag()=0;
	virtual void SetScrollTimer(TPoint ptMouse);
	virtual void HandleDropEvent( int iState ){};
	virtual bool HandleHoverEvent(TPoint ptMouse){return false;};
	virtual void SetCollect(TCommonItem* pStyItem);   //add laq
	virtual void PlayDemo( TCommonItem *pItem, int tempo );
	virtual void VolumeChanged( TCommonItem *pItem, char volNew );
	virtual String ChargeTip( TStyleItem* pItem ){ return ""; };

	virtual void __fastcall DoubleClick(TObject* sender);
	void __fastcall TimerProc(TObject* Sender);
	void __fastcall MouseLeave(TObject* Sender);

	void __fastcall DoDownload(TObject* Sender);
 	void __fastcall DoDownloadAll(TObject* Sender);
	void __fastcall DoCancelDownload(TObject* Sender);
	void __fastcall DoPlay(TObject* Sender);
  	void __fastcall DoStop(TObject* Sender);
	void __fastcall DoFold(TObject* Sender);
 	void __fastcall DoMute(TObject* Sender);
	void __fastcall DoAdjustVolume(TObject* Sender);
	void __fastcall DoUseBrush(TObject* Sender);
	void __fastcall DoDelete(TObject* Sender);
	void __fastcall DoApplyPreStyle(TObject* Sender);
	void __fastcall DoApplyUseStyle(TObject* Sender);
	void __fastcall DoSaveLocalStyle(TObject* Sender);

	virtual void __fastcall DoHandleMessage(MSG &Msg, bool &Handled);  //鼠标消息处理
	virtual void __fastcall DoCollect(TObject* Sender){};
	virtual void __fastcall DoChangeFontProg(TObject* Sender){};
	virtual void __fastcall DoChangeTexture(TObject* Sender){};
	virtual void __fastcall DoImportSegment(TObject* Sender){};
	virtual void __fastcall DoRename(TObject* Sender){};
	virtual void __fastcall RenameTiming(int op){};

	virtual MESSAGE void __fastcall WMMouseDown(TWMMouse &Message);
	virtual MESSAGE void __fastcall UMMouseUp(TWMMouse &Message);
	virtual MESSAGE void __fastcall WMSize(Winapi::Messages::TWMSize &Message);
	MESSAGE void __fastcall WMVScroll(Winapi::Messages::TWMScroll &Message);
	MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
	MESSAGE void __fastcall UMMouseMove(TWMMouse &Message);

	BEGIN_MESSAGE_MAP
//		MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
		MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)
		MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
		MESSAGE_HANDLER(UM_MOUSEMOVE, TWMMouseMove, UMMouseMove)
		MESSAGE_HANDLER(UM_MOUSEUP, TWMMouse, UMMouseUp)
	END_MESSAGE_MAP(TToolpalPanel)

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

public:
	__fastcall TStylePanel(System::Classes::TComponent* AOwner);
	__fastcall ~TStylePanel();

	static void LoadImages();
	static void FreeImages();

	void InitItems();
	virtual void __fastcall SetStyleItem( TStyleItem* pStyItem );
	virtual bool __fastcall GetPrebeat( BYTE* pData, int& nSize ){ return false; };

	void __fastcall SetFocusedItem( TCommonItem* pItem, int iLine, WORD iCol );
	virtual void Stop( DWORD dwSpec=STOP_SELF );
	virtual bool ShowDragImg( bool bShow=true, int iState=0 );
	TCommonItem* GetDragItem(){ return m_pDragItem; };
	TCommonItem* GetDropItem(){ return m_pDropItem; };
	virtual void SetDropItem( TCommonItem* pItem ){ m_pDropItem = pItem; };
};

//---------------------------------------------------------------------------
#endif
