#include "stdafx.h"
#include "ArticleSubmitter.h"
#include "SetupDlg.h"


// CSetupDlg dialog

IMPLEMENT_DYNAMIC(CSetupDlg, CDialog)
CSetupDlg::CSetupDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSetupDlg::IDD, pParent)
	, mFirstName(_T(""))
	, mLastName(_T(""))
	, mFullName(_T(""))
	, mWebsite(_T(""))
	, mEmail(_T(""))
	, mWebsiteTitle(_T(""))
	, mCompany(_T(""))
	, mBio(_T(""))
	, mAddress(_T(""))
	, mAddress2(_T(""))
	, mCity(_T(""))
	, mState(_T(""))
	, mZip(_T(""))
	, mPhone(_T(""))
	, mUsername(_T(""))
	, mPassword(_T(""))
	, mCountry(_T(""))
{
	mSizeInited = 0;
}

CSetupDlg::~CSetupDlg()
{
}

void CSetupDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_FIRSTNAME, mFirstName);
	DDX_Text(pDX, IDC_LASTNAME, mLastName);
	DDX_Text(pDX, IDC_FULLNAME, mFullName);
	DDX_Text(pDX, IDC_WEBSITEURL, mWebsite);
	DDX_Text(pDX, IDC_AUTHOREMAIL, mEmail);
	DDX_Text(pDX, IDC_WEBSITETITLE, mWebsiteTitle);
	DDX_Text(pDX, IDC_COMPANY, mCompany);
	DDX_Text(pDX, IDC_BIO, mBio);
	DDX_Control(pDX, IDC_FIRSTNAME, mFirstNameEdit);
	DDX_Control(pDX, IDC_LASTNAME, mLastNameEdit);
	DDX_Control(pDX, IDC_FULLNAME, mFullNameEdit);
	DDX_Control(pDX, IDC_WEBSITEURL, mWebsiteEdit);
	DDX_Control(pDX, IDC_AUTHOREMAIL, mEmailEdit);
	DDX_Control(pDX, IDC_WEBSITETITLE, mWebsiteTitleEdit);
	DDX_Control(pDX, IDC_COMPANY, mCompanyEdit);
	DDX_Control(pDX, IDC_BIO, mBioBoxEdit);
	DDX_Control(pDX, IDC_FIRSTNAMESTATIC, mFirstNameStatic);
	DDX_Control(pDX, IDC_FULLNAMESTATIC, mFullNameStatic);
	DDX_Control(pDX, IDC_LASTNAMESTATIC, mLastNameStatic);
	DDX_Control(pDX, IDC_WEBSITESTATIC, mWebsiteStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC, mEmailStatic);
	DDX_Control(pDX, IDC_WEBSITETITLESTATIC, mWebsiteTitleStatic);
	DDX_Control(pDX, IDC_COMPANYSTATIC, mCompanyStatic);
	DDX_Control(pDX, IDC_BIOSTATIC, mBioBoxStatic);
	DDX_Control(pDX, IDOK, mSaveButton);
	DDX_Control(pDX, IDC_EMAILSTATIC2, mAddressStatic);
	DDX_Control(pDX, IDC_WEBSITETITLESTATIC2, mAddress2Static);
	DDX_Control(pDX, IDC_EMAILSTATIC3, mCityStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC4, mStateStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC5, mZipStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC6, mPhoneStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC7, mUsernameStatic);
	DDX_Control(pDX, IDC_EMAILSTATIC8, mPasswordStatic);
	DDX_Control(pDX, IDC_ADDRESS, mAddressEdit);
	DDX_Control(pDX, IDC_ADDRESS2, mAddress2Edit);
	DDX_Control(pDX, IDC_CITY, mCityEdit);
	DDX_Control(pDX, IDC_STATE, mStateEdit);
	DDX_Control(pDX, IDC_ZIP, mZipEdit);
	DDX_Control(pDX, IDC_PHONE, mPhoneEdit);
	DDX_Control(pDX, IDC_USER, mUsernameEdit);
	DDX_Control(pDX, IDC_PASS, mPasswordEdit);
	DDX_Text(pDX, IDC_ADDRESS, mAddress);
	DDX_Text(pDX, IDC_ADDRESS2, mAddress2);
	DDX_Text(pDX, IDC_CITY, mCity);
	DDX_Text(pDX, IDC_STATE, mState);
	DDX_Text(pDX, IDC_ZIP, mZip);
	DDX_Text(pDX, IDC_PHONE, mPhone);
	DDX_Text(pDX, IDC_USER, mUsername);
	DDX_Text(pDX, IDC_PASS, mPassword);
	DDX_Text(pDX, IDC_COUNTRY, mCountry);
	DDX_Control(pDX, IDC_COUNTRY, mCountryEdit);
	DDX_Control(pDX, IDC_WEBSITETITLESTATIC3, mCountryStatic);
}


