// ClusterView.cpp : implementation file
//

#include "stdafx.h"
#include "CTMS.h"
#include "ClusterView.h"

#include "MainFrm.h"
#include <time.h>
#include <sys/types.h>
#include <sys/timeb.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CClusterView

IMPLEMENT_DYNCREATE(CClusterView, CFormView)

/////////////////////////////////////////////////////////////////////////////
// CClusterView::CClusterView()
// 
// 
/////////////////////////////////////////////////////////////////////////////
CClusterView::CClusterView()
	: CFormView(CClusterView::IDD)
{
	//{{AFX_DATA_INIT(CClusterView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

  //mark timers as not present and invalid, so we won't use them
  m_iTimerRead = 0;
  m_iTimerId = 0;

  memset( (void *)m_iCEdit2Index, 0, sizeof(m_iCEdit2Index));

  //edit changes are still ignored
  DisregardChanges();
}

/////////////////////////////////////////////////////////////////////////////
// CClusterView::~CClusterView()
// 
// 
/////////////////////////////////////////////////////////////////////////////
CClusterView::~CClusterView()
{
}

void CClusterView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClusterView)
	DDX_Control(pDX, IDC_YLED, m_LEDyellow);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CClusterView, CFormView)
	//{{AFX_MSG_MAP(CClusterView)
	ON_WM_TIMER()
	ON_EN_CHANGE(IDC_CEDIT1, OnChangeCedit1)
	ON_EN_CHANGE(IDC_CEDIT2, OnChangeCedit2)
	ON_EN_CHANGE(IDC_CEDIT3, OnChangeCedit3)
	ON_EN_CHANGE(IDC_CEDIT4, OnChangeCedit4)
	ON_EN_CHANGE(IDC_CEDIT5, OnChangeCedit5)
	ON_EN_CHANGE(IDC_CEDIT6, OnChangeCedit6)
	ON_EN_CHANGE(IDC_CEDIT7, OnChangeCedit7)
	ON_EN_CHANGE(IDC_CEDIT8, OnChangeCedit8)
	ON_EN_CHANGE(IDC_CEDIT9, OnChangeCedit9)
	ON_EN_CHANGE(IDC_CEDIT10, OnChangeCedit10)
	ON_EN_CHANGE(IDC_CEDIT11, OnChangeCedit11)
	ON_EN_CHANGE(IDC_CEDIT12, OnChangeCedit12)
	ON_EN_CHANGE(IDC_CEDIT13, OnChangeCedit13)
	ON_EN_CHANGE(IDC_CEDIT14, OnChangeCedit14)
	ON_EN_CHANGE(IDC_CEDIT15, OnChangeCedit15)
	ON_EN_CHANGE(IDC_CEDIT16, OnChangeCedit16)
	ON_EN_CHANGE(IDC_CEDIT17, OnChangeCedit17)
	ON_EN_CHANGE(IDC_CEDIT18, OnChangeCedit18)
	ON_EN_CHANGE(IDC_CEDIT19, OnChangeCedit19)
	ON_EN_CHANGE(IDC_CEDIT20, OnChangeCedit20)
	ON_EN_CHANGE(IDC_CEDIT21, OnChangeCedit21)
	ON_EN_CHANGE(IDC_CEDIT22, OnChangeCedit22)
	ON_EN_CHANGE(IDC_CEDIT23, OnChangeCedit23)
	ON_EN_CHANGE(IDC_CEDIT24, OnChangeCedit24)
	ON_EN_CHANGE(IDC_CEDIT25, OnChangeCedit25)
	ON_EN_CHANGE(IDC_CEDIT26, OnChangeCedit26)
	ON_EN_CHANGE(IDC_CEDIT27, OnChangeCedit27)
	ON_EN_CHANGE(IDC_CEDIT28, OnChangeCedit28)
	ON_EN_CHANGE(IDC_CEDIT29, OnChangeCedit29)
	ON_EN_CHANGE(IDC_CEDIT30, OnChangeCedit30)
	ON_EN_CHANGE(IDC_CEDIT31, OnChangeCedit31)
	ON_EN_CHANGE(IDC_CEDIT32, OnChangeCedit32)
	ON_EN_CHANGE(IDC_CEDIT33, OnChangeCedit33)
	ON_EN_CHANGE(IDC_CEDIT34, OnChangeCedit34)
	ON_EN_CHANGE(IDC_CEDIT35, OnChangeCedit35)
	ON_EN_CHANGE(IDC_CEDIT36, OnChangeCedit36)
	ON_EN_CHANGE(IDC_CEDIT37, OnChangeCedit37)
	ON_EN_CHANGE(IDC_CEDIT38, OnChangeCedit38)
	ON_EN_CHANGE(IDC_CEDIT39, OnChangeCedit39)
	ON_EN_CHANGE(IDC_CEDIT40, OnChangeCedit40)
	ON_EN_CHANGE(IDC_CEDIT41, OnChangeCedit41)
	ON_EN_CHANGE(IDC_CEDIT42, OnChangeCedit42)
	ON_EN_CHANGE(IDC_CEDIT43, OnChangeCedit43)
	ON_EN_CHANGE(IDC_CEDIT44, OnChangeCedit44)
	ON_EN_CHANGE(IDC_CEDIT45, OnChangeCedit45)
	ON_EN_CHANGE(IDC_CEDIT46, OnChangeCedit46)
	ON_EN_CHANGE(IDC_CEDIT47, OnChangeCedit47)
	ON_EN_CHANGE(IDC_CEDIT48, OnChangeCedit48)
	ON_EN_CHANGE(IDC_CEDIT49, OnChangeCedit49)
	ON_EN_CHANGE(IDC_CEDIT50, OnChangeCedit50)
	ON_EN_CHANGE(IDC_CEDIT51, OnChangeCedit51)
	ON_EN_CHANGE(IDC_CEDIT52, OnChangeCedit52)
	ON_EN_CHANGE(IDC_CEDIT53, OnChangeCedit53)
	ON_EN_CHANGE(IDC_CEDIT54, OnChangeCedit54)
	ON_EN_CHANGE(IDC_CEDIT55, OnChangeCedit55)
	ON_EN_CHANGE(IDC_CEDIT56, OnChangeCedit56)
	ON_EN_CHANGE(IDC_CEDIT57, OnChangeCedit57)
	ON_EN_CHANGE(IDC_CEDIT58, OnChangeCedit58)
	ON_EN_CHANGE(IDC_CEDIT59, OnChangeCedit59)
	ON_EN_CHANGE(IDC_CEDIT60, OnChangeCedit60)
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT1, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT2, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT3, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT4, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT5, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT6, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT7, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT8, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT9, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT10, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT11, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT12, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT13, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT14, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT15, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT16, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT17, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT18, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT19, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT10, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT11, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT12, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT13, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT14, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT15, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT16, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT17, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT18, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT19, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT20, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT21, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT22, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT23, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT24, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT25, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT26, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT27, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT28, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT29, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT30, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT31, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT32, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT33, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT34, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT35, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT36, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT37, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT38, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT39, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT40, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT41, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT42, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT43, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT44, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT45, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT46, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT47, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT48, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT49, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT50, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT51, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT52, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT53, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT54, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT55, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT56, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT57, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT58, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT59, OnTimeNotify)
  ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CEDIT60, OnTimeNotify)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClusterView diagnostics

