// EffectEditDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EffectEdit.h"
#include "EffectEditDlg.h"
#include "contents.hpp"

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


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum
	{
		IDD = IDD_ABOUTBOX
	};
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);		// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEffectEditDlg dialog

CEffectEditDlg::CEffectEditDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEffectEditDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEffectEditDlg)
	m_Audio = _T("");
	m_Video = _T("");
	m_Sound = _T("");
	m_MaxRange = 0.0f;
	m_MinRange = 0.0f;
	m_TransX = 0.0f;
	m_TransY = 0.0f;
	m_TransZ = 0.0f;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CEffectEditDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEffectEditDlg)
	DDX_Control(pDX, IDC_LOOP, m_Loop);
	DDX_Control(pDX, IDC_FOG, m_Fog);
	DDX_Control(pDX, IDC_DATASTARTRUN, m_DataStartRunning);
	DDX_Control(pDX, IDC_LOCKCHECK, m_LockButton);
	DDX_Control(pDX, IDC_MASTERLIST, m_MasterList);
	DDX_Control(pDX, IDC_EFFECTLIST, m_EffectList);
	DDX_Text(pDX, IDC_AUDIO, m_Audio);
	DDX_Text(pDX, IDC_VIDEO, m_Video);
	DDX_Text(pDX, IDC_SOUND, m_Sound);
	DDX_Text(pDX, IDC_MAXRANGEEDIT, m_MaxRange);
	DDX_Text(pDX, IDC_MINRANGEEDIT, m_MinRange);
	DDX_Text(pDX, IDC_TRANSX, m_TransX);
	DDX_Text(pDX, IDC_TRANSY, m_TransY);
	DDX_Text(pDX, IDC_TRANSZ, m_TransZ);
	//}}AFX_DATA_MAP
	DDX_Text(pDX, IDC_CONT1, m_ContentEntry[0]);
	DDX_Text(pDX, IDC_CONT2, m_ContentEntry[1]);
	DDX_Text(pDX, IDC_CONT3, m_ContentEntry[2]);
	DDX_Text(pDX, IDC_CONT4, m_ContentEntry[3]);
	DDX_Text(pDX, IDC_CONT5, m_ContentEntry[4]);
	DDX_Text(pDX, IDC_CONT6, m_ContentEntry[5]);
	DDX_Text(pDX, IDC_CONT7, m_ContentEntry[6]);
	DDX_Text(pDX, IDC_CONT8, m_ContentEntry[7]);
	DDX_Text(pDX, IDC_CONT9, m_ContentEntry[8]);
	DDX_Text(pDX, IDC_CONT10, m_ContentEntry[9]);
	DDX_Text(pDX, IDC_CONT11, m_ContentEntry[10]);
	DDX_Text(pDX, IDC_CONT12, m_ContentEntry[11]);
	DDX_Text(pDX, IDC_CONT13, m_ContentEntry[12]);
	DDX_Text(pDX, IDC_CONT14, m_ContentEntry[13]);
	DDX_Text(pDX, IDC_CONT15, m_ContentEntry[14]);
	DDX_Text(pDX, IDC_CONT16, m_ContentEntry[15]);
	DDX_Text(pDX, IDC_CONT17, m_ContentEntry[16]);
	DDX_Text(pDX, IDC_CONT18, m_ContentEntry[17]);

}

