X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8fdca65cf20ae4dba861fa6667d6e233cbb900cf..5d1902d6d6efc842c8f488520d3cca40f1ae99f8:/src/common/config.cpp?ds=sidebyside diff --git a/src/common/config.cpp b/src/common/config.cpp index e099f0af2c..9551a9b94c 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- @@ -23,20 +19,23 @@ #include "wx/wxprec.h" +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include + +#ifdef wxUSE_CONFIG + #ifdef __BORLANDC__ #pragma hdrstop #endif //__BORLANDC__ -#ifndef WX_PRECOMP - #include - #include -#endif //WX_PRECOMP - #include #include #include #include -#include +#include // we must include (one of) these files for wxConfigBase::Create #if defined(__WXMSW__) && defined(wxCONFIG_WIN32_NATIVE) @@ -134,7 +133,7 @@ bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const bool wxConfigBase::Read(const wxString& key, double* val) const { wxString str; - if (Read(key, str)) + if (Read(key, & str)) { *val = atof(str); return TRUE; @@ -178,6 +177,24 @@ bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const } // 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); + *pi = (int) l; + return ret; +} + bool wxConfigBase::Write(const wxString& key, double val) { wxString str; @@ -191,6 +208,15 @@ bool wxConfigBase::Write(const wxString& key, bool value) return Write(key, l); } +wxString wxConfigBase::ExpandEnvVars(const wxString& str) const +{ + wxString tmp; // Required for BC++ + if (IsExpandingEnvVars()) + tmp = wxExpandEnvVars(str); + else + tmp = str; + return tmp; +} // ---------------------------------------------------------------------------- // wxConfigPathChanger @@ -200,16 +226,21 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry) { m_pContainer = (wxConfigBase *)pContainer; - wxString strPath = strEntry.Before(wxCONFIG_PATH_SEPARATOR); - // special case of "/keyname" when there is nothing before "/" - if ( strPath.IsEmpty() && ((!strEntry.IsEmpty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR )) + // 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.Right(wxCONFIG_PATH_SEPARATOR); + m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR); m_strOldPath = m_pContainer->GetPath(); m_strOldPath += wxCONFIG_PATH_SEPARATOR; m_pContainer->SetPath(strPath); @@ -247,9 +278,9 @@ wxString wxExpandEnvVars(const wxString& str) { Bracket_None, Bracket_Normal = ')', - Bracket_Curly = '}', + Bracket_Curly = '}' #ifdef __WXMSW__ - Bracket_Windows = '%' // yeah, Windows people are a bit strange ;-) + ,Bracket_Windows = '%' // yeah, Windows people are a bit strange ;-) #endif }; @@ -382,4 +413,7 @@ void wxSplitPath(wxArrayString& aParts, const char *sz) } } +#endif + + // wxUSE_CONFIG