#ifdef _DEBUG
void CClusterView::AssertValid() const
{
	CFormView::AssertValid();
}

void CClusterView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CClusterView message handlers

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::OnInitialUpdate() 
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::OnInitialUpdate() 
{
  CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
//  CTDI *tdi = ((CCTMSApp *)AfxGetApp())->GetTDI();
//  int cluster = tdi->GetCluster();
  int i, count;
  long min, max;
  char buf[ 40];
  //char frm[ 40];
  int idx = ((CCTMSApp *)AfxGetApp())->GetTMIndex() & 0x00ff;
  int tp = (((CCTMSApp *)AfxGetApp())->GetTMIndex() >> 8) & 0x00ff;
  CTM *tm = ((CCTMSApp *)AfxGetApp())->GetTM(idx);
	
  memset( (void *)m_iCEdit2Index, 0, sizeof(m_iCEdit2Index));

  //find description for view
  switch (tp)
  {

  case COMM_BOOL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Commands")); break;

  case STAT_BOOL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Status information")); break;
  
  case INFO_BOOL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Statistical Information (boolean)")); break;
  case INFO_INT:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Statistical Information (integer)")); break;
  case INFO_LONG:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Statistical Information (long)")); break;
  case INFO_REAL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Statistical Information (real)")); break;
  case INFO_STRING:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Statistical Information (string)")); break;
  
  case PARA_BOOL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Parameters (boolean)")); break;
  case PARA_INT:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Parameters (integer)")); break;
  case PARA_LONG:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Parameters (long)")); break;
  case PARA_REAL:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Parameters (real)")); break;
  case PARA_STRING:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("Parameters (string)")); break;
  
  default:
    GetDlgItem( IDC_CLUSTERNAME)->SetWindowText( _T("?????????")); break;
  }

  CWnd *pWndLED = (CWnd *)GetDlgItem(IDC_YLED);
  m_LEDyellow.Blinking( 0);
  m_LEDyellow.SetLED(pWndLED,ID_LED_YELLOW, ID_SHAPE_ROUND, 0);

  //we need a tm from now on
  if (!tm) return;

  //set read only flag according to editing allowed flag from parameter

  //for ( i = 0, count = 0; i < TDI_MAX_CLUSTER_ITEM; i++)
  for ( i = 0, count = 0; (i < 10000)  && (count < 60); i++)
  {

    //get the parameter number
    //k = tdi->ClusterGetItem( cluster, i);

    //add some text to the parameter description
    if ((strlen(tm->GetIndex( i, tp)) > 0))
    {

      (GetDlgItem( IDC_CEDIT1+(count*3)))->ShowWindow( SW_SHOW);
      (GetDlgItem( IDC_CSTATIC1+(count*3)))->ShowWindow( SW_SHOW);

      CString sTmp = tm->GetIndexText( i, tp, buf);
      if (sTmp.GetLength() == 0) sTmp.Format( "%s", buf);
      GetDlgItem( IDC_CSTATIC1+(count*3))->SetWindowText( sTmp);
      //sprintf( buf, "Command %d", i);

	  //initialise min and max to keep compiler happy
	  min = max = 0;

      switch (tp)
      {
        case PARA_BOOL:
        case STAT_BOOL:
        case INFO_BOOL:
        case COMM_BOOL:
          min = 0; max = 1; 
          sprintf( buf, "%s", tm->GetIndex( i, tp));
          break;
        case INFO_INT:
        case PARA_INT:
          min = 0; max = 999; 
          sprintf( buf, "%d", atoi(tm->GetIndex( i, tp)));
          break;
        case INFO_LONG:
        case PARA_LONG:
          min = 0; max = -999999; 
          sprintf( buf, "%ld", atol(tm->GetIndex( i, tp)));
          break;
        case INFO_REAL:
        case PARA_REAL:
          min = 0; max = -1000000; 
          sprintf( buf, "%f", atof(tm->GetIndex( i, tp)));
          break;
        case INFO_STRING:
        case PARA_STRING:
          min = 0; max = 0; 
          sprintf( buf, "%.20s", tm->GetIndex( i, tp));
          if (strcmp(buf, "                    ") == 0)
          {
            strcpy( buf, "");
          }
          break;
      }

      GetDlgItem( IDC_CEDIT1+(count*3))->SetWindowText( buf);

      if (tp != COMM_BOOL)
      {

        (GetDlgItem( IDC_CEDIT1+(count*3)))->EnableWindow( TRUE);
        ((CEdit *)GetDlgItem( IDC_CEDIT1+(count*3)))->SetReadOnly( FALSE);

        if (max > 0)
        {
          ((CSpinButtonCtrl *)GetDlgItem( IDC_CSPIN1+(count*3)))->SetRange( min, max);
          ((CSpinButtonCtrl *)GetDlgItem( IDC_CSPIN1+(count*3)))->SetBuddy( GetDlgItem( IDC_CEDIT1+(count*3)));
          (GetDlgItem( IDC_CSPIN1+(count*3)))->ShowWindow(SW_SHOW);
          ((CSpinButtonCtrl *)GetDlgItem( IDC_CSPIN1+(count*3)))->EnableWindow( TRUE);
        }
      }

      m_iCEdit2Index[ count] = i;
      count++;
    }
//    else
//    {

//      (GetDlgItem( IDC_CEDIT1+(i*3)))->ShowWindow(SW_HIDE);
//      (GetDlgItem( IDC_CSPIN1+(i*3)))->ShowWindow(SW_HIDE);
//      (GetDlgItem( IDC_CSTATIC1+(i*3)))->ShowWindow(SW_HIDE);
//    }
/*
    //set edit flag
    x = (tdi->IsEdit( k)) ? 0: 1;

    switch (tdi->Display( k))
    {

      //time fields
      case -5:
        {
        (GetDlgItem( IDC_CSPIN1+(i*3)))->ShowWindow(SW_HIDE);
        
        //find the placeholder for the time control
        m_DateTime[ i].SubclassDlgItem( IDC_CEDIT1+(i*3), this);

        (GetDlgItem( IDC_CEDIT1+(i*3)))->EnableWindow( TRUE);
        ((CTimeEdit *)GetDlgItem( IDC_CEDIT1+(i*3)))->SetReadOnly( FALSE);

        CString tempje;
        tempje.Format( "%02d:%02d", (int)(tdi->Get( k) / 100), (int)(tdi->Get( k) % 100));
        m_DateTime[ i].SetTime( tempje);
        }
        break;

    case 7: 
      (GetDlgItem( IDC_CEDIT1+(i*3)))->EnableWindow( FALSE);
      (GetDlgItem( IDC_CSPIN1+(i*3)))->EnableWindow( FALSE);
      (GetDlgItem( IDC_CSTATIC1+(i*3)))->EnableWindow( FALSE);
      break;

    default: 
      ((CEdit *)GetDlgItem( IDC_CEDIT1+(i*3)))->SetReadOnly( x);
      break;
    }*/
  }
