// CTMSView.cpp : implementation of the CCTMSView class
//

#include "stdafx.h"
#include "CTMS.h"

#include "CTMSDoc.h"
#include "CTMSView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCTMSView

IMPLEMENT_DYNCREATE(CCTMSView, CFormView)

BEGIN_MESSAGE_MAP(CCTMSView, CFormView)
	//{{AFX_MSG_MAP(CCTMSView)
	ON_COMMAND(ID_REFRESH, OnRefresh)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCTMSView construction/destruction

CCTMSView::CCTMSView()
	: CFormView(CCTMSView::IDD)
{
	//{{AFX_DATA_INIT(CCTMSView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

  m_oGreen.LoadBitmap( IDB_LEDGREEN);
  m_oYellow.LoadBitmap( IDB_LEDYELLOW);
  m_oMap.LoadBitmap( IDB_MAP);
}

CCTMSView::~CCTMSView()
{
}

void CCTMSView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCTMSView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CCTMSView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

//////////////////////////////////////////////////////////////////////
// void CCTMSView::OnInitialUpdate()
// 
// 
//////////////////////////////////////////////////////////////////////
void CCTMSView::OnInitialUpdate()
{

  CTM *tm = ((CCTMSApp *)AfxGetApp())->GetTM(0);
  CString sIp="";
  if (tm) sIp = tm->GetTMip();

	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

  //show clock to user and route message through dialog item
  m_cClock.SubclassDlgItem( IDC_CLOCK, this);

  //IP address CTMS
//  CString adr = "";
//  CTDI *tdi = ((CCTMSApp *)AfxGetApp())->GetTDI();

  //show the TDI adress as IP-address, there should be a TDI present!
//  if (tdi)
//  {

//    adr.Format( _T("%3d   .   %3d   .   %3d   .   %3d"), 
//                (tdi->GetIPAddressCTMS() & 0x000000ff),
//                ((tdi->GetIPAddressCTMS() >> 8) & 0x000000ff),
//                ((tdi->GetIPAddressCTMS() >> 16) & 0x000000ff),
//                ((tdi->GetIPAddressCTMS() >> 24) & 0x000000ff));
//
//  }

  //now we have the ip address of a TDI or an empty string, show it
  GetDlgItem(IDC_IPADDRESS)->SetWindowText( sIp);

  //do show some (or none) TDI Loacations
//  OnRefresh();
}

/////////////////////////////////////////////////////////////////////////////
// CCTMSView printing

BOOL CCTMSView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CCTMSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CCTMSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CCTMSView::OnPrint(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CCTMSView diagnostics

#ifdef _DEBUG
void CCTMSView::AssertValid() const
{
	CFormView::AssertValid();
}

void CCTMSView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CCTMSDoc* CCTMSView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCTMSDoc)));
	return (CCTMSDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCTMSView message handlers

BOOL CCTMSView::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
	
	return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

//////////////////////////////////////////////////////////////////////
// void CCTMSView::OnRefresh() 
// 
// This refresh shows one or moer TDI locations on the map, only the
// who's IP address is known is present and therefore shown
//////////////////////////////////////////////////////////////////////
void CCTMSView::OnRefresh() 
{

  
//  int i;
//  CString loc = _T("IPLocation%s");

//  for( i = 0; i < 10; i++)
//  {

//    loc.Format( "IPLocation%d", i+1);
    
    //read the ip address for the location
//    CString ip = ((CCTMSApp *)AfxGetApp())->theINIFile.GetString( loc, "Locations");
//    ((CStatic *)GetDlgItem( IDC_LOCATION1 + i))->ShowWindow( SW_HIDE);
//    int k;

//    for (k = 1; k < ((CCTMSApp *)AfxGetApp())->GetLastTDI(); k++)
//    {

//      CString tmp = ((CCTMSApp *)AfxGetApp())->GetTDI( k-1)->m_sTDIName;
//      if (((CCTMSApp *)AfxGetApp())->GetTDI( k-1)->m_sTDIName == ip)
//      {

//        CBitmap *bm = NULL;

//        bm = &m_oGreen;
//        ((CStatic *)GetDlgItem( IDC_LOCATION1 + i))->ShowWindow( SW_SHOW);
//      }
//    }

//  }
}
