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
)
100 // we use 0 as the default value just to avoid compiler warnings, as there
101 // is no invalid colour value we use hasCol as the real indicator of
102 // whether colSys was initialized or not
106 // the default colours for the entries after BTNHIGHLIGHT
107 static const COLORREF s_defaultSysColors
[] =
109 0x000000, // 3DDKSHADOW
111 0x000000, // INFOTEXT
114 0, // filler - no std colour with this index
116 // TODO: please fill in the standard values of those, I don't have them
118 0, // GRADIENTACTIVECAPTION
119 0, // GRADIENTINACTIVECAPTION
121 0, // MENUBAR (unused)
124 if ( index
== wxSYS_COLOUR_LISTBOX
)
126 // there is no standard colour with this index, map to another one
127 index
= wxSYS_COLOUR_WINDOW
;
129 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
131 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
132 // all Windows version, for the other ones we have to check
135 // none of the is supported under Win16 anyhow
138 wxGetOsVersion(&verMaj
, &verMin
);
144 else if ( verMaj
== 4 )
147 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
149 else if ( verMaj
== 5 && verMin
== 0 )
152 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
165 // special handling for MENUBAR colour: we use this in wxToolBar
166 // and wxStatusBar to have correct bg colour under Windows XP
167 // (which uses COLOR_MENUBAR for them) but they should still look
168 // correctly under previous Windows versions as well
169 if ( index
== wxSYS_COLOUR_MENUBAR
)
171 index
= wxSYS_COLOUR_3DFACE
;
173 else // replace with default colour
175 int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
177 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
178 _T("forgot tp update the default colours array") );
180 colSys
= s_defaultSysColors
[n
];
188 colSys
= ::GetSysColor(index
);
191 return wxRGBToColour(colSys
);
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 wxFont
wxCreateFontFromStockObject(int index
)
202 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
206 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
208 wxNativeFontInfo info
;
210 // Under MicroWindows we pass the HFONT as well
211 // because it's hard to convert HFONT -> LOGFONT -> HFONT
212 // It's OK to delete stock objects, the delete will be ignored.
213 #ifdef __WXMICROWIN__
214 font
.Create(info
, (WXHFONT
) hFont
);
221 wxFAIL_MSG( _T("failed to get LOGFONT") );
224 else // GetStockObject() failed
226 wxFAIL_MSG( _T("stock font not found") );
232 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
234 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
235 // called fairly often - this is why we cache this particular font
236 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
237 if ( isDefaultRequested
&& gs_fontDefault
)
239 return *gs_fontDefault
;
242 wxFont font
= wxCreateFontFromStockObject(index
);
244 if ( isDefaultRequested
)
246 // if we got here it means we hadn't cached it yet - do now
247 gs_fontDefault
= new wxFont(font
);
253 // ----------------------------------------------------------------------------
254 // system metrics/features
255 // ----------------------------------------------------------------------------
257 // TODO: some of the "metrics" clearly should be features now that we have
260 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
262 // if the constant is not defined, put -1 in the table to indicate that it is
264 static const int gs_metricsMap
[] =
266 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
279 #if defined(__WIN32__) && defined(SM_CXDRAG)
299 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
314 #if defined(__WIN32__) && defined(SM_NETWORK)
320 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
328 // Get a system metric, e.g. scrollbar size
329 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
)
331 #ifdef __WXMICROWIN__
332 // TODO: probably use wxUniv themes functionality
334 #else // !__WXMICROWIN__
335 wxCHECK_MSG( index
< WXSIZEOF(gs_metricsMap
), 0, _T("invalid metric") );
337 int indexMSW
= gs_metricsMap
[index
];
338 if ( indexMSW
== -1 )
340 // not supported under current system
344 int rc
= ::GetSystemMetrics(indexMSW
);
345 if ( index
== wxSYS_NETWORK_PRESENT
)
347 // only the last bit is significant according to the MSDN
352 #endif // __WXMICROWIN__/!__WXMICROWIN__
355 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
359 case wxSYS_CAN_ICONIZE_FRAME
:
360 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
364 wxFAIL_MSG( _T("unknown system feature") );