smartmsgdlg.h

00001 
00002 // Name:        smartmsgdlg.h
00003 // Purpose:     wxSmartMessageDialog definition
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     10/7/2006
00007 // RCS-ID:      $Id: smartmsgdlg.h,v 1.1.1.1 2006/12/12 09:41:00 frm Exp $
00008 // Copyright:   (c) Francesco Montorsi
00009 // Licence:     wxWindows licence
00011 
00012 #ifndef _WX_SMARTMSGDLG_H_
00013 #define _WX_SMARTMSGDLG_H_
00014 
00015 // includes
00016 #include "wx/msgdlg.h"
00017 #include "wx/config.h"
00018 
00019 // for wxStringHashMap
00020 #include "wxp/wxputils.h"
00021 
00022 
00023 
00024 // ----------------------------------------------------------------------------
00025 // wxSmartMessageDialog
00026 // ----------------------------------------------------------------------------
00027 
00028 class wxSmartMessageDialog : public wxDialog, public wxMessageDialogBase
00029 {
00030     friend class wxSmartMessageDialogModule;
00031 
00032     DECLARE_DYNAMIC_CLASS( wxSmartMessageDialog )
00033     DECLARE_EVENT_TABLE()
00034 
00035 public:
00036 
00037     wxSmartMessageDialog(const wxString &keyname);
00038 
00039     bool Create( wxWindow *parent,
00040                 const wxString& message,
00041                 const wxString& caption = wxMessageBoxCaptionStr,
00042                 long style = wxOK | wxCENTRE,
00043                 const wxPoint& pos = wxDefaultPosition);
00044 
00045     ~wxSmartMessageDialog()
00046     {
00047         Save();
00048     }
00049 
00050 public:     // event handlers
00051 
00052     void OnYes(wxCommandEvent& WXUNUSED(event));
00053     void OnNo(wxCommandEvent& WXUNUSED(event));
00054     void OnCancel(wxCommandEvent& WXUNUSED(event));
00055 
00056 public:     // public API
00057 
00058     bool ShowAgain() const
00059     { 
00060         if (m_pDoNotShowAgain)
00061             return !m_pDoNotShowAgain->GetValue(); 
00062         return m_bShowAgain;        // not created yet!
00063     }
00064 
00065     void Save()
00066     {
00067         m_bShowAgain = ShowAgain();
00068         SetValueFor(m_strKeyName, m_bShowAgain); 
00069     }
00070 
00071     void Load()
00072         { m_bShowAgain = GetValueFor(m_strKeyName); }
00073 
00074 public:     // static
00075 
00076     static wxStringHashMap s_hashDesc;
00077 
00078 
00079     static wxString GetDescriptionFor(const wxString &keyname)
00080         { return s_hashDesc[keyname]; }
00081 
00082     static bool GetValueFor(const wxString &keyname)
00083     {
00084         bool value = true;
00085         if (m_pCfg)
00086             m_pCfg->Read(m_strPath + wxT("/") + keyname, &value);
00087         return value;
00088     }
00089 
00090     static void SetValueFor(const wxString &keyname, bool value)
00091     {
00092         if (m_pCfg)
00093             m_pCfg->Write(m_strPath + wxT("/") + keyname, value);
00094     }
00095 
00096     static void SetConfig(wxConfigBase *cfg, const wxString &path)
00097         { m_pCfg=cfg; m_strPath=path; }
00098 
00099     static wxConfigBase *GetConfig()
00100         { return m_pCfg; }
00101 
00102     static wxString GetConfigPath()
00103         { return m_strPath; }
00104 
00105 protected:
00106     wxCheckBox *m_pDoNotShowAgain;
00107     wxString m_strKeyName;
00108     bool m_bShowAgain;
00109 
00110 protected:
00111     static wxConfigBase *m_pCfg;
00112     static wxString m_strPath;
00113 };
00114 
00115 
00116 // ----------------------------------------------------------------------------
00117 // wxSmartMessageBox: the simplest way to use wxSmartMessageDialog
00118 // ----------------------------------------------------------------------------
00119 
00120 int WXDLLEXPORT wxSmartMessageBox(const wxString &keyname,
00121                                 const wxString& message,
00122                                 const wxString& caption = wxMessageBoxCaptionStr,
00123                                 long style = wxOK | wxCENTRE,
00124                                 wxWindow *parent = NULL);
00125 
00126 
00127 // ----------------------------------------------------------------------------
00128 // wxSmartLog* family:
00129 // unlike wxLog* family these functions do not put the given text in a queue;
00130 // the text is immediately shown!
00131 // ----------------------------------------------------------------------------
00132 
00133 #define DECLARE_SMARTLOG_FUNCTION(level)                                    \
00134 extern int WXDLLIMPEXP_BASE wxSmartVLog##level(const wxChar *keyname,       \
00135                                                 const wxChar *szFormat,     \
00136                                                 va_list argptr);            \
00137 extern int WXDLLIMPEXP_BASE wxSmartLog##level(const wxChar *keyname,        \
00138                                                const wxChar *szFormat,      \
00139                                                ...);
00140 
00141 DECLARE_SMARTLOG_FUNCTION(Message)
00142 DECLARE_SMARTLOG_FUNCTION(Warning)
00143 DECLARE_SMARTLOG_FUNCTION(Error)
00144 DECLARE_SMARTLOG_FUNCTION(YesNoQuestion)
00145 
00146 #endif
00147     // _WX_SMARTMSGDLG_H_
00148 

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1