// ChDataDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Client.h"
#include "ChDataDlg.h"
#include "ClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChDataDlg dialog


CChDataDlg::CChDataDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CChDataDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChDataDlg)
	m_Email = _T("");
	m_Nickname = _T("");
	m_Pass = _T("");
	m_bEmail = FALSE;
	m_bNickname = FALSE;
	m_bPass = FALSE;
	//}}AFX_DATA_INIT
}


void CChDataDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChDataDlg)
	DDX_Text(pDX, IDC_EDIT_EMAIL, m_Email);
	DDX_Text(pDX, IDC_EDIT_NICKNAME, m_Nickname);
	DDX_Text(pDX, IDC_EDIT_PASS, m_Pass);
	DDX_Check(pDX, IDC_CHECK_EMAIL, m_bEmail);
	DDX_Check(pDX, IDC_CHECK_NICKNAME, m_bNickname);
	DDX_Check(pDX, IDC_CHECK_PASS, m_bPass);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChDataDlg, CDialog)
	//{{AFX_MSG_MAP(CChDataDlg)
	ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnButtonChange)
	ON_BN_CLICKED(IDC_CHECK_EMAIL, OnCheckEmail)
	ON_BN_CLICKED(IDC_CHECK_NICKNAME, OnCheckNickname)
	ON_BN_CLICKED(IDC_CHECK_PASS, OnCheckPass)
	ON_WM_CTLCOLOR()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChDataDlg message handlers

//******************************************************
void CChDataDlg::SetParent(CClientDlg *pParent)
{
	m_pParent = pParent;
}
//******************************************************

void CChDataDlg::OnButtonChange() 
{
	// TODO: Add your control notification handler code here
//******************************************************
	UpdateData(TRUE);
	/*if(m_bEmail) {
		m_Send = "<EDITMAIL>" + m_Email + "</EDITMAIL>";
		m_pParent->OnSend(m_Send);
	}
	if(m_bNickname) {
		m_Send = "<EDITNICK>" + m_Nickname + "</EDITNICK>";
		m_pParent->OnSend(m_Send);
	}
	if(m_bPass) {
		m_Send = "<EDITPWD>" + m_Pass + "</EDITPWD>";
		m_pParent->OnSend(m_Send);
	}*/
	EndDialog(IDOK);
//******************************************************
}

BOOL CChDataDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

//**************************************************************
	CEdit* pEditEmail = (CEdit*) GetDlgItem(IDC_EDIT_EMAIL);
	CEdit* pEditPass = (CEdit*) GetDlgItem(IDC_EDIT_PASS);
	CEdit* pEditNick = (CEdit*) GetDlgItem(IDC_EDIT_NICKNAME);
	POSITION pos;
	SUserData* pud;
	CString str;

	pEditEmail->EnableWindow(FALSE);
	pEditPass->EnableWindow(FALSE);
	pEditNick->EnableWindow(FALSE);

	for(pos = m_pParent->m_UDataList.GetHeadPosition(); pos != NULL;) {
		pud = (SUserData*) m_pParent->m_UDataList.GetNext(pos);
		if(!m_pParent->m_User.Compare(pud->s_User)) {
			m_Nickname =  pud->s_Nickname;
			m_Email = pud->s_Email;
		}
	}
	UpdateData(FALSE);

//**************************************************************

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CChDataDlg::OnCheckEmail() 
{
	// TODO: Add your control notification handler code here
//**************************************************************
	UpdateData(TRUE);
	CEdit* pEditEmail = (CEdit*) GetDlgItem(IDC_EDIT_EMAIL);
	pEditEmail->EnableWindow(m_bEmail);
//**************************************************************
}

void CChDataDlg::OnCheckNickname() 
{
	// TODO: Add your control notification handler code here
//**************************************************************
	UpdateData(TRUE);
	CEdit* pEditNick = (CEdit*) GetDlgItem(IDC_EDIT_NICKNAME);
	pEditNick->EnableWindow(m_bNickname);
//**************************************************************
}

void CChDataDlg::OnCheckPass() 
{
	// TODO: Add your control notification handler code here
//**************************************************************
	UpdateData(TRUE);
	CEdit* pEditPass = (CEdit*) GetDlgItem(IDC_EDIT_PASS);
	pEditPass->EnableWindow(m_bPass);
//**************************************************************
}

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

HBRUSH CChDataDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	if (mBitmap.GetSafeHandle()!=NULL) 
	{ 
		switch (nCtlColor) 
		{ 
		case CTLCOLOR_STATIC:
			pDC->SetBkMode (TRANSPARENT); 
			return (HBRUSH) mHollowBrush.m_hObject; 
			break; 
		default: 
			HBRUSH hbr = CDialog::OnCtlColor (pDC, pWnd, nCtlColor); 
			return hbr ; 
			break; 
		} 
	}
	else 
	{ 
		HBRUSH hbr = CDialog::OnCtlColor (pDC, pWnd, nCtlColor); 
		return hbr; 
	} 
}

BOOL CChDataDlg::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	if (mBitmap.m_hObject!=NULL) 
	{ 
		CDC MemDC; 
		BITMAP bm; 
		CRect Rect;
		int x=0, y=0; 
		GetClientRect (&Rect); 
		mBitmap.GetObject (sizeof(BITMAP),&bm); 
		MemDC.CreateCompatibleDC(pDC); 
		CBitmap* pOldBitmap=MemDC.SelectObject(&mBitmap); 
		if (mType==BITMAP_CENTER) 
		{ 
			CDialog::OnEraseBkgnd(pDC); 
			x= (Rect.Width()-bm.bmWidth) /2; 
			y= (Rect.Height()-bm.bmHeight) /2; 
			pDC->BitBlt (x,y,bm.bmWidth,bm.bmHeight, &MemDC, 0, 0, SRCCOPY);
		} 
		else 
		{ 
			while (y<Rect.Height ()) 
			{ 
				while (x<Rect.Width ()) 
				{ 
					pDC->BitBlt (x,y,bm.bmWidth,bm.bmHeight, &MemDC,0,0,SRCCOPY ); 
					x=x+bm.bmWidth; 
				} 
				x=0; 
				y=y+bm.bmHeight; 
			} 
		} 
		MemDC.SelectObject (pOldBitmap);  
		return TRUE; 
	} 
	else 
		return CDialog::OnEraseBkgnd (pDC); 
}

void CChDataDlg::SetBitmap (UINT ResID, int Type) 

{ 
	mBitmap.DeleteObject();
	mBitmap.LoadBitmap(ResID);
	mType=Type;

}
