From 84281b92d51cf7cd61dccee4c2399ed110835220 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 May 2007 00:50:54 +0000 Subject: [PATCH] added wxAppTraits::CreateConfig() (patch 1721149) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46189 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/apptrait.h | 14 ++++++++++---- src/common/config.cpp | 29 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index d9147fdd24..b6447ed965 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -16,15 +16,16 @@ #include "wx/platinfo.h" class WXDLLIMPEXP_BASE wxArrayString; -class WXDLLIMPEXP_BASE wxObject; -class WXDLLEXPORT wxAppTraits; +class WXDLLIMPEXP_BASE wxConfigBase; class WXDLLIMPEXP_BASE wxEventLoopBase; #if wxUSE_FONTMAP class WXDLLEXPORT wxFontMapper; #endif // wxUSE_FONTMAP class WXDLLIMPEXP_BASE wxLog; class WXDLLIMPEXP_BASE wxMessageOutput; +class WXDLLIMPEXP_BASE wxObject; class WXDLLEXPORT wxRendererNative; +class WXDLLIMPEXP_BASE wxStandardPathsBase; class WXDLLIMPEXP_BASE wxString; class WXDLLIMPEXP_BASE wxTimer; class WXDLLIMPEXP_BASE wxTimerImpl; @@ -36,8 +37,6 @@ class GSocketGUIFunctionsTable; // wxAppTraits: this class defines various configurable aspects of wxApp // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_BASE wxStandardPathsBase; - class WXDLLIMPEXP_BASE wxAppTraitsBase { public: @@ -47,6 +46,13 @@ public: // hooks for working with the global objects, may be overridden by the user // ------------------------------------------------------------------------ +#if wxUSE_CONFIG + // create the default configuration object (base class version is + // implemented in config.cpp and creates wxRegConfig for wxMSW and + // wxFileConfig for all the other platforms) + virtual wxConfigBase *CreateConfig(); +#endif // wxUSE_CONFIG + #if wxUSE_LOG // create the default log target virtual wxLog *CreateLogTarget() = 0; diff --git a/src/common/config.cpp b/src/common/config.cpp index 17db0fca5a..e7e62a34bb 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -37,6 +37,7 @@ #if wxUSE_CONFIG && ((wxUSE_FILE && wxUSE_TEXTFILE) || wxUSE_CONFIG_NATIVE) +#include "wx/apptrait.h" #include "wx/file.h" #include @@ -54,6 +55,22 @@ bool wxConfigBase::ms_bAutoCreate = true; // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// wxAppTraitsBase +// ---------------------------------------------------------------------------- + +wxConfigBase *wxAppTraitsBase::CreateConfig() +{ + return new + #if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE + wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName()); + #elif defined(__WXPALMOS__) && wxUSE_CONFIG_NATIVE + wxPrefConfig(wxTheApp->GetAppName()); + #else // either we're under Unix or wish to use files even under Windows + wxFileConfig(wxTheApp->GetAppName()); + #endif +} + // ---------------------------------------------------------------------------- // wxConfigBase // ---------------------------------------------------------------------------- @@ -87,14 +104,10 @@ wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig) wxConfigBase *wxConfigBase::Create() { if ( ms_bAutoCreate && ms_pConfig == NULL ) { - ms_pConfig = - #if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE - new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName()); - #elif defined(__WXPALMOS__) && wxUSE_CONFIG_NATIVE - new wxPrefConfig(wxTheApp->GetAppName()); - #else // either we're under Unix or wish to use files even under Windows - new wxFileConfig(wxTheApp->GetAppName()); - #endif + wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxCHECK_MSG( traits, NULL, _T("create wxApp before calling this") ); + + ms_pConfig = traits->CreateConfig(); } return ms_pConfig; -- 2.45.2