// PenProps.cpp : implementation file
//

#include "stdafx.h"
#include "MW4GameEd2.h"
#include "PenProps.h"
#include "DrawInfo.h"


/////////////////////////////////////////////////////////////////////////////
// CPenProps dialog


CPenProps::CPenProps(DrawInfo *dinf, CWnd* pParent /*=NULL*/)
	: CDialog(CPenProps::IDD, pParent)
{
	MyDrawInfo=dinf;

	//{{AFX_DATA_INIT(CPenProps)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPenProps::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPenProps)
	DDX_Control(pDX, IDC_PENLIST, m_PenList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPenProps, CDialog)
	//{{AFX_MSG_MAP(CPenProps)
	ON_NOTIFY(NM_DBLCLK, IDC_PENLIST, OnDblclkPenlist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPenProps message handlers

BOOL CPenProps::OnInitDialog() 
{
	CDialog::OnInitDialog();

	for(int i=0;i<DrawInfo::PenCount;i++)
		{
		cols[i]=MyDrawInfo->GetPenColor(i);
		m_PenList.SetItemData(m_PenList.InsertItem(0,MyDrawInfo->GetPenName(i),-1),i);
		}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPenProps::OnDblclkPenlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
POSITION pos=m_PenList.GetFirstSelectedItemPosition();
int nItem = m_PenList.GetNextSelectedItem(pos);
int penidx=      m_PenList.GetItemData(nItem);

CColorDialog dlg(cols[penidx],NULL,this);

	if(dlg.DoModal()==IDOK)
	{
		cols[penidx]=dlg.m_cc.rgbResult;
	}
	
	*pResult = 0;
}

void CPenProps::OnOK() 
{

	for(int i=0;i<DrawInfo::PenCount;i++)
		MyDrawInfo->SetPenColor(i,cols[i]);
	
	CDialog::OnOK();
}
