]> git.saurik.com Git - wxWidgets.git/commitdiff
wxConfig changes to be more logical.
authorJulian Smart <julian@anthemion.co.uk>
Thu, 27 Aug 1998 21:06:02 +0000 (21:06 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 27 Aug 1998 21:06:02 +0000 (21:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@636 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
include/wx/confbase.h
include/wx/fileconf.h
include/wx/msw/iniconf.h
include/wx/msw/regconf.h
samples/config/conftest.cpp
samples/forty/scorefil.cpp
samples/forty/scorefil.h
samples/listctrl/listtest.cpp
samples/regtest/regtest.cpp
src/common/config.cpp
src/common/fileconf.cpp
src/msw/iniconf.cpp
src/msw/makefile.nt
src/msw/regconf.cpp

index eac77600e54eb34f6574560b0a4de6777bc997e4..ae259b88ec69f27eb6523e140b1505cb1a783455 100644 (file)
   #define wxCONFIG_WIN32_NATIVE          TRUE
 #endif
 
   #define wxCONFIG_WIN32_NATIVE          TRUE
 #endif
 
+// Style flags for constructor style parameter
+#define wxCONFIG_USE_LOCAL_FILE         1
+#define wxCONFIG_USE_GLOBAL_FILE        2
+
 // ----------------------------------------------------------------------------
 // various helper global functions
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // various helper global functions
 // ----------------------------------------------------------------------------
@@ -101,7 +105,17 @@ public:
 
   // ctor & virtual dtor
     // environment variable expansion is on by default
 
   // ctor & virtual dtor
     // environment variable expansion is on by default
-  wxConfigBase() { m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE; }
+//  wxConfigBase() { m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE; }
+
+  // ctor
+
+  // Not all args will always be used by derived classes, but
+  // including them all in each class ensures compatibility.
+  // If appName is empty, uses wxApp name
+  wxConfigBase(const wxString& appName = wxEmptyString, const wxString& vendorName = wxEmptyString,
+    const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
+    long style = 0);
+
     // empty but ensures that dtor of all derived classes is virtual
   virtual ~wxConfigBase() { }
 
     // empty but ensures that dtor of all derived classes is virtual
   virtual ~wxConfigBase() { }
 
@@ -138,31 +152,44 @@ public:
   // key access: returns TRUE if value was really read, FALSE if default used
   // (and if the key is not found the default value is returned.)
     // read a string from the key
   // key access: returns TRUE if value was really read, FALSE if default used
   // (and if the key is not found the default value is returned.)
     // read a string from the key
-  virtual bool Read(wxString *pStr, const char *szKey,
-                    const char *szDefault = (const char *) NULL) const = 0;
-    // another version using statis buffer - it means it will be overwritten
-    // after each call to this function!
-  virtual const char *Read(const char *szKey,
-                           const char *szDefault = (const char *) NULL) const;
-    // the same for longs
-  virtual long Read(const char *szKey, long lDefault) const
-    { long l; Read(&l, szKey, lDefault); return l; }
-    // and another version: returns true if default value is returned
-  virtual bool Read(long *pl, const char *szKey, long lDefault = 0) const = 0;
+  virtual bool Read(const wxString& key, wxString *pStr) const = 0;
+  virtual bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const;
+
+  virtual wxString Read(const wxString& key, const wxString& defVal) const;
+
+  virtual bool Read(const wxString& key, long *pl) const = 0;
+  virtual bool Read(const wxString& key, long *pl, long defVal) const;
+
+  virtual long Read(const wxString& strKey, long defVal) const
+    { long l; Read(strKey, &l, defVal); return l; }
+
+  // Convenience functions that are built on other forms
+  // double
+  virtual bool Read(const wxString& key, double* val) const;
+  virtual bool Read(const wxString& key, double* val, double defVal) const;
+
+  // bool
+  virtual bool Read(const wxString& key, bool* val) const;
+  virtual bool Read(const wxString& key, bool* val, bool defVal) const;
 
     // write the value (return true on success)
 
     // write the value (return true on success)
-  virtual bool Write(const char *szKey, const char *szValue) = 0;
-  virtual bool Write(const char *szKey, long lValue) = 0;
+  virtual bool Write(const wxString& key, const wxString& value) = 0;
+  virtual bool Write(const wxString& key, long value) = 0;
+
+  // Convenience functions
+  virtual bool Write(const wxString& key, double value);
+  virtual bool Write(const wxString& key, bool value);
+
     // permanently writes all changes
   virtual bool Flush(bool bCurrentOnly = FALSE) = 0;
 
   // delete entries/groups
     // deletes the specified entry and the group it belongs to if
     // it was the last key in it and the second parameter is true
     // permanently writes all changes
   virtual bool Flush(bool bCurrentOnly = FALSE) = 0;
 
   // delete entries/groups
     // deletes the specified entry and the group it belongs to if
     // it was the last key in it and the second parameter is true
-  virtual bool DeleteEntry(const char *szKey,
+  virtual bool DeleteEntry(const wxString& key,
                            bool bDeleteGroupIfEmpty = TRUE) = 0;
     // delete the group (with all subgroups)
                            bool bDeleteGroupIfEmpty = TRUE) = 0;
     // delete the group (with all subgroups)
-  virtual bool DeleteGroup(const char *szKey) = 0;
+  virtual bool DeleteGroup(const wxString& key) = 0;
     // delete the whole underlying object (disk file, registry key, ...)
     // primarly for use by desinstallation routine.
   virtual bool DeleteAll() = 0;
     // delete the whole underlying object (disk file, registry key, ...)
     // primarly for use by desinstallation routine.
   virtual bool DeleteAll() = 0;
@@ -186,20 +213,49 @@ public:
         return tmp;
     }
 
         return tmp;
     }
 
+    // misc accessors
+  inline wxString GetAppName() const { return m_appName; }
+  inline wxString GetVendorName() const { return m_vendorName; }
+
+  inline void SetAppName(const wxString& appName) { m_appName = appName; }
+  inline void SetVendorName(const wxString& vendorName) { m_vendorName = vendorName; }
+
+  inline void SetStyle(long style) { m_style; }
+  inline long GetStyle() const { return m_style; }
+
 protected:
 protected:
-  static bool IsImmutable(const char *szKey)
-    { return *szKey == wxCONFIG_IMMUTABLE_PREFIX; }
+  static bool IsImmutable(const wxString& key)
+    { return key[0] == wxCONFIG_IMMUTABLE_PREFIX; }
+
+private:
+  // are we doing automatic environment variable expansion?
+  bool m_bExpandEnvVars;
+  // do we record default values?
+  bool m_bRecordDefaults;
+  
+  // static variables
+  static wxConfigBase *ms_pConfig;
+  static bool          ms_bAutoCreate;
+
+  // Application name and organisation name
+  wxString          m_appName;
+  wxString          m_vendorName;
+
+  // Style flag
+  long              m_style;
+};
 
   // a handy little class which changes current path to the path of given entry
   // and restores it in dtor: so if you declare a local variable of this type,
   // you work in the entry directory and the path is automatically restored
   // when the function returns
 
   // a handy little class which changes current path to the path of given entry
   // and restores it in dtor: so if you declare a local variable of this type,
   // you work in the entry directory and the path is automatically restored
   // when the function returns
