// EdIRPrtB.cpp : implementation file
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRPrtB.hpp"

#include "ai_intf.hpp"

#include "IncTUT.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_PrintDialog dialog
/////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(CPA_EdIR_PrintDialog, CDialog)
	//{{AFX_MSG_MAP(CPA_EdIR_PrintDialog)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_CHANGE_FONT, OnButtonChangeFont)
	ON_BN_CLICKED(IDC_BUTTON_PREVIEW, OnButtonPrintPreview)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/**********************************************************************************/
CPA_EdIR_PrintDialog::CPA_EdIR_PrintDialog(CString csBehaviourListName,CString csFontName,long lFontSize,CWnd* pParent /*=NULL*/)
	: CDialog(CPA_EdIR_PrintDialog::IDD, &g_oBaseFrame)
{
	//{{AFX_DATA_INIT(CPA_EdIR_PrintDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_csBehaviourListName=csBehaviourListName;
	m_csFontName=csFontName;
	m_lFontSize=lFontSize;
	m_bIsPreview=FALSE;
	m_bCurrentBehaviour=TRUE;
	m_bAllBehaviours=FALSE;
	m_bAllIA=FALSE;
	m_bOneBehaviourOnAPage=FALSE;

	m_hOldInstance=AfxGetResourceHandle();
	AfxSetResourceHandle(g_stAIIdentity.hModule);
}

/**********************************************************************************/
CPA_EdIR_PrintDialog::~CPA_EdIR_PrintDialog()
{
	AfxSetResourceHandle(m_hOldInstance);
}

/**********************************************************************************/
void CPA_EdIR_PrintDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_EdIR_PrintDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_Print_Dialog message handlers

/**********************************************************************************/
BOOL CPA_EdIR_PrintDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//Sets font name
	GetDlgItem(IDC_STATIC_FONT_NAME)->SetWindowText(m_csFontName);

	//Sets Print Prefs
	((CButton *)GetDlgItem(IDC_RADIO_CURRENT_BEHAVIOUR))->SetCheck((m_bCurrentBehaviour)?1:0);
	((CButton *)GetDlgItem(IDC_RADIO_ALL_BEHAVIOURS))->SetCheck((m_bAllBehaviours)?1:0);
	((CButton *)GetDlgItem(IDC_RADIO_ALL_BEHAVIOURS))->SetWindowText(m_csBehaviourListName);
	((CButton *)GetDlgItem(IDC_RADIO_ALL_IA))->SetCheck((m_bAllIA)?1:0);

	((CButton *)GetDlgItem(IDC_CHECK_ONE_BEHAVIOUR_ON_PAGE))->SetCheck((m_bOneBehaviourOnAPage)?1:0);
	
	//////////////
	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControl(m_hWnd,"EdIR_PrintDlg_Window",TUT_e_Window);

	TUT_M_vRegisterControlID(IDC_STATIC_FONT_NAME,"EdIR_PrintDlg_FontName",TUT_e_TextEdit);
	TUT_M_vRegisterControlID(IDC_BUTTON_CHANGE_FONT,"EdIR_PrintDlg_ChangeFont",TUT_e_Button);
	
	TUT_M_vRegisterControlID(IDC_RADIO_CURRENT_BEHAVIOUR,"EdIR_PrintDlg_CheckCurrent",TUT_e_Button);
	TUT_M_vRegisterControlID(IDC_RADIO_ALL_BEHAVIOURS,"EdIR_PrintDlg_CheckAll",TUT_e_Button);
	TUT_M_vRegisterControlID(IDC_RADIO_ALL_IA,"EdIR_PrintDlg_CheckAllIA",TUT_e_Button);
	TUT_M_vRegisterControlID(IDC_CHECK_ONE_BEHAVIOUR_ON_PAGE,"EdIR_PrintDlg_CheckOneBehaviourOnPage",TUT_e_Button);
	
	TUT_M_vRegisterControlID(IDOK,"EdIR_PrintDlg_Print",TUT_e_Button);
	TUT_M_vRegisterControlID(IDC_BUTTON_PREVIEW,"EdIR_PrintDlg_PrintPriview",TUT_e_Button);
	TUT_M_vRegisterControlID(IDCANCEL,"EdIR_PrintDlg_Cancel",TUT_e_Button);
	//End of Register for TUT Module
	//////////////
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/**********************************************************************************/
void CPA_EdIR_PrintDialog::OnDestroy() 
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControl(m_hWnd);

	TUT_M_vUnregisterControlID(IDC_STATIC_FONT_NAME);
	TUT_M_vUnregisterControlID(IDC_BUTTON_CHANGE_FONT);

	TUT_M_vUnregisterControlID(IDC_RADIO_CURRENT_BEHAVIOUR);
	TUT_M_vUnregisterControlID(IDC_RADIO_ALL_BEHAVIOURS);
	TUT_M_vUnregisterControlID(IDC_RADIO_ALL_IA);
	TUT_M_vUnregisterControlID(IDC_CHECK_ONE_BEHAVIOUR_ON_PAGE);

	TUT_M_vUnregisterControlID(IDOK);
	TUT_M_vUnregisterControlID(IDC_BUTTON_PREVIEW);
	TUT_M_vUnregisterControlID(IDCANCEL);
	//End of UnRegister for TUT Module
	//////////////

	CDialog::OnDestroy();
}