BEGIN_MESSAGE_MAP(CSetupDlg, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_WM_SIZE()
END_MESSAGE_MAP()


// CSetupDlg message handlers

void CSetupDlg::OnBnClickedOk()
{
	UpdateData(1);
	theApp.mManager.mFirstName = mFirstName;
	theApp.mManager.mLastName = mLastName;
	theApp.mManager.mFullName = mFullName;
	theApp.mManager.mWebsite = mWebsite;
	theApp.mManager.mEmail = mEmail;
	theApp.mManager.mWebsiteTitle = mWebsiteTitle;
	theApp.mManager.mCompany = mCompany;
	theApp.mManager.mBio = mBio;
	theApp.mManager.mAddress = mAddress;
	theApp.mManager.mAddress2 = mAddress2;
	theApp.mManager.mCity = mCity;
	theApp.mManager.mState = mState;
	theApp.mManager.mZipCode = mZip;
	theApp.mManager.mPhone = mPhone;
	theApp.mManager.mUsername = mUsername;
	theApp.mManager.mPassword = mPassword;
	theApp.mManager.mCountry = mCountry;


	theApp.mManager.Save();
}

void CSetupDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);
	return;

	if (!mSizeInited)
		return;

	RECT r1;
	mFirstNameStatic.GetWindowRect( &r1 );
	int x = 15;
	int y = 10;
	int w = 100;
	int h = r1.bottom - r1.top;
	mFirstNameStatic.MoveWindow( x, y+5, w, h );

	int xx = 120;
	w = 120;
	h = 20;
	mFirstNameEdit.MoveWindow( xx, y, w, h );

	xx += w + 20;
	mLastNameStatic.GetWindowRect( &r1 );
	w = 50;
	h = r1.bottom - r1.top;
	mLastNameStatic.MoveWindow( xx, y + 5, w, h );

	xx += w + 5;
	w = 120;
	h = 20;
	mLastNameEdit.MoveWindow( xx, y, w, h );

//bio box
	//bio box
	mBioBoxStatic.GetWindowRect( &r1 );
	x = xx + w + 20;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mBioBoxStatic.MoveWindow( x, y+5, w, h );

	xx = x + w + 5;
	w = 175;
	h = 100;
	mBioBoxEdit.MoveWindow( xx, y, w, h );


	//fullname
	mFullNameStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mFullNameStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mFullNameEdit.MoveWindow( xx, y, w, h );

	//website
	mWebsiteStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mWebsiteStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mWebsiteEdit.MoveWindow( xx, y, w, h );

	//email
	mEmailStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mEmailStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mEmailEdit.MoveWindow( xx, y, w, h );


	//website title
	mWebsiteTitleStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mWebsiteTitleStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mWebsiteTitleEdit.MoveWindow( xx, y, w, h );

	//company
	mCompanyStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mCompanyStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mCompanyEdit.MoveWindow( xx, y, w, h );

	//coutnry
	mCountryStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mCountryStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mCountryEdit.MoveWindow( xx, y, w, h );


	//address
	mAddressStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mAddressStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mAddressEdit.MoveWindow( xx, y, w, h );

	//address 2
	mAddress2Static.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mAddress2Static.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 315;
	h = 20;
	mAddress2Edit.MoveWindow( xx, y, w, h );


	//city
	mCityStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mCityStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 120;
	h = 20;
	mCityEdit.MoveWindow( xx, y, w, h );

	//state
	mStateStatic.GetWindowRect( &r1 );
	x = 260;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mStateStatic.MoveWindow( x, y+5, w, h );

	xx = x + 55;
	w = 120;
	h = 20;
	mStateEdit.MoveWindow( xx, y, w, h );

	//zip
	mZipStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mZipStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 120;
	h = 20;
	mZipEdit.MoveWindow( xx, y, w, h );

	//phone
	mPhoneStatic.GetWindowRect( &r1 );
	x = 260;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mPhoneStatic.MoveWindow( x, y+5, w, h );

	xx = x + 55;
	w = 120;
	h = 20;
	mPhoneEdit.MoveWindow( xx, y, w, h );


	//username
	mUsernameStatic.GetWindowRect( &r1 );
	x = 15;
	y += 25;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mUsernameStatic.MoveWindow( x, y+5, w, h );

	xx = 120;
	w = 120;
	h = 20;
	mUsernameEdit.MoveWindow( xx, y, w, h );

	//password
	mPasswordStatic.GetWindowRect( &r1 );
	x = 260;
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mPasswordStatic.MoveWindow( x, y+5, w, h );

	xx = x + 55;
	w = 120;
	h = 20;
	mPasswordEdit.MoveWindow( xx, y, w, h );



	//save button
	mSaveButton.GetWindowRect( &r1 );
	xx += w + 10;
	y += h;
	y -= (r1.bottom - r1.top);
	w = r1.right - r1.left;
	h = r1.bottom - r1.top;
	mSaveButton.MoveWindow( xx, y, w, h );
}

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

	mSizeInited = 1;
	return TRUE;
}
