X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ca6a5f04692678cd2d9f3ea0843fc3f5a0b254f..87df17a11b0017d31c09f767bd921abb27193bee:/src/msw/settings.cpp diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 5e05b92cdf..133c23ab95 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: settings.cpp -// Purpose: wxSettings +// Name: msw/settings.cpp +// Purpose: wxSystemSettings // Author: Julian Smart // Modified by: // Created: 04/01/98 @@ -9,8 +9,16 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "settings.h" + #pragma implementation "settings.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -21,16 +29,72 @@ #endif #ifndef WX_PRECOMP -#include -#include "wx/defs.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/gdicmn.h" + #include + #include "wx/defs.h" + #include "wx/pen.h" + #include "wx/brush.h" + #include "wx/gdicmn.h" #endif #include "wx/settings.h" #include "wx/window.h" #include "wx/msw/private.h" +#include "wx/module.h" + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// the module which is used to clean up wxSystemSettings data (this is a +// singleton class so it can't be done in the dtor) +class wxSystemSettingsModule : public wxModule +{ + friend class wxSystemSettings; +public: + virtual bool OnInit(); + virtual void OnExit(); + +private: + DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule) + + static wxArrayString sm_optionNames; + static wxArrayString sm_optionValues; +}; + +// ---------------------------------------------------------------------------- +// global data +// ---------------------------------------------------------------------------- + +static wxFont *gs_fontDefault = NULL; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxSystemSettingsModule +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) + +wxArrayString wxSystemSettingsModule::sm_optionNames; +wxArrayString wxSystemSettingsModule::sm_optionValues; + +bool wxSystemSettingsModule::OnInit() +{ + return TRUE; +} + +void wxSystemSettingsModule::OnExit() +{ + sm_optionNames.Clear(); + sm_optionValues.Clear(); + delete gs_fontDefault; +} + +// ---------------------------------------------------------------------------- +// wxSystemSettings +// ---------------------------------------------------------------------------- // TODO: see ::SystemParametersInfo for all sorts of Windows settings. // Different args are required depending on the id. How does this differ @@ -45,36 +109,51 @@ wxColour wxSystemSettings::GetSystemColour(int index) { case wxSYS_COLOUR_LISTBOX: return *wxWHITE; - break; - + default: COLORREF ref = ::GetSysColor(index); wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); return col; - break; } } wxFont wxSystemSettings::GetSystemFont(int index) { + // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're + // called fairly often - this is why we cache this particular font + bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT; + if ( isDefaultRequested && gs_fontDefault ) + { + return *gs_fontDefault; + } + + wxFont font; + HFONT hFont = (HFONT) ::GetStockObject(index); - if ( hFont != (HFONT) NULL ) + if ( hFont ) { LOGFONT lf; if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) { - // In fontdlg.cpp - return wxCreateFontFromLogFont(&lf); + font = wxCreateFontFromLogFont(&lf); } else { - return wxNullFont; + wxFAIL_MSG( _T("failed to get LOGFONT") ); } } - else + else // GetStockObject() failed { - return wxNullFont; + wxFAIL_MSG( _T("stock font not found") ); } + + if ( isDefaultRequested ) + { + // if we got here it means we hadn't cached it yet - do now + gs_fontDefault = new wxFont(font); + } + + return font; } // Get a system metric, e.g. scrollbar size @@ -173,3 +252,45 @@ int wxSystemSettings::GetSystemMetric(int index) } } +// Option functions (arbitrary name/value mapping) +void wxSystemSettings::SetOption(const wxString& name, const wxString& value) +{ + int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE); + if (idx == wxNOT_FOUND) + { + wxSystemSettingsModule::sm_optionNames.Add(name); + wxSystemSettingsModule::sm_optionValues.Add(value); + } + else + { + wxSystemSettingsModule::sm_optionNames[idx] = name; + wxSystemSettingsModule::sm_optionValues[idx] = value; + } +} + +void wxSystemSettings::SetOption(const wxString& name, int value) +{ + wxString valStr; + valStr.Printf(wxT("%d"), value); + SetOption(name, valStr); +} + +wxString wxSystemSettings::GetOption(const wxString& name) +{ + int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE); + if (idx == wxNOT_FOUND) + return wxEmptyString; + else + return wxSystemSettingsModule::sm_optionValues[idx]; +} + +int wxSystemSettings::GetOptionInt(const wxString& name) +{ + return wxAtoi(GetOption(name)); +} + +bool wxSystemSettings::HasOption(const wxString& name) +{ + return (wxSystemSettingsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND); +} +