1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/settings.cpp
3 // Purpose: wxSystemSettingsNative implementation for MSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/gdicmn.h"
31 #include "wx/settings.h"
33 #include "wx/msw/private.h"
35 #include "wx/module.h"
36 #include "wx/fontutil.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // the module which is used to clean up wxSystemSettingsNative data (this is a
43 // singleton class so it can't be done in the dtor)
44 class wxSystemSettingsModule
: public wxModule
47 virtual bool OnInit();
48 virtual void OnExit();
51 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
59 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
60 static wxFont
*gs_fontDefault
= NULL
;
62 // ============================================================================
64 // ============================================================================
66 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
67 // Different args are required depending on the id. How does this differ
68 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
69 // and pass an optional void* arg to get further info.
70 // Should also have SetSystemParameter.
71 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
73 // ----------------------------------------------------------------------------
74 // wxSystemSettingsModule
75 // ----------------------------------------------------------------------------
77 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
79 bool wxSystemSettingsModule::OnInit()
84 void wxSystemSettingsModule::OnExit()
86 delete gs_fontDefault
;
87 gs_fontDefault
= NULL
;
90 // ----------------------------------------------------------------------------
91 // wxSystemSettingsNative
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
101 wxRGBToColour(col
, ::GetSysColor(index
));
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 wxFont
wxCreateFontFromStockObject(int index
)
113 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
117 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
119 wxNativeFontInfo info
;
121 // Under MicroWindows we pass the HFONT as well
122 // because it's hard to convert HFONT -> LOGFONT -> HFONT
123 // It's OK to delete stock objects, the delete will be ignored.
124 #ifdef __WXMICROWIN__
125 font
.Create(info
, (WXHFONT
) hFont
);
132 wxFAIL_MSG( _T("failed to get LOGFONT") );
135 else // GetStockObject() failed
137 wxFAIL_MSG( _T("stock font not found") );
143 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
145 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
146 // called fairly often - this is why we cache this particular font
147 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
148 if ( isDefaultRequested
&& gs_fontDefault
)
150 return *gs_fontDefault
;
153 wxFont font
= wxCreateFontFromStockObject(index
);
155 if ( isDefaultRequested
)
157 // if we got here it means we hadn't cached it yet - do now
158 gs_fontDefault
= new wxFont(font
);
164 // ----------------------------------------------------------------------------
165 // system metrics/features
166 // ----------------------------------------------------------------------------
168 // TODO: some of the "metrics" clearly should be features now that we have
171 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
173 // if the constant is not defined, put -1 in the table to indicate that it is
175 static const int gs_metricsMap
[] =
189 #if defined(__WIN32__) && defined(SM_CXDRAG)
209 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
224 #if defined(__WIN32__) && defined(SM_NETWORK)
230 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
238 // Get a system metric, e.g. scrollbar size
239 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
)
241 #ifdef __WXMICROWIN__
242 // TODO: probably use wxUniv themes functionality
244 #else // !__WXMICROWIN__
245 wxCHECK_MSG( index
< WXSIZEOF(gs_metricsMap
), 0, _T("invalid metric") );
247 int indexMSW
= gs_metricsMap
[index
];
248 if ( indexMSW
== -1 )
250 // not supported under current system
254 int rc
= ::GetSystemMetrics(indexMSW
);
255 if ( index
== wxSYS_NETWORK_PRESENT
)
257 // only the last bit is significant according to the MSDN
262 #endif // __WXMICROWIN__/!__WXMICROWIN__
265 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
269 case wxSYS_CAN_ICONIZE_FRAME
:
270 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
274 wxFAIL_MSG( _T("unknown system feature") );