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

#ifndef MainFormUnitH
#define MainFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.jpeg.hpp>

#include "PNGButton.hpp"
#include "Capbutton.h"
#include "MenuBar.h"
#include "MenuUnit.h"
#include "SkinHintWindow.h"
#include "MicSetFormUnit.h"
#include "SetUpFormUnit.h"
#include "ComboBoxComponent.h"
#include "VolumeFormUnit.h" //add by lm 14.1.7

#include "LineEdit.h"
#include "KeyBoard.h"
#include "HelpFormUnit.h"

#include "NotificationFormUnit.h"
#include "TextButton.h"
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published:	// IDE-managed Components
	TPNGButton *m_btnClose;
	TPNGButton *m_btnMax;
	TPNGButton *m_btnMin;
	TPNGButton *m_btnRest;
	TPNGButton *m_btnRecord;
	TPNGButton *m_btnPlay;
	TPNGButton *m_btnStop;
	TPNGButton *m_btnPause;
	TLabel *m_lblTitle;
	TLabel *m_lblLogon;
	TPNGButton *m_tabStyle;
	TPNGButton *m_tabChord;
	TPNGButton *m_tabAudio;
	TComboBoxComponent *m_cbPreStage;
	TCapButton *m_btnTS;
	TCapButton *m_btnTempo;
	TPanel *m_panelVolLevel;
	TImage *m_imgVolLevelBk;
	TPaintBox *m_pbVolLevel;
	TComboBoxComponent *m_cbFontSelect;
	TComboBoxComponent *m_cbKey;
	TPNGButton *m_btnOpen;
	TPNGButton *m_btnSave;
	TPNGButton *m_btnUpload;
	TPNGButton *m_btnKeyboard;
	TPNGButton *m_btnVolSet;
	TImage *m_Logo;
	TPaintBox *m_pbUserNoticeNum;
	TPNGButton *m_btnExtFontOn;
	TPNGButton *m_btnExtFontOff;
	TLabel *m_lblExtFont;
	TLabel *m_lblWebsite;

	void __fastcall FormCreate(TObject *Sender);
	void __fastcall FormResize(TObject *Sender);
	void __fastcall CloseClick(TObject *Sender);
	void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
	void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
	void __fastcall MaxClick(TObject *Sender);
	void __fastcall MinClick(TObject *Sender);
	void __fastcall RestClick(TObject *Sender);
	void __fastcall FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
														int X, int Y);
	void __fastcall FormPaint(TObject *Sender);
	void __fastcall LogonMouseEnter(TObject *Sender);
	void __fastcall LogonMouseLeave(TObject *Sender);
	void __fastcall RecordClick(TObject *Sender);
	void __fastcall StopClick(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall PlayClick(TObject *Sender);
	void __fastcall PauseClick(TObject *Sender);
	void __fastcall PanelMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
//	void __fastcall PanelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall PanelMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall TabClick(TObject *Sender);
	void __fastcall PreStageChange(TComboBoxItem *Sender, int Index);
	void __fastcall VolLevelPaint(TObject *Sender);
    void __fastcall UserNameClick(TObject *Sender);
	void __fastcall FontSelectChange(TComboBoxItem *Sender, int Index);
	void __fastcall KeyChange(TComboBoxItem *Sender, int Index);
	void __fastcall OpenClick(TObject *Sender);
	void __fastcall SaveClick(TObject *Sender);
	void __fastcall UploadClick(TObject *Sender);
	void __fastcall TTClick(TObject *Sender);
	void __fastcall VolSetClick(TObject *Sender);
	void __fastcall OnKeyBoard(TObject *Sender);
	void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall PlayTimeClick(TObject *Sender);
	void __fastcall DoShowNoticeNumPaint(TObject *Sender);
	void __fastcall UserNoticeNumClick(TObject *Sender);
	void __fastcall ExtFontClick(TObject *Sender);
	void __fastcall URLClick(TObject *Sender);
	void __fastcall URLMouseEnter(TObject *Sender);
	void __fastcall URLMouseLeave(TObject *Sender);

private:	// User declarations
	TMenuBar *m_pMenuBar;
	TMenuPanel *m_pMenu,
				*m_pPopMenu;
	TVolumeForm *m_pVolumeForm;

	TPlayTimePanel *m_pPlayTimePanel;
	TContentPanel *m_pContentPanel;
	TToolpalPanel *m_pUseStylePanel, *m_pAudStylePanel, *m_pPreStylePanel,
				*m_pChordPanel, *m_pTrackPanel;
	int m_ToolpalWidth, m_UseStyleHeight, m_PreStyleHeight;

	TKeyBoard *m_KeyBoard;	//模拟键盘 add by laq 2014.1.17

	//录音/播放相关
	DWORD m_dwLastVol;
	int m_iStartBar,
		m_iLastStartBar,
		m_iRecordBar,
		m_nDelayPoint;
	double m_dblStartPoint,
		m_dblLastStartPoint,
		m_dblRecordPoint;

//	bool m_bAudioModified;
	bool m_bFromFile;
	UINT m_tTimer, m_tAccuracy, m_tBeatHint;
	int m_nVolLevel;          //音量等级

	HRESULT __fastcall AutoRecognition( int iType );  //旋律识别 0=录音 1=音频导入 2=MIDI导入 3=移动
	HRESULT __fastcall AutoChords(); 	//自动配置和弦
	void __fastcall OnLoadMelody(TObject *Sender);
	void __fastcall SetMode( int iMode, bool bForce=false ); //设置视图模式, bForce强制刷新
	void __fastcall ChangeTT( bool bTS, int iValue );
	void __fastcall SetFont( int idFont, bool bExtFont=false, bool bAddUndo=true );

    //倒计时定时器
    TTimer * m_pCDTimer;
	void __fastcall CDTimerProc(TObject* Sender);
    void __fastcall ClearCDTimer();

	//保存相关
	String m_strLoadProjectName,
		m_strUploadFile;

	void __fastcall SaveAs( int iComb );

	//显示相关
	void __fastcall ShowPlayTime();
	void __fastcall CreateMenus();
	void __fastcall ViewLayout();

	void __fastcall NewProject();
	void __fastcall DoLoadProject( LPCTSTR strName );
	void __fastcall AfterLoadProject();
	void __fastcall Undo( bool bUndo );

	void __fastcall SetRecordState( bool bRecord );
	void __fastcall ShowToolPanels( int iShow );

	bool __fastcall RecordEnabled();
	bool __fastcall CheckPayment( int iOperation );
	void __fastcall Logout();	   // add by lm 14.1.17

	int __fastcall SaveMedia( int iOperation, int iSaveOption, int iFileType, String strFileName, bool bUpload=false );

	//帮助
	THelpForm* m_HelpForm;

	//动态 //add by tj 2014/04/18
	TTimer *m_pNotificationGetTimer;
	void __fastcall NotificationTimerProc(TObject* Sender);
	TNotificationForm *m_pNotificationForm;

	void __fastcall CreateParams(TCreateParams &Params);

	void __fastcall OnCreateNewProject(TObject * Sender = NULL);
	void __fastcall OnPredefineProject(TObject * Sender = NULL);
	void __fastcall OnSaveProject(TObject *Sender=NULL);
	void __fastcall OnLoadProject(TObject *Sender=NULL);
	void __fastcall OnUserHelp(TObject *Sender=NULL);
	void __fastcall OnUserManual(TObject *Sender=NULL);
	void __fastcall OnForumVist(TObject *Sender=NULL);
	void __fastcall OnAbout(TObject *Sender=NULL);
	void __fastcall OnMicSetting(TObject *Sender=NULL);
	void __fastcall OnVSTPathSetting(TObject *Sender=NULL);
	void __fastcall OnSaveAs(TObject *Sender=NULL);// add by lm 14.1.7
	void __fastcall OnShowToolPanels(TObject *Sender=NULL);
	void __fastcall OnViewMode(TObject *Sender=NULL);
	void __fastcall OnNotification(TObject *Sender=NULL); //add by tj 2014/04/18
	void __fastcall OnCustomerSetting(TObject *Sender=NULL); //add by tj 2014/05/13
	void __fastcall OnUndo(TObject *Sender=NULL);
	void __fastcall OnRedo(TObject *Sender=NULL);
    void __fastcall OnShowMore(TObject *Sender=NULL);

	//消息处理
	MESSAGE void __fastcall WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message);
	MESSAGE void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
	MESSAGE void __fastcall WMNCLButtonDown(TWMNCLButtonDown &Msg);
	MESSAGE void __fastcall WMNCRButtonDown(TWMNCRButtonDown &Msg);
	MESSAGE void __fastcall WMNCLButtonDblClk(TWMNCLButtonDblClk &Msg);
	MESSAGE void __fastcall WMWindowPosChanged(TWMWindowPosChanged &Msg);

	MESSAGE void __fastcall OnRestoreWindow(TMessage &msg);
	MESSAGE void __fastcall OnShowMenu(TMessage &msg);
