X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3897b707bd39c491c820849953431e4a5751fced..a111f2b216a90bacb254644d3cae526eddc9f9f1:/src/msw/settings.cpp diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index bfdb3d7506..360e8a2fc3 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,66 @@ #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" +#include "wx/fontutil.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) +}; + +// ---------------------------------------------------------------------------- +// global data +// ---------------------------------------------------------------------------- + +static wxFont *gs_fontDefault = NULL; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxSystemSettingsModule +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) + +bool wxSystemSettingsModule::OnInit() +{ + return TRUE; +} + +void wxSystemSettingsModule::OnExit() +{ + delete gs_fontDefault; + gs_fontDefault = NULL; +} + +// ---------------------------------------------------------------------------- +// wxSystemSettings +// ---------------------------------------------------------------------------- // TODO: see ::SystemParametersInfo for all sorts of Windows settings. // Different args are required depending on the id. How does this differ @@ -45,7 +103,7 @@ wxColour wxSystemSettings::GetSystemColour(int index) { case wxSYS_COLOUR_LISTBOX: return *wxWHITE; - + default: COLORREF ref = ::GetSysColor(index); wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); @@ -53,31 +111,67 @@ wxColour wxSystemSettings::GetSystemColour(int index) } } -wxFont wxSystemSettings::GetSystemFont(int index) +wxFont wxCreateFontFromStockObject(int index) { + 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); + wxNativeFontInfo info; + info.lf = lf; + // Under MicroWindows we pass the HFONT as well + // because it's hard to convert HFONT -> LOGFONT -> HFONT + // It's OK to delete stock objects, the delete will be ignored. +#ifdef __WXMICROWIN__ + font.Create(info, (WXHFONT) hFont); +#else + font.Create(info); +#endif } else { - return wxNullFont; + wxFAIL_MSG( _T("failed to get LOGFONT") ); } } - else + else // GetStockObject() failed { - return wxNullFont; + wxFAIL_MSG( _T("stock font not found") ); } + return font; +} + +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 = wxCreateFontFromStockObject(index); + + 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 int wxSystemSettings::GetSystemMetric(int index) { +#ifdef __WXMICROWIN__ + // TODO: probably use wxUniv themes functionality + return 0; +#else switch ( index) { #ifdef __WIN32__ @@ -169,5 +263,7 @@ int wxSystemSettings::GetSystemMetric(int index) default: return 0; } +#endif + // __WXMICROWIN__ }