BEGIN_MESSAGE_MAP(CEffectEditDlg, CDialog)
//{{AFX_MSG_MAP(CEffectEditDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TVN_SELCHANGED, IDC_EFFECTLIST, OnSelchangedEffectlist)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_LBN_SELCHANGE(IDC_MASTERLIST, OnSelchangeMasterlist)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_LOCKCHECK, OnLockcheck)
ON_BN_CLICKED(IDC_SOUNDSELECT, OnSoundselect)
ON_BN_CLICKED(IDC_DATASTARTRUN, OnDatastartrun)
ON_NOTIFY(TVN_SELCHANGING, IDC_EFFECTLIST, OnSelchangingEffectlist)
ON_BN_CLICKED(IDC_FOG, OnFog)
ON_BN_CLICKED(IDC_LOOP, OnLoop)
ON_EN_UPDATE(IDC_MAXRANGEEDIT, OnUpdateMaxrangeedit)
ON_EN_UPDATE(IDC_MINRANGEEDIT, OnUpdateMinrangeedit)
ON_EN_UPDATE(IDC_TRANSX, OnUpdateTransx)
ON_EN_UPDATE(IDC_TRANSY, OnUpdateTransy)
ON_EN_UPDATE(IDC_TRANSZ, OnUpdateTransz)
	ON_BN_CLICKED(IDC_CONTENT, OnContent)
	ON_BN_CLICKED(IDC_CONTSELECT1, OnContselect1)
	ON_BN_CLICKED(IDC_CONTSELECT2, OnContselect2)
	ON_BN_CLICKED(IDC_CONTSELECT3, OnContselect3)
	ON_BN_CLICKED(IDC_CONTSELECT4, OnContselect4)
	ON_BN_CLICKED(IDC_CONTSELECT5, OnContselect5)
	ON_BN_CLICKED(IDC_CONTSELECT6, OnContselect6)
	ON_BN_CLICKED(IDC_CONTSELECT7, OnContselect7)
	ON_BN_CLICKED(IDC_CONTSELECT8, OnContselect8)
	ON_BN_CLICKED(IDC_CONTSELECT9, OnContselect9)
	ON_BN_CLICKED(IDC_CONTSELECT10, OnContselect10)
	ON_BN_CLICKED(IDC_CONTSELECT11, OnContselect11)
	ON_BN_CLICKED(IDC_CONTSELECT12, OnContselect12)
	ON_BN_CLICKED(IDC_CONTSELECT13, OnContselect13)
	ON_BN_CLICKED(IDC_CONTSELECT14, OnContselect14)
	ON_BN_CLICKED(IDC_CONTSELECT15, OnContselect15)
	ON_BN_CLICKED(IDC_CONTSELECT16, OnContselect16)
	ON_BN_CLICKED(IDC_CONTSELECT17, OnContselect17)
	ON_BN_CLICKED(IDC_CONTSELECT18, OnContselect18)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEffectEditDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	AddEffectList (m_EffectList);
	AddMasterList (m_MasterList);
	m_LockButton.SetCheck (1);
	m_Locked = true;

	return TRUE;	// return TRUE  unless you set the focus to a control
}

void CEffectEditDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CEffectEditDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CEffectEditDlg::OnQueryDragIcon()
{
	return(HCURSOR) m_hIcon;
}

void CEffectEditDlg::ClearAudioDialog (void)
{
	m_MinRange = 0;
	m_MaxRange = 0;
	m_Loop.SetCheck (2);
}

void CEffectEditDlg::ClearVideoDialog (void)
{
	m_TransX = 0;
	m_TransY = 0;
	m_TransZ = 0;
	m_Fog.SetCheck (2);
}

void CEffectEditDlg::ClearDialog (void)
{
	ClearEffectDialog ();
	ClearContentDialog ();
}

void CEffectEditDlg::ClearEffectDialog (void)
{
	m_MasterList.SetCurSel (-1);
	m_Audio.Empty ();
	m_Video.Empty ();
	m_Sound.Empty ();
	m_DataStartRunning.SetCheck (2);
	ClearAudioDialog ();
	ClearVideoDialog ();
}

void CEffectEditDlg::ClearContentDialog (void)
{
	int i;
	for (i=0;i<18;i++)
	{
		m_ContentEntry[i].Empty ();
	}
}

