/////////////////////////////////////////////////////////////////////////////
// Name:        depeditdlg.cpp
// Purpose:     wxPackageDependencyEditDlg
// Author:      Francesco Montorsi
// Modified by:
// Created:     Thu 10 Aug 2006 18:22:11 CEST
// RCS-ID:      $Id: depeditdlg.cpp,v 1.2 2007/01/01 20:06:20 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/depeditdlg.h"


// ----------------------------------------------------------------------------
// wxPackageDependencyEditDlg
// ----------------------------------------------------------------------------

IMPLEMENT_DYNAMIC_CLASS( wxPackageDependencyEditDlg, wxDialog )
BEGIN_EVENT_TABLE( wxPackageDependencyEditDlg, wxDialog )
    EVT_BUTTON( wxID_OK, wxPackageDependencyEditDlg::OnOK )
END_EVENT_TABLE()

wxPackageDependencyEditDlg::wxPackageDependencyEditDlg( )
{
}

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

bool wxPackageDependencyEditDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin wxPackageDependencyEditDlg member initialisation
    m_pDepType = NULL;
    m_pName = NULL;
    m_pVersion = NULL;
////@end wxPackageDependencyEditDlg member initialisation

////@begin wxPackageDependencyEditDlg creation
    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end wxPackageDependencyEditDlg creation
    return true;
}

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

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

    wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC, _("Note: if this dependency regards some software which has not\nbeen wx-packaged yet, you should use the \"Suggested\"\ndependency type to make this package usable."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
    itemBoxSizer2->Add(itemStaticText3, 0, wxGROW|wxALL|wxADJUST_MINSIZE, 5);

    wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(2, 2, 0, 0);
    itemFlexGridSizer4->AddGrowableCol(1);
    itemBoxSizer2->Add(itemFlexGridSizer4, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Dependency type:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);

    wxString* m_pDepTypeStrings = NULL;
    m_pDepType = new wxChoice( itemDialog1, ID_DEPEDIT_TYPE, wxDefaultPosition, wxDefaultSize, 0, m_pDepTypeStrings, 0 );
    itemFlexGridSizer4->Add(m_pDepType, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("Name of the package:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer4->Add(itemStaticText7, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);

    m_pName = new wxTextCtrl( itemDialog1, ID_DEPEDIT_NAME, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer4->Add(m_pName, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, wxID_STATIC, _("Version of the package:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer4->Add(itemStaticText9, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);

    m_pVersion = new wxTextCtrl( itemDialog1, ID_DEPEDIT_VERSION, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
    m_pVersion->SetHelpText(_("You can use either the 2.1.0-3.4.2 syntax (i.e. the hyphen separes two version numbers) or the 2.x.x syntax ('x' acts as a wildcard)"));
    if (ShowToolTips())
        m_pVersion->SetToolTip(_("You can use either the 2.1.0-3.4.2 syntax (i.e. the hyphen separes two version numbers) or the 2.x.x syntax ('x' acts as a wildcard)"));
    itemFlexGridSizer4->Add(m_pVersion, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer11 = new wxStdDialogButtonSizer;

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

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

    itemStdDialogButtonSizer11->Realize();

////@end wxPackageDependencyEditDlg content construction

    m_pDepType->Append(wxArrayString(wxPDT_MAX, wxPackageDependencyTypeName));
    m_pDepType->Select(0);
}

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




// ----------------------------------------------------------------------------
// wxPackageDependencyEditDlg - event handlers
// ----------------------------------------------------------------------------

void wxPackageDependencyEditDlg::OnOK(wxCommandEvent &WXUNUSED(ev))
{
    if (m_pName->GetValue().IsEmpty())
    {
        wxLogError(wxT("Please specify the name of the %s package."),
                   m_pDepType->GetSelection() == wxPDT_REQUIRED ? wxT("required") : wxT("suggested"));
        return;
    }

    if (m_pVersion->GetValue().IsEmpty())
    {
        wxLogError(wxT("Please specify the valid versions of the %s package."),
                   m_pName->GetValue().c_str());
        return;
    }
    else if (!wxVersionRange(m_pVersion->GetValue()).IsOk())
    {
        wxLogError(wxT("Invalid version range syntax: %s"),
                   m_pVersion->GetValue().c_str());
        return;
    }

    EndModal(wxID_OK);
}
