///////////////////////////////////////////////////////////////////////////////
// Name:        smartmsgdlg.h
// Purpose:     wxSmartMessageDialog definition
// Author:      Francesco Montorsi
// Modified by:
// Created:     10/7/2006
// RCS-ID:      $Id: smartmsgdlg.h,v 1.1.1.1 2006/12/12 09:41:00 frm Exp $
// Copyright:   (c) Francesco Montorsi
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#ifndef _WX_SMARTMSGDLG_H_
#define _WX_SMARTMSGDLG_H_

// includes
#include "wx/msgdlg.h"
#include "wx/config.h"

// for wxStringHashMap
#include "wxp/wxputils.h"



// ----------------------------------------------------------------------------
// wxSmartMessageDialog
// ----------------------------------------------------------------------------

class wxSmartMessageDialog : public wxDialog, public wxMessageDialogBase
{
    friend class wxSmartMessageDialogModule;

    DECLARE_DYNAMIC_CLASS( wxSmartMessageDialog )
    DECLARE_EVENT_TABLE()

public:

    wxSmartMessageDialog(const wxString &keyname);

    bool Create( wxWindow *parent,
                const wxString& message,
                const wxString& caption = wxMessageBoxCaptionStr,
                long style = wxOK | wxCENTRE,
                const wxPoint& pos = wxDefaultPosition);

    ~wxSmartMessageDialog()
    {
        Save();
    }

public:     // event handlers

    void OnYes(wxCommandEvent& WXUNUSED(event));
    void OnNo(wxCommandEvent& WXUNUSED(event));
    void OnCancel(wxCommandEvent& WXUNUSED(event));

public:     // public API

    bool ShowAgain() const
    { 
        if (m_pDoNotShowAgain)
            return !m_pDoNotShowAgain->GetValue(); 
        return m_bShowAgain;        // not created yet!
    }

    void Save()
    {
        m_bShowAgain = ShowAgain();
        SetValueFor(m_strKeyName, m_bShowAgain); 
    }

    void Load()
        { m_bShowAgain = GetValueFor(m_strKeyName); }

public:     // static

    static wxStringHashMap s_hashDesc;


    static wxString GetDescriptionFor(const wxString &keyname)
        { return s_hashDesc[keyname]; }

    static bool GetValueFor(const wxString &keyname)
    {
        bool value = true;
        if (m_pCfg)
            m_pCfg->Read(m_strPath + wxT("/") + keyname, &value);
        return value;
    }

    static void SetValueFor(const wxString &keyname, bool value)
    {
        if (m_pCfg)
            m_pCfg->Write(m_strPath + wxT("/") + keyname, value);
    }

    static void SetConfig(wxConfigBase *cfg, const wxString &path)
        { m_pCfg=cfg; m_strPath=path; }

    static wxConfigBase *GetConfig()
        { return m_pCfg; }

    static wxString GetConfigPath()
        { return m_strPath; }

protected:
    wxCheckBox *m_pDoNotShowAgain;
    wxString m_strKeyName;
    bool m_bShowAgain;

protected:
    static wxConfigBase *m_pCfg;
    static wxString m_strPath;
};


// ----------------------------------------------------------------------------
// wxSmartMessageBox: the simplest way to use wxSmartMessageDialog
// ----------------------------------------------------------------------------

int WXDLLEXPORT wxSmartMessageBox(const wxString &keyname,
                                const wxString& message,
                                const wxString& caption = wxMessageBoxCaptionStr,
                                long style = wxOK | wxCENTRE,
                                wxWindow *parent = NULL);


// ----------------------------------------------------------------------------
// wxSmartLog* family:
// unlike wxLog* family these functions do not put the given text in a queue;
// the text is immediately shown!
// ----------------------------------------------------------------------------

#define DECLARE_SMARTLOG_FUNCTION(level)                                    \
extern int WXDLLIMPEXP_BASE wxSmartVLog##level(const wxChar *keyname,       \
                                                const wxChar *szFormat,     \
                                                va_list argptr);            \
extern int WXDLLIMPEXP_BASE wxSmartLog##level(const wxChar *keyname,        \
                                               const wxChar *szFormat,      \
                                               ...);

DECLARE_SMARTLOG_FUNCTION(Message)
DECLARE_SMARTLOG_FUNCTION(Warning)
DECLARE_SMARTLOG_FUNCTION(Error)
DECLARE_SMARTLOG_FUNCTION(YesNoQuestion)

#endif
    // _WX_SMARTMSGDLG_H_

