
#include "wx/wx.h"
#include "wx/panel.h"
#include "wx/notebook.h"
#include "wx/toolbook.h"
#include "wx/grid.h"

#include "Consts.h"
#include "Toolkit.h"

#include "NotebookPanels.h"

CNotebookPanelManager::CNotebookPanelManager()
: _ctrlNotebook(NULL)
{
}

CNotebookPanelManager::~CNotebookPanelManager()
{
	DestoryPanels();
}

void CNotebookPanelManager::DestoryPanels()
{
}

int CNotebookPanelManager::InitPanels(wxToolbook *notebook)
{
	_ctrlNotebook = notebook;

	return 0;
}

CNotebookPanel* CNotebookPanelManager::ShowPanel(PanelType type, bool show, bool selected)
{
	if(_ctrlNotebook == NULL)
		return NULL;

	TPanelMap::iterator it = _mapPanel.find(type);
	if(show)
	{
		CNotebookPanel* panel = NULL;
		if(it == _mapPanel.end())
		{
			switch(type)
			{
			case PT_INFO:
				panel = new CNotebookInfoPanel(_ctrlNotebook);
				break;
			case PT_DATA:
				panel = new CNotebookDataPanel(_ctrlNotebook);
				break;
			case PT_DBC:
				panel = new CNotebookDBCPanel(_ctrlNotebook);
				break;
			case PT_BLP:
				panel = new CNotebookBLPPanel(_ctrlNotebook);
				break;
			case PT_WAVE:
				panel = new CNotebookWavePanel(_ctrlNotebook);
				break;
			default:
				return NULL;
			}
			panel->InitControls();
			_ctrlNotebook->AddPage(panel, panel->m_strTitle, false, panel->m_iImageID);
			PanelData_t data(_ctrlNotebook->GetPageCount() - 1, panel);
			it = _mapPanel.insert(std::make_pair(type, data)).first;
		}
		if(selected)
			_ctrlNotebook->SetSelection(it->second.m_szPos);
		return it->second.m_objPanel;
	}
	else
	{
		if(it != _mapPanel.end())
		{
			_ctrlNotebook->DeletePage(it->second.m_szPos);
			//delete it->second.m_objPanel;
			_mapPanel.erase(it);
		}
	}
	return NULL;
}

CNotebookPanel* CNotebookPanelManager::GetPanel(PanelType type)
{
	if(_ctrlNotebook == NULL)
		return NULL;

	TPanelMap::iterator it = _mapPanel.find(type);
	if(it == _mapPanel.end())
		return NULL;

	return it->second.m_objPanel;
}

////

CNotebookPanel::CNotebookPanel(wxWindow* parent, PanelType type, const wxString& title, int image, int id)
: wxPanel(parent, id)
, m_eType(type)
, m_strTitle(title)
, m_iImageID(image)
{
}

CNotebookPanel::~CNotebookPanel()
{
}

int CNotebookPanel::InitControls()
{
	if(CreatePanelControls() == 0 && SetPanelControls() == 0)
		return 0;

	return -1;
}

////
CNotebookInfoPanel::CNotebookInfoPanel(wxWindow* parent)
: CNotebookPanel(parent, PT_INFO, wxT("Information"), 0)
{
}

CNotebookInfoPanel::~CNotebookInfoPanel()
{
}

