// ComboView.cpp : implementation file
//

#include "stdafx.h"
#include "ComboView.h"


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

/////////////////////////////////////////////////////////////////////////////
// CComboView

IMPLEMENT_DYNCREATE(CComboView, CFormView)

CComboView::CComboView()
	: CFormView(CComboView::IDD)
{
	//{{AFX_DATA_INIT(CComboView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CComboView::~CComboView()
{
}

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


BEGIN_MESSAGE_MAP(CComboView, CFormView)
	//{{AFX_MSG_MAP(CComboView)
	ON_CBN_EDITCHANGE(IDC_NUMBER_COMBO, OnEditchangeNumberCombo)
	ON_CBN_SELCHANGE(IDC_NUMBER_COMBO, OnSelchangeNumberCombo)
	ON_CBN_SELCHANGE(IDC_SECOND_COMBO, OnSelchangeSecondCombo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComboView diagnostics

#ifdef _DEBUG
void CComboView::AssertValid() const
{
	CFormView::AssertValid();
}

void CComboView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CComboView message handlers


void CComboView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();

	CComboBox* pList = (CComboBox*)GetDlgItem(IDC_NUMBER_COMBO);
	
	char number_buffer[5];

	for (int i = 0; i < SCALE_STEP_COUNT; ++i)
	{
		itoa(SCALE_STEP[i], number_buffer, 10);
		pList->AddString(number_buffer);
	}

	pList = (CComboBox*)GetDlgItem(IDC_SECOND_COMBO);
	for ( i = 0; i < SCALES_COUNT; ++i)
	{
		pList->AddString(SCALES_TEXT[i]);
	}

	myParent->OnInitialUpdate();

}


void CComboView::OnEditchangeNumberCombo() 
{
	CComboBox* pList = (CComboBox*)GetDlgItem(IDC_NUMBER_COMBO);
	CString temp;
	int number;
	pList->GetWindowText(temp);
	number = atoi(temp);
	
	//
	// Register Change...
	//

	// TODO: Register Change


	//
	// It will ignore trailing letters but not leading letters.
	//
	if (number == 0)
	{
		pList->SetWindowText("");
	}
	else
	{
		myParent->viewedTime.step = number; 
		myParent->SetTime();
		myParent->Draw(myParent->timeView);
		myParent->Draw(myParent->logicView);
	}
}


void CComboView::OnSelchangeNumberCombo() 
{
	CComboBox* pList = (CComboBox*)GetDlgItem(IDC_NUMBER_COMBO);
	myParent->viewedTime.step = SCALE_STEP[pList->GetCurSel()];	
	myParent->SetTime();
	myParent->Draw(myParent->timeView);
	myParent->Draw(myParent->logicView);
}


void CComboView::OnSelchangeSecondCombo() 
{
	CComboBox* pList = (CComboBox*)GetDlgItem(IDC_SECOND_COMBO);	
	myParent->viewedTime.secondEnum = pList->GetCurSel();	
	myParent->SetTime();
	myParent->Draw(myParent->timeView);
	myParent->Draw(myParent->logicView);
}
