// MenuTitleSetting_Dlg.cpp : 实现文件
//

#include "stdafx.h"
#include "CombineSubjectDrawTest.h"
#include "MenuTitleSetting_Dlg.h"
#include "afxdialogex.h"

#include "PublicObj.h"


// CMenuTitleSetting_Dlg 对话框

IMPLEMENT_DYNAMIC(CMenuTitleSetting_Dlg, CDialogEx)

CMenuTitleSetting_Dlg::CMenuTitleSetting_Dlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG_CAPTION, pParent)
	 
	, m_nTitleHeight(0)
	, m_strFontDetail(_T(""))
	, m_nShowPos(0)
{
	m_pControl = NULL;
}

CMenuTitleSetting_Dlg::~CMenuTitleSetting_Dlg()
{
}

void CMenuTitleSetting_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);

	DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nTitleHeight);
	DDX_Text(pDX, IDC_EDIT_FONT, m_strFontDetail);
	DDX_Radio(pDX, IDC_RADIO_POS, m_nShowPos);
}


BEGIN_MESSAGE_MAP(CMenuTitleSetting_Dlg, CDialogEx)
	ON_BN_CLICKED(IDC_CHECK_ENABLE, &CMenuTitleSetting_Dlg::OnBnClickedCheckEnable)
	ON_EN_CHANGE(IDC_EDIT_TITLE, &CMenuTitleSetting_Dlg::OnEnChangeEditTitle)
	ON_BN_CLICKED(IDC_RADIO_POS, &CMenuTitleSetting_Dlg::OnBnClickedRadioPos)
	ON_BN_CLICKED(IDC_RADIO2, &CMenuTitleSetting_Dlg::OnBnClickedRadio2)
	ON_EN_CHANGE(IDC_EDIT_HEIGHT, &CMenuTitleSetting_Dlg::OnEnChangeEditHeight)
	ON_BN_CLICKED(IDC_MFCCOLORBUTTON_BACK, &CMenuTitleSetting_Dlg::OnBnClickedMfccolorbuttonBack)
	ON_BN_CLICKED(IDC_MFCCOLORBUTTON_TEXT, &CMenuTitleSetting_Dlg::OnBnClickedMfccolorbuttonText)
	ON_BN_CLICKED(IDOK, &CMenuTitleSetting_Dlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_FONT, &CMenuTitleSetting_Dlg::OnBnClickedButtonFont)
END_MESSAGE_MAP()


// CMenuTitleSetting_Dlg 消息处理程序


BOOL CMenuTitleSetting_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();


	BOOL bEnable = m_pControl->GetControlInfoStatus();
	CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK_ENABLE);
	pBtn->SetCheck(bEnable);
	OnBnClickedCheckEnable();


	//
	std::string _titleString;
	m_pControl->GetControlInfo(_titleString);
	std::wstring _wtitleString;
	CPublicObj::Ansi2Unicode(_titleString, _wtitleString);
	CString strTitle(_wtitleString.c_str());
	GetDlgItem(IDC_EDIT_TITLE)->SetWindowText(strTitle);

	BOOL bTop = m_pControl->ContrlInfoPosIsTop();
	if (bTop == TRUE)
		m_nShowPos = 0;
	else
		m_nShowPos = 1;

	m_nTitleHeight = m_pControl->GetControlInfoHeight();

	
	COLORREF _color;
	m_pControl->GetControlInfoBackColor(_color);
	CMFCColorButton * pColorBtn = (CMFCColorButton*)GetDlgItem(IDC_MFCCOLORBUTTON_BACK);
	pColorBtn->SetColor(_color);

	m_pControl->GetControlInfoTextColor(_color);
	pColorBtn = (CMFCColorButton*)GetDlgItem(IDC_MFCCOLORBUTTON_TEXT);
	pColorBtn->SetColor(_color);

 
	int     nFontSize;
	
	m_pControl->GetControlInfoFont(_titleString);
	CPublicObj::Ansi2Unicode(_titleString, _wtitleString);
	 
	m_pControl->GetControlInfoFontSize(nFontSize);
	m_strFontDetail.Format(_T("%s:%d"), _wtitleString.c_str(), nFontSize);

	
	UpdateData(FALSE);


	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CMenuTitleSetting_Dlg::OnBnClickedCheckEnable()
{
	CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK_ENABLE);
	BOOL bEnable = pBtn->GetCheck();
	GetDlgItem(IDC_EDIT_TITLE)->EnableWindow(bEnable);
	GetDlgItem(IDC_RADIO_POS)->EnableWindow(bEnable);
	GetDlgItem(IDC_RADIO2)->EnableWindow(bEnable);
	GetDlgItem(IDC_EDIT_HEIGHT)->EnableWindow(bEnable);
	GetDlgItem(IDC_MFCCOLORBUTTON_BACK)->EnableWindow(bEnable);
	GetDlgItem(IDC_MFCCOLORBUTTON_TEXT)->EnableWindow(bEnable);
	GetDlgItem(IDC_BUTTON_FONT)->EnableWindow(bEnable);
	m_pControl->SetControlInfoStatus(bEnable);
}


