/////////////////////////////////////////////////////////////////////////////
// Name:        optpresetchooserdlg.cpp
// Purpose:     wxPackageOptionPresetChooserDialog
// Author:      Francesco Montorsi
// Modified by:
// Created:     18/09/2006 23:11:38
// RCS-ID:      $Id: optpresetchooserdlg.cpp,v 1.4 2007/01/27 23:15:36 frm Exp $
// Copyright:   (c) 2006 Francesco Montorsi
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "guipkg/optpresetchooserdlg.h"
#include "guipkg/optlistctrl.h"


// ----------------------------------------------------------------------------
// wxPackageOptionPresetChooserDialog
// ----------------------------------------------------------------------------

IMPLEMENT_DYNAMIC_CLASS( wxPackageOptionPresetChooserDlg, wxDialog )
BEGIN_EVENT_TABLE( wxPackageOptionPresetChooserDlg, wxDialog )
    EVT_CHOICE( ID_OPTPRESETCHOOSER_PRESETS, 
                wxPackageOptionPresetChooserDlg::OnPreset )
END_EVENT_TABLE()

wxPackageOptionPresetChooserDlg::wxPackageOptionPresetChooserDlg( )
{
}

wxPackageOptionPresetChooserDlg::wxPackageOptionPresetChooserDlg( wxWindow* parent, wxWindowID id, wxPackageBuildSystemType type, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Create(parent, id, type, caption, pos, size, style);
}

bool wxPackageOptionPresetChooserDlg::Create( wxWindow* parent, wxWindowID id, wxPackageBuildSystemType type, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin wxPackageOptionPresetChooserDlg member initialisation
    m_pPresets = NULL;
    m_pDescription = NULL;
    m_pPreview = NULL;
////@end wxPackageOptionPresetChooserDlg member initialisation

    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls(type);
    if (GetSizer())
    {
        SetMinSize(GetBestSize().Scale(2.5, 1.0));
        GetSizer()->SetSizeHints(this);
    }
    Centre();
    return true;
}

void wxPackageOptionPresetChooserDlg::CreateControls(wxPackageBuildSystemType type)
{    
////@begin wxPackageOptionPresetChooserDlg content construction
    wxPackageOptionPresetChooserDlg* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW, 5);

    wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Available option presets:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxString* m_pPresetsStrings = NULL;
    m_pPresets = new wxChoice( itemDialog1, ID_OPTPRESETCHOOSER_PRESETS, wxDefaultPosition, wxDefaultSize, 0, m_pPresetsStrings, 0 );
    itemBoxSizer3->Add(m_pPresets, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("Preset description:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer2->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);

    m_pDescription = new wxTextCtrl( itemDialog1, ID_OPTPRESETCHOOSER_DESC, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
    itemBoxSizer2->Add(m_pDescription, 1, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Preset preview:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer2->Add(itemStaticText8, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);

    m_pPreview = new wxOptionListCtrl( itemDialog1, ID_OPTPRESETCHOOSER_PREVIEW, wxDefaultPosition, wxSize(350, 100), 0 );
    itemBoxSizer2->Add(m_pPreview, 3, wxGROW|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer10 = new wxStdDialogButtonSizer;

    itemBoxSizer2->Add(itemStdDialogButtonSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
    wxButton* itemButton11 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer10->AddButton(itemButton11);

    wxButton* itemButton12 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer10->AddButton(itemButton12);

    itemStdDialogButtonSizer10->Realize();

////@end wxPackageOptionPresetChooserDlg content construction

    // init controls with presets suitable for the given build system type
    m_pPresets->Append(wxPresetXMLDescriptor::GetOptionPresetNamesFor(type));

    wxASSERT(m_pPresets->GetCount() > 0);
    m_pPresets->Select(0);

    wxCommandEvent fake;
    OnPreset(fake);
}

bool wxPackageOptionPresetChooserDlg::ShowToolTips()
{
    return true;
}


// ----------------------------------------------------------------------------
// wxPackageOptionPresetChooserDialog - event handlers
// ----------------------------------------------------------------------------

void wxPackageOptionPresetChooserDlg::OnPreset(wxCommandEvent &WXUNUSED(ev))
{
    const wxPackageCommandOptionArray &arr = GetSelectedPreset();

    // update description
    m_pDescription->SetValue(arr.GetDescription());

    // update preview
    m_pPreview->SetOptions(arr);
}

