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

#ifndef TrackPanelH
#define TrackPanelH

#include "ContentPanelUnit.h"
#include "ToolpalPanel.h"
#include "TextButton.h"
#include "SkinTrackBar.h"
#include "ComboBoxComponent.h"
#include "CapButton.h"
#include "ListViewMove.h"
#include "MessageFormUnit.h"

//---------------------------------------------------------------------------
class TSMButton : public Vcl::Controls::TGraphicControl
{
private:
	int FType;
	bool FHover,
		FDown;

	void __fastcall SetDown( bool bDown );

protected:
	virtual void __fastcall Paint(void);

	MESSAGE void __fastcall CMMouseEnter(Winapi::Messages::TMessage &Message);
	MESSAGE void __fastcall CMMouseLeave(Winapi::Messages::TMessage &Message);
	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
		MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
	END_MESSAGE_MAP(Vcl::Controls::TGraphicControl)
public:
	__fastcall virtual TSMButton(System::Classes::TComponent* AOwner);

__published:
	__property bool Down = {read=FDown, write=SetDown, default=false};
	__property int Type = {read=FType, write=FType, default=0};
	__property OnMouseDown;
};

#define CTRL_VOL	3
#define CTRL_MIDI	4

class TTrackPanel : public TToolpalPanel
{
private:
	int m_iType, m_iTrack;

	TContentPanel* m_pContentPanel; //ÄÚÈÝÃæ°å¾ä±ú

	TLabel  *m_lblName,
			*m_lstCaption[CTRL_VOL],
			*m_lblMidi[CTRL_MIDI],
			*m_lblAudio;
	TSkinTrackBar* m_lstTrack[CTRL_VOL];
	TBitmap	*m_iconMidi,
			*m_iconWave;
	TImage *m_imgType;
	TSMButton *m_btnMute,
			*m_btnSolo;
	TComboBoxComponent *m_cbChannel;
	TCapButton* m_btnMidi[CTRL_MIDI-1];

	void EnableComponets();
	void GetAudioDemoRange( double& dblStart, double& dblEnd );
	void AddAudioFxParamUndo( int ind, DWORD iBegin, DWORD iEnd, void* pBefore, void* pAfter );
	void OnTrackParamChange( int iParam, int nValue, bool bAddUndo=true );
	void OnAddAudioFx( int iFxType );
	void OnAudioFxParam( int ind );
	void OnAudioFxState( int ind, bool bOn );
 	void OnAudioFxDelete( int ind );

	void __fastcall DoAudioAddFx(System::TObject* Sender);
	void __fastcall DoAudioAddVst(System::TObject* Sender);
	void __fastcall DoAudioFxState(System::TObject* Sender);
	void __fastcall DoAudioFxParam(System::TObject* Sender);
	void __fastcall DoAudioFxDelete(System::TObject* Sender);
	void __fastcall TrackBarChange(TObject *Sender);
	void __fastcall ComboBoxChange(TComboBoxItem *Sender, int Index);
	void __fastcall CapButtonClick(TObject *Sender);
	void __fastcall SMMouseDown(System::TObject* Sender, System::Uitypes::TMouseButton Button,
												System::Classes::TShiftState Shift, int X, int Y);

	//add by tj
	TPngImage *m_pImgDel;
	TPngImage *m_pImgOff;
	TPngImage *m_pImgOn;
	TListViewMove *m_pLstView;

	bool __fastcall DoLstItemDBLClick(int index, bool bOn);
	bool __fastcall DoLstItemRightClick(int index, bool bOn, TPoint pt);
	bool __fastcall DoLstItemStateChange(int index, bool bOn);
	bool __fastcall DoLstItemDelete(int indSrc, int indDes);
	bool __fastcall DoLstItemMovEnd(int indSrc, int indDes);

	void __fastcall DoLstMouseEnter(TObject *Sender);

	TPngImage    *m_pngAdd;
	TPNGButton   *m_pBtnAdd;
	void __fastcall DoLstAddItem(TObject *Sender);

protected:
	virtual void __fastcall CreateWnd();
	virtual MESSAGE void __fastcall WMSize(Winapi::Messages::TWMSize &Message);

	MESSAGE void __fastcall UMAudioFx(TMessage &msg);

	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(UM_AUDIOFX, TMessage, UMAudioFx)
	END_MESSAGE_MAP(TToolpalPanel)
public:
	__fastcall virtual TTrackPanel(System::Classes::TComponent* AOwner);
	__fastcall ~TTrackPanel();

	void __fastcall SetContentPanel( TContentPanel* pPanel ){ m_pContentPanel=pPanel; };
	void __fastcall SetSelTrack( int iType, int iTrack );
	void __fastcall OnTrackStateChanged( int iState, bool bAddUndo=true );
	void __fastcall OnAddFx();
	void __fastcall RefreshTrackState( int iState, bool bUnset );

	void Undo( bool bUndo );
};

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

#endif
