// ogldoc.cpp : implementation of the OGLDoc class
//

#include "stdafx.h"
#include "OGLApp.h"

#include "ogldoc.h"
#include <bmpreader.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// OGLDoc

IMPLEMENT_DYNCREATE(OGLDoc, CDocument)

BEGIN_MESSAGE_MAP(OGLDoc, CDocument)
	//{{AFX_MSG_MAP(OGLDoc)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// OGLDoc construction/destruction

OGLDoc::OGLDoc()
{
	// TODO: add one-time construction code here

}

OGLDoc::~OGLDoc()
{
}

BOOL OGLDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// OGLDoc serialization

void OGLDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// OGLDoc diagnostics

#ifdef _DEBUG
void OGLDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void OGLDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// OGLDoc commands

void OGLDoc::OnFileOpen() 
{
	CString file_types = "24-bit BMP Files (*.bmp)|*.bmp||";

	CFileDialog dlg(TRUE,NULL,NULL,
		OFN_HIDEREADONLY | OFN_EXPLORER,
		(LPCTSTR)file_types,NULL);
	if (dlg.DoModal() == IDOK)
	{
		CString filename = dlg.GetPathName();

		if (ReadBMPFile((const char *)(LPCTSTR)filename,m_dib))
		{
			UpdateAllViews(NULL);
		}
	}
}
