#pragma once

#include "resource.h"

// Forward declarations
class uie_win;
class CDialogFind;
class CDialogReplace;

enum
{
	UM_DIALOG_STYLE_RELOAD = WM_APP + 300,
};

//class config_dialog_manager
//{
//private:
//	pfc::list_t<HWND> m_wnds;
//
//public:
//	void add_window(HWND p_wnd)
//	{
//		if (m_wnds.have_item(p_wnd))
//			m_wnds.remove_item(p_wnd);
//
//		m_wnds.add_item(p_wnd);
//	}
//
//	void remove_window(HWND p_wnd)
//	{
//		m_wnds.remove_item(p_wnd);
//	}
//
//	void PostMessage(UINT msg, WPARAM wp, LPARAM lp)
//	{
//		for (t_size i = 0; i < m_wnds.get_count(); ++i)
//		{
//			::PostMessage(m_wnds[i], msg, wp, lp);
//		}
//	}
//};

//extern config_dialog_manager g_config_dlg_mgr;

//-----
class CDialogConf 
	: public CDialogImpl<CDialogConf>
	, public CDialogResize<CDialogConf>
{
private:
	CDialogFind * m_dlgfind;
	CDialogReplace * m_dlgreplace;
	uie_win * m_parent;
	pfc::string8 m_caption;

public:
	CDialogConf(uie_win * p_parent) 
		: m_parent(p_parent)
		, m_dlgfind(NULL)
		, m_dlgreplace(NULL)
	{
		//pfc::dynamic_assert(m_parent != NULL, "CDialogConf: m_parent invalid.");
	}

	virtual ~CDialogConf()
	{
		m_hWnd = NULL;
	}

	static LRESULT CALLBACK EditorSubclassFunc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
	void MatchShortcuts(unsigned vk);
	void Apply();

public:
	enum { IDD = IDD_DIALOG_CONFIG };

	BEGIN_MSG_MAP(CDialogConf)
		MSG_WM_INITDIALOG(OnInitDialog)
		MSG_WM_NOTIFY(OnNotify)
		COMMAND_RANGE_HANDLER_EX(IDOK, IDCANCEL, OnCloseCmd)
		COMMAND_ID_HANDLER_EX(IDAPPLY, OnCloseCmd)
		COMMAND_HANDLER_EX(IDC_SCRIPT_ENGINE, CBN_SELENDOK, OnScriptEngineCbnSelEndOk)
		COMMAND_ID_HANDLER_EX(IDC_RESET_DEFAULT, OnResetDefault)
		COMMAND_ID_HANDLER_EX(IDC_RESET_CURRENT, OnResetCurrent)
		COMMAND_ID_HANDLER_EX(IDC_IMPORT, OnImport)
		COMMAND_ID_HANDLER_EX(IDC_EXPORT, OnExport)
		COMMAND_CODE_HANDLER_EX(SCEN_CHANGE, OnScenChange)
		COMMAND_HANDLER_EX(IDC_CHECK_PSEUDO_TRANSPARENT, BN_CLICKED, OnCheckPseudoTransparentBnClicked)
		MESSAGE_HANDLER_EX(UM_DIALOG_STYLE_RELOAD, OnUmDialogStyleReload)
		CHAIN_MSG_MAP(CDialogResize<CDialogConf>)
	END_MSG_MAP()

	BEGIN_DLGRESIZE_MAP(CDialogConf)
		DLGRESIZE_CONTROL(IDC_CHECK_PSEUDO_TRANSPARENT, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_CHECK_GRABFOCUS, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_IMPORT, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_EXPORT, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_RESET_CURRENT, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_RESET_DEFAULT, DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_EDIT, DLSZ_SIZE_X | DLSZ_SIZE_Y)
		DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_X | DLSZ_MOVE_Y)  
		DLGRESIZE_CONTROL(IDAPPLY, DLSZ_MOVE_X | DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X | DLSZ_MOVE_Y)
		DLGRESIZE_CONTROL(IDC_STATIC_GUID, DLSZ_SIZE_X | DLSZ_MOVE_Y)
	END_DLGRESIZE_MAP()

public:
	void OnFinalMessage(HWND hWnd);
	LRESULT OnInitDialog(HWND hwndFocus, LPARAM lParam);
	LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnScriptEngineCbnSelEndOk(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnResetDefault(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnResetCurrent(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnImport(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnExport(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnNotify(int idCtrl, LPNMHDR pnmh);
	LRESULT OnNCDestroy();
	LRESULT OnScenChange(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	LRESULT OnUmDialogStyleReload(UINT uMsg, WPARAM wParam, LPARAM lParam);
	LRESULT OnCheckPseudoTransparentBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl);
};
