// TexturePropPage.cpp : implementation file
//

#include "stdafx.h"
#include "Megatron.h"

#include <Stuff\Stuff.hpp>

#include "TexturePropPage.h"


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

/////////////////////////////////////////////////////////////////////////////
// CTexturePropPage property page

IMPLEMENT_DYNCREATE(CTexturePropPage, CPropertyPage)

CTexturePropPage::CTexturePropPage() : CPropertyPage(CTexturePropPage::IDD)
{
	//{{AFX_DATA_INIT(CTexturePropPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pPage = NULL;
}

CTexturePropPage::~CTexturePropPage()
{
}

void CTexturePropPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTexturePropPage)
	DDX_Control(pDX, IDC_PROPLIST, m_wndPropList);
	DDX_Control(pDX, IDC_LIST, m_wndList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTexturePropPage, CPropertyPage)
	//{{AFX_MSG_MAP(CTexturePropPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTexturePropPage message handlers

BOOL CTexturePropPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	if (m_pPage)
	{
		Stuff::Page::NoteIterator *notes = m_pPage->MakeNoteIterator();
		Stuff::Note *note;
		while (note = notes->ReadAndNext())
		{
			CString name;
			const char *entry;
			name = note->GetName();
			note->GetEntry(&entry);
			
			CString str;
			str.Format("%s=%s",name,entry);
			m_wndList.AddString(str);
		}
		delete notes;
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CTexturePropPage::OnSetActive() 
{	
	CWnd *pWnd = GetParentFrame();
	CFrameWnd *pFrame = (CFrameWnd *)pWnd;
	CDocument *pDoc = pFrame->GetActiveDocument();
	if (pDoc && m_pPage)
	{
		CPtrList list;
		list.AddHead((LPVOID)m_pPage);
		pDoc->UpdateAllViews(NULL,UPDATE_TEXTUREVIEWSELECT,&list);

		m_wndPropList.ResetContent();

		POSITION pos = m_listProp.GetHeadPosition();
		while (pos)
		{
			CString str = m_listProp.GetNext(pos);
			m_wndPropList.AddString(str);
		}
	}
	return CPropertyPage::OnSetActive();
}

int CTexturePropPage::SetImageData(Image *pImage)
{
	//m_wndPropList.ResetContent();
	CString str;
	m_listProp.RemoveAll();

	str.Format("File Name: %s",pImage->GetFileName());
	m_listProp.AddTail(str);
	//m_wndPropList.AddString(str);

	CString str1;
	switch (pImage->GetIType())
	{
	case ITYPE_RGB:
		{
			str1 = "RGB";
			break;
		}
	case ITYPE_INDEXED:
		{
			str1 = "INDEXED";
			break;
		}
	}
	str.Format("Size: %d x %d x %d %s",pImage->GetWidth(),pImage->GetHeight(),pImage->GetBpp(),str1);
	//m_wndPropList.AddString(str);
	m_listProp.AddTail(str);

	str = "Has Alpha: ";
	if (pImage->HasAlpha())
		str+="true";
	else
		str+="false";
	m_listProp.AddTail(str);

	return 0;
}
