// GosEventPane.cpp : implementation file
//

#include "stdafx.h"
#include "GosView.h"
#include "GosEventPane.h"
#include "GosViewDoc.h"
#include "TimeFrame.h"

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

char CGosEventPane::dbgmsg[4][256];
CView *CGosEventPane::pDebugView = NULL;

/////////////////////////////////////////////////////////////////////////////
// CGosEventPane

IMPLEMENT_DYNCREATE(CGosEventPane, CView)

CGosEventPane::CGosEventPane()
{
	m_fReady = false;
	for(int i=0; i<4; i++ )
		dbgmsg[i][0] = '\0';
}

CGosEventPane::~CGosEventPane()
{
}


BEGIN_MESSAGE_MAP(CGosEventPane, CView)
	//{{AFX_MSG_MAP(CGosEventPane)
	ON_WM_ERASEBKGND()
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGosEventPane drawing

void CGosEventPane::OnDraw(CDC* pDC)
{
	CGosViewDoc* pDoc = (CGosViewDoc *)GetDocument();
	// TODO: add draw code here
	SCROLLINFO si;
	GetScrollBarCtrl(SB_VERT)->GetScrollInfo( &si, SIF_ALL );
	int topRow = si.nPos;
	int numRows = si.nPage;

	int i;
	for( i=0; i<4; i++ )
	{
		pDC->TextOut( 0, i*20, dbgmsg[i] );
	}

	pDebugView = this;


	// TODO: add draw code here
/*
	for( int i=0; i<numRows; i++ )
	{
		// char *pName = pDoc->m_EventTree.EventName(i+topRow);
		pDC->SetBkMode( TRANSPARENT );
		pDC->TextOut( 0, i * m_pParentFrame->m_nRowHeight, "test" );
	}
*/
/*	for( int i=0; i<numRows; i++ )
	{
		char *pName = pDoc->m_EventTree.EventName(i+topRow);
		pDC->SetBkMode( TRANSPARENT );
		pDC->TextOut( 0, i * m_pParentFrame->m_nRowHeight, pName );
	}
*/
}

/////////////////////////////////////////////////////////////////////////////
// CGosEventPane diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CGosEventPane message handlers

BOOL CGosEventPane::OnEraseBkgnd(CDC* pDC) 
{
	if( !m_fReady )
		return FALSE;
	
	SCROLLINFO si;
	GetScrollBarCtrl(SB_VERT)->GetScrollInfo( &si, SIF_ALL );
	int topRow = si.nPos;
	int numRows = si.nPage;


	RECT rect;
	GetClientRect(&rect);

	int row;
	for( row=0; row<numRows ; row++ )
	{
		int bandMod = ( si.nPos + row ) % m_pParentFrame->m_nNumBandColors;

		rect.top = (int)((double)row * m_pParentFrame->m_rRowHeight);
		rect.bottom = rect.top + (int)(m_pParentFrame->m_rRowHeight + 1.0);

		pDC->FillRect( &rect, &m_pParentFrame->m_pBandColor[bandMod] );

	}

	return TRUE;
}

void CGosEventPane::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	//CView::OnVScroll(nSBCode, nPos, pScrollBar);
	SetScrollPos( SB_VERT, m_pParentFrame->m_VScrollPos );
	Invalidate();
}


BOOL CGosEventPane::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	m_pParentFrame = (CTimeFrame *)(pContext->m_pCurrentFrame);
	
	BOOL rc = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);

	m_fReady = true;

	return rc;
}


void CGosEventPane::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	Invalidate(true);
	
}