-  class PathChanger
+  // Taken out of wxConfig since not all compilers can cope with nested classes.
+  class wxConfigPathChanger
   {
   public:
     // ctor/dtor do path changing/restorin
   {
   public:
     // ctor/dtor do path changing/restorin
-    PathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
-   ~PathChanger();
+    wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
+   ~wxConfigPathChanger();
 
     // get the key name
     const wxString& Name() const { return m_strName; }
 
     // get the key name
     const wxString& Name() const { return m_strName; }
@@ -211,16 +267,6 @@ protected:
     bool          m_bChanged;     // was the path changed?
   };
 
     bool          m_bChanged;     // was the path changed?
   };
 
-private:
-  // are we doing automatic environment variable expansion?
-  bool m_bExpandEnvVars;
-  // do we record default values?
-  bool m_bRecordDefaults;
-  
-  // static variables
-  static wxConfigBase *ms_pConfig;
-  static bool          ms_bAutoCreate;
-};
 
 // ----------------------------------------------------------------------------
 // the native wxConfigBase implementation
 
 // ----------------------------------------------------------------------------
 // the native wxConfigBase implementation
@@ -240,5 +286,7 @@ private:
   #define classwxConfig classwxFileConfig
 #endif
 
   #define classwxConfig classwxFileConfig
 #endif
 
+
+
 #endif  // _WX_CONFIG_H_
 
 #endif  // _WX_CONFIG_H_
 
index 063394de64c904819d7b2c9e20ab6a65df1fdb5a..dcf9d10e4289dbf3dfefe3c7d213e6928a435cba 100644 (file)
@@ -112,6 +112,8 @@ public:
   static wxString GetLocalFileName(const char *szFile);
 
   // ctor & dtor
   static wxString GetLocalFileName(const char *szFile);
 
   // ctor & dtor
+
+#if 0
     // the names of local and global (if not disabled) config files are
     // constructed using Get{Local|Global}FileName functions described above
     // (szAppName is just the (short) name of your application)
     // the names of local and global (if not disabled) config files are
     // constructed using Get{Local|Global}FileName functions described above
     // (szAppName is just the (short) name of your application)
@@ -123,6 +125,14 @@ public:
     // directory). If either of strings is empty, the corresponding file is not
     // used.
   wxFileConfig(const wxString& strLocal, const wxString& strGlobal);
     // directory). If either of strings is empty, the corresponding file is not
     // used.
   wxFileConfig(const wxString& strLocal, const wxString& strGlobal);
+#endif
+
+   // New constructor: one size fits all. Specify wxCONFIG_USE_LOCAL_FILE
+   // or wxCONFIG_USE_GLOBAL_FILE to say which files should be used.
+  wxFileConfig(const wxString& appName, const wxString& vendorName = wxEmptyString,
+    const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
+    long style = wxCONFIG_USE_LOCAL_FILE);
+
     // dtor will save unsaved data
   virtual ~wxFileConfig();
 
     // dtor will save unsaved data
   virtual ~wxFileConfig();
 
@@ -141,6 +151,7 @@ public:
   virtual bool HasGroup(const wxString& strName) const;
   virtual bool HasEntry(const wxString& strName) const;
 
   virtual bool HasGroup(const wxString& strName) const;
   virtual bool HasEntry(const wxString& strName) const;
 
+#if 0
   virtual bool Read(wxString *pstr, const char *szKey,
                     const char *szDefault = 0) const;
   virtual const char *Read(const char *szKey,
   virtual bool Read(wxString *pstr, const char *szKey,
                     const char *szDefault = 0) const;
   virtual const char *Read(const char *szKey,
@@ -150,10 +161,31 @@ public:
     { return wxConfigBase::Read(szKey, lDefault); }
   virtual bool Write(const char *szKey, const char *szValue);
   virtual bool Write(const char *szKey, long lValue);
     { return wxConfigBase::Read(szKey, lDefault); }
   virtual bool Write(const char *szKey, const char *szValue);
   virtual bool Write(const char *szKey, long lValue);
+#endif
+
+  virtual bool Read(const wxString& key, wxString *pStr) const;
+  virtual bool Read(const wxString& key, wxString *pStr, const wxString& defValue) const;
+  virtual bool Read(const wxString& key, long *pl) const;
+
+  // The following are necessary to satisfy the compiler
+  wxString Read(const wxString& key, const wxString& defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, long *pl, long defVal) const
+  { return wxConfigBase::Read(key, pl, defVal); }
+  long Read(const wxString& key, long defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, double* val) const
+  { return wxConfigBase::Read(key, val); }
+  bool Read(const wxString& key, double* val, double defVal) const
+  { return wxConfigBase::Read(key, val, defVal); }
+
+  virtual bool Write(const wxString& key, const wxString& szValue);
+  virtual bool Write(const wxString& key, long lValue);
+
   virtual bool Flush(bool bCurrentOnly = FALSE);
 
   virtual bool Flush(bool bCurrentOnly = FALSE);
 
-  virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
-  virtual bool DeleteGroup(const char *szKey);
+  virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso);
+  virtual bool DeleteGroup(const wxString& szKey);
   virtual bool DeleteAll();
 
 public:
   virtual bool DeleteAll();
 
 public:
index d67a8cf886f3630ab3a9c70ed223363014051c11..2d56f13f28171234d283ee81da28519ead42038b 100644 (file)
@@ -43,7 +43,8 @@ public:
     // if strAppName doesn't contain the extension and is not an absolute path,
     // ".ini" is appended to it. if strVendor is empty, it's taken to be the
     // same as strAppName.
     // if strAppName doesn't contain the extension and is not an absolute path,
     // ".ini" is appended to it. if strVendor is empty, it's taken to be the
     // same as strAppName.
-  wxIniConfig(const wxString& strAppName, const wxString& strVendor = "");
+  wxIniConfig(const wxString& strAppName = wxEmptyString, const wxString& strVendor = wxEmptyString,
+    const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString, long style = wxCONFIG_USE_LOCAL_FILE);
   virtual ~wxIniConfig();
 
   // implement inherited pure virtual functions
   virtual ~wxIniConfig();
 
   // implement inherited pure virtual functions
@@ -64,14 +65,26 @@ public:
   // return TRUE if the current group is empty
   bool IsEmpty() const;
 
   // return TRUE if the current group is empty
   bool IsEmpty() const;
 
-  virtual bool Read(wxString *pstr, const char *szKey,
-                    const char *szDefault = 0) const;
-  virtual const char *Read(const char *szKey,
-                           const char *szDefault = 0) const;
-  virtual bool Read(long *pl, const char *szKey, long lDefault) const;
-  virtual long Read(const char *szKey, long lDefault) const;
-  virtual bool Write(const char *szKey, const char *szValue);
-  virtual bool Write(const char *szKey, long lValue);
+  // read/write
+  bool Read(const wxString& key, wxString *pStr) const;
+  bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
+  bool Read(const wxString& key, long *plResult) const;
+
+  // The following are necessary to satisfy the compiler
+  wxString Read(const wxString& key, const wxString& defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, long *pl, long defVal) const
+  { return wxConfigBase::Read(key, pl, defVal); }
+  long Read(const wxString& key, long defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, double* val) const
+  { return wxConfigBase::Read(key, val); }
+  bool Read(const wxString& key, double* val, double defVal) const
+  { return wxConfigBase::Read(key, val, defVal); }
+
+  bool Write(const wxString& key, const wxString& szValue);
+  bool Write(const wxString& key, long lValue);
+
   virtual bool Flush(bool bCurrentOnly = FALSE);
 
   virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
   virtual bool Flush(bool bCurrentOnly = FALSE);
 
   virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
@@ -80,11 +93,10 @@ public:
 
 private:
   // helpers
 
 private:
   // helpers
-  wxString GetPrivateKeyName(const char *szKey) const;
-  wxString GetKeyName(const char *szKey) const;
+  wxString GetPrivateKeyName(const wxString& szKey) const;
+  wxString GetKeyName(const wxString& szKey) const;
 
 
-  wxString m_strAppName,  // name of the private INI file
-           m_strVendor;   // name of our section in WIN.INI
+  wxString m_strLocalFilename;  // name of the private INI file
   wxString m_strGroup,    // current group in appname.ini file
            m_strPath;     // the rest of the path (no trailing '_'!)
 };
   wxString m_strGroup,    // current group in appname.ini file
            m_strPath;     // the rest of the path (no trailing '_'!)
 };