void CMenuTitleSetting_Dlg::OnEnChangeEditTitle()
{
	CString strInfo;
	GetDlgItem(IDC_EDIT_TITLE)->GetWindowText(strInfo);
#ifdef  _UNICODE
	std::string  _ansi_text;
	CPublicObj::Unicode2Ansi(std::wstring(strInfo.GetBuffer()), _ansi_text);
	strInfo.ReleaseBuffer();
	m_pControl->SetControlInfo(_ansi_text);
#else
	m_pControl->SetControlInfo(strInfo.GetBuffer());
	strInfo.ReleaseBuffer();
#endif //  _UNICODE

	
}


void CMenuTitleSetting_Dlg::OnBnClickedRadioPos()
{
	m_pControl->SetControlInfoShowAtTop(TRUE);
}


void CMenuTitleSetting_Dlg::OnBnClickedRadio2()
{
	m_pControl->SetControlInfoShowAtTop(FALSE);
}


void CMenuTitleSetting_Dlg::OnEnChangeEditHeight()
{
	// TODO:  如果该控件是 RICHEDIT 控件，它将不
	// 发送此通知，除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask()，
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	CString strHeight;
	GetDlgItem(IDC_EDIT_HEIGHT)->GetWindowText(strHeight);
	//  20-----------200
	int nHeight = 0;
#ifdef _UNICODE
	nHeight = _wtol(strHeight);
#else
	nHeight = atol(strHeight);
#endif
	if (nHeight < 20)
		nHeight = 20;
	if (nHeight > 200)
		nHeight = 200;
	m_pControl->SetControlInfoHeight(nHeight);


	
}


void CMenuTitleSetting_Dlg::OnBnClickedMfccolorbuttonBack()
{
	CMFCColorButton * pBtn = (CMFCColorButton*)GetDlgItem(IDC_MFCCOLORBUTTON_BACK);
	m_pControl->SetControlInfoBackColor(pBtn->GetColor());
}


void CMenuTitleSetting_Dlg::OnBnClickedMfccolorbuttonText()
{
	CMFCColorButton * pBtn = (CMFCColorButton*)GetDlgItem(IDC_MFCCOLORBUTTON_TEXT);
	m_pControl->SetControlInfoTextColor(pBtn->GetColor());
}


void CMenuTitleSetting_Dlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnOK();
}


void CMenuTitleSetting_Dlg::OnBnClickedButtonFont()
{
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));

	std::string _titleString;
	m_pControl->GetControlInfoFont(_titleString);

#ifdef _UNICODE
	std::wstring _wtitleString;
	CPublicObj::Ansi2Unicode(_titleString, _wtitleString);
	_tcscpy_s(lf.lfFaceName, LF_FACESIZE, _wtitleString.c_str());
#endif
	int nSize = 20;
	m_pControl->GetControlInfoFontSize(nSize);
	lf.lfHeight = nSize;
	CFontDialog dlg(&lf);
	if (IDOK == dlg.DoModal())
	{
#ifdef _UNICODE
		_wtitleString = dlg.m_cf.lpLogFont->lfFaceName;
		CPublicObj::Unicode2Ansi(_wtitleString, _titleString);
#else
		_titleString = dlg.m_cf.lpLogFont->lfFaceName;
#endif
		m_pControl->SetControlInfoFont(_titleString);
		m_pControl->SetControlInfoFontSize(dlg.m_cf.lpLogFont->lfHeight);

	}







}
