/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


// ConstellateView.cpp : implementation of the CConstellateView class
//

#include "stdafx.h"
#include "Constellate.h"

#include "ConstellateDoc.h"
#include "ConstellateView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConstellateView

IMPLEMENT_DYNCREATE(CConstellateView, CView)

BEGIN_MESSAGE_MAP(CConstellateView, CView)
	//{{AFX_MSG_MAP(CConstellateView)
	ON_UPDATE_COMMAND_UI(ID_SAMPLING_START, OnUpdateSamplingStart)
	ON_UPDATE_COMMAND_UI(ID_SAMPLING_STOP, OnUpdateSamplingStop)
	ON_WM_CREATE()
	ON_WM_ERASEBKGND()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConstellateView construction/destruction

CConstellateView::CConstellateView()
{
}

CConstellateView::~CConstellateView()
{
}

BOOL CConstellateView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CView::PreCreateWindow(cs);
}


int CConstellateView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

   m_nTimer = SetTimer(0, 500, NULL);

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CConstellateView drawing

void CConstellateView::OnDraw(CDC* pDC)
{
   ASSERT(pDC != NULL);

	CConstellateDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

   CRect rcClient;
   GetClientRect(rcClient);

   int x = (rcClient.Width() - 1044) / 2;
   int y = (rcClient.Height() - 1044) / 2;
   
   CRect rcBmp(CPoint(x, y), CSize(1044, 1044));
   VERIFY(DrawBitmap(*pDC, &(pDoc->m_bmp), &rcBmp));
}

BOOL CConstellateView::OnEraseBkgnd(CDC* pDC) 
{
	//return CView::OnEraseBkgnd(pDC);
   ASSERT(pDC != NULL);

   /*
   CRect rcClient;
   GetClientRect(rcClient);
   pDC->FillSolidRect(rcClient, RGB(0, 0, 0));
   */

   return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CConstellateView diagnostics

#ifdef _DEBUG
void CConstellateView::AssertValid() const
{
	CView::AssertValid();
}

void CConstellateView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CConstellateDoc* CConstellateView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CConstellateDoc)));
	return (CConstellateDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CConstellateView message handlers

void CConstellateView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
   RedrawWindow();
}

void CConstellateView::OnUpdateSamplingStart(CCmdUI* pCmdUI) 
{
   ASSERT(pCmdUI != NULL);

	CConstellateDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

   pCmdUI->Enable(!pDoc->m_fSampling);
}

void CConstellateView::OnUpdateSamplingStop(CCmdUI* pCmdUI) 
{
   ASSERT(pCmdUI != NULL);

	CConstellateDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

   pCmdUI->Enable(pDoc->m_fSampling);
}

void CConstellateView::OnTimer(UINT nIDEvent) 
{
   RedrawWindow();
	CView::OnTimer(nIDEvent);
}