int CNotebookInfoPanel::CreatePanelControls()
{
    sizer_16_staticbox = new wxStaticBox(this, -1, wxEmptyString);
	sizer_6_staticbox = new wxStaticBox(this, -1, wxEmptyString);

    m_labelFileName = new wxStaticText(this, wxID_ANY, wxEmptyString);

	label_8 = new wxStaticText(this, wxID_ANY, wxT("FileName : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoFileName = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_9 = new wxStaticText(this, wxID_ANY, wxT("Offset : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoOffset = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_10 = new wxStaticText(this, wxID_ANY, wxT("Version : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoVersion = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_11 = new wxStaticText(this, wxID_ANY, wxT("Size : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoSize = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_12 = new wxStaticText(this, wxID_ANY, wxT("Flag : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoFlag = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_13 = new wxStaticText(this, wxID_ANY, wxT("Index : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoIndex = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_14 = new wxStaticText(this, wxID_ANY, wxT("CompSize : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editInfoCompSize = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    m_btnInfoExport = new wxButton(this, IDB_DATA_EXPORT, wxT("Export ..."));
    panel_1 = new wxPanel(this, wxID_ANY);

	return 0;
}

int CNotebookInfoPanel::SetPanelControls()
{
    wxBoxSizer* sizer_5 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_6 = new wxStaticBoxSizer(sizer_6_staticbox, wxHORIZONTAL);
    wxBoxSizer* sizer_7 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_14 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_13 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_12 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_11 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_10 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_9 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);

    wxStaticBoxSizer* sizer_16 = new wxStaticBoxSizer(sizer_16_staticbox, wxHORIZONTAL);


    sizer_16->Add(m_labelFileName, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
    sizer_5->Add(sizer_16, 0, wxEXPAND, 0);

	sizer_8->Add(label_8, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_8->Add(m_editInfoFileName, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_8, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_9->Add(label_9, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_9->Add(m_editInfoOffset, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_9, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_10->Add(label_10, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_10->Add(m_editInfoVersion, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_10, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_11->Add(label_11, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_11->Add(m_editInfoSize, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_11, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_12->Add(label_12, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_12->Add(m_editInfoFlag, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_12, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_13->Add(label_13, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_13->Add(m_editInfoIndex, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_13, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_14->Add(label_14, 2, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
    sizer_14->Add(m_editInfoCompSize, 8, wxRIGHT, 16);
    sizer_7->Add(sizer_14, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_6->Add(sizer_7, 1, wxEXPAND, 0);
    sizer_5->Add(sizer_6, 0, wxEXPAND, 0);
    sizer_5->Add(m_btnInfoExport, 0, wxTOP|wxBOTTOM|wxEXPAND, 4);
    sizer_5->Add(panel_1, 1, wxEXPAND, 0);
    this->SetSizer(sizer_5);

	this->Layout();

	return 0;
}

void CNotebookInfoPanel::DisplayInfo(const MPQData::TFileData *data)
{
	if(data == NULL)
	{
		m_btnInfoExport->Disable();
	}
	else
	{
		m_labelFileName->SetLabel(Toolkit::String2wxString(data->m_strName));
		m_editInfoFileName->SetValue(Toolkit::String2wxString(data->m_strName));
		wxString str;
		str.sprintf(wxT("0x%X"), data->m_pPointer);
		m_editInfoOffset->SetValue(str);
		str.sprintf(wxT("0x%X"), data->m_uiVersion); 
		m_editInfoVersion->SetValue(str);
		str.sprintf(wxT("%d Bytes"), data->m_uiSize);
		m_editInfoSize->SetValue(str);
		str.sprintf(wxT("0x%X"), data->m_uiFlag);
		m_editInfoFlag->SetValue(str);
		str.sprintf(wxT("0x%X"), data->m_uiIndex);
		m_editInfoIndex->SetValue(str);
		str.sprintf(wxT("%d Bytes"), data->m_uiCompSize);
		m_editInfoCompSize->SetValue(str);

		m_btnInfoExport->Enable();
	}
}

////

CNotebookDataPanel::CNotebookDataPanel(wxWindow* parent)
: CNotebookPanel(parent, PT_DATA, wxT("Data Dump"), 0)
{
}

CNotebookDataPanel::~CNotebookDataPanel()
{
}

int CNotebookDataPanel::CreatePanelControls()
{
	sizer_15_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    m_labelDataFileName = new wxStaticText(this, wxID_ANY, wxEmptyString);
    m_ctrlDataText = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL);

	return 0;
}

int CNotebookDataPanel::SetPanelControls()
{
    wxBoxSizer* sizer_4 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_15 = new wxStaticBoxSizer(sizer_15_staticbox, wxHORIZONTAL);
 
	sizer_15->Add(m_labelDataFileName, 0, wxEXPAND|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
    sizer_4->Add(sizer_15, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_4->Add(m_ctrlDataText, 1, wxEXPAND, 0);
    this->SetSizer(sizer_4);

	m_labelDataFileName->SetLabel(wxT(""));
    m_ctrlDataText->SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, wxT("Courier New")));

	this->Layout();

	return 0;
}

bool CNotebookDataPanel::CheckDataFileName(const wxString& file) const
{
	return file == m_labelDataFileName->GetLabel();
}

void CNotebookDataPanel::SetFileName(const wxString& str)
{
	m_labelDataFileName->SetLabel(str);
}

void CNotebookDataPanel::Refresh(const wxString& str)
{
	m_labelDataFileName->SetLabel(str);
	m_ctrlDataText->Clear();
}

void CNotebookDataPanel::AppendEnd()
{
	m_ctrlDataText->ShowPosition(0);
}

void CNotebookDataPanel::AppendData(const wxString& str)
{
	m_ctrlDataText->AppendText(str);
}

////

CNotebookDBCPanel::CNotebookDBCPanel(wxWindow* parent)
: CNotebookPanel(parent, PT_DBC, wxT("DBC"), 0)
{
}

CNotebookDBCPanel::~CNotebookDBCPanel()
{
}

int CNotebookDBCPanel::CreatePanelControls()
{
    sizer_6_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    sizer_3_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    m_labelFileName = new wxStaticText(this, wxID_ANY, wxEmptyString);
    label_6 = new wxStaticText(this, wxID_ANY, wxT("Signature:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editSignature = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_8 = new wxStaticText(this, wxID_ANY, wxT("Records:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editRecords = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_9 = new wxStaticText(this, wxID_ANY, wxT("Fields:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editFields = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_7 = new wxStaticText(this, wxID_ANY, wxT("Record Size:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editRecordSize = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_10 = new wxStaticText(this, wxID_ANY, wxT("String Size:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    m_editStringSize = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    panel_2 = new wxPanel(this, wxID_ANY);
    panel_3 = new wxPanel(this, wxID_ANY);
    m_ctrlGrid = new wxGrid(this, wxID_ANY);

	return 0;
}

int CNotebookDBCPanel::SetPanelControls()
{
	wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_6 = new wxStaticBoxSizer(sizer_6_staticbox, wxVERTICAL);
    wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_7 = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(sizer_3_staticbox, wxHORIZONTAL);
    sizer_3->Add(m_labelFileName, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
    sizer_2->Add(sizer_3, 0, wxEXPAND, 0);
    sizer_7->Add(label_6, 4, wxALIGN_CENTER_VERTICAL, 0);
    sizer_7->Add(m_editSignature, 5, wxEXPAND, 0);
    sizer_7->Add(label_8, 4, wxALIGN_CENTER_VERTICAL, 0);
    sizer_7->Add(m_editRecords, 5, wxEXPAND, 0);
    sizer_7->Add(label_9, 4, wxALIGN_CENTER_VERTICAL, 0);
    sizer_7->Add(m_editFields, 5, wxEXPAND, 0);
    sizer_6->Add(sizer_7, 0, wxTOP|wxBOTTOM|wxEXPAND, 2);
    sizer_8->Add(label_7, 4, wxALIGN_CENTER_VERTICAL, 0);
    sizer_8->Add(m_editRecordSize, 5, wxEXPAND, 0);
    sizer_8->Add(label_10, 4, wxALIGN_CENTER_VERTICAL, 0);
    sizer_8->Add(m_editStringSize, 5, wxEXPAND, 0);
    sizer_8->Add(panel_2, 4, wxEXPAND, 0);
    sizer_8->Add(panel_3, 5, wxEXPAND, 0);
    sizer_6->Add(sizer_8, 0, wxEXPAND, 2);
    sizer_2->Add(sizer_6, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_2->Add(m_ctrlGrid, 1, wxEXPAND, 0);
    this->SetSizer(sizer_2);

    m_ctrlGrid->CreateGrid(0, 0,wxGrid::wxGridSelectRows);
    m_ctrlGrid->EnableEditing(false);
    m_ctrlGrid->SetGridLineColour(wxColour(0, 0, 255));
//    m_ctrlGrid->SetColLabelValue(0, wxEmptyString);

	this->Layout();

	return 0;
}

void CNotebookDBCPanel::SetFileName(const wxString &str)
{
	m_labelFileName->SetLabel(str);
}

void CNotebookDBCPanel::SetHeaderInfo(const MPQData::CDBCHeader &header)
{
	wxString str;
	str.sprintf(wxT("%c%c%c%c"), header.m_acSignature[0], header.m_acSignature[1], header.m_acSignature[2], header.m_acSignature[3]);
	m_editSignature->SetValue(str);
	str.sprintf(wxT("%d"), header.m_iRecords);
	m_editRecords->SetValue(str);
	str.sprintf(wxT("%d"), header.m_iFields);
	m_editFields->SetValue(str);
	str.sprintf(wxT("%d"), header.m_iRecordSize);
	m_editRecordSize->SetValue(str);
	str.sprintf(wxT("%d"), header.m_iBlockSize);
	m_editStringSize->SetValue(str);
}

void CNotebookDBCPanel::InitGrid(int fields, const CMPQDBCFieldManager::TFieldMap* mapField)
{
	m_ctrlGrid->ClearGrid();
	if(m_ctrlGrid->GetNumberCols() > 0)
		m_ctrlGrid->DeleteCols(0, m_ctrlGrid->GetNumberCols());
	if(m_ctrlGrid->GetNumberRows() > 0)
		m_ctrlGrid->DeleteRows(0, m_ctrlGrid->GetNumberRows());
	m_ctrlGrid->AppendCols(fields);
	if(mapField != NULL)
	{
		for(CMPQDBCFieldManager::TFieldMap::const_iterator it = mapField->begin(); it != mapField->end(); ++ it)
		{
			if(it->first < fields)
			{
				m_ctrlGrid->SetColLabelValue(it->first, Toolkit::String2wxString(it->second->m_strTitle));
			}
		}
	}
}

void CNotebookDBCPanel::AppendRow()
{
	m_ctrlGrid->AppendRows(1);
}

void CNotebookDBCPanel::SetGridData(int row, int col, const wxString& data)
{
	m_ctrlGrid->SetCellValue(row, col, data);
}
////

BEGIN_EVENT_TABLE(CNotebookBLPPanel::CScrolledBitmapCanvas, wxScrolledWindow)
    EVT_PAINT(CNotebookBLPPanel::CScrolledBitmapCanvas::OnPaint)
END_EVENT_TABLE()

CNotebookBLPPanel::CScrolledBitmapCanvas::CScrolledBitmapCanvas(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
: wxScrolledWindow(parent, id, pos, size)
{
}

CNotebookBLPPanel::CScrolledBitmapCanvas::~CScrolledBitmapCanvas()
{
}

int CNotebookBLPPanel::CScrolledBitmapCanvas::InitPNGHandler()
{
	//wxPNGHandler handler;
	//wxImage image;
	//image.AddHandler(&handler);
	return 0;
}

void CNotebookBLPPanel::CScrolledBitmapCanvas::OnPaint(wxPaintEvent &event)
{
	if(_bitmapPNG.Ok())
	{
		wxPaintDC dc(this);
		PrepareDC(dc);

		dc.DrawBitmap(_bitmapPNG, 0, 0);
	}
	event.Skip();
}

int CNotebookBLPPanel::CScrolledBitmapCanvas::SetBitmap(const wxString& file, wxSize& size)
{
	if(!_bitmapPNG.LoadFile(file, wxBITMAP_TYPE_PNG))
		return -1;
	size.Set(_bitmapPNG.GetWidth(), _bitmapPNG.GetHeight());
	return 0;
}

CNotebookBLPPanel::CNotebookBLPPanel(wxWindow* parent)
: CNotebookPanel(parent, PT_BLP, wxT("BLP"), 0)
{
}

CNotebookBLPPanel::~CNotebookBLPPanel()
{
}

int CNotebookBLPPanel::CreatePanelControls()
{
    sizer_3_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    m_labelFileName = new wxStaticText(this, wxID_ANY, wxEmptyString);
    m_canvasBitmap = new CScrolledBitmapCanvas(this, IDC_NB_BLP_BITMAPCANVAS, wxPoint(0, 0), wxSize(-1, -1));
	m_canvasBitmap->InitPNGHandler();

	return 0;
}

int CNotebookBLPPanel::SetPanelControls()
{
	wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_3 = new wxStaticBoxSizer(sizer_3_staticbox, wxHORIZONTAL);
    sizer_3->Add(m_labelFileName, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
	sizer_2->Add(sizer_3, 0, wxBOTTOM|wxEXPAND, 4);
    sizer_2->Add(m_canvasBitmap, 1, wxEXPAND, 0);
    this->SetSizer(sizer_2);

	this->Layout();

	return 0;
}

void CNotebookBLPPanel::SetFileName(const wxString &str)
{
	m_labelFileName->SetLabel(str);
}

int CNotebookBLPPanel::ShowImage(const wxString& file)
{
	wxSize size(0, 0);
	if(m_canvasBitmap->SetBitmap(file, size) != 0)
		return -1;

	m_canvasBitmap->SetScrollbars(1, 1, size.GetWidth(), size.GetHeight());

	return 0;
}
//////

BEGIN_EVENT_TABLE(CNotebookWavePanel, wxPanel)
    // begin wxGlade: CNotebookWavePanel::event_table
    EVT_BUTTON(IDC_NB_WAVE_BUTTON_PLAY, CNotebookWavePanel::OnBtnPlay)
    EVT_BUTTON(IDC_NB_WAVE_BUTTON_PAUSE, CNotebookWavePanel::OnBtnPause)
    EVT_BUTTON(IDC_NB_WAVE_BUTTON_STOP, CNotebookWavePanel::OnBtnStop)
    // end wxGlade
END_EVENT_TABLE();

CNotebookWavePanel::CNotebookWavePanel(wxWindow *parent)
: CNotebookPanel(parent, PT_WAVE, wxT("Wave"), 0)
, _objDSound(NULL)
{
}

CNotebookWavePanel::~CNotebookWavePanel()
{
	Release();
}

int CNotebookWavePanel::CreatePanelControls()
{
    sizer_24_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    sizer_23_staticbox = new wxStaticBox(this, -1, wxEmptyString);
    m_labelFileName = new wxStaticText(this, wxID_ANY, wxEmptyString);
    m_ctrlSlider = new wxSlider(this, wxID_ANY, 0, 0, 0, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_AUTOTICKS|wxSL_LABELS|wxSL_TOP);
    panel_4 = new wxPanel(this, wxID_ANY);
    m_btnPlay = new wxButton(this, IDC_NB_WAVE_BUTTON_PLAY, wxT("&Play"));
    m_btnPause = new wxButton(this, IDC_NB_WAVE_BUTTON_PAUSE, wxT("P&ause"));
    m_btnStop = new wxButton(this, IDC_NB_WAVE_BUTTON_STOP, wxT("&Stop"));
    panel_5 = new wxPanel(this, wxID_ANY);
    panel_6 = new wxPanel(this, wxID_ANY);

	return 0;
}

int CNotebookWavePanel::SetPanelControls()
{
   wxBoxSizer* sizer_21 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_22 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_24 = new wxStaticBoxSizer(sizer_24_staticbox, wxVERTICAL);
    wxBoxSizer* sizer_25 = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_23 = new wxStaticBoxSizer(sizer_23_staticbox, wxHORIZONTAL);
    sizer_23->Add(m_labelFileName, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
    sizer_22->Add(sizer_23, 0, wxEXPAND, 0);
    sizer_24->Add(m_ctrlSlider, 0, wxLEFT|wxRIGHT|wxEXPAND, 16);
    sizer_25->Add(panel_4, 1, wxEXPAND, 0);
    sizer_25->Add(m_btnPlay, 0, wxLEFT|wxRIGHT, 4);
    sizer_25->Add(m_btnPause, 0, wxLEFT|wxRIGHT, 4);
    sizer_25->Add(m_btnStop, 0, wxLEFT|wxRIGHT, 4);
    sizer_25->Add(panel_5, 1, wxEXPAND, 0);
    sizer_24->Add(sizer_25, 1, wxEXPAND, 0);
    sizer_22->Add(sizer_24, 0, wxEXPAND, 0);
    sizer_22->Add(panel_6, 1, wxEXPAND, 0);
    this->SetSizer(sizer_22);
    this->Layout();

	return 0;
}

void CNotebookWavePanel::Release()
{
	if(_objDSound != NULL)
		delete _objDSound, _objDSound = NULL;
}

void CNotebookWavePanel::OnBtnPlay(wxCommandEvent &event)
{
	Play();
    event.Skip();
}


void CNotebookWavePanel::OnBtnPause(wxCommandEvent &event)
{
	Pause();
    event.Skip();
}

void CNotebookWavePanel::OnBtnStop(wxCommandEvent &event)
{
	Stop();
    event.Skip();
}

void CNotebookWavePanel::SetFileName(const wxString &str)
{
	m_labelFileName->SetLabel(str);
}

int CNotebookWavePanel::LoadWaveFile(const wxString& file)
{
	Release();

	_objDSound = new CDSWaveObject();
	_objDSound->Init((HWND)this->GetHandle());
	_objDSound->LoadFile(Toolkit::wxString2String(file));

	ShowInfo();
	
	_objDSound->Play();

	return 0;
}

int CNotebookWavePanel::LoadMP3File(const wxString& file)
{
	return -1;
}

int CNotebookWavePanel::Play()
{
	_objDSound->Play();
	return 0;
}

int CNotebookWavePanel::Pause()
{
	_objDSound->Pause();
	return 0;
}

int CNotebookWavePanel::Stop()
{
	_objDSound->Stop();
	return 0;
}

int CNotebookWavePanel::ShowInfo()
{
	size_t duration = _objDSound->Duration();

	m_ctrlSlider->SetMin(0);
	m_ctrlSlider->SetMax(duration);
	m_ctrlSlider->SetTickFreq(500, 0);

	return 0;
}