/*=========================================================================
* 
* EDTdUser.cpp :  User - Implementation file
* 
*
* Version			1.0
* Creation date		
* Revision date
*
* Shaitan
*=======================================================================*/

#include "stdafx.h"
#ifdef ACTIVE_EDITOR
#include "acp_base.h"

#include "itf/CPAdStat.hpp"
#include "itf/CPAInter.hpp"
#include "itf/CPASpec.hpp"
#include "itf/FrmGest.hpp"

//#################################################################################
// CPA_DialogStatus dialog
//#################################################################################

/*----------------------------------------
----------------------------------------*/
CPA_DialogStatus::CPA_DialogStatus (CWnd* pParent)
	: CDialog (CPA_DialogStatus::IDD, &g_oBaseFrame)
{
	//{{AFX_DATA_INIT(CPA_DialogStatus)
	//}}AFX_DATA_INIT
}



/*----------------------------------------
----------------------------------------*/
void CPA_DialogStatus::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_DialogStatus)
	DDX_Control(pDX, CPA_IDC_GRAPHIST, m_cGraphic);
	DDX_Control(pDX, CPA_IDC_DESIGNER, m_cDesign);
	DDX_Control(pDX, CPA_IDC_MANAGER, m_cManager);
	DDX_Control(pDX, CPA_IDC_SAVESTATUS, m_cSaveStatus);
	DDX_Control(pDX, IDOK, m_cOK);
	//}}AFX_DATA_MAP
}


/*----------------------------------------
----------------------------------------*/
BEGIN_MESSAGE_MAP(CPA_DialogStatus, CDialog)
	//{{AFX_MSG_MAP(CPA_DialogStatus)
	ON_BN_CLICKED(CPA_IDC_SAVESTATUS, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//#################################################################################
// CPA_DialogStatus Inits
//#################################################################################

/*===========================================================================
*		Description:	Init dialog
*		Creation date:	
*		Author:			Shaitan
*---------------------------------------------------------------------------
*		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*=========================================================================*/
void CPA_DialogStatus::fn_vDoDialog (CPA_SpecificInterface *pEditor, BOOL bCanUpdate)
{
	// create the dialog
	m_pEditor = pEditor;
	m_bCanUpdate = bCanUpdate;
	DoModal();
}


//#################################################################################
// CPA_DialogStatus message handlers
//#################################################################################

/*----------------------------------------
----------------------------------------*/
BOOL CPA_DialogStatus::OnInitDialog (void)
{
	tdeUserStatus eInitStatus;
	
	// Create the dialog
	CDialog::OnInitDialog();
	
	eInitStatus = m_pEditor->GetUserStatus();
	if (eInitStatus == E_us_NoStatus)
		eInitStatus = E_us_StatusDesign;
	
	// init mode
	m_cGraphic.SetCheck(eInitStatus == E_us_StatusGraphic);
	m_cDesign.SetCheck(eInitStatus == E_us_StatusDesign);
	m_cManager.SetCheck(eInitStatus == E_us_StatusAll);

	// init controls
	m_cOK.SetWindowText(m_bCanUpdate ? "OK" : "Cancel");

	return TRUE;
}


/*----------------------------------------
----------------------------------------*/
void CPA_DialogStatus::OnSave (void)
{
	// save user mode
	if (m_cGraphic.GetCheck())
		m_pEditor->fn_vSaveUserStatus(E_us_StatusGraphic);
	else if (m_cDesign.GetCheck())
		m_pEditor->fn_vSaveUserStatus(E_us_StatusDesign);
	else
		m_pEditor->fn_vSaveUserStatus(E_us_StatusAll);

	// close dialog
	if (!m_bCanUpdate)
		CDialog::OnOK();
}

/*----------------------------------------
----------------------------------------*/
void CPA_DialogStatus::OnOK (void)
{
	if (m_bCanUpdate)
	{
		// get user mode
		if (m_cGraphic.GetCheck())
			m_pEditor->SetUserStatus(E_us_StatusGraphic);
		else if (m_cDesign.GetCheck())
			m_pEditor->SetUserStatus(E_us_StatusDesign);
		else
			m_pEditor->SetUserStatus(E_us_StatusAll);
	}
	// close dialog
	CDialog::OnOK();
}

/*----------------------------------------
----------------------------------------*/
void CPA_DialogStatus::OnCancel (void)
{
	if (m_bCanUpdate)
	{
		// get user mode
		if (m_cGraphic.GetCheck())
			m_pEditor->SetUserStatus(E_us_StatusGraphic);
		else if (m_cDesign.GetCheck())
			m_pEditor->SetUserStatus(E_us_StatusDesign);
		else
			m_pEditor->SetUserStatus(E_us_StatusAll);
	}
	// close dialog
	CDialog::OnCancel();
}

#endif // ACTIVE_EDITOR