/////////////////////////////////////////////////////////////////////////////
// Name:        viewerpanel.h
// Purpose:     wxPackageViewerPanel definition
// Author:      Julian Smart, Francesco Montorsi
// Modified by:
// Created:     07/06/2006 00:24:55
// RCS-ID:      $Id: viewerpanel.h,v 1.2 2007/01/01 20:06:20 frm Exp $
// Copyright:   (c) 2004 Francesco Montorsi
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////

#ifndef _PMVIEWERPANEL_H_
#define _PMVIEWERPANEL_H_


/*!
 * Includes
 */

#include "wx/notebook.h"
#include "wx/html/htmlwin.h"
#include "wxp/package.h"
#include "guipm/taskpanel.h"


/*!
 * Forward declarations
 */

class wxNotebook;
class wxHtmlWindow;
class wxHtmlHelpController;
class wxHtmlHelpWindow;
class wxWebBrowserWindow;
class wxConfigBase;


/*!
 * Control identifiers
 */

////@begin control identifiers
#define SYMBOL_WXPACKAGEVIEWERPANEL_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
#define SYMBOL_WXPACKAGEVIEWERPANEL_TITLE _("Dialog")
#define SYMBOL_WXPACKAGEVIEWERPANEL_IDNAME wxID_ANY
#define SYMBOL_WXPACKAGEVIEWERPANEL_SIZE wxSize(400, 300)
#define SYMBOL_WXPACKAGEVIEWERPANEL_POSITION wxDefaultPosition
#define ID_VIEWER_NOTEBOOK 10024
#define ID_VIEWER_SUMMARY 10027
#define ID_VIEWER_DETAILS 10025
////@end control identifiers

#ifdef __WXMSW__
    #define wxPM_HAS_EMBEDDED_BROWSER   1
#else
    #define wxPM_HAS_EMBEDDED_BROWSER   0
#endif



// ----------------------------------------------------------------------------
// wxPackageViewerPanel
// ----------------------------------------------------------------------------

class wxPackageViewerPanel: public wxPanel
{
    DECLARE_DYNAMIC_CLASS( wxPackageViewerPanel )
    DECLARE_EVENT_TABLE()

public:
    /// Constructors
    wxPackageViewerPanel( );
    wxPackageViewerPanel( wxWindow* parent, wxWindowID id = SYMBOL_WXPACKAGEVIEWERPANEL_IDNAME, const wxPoint& pos = SYMBOL_WXPACKAGEVIEWERPANEL_POSITION, const wxSize& size = SYMBOL_WXPACKAGEVIEWERPANEL_SIZE, long style = SYMBOL_WXPACKAGEVIEWERPANEL_STYLE );
    ~wxPackageViewerPanel();

    /// Creation
    bool Create( wxWindow* parent, wxWindowID id = SYMBOL_WXPACKAGEVIEWERPANEL_IDNAME, const wxPoint& pos = SYMBOL_WXPACKAGEVIEWERPANEL_POSITION, const wxSize& size = SYMBOL_WXPACKAGEVIEWERPANEL_SIZE, long style = SYMBOL_WXPACKAGEVIEWERPANEL_STYLE );

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

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


public:     // setters

    void SetPackage(const wxPackage &p)
        { m_arrPkg.Clear(); m_arrPkg.Add(p); UpdateSummaryAndDesc(); }
    void SetPackages(const wxPackageArray &arr)
        { m_arrPkg=arr; UpdateSummaryAndDesc(); }

    void UpdateSummaryAndDesc();

    void Reset();

    void SelectSummaryPage()
        { m_pNotebook->ChangeSelection(0); }
    void SelectDetailsPage()
        { m_pNotebook->ChangeSelection(1); }
    void SelectReferencePage()
        { m_pNotebook->ChangeSelection(2); }

    void SelectDownloadQueuePanel()
        { m_pNotebook->ChangeSelection(3); }
    void SelectTaskQueuePage()
        { m_pNotebook->ChangeSelection(4); }

    void SetViewMode(const wxString &name)
    {
        m_strViewModeName = name;
        m_viewMode = wxPackageInfo::s_hashmapHTMLFormats[name];
        wxASSERT(m_viewMode != wxEmptyPackageHTMLOutputFormat);
        UpdateSummaryAndDesc();
    }

public:     // getters

    bool IsOk() const;

    wxPackageCommandQueuePanel *GetTaskQueuePanel()
        { return m_pTaskQueuePanel; }
    wxPackageDownloadQueuePanel *GetDownloadQueuePanel()
        { return m_pDownloadQueuePanel; }

    wxHtmlHelpWindow* GetEmbeddedHelpWindow() const
        { return m_embeddedHelpWindow ; }
    wxHtmlHelpController* GetEmbeddedHelpController() const
        { return m_embeddedHelpController ; }

#if wxPM_HAS_EMBEDDED_BROWSER
    void SelectBrowserPage()
        { m_pNotebook->ChangeSelection(5); }
    wxWebBrowserWindow *GetBrowser()
        { return (wxWebBrowserWindow *)m_pNotebook->GetPage(5); }
#endif

    wxPackageHTMLOutputFormat GetViewMode() const
        { return m_viewMode; }
    wxString GetViewModeName() const
        { return m_strViewModeName; }

    wxArrayString &GetDocs()
        { return m_arrDocs; }

public:     // load/save

    bool Load(wxConfigBase *, const wxString &path);
    void Save(wxConfigBase *, const wxString &path) const;

    bool LoadViewFormats();

protected:      // internal utilities

    void InitReference();

public:     // event handlers

    void OnLinkClicked(wxHtmlLinkEvent &ev);
    void OnPageChanged(wxNotebookEvent &ev);

protected:  // controls

    wxHtmlWindow *m_pSummaryHtmlWin, *m_pDetailsHtmlWin;
    wxNotebook* m_pNotebook;

    wxHtmlHelpWindow* m_embeddedHelpWindow;
    wxHtmlHelpController* m_embeddedHelpController;

    wxPackageDownloadQueuePanel *m_pDownloadQueuePanel;
    wxPackageCommandQueuePanel *m_pTaskQueuePanel;

protected:  // member variables

    /// List of files to load in the Reference tab.
    wxArrayString m_arrDocs;

    /// The current view mode.
    wxPackageHTMLOutputFormat m_viewMode;
    wxString m_strViewModeName;

    /// Messages shown when no packages are selected.
    wxString m_strDefaultSummary, m_strDefaultDetails;

    /// The packages info currently shown.
    wxPackageArray m_arrPkg;
};

#endif
    // _PMVIEWERPANEL_H_