void CEffectEditDlg::OnSelchangedEffectlist(NMHDR* pNMHDR, LRESULT* pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here

	HTREEITEM item;

	item = m_EffectList.GetSelectedItem ();
	if (item == NULL)
	{
		ClearDialog ();
	}
	else
	{
		CEffectData *effdata;
		CDataBase *basedata;
		CContentData *contdata;
		ClearContentDialog ();

		basedata = (CDataBase *) m_EffectList.GetItemData (item);
		effdata = dynamic_cast<CEffectData *> (basedata);
		contdata = dynamic_cast<CContentData *> (basedata);
		if (!basedata)
		{
			ClearDialog ();
		}
		else if (effdata)
		{
			m_Audio = effdata->AudioFileName ();
			m_Video = effdata->VideoFileName ();
			m_Sound = effdata->Sample ();
			if (m_MasterList.SelectString (-1,effdata->FX ()) == LB_ERR)
			{
				m_MasterList.SetCurSel (-1);
			}

			if (effdata->StartRunning () == "yes")
				m_DataStartRunning.SetCheck (1);
			else
				m_DataStartRunning.SetCheck	(0);
			if (effdata->VideoFileName ().IsEmpty ())
			{
				ClearVideoDialog ();
			}
			else
			{
				if (effdata->Translation () == "fred")
				{
					m_TransX = 0;
					m_TransY = 0;
					m_TransZ = 0;
				}
				else
				{
					sscanf ((LPCTSTR) effdata->Translation (),"%f %f %f",&m_TransX,&m_TransY,&m_TransZ);
				}
				if (effdata->Fog () == "no")
					m_Fog.SetCheck (0);
				else
					m_Fog.SetCheck (1);
			}



			if (effdata->AudioFileName ().IsEmpty ())
			{
				ClearAudioDialog ();
			}
			else
			{
				if (effdata->Loop () == "1")
					m_Loop.SetCheck (1);
				else
					m_Loop.SetCheck	(0);
				sscanf ((LPCTSTR) effdata->MinRange (),"%f",&m_MinRange);
				sscanf ((LPCTSTR) effdata->MaxRange (),"%f",&m_MaxRange);
			}
		}
		else if (contdata)
		{
			ClearEffectDialog ();
			int i;
			for (i=0;i<18;i++)
			{
				m_ContentEntry[i] = contdata->EffectName (i);
			}
		}
		else
			ASSERT (false);
		UpdateData (FALSE);
	}

	*pResult = 0;
}

void CEffectEditDlg::StripPathFolder (CString& path,CString& foldername)
{
	int index;
	path.MakeLower ();
	index = path.Find ("content");
	if (index == -1)
		return;
	path = path.Right (path.GetLength () - index);
	index = path.ReverseFind ('\\');
	if (index != -1)
	{
		path = path.Left (index);
	}
	index = path.Find ("effects");
	if (index == -1)
		return;
	foldername = path.Right (path.GetLength () - index - 7 -1);		// 7 is length of effects string
}

void CEffectEditDlg::OnAdd()
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg (TRUE,"data",NULL,OFN_CREATEPROMPT,"Effect Files (*.data)|*.data||",this);
	dlg.m_ofn.lpstrInitialDir = "content\\effects";
	char dir[MAX_PATH];
	GetCurrentDirectory (MAX_PATH-1,dir);

	if (dlg.DoModal () == IDOK)
	{
		CString filename,name,path;
		CString foldername;
		CString videoname;

		filename = dlg.GetFileName ();
		path = dlg.GetPathName ();
		StripPathFolder (path,foldername);

		int index;

		index = filename.ReverseFind ('.');
		if (index != -1)
		{
			filename = filename.Left (index);
		}
		filename += ".data";
		CEffectData *data;
		data = new CEffectData (path);
		data->InitialData (filename);
		index = filename.ReverseFind ('.');
		if (index != -1)
		{
			videoname = filename.Left (index);
		}
		videoname += ".video";
		data->VideoFileName (videoname);

		HTREEITEM item,root;

		root = InsertEffectFolder (foldername,m_EffectList);
		if (root == NULL)
		{
			MessageBox ("Unable to add item to tree control","error",MB_OK);
			delete data;
			return;
		}
		if (CheckEffectItem (filename,m_EffectList,root))
		{
			MessageBox ("Unable to add an effect that already exists","error",MB_OK);
			delete data;
			return;
		}
		item = m_EffectList.InsertItem (filename,root);
		m_EffectList.SetItemData (item,(DWORD) data);
		m_EffectList.Expand (root,TVE_EXPAND);
		m_EffectList.SelectItem (item);
	}
	SetCurrentDirectory (dir);
}

void CEffectEditDlg::OnSelchangeMasterlist()
{
	// TODO: Add your control notification handler code here
	HTREEITEM item;

	if (m_Locked)
		return;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;

	int sel;
	sel = m_MasterList.GetCurSel ();
	if (sel == LB_ERR)
		return;
	CString name;
	m_MasterList.GetText (sel,name);
	effdata->FX (name);
}

void CEffectEditDlg::OnClose()
{
	// TODO: Add your message handler code here and/or call default

	CDialog::OnClose();
}

BOOL CEffectEditDlg::DestroyWindow()
{
	// TODO: Add your specialized code here and/or call the base class

	KillEffectList (m_EffectList);
	KillMasterList (m_MasterList);
	return CDialog::DestroyWindow();
}