//	MESSAGE void __fastcall OnMenuCall(TMessage &msg);
	MESSAGE void __fastcall OnMenuClose(TMessage & Msg);
	MESSAGE void __fastcall OnLogin(TMessage &msg);
	MESSAGE void __fastcall OnNetworkError(TMessage &msg);
	MESSAGE void __fastcall OnNetworkMessage(TMessage &msg);
	MESSAGE void __fastcall OnLoadProjectMessage(TMessage &msg);
	MESSAGE void __fastcall OnSaveProjectMessage(TMessage &msg);
	MESSAGE void __fastcall OnNewProjectMessage(TMessage &msg);
	MESSAGE void __fastcall OnUploadMusic(TMessage & Msg);
	MESSAGE void __fastcall AcceptFiles (TMessage& Msg);
	MESSAGE void __fastcall OnShowAbout(TMessage & Msg);
	MESSAGE void __fastcall OnOpenManual(TMessage & Msg);
	MESSAGE void __fastcall OnOpenAutoProj(TMessage & Msg);

	MESSAGE void __fastcall UMShowBrush(TMessage &msg);
	MESSAGE void __fastcall UMMediaTime(TMessage &Message);
	MESSAGE void __fastcall UMRecordComplete(TMessage &Message);
	MESSAGE void __fastcall UMRecordVolJust(TMessage &Message);
	MESSAGE void __fastcall UMPlayOver(TMessage &Message);
	MESSAGE void __fastcall UMShowPlayTime(TMessage &Message);
	MESSAGE void __fastcall UMStop(TMessage &Message);
	MESSAGE void __fastcall UMRecord(TMessage &Message);
	MESSAGE void __fastcall UMTTSetup(TMessage &Message);
	MESSAGE void __fastcall UMChangeTT(TMessage &Message);
	MESSAGE void __fastcall UMStageChanged(TMessage &Message);
	MESSAGE void __fastcall UMShowKeyBoard(TMessage &Message);
	MESSAGE void __fastcall UMShowHelp(TMessage &Message);
	MESSAGE void __fastcall UMStyleScore(TMessage &Message);
	MESSAGE void __fastcall UMNotification(TMessage & Msg);  //add by tj 2014/04/18
	MESSAGE void __fastcall UMApplyStyle(TMessage &Message);
	MESSAGE void __fastcall UMSaveLocalStyle(TMessage &Message);
	MESSAGE void __fastcall UMImportSegment(TMessage &Message);
	MESSAGE void __fastcall UMUploadStyle(TMessage &Message);
   	MESSAGE void __fastcall UMChangeMelodyKey(TMessage &Message);
	MESSAGE void __fastcall UMSetViewMode(TMessage &Message);
	MESSAGE void __fastcall UMEnableRecord(TMessage &Message);
	MESSAGE void __fastcall UMAudioLoad(TMessage &Message);
	MESSAGE void __fastcall UMAutoRecognition(TMessage &Message);
	MESSAGE void __fastcall UMShowVolSet(TMessage &Message);
	MESSAGE void __fastcall UMVSTPath(TMessage &Message);
	MESSAGE void __fastcall UMSetContentView(TMessage &Message);
	MESSAGE void __fastcall UMGetContentView(TMessage &Message);
	MESSAGE void __fastcall UMAudioVolChanged(TMessage &Message);
 	MESSAGE void __fastcall UMPreferChanged(TMessage &Message);
 	MESSAGE void __fastcall UMShowMore(TMessage &Message);
 	MESSAGE void __fastcall UMStartCDTimer(TMessage &Message);

	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
		MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
		MESSAGE_HANDLER(WM_NCLBUTTONDOWN, TWMNCLButtonDown, WMNCLButtonDown)
		MESSAGE_HANDLER(WM_NCRBUTTONDOWN, TWMNCRButtonDown, WMNCRButtonDown)
		MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, TWMNCLButtonDblClk, WMNCLButtonDblClk)
		MESSAGE_HANDLER(WM_WINDOWPOSCHANGED, TWMWindowPosChanged, WMWindowPosChanged)
		MESSAGE_HANDLER(WM_DROPFILES,TMessage, AcceptFiles)

		MESSAGE_HANDLER(MSG_NETWORKERROR, TMessage, OnNetworkError)
		MESSAGE_HANDLER(MSG_NETWORKMESSAGE, TMessage, OnNetworkMessage)
		MESSAGE_HANDLER(MSG_MEDIATIME, TMessage, UMMediaTime)
		MESSAGE_HANDLER(MSG_RECORD_COMPLETE, TMessage, UMRecordComplete)
		MESSAGE_HANDLER(MSG_RECORD_VOLJUST, TMessage, UMRecordVolJust)
		MESSAGE_HANDLER(MSG_PLAY_END, TMessage, UMPlayOver)

		MESSAGE_HANDLER(UM_RESTORE, TMessage, OnRestoreWindow)
		MESSAGE_HANDLER(UM_SHOWMENU, TMessage, OnShowMenu)
		MESSAGE_HANDLER(UM_MENUCLOSE, TMessage, OnMenuClose)
		MESSAGE_HANDLER(UM_SHOWPLAYTIME, TMessage, UMShowPlayTime)
		MESSAGE_HANDLER(UM_STOP, TMessage, UMStop)
		MESSAGE_HANDLER(UM_RECORD, TMessage, UMRecord)
		MESSAGE_HANDLER(UM_SHOWBRUSH, TMessage, UMShowBrush)
		MESSAGE_HANDLER(UM_TTSETUP, TMessage, UMTTSetup)
		MESSAGE_HANDLER(UM_CHANGETT, TMessage, UMChangeTT)
		MESSAGE_HANDLER(UM_STAGECHANGED, TMessage, UMStageChanged)
		MESSAGE_HANDLER(UM_LOGIN, TMessage, OnLogin)
		MESSAGE_HANDLER(UM_LOADPROJECT, TMessage, OnLoadProjectMessage)
		MESSAGE_HANDLER(UM_SAVEPROJECT, TMessage, OnSaveProjectMessage)
		MESSAGE_HANDLER(UM_NEWPROJECT, TMessage, OnNewProjectMessage)
		MESSAGE_HANDLER(UM_UPLOADMUSIC,TMessage,OnUploadMusic)
		MESSAGE_HANDLER(UM_SHOWABOUT,TMessage,OnShowAbout)
		MESSAGE_HANDLER(UM_OPENMANUAL,TMessage,OnOpenManual)
		MESSAGE_HANDLER(UM_SHOW_KB, TMessage, UMShowKeyBoard)
 		MESSAGE_HANDLER(UM_OPENAUTOPROJ,TMessage,OnOpenAutoProj)
		MESSAGE_HANDLER(UM_SHOWHELP, TMessage, UMShowHelp)
		MESSAGE_HANDLER(UM_STYLESCORE, TMessage, UMStyleScore)
		MESSAGE_HANDLER(UM_NOTIFICATION, TMessage, UMNotification)  //add by tj 2014/04/18
		MESSAGE_HANDLER(UM_APPLYSTYLE, TMessage, UMApplyStyle)
		MESSAGE_HANDLER(UM_SAVELOCALSTYLE, TMessage, UMSaveLocalStyle)
		MESSAGE_HANDLER(UM_IMPORTSEGMENT, TMessage, UMImportSegment)
		MESSAGE_HANDLER(UM_UPLOADSTYLE, TMessage, UMUploadStyle)
		MESSAGE_HANDLER(UM_CHANGEKEY, TMessage, UMChangeMelodyKey)
		MESSAGE_HANDLER(UM_SETVIEWMODE, TMessage, UMSetViewMode)
		MESSAGE_HANDLER(UM_ENABLERECORD, TMessage, UMEnableRecord)
		MESSAGE_HANDLER(UM_AUDIOLOAD, TMessage, UMAudioLoad)
		MESSAGE_HANDLER(UM_AUTORECOGNITION, TMessage, UMAutoRecognition)
		MESSAGE_HANDLER(UM_SHOW_VOLSET, TMessage, UMShowVolSet)
		MESSAGE_HANDLER(UM_VSTPATH, TMessage, UMVSTPath)
		MESSAGE_HANDLER(UM_SETCONTENTVIEW, TMessage, UMSetContentView)
		MESSAGE_HANDLER(UM_GETCONTENTVIEW, TMessage, UMGetContentView)
		MESSAGE_HANDLER(UM_AUDIOVOLCHANGED, TMessage, UMAudioVolChanged)
		MESSAGE_HANDLER(UM_PREFERCHANGED, TMessage, UMPreferChanged)
        MESSAGE_HANDLER(UM_SHOWMORE, TMessage, UMShowMore)
		MESSAGE_HANDLER(UM_STARTCDTIMER, TMessage, UMStartCDTimer)
	END_MESSAGE_MAP(TForm)

public:		// User declarations
	__fastcall TMainForm(TComponent* Owner);

	void __fastcall ShowErrorMessage( int err, String strOperation );
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
