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"
29 #include "wx/gdicmn.h"
32 #include "wx/settings.h"
34 #include "wx/msw/private.h"
36 #include "wx/module.h"
37 #include "wx/fontutil.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // the module which is used to clean up wxSystemSettingsNative data (this is a
44 // singleton class so it can't be done in the dtor)
45 class wxSystemSettingsModule
: public wxModule
48 virtual bool OnInit();
49 virtual void OnExit();
52 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
60 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
61 static wxFont
*gs_fontDefault
= NULL
;
63 // ============================================================================
65 // ============================================================================
67 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
68 // Different args are required depending on the id. How does this differ
69 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
70 // and pass an optional void* arg to get further info.
71 // Should also have SetSystemParameter.
72 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
74 // ----------------------------------------------------------------------------
75 // wxSystemSettingsModule
76 // ----------------------------------------------------------------------------
78 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
80 bool wxSystemSettingsModule::OnInit()
85 void wxSystemSettingsModule::OnExit()
87 delete gs_fontDefault
;
88 gs_fontDefault
= NULL
;
91 // ----------------------------------------------------------------------------
92 // wxSystemSettingsNative
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
101 // we use 0 as the default value just to avoid compiler warnings, as there
102 // is no invalid colour value we use hasCol as the real indicator of
103 // whether colSys was initialized or not
107 // the default colours for the entries after BTNHIGHLIGHT
108 static const COLORREF s_defaultSysColors
[] =
110 0x000000, // 3DDKSHADOW
112 0x000000, // INFOTEXT
115 0, // filler - no std colour with this index
117 // TODO: please fill in the standard values of those, I don't have them
119 0, // GRADIENTACTIVECAPTION
120 0, // GRADIENTINACTIVECAPTION
122 0, // MENUBAR (unused)
125 if ( index
== wxSYS_COLOUR_LISTBOX
)
127 // there is no standard colour with this index, map to another one
128 index
= wxSYS_COLOUR_WINDOW
;
130 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
132 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
133 // all Windows version, for the other ones we have to check
136 // none of the is supported under Win16 anyhow
139 wxGetOsVersion(&verMaj
, &verMin
);
145 else if ( verMaj
== 4 )
148 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
150 else if ( verMaj
== 5 && verMin
== 0 )
153 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
166 // special handling for MENUBAR colour: we use this in wxToolBar
167 // and wxStatusBar to have correct bg colour under Windows XP
168 // (which uses COLOR_MENUBAR for them) but they should still look
169 // correctly under previous Windows versions as well
170 if ( index
== wxSYS_COLOUR_MENUBAR
)
172 index
= wxSYS_COLOUR_3DFACE
;
174 else // replace with default colour
176 int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
178 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
179 _T("forgot tp update the default colours array") );
181 colSys
= s_defaultSysColors
[n
];
189 colSys
= ::GetSysColor(index
);
192 return wxRGBToColour(colSys
);
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 wxFont
wxCreateFontFromStockObject(int index
)
203 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
207 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
209 wxNativeFontInfo info
;
211 // Under MicroWindows we pass the HFONT as well
212 // because it's hard to convert HFONT -> LOGFONT -> HFONT
213 // It's OK to delete stock objects, the delete will be ignored.
214 #ifdef __WXMICROWIN__
215 font
.Create(info
, (WXHFONT
) hFont
);
222 wxFAIL_MSG( _T("failed to get LOGFONT") );
225 else // GetStockObject() failed
227 wxFAIL_MSG( _T("stock font not found") );
233 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
235 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
236 // called fairly often - this is why we cache this particular font
237 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
238 if ( isDefaultRequested
&& gs_fontDefault
)
240 return *gs_fontDefault
;
243 wxFont font
= wxCreateFontFromStockObject(index
);
245 if ( isDefaultRequested
)
247 // if we got here it means we hadn't cached it yet - do now
248 gs_fontDefault
= new wxFont(font
);
254 // ----------------------------------------------------------------------------
255 // system metrics/features
256 // ----------------------------------------------------------------------------
258 // TODO: some of the "metrics" clearly should be features now that we have
261 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
263 // if the constant is not defined, put -1 in the table to indicate that it is
265 static const int gs_metricsMap
[] =
267 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
280 #if defined(__WIN32__) && defined(SM_CXDRAG)
300 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
315 #if defined(__WIN32__) && defined(SM_NETWORK)
321 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
329 // Get a system metric, e.g. scrollbar size
330 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
)
332 #ifdef __WXMICROWIN__
333 // TODO: probably use wxUniv themes functionality
335 #else // !__WXMICROWIN__
336 wxCHECK_MSG( index
< WXSIZEOF(gs_metricsMap
), 0, _T("invalid metric") );
338 int indexMSW
= gs_metricsMap
[index
];
339 if ( indexMSW
== -1 )
341 // not supported under current system
345 int rc
= ::GetSystemMetrics(indexMSW
);
346 if ( index
== wxSYS_NETWORK_PRESENT
)
348 // only the last bit is significant according to the MSDN
353 #endif // __WXMICROWIN__/!__WXMICROWIN__
356 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
360 case wxSYS_CAN_ICONIZE_FRAME
:
361 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
365 wxFAIL_MSG( _T("unknown system feature") );