+ m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE;
+}
+
+wxConfigBase::~wxConfigBase()
+{
+}
+
+wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
+{
+ wxConfigBase *pOld = ms_pConfig;
+ ms_pConfig = pConfig;
+ return pOld;
+}
+
+wxConfigBase *wxConfigBase::Create()
+{
+ if ( ms_bAutoCreate && ms_pConfig == NULL ) {
+ ms_pConfig =
+ #if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE
+ #ifdef __WIN32__
+ new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
+ #else //WIN16
+ new wxIniConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
+ #endif
+ #else // either we're under Unix or wish to use files even under Windows
+ new wxFileConfig(wxTheApp->GetAppName());
+ #endif
+ }
+
+ return ms_pConfig;
+}
+
+wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const
+{
+ wxString s;
+ Read(key, &s, defVal);
+ return s;
+}
+
+bool wxConfigBase::Read(const wxString& key, wxString *str, const wxString& defVal) const
+{
+ if (!Read(key, str))
+ {
+ *str = ExpandEnvVars(defVal);
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const
+{
+ if (!Read(key, pl))
+ {
+ *pl = defVal;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+bool wxConfigBase::Read(const wxString& key, double* val) const
+{
+ wxString str;
+ if ( Read(key, &str) )
+ {
+ return str.ToDouble(val);
+ }
+
+ return FALSE;
+}
+
+bool wxConfigBase::Read(const wxString& key, double* val, double defVal) const
+{
+ if (!Read(key, val))
+ {
+ *val = defVal;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+bool wxConfigBase::Read(const wxString& key, bool* val) const
+{
+ long l;
+ if (Read(key, & l))
+ {
+ *val = (l != 0);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const
+{
+ if (!Read(key, val))
+ {
+ *val = defVal;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+// Convenience functions
+
+bool wxConfigBase::Read(const wxString& key, int *pi) const
+{
+ long l;
+ bool ret = Read(key, &l);
+ if (ret)
+ *pi = (int) l;
+ return ret;
+}
+
+bool wxConfigBase::Read(const wxString& key, int *pi, int defVal) const
+{
+ long l;
+ bool ret = Read(key, &l, (long) defVal);
+ if (ret)
+ *pi = (int) l;
+ return ret;
+}
+
+bool wxConfigBase::Write(const wxString& key, double val)
+{
+ wxString str;
+ str.Printf(wxT("%g"), val);
+ return Write(key, str);
+}
+
+bool wxConfigBase::Write(const wxString& key, bool value)
+{
+ return Write(key, value ? 1l : 0l);
+}
+
+bool wxConfigBase::Write(const wxString& key, const wxChar *value)
+{
+ // explicit cast needed, otherwise value would have been converted to bool
+ return Write(key, wxString(value));
+}
+
+wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
+{
+ wxString tmp; // Required for BC++
+ if (IsExpandingEnvVars())
+ tmp = wxExpandEnvVars(str);
+ else
+ tmp = str;
+ return tmp;
+}
+
+// ----------------------------------------------------------------------------
+// wxConfigPathChanger
+// ----------------------------------------------------------------------------
+
+wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
+ const wxString& strEntry)
+{
+ m_pContainer = (wxConfigBase *)pContainer;
+
+ // the path is everything which precedes the last slash
+ wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR);
+
+ // except in the special case of "/keyname" when there is nothing before "/"
+ if ( strPath.IsEmpty() &&
+ ((!strEntry.IsEmpty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR) )
+ {
+ strPath = wxCONFIG_PATH_SEPARATOR;
+ }
+
+ if ( !strPath.IsEmpty() ) {
+ // do change the path
+ m_bChanged = TRUE;
+ m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR);
+ m_strOldPath = m_pContainer->GetPath();
+ if ( m_strOldPath.Len() == 0 ||
+ m_strOldPath.Last() != wxCONFIG_PATH_SEPARATOR )
+ m_strOldPath += wxCONFIG_PATH_SEPARATOR;
+ m_pContainer->SetPath(strPath);
+ }
+ else {
+ // it's a name only, without path - nothing to do
+ m_bChanged = FALSE;
+ m_strName = strEntry;
+ }
+}
+
+wxConfigPathChanger::~wxConfigPathChanger()
+{
+ // only restore path if it was changed
+ if ( m_bChanged ) {
+ m_pContainer->SetPath(m_strOldPath);
+ }