index 700501f87131d83a2bccf89cea7bcc6e81def650..3c33e2731acd1423dd0a5e50001867a7cfc1d2f6 100644 (file)
@@ -28,8 +28,11 @@ class wxRegConfig : public wxConfigBase
 {
 public:
   // ctor & dtor
 {
 public:
   // ctor & dtor
-    // will store data in HKLM\strRegHive and HKCU\strRegHive
-  wxRegConfig(const wxString& strRegHive);
+    // will store data in HKLM\appName and HKCU\appName
+  wxRegConfig(const wxString& appName = wxEmptyString, const wxString& vendorName = wxEmptyString,
+    const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
+    long style = 0);
+
     // dtor will save unsaved data
   virtual ~wxRegConfig();
 
     // dtor will save unsaved data
   virtual ~wxRegConfig();
 
@@ -57,16 +60,30 @@ public:
   virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
 
   // read/write
   virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
 
   // read/write
-  virtual bool Read(wxString *pStr, const char *szKey,
-                    const char *szDefault = 0) const;
-  virtual bool Read(long *result, const char *szKey, long lDefault = 0) const;
-  virtual bool Write(const char *szKey, const char *szValue);
-  virtual bool Write(const char *szKey, long Value);
+  bool Read(const wxString& key, wxString *pStr) const;
+  bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
+  bool Read(const wxString& key, long *plResult) const;
+
+  // The following are necessary to satisfy the compiler
+  wxString Read(const wxString& key, const wxString& defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, long *pl, long defVal) const
+  { return wxConfigBase::Read(key, pl, defVal); }
+  long Read(const wxString& key, long defVal) const
+  { return wxConfigBase::Read(key, defVal); }
+  bool Read(const wxString& key, double* val) const
+  { return wxConfigBase::Read(key, val); }
+  bool Read(const wxString& key, double* val, double defVal) const
+  { return wxConfigBase::Read(key, val, defVal); }
+
+  bool Write(const wxString& key, const wxString& szValue);
+  bool Write(const wxString& key, long lValue);
+
   virtual bool Flush(bool /* bCurrentOnly = FALSE */ ) { return TRUE; }
 
   // delete
   virtual bool Flush(bool /* bCurrentOnly = FALSE */ ) { return TRUE; }
 
   // delete
-  virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
-  virtual bool DeleteGroup(const char *szKey);
+  virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso);
+  virtual bool DeleteGroup(const wxString& key);
   virtual bool DeleteAll();
 
 private:
   virtual bool DeleteAll();
 
 private:
index 9c97ccce3f759c0fcde104d27b37ffd46d40e44f..3d0b4b5217b26ce6704157fceffa7506ab849a2f 100644 (file)
@@ -225,8 +225,8 @@ MyFrame::~MyFrame()
   int x, y, w, h;
   GetClientSize(&w, &h);
   GetPosition(&x, &y);
   int x, y, w, h;
   GetClientSize(&w, &h);
   GetPosition(&x, &y);
-  pConfig->Write("/MainFrame/x", x);
-  pConfig->Write("/MainFrame/y", y);
-  pConfig->Write("/MainFrame/w", w);
-  pConfig->Write("/MainFrame/h", h);
+  pConfig->Write("/MainFrame/x", (long) x);
+  pConfig->Write("/MainFrame/y", (long) y);
+  pConfig->Write("/MainFrame/w", (long) w);
+  pConfig->Write("/MainFrame/h", (long) h);
 }
 }
index 6b9e323786b422393c6d44822d30cfebda2ad9a1..d066ec8a90841289a7c6ffaf1a9c1fcdb19d1103 100644 (file)
@@ -41,7 +41,7 @@
 
 ScoreFile::ScoreFile(const char* appName)
 {
 
 ScoreFile::ScoreFile(const char* appName)
 {
-#ifdef 0
+#if 0
        wxString filename;
        m_configFilename << "/usr/local/share/" << appName << ".scores";
        if (access(m_configFilename, F_OK) == 0)
        wxString filename;
        m_configFilename << "/usr/local/share/" << appName << ".scores";
        if (access(m_configFilename, F_OK) == 0)
@@ -69,11 +69,7 @@ ScoreFile::ScoreFile(const char* appName)
        }
 #endif
 
        }
 #endif
 
-#ifdef __UNIX__
-       m_config = new wxFileConfig( appName, "" );  // only local
-#else
-       m_config = new wxFileConfig( "",appName );   // only global
-#endif
+       m_config = new wxConfig(appName, "wxWindows", appName, "", wxCONFIG_USE_LOCAL_FILE);  // only local
 }
 
 ScoreFile::~ScoreFile()
 }
 
 ScoreFile::~ScoreFile()
@@ -132,7 +128,7 @@ wxString ScoreFile::GetPreviousPlayer() const
 {
        wxString result;
        m_config->SetPath("/General");
 {
        wxString result;
        m_config->SetPath("/General");
-       m_config->Read(&result, "LastPlayer");
+       m_config->Read("LastPlayer", &result);
        return result;
 }
 
        return result;
 }
 
