// Options.cpp : implementation file
//

#include "stdafx.h"
#include "Osmo4.h"
#include "Options.h"
#include <gx.h>

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

/////////////////////////////////////////////////////////////////////////////
// COptions dialog


COptions::COptions(CWnd* pParent /*=NULL*/)
	: CDialog(COptions::IDD, pParent)
{
	//{{AFX_DATA_INIT(COptions)
	//}}AFX_DATA_INIT
}


void COptions::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COptions)
	DDX_Control(pDX, IDC_COMBOSEL, m_Selection);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COptions, CDialog)
	//{{AFX_MSG_MAP(COptions)
	ON_BN_CLICKED(IDC_SAVEOPT, OnSaveopt)
	ON_CBN_SELCHANGE(IDC_COMBOSEL, OnSelchangeCombosel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COptions message handlers


void COptions::OnSelchangeCombosel() 
{
	HideAll();
	switch (m_Selection.GetCurSel()) {
	case 0: m_general.ShowWindow(SW_SHOW); break;
	case 1: m_systems.ShowWindow(SW_SHOW); break;
	case 2: m_decoder.ShowWindow(SW_SHOW); break;
	case 3: m_render.ShowWindow(SW_SHOW); break;
	case 4: m_audio.ShowWindow(SW_SHOW); break;
	case 5: m_font.ShowWindow(SW_SHOW); break;
	case 6: m_http.ShowWindow(SW_SHOW); break;
	case 7: m_stream.ShowWindow(SW_SHOW); break;
	}
}

void COptions::HideAll()
{
	m_general.ShowWindow(SW_HIDE);
	m_systems.ShowWindow(SW_HIDE);
	m_render.ShowWindow(SW_HIDE);
	m_audio.ShowWindow(SW_HIDE);
	m_http.ShowWindow(SW_HIDE);
	m_font.ShowWindow(SW_HIDE);
	m_stream.ShowWindow(SW_HIDE);
	m_decoder.ShowWindow(SW_HIDE);
}

BOOL COptions::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_general.Create(IDD_OPT_GEN, this);
	m_systems.Create(IDD_OPT_SYSTEMS, this);
	m_decoder.Create(IDD_OPT_DECODER, this);
	m_render.Create(IDD_OPT_RENDER, this);
	m_audio.Create(IDD_OPT_AUDIO, this);
	m_http.Create(IDD_OPT_HTTP, this);
	m_font.Create(IDD_OPT_FONT, this);
	m_stream.Create(IDD_OPT_STREAM, this);

	m_Selection.AddString(_T("General"));
	m_Selection.AddString(_T("MPEG-4 Systems"));
	m_Selection.AddString(_T("Decoders"));
	m_Selection.AddString(_T("Rendering"));
	m_Selection.AddString(_T("Audio"));
	m_Selection.AddString(_T("Text"));
	m_Selection.AddString(_T("Download"));
	m_Selection.AddString(_T("Streaming"));
	HideAll();
	m_Selection.SetCurSel(0);
	m_general.ShowWindow(SW_SHOW);

	SetFocus();
	return TRUE;  
}

void COptions::OnSaveopt() 
{
	m_general.SaveOptions();
	m_systems.SaveOptions();
	m_render.SaveOptions();
	m_audio.SaveOptions();
	m_http.SaveOptions();
	m_font.SaveOptions();
	m_stream.SaveOptions();
	m_decoder.SaveOptions();

	COsmo4 *gpac = GetApp();
	M4T_SetOption(gpac->m_term, M4O_ReloadConfig, 1);
}

void COptions::OnOK() 
{
	EndDialog(IDCANCEL);
}