/**********************************************************************************/
void CPA_EdIR_PrintDialog::OnButtonChangeFont() 
{
	//Gets font name
	GetDlgItem(IDC_STATIC_FONT_NAME)->GetWindowText(m_csFontName);

	//Inits params to call a CFontDialog box
	LOGFONT			lfFont;
	lfFont.lfHeight=m_lFontSize;
	lfFont.lfWidth=0;
	lfFont.lfEscapement=0;
	lfFont.lfOrientation=0;
	lfFont.lfWeight=FW_NORMAL;
	lfFont.lfItalic=FALSE;
	lfFont.lfUnderline=FALSE;
	lfFont.lfStrikeOut=FALSE;
	lfFont.lfCharSet=DEFAULT_CHARSET;
	lfFont.lfOutPrecision=OUT_STRING_PRECIS;
	lfFont.lfClipPrecision=CLIP_CHARACTER_PRECIS;
	lfFont.lfQuality=DEFAULT_QUALITY;
	lfFont.lfPitchAndFamily=DEFAULT_PITCH;
	strcpy(lfFont.lfFaceName,(char *)LPCTSTR(m_csFontName));

	CFontDialog	cfd(&lfFont);

	if(cfd.DoModal()==IDOK)
	{
		//Sets font name
		m_csFontName=cfd.GetFaceName();
		GetDlgItem(IDC_STATIC_FONT_NAME)->SetWindowText(m_csFontName);

		//Sets font size
		m_lFontSize=cfd.GetSize()/10;
	}
}

/**********************************************************************************/
void CPA_EdIR_PrintDialog::OnButtonPrintPreview() 
{
	m_bIsPreview=TRUE;
	
	OnOK();
}

/**********************************************************************************/
void CPA_EdIR_PrintDialog::OnOK() 
{
	//Gets font name
	GetDlgItem(IDC_STATIC_FONT_NAME)->GetWindowText(m_csFontName);

	//Gets Print Prefs
	m_bCurrentBehaviour=((CButton *)GetDlgItem(IDC_RADIO_CURRENT_BEHAVIOUR))->GetCheck();
	m_bAllBehaviours=((CButton *)GetDlgItem(IDC_RADIO_ALL_BEHAVIOURS))->GetCheck();
	m_bAllIA=((CButton *)GetDlgItem(IDC_RADIO_ALL_IA))->GetCheck();

	m_bOneBehaviourOnAPage=((CButton *)GetDlgItem(IDC_CHECK_ONE_BEHAVIOUR_ON_PAGE))->GetCheck();

	CDialog::OnOK();
}

#endif //D_ED_IR_ACTIVE