@@ -149,10 +145,10 @@ void ScoreFile::ReadPlayersScore(
 
        m_config->SetPath("/Players");
        m_config->SetPath(player);
 
        m_config->SetPath("/Players");
        m_config->SetPath(player);
-       if (m_config->Read(&myScore, (const char *) "Score",0L) &&
-               m_config->Read(&myGames, (const char *) "Games",0L) &&
-               m_config->Read(&myWins, (const char *) "Wins",0L) &&
-               m_config->Read(&check, (const char *) "Check",0L))
+       if (m_config->Read("Score", &myScore, 0L) &&
+               m_config->Read("Games", &myGames, 0L) &&
+               m_config->Read("Wins",  &myWins, 0L) &&
+               m_config->Read("Check", &check, 0L))
        {
            if (check != CalcCheck(player, myGames, myWins, myScore))
                {
        {
            if (check != CalcCheck(player, myGames, myWins, myScore))
                {
index 8e41d63198ab6e7c369012c00b5ff904b7123774..1e89904eca9b2a61b471f9e0079fd9ebd1ca2d73 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef _SCOREFILE_H_
 #define _SCOREFILE_H_
 
 #ifndef _SCOREFILE_H_
 #define _SCOREFILE_H_
 
+#include <wx/config.h>
+
 class wxConfig;
 
 class ScoreFile {
 class wxConfig;
 
 class ScoreFile {
@@ -28,8 +30,8 @@ public:
 
 private:
        long CalcCheck(const char* name, int p1, int p2, int p3);
 
 private:
        long CalcCheck(const char* name, int p1, int p2, int p3);
-       wxString        m_configFilename;
-       wxConfig*       m_config;
+       wxString            m_configFilename;
+       wxConfig*           m_config;
 };
 
 #endif
 };
 
 #endif
index fb90214ccaccba267b77a30939090195d51bce29..6e4b55f5eef2540f9cbff34baab66230ce8fedd4 100644 (file)
@@ -38,7 +38,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
        EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
        EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
        EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
        EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
        EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
        EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
-       EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnSelectAll)
+       EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
index 5873fc4441baa149fb620d440b213b8be20de2a6..4f3eb6ee1f8380e0aa2845dbb507d1fc7b5e1fa4 100644 (file)
@@ -57,6 +57,10 @@ public:
   RegImageList();
 };
 
   RegImageList();
 };
 
+// array of children of the node
+struct TreeNode;
+WX_DEFINE_ARRAY(TreeNode *, TreeChildren);
+
 // ----------------------------------------------------------------------------
 // our control
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // our control
 // ----------------------------------------------------------------------------
@@ -90,10 +94,7 @@ public:
   DECLARE_EVENT_TABLE();
 
 private:
   DECLARE_EVENT_TABLE();
 
 private:
-  // array of children of the node
-  struct TreeNode;
-  WX_DEFINE_ARRAY(TreeNode *, TreeChildren);
-  
+
   // structure describing a registry key/value
   struct TreeNode
   {
   // structure describing a registry key/value
   struct TreeNode
   {
index 2eb6facd54442274d7c63172e61e5fc996b05a1d..ec03c728f62b21792a89b59ac4409e0d0aad47a8 100644 (file)
@@ -50,6 +50,7 @@
 #endif
 
 #include  <stdlib.h>
 #endif
 
 #include  <stdlib.h>
+#include  <math.h>
 #include  <ctype.h>       // for isalnum()
 
 // ----------------------------------------------------------------------------
 #include  <ctype.h>       // for isalnum()
 
 // ----------------------------------------------------------------------------
@@ -67,6 +68,15 @@ bool          wxConfigBase::ms_bAutoCreate = TRUE;
 // wxConfigBase
 // ----------------------------------------------------------------------------
 
 // wxConfigBase
 // ----------------------------------------------------------------------------
 
+// Not all args will always be used by derived classes, but
+// including them all in each class ensures compatibility.
+wxConfigBase::wxConfigBase(const wxString& appName, const wxString& vendorName,
+    const wxString& localFilename, const wxString& globalFilename, long style):
+        m_appName(appName), m_vendorName(vendorName), m_style(style)
+{
+    m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE;
+}
+
 wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
 {
   wxConfigBase *pOld = ms_pConfig;
 wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
 {
   wxConfigBase *pOld = ms_pConfig;
@@ -80,8 +90,7 @@ wxConfigBase *wxConfigBase::Create()
     ms_pConfig =
     #if defined(__WXMSW__) && defined(wxCONFIG_WIN32_NATIVE)
       #ifdef __WIN32__
     ms_pConfig =
     #if defined(__WXMSW__) && defined(wxCONFIG_WIN32_NATIVE)
       #ifdef __WIN32__
-        new wxRegConfig(wxTheApp->GetVendorName() + '\\' 
-                        + wxTheApp->GetAppName());
+        new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
       #else  //WIN16
         new wxIniConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
       #endif
       #else  //WIN16
         new wxIniConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
       #endif
@@ -93,21 +102,101 @@ wxConfigBase *wxConfigBase::Create()
   return ms_pConfig;
 }
 
   return ms_pConfig;
 }
 
-const char *wxConfigBase::Read(const char *szKey, const char *szDefault) const
+wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const
 {
 {
-  static char s_szBuf[1024];
   wxString s;
   wxString s;
-  Read(&s, szKey, szDefault);
-  strncpy(s_szBuf, s, WXSIZEOF(s_szBuf));
+  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))
+    {
+        *val = atof(str);
+        return TRUE;
+    }
+    else
+        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::Write(const wxString& key, double val)
+{
+    wxString str;
+    str.Printf("%f", val);
+    return Write(key, str);
+}
 
 
-  return s_szBuf;
+bool wxConfigBase::Write(const wxString& key, bool value)
+{
+    long l = (value ? 1 : 0);
+    return Write(key, l);
 }
 
 }
 
+
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-// Config::PathChanger
+// wxConfigPathChanger
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-wxConfigBase::PathChanger::PathChanger(const wxConfigBase *pContainer,
+wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
                                  const wxString& strEntry)
 {
   m_pContainer = (wxConfigBase *)pContainer;
                                  const wxString& strEntry)
 {
   m_pContainer = (wxConfigBase *)pContainer;
@@ -132,7 +221,7 @@ wxConfigBase::PathChanger::PathChanger(const wxConfigBase *pContainer,
   }
 }
 
   }
 }
 
-wxConfigBase::PathChanger::~PathChanger()
+wxConfigPathChanger::~wxConfigPathChanger()
 {
   // only restore path if it was changed
   if ( m_bChanged ) {
 {
   // only restore path if it was changed
   if ( m_bChanged ) {
@@ -293,3 +382,4 @@ void wxSplitPath(wxArrayString& aParts, const char *sz)
   }
 }
 
   }
 }
 
+
index 454dc463ad9c613ca0d75c8bd28dee97643ba4f8..bdf11498cbdea65efe98ff03edf95e4df6959461 100644 (file)
@@ -32,6 +32,7 @@
   #include  <wx/intl.h>
 #endif  //WX_PRECOMP
 
   #include  <wx/intl.h>
 #endif  //WX_PRECOMP
 
+#include  <wx/app.h>
 #include  <wx/dynarray.h>
 #include  <wx/file.h>
 #include  <wx/log.h>
 #include  <wx/dynarray.h>
 #include  <wx/file.h>
 #include  <wx/log.h>
@@ -207,6 +208,7 @@ void wxFileConfig::Init()
   }
 }
 
   }
 }
 
+#if 0
 wxFileConfig::wxFileConfig(const char *szAppName, bool bLocalOnly)
 {
   wxASSERT( !IsEmpty(szAppName) ); // invent a name for your application!
 wxFileConfig::wxFileConfig(const char *szAppName, bool bLocalOnly)
 {
   wxASSERT( !IsEmpty(szAppName) ); // invent a name for your application!
@@ -237,6 +239,55 @@ wxFileConfig::wxFileConfig(const wxString& strLocal, const wxString& strGlobal)
 
   Init();
 }
 
   Init();
 }
