// myView.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "test.h"

#include "myDoc.h"
#include "myView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CFormView)

BEGIN_MESSAGE_MAP(CMyView, CFormView)
	//{{AFX_MSG_MAP(CMyView)
	ON_LBN_SELCHANGE(IDC_RESLIST, OnSelchangeReslist)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
	: CFormView(CMyView::IDD)
{
	//{{AFX_DATA_INIT(CMyView)
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMyView::~CMyView()
{
}

void CMyView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyView)
	DDX_Control(pDX, IDC_RESLIST, m_resItemsList);
	DDX_Control(pDX, IDC_GLVIEW, m_myGraph);
	//}}AFX_DATA_MAP
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CMyView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CMyView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
	CFormView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
	return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
int index;

	CMyDoc* doc;
	doc=GetDocument();
	SIResFile *res=&doc->theRes;

	m_resItemsList.ResetContent();

	int i;

	for(i=0;i<res->numItems;i++)
	   {
	   index=m_resItemsList.AddString(res->items[i].name);
	   m_resItemsList.SetItemData(index,res->items[i].id);
	   }
	
}


void CMyView::OnSelchangeReslist() 
{
CMyDoc* doc;
int index;
int id;

	doc=GetDocument();
	SIResFile *res=&doc->theRes;

	// TODO: Add your control notification handler code here
	index=m_resItemsList.GetCurSel();
	id=m_resItemsList.GetItemData(index);
	if(id)
		{
		int list;
		list=m_myGraph.startNewDlist();
		if(res->parseItem(id))
			{
			m_myGraph.endDlist();
			m_myGraph.setDlist(list);
			m_myGraph.lightsEnabled=FALSE;
			}
		}


}
