#include "StdAfx.h"

#include "SampleDlg1.h"
#include "PluginResource.h"

// dialog control IDs
#define		kDialogID             12000
#define		kOK                   1
#define		kCancel               2
#define		kEditFieldsGrp        5
#define		kIntegerEdit          6
#define		kRealEdit             7
#define		kTextEdit             8
#define		kSeparator            9
#define		kCenStaticText        10
#define		kCommonCtrlGrp        11
#define		kCheckBox             12
#define		kThreeStateCheckBox   13
#define		kRadioGrp             14
#define		kStaticText           15
#define		kRadio1               16
#define		kRadio2               17
#define		kRadio3               18
#define		kGetDataButton        19


using namespace UI;

EVENT_DISPATCH_MAP_BEGIN( CSampleDlg1 );
ADD_DISPATCH_EVENT( kTextEdit, OnTextEditControl );
ADD_DISPATCH_EVENT( kGetDataButton, OnGetDataButton );
EVENT_DISPATCH_MAP_END;

CSampleDlg1::CSampleDlg1()
{
	fIntegerEdit	= 11;
	fRealEdit		= 11.11;
	fTextEdit		= "some text from DDX";
	fCheckBox		= true;
	fRadio1			= false;
	fRadio2			= true;
	fRadio3			= false;

}

CSampleDlg1::~CSampleDlg1()
{
}

bool CSampleDlg1::CreateDialogLayout()
{
	return this->CreateDialogLayoutFromRsrc( kDialogID );
}

void CSampleDlg1::OnInizializeContent()
{
	VWDialog::OnInizializeContent();

	// TODO: Fill up your dialog controls here
}

void CSampleDlg1::OnDDXInitialize()
{
	this->AddDDX_EditInteger( kIntegerEdit, & fIntegerEdit );
	this->AddDDX_EditReal( kRealEdit, & fRealEdit, VWEditRealCtrl::kEditControlDimension );
	this->AddDDX_EditText( kTextEdit, & fTextEdit, false );
	this->AddDDX_CheckButton( kCheckBox, & fCheckBox );
	this->AddDDX_RadioButton( kRadio1, & fRadio1 );
	this->AddDDX_RadioButton( kRadio2, & fRadio2 );
	this->AddDDX_RadioButton( kRadio3, & fRadio3 );

	this->AddDDXValidator( kIntegerEdit, new CDDXValidator_NumberInRange( "Invalid Integer Value.", "Value should be in\na number range [0-10]", 0, 10 ) );
	this->AddDDXValidator( kRealEdit, new CDDXValidator_RealInRange( "Invalid Real Value.", "Value should be\nnegative real value", 0, true, false ) );

}

void CSampleDlg1::OnUpdateUI()
{
	VWDialog::OnUpdateUI();

	// this is the place where you manage enable/disable or visible/invisible
	// state of your controls
	this->EnableControl( kIntegerEdit, fRadio2 );
	this->EnableControl( kRealEdit, fRadio2 );
	this->EnableControl( kTextEdit, fRadio2 );

	this->EnableControl( kOK, fRadio1 || fRadio2 );
}

void CSampleDlg1::OnTextEditControl(long controlID, VWDialogEventArgs& eventArgs)
{
	VWStaticTextCtrl*	pStaticText	= this->GetStaticTextCtrlByID( kStaticText );
	pStaticText->SetControlText( fTextEdit );

	VWStaticTextCtrl*	pCenteredStaticText	= this->GetStaticTextCtrlByID( kCenStaticText );
	pCenteredStaticText->SetControlText( fTextEdit );
}

void CSampleDlg1::OnGetDataButton(long controlID, VWDialogEventArgs& eventArgs)
{
	TXString	text;
	text.Format(	"integer edit=%d   "
					"real edit=%f   "
					"text edit=\"%s\"   "
					"check box=%s   "
					"radio1=%s   "
					"radio2=%s   "
					"radio3=%s",
					fIntegerEdit,
					fRealEdit,
					(const char*) fTextEdit,
					fCheckBox ? "TRUE" : "FALSE",
					fRadio1 ? "TRUE" : "FALSE",
					fRadio2 ? "TRUE" : "FALSE",
					fRadio3 ? "TRUE" : "FALSE" );

	VWDialog::AlertInform( "Auto DDX variable values", text );
}