/*
  if ((count % 2)) count++;
  SIZE sizeTotal;
  sizeTotal.cy = ((m_sSizeTotal.cy - 60)/30)*(count/2) + 60;
  sizeTotal.cx = m_sSizeTotal.cx;

  //ModifyStyle( 0, WS_VSCROLL, SWP_NOREDRAW|SWP_DEFERERASE|SWP_NOACTIVATE);
  SetScrollSizes( MM_TEXT, CSize(sizeTotal.cx, sizeTotal.cy) );

	UpdateView( 1);
  AcceptChanges();

  //ask for the displayed cluster
  tdi->SendData( 1, 6, tdi->GetCluster());
*/


  UpdateView();
  AcceptChanges();
  //create 500 msec timer event
  //if (tp == COMM_BOOL)
  {
    m_iTimerId = SetTimer( TIMER_CLUSTER, TIME_CLUSTER, NULL);
    m_iTimerRead = SetTimer( TIMER_CLUSTER_READ, TIME_CLUSTER_READ, NULL);
  }
}

/////////////////////////////////////////////////////////////////////////////
// BOOL CClusterView::Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, 
//                            DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
//                            UINT nID, CCreateContext* pContext) 
// 
// 
/////////////////////////////////////////////////////////////////////////////
BOOL CClusterView::Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, 
                           DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, 
                           UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	dwStyle &= ~WS_VSCROLL;
	BOOL x = CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);

  int nMapMode;
  SIZE sizePage;
  SIZE sizeLine;
  GetDeviceScrollSizes( nMapMode, m_sSizeTotal, sizePage, sizeLine ); 
  SetScrollSizes( MM_TEXT, CSize(m_sSizeTotal.cx, 50));
  return x;
}

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::OnTimeNotify(NMHDR *pHdr, LRESULT *pRes)
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::OnTimeNotify(NMHDR *pHdr, LRESULT *pRes)
{
  //keep compiler happy
  pHdr = NULL;
  pRes = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::Updateview(int force)
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::UpdateView()
{

  int idx = ((CCTMSApp *)AfxGetApp())->GetTMIndex() & 0x00ff;
  int tp = (((CCTMSApp *)AfxGetApp())->GetTMIndex() >> 8) & 0x00ff;
  CTM *tm = ((CCTMSApp *)AfxGetApp())->GetTM(idx);
  int i, k;
  CString sVal;
  char buf[ 40];
  char buf2[40];


  //we just need a tm
  if (!tm) return;

  //lifesign registration
  if (tm->IsConnected())
    m_LEDyellow.SwitchOn();
  else
    m_LEDyellow.SwitchOff();

  //set read only flag according to editing allowed flag from parameter
  for ( i = 0, k = 0; i < 10000; i++)
  {

    //get the parameter number
    if (strlen(tm->GetIndex( i, tp)) == 0) 
      continue; //quit if we reached the last parameter

    //get the (stored) value of the parameter
    sVal = tm->GetIndex( i, tp); 

    switch (tp)
    {
      case PARA_BOOL:
      case STAT_BOOL:
      case INFO_BOOL:
      case COMM_BOOL:
        //min = 0; max = 1; 
        sprintf( buf, "%s", tm->GetIndex( i, tp));
        break;
      case INFO_INT:
      case PARA_INT:
        //min = 0; max = 999; 
        sprintf( buf, "%d", atoi(tm->GetIndex( i, tp)));
        break;
      case INFO_LONG:
      case PARA_LONG:
        //min = 0; max = -999999; 
        sprintf( buf, "%ld", atol(tm->GetIndex( i, tp)));
        break;
      case INFO_REAL:
      case PARA_REAL:
        //min = 0; max = -1000000; 
        sprintf( buf, "%f", atof(tm->GetIndex( i, tp)));
        break;
      case INFO_STRING:
      case PARA_STRING:
        //min = 0; max = 0; 
        sprintf( buf, "%.20s", tm->GetIndex( i, tp));
        if (strcmp(buf, "                    ") == 0)
        {
          strcpy( buf, "");
        }
        break;
    }


    GetDlgItem( IDC_CEDIT1+(k*3))->GetWindowText( buf2, sizeof(buf2));

    if (strcmp( buf2, buf) != 0)
    {

      //sprintf( buf, "%s", sVal);
      GetDlgItem( IDC_CEDIT1+(k*3))->SetWindowText( buf);

/*
    //add some text to the parameter value, create the format string
    switch((t = tdi->Display( k)))
    {

      //hexadecimal representation
      case -1: 
        strcpy( format, "0x%lX");
        break;
      case -5: 

        if (((m_DateTime[ i].GetHour() * 100) + m_DateTime[ i].GetMinute()) != x)
        {

          CString tempje;
          tempje.Format( "%02d:%02d", (int)(tdi->Get( k) / 100), (int)(tdi->Get( k) % 100));
          m_DateTime[ i].SetTime( tempje);
        }
        continue;

      case 7: 
        strcpy( format, "%ld");
        break;

      //the defaults parameter representation
      default: 

        if (t < 0) t *= -1;
                 
        //fixed length for display
        if (t)
        {
          sprintf( &format[2], "%d", t);
          format[ 0] = '%';
          format[ 1] = '0';
          format[ strlen( format)+1] = '\0';
          format[ strlen( format)+2] = '\0';
          format[ strlen( format)] = 'l';
          format[ strlen( format)] = 'd';
        }
        else
          strcpy( format, "%ld");
        break;
    }

    sprintf( buf, format, tdi->Get( k));
    GetDlgItem( IDC_CEDIT1+(i*3))->GetWindowText( old);

    if (strcmp( old, buf) || Force)
    {

      int set = ((GetDlgItem( IDC_CEDIT1+(i*3)) != GetFocus())|| Force) ? 1: 0;

      if ((((CEdit *)GetDlgItem( IDC_CEDIT1+(i*3)))->GetStyle() & ES_READONLY))
        set = 1;

      if (set)
        GetDlgItem( IDC_CEDIT1+(i*3))->SetWindowText( buf);
      */
    } 
    k++;

  } 
}

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::AcceptChanges()
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::AcceptChanges()
{

  m_iFirst = 0;
}

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::DisregardChanges()
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::DisregardChanges()
{

  m_iFirst = 1;
}

/////////////////////////////////////////////////////////////////////////////
// BOOL CClusterView::ChangesAllowed()
// 
// 
/////////////////////////////////////////////////////////////////////////////
BOOL CClusterView::ChangesAllowed()
{

  return m_iFirst ? FALSE: TRUE;
}

BOOL CClusterView::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	if (m_iTimerId) KillTimer( m_iTimerId);
  if (m_iTimerRead) KillTimer( m_iTimerRead);

  m_iTimerRead = m_iTimerId = 0;

	return CFormView::DestroyWindow();
}

