// EDACDgCp.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "_AInterf.hpp"
#include "IncGAM.h"

#include "EDACDgCp.hpp"

#include "EDACDgIf.hpp"

//External Modules
#include "IncTUT.h"
//End of External Modules

#undef CPA_WANTS_IMPORT
#undef CPA_EXPORT
#define CPA_WANTS_EXPORT
    #include "_Actors.hpp"
#undef CPA_WANTS_EXPORT
#define CPA_WANTS_IMPORT

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

/////////////////////////////////////////////////////////////////////////////
// EdActors_CopyDialog dialog

BEGIN_MESSAGE_MAP(EdActors_CopyDialog, CDialog)
	//{{AFX_MSG_MAP(EdActors_CopyDialog)
	ON_EN_CHANGE(IDC_EDIT_COPIES_NUMBER, OnChangeEditCopiesNumber)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//***************************************************************************
EdActors_CopyDialog::EdActors_CopyDialog(CPA_Actor *_pclSourceActor, CWnd* _pParent /*= NULL*/)
										: CDialog(EdActors_CopyDialog::IDD, _pParent)
{
	m_pclSourceActor = _pclSourceActor;

	m_hOldInstance = AfxGetResourceHandle();
	AfxSetResourceHandle(g_stActorEditorIdentity.hModule);

	//{{AFX_DATA_INIT(EdActors_CopyDialog)
	m_lCopiesNumber = 1;
	m_bAutoName = TRUE;
	//}}AFX_DATA_INIT

	//Computes copy name
	m_csNewName = _pclSourceActor->GetName() + "_Copy";
}

//***************************************************************************
//Destructor
EdActors_CopyDialog::~EdActors_CopyDialog()
{
	AfxSetResourceHandle(m_hOldInstance);
}

//***************************************************************************
void EdActors_CopyDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	//{{AFX_DATA_MAP(EdActors_CopyDialog)
	DDX_Text(pDX, IDC_EDIT_COPIES_NUMBER, m_lCopiesNumber);
	DDX_Text(pDX, IDC_EDIT_FOR_NAME, m_csNewName);
	DDX_Check(pDX, IDC_CHECK_NAME_AUTO, m_bAutoName);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// EdActors_CopyDialog message handlers

//***************************************************************************
BOOL EdActors_CopyDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//Changes Bitmap
	if ( m_pclSourceActor->m_fn_bIsAModel() )
	{
		m_cbBitmap.LoadBitmap(IDB_BITMAP_MODEL);
		((CStatic *)GetDlgItem(IDC_IMAGE_MODE))->SetBitmap(HBITMAP(m_cbBitmap));
	}

	((CSpinButtonCtrl *)GetDlgItem(IDC_SPIN))->SetRange(1, 50);
	
	OnChangeEditCopiesNumber();

	//////////////
	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControlID(IDC_EDIT_FOR_NAME, "OAc_CopyDialog_NameEdit", TUT_e_TextEdit);
	TUT_M_vRegisterControlID(IDC_EDIT_COPIES_NUMBER, "OAc_CopyDialog_CopiesNumberEdit", TUT_e_TextEdit);
	TUT_M_vRegisterControlID(IDC_SPIN, "OAc_CopyDialog_Spin", TUT_e_Spin);
	TUT_M_vRegisterControlID(IDC_CHECK_NAME_AUTO, "OAc_CopyDialog_AutoNameButton", TUT_e_Button);
	TUT_M_vRegisterControlID(IDOK, "OAc_CopyDialog_OKButton", TUT_e_Button);
	TUT_M_vRegisterControlID(IDCANCEL, "OAc_CopyDialog_CancelButton", TUT_e_Button);

	//End of Registers for TUT Module
	//////////////

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

//***************************************************************************
void EdActors_CopyDialog::OnDestroy() 
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControlID(IDC_EDIT_FOR_NAME);
	TUT_M_vUnregisterControlID(IDC_EDIT_COPIES_NUMBER);
	TUT_M_vUnregisterControlID(IDC_SPIN);
	TUT_M_vUnregisterControlID(IDC_CHECK_NAME_AUTO);
	TUT_M_vUnregisterControlID(IDOK);
	TUT_M_vUnregisterControlID(IDCANCEL);
	
	//End of UnRegisters for TUT Module
	//////////////
	
	CDialog::OnDestroy();
}

//***************************************************************************
void EdActors_CopyDialog::OnChangeEditCopiesNumber() 
{
//	UpdateData(TRUE);

//	GetDlgItem(IDC_CHECK_NAME_AUTO)->EnableWindow( m_lCopiesNumber > 1 );
}

//***************************************************************************
void EdActors_CopyDialog::OnOK() 
{
	UpdateData(TRUE);

	if ( m_lCopiesNumber < 1 )
		m_lCopiesNumber = 1;

	if ( m_csNewName.IsEmpty() )
	{
		CString csMessage = "You must chose a name, or press 'Cancel' !";
		EdActors_InformationDialog dial(&g_oBaseFrame, csMessage);
		dial.DoModal();
	}
	else
		CDialog::OnOK();
}

