// DlgNwSt.cpp : implementation file
//

#include "stdafx.h"

#include "DlgNwSt.hpp"

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

#define M_BtNormal()		( (CButton*)GetDlgItem( ID_RB_NORMAL ) )
#define M_BtTransition()	( (CButton*)GetDlgItem( ID_RB_TRANSITIONAL ) )
#define M_EditName()		( (CEdit*)  GetDlgItem( IDC_EDIT_TEXT ) )

/////////////////////////////////////////////////////////////////////////////
// CDlgNewState dialog


CDlgNewState::CDlgNewState(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgNewState::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgNewState)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	csName = "";
	bNormal = TRUE;
}


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


BEGIN_MESSAGE_MAP(CDlgNewState, CDialog)
	//{{AFX_MSG_MAP(CDlgNewState)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgNewState message handlers

void CDlgNewState::OnOK()
{
	// TODO: Add extra validation here
	M_EditName() -> GetWindowText( csName );
    if( !csName.IsEmpty() )
    {
	    bNormal = ( M_BtNormal() -> GetCheck() ? TRUE : FALSE );
	    CDialog::OnOK();
    }
}

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

    CRect oRect;
    CSize oScreenSize( GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ) ) ;

    GetClientRect(&oRect);
    oRect += m_xPoint;
    // dialog must be in screen
    if ( oRect . right >= oScreenSize . cx )
    {
        oRect . OffsetRect ( -(oRect . right - oScreenSize . cx + 10), 0 );
    }
    if ( oRect . bottom >= oScreenSize . cy )
    {
        oRect . OffsetRect ( 0, -(oRect . bottom - oScreenSize . cy + 10) );
    }
    MoveWindow( &oRect ) ;

	M_EditName() -> SetWindowText( csName );
	M_BtNormal() -> SetCheck( bNormal );
	M_BtTransition() -> SetCheck( !bNormal );

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

void CDlgNewState::SetPos(POINT *_pPoint)
{
    memcpy ( &m_xPoint, _pPoint, sizeof POINT ) ;
}