void CClusterView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (nIDEvent == TIMER_CLUSTER) UpdateView();

//	if (nIDEvent == TIMER_CLUSTER_READ)
//  {

    //read the values from the TDI
//    CTDI *tdi = ((CCTMSApp *)AfxGetApp())->GetTDI();

    //ask for the displayed cluster
//    tdi->SendData( 1, 6, tdi->GetCluster());
//  }

	CFormView::OnTimer(nIDEvent);
}

void CClusterView::OnChangeCedit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 0);
}

void CClusterView::OnChangeCedit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 1);
}

void CClusterView::OnChangeCedit3() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 2);
}

void CClusterView::OnChangeCedit4() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 3);
}

void CClusterView::OnChangeCedit5() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 4);
}

void CClusterView::OnChangeCedit6() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 5);
}

void CClusterView::OnChangeCedit7() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 6);
}

void CClusterView::OnChangeCedit8() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 7);
}

void CClusterView::OnChangeCedit9() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 8);
}

void CClusterView::OnChangeCedit10() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 9);
}

void CClusterView::OnChangeCedit11() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 10);
}

void CClusterView::OnChangeCedit12() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 11);
}

void CClusterView::OnChangeCedit13() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 12);
}

void CClusterView::OnChangeCedit14() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 13);
}