+#endif
+
+// New-style constructor
+wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
+      const wxString& strLocal, const wxString& strGlobal, long style)
+            : wxConfigBase(appName, vendorName, strLocal, strGlobal, style),
+              m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
+{
+    // Make up an application name if not supplied
+    if (appName.IsEmpty() && wxTheApp)
+    {
+        SetAppName(wxTheApp->GetAppName());
+    }
+
+    // Make up names for files if empty
+    if (m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) && wxTheApp)
+    {
+        m_strLocalFile = wxTheApp->GetAppName();
+    }
+
+    if (m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE))
+    {
+        // TODO: What should the default global filename be?
+        m_strGlobalFile = "global";
+    }
+
+    // Check if styles are not supplied, but filenames are, in which case
+    // add the correct styles.
+    if (!m_strLocalFile.IsEmpty() && ((style & wxCONFIG_USE_LOCAL_FILE) != wxCONFIG_USE_LOCAL_FILE))
+        SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
+
+    if (!m_strGlobalFile.IsEmpty() && ((style & wxCONFIG_USE_GLOBAL_FILE) != wxCONFIG_USE_GLOBAL_FILE))
+        SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);
+
+  // if the path is not absolute, prepend the standard directory to it
+  if ( !strLocal.IsEmpty() && !wxIsAbsolutePath(strLocal) )
+  {
+     m_strLocalFile = GetLocalDir();
+     m_strLocalFile << strLocal;
+  }
+  
+  if ( !strGlobal.IsEmpty() && !wxIsAbsolutePath(strGlobal) )
+  {
+     m_strGlobalFile = GetGlobalDir();
+     m_strGlobalFile << strGlobal;
+  }
+
+  Init();
+}
 
 void wxFileConfig::CleanUp()
 {
 
 void wxFileConfig::CleanUp()
 {
@@ -509,7 +560,7 @@ size_t wxFileConfig::GetNumberOfGroups(bool bRecursive) const
 
 bool wxFileConfig::HasGroup(const wxString& strName) const
 {
 
 bool wxFileConfig::HasGroup(const wxString& strName) const
 {
-  PathChanger path(this, strName);
+  wxConfigPathChanger path(this, strName);
 
   ConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
   return pGroup != NULL;
 
   ConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
   return pGroup != NULL;
@@ -517,7 +568,7 @@ bool wxFileConfig::HasGroup(const wxString& strName) const
 
 bool wxFileConfig::HasEntry(const wxString& strName) const
 {
 
 bool wxFileConfig::HasEntry(const wxString& strName) const
 {
-  PathChanger path(this, strName);
+  wxConfigPathChanger path(this, strName);
 
   ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
   return pEntry != NULL;
 
   ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
   return pEntry != NULL;
@@ -527,50 +578,54 @@ bool wxFileConfig::HasEntry(const wxString& strName) const
 // read/write values
 // ----------------------------------------------------------------------------
 
 // read/write values
 // ----------------------------------------------------------------------------
 
-bool wxFileConfig::Read(wxString   *pstr,
-                        const char *szKey,
-                        const char *szDefault) const
+bool wxFileConfig::Read(const wxString& key,
+                        wxString* pStr) const
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
   if (pEntry == NULL) {
 
   ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
   if (pEntry == NULL) {
-    if( IsRecordingDefaults() )
-      ((wxFileConfig *)this)->Write(szKey,szDefault);
-    *pstr = ExpandEnvVars(szDefault);
     return FALSE;
   }
   else {
     return FALSE;
   }
   else {
-    *pstr = ExpandEnvVars(pEntry->Value());
+    *pStr = ExpandEnvVars(pEntry->Value());
     return TRUE;
   }
 }
 
     return TRUE;
   }
 }
 
-const char *wxFileConfig::Read(const char *szKey,
-                               const char *szDefault) const
+bool wxFileConfig::Read(const wxString& key,
+                        wxString* pStr, const wxString& defVal) const
 {
 {
-  static wxString s_str;
-  Read(&s_str, szKey, szDefault);
+  wxConfigPathChanger path(this, key);
 
 
-  return s_str.c_str();
+  ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
+  if (pEntry == NULL) {
+    if( IsRecordingDefaults() )
+      ((wxFileConfig *)this)->Write(key,defVal);
+    *pStr = ExpandEnvVars(defVal);
+    return FALSE;
+  }
+  else {
+    *pStr = ExpandEnvVars(pEntry->Value());
+    return TRUE;
+  }
 }
 
 }
 
-bool wxFileConfig::Read(long *pl, const char *szKey, long lDefault) const
+bool wxFileConfig::Read(const wxString& key, long *pl) const
 {
   wxString str;
 {
   wxString str;
-  if ( Read(&str, szKey) ) {
+  if ( Read(key, & str) ) {
     *pl = atol(str);
     return TRUE;
   }
   else {
     *pl = atol(str);
     return TRUE;
   }
   else {
-    *pl = lDefault;
     return FALSE;
   }
 }
 
     return FALSE;
   }
 }
 
-bool wxFileConfig::Write(const char *szKey, const char *szValue)
+bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   wxString strName = path.Name();
   if ( strName.IsEmpty() ) {
 
   wxString strName = path.Name();
   if ( strName.IsEmpty() ) {
@@ -611,12 +666,12 @@ bool wxFileConfig::Write(const char *szKey, const char *szValue)
   return TRUE;
 }
 
   return TRUE;
 }
 
-bool wxFileConfig::Write(const char *szKey, long lValue)
+bool wxFileConfig::Write(const wxString& key, long lValue)
 {
   // ltoa() is not ANSI :-(
   char szBuf[40];   // should be good for sizeof(long) <= 16 (128 bits)
   sprintf(szBuf, "%ld", lValue);
 {
   // ltoa() is not ANSI :-(
   char szBuf[40];   // should be good for sizeof(long) <= 16 (128 bits)
   sprintf(szBuf, "%ld", lValue);
-  return Write(szKey, szBuf);
+  return Write(key, szBuf);
 }
 
 bool wxFileConfig::Flush(bool /* bCurrentOnly */)
 }
 
 bool wxFileConfig::Flush(bool /* bCurrentOnly */)
@@ -646,9 +701,9 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
 // delete groups/entries
 // ----------------------------------------------------------------------------
 
 // delete groups/entries
 // ----------------------------------------------------------------------------
 
-bool wxFileConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
+bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   if ( !m_pCurrentGroup->DeleteEntry(path.Name()) )
     return FALSE;
 
   if ( !m_pCurrentGroup->DeleteEntry(path.Name()) )
     return FALSE;
@@ -665,9 +720,9 @@ bool wxFileConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
   return TRUE;
 }
 
   return TRUE;
 }
 
-bool wxFileConfig::DeleteGroup(const char *szKey)
+bool wxFileConfig::DeleteGroup(const wxString& key)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   return m_pCurrentGroup->DeleteSubgroupByName(path.Name());
 }
 
   return m_pCurrentGroup->DeleteSubgroupByName(path.Name());
 }
index 6a33921c5bb4e73d43fedcb0005ff08391dcf684..d3035015971b31c8bbbb4856ea4f50ddb7e64fc4 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef   WX_PRECOMP
   #include  <wx/string.h>
   #include  <wx/intl.h>
 #ifndef   WX_PRECOMP
   #include  <wx/string.h>
   #include  <wx/intl.h>
+  #include  <wx/app.h>
 #endif  //WX_PRECOMP
 
 #include  <wx/dynarray.h>
 #endif  //WX_PRECOMP
 
 #include  <wx/dynarray.h>
 // ctor & dtor
 // ----------------------------------------------------------------------------
 
 // ctor & dtor
 // ----------------------------------------------------------------------------
 
