diff --git a/docs/changes.txt b/docs/changes.txt index c6f93d8848..bae06e4442 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -408,6 +408,10 @@ Changes in behaviour which may result in compilation errors any more. Use wxBookCtrlEvent in your code if you need to forward-declare it or just include the appropriate header instead of forward declaration. +- wxStandardPaths class can't be created now. This was never the right thing + to do, wxStandardPaths::Get() always had to be used to access the global + object of the correct type but now doing it results in a compilation error. + Deprecated methods and their replacements ----------------------------------------- diff --git a/include/wx/msw/stdpaths.h b/include/wx/msw/stdpaths.h index a9d53f38a6..eb18bd2b83 100644 --- a/include/wx/msw/stdpaths.h +++ b/include/wx/msw/stdpaths.h @@ -19,10 +19,6 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase { public: - // ctor calls IgnoreAppBuildSubDirs() and also sets up the object to use - // both vendor and application name by default - wxStandardPaths(); - // implement base class pure virtuals virtual wxString GetExecutablePath() const; virtual wxString GetConfigDir() const; @@ -67,6 +63,13 @@ public: static wxString MSWGetShellDir(int csidl); protected: + // Ctor is protected, use wxStandardPaths::Get() instead of instantiating + // objects of this class directly. + // + // It calls IgnoreAppBuildSubDirs() and also sets up the object to use + // both vendor and application name by default. + wxStandardPaths(); + // get the path corresponding to the given standard CSIDL_XXX constant static wxString DoGetDirectory(int csidl); diff --git a/include/wx/os2/stdpaths.h b/include/wx/os2/stdpaths.h index 72ae2ea183..571ca38b99 100644 --- a/include/wx/os2/stdpaths.h +++ b/include/wx/os2/stdpaths.h @@ -40,6 +40,11 @@ public: virtual wxString GetUserDataDir() const; virtual wxString GetPluginsDir() const; +protected: + // Ctor is protected, use wxStandardPaths::Get() instead of instantiating + // objects of this class directly. + wxStandardPaths() { } + private: static wxString m_prefix; }; diff --git a/include/wx/osx/core/stdpaths.h b/include/wx/osx/core/stdpaths.h index 4c48407f7b..aed2c10a21 100644 --- a/include/wx/osx/core/stdpaths.h +++ b/include/wx/osx/core/stdpaths.h @@ -35,7 +35,6 @@ typedef __CFBundle * wxCFBundleRef; class WXDLLIMPEXP_BASE wxStandardPathsCF : public wxStandardPathsCFBase { public: - wxStandardPathsCF(); virtual ~wxStandardPathsCF(); // wxMac specific: allow user to specify a different bundle @@ -57,6 +56,10 @@ public: virtual wxString GetDocumentsDir() const; protected: + // Ctor is protected, use wxStandardPaths::Get() instead of instantiating + // objects of this class directly. + wxStandardPathsCF(); + // this function can be called with any of CFBundleCopyXXXURL function // pointer as parameter wxString GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const; diff --git a/include/wx/stdpaths.h b/include/wx/stdpaths.h index 1bf5af0831..55c0b785f8 100644 --- a/include/wx/stdpaths.h +++ b/include/wx/stdpaths.h @@ -142,9 +142,6 @@ public: virtual wxString GetTempDir() const; - // ctor for the base class - wxStandardPathsBase(); - // virtual dtor for the base class virtual ~wxStandardPathsBase(); @@ -158,6 +155,10 @@ public: protected: + // Ctor is protected as this is a base class which should never be created + // directly. + wxStandardPathsBase(); + // append the path component, with a leading path separator if a // path separator or dot (.) is not already at the end of dir static wxString AppendPathComponent(const wxString& dir, const wxString& component); @@ -210,6 +211,12 @@ public: virtual wxString GetPluginsDir() const { return m_prefix; } virtual wxString GetDocumentsDir() const { return m_prefix; } +protected: + // Ctor is protected because wxStandardPaths::Get() should always be used + // to access the global wxStandardPaths object of the correct type instead + // of creating one of a possibly wrong type yourself. + wxStandardPaths() { } + private: wxString m_prefix; }; diff --git a/include/wx/unix/stdpaths.h b/include/wx/unix/stdpaths.h index 0692bfaec1..0d63f1a4ce 100644 --- a/include/wx/unix/stdpaths.h +++ b/include/wx/unix/stdpaths.h @@ -51,6 +51,11 @@ public: virtual wxString GetDocumentsDir() const; #endif +protected: + // Ctor is protected, use wxStandardPaths::Get() instead of instantiating + // objects of this class directly. + wxStandardPaths() { } + private: wxString m_prefix; }; diff --git a/interface/wx/stdpaths.h b/interface/wx/stdpaths.h index 29d9c849e3..829de479ae 100644 --- a/interface/wx/stdpaths.h +++ b/interface/wx/stdpaths.h @@ -363,5 +363,15 @@ public: @since 2.9.0 */ void UseAppInfo(int info); + +protected: + /** + Protected default constructor. + + This constructor is protected in order to prevent creation of objects + of this class as Get() should be used instead to access the unique + global wxStandardPaths object of the correct type. + */ + wxStandardPaths(); }; diff --git a/src/common/stdpbase.cpp b/src/common/stdpbase.cpp index e421f3b26a..1d831afed3 100644 --- a/src/common/stdpbase.cpp +++ b/src/common/stdpbase.cpp @@ -36,7 +36,21 @@ // module globals // ---------------------------------------------------------------------------- -static wxStandardPaths gs_stdPaths; +namespace +{ + +// Derive a class just to be able to create it: wxStandardPaths ctor is +// protected to prevent its misuse, but it also means we can't create an object +// of this class directly. +class wxStandardPathsDefault : public wxStandardPaths +{ +public: + wxStandardPathsDefault() { } +}; + +static wxStandardPathsDefault gs_stdPaths; + +} // anonymous namespace // ============================================================================ // implementation diff --git a/src/osx/core/utilsexc_cf.cpp b/src/osx/core/utilsexc_cf.cpp index f00cb5e38f..b9fae2e446 100644 --- a/src/osx/core/utilsexc_cf.cpp +++ b/src/osx/core/utilsexc_cf.cpp @@ -156,9 +156,19 @@ wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager() // NOTE: This doesn't really belong here but this was a handy file to // put it in because it's already compiled for wxCocoa and wxMac GUI lib. #if wxUSE_STDPATHS -static wxStandardPathsCF gs_stdPaths; wxStandardPaths& wxGUIAppTraits::GetStandardPaths() { + // Derive a class just to be able to create it: wxStandardPaths ctor is + // protected to prevent its misuse, but it also means we can't create an + // object of this class directly. + class wxStandardPathsDefault : public wxStandardPathsCF + { + public: + wxStandardPathsDefault() { } + }; + + static wxStandardPathsDefault gs_stdPaths; + return gs_stdPaths; } #endif