void CEffectEditDlg::OnLockcheck()
{
	// TODO: Add your control notification handler code here

	m_Locked = !m_Locked;
	if (m_Locked)
	{
		m_LockButton.SetCheck (1);
	}
	else
	{
		m_LockButton.SetCheck (0);
	}
}

void CEffectEditDlg::OnSoundselect()
{
	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;

	CFileDialog dlg (TRUE,"Sound",NULL,OFN_CREATEPROMPT,"Sound Files (*.wav)|*.wav||",this);
	dlg.m_ofn.lpstrInitialDir = "content\\audio";

	char dir[MAX_PATH];
	GetCurrentDirectory (MAX_PATH-1,dir);

	if (dlg.DoModal () == IDOK)
	{
		CString filename,name;

		filename = dlg.GetFileName ();
		name = "content\\audio\\";
		name += filename;
		effdata->Sample (name);
		m_Sound = name;
		UpdateData (FALSE);
	}
	SetCurrentDirectory (dir);
}

void CEffectEditDlg::OnDatastartrun()
{
	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	
	switch (m_DataStartRunning.GetCheck ())
	{
		case 0:
			effdata->StartRunning ("no");
			break;
		case 1:
			effdata->StartRunning ("yes");
			break;
		case 2:
			effdata->StartRunning ("yes");
			break;
	}
}

void CEffectEditDlg::OnSelchangingEffectlist(NMHDR* pNMHDR, LRESULT* pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here

	*pResult = 0;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
}

void CEffectEditDlg::OnFog()
{
	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	switch (m_Fog.GetCheck ())
	{
		case 0:
			effdata->Fog ("no");
			break;
		case 1:
			effdata->Fog ("yes");
			break;
		case 2:
			effdata->Fog ("yes");
			break;
	}
}

void CEffectEditDlg::OnLoop()
{
	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	switch (m_Loop.GetCheck ())
	{
		case 0:
			effdata->Loop ("0");
			break;
		case 1:
			effdata->Loop ("1");
			break;
		case 2:
			effdata->Loop ("1");
			break;
	}
}

void CEffectEditDlg::OnUpdateMaxrangeedit()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.

	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	if (!m_EffectList.m_hWnd)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;

	UpdateData (TRUE);
	char fred[255];
	sprintf (fred,"%f",m_MaxRange);
	effdata->MaxRange (fred);
}

void CEffectEditDlg::OnUpdateMinrangeedit()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.

	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	if (!m_EffectList.m_hWnd)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	UpdateData (TRUE);
	char fred[255];
	sprintf (fred,"%f",m_MinRange);
	effdata->MinRange (fred);
}

void CEffectEditDlg::OnUpdateTransx()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.

	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	if (!m_EffectList.m_hWnd)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	UpdateData (TRUE);
	char fred[255];
	sprintf (fred,"%f %f %f",m_TransX,m_TransY,m_TransZ);
	effdata->Translation (fred);
}

void CEffectEditDlg::OnUpdateTransy()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.

	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	if (!m_EffectList.m_hWnd)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	UpdateData (TRUE);
	char fred[255];
	sprintf (fred,"%f %f %f",m_TransX,m_TransY,m_TransZ);
	effdata->Translation (fred);
}

void CEffectEditDlg::OnUpdateTransz()
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.

	// TODO: Add your control notification handler code here
	if (m_Locked)
		return;
	if (!m_EffectList.m_hWnd)
		return;
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CEffectData *effdata;
	effdata = dynamic_cast<CEffectData *> (data);
	if (!effdata)
		return;
	UpdateData (TRUE);
	char fred[255];
	sprintf (fred,"%f %f %f",m_TransX,m_TransY,m_TransZ);
	effdata->Translation (fred);
}