-wxIniConfig::wxIniConfig(const wxString& strAppName, const wxString& strVendor)
-           : m_strAppName(strAppName), m_strVendor(strVendor)
+wxIniConfig::wxIniConfig(const wxString& strAppName, const wxString& strVendor,
+    const wxString& localFilename, const wxString& globalFilename, long style):
+     wxConfigBase(strAppName, strVendor, localFilename, globalFilename, style)
 {
 {
-  if ( strVendor.IsEmpty() )
-    m_strVendor = strAppName;
-
-  // append the extension if none given and it's not an absolute file name
-  // (otherwise we assume that they know what they're doing)
-  if ( !wxIsPathSeparator(m_strAppName[0u]) &&
-        m_strAppName.Find('.') == NOT_FOUND ) {
-    m_strAppName << ".ini";
-  }
+    if ( GetAppName().IsEmpty() )
+    {
+        wxString app;
+        if (wxTheApp)
+            app = wxTheApp->GetAppName();
+        wxASSERT( !app.IsEmpty() );
+        SetAppName(app);
+    }
 
 
-  // set root path
-  SetPath("");
+    // Vendor name is required in wxIniConfig.
+    // TODO: should it be required? Why isn't appName used instead? -- JACS
+    if ( GetVendorName().IsEmpty() )
+    {
+        wxString vendor;
+        if (wxTheApp)
+            vendor = wxTheApp->GetVendorName();
+        else
+            vendor = strAppName;
+        SetVendorName(vendor);
+    }
+
+    m_strLocalFilename = localFilename;
+    if (m_strLocalFilename.IsEmpty())
+    {
+        m_strLocalFilename = GetAppName() + ".ini";
+    }
+
+    // append the extension if none given and it's not an absolute file name
+    // (otherwise we assume that they know what they're doing)
+    if ( !wxIsPathSeparator(m_strLocalFilename[0u]) &&
+        m_strLocalFilename.Find('.') == NOT_FOUND )
+    {
+        m_strLocalFilename << ".ini";
+    }
+
+    // set root path
+    SetPath("");
 }
 
 wxIniConfig::~wxIniConfig()
 }
 
 wxIniConfig::~wxIniConfig()
@@ -142,7 +169,7 @@ const wxString& wxIniConfig::GetPath() const
   return s_str;
 }
 
   return s_str;
 }
 
-wxString wxIniConfig::GetPrivateKeyName(const char *szKey) const
+wxString wxIniConfig::GetPrivateKeyName(const wxString& szKey) const
 {
   wxString strKey;
 
 {
   wxString strKey;
 
@@ -154,7 +181,7 @@ wxString wxIniConfig::GetPrivateKeyName(const char *szKey) const
   return strKey;
 }
 
   return strKey;
 }
 
-wxString wxIniConfig::GetKeyName(const char *szKey) const
+wxString wxIniConfig::GetKeyName(const wxString& szKey) const
 {
   wxString strKey;
 
 {
   wxString strKey;
 
@@ -240,7 +267,7 @@ bool wxIniConfig::IsEmpty() const
   char szBuf[1024];
 
   GetPrivateProfileString(m_strGroup, NULL, "",
   char szBuf[1024];
 
   GetPrivateProfileString(m_strGroup, NULL, "",
-                          szBuf, WXSIZEOF(szBuf), m_strAppName);
+                          szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
   if ( !::IsEmpty(szBuf) )
     return FALSE;
 
   if ( !::IsEmpty(szBuf) )
     return FALSE;
 
@@ -255,11 +282,9 @@ bool wxIniConfig::IsEmpty() const
 // read/write
 // ----------------------------------------------------------------------------
 
 // read/write
 // ----------------------------------------------------------------------------
 
-bool wxIniConfig::Read(wxString *pstr,
-                       const char *szKey,
-                       const char *szDefault) const
+bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, szKey);
   wxString strKey = GetPrivateKeyName(path.Name());
 
   char szBuf[1024]; // @@ should dynamically allocate memory...
   wxString strKey = GetPrivateKeyName(path.Name());
 
   char szBuf[1024]; // @@ should dynamically allocate memory...
@@ -268,7 +293,7 @@ bool wxIniConfig::Read(wxString *pstr,
 
   // NB: the lpDefault param to GetPrivateProfileString can't be NULL
   GetPrivateProfileString(m_strGroup, strKey, "",
 
   // NB: the lpDefault param to GetPrivateProfileString can't be NULL
   GetPrivateProfileString(m_strGroup, strKey, "",
-                          szBuf, WXSIZEOF(szBuf), m_strAppName);
+                          szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
   if ( ::IsEmpty(szBuf) ) {
     // now look in win.ini
     wxString strKey = GetKeyName(path.Name());
   if ( ::IsEmpty(szBuf) ) {
     // now look in win.ini
     wxString strKey = GetKeyName(path.Name());
@@ -276,7 +301,6 @@ bool wxIniConfig::Read(wxString *pstr,
   }
 
   if ( ::IsEmpty(szBuf) ) {
   }
 
   if ( ::IsEmpty(szBuf) ) {
-    *pstr = szDefault;
     return FALSE;
   }
   else {
     return FALSE;
   }
   else {
@@ -284,18 +308,37 @@ bool wxIniConfig::Read(wxString *pstr,
   }
 }
 
   }
 }
 
-const char *wxIniConfig::Read(const char *szKey,
-                              const char *szDefault) const
+bool wxIniConfig::Read(const wxString& szKey, wxString *pstr,
+                       const wxString& szDefault) const
 {
 {
-  static wxString s_str;
-  Read(&s_str, szKey, szDefault);
+  wxConfigPathChanger path(this, szKey);
+  wxString strKey = GetPrivateKeyName(path.Name());
+
+  char szBuf[1024]; // @@ should dynamically allocate memory...
+
+  // first look in the private INI file
+
+  // NB: the lpDefault param to GetPrivateProfileString can't be NULL
+  GetPrivateProfileString(m_strGroup, strKey, "",
+                          szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
+  if ( ::IsEmpty(szBuf) ) {
+    // now look in win.ini
+    wxString strKey = GetKeyName(path.Name());
+    GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
+  }
 
 
-  return s_str.c_str();
+  if ( ::IsEmpty(szBuf) ) {
+    *pstr = szDefault;
+    return FALSE;
+  }
+  else {
+    return TRUE;
+  }
 }
 
 }
 
-bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
+bool wxIniConfig::Read(const wxString& szKey, long *pl) const
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, szKey);
   wxString strKey = GetPrivateKeyName(path.Name());
 
   // hack: we have no mean to know if it really found the default value or
   wxString strKey = GetPrivateKeyName(path.Name());
 
   // hack: we have no mean to know if it really found the default value or
@@ -303,7 +346,7 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
 
   static const int nMagic  = 17; // 17 is some "rare" number
   static const int nMagic2 = 28; // arbitrary number != nMagic
 
   static const int nMagic  = 17; // 17 is some "rare" number
   static const int nMagic2 = 28; // arbitrary number != nMagic
-  long lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strAppName);
+  long lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strLocalFilename);
   if ( lVal != nMagic ) {
     // the value was read from the file
     *pl = lVal;
   if ( lVal != nMagic ) {
     // the value was read from the file
     *pl = lVal;
@@ -311,7 +354,7 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
   }
 
   // is it really nMagic?
   }
 
   // is it really nMagic?
-  lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strAppName);
+  lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strLocalFilename);
   if ( lVal == nMagic ) {
     // the nMagic it returned was indeed read from the file
     *pl = lVal;
   if ( lVal == nMagic ) {
     // the nMagic it returned was indeed read from the file
     *pl = lVal;
@@ -319,28 +362,18 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
   }
 
   // no, it was just returning the default value, so now look in win.ini
   }
 
   // no, it was just returning the default value, so now look in win.ini
