// NumPanel.cpp : implementation file
//

#include "stdafx.h"
#include "pixelwhippro.h"
#include "NumPanel.h"
#include "CurveSet.h"


extern CPixelWhipProApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CNumPanel dialog


CNumPanel::CNumPanel(CWnd* pParent /*=NULL*/)
	: CDynaPanel(CNumPanel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNumPanel)
	m_NumVal = 0;
	//}}AFX_DATA_INIT
NeedUpdate=false;
}


void CNumPanel::DoDataExchange(CDataExchange* pDX)
{
	CDynaPanel::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNumPanel)
	DDX_Text(pDX, IDC_NUM, m_NumVal);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNumPanel, CDynaPanel)
	//{{AFX_MSG_MAP(CNumPanel)
	ON_EN_CHANGE(IDC_NUM, OnChangeNum)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNumPanel message handlers

void CNumPanel::UpdateControl()
{
	m_NumVal=*intval;
UpdateData(FALSE);
}

void CNumPanel::Set(void *pt)
{
intval=(int *)pt;
}


void CNumPanel::OnChangeNum() 
{
UpdateData(TRUE);
NeedUpdate=true;
SetTimer(1,1000,NULL);
}

BOOL CNumPanel::OnInitDialog() 
{
	CDynaPanel::OnInitDialog();
	UpdateControl();
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CNumPanel::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
if(NeedUpdate)
{
theApp.StopEffects();

int OldValue=*intval;
*intval=m_NumVal;

if(!MyCSet->IsDataValid())
{
*intval=m_NumVal=OldValue;
UpdateData(FALSE);
}

NeedUpdate=false;
theApp.StartEffects();
}
	CDynaPanel::OnTimer(nIDEvent);
}
