]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/regconf.cpp
TestDestroy() is not const any more (warnings suppressed)
[wxWidgets.git] / src / msw / regconf.cpp
index 22743d41a09905bc83813b46113739eb7bc1f2c5..99382c2ce2d9ea21a4d13b54729c6827cab97cad 100644 (file)
 #pragma implementation "regconf.h"
 #endif
 
-// ============================================================================
-// declarations
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// headers
-// ----------------------------------------------------------------------------
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
 
-#ifdef __GNUG__
-  #pragma implementation "regconf.h"
+#ifdef __BORLANDC__
+#pragma hdrstop
 #endif
 
-#include  "wx/wxprec.h"
-
-#ifdef    __BORLANDC__
-  #pragma hdrstop
-#endif  //__BORLANDC__
-
 #ifndef WX_PRECOMP
   #include  <wx/string.h>
 #endif //WX_PRECOMP
 
+#include <wx/event.h>
 #include <wx/app.h>
 #include <wx/log.h>
 #include <wx/config.h>
+
+#ifndef __WIN16__
+
 #include <wx/msw/registry.h>
 #include <wx/msw/regconf.h>
 
@@ -71,62 +64,60 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal)
 // ctor/dtor
 // ----------------------------------------------------------------------------
 
-#if 0
-wxRegConfig::wxRegConfig(const wxString& strRoot)
-           : m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
-             m_keyLocal(m_keyLocalRoot, ""),
-             m_keyGlobalRoot(wxRegKey::HKLM, SOFTWARE_KEY + strRoot),
-             m_keyGlobal(m_keyGlobalRoot, "")
+// create the config object which stores its data under HKCU\vendor\app and, if
+// style & wxCONFIG_USE_GLOBAL_FILE, under HKLM\vendor\app
+wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
+                         const wxString& strLocal, const wxString& strGlobal,
+                         long style)
+           : wxConfigBase(appName, vendorName, strLocal, strGlobal, style)
 {
-  // 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();
-}
-#endif
+  wxString strRoot;
 
-// 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.
+  bool bDoUseGlobal = (style & wxCONFIG_USE_GLOBAL_FILE) != 0;
 
-wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
-      const wxString& strLocal, const wxString& strGlobal, long style)
-            : wxConfigBase(appName, vendorName, strLocal, strGlobal, style),
+  // the convention is to put the programs keys under <vendor>\<appname>
+  // (but it can be overriden by specifying the pathes explicitly in strLocal
+  // and/or strGlobal)
+  if ( strLocal.IsEmpty() || (strGlobal.IsEmpty() && bDoUseGlobal) )
+  {
+    if ( vendorName.IsEmpty() )
+    {
+      if ( wxTheApp )
+        strRoot = wxTheApp->GetVendorName();
+    }
+    else
+    {
+      strRoot = vendorName;
+    }
 
-             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)
+    // no '\\' needed if no vendor name
+    if ( !strRoot.IsEmpty() )
     {
-        strRoot = wxTheApp->GetAppName();
+      strRoot += '\\';
     }
-    wxASSERT( !strRoot.IsEmpty() );
 
-    if (!vendorName.IsEmpty())
+    if ( appName.IsEmpty() )
     {
-        strRoot += "\\";
-        strRoot += vendorName;
+      wxCHECK_RET( wxTheApp, "No application name in wxRegConfig ctor!" );
+      strRoot << wxTheApp->GetAppName();
     }
+    else
+    {
+      strRoot << appName;
+    }
+  }
+  //else: we don't need to do all the complicated stuff above
 
-    m_keyLocalRoot.Set(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
-    m_keyLocal.Set(m_keyLocalRoot, ""),
+  wxString str = strLocal.IsEmpty() ? strRoot : strLocal;
+  m_keyLocalRoot.SetName(wxRegKey::HKCU, SOFTWARE_KEY + str);
+  m_keyLocal.SetName(m_keyLocalRoot, "");
 
-    m_keyGlobalRoot.Set(wxRegKey::HKLM, SOFTWARE_KEY + strRoot),
-    m_keyGlobal.Set(m_keyGlobalRoot, "")
-*/
+  if ( bDoUseGlobal )
+  {
+    str = strGlobal.IsEmpty() ? strRoot : strGlobal;
+    m_keyGlobalRoot.SetName(wxRegKey::HKLM, SOFTWARE_KEY + str);
+    m_keyGlobal.SetName(m_keyGlobalRoot, "");
+  }
 
   // Create() will Open() if key already exists
   m_keyLocalRoot.Create();
@@ -134,9 +125,13 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
   // as it's the same key, Open() shouldn't fail (i.e. no need for Create())
   m_keyLocal.Open();
 
-  wxLogNull nolog;
-  m_keyGlobalRoot.Open();
-
+  // OTOH, this key may perfectly not exist, so suppress error messages the call
+  // to Open() might generate
+  if ( bDoUseGlobal )
+  {
+    wxLogNull nolog;
+    m_keyGlobalRoot.Open();
+  }
 }
 
 wxRegConfig::~wxRegConfig()
@@ -453,7 +448,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso)
     return FALSE;
 
   if ( !m_keyLocal.HasSubkeys() ) {
-    wxString strKey = GetPath().Right(wxCONFIG_PATH_SEPARATOR);
+    wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR);
     SetPath("..");  // changes m_keyLocal
     return m_keyLocal.DeleteKey(strKey);
   }
@@ -472,10 +467,18 @@ bool wxRegConfig::DeleteAll()
 {
   m_keyLocal.Close();
   m_keyGlobal.Close();
-
+#if 1
+  wxFAIL_MSG("wxRegConfig::DeleteAll will wipe out your entire registry, so please do not use until it's fixed!");
+  return FALSE;
+#else
   bool bOk = m_keyLocalRoot.DeleteSelf();
   if ( bOk )
     bOk = m_keyGlobalRoot.DeleteSelf();
 
   return bOk;
+#endif
 }
+
+#endif
+  // __WIN16__
+