// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "CApp.h"
#include "IBaseClash.h"
#include "CManageNetWork.h"


#include "CNodeAdapter.hpp"
#include "CConnectMage.h"


class CMainDlg : public SHostWnd, protected TAutoEventMapReg<CMainDlg>
{
public:
	CMainDlg();
	~CMainDlg();

	void OnConnecting_UdateUi(bool b, SStringW msg = L"", SStringW acc_msg = L"",bool connect = false);

	void OnClose();
	void OnMaximize();
	void OnRestore();
	void OnMinimize();
	int OnCreate(LPCREATESTRUCT lpCreateStruct);
	void OnCommand(UINT uNotifyCode, int nID, HWND wndCtl);
	BOOL OnInitDialog(HWND wndFocus, LPARAM lInitParam);
protected:
	void Init();
	void OnNode();
	void OnBackNode();
	bool OnSysModeType(SOUI::EventArgs* pEvt);
	bool OnRouteModeType(SOUI::EventArgs* pEvt);
	void OnAuthFinish(SOUI::EventArgs* pEvt);
	void OnServerListFinish(SOUI::EventArgs* pEvt);
	void OnVersionFinish(SOUI::EventArgs* pEvt);
	void OnConnectFinish(SOUI::EventArgs* pEvt);
	void OnClashPreoceeQutFinish(SOUI::EventArgs* pEvt);
	void UPdateMsgStatus(SStringW msg);
	void UPdateVersionMsgStatus(SStringW msg,SStringW url = L"", int appversionupdate = 0);
	void UpDateUserInfo();
	void ShowView(int nItem, SWindow* pItem);
	void ItemRClick(int nItem);
	void OnRefresh();
	void OnConnect();
	void OnAuth();
	void OnUpdataNodeName(SStringW nodename = L"");
	//soui消息
	EVENT_MAP_BEGIN()
		EVENT_HANDLER(EventNodeList::EventID, OnServerListFinish)
		EVENT_HANDLER(EventClashPreOceeQut::EventID, OnClashPreoceeQutFinish)
		EVENT_HANDLER(EventAUTH::EventID, OnAuthFinish)
		
		EVENT_HANDLER(EventVerions::EventID, OnVersionFinish)
		EVENT_HANDLER(EventConnect::EventID, OnConnectFinish)
		EVENT_NAME_COMMAND(L"btn_close", OnClose)
		EVENT_NAME_COMMAND(L"btn_min", OnMinimize)
		EVENT_NAME_COMMAND(L"btn_max", OnMaximize)
		EVENT_NAME_COMMAND(L"btn_restore", OnRestore)
		EVENT_NAME_COMMAND(L"selectnode", OnNode)
		EVENT_NAME_COMMAND(L"list_back", OnBackNode)
		EVENT_NAME_COMMAND(L"onRefresh", OnRefresh)
		EVENT_NAME_COMMAND(L"OnRefresh", OnRefresh)
		 
		EVENT_NAME_COMMAND(L"connect_touch", OnAuth)
	EVENT_MAP_END()
		
	//HostWnd真实窗口消息处理
	BEGIN_MSG_MAP_EX(CMainDlg)
		MSG_WM_CREATE(OnCreate)
		MSG_WM_INITDIALOG(OnInitDialog)
		MSG_WM_CLOSE(OnClose)
		MSG_WM_COMMAND(OnCommand)
		CHAIN_MSG_MAP(SHostWnd)
		REFLECT_NOTIFICATIONS_EX()
	END_MSG_MAP()
private:
	BOOL			m_bLayoutInited;	
	std::vector<SysMode> m_sysmode_vctor;
	std::vector<RouteMode> m_route_vctor;
	IBaseClash* m_base_clash;
	CAutoRefPtr<CNodeAdapter> pNodeAdapter;
	bool		m_refresh;
	CConnectMage* m_connect_mage;
};