void CClusterView::OnChangeCedit15() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 14);
}

void CClusterView::OnChangeCedit16() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 15);
}

void CClusterView::OnChangeCedit17() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 16);
}

void CClusterView::OnChangeCedit18() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 17);
}

void CClusterView::OnChangeCedit19() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 18);
}

void CClusterView::OnChangeCedit20() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 19);
}

void CClusterView::OnChangeCedit21() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 20);
}

void CClusterView::OnChangeCedit22() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 21);
}

void CClusterView::OnChangeCedit23() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 22);
}

void CClusterView::OnChangeCedit24() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 23);
}

void CClusterView::OnChangeCedit25() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 24);
}

void CClusterView::OnChangeCedit26() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 25);
}

void CClusterView::OnChangeCedit27() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 26);
}

void CClusterView::OnChangeCedit28() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 27);
}

void CClusterView::OnChangeCedit29() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 28);
}

void CClusterView::OnChangeCedit30() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 29);
}

void CClusterView::OnChangeCedit31() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 30);
}

void CClusterView::OnChangeCedit32() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 31);
}

void CClusterView::OnChangeCedit33() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 32);
}

void CClusterView::OnChangeCedit34() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 33);
}

void CClusterView::OnChangeCedit35() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 34);
}

void CClusterView::OnChangeCedit36() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 35);
}