-  *pl = GetProfileInt(m_strVendor, GetKeyName(szKey), lDefault);
+  *pl = GetProfileInt(GetVendorName(), GetKeyName(szKey), *pl);
 
 
-  // we're not going to check here whether it read the default or not: it's
-  // not that important
   return TRUE;
 }
 
   return TRUE;
 }
 
-long wxIniConfig::Read(const char *szKey, long lDefault) const
-{
-  long lVal;
-  Read(&lVal, szKey, lDefault);
-
-  return lVal;
-}
-
-bool wxIniConfig::Write(const char *szKey, const char *szValue)
+bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, szKey);
   wxString strKey = GetPrivateKeyName(path.Name());
 
   bool bOk = WritePrivateProfileString(m_strGroup, strKey,
   wxString strKey = GetPrivateKeyName(path.Name());
 
   bool bOk = WritePrivateProfileString(m_strGroup, strKey,
-                                       szValue, m_strAppName) != 0;
+                                       szValue, m_strLocalFilename) != 0;
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
@@ -348,7 +381,7 @@ bool wxIniConfig::Write(const char *szKey, const char *szValue)
   return bOk;
 }
 
   return bOk;
 }
 
-bool wxIniConfig::Write(const char *szKey, long lValue)
+bool wxIniConfig::Write(const wxString& szKey, long lValue)
 {
   // ltoa() is not ANSI :-(
   char szBuf[40];   // should be good for sizeof(long) <= 16 (128 bits)
 {
   // ltoa() is not ANSI :-(
   char szBuf[40];   // should be good for sizeof(long) <= 16 (128 bits)
@@ -360,7 +393,7 @@ bool wxIniConfig::Write(const char *szKey, long lValue)
 bool wxIniConfig::Flush(bool /* bCurrentOnly */)
 {
   // this is just the way it works
 bool wxIniConfig::Flush(bool /* bCurrentOnly */)
 {
   // this is just the way it works
-  return WritePrivateProfileString(NULL, NULL, NULL, m_strAppName) != 0;
+  return WritePrivateProfileString(NULL, NULL, NULL, m_strLocalFilename) != 0;
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -378,7 +411,7 @@ bool wxIniConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
 
   // delete the current group too
   bool bOk = WritePrivateProfileString(m_strGroup, NULL,
 
   // delete the current group too
   bool bOk = WritePrivateProfileString(m_strGroup, NULL,
-                                       NULL, m_strAppName) != 0;
+                                       NULL, m_strLocalFilename) != 0;
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
@@ -388,12 +421,12 @@ bool wxIniConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
 
 bool wxIniConfig::DeleteGroup(const char *szKey)
 {
 
 bool wxIniConfig::DeleteGroup(const char *szKey)
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, szKey);
 
   // passing NULL as section name to WritePrivateProfileString deletes the 
   // whole section according to the docs
   bool bOk = WritePrivateProfileString(path.Name(), NULL,
 
   // passing NULL as section name to WritePrivateProfileString deletes the 
   // whole section according to the docs
   bool bOk = WritePrivateProfileString(path.Name(), NULL,
-                                       NULL, m_strAppName) != 0;
+                                       NULL, m_strLocalFilename) != 0;
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
 
   if ( !bOk )
     wxLogLastError("WritePrivateProfileString");
@@ -404,7 +437,7 @@ bool wxIniConfig::DeleteGroup(const char *szKey)
 bool wxIniConfig::DeleteAll()
 {
   // first delete our group in win.ini
 bool wxIniConfig::DeleteAll()
 {
   // first delete our group in win.ini
-  WriteProfileString(m_strVendor, NULL, NULL);
+  WriteProfileString(GetVendorName(), NULL, NULL);
 
   // then delete our own ini file
   char szBuf[MAX_PATH];
 
   // then delete our own ini file
   char szBuf[MAX_PATH];
@@ -415,7 +448,7 @@ bool wxIniConfig::DeleteAll()
     wxFAIL_MSG("buffer is too small for Windows directory.");
 
   wxString strFile = szBuf;
     wxFAIL_MSG("buffer is too small for Windows directory.");
 
   wxString strFile = szBuf;
-  strFile << '\\' << m_strAppName;
+  strFile << '\\' << m_strLocalFilename;
 
   if ( !DeleteFile(strFile) ) {
     wxLogSysError(_("Can't delete the INI file '%s'"), strFile.c_str());
 
   if ( !DeleteFile(strFile) ) {
     wxLogSysError(_("Can't delete the INI file '%s'"), strFile.c_str());
index f95967bf11fa806d21a45ca8bcb477d8942ecec6..90c5eabfb6aaec3e271871e8b276bc453ca15fcf 100644 (file)
@@ -158,6 +158,7 @@ MSWOBJS = \
   $(MSWDIR)\helpwin.obj \
   $(MSWDIR)\icon.obj \
   $(MSWDIR)\imaglist.obj \
   $(MSWDIR)\helpwin.obj \
   $(MSWDIR)\icon.obj \
   $(MSWDIR)\imaglist.obj \
+  $(MSWDIR)\iniconf.obj \
   $(MSWDIR)\joystick.obj \
   $(MSWDIR)\listbox.obj \
   $(MSWDIR)\listctrl.obj \
   $(MSWDIR)\joystick.obj \
   $(MSWDIR)\listbox.obj \
   $(MSWDIR)\listctrl.obj \
@@ -787,6 +788,11 @@ $(COMMDIR)/gdicmn.obj:     $*.$(SRCSUFF)
 $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
 <<
 
 $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
 <<
 
+$(COMMDIR)/iniconf.obj:     $*.$(SRCSUFF)
+        cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
+<<
+
 $(COMMDIR)/intl.obj:     $*.$(SRCSUFF)
         cl @<<
 $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
 $(COMMDIR)/intl.obj:     $*.$(SRCSUFF)
         cl @<<
 $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
index 9b6bdf0962b40cf2884ab983c19f9eef32637585..22743d41a09905bc83813b46113739eb7bc1f2c5 100644 (file)
@@ -35,6 +35,7 @@
   #include  <wx/string.h>
 #endif //WX_PRECOMP
 
   #include  <wx/string.h>
 #endif //WX_PRECOMP
 
+#include <wx/app.h>
 #include <wx/log.h>
 #include <wx/config.h>
 #include <wx/msw/registry.h>
 #include <wx/log.h>
 #include <wx/config.h>
 #include <wx/msw/registry.h>
@@ -69,6 +70,8 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal)
 // ----------------------------------------------------------------------------
 // ctor/dtor
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // ctor/dtor
 // ----------------------------------------------------------------------------
+
+#if 0
 wxRegConfig::wxRegConfig(const wxString& strRoot)
            : m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
              m_keyLocal(m_keyLocalRoot, ""),
 wxRegConfig::wxRegConfig(const wxString& strRoot)
            : m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
              m_keyLocal(m_keyLocalRoot, ""),
@@ -84,6 +87,57 @@ wxRegConfig::wxRegConfig(const wxString& strRoot)
   wxLogNull nolog;
   m_keyGlobalRoot.Open();
 }
   wxLogNull nolog;
   m_keyGlobalRoot.Open();
 }
+#endif
+
+// TODO: vendor name is ignored, because we can't yet do the test for optional vendor
+// name in the constructor body. We need a wxRegKey::Set that takes the same
+// args as the constructor. Then we'll set m_keyLocalRoot etc. in the constructor body.
+
+wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
+      const wxString& strLocal, const wxString& strGlobal, long style)
+            : wxConfigBase(appName, vendorName, strLocal, strGlobal, style),
+
+             m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + appName),
+             m_keyLocal(m_keyLocalRoot, ""),
+             m_keyGlobalRoot(wxRegKey::HKLM, SOFTWARE_KEY + appName),
+             m_keyGlobal(m_keyGlobalRoot, "")
+{
+    // TODO: really, we should check and supply an app name if one isn't supplied.
+    // Unfortunately I don't know how to initialise the member wxRegKey
+    // variables from within the constructor body. -- JACS
+    // Vadim - we just need an implementation of wxRegKey::Set,
+    // and then we can uncomment this and remove the constructor lines above.
+/*
+    wxString strRoot(appName);
+    if (appName.IsEmpty() && wxTheApp)
+    {
+        strRoot = wxTheApp->GetAppName();
+    }
+    wxASSERT( !strRoot.IsEmpty() );
+
+    if (!vendorName.IsEmpty())
+    {
+        strRoot += "\\";
+        strRoot += vendorName;
+    }
+
+    m_keyLocalRoot.Set(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
+    m_keyLocal.Set(m_keyLocalRoot, ""),
+
+    m_keyGlobalRoot.Set(wxRegKey::HKLM, SOFTWARE_KEY + strRoot),
+    m_keyGlobal.Set(m_keyGlobalRoot, "")
+*/
+
+  // Create() will Open() if key already exists
+  m_keyLocalRoot.Create();
+
+  // as it's the same key, Open() shouldn't fail (i.e. no need for Create())
+  m_keyLocal.Open();
+
+  wxLogNull nolog;
+  m_keyGlobalRoot.Open();
+
+}
 
 wxRegConfig::~wxRegConfig()
 {
 
 wxRegConfig::~wxRegConfig()
 {
@@ -252,11 +306,9 @@ bool wxRegConfig::HasEntry(const wxString& strName) const
 // reading/writing
 // ----------------------------------------------------------------------------
 
 // reading/writing
 // ----------------------------------------------------------------------------
 
-bool wxRegConfig::Read(wxString *pStr,
-                       const char *szKey,
-                       const char *szDefault) const
+bool wxRegConfig::Read(const wxString& key, wxString *pStr) const
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   bool bQueryGlobal = TRUE;
 
 
   bool bQueryGlobal = TRUE;
 
@@ -268,7 +320,7 @@ bool wxRegConfig::Read(wxString *pStr,
         wxLogWarning("User value for immutable key '%s' ignored.",
                    path.Name().c_str());
       }
         wxLogWarning("User value for immutable key '%s' ignored.",
                    path.Name().c_str());
       }
-
+     *pStr = wxConfigBase::ExpandEnvVars(*pStr);
       return TRUE;
     }
     else {
       return TRUE;
     }
     else {
@@ -281,10 +333,49 @@ bool wxRegConfig::Read(wxString *pStr,
   if ( TryGetValue(m_keyLocal, path.Name(), *pStr) ||
        (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
     // nothing to do
   if ( TryGetValue(m_keyLocal, path.Name(), *pStr) ||
        (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
     // nothing to do
+
+    // TODO: do we return TRUE? Not in original implementation,
+    // but I don't see why not. -- JACS
+    *pStr = wxConfigBase::ExpandEnvVars(*pStr);
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+bool wxRegConfig::Read(const wxString& key, wxString *pStr,
+                       const wxString& szDefault) const
+{
+  wxConfigPathChanger path(this, key);
+
+  bool bQueryGlobal = TRUE;
+
+  // if immutable key exists in global key we must check that it's not
+  // overriden by the local key with the same name
+  if ( IsImmutable(path.Name()) ) {
+    if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) {
+      if ( m_keyLocal.HasValue(path.Name()) ) {
+        wxLogWarning("User value for immutable key '%s' ignored.",
+                   path.Name().c_str());
+      }
+
+      return TRUE;
+    }
+    else {
+      // don't waste time - it's not there anyhow
+      bQueryGlobal = FALSE;
+    }
+  }
+
+  // first try local key
+  if ( TryGetValue(m_keyLocal, path.Name(), *pStr) ||
+       (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
+    *pStr = wxConfigBase::ExpandEnvVars(*pStr);
+    return TRUE;
   }
   else {
     if ( IsRecordingDefaults() ) {
   }
   else {
     if ( IsRecordingDefaults() ) {
-      ((wxRegConfig*)this)->Write(szKey, szDefault);
+      ((wxRegConfig*)this)->Write(key, szDefault);
     }
 
     // default value
     }
 
     // default value
@@ -296,9 +387,9 @@ bool wxRegConfig::Read(wxString *pStr,
   return FALSE;
 }
 
   return FALSE;
 }
 
-bool wxRegConfig::Read(long *plResult, const char *szKey, long lDefault) const
+bool wxRegConfig::Read(const wxString& key, long *plResult) const
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   bool bQueryGlobal = TRUE;
 
 
   bool bQueryGlobal = TRUE;
 
@@ -324,15 +415,12 @@ bool wxRegConfig::Read(long *plResult, const char *szKey, long lDefault) const
        (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
     return TRUE;
   }
        (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
     return TRUE;
   }
-
-  // default
-  *plResult = lDefault;
   return FALSE;
 }
 
   return FALSE;
 }
 
-bool wxRegConfig::Write(const char *szKey, const char *szValue)
+bool wxRegConfig::Write(const wxString& key, const wxString& szValue)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   if ( IsImmutable(path.Name()) ) {
     wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
 
   if ( IsImmutable(path.Name()) ) {
     wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
@@ -342,9 +430,9 @@ bool wxRegConfig::Write(const char *szKey, const char *szValue)
   return m_keyLocal.SetValue(path.Name(), szValue);
 }
 
   return m_keyLocal.SetValue(path.Name(), szValue);
 }
 
-bool wxRegConfig::Write(const char *szKey, long lValue)
+bool wxRegConfig::Write(const wxString& key, long lValue)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   if ( IsImmutable(path.Name()) ) {
     wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
 
   if ( IsImmutable(path.Name()) ) {
     wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
@@ -357,9 +445,9 @@ bool wxRegConfig::Write(const char *szKey, long lValue)
 // ----------------------------------------------------------------------------
 // deleting
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // deleting
 // ----------------------------------------------------------------------------
-bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso)
+bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso)
 {
 {
-  PathChanger path(this, szValue);
+  wxConfigPathChanger path(this, value);
 
   if ( !m_keyLocal.DeleteValue(path.Name()) )
     return FALSE;
 
   if ( !m_keyLocal.DeleteValue(path.Name()) )
     return FALSE;
@@ -373,9 +461,9 @@ bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso)
   return TRUE;
 }
 
   return TRUE;
 }
 
-bool wxRegConfig::DeleteGroup(const char *szKey)
+bool wxRegConfig::DeleteGroup(const wxString& key)
 {
 {
-  PathChanger path(this, szKey);
+  wxConfigPathChanger path(this, key);
 
   return m_keyLocal.DeleteKey(path.Name());
 }
 
   return m_keyLocal.DeleteKey(path.Name());
 }