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

#ifndef UseStylePanelH
#define UseStylePanelH

#include "ContentPanelUnit.h"
#include "StylePanel.h"

//---------------------------------------------------------------------------
class TUseStylePanel : public TStylePanel
{
private:
	TContentPanel* m_pContentPanel; //ÄÚÈÝÃæ°å¾ä±ú
	TTimer *m_pPlayTimer;

    bool m_bAddWeakupBar;
	STYLELIST m_aStyles;

	void __fastcall PlayEndProc(TObject* Sender);

	int FindItemStage( TCommonItem* pItem );
	TSegmentItem* AddStage( TOpusStage* pStage );
	TTrackItem* AddTrack( TSegmentItem* pSeg, TTrack* pSrcTrk, int iInd=-1 );
	TTrackItem* FindTrackItem( int iStage, TTrack* pTrk );
	bool IntegrateStages( int iStageBegin, bool bSetMM=true );
	int GetInsertStage( int iCutBar );
	void HandleWeakup( int iStageBegin, bool bSetMM=true );
	void CountStyles();
	void DeleteBars( int iStartBar, int iEndBar, bool bDelWave );
	void DeleteTrack( int iStage, TTrackItem* pTrkItem, int iLine );
	void SetSelectTrack( TTrackItem* pTrack );
	void ChangeVolume( int iStage, TCommonItem* pItem, char newVol, bool bAddUndo=true );
	int GetDemoData( TCommonItem* pItem, int &nLen, BYTE* pData, int& iStartBar, int& lenBar );
	void CountTotalLine();

protected:
	void ReplaceSegment( TSegmentItem* pDestSeg,
									TSegmentItem* pSrcSeg);
	void RemoveSegment( TSegmentItem* pItem, bool bSetMM=true );
	TSegmentItem* InsertSegment( int iStage, TSegmentItem* pSrcSeg, int nBars );

	virtual void ClearAllItems();
	virtual void Init(){};
	virtual void PlayDemo( TCommonItem *pItem, int tempo );
	virtual bool StartDrag(){ return false; };
	virtual void HandleDropEvent( int iState=0 );
	virtual bool HandleHoverEvent(TPoint ptMouse);
	virtual void VolumeChanged( TCommonItem *pItem, char volNew );
	virtual void RestoreItems();
	virtual void SetSelect( TCommonItem *pItem, int iLine );
	virtual void DeleteItem( TCommonItem *pItem, int iLine );
	virtual String ChargeTip( TStyleItem* pItem );

	virtual void __fastcall DoChangeFontProg(TObject* Sender);
	virtual void __fastcall DoChangeTexture(TObject* Sender);

	MESSAGE void __fastcall OnPlayEnd(TMessage &msg);

	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(MSG_PLAY_END, TMessage, OnPlayEnd )
	END_MESSAGE_MAP(TStylePanel)

public:
	__fastcall TUseStylePanel(System::Classes::TComponent* AOwner);

	virtual void Stop( DWORD dwSpec=STOP_CONTENT|STOP_USESTYLE );
	virtual void __fastcall SetStyleItem( TStyleItem* pStyItem );
	virtual bool __fastcall GetPrebeat( BYTE* pData, int& nSize );

	void __fastcall InitOpus( TStyleItem* pPreStyle, int iMode );
						//iMode: 0=³õÊ¼»¯ 1=IME 2=IMIME 3=Predefine
	void __fastcall InsertStage( int iInsertBar, TSegmentItem* pSrcSeg );
	void __fastcall MoveBars( int iStartBar, int iEndBar, int iInsertBar, int iMode );
	void __fastcall ReformStage( int iDestStage, TSegmentItem* pSrcSeg );
	void __fastcall RemoveStage( int iDestStage );
	void __fastcall ReformBars( int iStartBar, int iEndBar, TSegmentItem* pScrSeg, bool bAddUndo=true );
	void __fastcall InsertBlankBar( int iInsertBar );
	bool __fastcall Charge4Fonts();
	void __fastcall ChangeTexture( int iSBar, int iEBar, char sType, int iMT, TTrack* pSubTrack, int op );
	void __fastcall ChangeFont( int iSBar, int iEBar, int iMT, int iBank, int iProg, int iChno, int op );
	void __fastcall DeleteAllTexture( bool bAddUndo=true );

	void SetContentPanel( TContentPanel* pPanel ){ m_pContentPanel=pPanel; };
	void SetSelectStage( int iStage );
	void ApplyStyle( TStyleItem* pSrcStyle );
	void CopyBars( int iStartBar, int iEndBar, TOpusStageList* lstStages,
								TSegmentList* lstSegments, TAudioTrackList* lstAudio );
	void CopyUndoBars( int iStartBar, int iEndBar, TOpusStageList* lstStages,
													TAudioTrackList* lstAudio, bool bFx=false );
	void SetBarsUndo( int iMode, int iStartBar, int nBars, int iMoveTo=-1 );
	void Undo( bool bUndo );
};

#endif