void CEffectEditDlg::OnContent()
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg (TRUE,"contents",NULL,OFN_CREATEPROMPT,"Content Files (*.contents)|*.contents||",this);
	dlg.m_ofn.lpstrInitialDir = "content\\effects";
	char dir[MAX_PATH];
	GetCurrentDirectory (MAX_PATH-1,dir);

	if (dlg.DoModal () == IDOK)
	{
		CString filename,name,path;
		CString foldername;

		filename = dlg.GetFileName ();
		path = dlg.GetPathName ();

		int index;
		path.MakeLower ();
		index = path.Find ("content");
		if (index == -1)
			return;
		path = path.Right (path.GetLength () - index);
		index = path.ReverseFind ('\\');
		if (index != -1)
		{
			path = path.Left (index);
		}
		index = path.Find ("effects");
		if (index == -1)
			return;
		foldername = path.Right (path.GetLength () - index - 7);		// 7 is length of effects string
		index = foldername.Find (filename);
		if (index != -1)
		{
			foldername = foldername.Left (index);
		}

		index = filename.ReverseFind ('.');
		if (index != -1)
		{
			filename = filename.Left (index);
		}
		filename += ".contents";
		CContentData *data;
		data = new CContentData (path);
		data->InitialData (filename);

		HTREEITEM item,root;

		root = InsertEffectFolder (foldername,m_EffectList);
		if (root == NULL)
		{
			MessageBox ("Unable to add item to tree control","error",MB_OK);
			delete data;
			return;
		}
		item = m_EffectList.InsertItem (filename,root);
		m_EffectList.SetItemData (item,(DWORD) data);
		m_EffectList.Expand (root,TVE_EXPAND);
		m_EffectList.SelectItem (item);
	}
	SetCurrentDirectory (dir);
}

void CEffectEditDlg::HandleContentClick (int id)
{
	if (m_Locked)
	{
		return;
	}
	id -= 1;			// id's from mfc are 1 based
	HTREEITEM item;
	item = m_EffectList.GetSelectedItem ();
	if (!item)
		return;
	CDataBase *data = (CDataBase *) m_EffectList.GetItemData (item);
	if (!data)
		return;
	CContentData *contdata;
	contdata = dynamic_cast<CContentData *> (data);
	if (!contdata)
		return;

	// TODO: Add your control notification handler code here
	CFileDialog dlg (TRUE,"data",NULL,OFN_CREATEPROMPT,"Effect Files (*.data)|*.data||",this);
	dlg.m_ofn.lpstrInitialDir = "content\\effects";
	char dir[MAX_PATH];
	GetCurrentDirectory (MAX_PATH-1,dir);

	if (dlg.DoModal () == IDOK)
	{
		CString filename,name,path;
		CString foldername;
		CString videoname;

		filename = dlg.GetFileName ();
		path = dlg.GetPathName ();
		StripPathFolder (path,foldername);

		int index;

		index = filename.ReverseFind ('.');
		if (index != -1)
		{
			filename = filename.Left (index);
		}
		filename += ".data";


		HTREEITEM item,root;
		root = InsertEffectFolder (foldername,m_EffectList);
		if (root == NULL)
		{
			MessageBox ("Unable to add item to tree control","error",MB_OK);
			return;
		}
		item = InsertEffectItem (filename,m_EffectList,root);

		CDataBase *data;
		data = (CDataBase *) m_EffectList.GetItemData (item);
		if (!data)
		{
			CEffectData *data;
			data = new CEffectData (path);
			data->InitialData (filename);
			m_EffectList.SetItemData (item,(DWORD) data);
		}

		m_EffectList.Expand (root,TVE_EXPAND);
		name = path;
		name += "\\";
		name += filename;
		contdata->EffectName (name,id);
		m_ContentEntry[id] = contdata->EffectName (id);
	}
	UpdateData (FALSE);
	SetCurrentDirectory (dir);
}

void CEffectEditDlg::OnContselect1()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (1);
}

void CEffectEditDlg::OnContselect2()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (2);
	
}

void CEffectEditDlg::OnContselect3()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (3);
	
}
void CEffectEditDlg::OnContselect4()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (4);
	
}

void CEffectEditDlg::OnContselect5()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (5);
	
}

void CEffectEditDlg::OnContselect6()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (6);
	
}

void CEffectEditDlg::OnContselect7()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (7);
	
}

void CEffectEditDlg::OnContselect8()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (8);
	
}

void CEffectEditDlg::OnContselect9()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (9);
	
}

void CEffectEditDlg::OnContselect10()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (10);
}

void CEffectEditDlg::OnContselect11()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (11);
}

void CEffectEditDlg::OnContselect12()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (12);
	
}

void CEffectEditDlg::OnContselect13()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (13);
	
}

void CEffectEditDlg::OnContselect14()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (14);
	
}

void CEffectEditDlg::OnContselect15()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (15);
	
}

void CEffectEditDlg::OnContselect16()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (16);
	
}

void CEffectEditDlg::OnContselect17()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (17);
	
}

void CEffectEditDlg::OnContselect18()
{
	// TODO: Add your control notification handler code here
	HandleContentClick (18);
	
}

