/////////////////////////////////////////////////////////////////////////////
// Name:        dependencydlg.h
// Purpose:     wxPackageDependencyDlg definition
// Author:      Francesco Montorsi
// Modified by:
// Created:     29/07/2006 09:48:04
// RCS-ID:      $Id: dependencydlg.h,v 1.2 2007/01/01 20:06:20 frm Exp $
// Copyright:   (c) 2006 Francesco Montorsi
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////

#ifndef _DEPENDENCYDLG_H_
#define _DEPENDENCYDLG_H_

/*!
 * Includes
 */

#include "wxp/packagedep.h"


/*!
 * Forward declarations
 */

class wxPackageDownloadQueuePanel;


/*!
 * Control identifiers
 */

////@begin control identifiers
#define SYMBOL_WXPACKAGEDEPENDENCYDLG_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
#define SYMBOL_WXPACKAGEDEPENDENCYDLG_TITLE _("Package dependencies")
#define SYMBOL_WXPACKAGEDEPENDENCYDLG_IDNAME wxID_ANY
#define SYMBOL_WXPACKAGEDEPENDENCYDLG_SIZE wxSize(400, 300)
#define SYMBOL_WXPACKAGEDEPENDENCYDLG_POSITION wxDefaultPosition
#define ID_DEPENDENCY_REQUIRED_LIST 10060
#define ID_DEPENDENCY_SUGGESTED_LIST 10061
#define ID_DEPENDENCY_NOTINREPO 10064
////@end control identifiers


// ----------------------------------------------------------------------------
// wxPackageDependencyDlg
// ----------------------------------------------------------------------------

class wxPackageDependencyDlg: public wxDialog
{
    DECLARE_DYNAMIC_CLASS( wxPackageDependencyDlg )
    DECLARE_EVENT_TABLE()

public:
    /// Constructors
    wxPackageDependencyDlg( );

    // NO CREATION IS PROVIDED THROUGH CONSTRUCTORS ON PURPOSE;
    // THIS BECAUSE YOU MUST CALL SetPackageArray() BEFORE Create() !

    /// Creation
    bool Create( wxWindow* parent,
                 wxWindowID id = SYMBOL_WXPACKAGEDEPENDENCYDLG_IDNAME,
                 const wxString& caption = SYMBOL_WXPACKAGEDEPENDENCYDLG_TITLE,
                 const wxPoint& pos = SYMBOL_WXPACKAGEDEPENDENCYDLG_POSITION,
                 const wxSize& size = SYMBOL_WXPACKAGEDEPENDENCYDLG_SIZE,
                 long style = SYMBOL_WXPACKAGEDEPENDENCYDLG_STYLE );

    /// Creates the controls and sizers
    void CreateControls();

    /// Should we show tooltips?
    static bool ShowToolTips();

public:     // event handlers

    void OnButton(wxCommandEvent &ev);


public:     // public API

    // must be called *before* Create() !
    bool SetPackageArray(const wxPackageArray &arr,
                         const wxPackageArray &installed,
                         const wxPackageArray &remote);
    bool SetPackage(const wxPackage &pkg,
                    const wxPackageArray &installed,
                    const wxPackageArray &remote);

    bool IsEmpty() const
        { return m_required.IsEmpty() && m_suggested.IsEmpty() && m_notfound.IsEmpty(); }

    // to call to retrieve data:

    void QueueAdditionalPackages(wxPackageDependencyType type,
                                 wxPackageDownloadQueuePanel *panel);

    //! Returns the list of additional packages which should be downloaded.
    //! Only packages which are dependency of the given type
    //! (wxPDT_INVALID means both required and suggested) are returned.
    wxPackageArray GetAdditionalPackages(wxPackageDependencyType t = wxPDT_INVALID) const;


protected:          // internal utils

    void FillListbox(wxListBox *box, const wxPackageDependencyArray &arr,
                     bool useversionrange = false);

    wxPackageArray GetPackagesFromCheckListbox(wxCheckListBox *box,
                                               const wxPackageDependencyArray &arr) const;
protected:      // controls

    wxStaticText* m_pMainMsg;
    wxCheckListBox* m_pRequiredCheckList;
    wxCheckListBox* m_pSuggestedCheckList;
    wxListBox* m_pNotFoundList;
    wxStaticText* m_pQuestionMsg;

protected:

    // the dependencies
    wxPackageDependencyArray m_required, m_suggested, m_notfound;

    // a pointer to remote array of packages given to SetPackage*() function
    const wxPackageArray *m_pRemote;

    // true if the packages given to SetPackage*() functions
    // were all packages already downloaded, false otherwise.
    bool m_bSelectedPackagesAreDownloaded;
};

#endif
    // _DEPENDENCYDLG_H_