void CClusterView::OnChangeCedit37() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 36);
}

void CClusterView::OnChangeCedit38() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 37);
}

void CClusterView::OnChangeCedit39() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 38);
}

void CClusterView::OnChangeCedit40() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 39);
}

void CClusterView::OnChangeCedit41() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 40);
}

void CClusterView::OnChangeCedit42() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 41);
}

void CClusterView::OnChangeCedit43() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 42);
}

void CClusterView::OnChangeCedit44() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 43);
}

void CClusterView::OnChangeCedit45() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 44);
}

void CClusterView::OnChangeCedit46() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 45);
}

void CClusterView::OnChangeCedit47() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 46);
}

void CClusterView::OnChangeCedit48() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 47);
}

void CClusterView::OnChangeCedit49() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 48);
}

void CClusterView::OnChangeCedit50() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 49);
}

void CClusterView::OnChangeCedit51() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 50);
}

void CClusterView::OnChangeCedit52() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 51);
}

void CClusterView::OnChangeCedit53() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 52);
}

void CClusterView::OnChangeCedit54() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 53);
}

void CClusterView::OnChangeCedit55() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 54);
}

void CClusterView::OnChangeCedit56() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 55);
}

void CClusterView::OnChangeCedit57() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 56);
}

void CClusterView::OnChangeCedit58() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 57);
}

void CClusterView::OnChangeCedit59() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 58);
}

void CClusterView::OnChangeCedit60() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	OnChangeEdit( 59);
}

/////////////////////////////////////////////////////////////////////////////
// void CClusterView::OnChangeEdit(int Idx)
// 
// 
/////////////////////////////////////////////////////////////////////////////
void CClusterView::OnChangeEdit(int Idx)
{

  //int i, count;
  //unsigned long min, max;
  char buf[ 40];
  double x;

  CString sVal;
  //char frm[ 40];
  int idx = ((CCTMSApp *)AfxGetApp())->GetTMIndex() & 0x00ff;
  int tp = (((CCTMSApp *)AfxGetApp())->GetTMIndex() >> 8) & 0x00ff;
  CTM *tm = ((CCTMSApp *)AfxGetApp())->GetTM(idx);

  if (!tm) return;
  if (!ChangesAllowed()) return;

  //read the value from the control
  ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->GetWindowText( buf, sizeof(buf));

  x = atof( buf);
  if((tp != INFO_STRING) && (tp != PARA_STRING))
  {

    if (x < 0.0)
    {
      x = 0;
      strcpy( buf, "0");
      ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
    }
  }

  switch (tp)
  {

    case STAT_BOOL:
    case PARA_BOOL:
    case INFO_BOOL:
      if (x > 1)
      {
        x = 1;
        strcpy( buf, "1");
        ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
      }
      break;

    case PARA_INT:
    case INFO_INT:

      if (x > 999)
      {
        x = 999;
        strcpy( buf, "999");
        ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
      }
      break;

    case PARA_LONG:
    case INFO_LONG:

      if (x > 999999)
      {
        x = 999999;
        strcpy( buf, "999999");
        ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
      }
      break;
    
    case PARA_REAL:
    case INFO_REAL:

      if (x > 99999999.99999999)
      {
        x = 99999999.99999999;
        strcpy( buf, "99999999.99999999");
        ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
      }
      break;

    case INFO_STRING:
    case PARA_STRING:
      if (strlen( buf) == 0) strcpy( buf, "                    ");
      break;

    case COMM_BOOL:
    default: return; break;
  }

  //update  parameter value in index array
  sVal = buf;
  tm->SetIndex( m_iCEdit2Index[Idx], tp, sVal);

/*
  int len = 40;
  char buf[ 80];
  CTDI *tdi = ((CCTMSApp *)AfxGetApp())->GetTDI();
  int x = tdi->GetCluster();
  int para = tdi->ClusterGetItem( x, Idx);
  //int para = ProcessControl.ClusterGetItem( x, Idx);
  long k = 0;

  int testje = 1;
  if ((((CEdit *)GetDlgItem( IDC_CEDIT1+(Idx*3)))->GetStyle() & ES_READONLY) == ES_READONLY)
    testje = 0;

//  int testje = (GetDlgItem( IDC_CEDIT1+(Idx*3)))->IsWindowEnabled();
  int allow = ChangesAllowed();
  //ignore firstchange in control, is done by system
  if (!allow || !para || !testje)
    return;

  //check for uumm representation
  if (tdi->Display( para) == -5)
  {

    k = (m_DateTime[ Idx].GetHour() * 100) + m_DateTime[ Idx].GetMinute();
  }
  else
  {

    if (tdi->Display( para) == -1) 
      return;

    //update the variable, check for minimum and maximum
    ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->GetWindowText( buf, len);
    k = atoi( buf);

    //absolute edit values
    if ((k > 999999999) || (k < -999999999))
    {
      sprintf( buf, "%d", tdi->Get( para));
      ((CEdit *)GetDlgItem( IDC_CEDIT1+(3*Idx)))->SetWindowText( buf);
    }
  }

  //update the parameter value
  tdi->SetSource( PRM_CTMS);

  if (k != tdi->Get( para))
  {

    tdi->Set( para, k);

    //write the cluster to the TDI
    tdi->SendData( 0, 3, tdi->GetCluster());
  }
*/
}

/////////////////////////////////////////////////////////////////////////////
// BOOL CClusterView::OnEraseBkgnd(CDC* pDC) 
// 
// 
/////////////////////////////////////////////////////////////////////////////
BOOL CClusterView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CFormView::OnEraseBkgnd(pDC);
}
